1
0
mirror of git://sourceware.org/git/lvm2.git synced 2025-03-31 14:50:37 +03:00

o Lock mechanism for LV activation

o #defines for common lock flag combinations
o Try out hyphens instead of colons in device-mapper names - does this
  make messages containing filenames easier to read?
This commit is contained in:
Alasdair Kergon 2002-02-27 12:26:41 +00:00
parent aaed82738a
commit 73a88ab3d3
18 changed files with 183 additions and 113 deletions

View File

@ -376,7 +376,7 @@ static struct logical_volume *_lv_from_lvid(struct cmd_context *cmd,
}
if (!(lvl = find_lv_in_vg_by_uuid(vg, slash + 1))) {
log_error("Can't find logical volume id %s", lvid);
log_verbose("Can't find logical volume id %s", lvid);
return NULL;
}
@ -390,7 +390,7 @@ int lv_suspend_if_active(struct cmd_context *cmd, const char *lvid)
if (!(lv = _lv_from_lvid(cmd, lvid)))
return 0;
if (lv_active(lv))
if (lv_active(lv) > 0)
lv_suspend(lv);
return 1;
}
@ -402,9 +402,35 @@ int lv_resume_if_active(struct cmd_context *cmd, const char *lvid)
if (!(lv = _lv_from_lvid(cmd, lvid)))
return 0;
if (lv_active(lv))
if ((lv_active(lv) > 0) && lv_suspended(lv))
lv_reactivate(lv);
return 1;
}
int lv_deactivate_if_active(struct cmd_context *cmd, const char *lvid)
{
struct logical_volume *lv;
if (!(lv = _lv_from_lvid(cmd, lvid)))
return 0;
if (lv_active(lv) > 0)
lv_deactivate(lv);
return 1;
}
int lv_activate_if_inactive(struct cmd_context *cmd, const char *lvid)
{
struct logical_volume *lv;
if (!(lv = _lv_from_lvid(cmd, lvid)))
return 0;
if (!lv_active(lv))
lv_activate(lv);
return 1;
}

View File

