/*
* Copyright (C) 2008,2009 Red Hat, Inc. All rights reserved.
*
* This file is part of LVM2.
*
* This copyrighted material is made available to anyone wishing to use,
* modify, copy, or redistribute it subject to the terms and conditions
* of the GNU Lesser General Public License v.2.1.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
/* Set default for linear segment specific LV parameters */
static void _lv_set_default_linear_params(struct cmd_context *cmd,
struct lvcreate_params *lp)
{
lp->segtype = get_segtype_from_string(cmd, "striped");
lp->stripes = 1;
lp->stripe_size = DEFAULT_STRIPESIZE * 2;
}
/*
* FIXME: This function should probably not commit to disk but require calling
* lvm_vg_write. However, this appears to be non-trivial change until
* lv_create_single is refactored by segtype.
*/
lv_t lvm_vg_create_lv_linear(vg_t vg, const char *name, uint64_t size)
{
struct lvcreate_params lp;
uint64_t extents;
struct lv_list *lvl;
if (vg_read_error(vg))
return NULL;
if (!vg_check_write_mode(vg))
return NULL;
memset(&lp, 0, sizeof(lp));
extents = extents_from_size(vg->cmd, size, vg->extent_size);
_lv_set_default_params(&lp, vg, name, extents);
_lv_set_default_linear_params(vg->cmd, &lp);
if (!lv_create_single(vg, &lp))
return NULL;
lvl = find_lv_in_vg(vg, name);
if (!lvl)
return NULL;
return (lv_t) lvl->lv;
}
/*
* FIXME: This function should probably not commit to disk but require calling
* lvm_vg_write.
*/
int lvm_vg_remove_lv(lv_t lv)
{
if (!lv || !lv->vg || vg_read_error(lv->vg))
return -1;
if (!vg_check_write_mode(lv->vg))
return -1;
if (!lv_remove_single(lv->vg->cmd, lv, DONT_PROMPT))
return -1;
return 0;
}
int lvm_lv_activate(lv_t lv)
{
if (!lv || !lv->vg || vg_read_error(lv->vg) || !lv->vg->cmd)
return -1;
/* FIXME: handle pvmove stuff later */
if (lv->status & LOCKED) {
log_error("Unable to activate locked LV");
return -1;
}
/* FIXME: handle lvconvert stuff later */
if (lv->status & CONVERTING) {
log_error("Unable to activate LV with in-progress lvconvert");
return -1;
}