@ -42,6 +42,8 @@ int lv_rename(const char *old_name, struct logical_volume *lv);
*/
int lv_suspend_if_active(struct cmd_context *cmd, const char *lvid);
int lv_resume_if_active(struct cmd_context *cmd, const char *lvid);
int lv_activate_if_inactive(struct cmd_context *cmd, const char *lvid);
int lv_deactivate_if_active(struct cmd_context *cmd, const char *lvid);
/*

View File

@ -57,28 +57,28 @@ struct dev_manager {
/*
* Device layer names are all of the form <vg>:<lv>:<layer>, any
* other colons that appear in these names are quoted with yet
* another colon. The top layer of any device is always called
* 'top'. eg, vg0:lvol0:top.
* Device layer names are all of the form <vg>-<lv>-<layer>, any
* other hyphens that appear in these names are quoted with yet
* another hyphen. The top layer of any device is always called
* 'top'. eg, vg0-lvol0-top.
*/
static void _count_colons(const char *str, size_t *len, int *colons)
static void _count_hyphens(const char *str, size_t *len, int *hyphens)
{
const char *ptr;
for (ptr = str; *ptr; ptr++, (*len)++)
if (*ptr == ':')
(*colons)++;
if (*ptr == '-')
(*hyphens)++;
}
/*
* Copies a string, quoting colons with colons.
* Copies a string, quoting hyphens with hyphens.
*/
static void _quote_colons(char **out, const char *src)
static void _quote_hyphens(char **out, const char *src)
{
while (*src) {
if (*src == ':')
*(*out)++ = ':';
if (*src == '-')
*(*out)++ = '-';
*(*out)++ = *src++;
}
@ -88,14 +88,14 @@ static char *_build_name(struct pool *mem, const char *vg,
const char *lv, const char *layer)
{
size_t len = 0;
int colons = 0;
int hyphens = 0;
char *r, *out;
_count_colons(vg, &len, &colons);
_count_colons(lv, &len, &colons);
_count_colons(layer, &len, &colons);
_count_hyphens(vg, &len, &hyphens);
_count_hyphens(lv, &len, &hyphens);
_count_hyphens(layer, &len, &hyphens);
len += colons + 2;
len += hyphens + 2;
if (!(r = pool_alloc(mem, len))) {
stack;
@ -103,9 +103,9 @@ static char *_build_name(struct pool *mem, const char *vg,
}
out = r;
_quote_colons(&out, vg); *out++ = ':';
_quote_colons(&out, lv); *out++ = ':';
_quote_colons(&out, layer); *out = '\0';
_quote_hyphens(&out, vg); *out++ = '-';
_quote_hyphens(&out, lv); *out++ = '-';
_quote_hyphens(&out, layer); *out = '\0';
return r;
}
@ -133,7 +133,7 @@ static int _load(struct dev_manager *dm, struct dev_layer *dl, int task)
int r;
struct dm_task *dmt;
log_very_verbose("Creating %s.", dl->name);
log_very_verbose("Loading %s", dl->name);
if (!(dmt = _setup_task(dl->name, task))) {
stack;
return 0;
@ -148,7 +148,7 @@ static int _load(struct dev_manager *dm, struct dev_layer *dl, int task)
}
if (!(r = dm_task_run(dmt)))
log_err("Couldn't create device '%s'.", dl->name);
log_err("Couldn't load device '%s'.", dl->name);
dm_task_destroy(dmt);
if (dl->visible)
@ -162,7 +162,7 @@ static int _remove(struct dev_layer *dl)
int r;
struct dm_task *dmt;
log_very_verbose("Removing device '%s'.", dl->name);
log_very_verbose("Removing %s", dl->name);
if (!(dmt = _setup_task(dl->name, DM_DEVICE_REMOVE))) {
stack;
return 0;

View File

@ -166,10 +166,18 @@ int lock_resource(struct cmd_context *cmd, const char *resource, int flags)
if (!lv_resume_if_active(cmd, resource))
return 0;
break;
case LCK_READ:
if (!lv_activate_if_inactive(cmd, resource))
return 0;
break;
case LCK_WRITE:
if (!lv_suspend_if_active(cmd, resource))
return 0;
break;
case LCK_EXCL:
if (!lv_deactivate_if_active(cmd, resource))
return 0;
break;
default:
break;
}

View File

@ -20,7 +20,9 @@ void fin_locking(void);
*
* LCK_LV:
* Lock/unlock an individual logical volume
* Also suspends/resumes the LV if it's active.
* If it's active, LCK_WRITE suspends it; LCK_EXCLUSIVE deactivates it;
* LCK_NONE unsuspends it.
* LCK_READ activates it.
* char *vol holds "VG_name/LV_uuid"
*
* FIXME: Change to something like
@ -35,6 +37,7 @@ int lock_vol(struct cmd_context *cmd, const char *vol, int flags);
#define LCK_NONE 0x00000000
#define LCK_READ 0x00000001
#define LCK_WRITE 0x00000002
#define LCK_EXCL 0x00000003
/*
* Lock scope
@ -48,3 +51,15 @@ int lock_vol(struct cmd_context *cmd, const char *vol, int flags);
*/
#define LCK_NONBLOCK 0x00010000
/*
* Common combinations
*/
#define LCK_VG_READ (LCK_VG | LCK_READ)
#define LCK_VG_WRITE (LCK_VG | LCK_WRITE)
#define LCK_VG_UNLOCK (LCK_VG | LCK_NONE)
#define LCK_LV_DEACTIVATE (LCK_LV | LCK_EXCL)
#define LCK_LV_SUSPEND (LCK_LV | LCK_WRITE)
#define LCK_LV_ACTIVATE (LCK_LV | LCK_READ)
#define LCK_LV_UNLOCK (LCK_LV | LCK_NONE)

View File

@ -155,7 +155,7 @@ static int lvchange_permission(struct cmd_context *cmd,
if (!lvid(lv, lvidbuf, sizeof(lvidbuf)))
return 0;
if (!lock_vol(cmd, lvidbuf, LCK_LV | LCK_WRITE)) {
if (!lock_vol(cmd, lvidbuf, LCK_LV_SUSPEND)) {
log_error("Failed to lock %s", lv->name);
return 0;
}
@ -163,14 +163,14 @@ static int lvchange_permission(struct cmd_context *cmd,
log_very_verbose("Updating logical volume \"%s\" on disk(s)", lv->name);
if (!cmd->fid->ops->vg_write(cmd->fid, lv->vg)) {
/* FIXME: Attempt reversion? */
lock_vol(cmd, lvidbuf, LCK_LV | LCK_NONE);
lock_vol(cmd, lvidbuf, LCK_LV_UNLOCK);
return 0;
}
backup(lv->vg);
log_very_verbose("Updating permissions for \"%s\" in kernel", lv->name);
if (!lock_vol(cmd, lvidbuf, LCK_LV | LCK_NONE)) {
if (!lock_vol(cmd, lvidbuf, LCK_LV_UNLOCK)) {
log_error("Problem reactivating %s", lv->name);
return 0;
}
@ -183,6 +183,7 @@ static int lvchange_availability(struct cmd_context *cmd,
{
int activate = 0;
int active;
char lvidbuf[128];
if (strcmp(arg_str_value(cmd, available_ARG, "n"), "n"))
activate = 1;
@ -215,16 +216,21 @@ static int lvchange_availability(struct cmd_context *cmd,
return 1;
}
if (!lvid(lv, lvidbuf, sizeof(lvidbuf)))
return 0;
if (activate) {
log_verbose("Activating logical volume \"%s\"", lv->name);
if (!lv_activate(lv))
if (!lock_vol(cmd, lvidbuf, LCK_LV_ACTIVATE))
return 0;
} else {
log_verbose("Deactivating logical volume \"%s\"", lv->name);
if (!lv_deactivate(lv))
if (!lock_vol(cmd, lvidbuf, LCK_LV_DEACTIVATE))
return 0;
}
lock_vol(cmd, lvidbuf, LCK_LV_UNLOCK);
return 1;
}
@ -272,7 +278,7 @@ static int lvchange_contiguous(struct cmd_context *cmd,
if (!lvid(lv, lvidbuf, sizeof(lvidbuf)))
return 0;
if (!lock_vol(cmd, lvidbuf, LCK_LV | LCK_WRITE)) {
if (!lock_vol(cmd, lvidbuf, LCK_LV_SUSPEND)) {
log_error("Failed to lock %s", lv->name);
return 0;
}
@ -280,14 +286,14 @@ static int lvchange_contiguous(struct cmd_context *cmd,
log_very_verbose("Updating logical volume \"%s\" on disk(s)", lv->name);
if (!cmd->fid->ops->vg_write(cmd->fid, lv->vg)) {
/* FIXME: Attempt reversion? */
lock_vol(cmd, lvidbuf, LCK_LV | LCK_NONE);
lock_vol(cmd, lvidbuf, LCK_LV_UNLOCK);
return 0;
}
backup(lv->vg);
log_very_verbose("Reactivating \"%s\" in kernel", lv->name);
if (!lock_vol(cmd, lvidbuf, LCK_LV | LCK_NONE)) {
if (!lock_vol(cmd, lvidbuf, LCK_LV_UNLOCK)) {
log_error("Problem reactivating %s", lv->name);
return 0;
}
@ -325,7 +331,7 @@ static int lvchange_readahead(struct cmd_context *cmd,
if (!lvid(lv, lvidbuf, sizeof(lvidbuf)))
return 0;
if (!lock_vol(cmd, lvidbuf, LCK_LV | LCK_WRITE)) {
if (!lock_vol(cmd, lvidbuf, LCK_LV_SUSPEND)) {
log_error("Failed to lock %s", lv->name);
return 0;
}
@ -333,14 +339,14 @@ static int lvchange_readahead(struct cmd_context *cmd,
log_very_verbose("Updating logical volume \"%s\" on disk(s)", lv->name);
if (!cmd->fid->ops->vg_write(cmd->fid, lv->vg)) {
/* FIXME: Attempt reversion? */
lock_vol(cmd, lvidbuf, LCK_LV | LCK_NONE);
lock_vol(cmd, lvidbuf, LCK_LV_UNLOCK);
return 0;
}
backup(lv->vg);
log_very_verbose("Reactivating \"%s\" in kernel", lv->name);
if (!lock_vol(cmd, lvidbuf, LCK_LV | LCK_NONE)) {
if (!lock_vol(cmd, lvidbuf, LCK_LV_UNLOCK)) {
log_error("Problem reactivating %s", lv->name);
return 0;
}
@ -380,7 +386,7 @@ static int lvchange_persistent(struct cmd_context *cmd,
if (!lvid(lv, lvidbuf, sizeof(lvidbuf)))
return 0;
if (!lock_vol(cmd, lvidbuf, LCK_LV | LCK_WRITE)) {
if (!lock_vol(cmd, lvidbuf, LCK_LV_SUSPEND)) {
log_error("Failed to lock %s", lv->name);
return 0;
}
@ -388,14 +394,14 @@ static int lvchange_persistent(struct cmd_context *cmd,
log_very_verbose("Updating logical volume \"%s\" on disk(s)", lv->name);
if (!cmd->fid->ops->vg_write(cmd->fid, lv->vg)) {
/* FIXME: Attempt reversion? */
lock_vol(cmd, lvidbuf, LCK_LV | LCK_NONE);
lock_vol(cmd, lvidbuf, LCK_LV_UNLOCK);
return 0;
}
backup(lv->vg);
log_very_verbose("Reactivating \"%s\" in kernel", lv->name);
if (!lock_vol(cmd, lvidbuf, LCK_LV | LCK_NONE)) {
if (!lock_vol(cmd, lvidbuf, LCK_LV_UNLOCK)) {
log_error("Problem reactivating %s", lv->name);
return 0;
}

View File

@ -431,13 +431,14 @@ int lvcreate(struct cmd_context *cmd, int argc, char **argv)
int r = ECMD_FAILED;
struct lvcreate_params lp;
struct logical_volume *lv;
char lvidbuf[128];
memset(&lp, 0, sizeof(lp));
if (!_read_params(&lp, cmd, argc, argv))
return -EINVALID_CMD_LINE;
if (!lock_vol(cmd, lp.vg_name, LCK_VG | LCK_WRITE)) {
if (!lock_vol(cmd, lp.vg_name, LCK_VG_WRITE)) {
log_error("Can't get lock for %s", lp.vg_name);
return 0;
}
@ -447,12 +448,15 @@ int lvcreate(struct cmd_context *cmd, int argc, char **argv)
goto out;
}
if (!lp.snapshot && !lv_setup_cow_store(lv)) {
if (lp.snapshot && !lv_setup_cow_store(lv)) {
stack;
goto out;
}
if (!lv_activate(lv))
if (!lvid(lv, lvidbuf, sizeof(lvidbuf)))
return 0;
if (!lock_vol(cmd, lvidbuf, LCK_LV_ACTIVATE))
goto out;
if (!lp.snapshot) {
@ -461,7 +465,7 @@ int lvcreate(struct cmd_context *cmd, int argc, char **argv)
else if (!_zero(cmd, lv)) {
stack;
goto out;
goto out_lv;
}
}
@ -472,7 +476,9 @@ int lvcreate(struct cmd_context *cmd, int argc, char **argv)
r = 0;
out_lv:
lock_vol(cmd, lp.vg_name, LCK_LV_UNLOCK);
out:
lock_vol(cmd, lp.vg_name, LCK_VG | LCK_NONE);
lock_vol(cmd, lp.vg_name, LCK_VG_UNLOCK);
return r;
}

View File

@ -36,6 +36,7 @@ static int lvremove_single(struct cmd_context *cmd, struct logical_volume *lv)
{
struct volume_group *vg;
int active;
char lvidbuf[128];
vg = lv->vg;
@ -67,12 +68,16 @@ static int lvremove_single(struct cmd_context *cmd, struct logical_volume *lv)
}
}
if (!lvid(lv, lvidbuf, sizeof(lvidbuf)))
return 0;
if (!archive(vg))
return ECMD_FAILED;
if (active && !lv_deactivate(lv)) {
if (!lock_vol(cmd, lvidbuf, LCK_LV_DEACTIVATE)) {
log_error("Unable to deactivate logical volume \"%s\"",
lv->name);
return ECMD_FAILED;
}
log_verbose("Removing snapshot.");
@ -93,6 +98,8 @@ static int lvremove_single(struct cmd_context *cmd, struct logical_volume *lv)
backup(vg);
log_print("logical volume \"%s\" successfully removed", lv->name);
lock_vol(cmd, lvidbuf, LCK_LV_UNLOCK);
log_print("Logical volume \"%s\" successfully removed", lv->name);
return 0;
}

View File

@ -87,7 +87,7 @@ int lvrename(struct cmd_context *cmd, int argc, char **argv)
log_verbose("Checking for existing volume group \"%s\"", vg_name);
if (!lock_vol(cmd, vg_name, LCK_VG | LCK_WRITE)) {
if (!lock_vol(cmd, vg_name, LCK_VG_WRITE)) {
log_error("Can't get lock for %s", vg_name);
return ECMD_FAILED;
}
@ -152,7 +152,7 @@ int lvrename(struct cmd_context *cmd, int argc, char **argv)
backup(lv->vg);
lock_vol(cmd, vg_name, LCK_VG | LCK_NONE);
lock_vol(cmd, vg_name, LCK_VG_UNLOCK);
log_print("Renamed \"%s\" to \"%s\" in volume group \"%s\"",
lv_name_old, lv_name_new, vg_name);
@ -160,6 +160,6 @@ int lvrename(struct cmd_context *cmd, int argc, char **argv)
return 0;
error:
lock_vol(cmd, vg_name, LCK_VG | LCK_NONE);
lock_vol(cmd, vg_name, LCK_VG_UNLOCK);
return ECMD_FAILED;
}

View File

@ -105,7 +105,7 @@ int lvresize(struct cmd_context *cmd, int argc, char **argv)
/* does VG exist? */
log_verbose("Finding volume group %s", vg_name);
if (!lock_vol(cmd, vg_name, LCK_VG | LCK_WRITE)) {
if (!lock_vol(cmd, vg_name, LCK_VG_WRITE)) {
log_error("Can't get lock for %s", vg_name);
return ECMD_FAILED;
}
@ -335,7 +335,7 @@ int lvresize(struct cmd_context *cmd, int argc, char **argv)
if (!lvid(lv, lvidbuf, sizeof(lvidbuf)))
goto error;
if (!lock_vol(cmd, lvidbuf, LCK_LV | LCK_WRITE)) {
if (!lock_vol(cmd, lvidbuf, LCK_LV_SUSPEND)) {
log_error("Can't get lock for %s", lv_name);
goto error;
}
@ -343,28 +343,28 @@ int lvresize(struct cmd_context *cmd, int argc, char **argv)
/* store vg on disk(s) */
if (!cmd->fid->ops->vg_write(cmd->fid, vg)) {
/* FIXME: Attempt reversion? */
lock_vol(cmd, lvidbuf, LCK_LV | LCK_NONE);
lock_vol(cmd, lvidbuf, LCK_LV_UNLOCK);
goto error;
}
backup(vg);
if (!lock_vol(cmd, lvidbuf, LCK_LV | LCK_NONE)) {
if (!lock_vol(cmd, lvidbuf, LCK_LV_UNLOCK)) {
log_error("Problem reactivating %s", lv_name);
goto error;
}
lock_vol(cmd, vg_name, LCK_VG | LCK_NONE);
lock_vol(cmd, vg_name, LCK_VG_UNLOCK);
log_print("Logical volume %s successfully resized", lv_name);
return 0;
error:
lock_vol(cmd, vg_name, LCK_VG | LCK_NONE);
lock_vol(cmd, vg_name, LCK_VG_UNLOCK);
return ECMD_FAILED;
error_cmdline:
lock_vol(cmd, vg_name, LCK_VG | LCK_NONE);
lock_vol(cmd, vg_name, LCK_VG_UNLOCK);
return EINVALID_CMD_LINE;
}

View File

@ -98,32 +98,32 @@ int pvchange_single(struct cmd_context *cmd, struct physical_volume *pv)
log_verbose("Finding volume group of physical volume \"%s\"",
pv_name);
if (!lock_vol(cmd, pv->vg_name, LCK_VG | LCK_WRITE)) {
if (!lock_vol(cmd, pv->vg_name, LCK_VG_WRITE)) {
log_error("Can't get lock for %s", pv->vg_name);
return ECMD_FAILED;
}
if (!(vg = cmd->fid->ops->vg_read(cmd->fid, pv->vg_name))) {
lock_vol(cmd, pv->vg_name, LCK_VG | LCK_NONE);
lock_vol(cmd, pv->vg_name, LCK_VG_UNLOCK);
log_error("Unable to find volume group of \"%s\"",
pv_name);
return 0;
}
if (vg->status & EXPORTED_VG) {
lock_vol(cmd, pv->vg_name, LCK_VG | LCK_NONE);
lock_vol(cmd, pv->vg_name, LCK_VG_UNLOCK);
log_error("Volume group \"%s\" is exported", vg->name);
return ECMD_FAILED;
}
if (!(vg->status & LVM_WRITE)) {
lock_vol(cmd, pv->vg_name, LCK_VG | LCK_NONE);
lock_vol(cmd, pv->vg_name, LCK_VG_UNLOCK);
log_error("Volume group \"%s\" is read-only", vg->name);
return ECMD_FAILED;
}
if (!(pvl = find_pv_in_vg(vg, pv_name))) {
lock_vol(cmd, pv->vg_name, LCK_VG | LCK_NONE);
lock_vol(cmd, pv->vg_name, LCK_VG_UNLOCK);
log_error
("Unable to find \"%s\" in volume group \"%s\"",
pv_name, vg->name);
@ -139,7 +139,7 @@ int pvchange_single(struct cmd_context *cmd, struct physical_volume *pv)
log_error("Physical volume \"%s\" is already allocatable",
pv_name);
if (*pv->vg_name)
lock_vol(cmd, pv->vg_name, LCK_VG | LCK_NONE);
lock_vol(cmd, pv->vg_name, LCK_VG_UNLOCK);
return 0;
}
@ -147,7 +147,7 @@ int pvchange_single(struct cmd_context *cmd, struct physical_volume *pv)
log_error("Physical volume \"%s\" is already unallocatable",
pv_name);
if (*pv->vg_name)
lock_vol(cmd, pv->vg_name, LCK_VG | LCK_NONE);
lock_vol(cmd, pv->vg_name, LCK_VG_UNLOCK);
return 0;
}
@ -164,13 +164,13 @@ int pvchange_single(struct cmd_context *cmd, struct physical_volume *pv)
log_verbose("Updating physical volume \"%s\"", pv_name);
if (*pv->vg_name) {
if (!(cmd->fid->ops->vg_write(cmd->fid, vg))) {
lock_vol(cmd, pv->vg_name, LCK_VG | LCK_NONE);
lock_vol(cmd, pv->vg_name, LCK_VG_UNLOCK);
log_error("Failed to store physical volume \"%s\" in "
"volume group \"%s\"", pv_name, vg->name);
return 0;
}
backup(vg);
lock_vol(cmd, pv->vg_name, LCK_VG | LCK_NONE);
lock_vol(cmd, pv->vg_name, LCK_VG_UNLOCK);
} else {
if (!(cmd->fid->ops->pv_write(cmd->fid, pv))) {
log_error("Failed to store physical volume \"%s\"",

View File

@ -140,7 +140,7 @@ int process_each_vg(struct cmd_context *cmd, int argc, char **argv,
}
if ((ret = process_single(cmd, vg_name)) > ret_max)
ret_max = ret;
lock_vol(cmd, (void *) vg_name, LCK_VG | LCK_NONE);
lock_vol(cmd, (void *) vg_name, LCK_VG_UNLOCK);
}
} else {
log_verbose("Finding all volume groups");
@ -158,7 +158,7 @@ int process_each_vg(struct cmd_context *cmd, int argc, char **argv,
if (ret > ret_max)
ret_max = ret;
lock_vol(cmd, (void *) vg_name, LCK_VG | LCK_NONE);
lock_vol(cmd, (void *) vg_name, LCK_VG_UNLOCK);
}
}

View File

@ -92,32 +92,32 @@ int vgcreate(struct cmd_context *cmd, int argc, char **argv)
log_error("Warning: Setting maxphysicalvolumes to %d",
vg->max_pv);
if (!lock_vol(cmd, "", LCK_VG | LCK_WRITE)) {
if (!lock_vol(cmd, "", LCK_VG_WRITE)) {
log_error("Can't get lock for orphan PVs");
return ECMD_FAILED;
}
if (!lock_vol(cmd, vg_name, LCK_VG | LCK_WRITE | LCK_NONBLOCK)) {
if (!lock_vol(cmd, vg_name, LCK_VG_WRITE | LCK_NONBLOCK)) {
log_error("Can't get lock for %s", vg_name);
lock_vol(cmd, "", LCK_VG | LCK_NONE);
lock_vol(cmd, "", LCK_VG_UNLOCK);
return ECMD_FAILED;
}
if (!archive(vg)) {
lock_vol(cmd, vg_name, LCK_VG | LCK_NONE);
lock_vol(cmd, "", LCK_VG | LCK_NONE);
lock_vol(cmd, vg_name, LCK_VG_UNLOCK);
lock_vol(cmd, "", LCK_VG_UNLOCK);
return ECMD_FAILED;
}
/* Store VG on disk(s) */
if (!cmd->fid->ops->vg_write(cmd->fid, vg)) {
lock_vol(cmd, vg_name, LCK_VG | LCK_NONE);
lock_vol(cmd, "", LCK_VG | LCK_NONE);
lock_vol(cmd, vg_name, LCK_VG_UNLOCK);
lock_vol(cmd, "", LCK_VG_UNLOCK);
return ECMD_FAILED;
}
lock_vol(cmd, vg_name, LCK_VG | LCK_NONE);
lock_vol(cmd, "", LCK_VG | LCK_NONE);
lock_vol(cmd, vg_name, LCK_VG_UNLOCK);
lock_vol(cmd, "", LCK_VG_UNLOCK);
backup(vg);

View File

@ -40,14 +40,14 @@ int vgextend(struct cmd_context *cmd, int argc, char **argv)
argc--;
argv++;
if (!lock_vol(cmd, "", LCK_VG | LCK_WRITE)) {
if (!lock_vol(cmd, "", LCK_VG_WRITE)) {
log_error("Can't get lock for orphan PVs");
return ECMD_FAILED;
}
log_verbose("Checking for volume group \"%s\"", vg_name);
if (!lock_vol(cmd, vg_name, LCK_VG | LCK_WRITE | LCK_NONBLOCK)) {
lock_vol(cmd, "", LCK_VG | LCK_NONE);
if (!lock_vol(cmd, vg_name, LCK_VG_WRITE | LCK_NONBLOCK)) {
lock_vol(cmd, "", LCK_VG_UNLOCK);
log_error("Can't get lock for %s", vg_name);
goto error;
}
@ -96,15 +96,15 @@ int vgextend(struct cmd_context *cmd, int argc, char **argv)
backup(vg);
lock_vol(cmd, vg_name, LCK_VG | LCK_NONE);
lock_vol(cmd, "", LCK_VG | LCK_NONE);
lock_vol(cmd, vg_name, LCK_VG_UNLOCK);
lock_vol(cmd, "", LCK_VG_UNLOCK);
log_print("Volume group \"%s\" successfully extended", vg_name);
return 0;
error:
lock_vol(cmd, vg_name, LCK_VG | LCK_NONE);
lock_vol(cmd, "", LCK_VG | LCK_NONE);
lock_vol(cmd, vg_name, LCK_VG_UNLOCK);
lock_vol(cmd, "", LCK_VG_UNLOCK);
return ECMD_FAILED;
}

View File

@ -60,33 +60,33 @@ int vgmerge_single(struct cmd_context *cmd, const char *vg_name_to,
}
log_verbose("Checking for volume group \"%s\"", vg_name_to);
if (!lock_vol(cmd, vg_name_to, LCK_VG | LCK_WRITE)) {
if (!lock_vol(cmd, vg_name_to, LCK_VG_WRITE)) {
log_error("Can't get lock for %s", vg_name_to);
return ECMD_FAILED;
}
if (!(vg_to = cmd->fid->ops->vg_read(cmd->fid, vg_name_to))) {
log_error("Volume group \"%s\" doesn't exist", vg_name_to);
lock_vol(cmd, vg_name_to, LCK_VG | LCK_NONE);
lock_vol(cmd, vg_name_to, LCK_VG_UNLOCK);
return ECMD_FAILED;
}
if (vg_to->status & EXPORTED_VG) {
log_error("Volume group \"%s\" is exported", vg_to->name);
lock_vol(cmd, vg_name_to, LCK_VG | LCK_NONE);
lock_vol(cmd, vg_name_to, LCK_VG_UNLOCK);
return ECMD_FAILED;
}
if (!(vg_to->status & LVM_WRITE)) {
log_error("Volume group \"%s\" is read-only", vg_to->name);
lock_vol(cmd, vg_name_to, LCK_VG | LCK_NONE);
lock_vol(cmd, vg_name_to, LCK_VG_UNLOCK);
return ECMD_FAILED;
}
log_verbose("Checking for volume group \"%s\"", vg_name_from);
if (!lock_vol(cmd, vg_name_from, LCK_VG | LCK_WRITE | LCK_NONBLOCK)) {
if (!lock_vol(cmd, vg_name_from, LCK_VG_WRITE | LCK_NONBLOCK)) {
log_error("Can't get lock for %s", vg_name_from);
lock_vol(cmd, vg_name_to, LCK_VG | LCK_NONE);
lock_vol(cmd, vg_name_to, LCK_VG_UNLOCK);
return ECMD_FAILED;
}
@ -190,15 +190,15 @@ int vgmerge_single(struct cmd_context *cmd, const char *vg_name_to,
backup(vg_to);
lock_vol(cmd, vg_name_from, LCK_VG | LCK_NONE);
lock_vol(cmd, vg_name_to, LCK_VG | LCK_NONE);
lock_vol(cmd, vg_name_from, LCK_VG_UNLOCK);
lock_vol(cmd, vg_name_to, LCK_VG_UNLOCK);
log_print("Volume group \"%s\" successfully merged into \"%s\"",
vg_from->name, vg_to->name);
return 0;
error:
lock_vol(cmd, vg_name_from, LCK_VG | LCK_NONE);
lock_vol(cmd, vg_name_to, LCK_VG | LCK_NONE);
lock_vol(cmd, vg_name_from, LCK_VG_UNLOCK);
lock_vol(cmd, vg_name_to, LCK_VG_UNLOCK);
return ECMD_FAILED;
}

View File

@ -51,32 +51,32 @@ int vgreduce(struct cmd_context *cmd, int argc, char **argv)
argc--;
log_verbose("Finding volume group \"%s\"", vg_name);
if (!lock_vol(cmd, vg_name, LCK_VG | LCK_WRITE)) {
if (!lock_vol(cmd, vg_name, LCK_VG_WRITE)) {
log_error("Can't get lock for %s", vg_name);
return ECMD_FAILED;
}
if (!(vg = cmd->fid->ops->vg_read(cmd->fid, vg_name))) {
log_error("Volume group \"%s\" doesn't exist", vg_name);
lock_vol(cmd, vg_name, LCK_VG | LCK_NONE);
lock_vol(cmd, vg_name, LCK_VG_UNLOCK);
return ECMD_FAILED;
}
if (vg->status & EXPORTED_VG) {
log_error("Volume group \"%s\" is exported", vg->name);
lock_vol(cmd, vg_name, LCK_VG | LCK_NONE);
lock_vol(cmd, vg_name, LCK_VG_UNLOCK);
return ECMD_FAILED;
}
if (!(vg->status & LVM_WRITE)) {
log_error("Volume group \"%s\" is read-only", vg_name);
lock_vol(cmd, vg_name, LCK_VG | LCK_NONE);
lock_vol(cmd, vg_name, LCK_VG_UNLOCK);
return ECMD_FAILED;
}
if (!(vg->status & RESIZEABLE_VG)) {
log_error("Volume group \"%s\" is not reducable", vg_name);
lock_vol(cmd, vg_name, LCK_VG | LCK_NONE);
lock_vol(cmd, vg_name, LCK_VG_UNLOCK);
return ECMD_FAILED;
}
@ -84,7 +84,7 @@ int vgreduce(struct cmd_context *cmd, int argc, char **argv)
/* and update in batch here? */
ret = process_each_pv(cmd, argc, argv, vg, vgreduce_single);
lock_vol(cmd, vg_name, LCK_VG | LCK_NONE);
lock_vol(cmd, vg_name, LCK_VG_UNLOCK);
return ret;

View File

@ -26,7 +26,7 @@ int vgremove(struct cmd_context *cmd, int argc, char **argv)
{
int ret;
if (!lock_vol(cmd, "", LCK_VG | LCK_WRITE)) {
if (!lock_vol(cmd, "", LCK_VG_WRITE)) {
log_error("Can't get lock for orphan PVs");
return ECMD_FAILED;
}
@ -34,7 +34,7 @@ int vgremove(struct cmd_context *cmd, int argc, char **argv)
ret = process_each_vg(cmd, argc, argv, LCK_WRITE | LCK_NONBLOCK,
&vgremove_single);
lock_vol(cmd, "", LCK_VG | LCK_NONE);
lock_vol(cmd, "", LCK_VG_UNLOCK);
return ret;
}

View File

@ -69,25 +69,25 @@ int vgrename(struct cmd_context *cmd, int argc, char **argv)
log_verbose("Checking for existing volume group \"%s\"", vg_name_old);
if (!lock_vol(cmd, vg_name_old, LCK_VG | LCK_WRITE)) {
if (!lock_vol(cmd, vg_name_old, LCK_VG_WRITE)) {
log_error("Can't get lock for %s", vg_name_old);
return ECMD_FAILED;
}
if (!(vg_old = cmd->fid->ops->vg_read(cmd->fid, vg_name_old))) {
log_error("Volume group \"%s\" doesn't exist", vg_name_old);
lock_vol(cmd, vg_name_old, LCK_VG | LCK_NONE);
lock_vol(cmd, vg_name_old, LCK_VG_UNLOCK);
return ECMD_FAILED;
}
if (vg_old->status & EXPORTED_VG) {
lock_vol(cmd, vg_name_old, LCK_VG | LCK_NONE);
lock_vol(cmd, vg_name_old, LCK_VG_UNLOCK);
log_error("Volume group \"%s\" is exported", vg_old->name);
return ECMD_FAILED;
}
if (!(vg_old->status & LVM_WRITE)) {
lock_vol(cmd, vg_name_old, LCK_VG | LCK_NONE);
lock_vol(cmd, vg_name_old, LCK_VG_UNLOCK);
log_error("Volume group \"%s\" is read-only", vg_old->name);
return ECMD_FAILED;
}
@ -98,7 +98,7 @@ int vgrename(struct cmd_context *cmd, int argc, char **argv)
/***** FIXME Handle this with multiple LV renames!
if (!force_ARG) {
log_error("Use -f to force the rename");
lock_vol(cmd, vg_name_old, LCK_VG | LCK_NONE);
lock_vol(cmd, vg_name_old, LCK_VG_UNLOCK);
return ECMD_FAILED;
}
*****/
@ -106,8 +106,8 @@ int vgrename(struct cmd_context *cmd, int argc, char **argv)
log_verbose("Checking for new volume group \"%s\"", vg_name_new);
if (!lock_vol(cmd, vg_name_new, LCK_VG | LCK_WRITE | LCK_NONBLOCK)) {
lock_vol(cmd, vg_name_old, LCK_VG | LCK_NONE);
if (!lock_vol(cmd, vg_name_new, LCK_VG_WRITE | LCK_NONBLOCK)) {
lock_vol(cmd, vg_name_old, LCK_VG_UNLOCK);
log_error("Can't get lock for %s", vg_name_new);
return ECMD_FAILED;
}
@ -158,8 +158,8 @@ int vgrename(struct cmd_context *cmd, int argc, char **argv)
backup(vg_old);
lock_vol(cmd, vg_name_new, LCK_VG | LCK_NONE);
lock_vol(cmd, vg_name_old, LCK_VG | LCK_NONE);
lock_vol(cmd, vg_name_new, LCK_VG_UNLOCK);
lock_vol(cmd, vg_name_old, LCK_VG_UNLOCK);
log_print("Volume group \"%s\" successfully renamed to \"%s\"",
vg_name_old, vg_name_new);
@ -167,8 +167,8 @@ int vgrename(struct cmd_context *cmd, int argc, char **argv)
return 0;
error:
lock_vol(cmd, vg_name_new, LCK_VG | LCK_NONE);
lock_vol(cmd, vg_name_old, LCK_VG | LCK_NONE);
lock_vol(cmd, vg_name_new, LCK_VG_UNLOCK);
lock_vol(cmd, vg_name_old, LCK_VG_UNLOCK);
return ECMD_FAILED;
}