mirror of
git://sourceware.org/git/lvm2.git
synced 2024-12-21 13:34:40 +03:00
Revise internal locking semantics.
This commit is contained in:
parent
5668c1abad
commit
23289e6d14
@ -1,5 +1,7 @@
|
|||||||
Version 2.00.16 -
|
Version 2.00.16 -
|
||||||
=============================
|
=============================
|
||||||
|
Revise internal locking semantics.
|
||||||
|
Move find_pv_by_name to library.
|
||||||
Rename move->copy.
|
Rename move->copy.
|
||||||
Add devices to segments report.
|
Add devices to segments report.
|
||||||
Begin separating out segment code. There's a lot of change here.
|
Begin separating out segment code. There's a lot of change here.
|
||||||
|
@ -232,9 +232,14 @@ static int _file_lock_resource(struct cmd_context *cmd, const char *resource,
|
|||||||
if (!lv_resume_if_active(cmd, resource))
|
if (!lv_resume_if_active(cmd, resource))
|
||||||
return 0;
|
return 0;
|
||||||
break;
|
break;
|
||||||
|
case LCK_NULL:
|
||||||
|
log_debug("Locking LV %s (NL)", resource);
|
||||||
|
if (!lv_deactivate(cmd, resource))
|
||||||
|
return 0;
|
||||||
|
break;
|
||||||
case LCK_READ:
|
case LCK_READ:
|
||||||
log_debug("Locking LV %s (R)", resource);
|
log_debug("Locking LV %s (R)", resource);
|
||||||
if (!lv_activate(cmd, resource))
|
if (!lv_activate_with_filter(cmd, resource))
|
||||||
return 0;
|
return 0;
|
||||||
break;
|
break;
|
||||||
case LCK_WRITE:
|
case LCK_WRITE:
|
||||||
@ -244,7 +249,7 @@ static int _file_lock_resource(struct cmd_context *cmd, const char *resource,
|
|||||||
break;
|
break;
|
||||||
case LCK_EXCL:
|
case LCK_EXCL:
|
||||||
log_debug("Locking LV %s (EX)", resource);
|
log_debug("Locking LV %s (EX)", resource);
|
||||||
if (!lv_deactivate(cmd, resource))
|
if (!lv_activate_with_filter(cmd, resource))
|
||||||
return 0;
|
return 0;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
|
@ -252,32 +252,54 @@ int lock_vol(struct cmd_context *cmd, const char *vol, int flags)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Unlock list of LVs */
|
/* Unlock list of LVs */
|
||||||
int unlock_lvs(struct cmd_context *cmd, struct list *lvs)
|
int resume_lvs(struct cmd_context *cmd, struct list *lvs)
|
||||||
{
|
{
|
||||||
struct list *lvh;
|
struct list *lvh;
|
||||||
struct logical_volume *lv;
|
struct logical_volume *lv;
|
||||||
|
|
||||||
list_iterate(lvh, lvs) {
|
list_iterate(lvh, lvs) {
|
||||||
lv = list_item(lvh, struct lv_list)->lv;
|
lv = list_item(lvh, struct lv_list)->lv;
|
||||||
unlock_lv(cmd, lv->lvid.s);
|
resume_lv(cmd, lv->lvid.s);
|
||||||
}
|
}
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Lock a list of LVs */
|
/* Lock a list of LVs */
|
||||||
int lock_lvs(struct cmd_context *cmd, struct list *lvs, int flags)
|
int suspend_lvs(struct cmd_context *cmd, struct list *lvs)
|
||||||
{
|
{
|
||||||
struct list *lvh;
|
struct list *lvh;
|
||||||
struct logical_volume *lv;
|
struct logical_volume *lv;
|
||||||
|
|
||||||
list_iterate(lvh, lvs) {
|
list_iterate(lvh, lvs) {
|
||||||
lv = list_item(lvh, struct lv_list)->lv;
|
lv = list_item(lvh, struct lv_list)->lv;
|
||||||
if (!lock_vol(cmd, lv->lvid.s, flags)) {
|
if (!suspend_lv(cmd, lv->lvid.s)) {
|
||||||
log_error("Failed to suspend %s", lv->name);
|
log_error("Failed to suspend %s", lv->name);
|
||||||
list_uniterate(lvh, lvs, lvh) {
|
list_uniterate(lvh, lvs, lvh) {
|
||||||
lv = list_item(lvh, struct lv_list)->lv;
|
lv = list_item(lvh, struct lv_list)->lv;
|
||||||
unlock_lv(cmd, lv->lvid.s);
|
resume_lv(cmd, lv->lvid.s);
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Lock a list of LVs */
|
||||||
|
int activate_lvs_excl(struct cmd_context *cmd, struct list *lvs)
|
||||||
|
{
|
||||||
|
struct list *lvh;
|
||||||
|
struct logical_volume *lv;
|
||||||
|
|
||||||
|
list_iterate(lvh, lvs) {
|
||||||
|
lv = list_item(lvh, struct lv_list)->lv;
|
||||||
|
if (!activate_lv_excl(cmd, lv->lvid.s)) {
|
||||||
|
log_error("Failed to activate %s", lv->name);
|
||||||
|
list_uniterate(lvh, lvs, lvh) {
|
||||||
|
lv = list_item(lvh, struct lv_list)->lv;
|
||||||
|
activate_lv(cmd, lv->lvid.s);
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -71,16 +71,23 @@ int check_lvm1_vg_inactive(struct cmd_context *cmd, const char *vgname);
|
|||||||
#define LCK_VG_WRITE (LCK_VG | LCK_WRITE | LCK_HOLD)
|
#define LCK_VG_WRITE (LCK_VG | LCK_WRITE | LCK_HOLD)
|
||||||
#define LCK_VG_UNLOCK (LCK_VG | LCK_UNLOCK)
|
#define LCK_VG_UNLOCK (LCK_VG | LCK_UNLOCK)
|
||||||
|
|
||||||
#define LCK_LV_SUSPEND (LCK_LV | LCK_WRITE)
|
#define LCK_LV_EXCLUSIVE (LCK_LV | LCK_EXCL | LCK_NONBLOCK)
|
||||||
|
#define LCK_LV_SUSPEND (LCK_LV | LCK_WRITE | LCK_NONBLOCK)
|
||||||
#define LCK_LV_RESUME (LCK_LV | LCK_UNLOCK | LCK_NONBLOCK)
|
#define LCK_LV_RESUME (LCK_LV | LCK_UNLOCK | LCK_NONBLOCK)
|
||||||
#define LCK_LV_UNLOCK (LCK_LV | LCK_UNLOCK)
|
#define LCK_LV_ACTIVATE (LCK_LV | LCK_READ | LCK_NONBLOCK)
|
||||||
#define LCK_LV_ACTIVATE (LCK_LV | LCK_READ)
|
#define LCK_LV_DEACTIVATE (LCK_LV | LCK_NULL | LCK_NONBLOCK)
|
||||||
#define LCK_LV_DEACTIVATE (LCK_LV | LCK_EXCL)
|
|
||||||
|
|
||||||
#define unlock_lv(cmd, vol) lock_vol(cmd, vol, LCK_LV_UNLOCK)
|
|
||||||
#define unlock_vg(cmd, vol) lock_vol(cmd, vol, LCK_VG_UNLOCK)
|
#define unlock_vg(cmd, vol) lock_vol(cmd, vol, LCK_VG_UNLOCK)
|
||||||
|
|
||||||
/* Process list of LVs */
|
#define resume_lv(cmd, vol) lock_vol(cmd, vol, LCK_LV_RESUME)
|
||||||
int lock_lvs(struct cmd_context *cmd, struct list *lvs, int flags);
|
#define suspend_lv(cmd, vol) lock_vol(cmd, vol, LCK_LV_SUSPEND | LCK_HOLD)
|
||||||
int unlock_lvs(struct cmd_context *cmd, struct list *lvs);
|
#define deactivate_lv(cmd, vol) lock_vol(cmd, vol, LCK_LV_DEACTIVATE)
|
||||||
|
#define activate_lv(cmd, vol) lock_vol(cmd, vol, LCK_LV_ACTIVATE | LCK_HOLD)
|
||||||
|
#define activate_lv_excl(cmd, vol) \
|
||||||
|
lock_vol(cmd, vol, LCK_LV_EXCLUSIVE | LCK_HOLD)
|
||||||
|
|
||||||
|
/* Process list of LVs */
|
||||||
|
int suspend_lvs(struct cmd_context *cmd, struct list *lvs);
|
||||||
|
int resume_lvs(struct cmd_context *cmd, struct list *lvs);
|
||||||
|
int activate_lvs_excl(struct cmd_context *cmd, struct list *lvs);
|
||||||
|
|
||||||
|
@ -53,14 +53,16 @@ static int _no_lock_resource(struct cmd_context *cmd, const char *resource,
|
|||||||
break;
|
break;
|
||||||
case LCK_LV:
|
case LCK_LV:
|
||||||
switch (flags & LCK_TYPE_MASK) {
|
switch (flags & LCK_TYPE_MASK) {
|
||||||
|
case LCK_NULL:
|
||||||
|
return lv_deactivate(cmd, resource);
|
||||||
case LCK_UNLOCK:
|
case LCK_UNLOCK:
|
||||||
return lv_resume_if_active(cmd, resource);
|
return lv_resume_if_active(cmd, resource);
|
||||||
case LCK_READ:
|
case LCK_READ:
|
||||||
return lv_activate(cmd, resource);
|
return lv_activate_with_filter(cmd, resource);
|
||||||
case LCK_WRITE:
|
case LCK_WRITE:
|
||||||
return lv_suspend_if_active(cmd, resource);
|
return lv_suspend_if_active(cmd, resource);
|
||||||
case LCK_EXCL:
|
case LCK_EXCL:
|
||||||
return lv_deactivate(cmd, resource);
|
return lv_activate_with_filter(cmd, resource);
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -52,19 +52,19 @@ static int lvchange_permission(struct cmd_context *cmd,
|
|||||||
|
|
||||||
backup(lv->vg);
|
backup(lv->vg);
|
||||||
|
|
||||||
if (!lock_vol(cmd, lv->lvid.s, LCK_LV_SUSPEND | LCK_HOLD)) {
|
if (!suspend_lv(cmd, lv->lvid.s)) {
|
||||||
log_error("Failed to lock %s", lv->name);
|
log_error("Failed to lock %s", lv->name);
|
||||||
vg_revert(lv->vg);
|
vg_revert(lv->vg);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!vg_commit(lv->vg)) {
|
if (!vg_commit(lv->vg)) {
|
||||||
unlock_lv(cmd, lv->lvid.s);
|
resume_lv(cmd, lv->lvid.s);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
log_very_verbose("Updating permissions for \"%s\" in kernel", lv->name);
|
log_very_verbose("Updating permissions for \"%s\" in kernel", lv->name);
|
||||||
if (!unlock_lv(cmd, lv->lvid.s)) {
|
if (!resume_lv(cmd, lv->lvid.s)) {
|
||||||
log_error("Problem reactivating %s", lv->name);
|
log_error("Problem reactivating %s", lv->name);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@ -84,7 +84,7 @@ static int lvchange_availability(struct cmd_context *cmd,
|
|||||||
if (activate) {
|
if (activate) {
|
||||||
/* FIXME Tighter locking if lv_is_origin() */
|
/* FIXME Tighter locking if lv_is_origin() */
|
||||||
log_verbose("Activating logical volume \"%s\"", lv->name);
|
log_verbose("Activating logical volume \"%s\"", lv->name);
|
||||||
if (!lock_vol(cmd, lv->lvid.s, LCK_LV_ACTIVATE))
|
if (!activate_lv(cmd, lv->lvid.s))
|
||||||
return 0;
|
return 0;
|
||||||
if ((lv->status & LOCKED) && (pv = get_pvmove_pv_from_lv(lv))) {
|
if ((lv->status & LOCKED) && (pv = get_pvmove_pv_from_lv(lv))) {
|
||||||
log_verbose("Spawning background pvmove process for %s",
|
log_verbose("Spawning background pvmove process for %s",
|
||||||
@ -93,8 +93,10 @@ static int lvchange_availability(struct cmd_context *cmd,
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
log_verbose("Deactivating logical volume \"%s\"", lv->name);
|
log_verbose("Deactivating logical volume \"%s\"", lv->name);
|
||||||
if (!lock_vol(cmd, lv->lvid.s, LCK_LV_DEACTIVATE))
|
if (!deactivate_lv(cmd, lv->lvid.s)) {
|
||||||
|
stack;
|
||||||
return 0;
|
return 0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
@ -103,8 +105,7 @@ static int lvchange_availability(struct cmd_context *cmd,
|
|||||||
static int lvchange_refresh(struct cmd_context *cmd, struct logical_volume *lv)
|
static int lvchange_refresh(struct cmd_context *cmd, struct logical_volume *lv)
|
||||||
{
|
{
|
||||||
log_verbose("Refreshing logical volume \"%s\" (if active)", lv->name);
|
log_verbose("Refreshing logical volume \"%s\" (if active)", lv->name);
|
||||||
if (!lock_vol(cmd, lv->lvid.s, LCK_LV_SUSPEND | LCK_HOLD) ||
|
if (!suspend_lv(cmd, lv->lvid.s) || !resume_lv(cmd, lv->lvid.s))
|
||||||
!unlock_lv(cmd, lv->lvid.s))
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
@ -199,19 +200,19 @@ static int lvchange_readahead(struct cmd_context *cmd,
|
|||||||
|
|
||||||
backup(lv->vg);
|
backup(lv->vg);
|
||||||
|
|
||||||
if (!lock_vol(cmd, lv->lvid.s, LCK_LV_SUSPEND | LCK_HOLD)) {
|
if (!suspend_lv(cmd, lv->lvid.s)) {
|
||||||
log_error("Failed to lock %s", lv->name);
|
log_error("Failed to lock %s", lv->name);
|
||||||
vg_revert(lv->vg);
|
vg_revert(lv->vg);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!vg_commit(lv->vg)) {
|
if (!vg_commit(lv->vg)) {
|
||||||
unlock_lv(cmd, lv->lvid.s);
|
resume_lv(cmd, lv->lvid.s);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
log_very_verbose("Updating permissions for \"%s\" in kernel", lv->name);
|
log_very_verbose("Updating permissions for \"%s\" in kernel", lv->name);
|
||||||
if (!unlock_lv(cmd, lv->lvid.s)) {
|
if (!resume_lv(cmd, lv->lvid.s)) {
|
||||||
log_error("Problem reactivating %s", lv->name);
|
log_error("Problem reactivating %s", lv->name);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@ -223,6 +224,7 @@ static int lvchange_persistent(struct cmd_context *cmd,
|
|||||||
struct logical_volume *lv)
|
struct logical_volume *lv)
|
||||||
{
|
{
|
||||||
struct lvinfo info;
|
struct lvinfo info;
|
||||||
|
int active = 0;
|
||||||
|
|
||||||
if (!strcmp(arg_str_value(cmd, persistent_ARG, "n"), "n")) {
|
if (!strcmp(arg_str_value(cmd, persistent_ARG, "n"), "n")) {
|
||||||
if (!(lv->status & FIXED_MINOR)) {
|
if (!(lv->status & FIXED_MINOR)) {
|
||||||
@ -247,17 +249,16 @@ static int lvchange_persistent(struct cmd_context *cmd,
|
|||||||
if (lv_info(lv, &info) && info.exists &&
|
if (lv_info(lv, &info) && info.exists &&
|
||||||
!arg_count(cmd, force_ARG)) {
|
!arg_count(cmd, force_ARG)) {
|
||||||
if (yes_no_prompt("Logical volume %s will be "
|
if (yes_no_prompt("Logical volume %s will be "
|
||||||
"deactivated first. "
|
"deactivated temporarily. "
|
||||||
"Continue? [y/n]: ",
|
"Continue? [y/n]: ", lv->name) == 'n') {
|
||||||
lv->name) == 'n') {
|
|
||||||
log_print("%s device number not changed.",
|
log_print("%s device number not changed.",
|
||||||
lv->name);
|
lv->name);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
active = 1;
|
||||||
}
|
}
|
||||||
log_print("Ensuring %s is inactive. "
|
log_print("Ensuring %s is inactive. ", lv->name);
|
||||||
"(Reactivate using lvchange -ay.)", lv->name);
|
if (!deactivate_lv(cmd, lv->lvid.s)) {
|
||||||
if (!lock_vol(cmd, lv->lvid.s, LCK_LV_DEACTIVATE)) {
|
|
||||||
log_error("%s: deactivation failed", lv->name);
|
log_error("%s: deactivation failed", lv->name);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@ -266,6 +267,14 @@ static int lvchange_persistent(struct cmd_context *cmd,
|
|||||||
lv->major = arg_int_value(cmd, major_ARG, lv->major);
|
lv->major = arg_int_value(cmd, major_ARG, lv->major);
|
||||||
log_verbose("Setting persistent device number to (%d, %d) "
|
log_verbose("Setting persistent device number to (%d, %d) "
|
||||||
"for \"%s\"", lv->major, lv->minor, lv->name);
|
"for \"%s\"", lv->major, lv->minor, lv->name);
|
||||||
|
if (active) {
|
||||||
|
log_verbose("Re-activating logical volume \"%s\"",
|
||||||
|
lv->name);
|
||||||
|
if (!activate_lv(cmd, lv->lvid.s)) {
|
||||||
|
log_error("%s: reactivation failed", lv->name);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
log_very_verbose("Updating logical volume \"%s\" on disk(s)", lv->name);
|
log_very_verbose("Updating logical volume \"%s\" on disk(s)", lv->name);
|
||||||
@ -276,19 +285,19 @@ static int lvchange_persistent(struct cmd_context *cmd,
|
|||||||
|
|
||||||
backup(lv->vg);
|
backup(lv->vg);
|
||||||
|
|
||||||
if (!lock_vol(cmd, lv->lvid.s, LCK_LV_SUSPEND | LCK_HOLD)) {
|
if (!suspend_lv(cmd, lv->lvid.s)) {
|
||||||
log_error("Failed to lock %s", lv->name);
|
log_error("Failed to lock %s", lv->name);
|
||||||
vg_revert(lv->vg);
|
vg_revert(lv->vg);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!vg_commit(lv->vg)) {
|
if (!vg_commit(lv->vg)) {
|
||||||
unlock_lv(cmd, lv->lvid.s);
|
resume_lv(cmd, lv->lvid.s);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
log_very_verbose("Updating permissions for \"%s\" in kernel", lv->name);
|
log_very_verbose("Updating permissions for \"%s\" in kernel", lv->name);
|
||||||
if (!unlock_lv(cmd, lv->lvid.s)) {
|
if (!resume_lv(cmd, lv->lvid.s)) {
|
||||||
log_error("Problem reactivating %s", lv->name);
|
log_error("Problem reactivating %s", lv->name);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -528,7 +528,7 @@ static int _lvcreate(struct cmd_context *cmd, struct lvcreate_params *lp)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!lock_vol(cmd, lv->lvid.s, LCK_LV_ACTIVATE)) {
|
if (!activate_lv(cmd, lv->lvid.s)) {
|
||||||
if (lp->snapshot)
|
if (lp->snapshot)
|
||||||
/* FIXME Remove the failed lv we just added */
|
/* FIXME Remove the failed lv we just added */
|
||||||
log_error("Aborting. Failed to activate snapshot "
|
log_error("Aborting. Failed to activate snapshot "
|
||||||
@ -554,14 +554,14 @@ static int _lvcreate(struct cmd_context *cmd, struct lvcreate_params *lp)
|
|||||||
/* Reset permission after zeroing */
|
/* Reset permission after zeroing */
|
||||||
if (!(lp->permission & LVM_WRITE))
|
if (!(lp->permission & LVM_WRITE))
|
||||||
lv->status &= ~LVM_WRITE;
|
lv->status &= ~LVM_WRITE;
|
||||||
if (!lock_vol(cmd, lv->lvid.s, LCK_LV_DEACTIVATE)) {
|
if (!deactivate_lv(cmd, lv->lvid.s)) {
|
||||||
log_err("Couldn't unlock snapshot.");
|
log_err("Couldn't deactivate new snapshot.");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* FIXME write/commit/backup sequence issue */
|
/* FIXME write/commit/backup sequence issue */
|
||||||
if (!lock_vol(cmd, org->lvid.s, LCK_LV_SUSPEND | LCK_HOLD)) {
|
if (!suspend_lv(cmd, org->lvid.s)) {
|
||||||
log_error("Failed to lock origin %s", org->name);
|
log_error("Failed to suspend origin %s", org->name);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -574,7 +574,7 @@ static int _lvcreate(struct cmd_context *cmd, struct lvcreate_params *lp)
|
|||||||
if (!vg_write(vg) || !vg_commit(vg))
|
if (!vg_write(vg) || !vg_commit(vg))
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
if (!unlock_lv(cmd, org->lvid.s)) {
|
if (!resume_lv(cmd, org->lvid.s)) {
|
||||||
log_error("Problem reactivating origin %s", org->name);
|
log_error("Problem reactivating origin %s", org->name);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -62,7 +62,7 @@ static int lvremove_single(struct cmd_context *cmd, struct logical_volume *lv,
|
|||||||
if (!archive(vg))
|
if (!archive(vg))
|
||||||
return ECMD_FAILED;
|
return ECMD_FAILED;
|
||||||
|
|
||||||
if (!lock_vol(cmd, lv->lvid.s, LCK_LV_DEACTIVATE)) {
|
if (!deactivate_lv(cmd, lv->lvid.s)) {
|
||||||
log_error("Unable to deactivate logical volume \"%s\"",
|
log_error("Unable to deactivate logical volume \"%s\"",
|
||||||
lv->name);
|
lv->name);
|
||||||
return ECMD_FAILED;
|
return ECMD_FAILED;
|
||||||
|
@ -160,19 +160,18 @@ int lvrename(struct cmd_context *cmd, int argc, char **argv)
|
|||||||
|
|
||||||
backup(lv->vg);
|
backup(lv->vg);
|
||||||
|
|
||||||
if (!lock_vol(cmd, lv->lvid.s, LCK_LV_SUSPEND | LCK_HOLD |
|
if (!suspend_lv(cmd, lv->lvid.s)) {
|
||||||
LCK_NONBLOCK)) {
|
|
||||||
stack;
|
stack;
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!vg_commit(vg)) {
|
if (!vg_commit(vg)) {
|
||||||
stack;
|
stack;
|
||||||
unlock_lv(cmd, lv->lvid.s);
|
resume_lv(cmd, lv->lvid.s);
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
|
|
||||||
unlock_lv(cmd, lv->lvid.s);
|
resume_lv(cmd, lv->lvid.s);
|
||||||
|
|
||||||
unlock_vg(cmd, vg_name);
|
unlock_vg(cmd, vg_name);
|
||||||
|
|
||||||
|
@ -380,19 +380,19 @@ int lvresize(struct cmd_context *cmd, int argc, char **argv)
|
|||||||
else
|
else
|
||||||
lock_lvid = lv->lvid.s;
|
lock_lvid = lv->lvid.s;
|
||||||
|
|
||||||
if (!lock_vol(cmd, lock_lvid, LCK_LV_SUSPEND | LCK_HOLD)) {
|
if (!suspend_lv(cmd, lock_lvid)) {
|
||||||
log_error("Can't get lock for %s", lv_name);
|
log_error("Failed to suspend %s", lv_name);
|
||||||
vg_revert(vg);
|
vg_revert(vg);
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!vg_commit(vg)) {
|
if (!vg_commit(vg)) {
|
||||||
stack;
|
stack;
|
||||||
unlock_lv(cmd, lock_lvid);
|
resume_lv(cmd, lock_lvid);
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!unlock_lv(cmd, lock_lvid)) {
|
if (!resume_lv(cmd, lock_lvid)) {
|
||||||
log_error("Problem reactivating %s", lv_name);
|
log_error("Problem reactivating %s", lv_name);
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
|
@ -241,15 +241,15 @@ static int _update_metadata(struct cmd_context *cmd, struct volume_group *vg,
|
|||||||
|
|
||||||
backup(vg);
|
backup(vg);
|
||||||
|
|
||||||
if (!lock_lvs(cmd, lvs_changed, LCK_LV_SUSPEND | LCK_HOLD)) {
|
if (!suspend_lvs(cmd, lvs_changed)) {
|
||||||
stack;
|
stack;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!first_time) {
|
if (!first_time) {
|
||||||
if (!lock_vol(cmd, lv_mirr->lvid.s, LCK_LV_SUSPEND | LCK_HOLD)) {
|
if (!suspend_lv(cmd, lv_mirr->lvid.s)) {
|
||||||
stack;
|
stack;
|
||||||
unlock_lvs(cmd, lvs_changed);
|
resume_lvs(cmd, lvs_changed);
|
||||||
vg_revert(vg);
|
vg_revert(vg);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@ -258,27 +258,27 @@ static int _update_metadata(struct cmd_context *cmd, struct volume_group *vg,
|
|||||||
if (!vg_commit(vg)) {
|
if (!vg_commit(vg)) {
|
||||||
log_error("ABORTING: Volume group metadata update failed.");
|
log_error("ABORTING: Volume group metadata update failed.");
|
||||||
if (!first_time)
|
if (!first_time)
|
||||||
unlock_lv(cmd, lv_mirr->lvid.s);
|
resume_lv(cmd, lv_mirr->lvid.s);
|
||||||
unlock_lvs(cmd, lvs_changed);
|
resume_lvs(cmd, lvs_changed);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (first_time) {
|
if (first_time) {
|
||||||
if (!lock_vol(cmd, lv_mirr->lvid.s, LCK_LV_ACTIVATE)) {
|
if (!activate_lv(cmd, lv_mirr->lvid.s)) {
|
||||||
log_error
|
log_error
|
||||||
("ABORTING: Temporary mirror activation failed.");
|
("ABORTING: Temporary mirror activation failed.");
|
||||||
unlock_lvs(cmd, lvs_changed);
|
resume_lvs(cmd, lvs_changed);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
} else if (!unlock_lv(cmd, lv_mirr->lvid.s)) {
|
} else if (!resume_lv(cmd, lv_mirr->lvid.s)) {
|
||||||
log_error("Unable to unlock logical volume \"%s\"",
|
log_error("Unable to reactivate logical volume \"%s\"",
|
||||||
lv_mirr->name);
|
lv_mirr->name);
|
||||||
unlock_lvs(cmd, lvs_changed);
|
resume_lvs(cmd, lvs_changed);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!unlock_lvs(cmd, lvs_changed)) {
|
if (!resume_lvs(cmd, lvs_changed)) {
|
||||||
log_error("Unable to unlock logical volumes");
|
log_error("Unable to resume logical volumes");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -331,7 +331,7 @@ static int _set_up_pvmove(struct cmd_context *cmd, const char *pv_name,
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Ensure mirror LV is active */
|
/* Ensure mirror LV is active */
|
||||||
if (!lock_vol(cmd, lv_mirr->lvid.s, LCK_LV_ACTIVATE)) {
|
if (!activate_lv(cmd, lv_mirr->lvid.s)) {
|
||||||
log_error
|
log_error
|
||||||
("ABORTING: Temporary mirror activation failed.");
|
("ABORTING: Temporary mirror activation failed.");
|
||||||
unlock_vg(cmd, pv->vg_name);
|
unlock_vg(cmd, pv->vg_name);
|
||||||
@ -363,7 +363,7 @@ static int _set_up_pvmove(struct cmd_context *cmd, const char *pv_name,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!lock_lvs(cmd, lvs_changed, LCK_LV_ACTIVATE)) {
|
if (!activate_lvs_excl(cmd, lvs_changed)) {
|
||||||
stack;
|
stack;
|
||||||
unlock_vg(cmd, pv->vg_name);
|
unlock_vg(cmd, pv->vg_name);
|
||||||
return ECMD_FAILED;
|
return ECMD_FAILED;
|
||||||
@ -400,12 +400,12 @@ static int _finish_pvmove(struct cmd_context *cmd, struct volume_group *vg,
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!lock_lvs(cmd, lvs_changed, LCK_LV_SUSPEND | LCK_HOLD)) {
|
if (!suspend_lvs(cmd, lvs_changed)) {
|
||||||
log_error("Locking LVs to remove temporary mirror failed");
|
log_error("Locking LVs to remove temporary mirror failed");
|
||||||
r = 0;
|
r = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!lock_vol(cmd, lv_mirr->lvid.s, LCK_LV_SUSPEND | LCK_HOLD)) {
|
if (!suspend_lv(cmd, lv_mirr->lvid.s)) {
|
||||||
log_error("Suspension of temporary mirror LV failed");
|
log_error("Suspension of temporary mirror LV failed");
|
||||||
r = 0;
|
r = 0;
|
||||||
}
|
}
|
||||||
@ -414,20 +414,20 @@ static int _finish_pvmove(struct cmd_context *cmd, struct volume_group *vg,
|
|||||||
log_error("ABORTING: Failed to write new data locations "
|
log_error("ABORTING: Failed to write new data locations "
|
||||||
"to disk.");
|
"to disk.");
|
||||||
vg_revert(vg);
|
vg_revert(vg);
|
||||||
unlock_lv(cmd, lv_mirr->lvid.s);
|
resume_lv(cmd, lv_mirr->lvid.s);
|
||||||
unlock_lvs(cmd, lvs_changed);
|
resume_lvs(cmd, lvs_changed);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!unlock_lv(cmd, lv_mirr->lvid.s)) {
|
if (!resume_lv(cmd, lv_mirr->lvid.s)) {
|
||||||
log_error("Unable to unlock logical volume \"%s\"",
|
log_error("Unable to reactivate logical volume \"%s\"",
|
||||||
lv_mirr->name);
|
lv_mirr->name);
|
||||||
r = 0;
|
r = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
unlock_lvs(cmd, lvs_changed);
|
resume_lvs(cmd, lvs_changed);
|
||||||
|
|
||||||
if (!lock_vol(cmd, lv_mirr->lvid.s, LCK_LV_DEACTIVATE)) {
|
if (!deactivate_lv(cmd, lv_mirr->lvid.s)) {
|
||||||
log_error("ABORTING: Unable to deactivate temporary logical "
|
log_error("ABORTING: Unable to deactivate temporary logical "
|
||||||
"volume \"%s\"", lv_mirr->name);
|
"volume \"%s\"", lv_mirr->name);
|
||||||
r = 0;
|
r = 0;
|
||||||
|
@ -16,7 +16,7 @@
|
|||||||
#include "tools.h"
|
#include "tools.h"
|
||||||
|
|
||||||
static int _activate_lvs_in_vg(struct cmd_context *cmd,
|
static int _activate_lvs_in_vg(struct cmd_context *cmd,
|
||||||
struct volume_group *vg, int lock)
|
struct volume_group *vg, int activate)
|
||||||
{
|
{
|
||||||
struct lv_list *lvl;
|
struct lv_list *lvl;
|
||||||
struct logical_volume *lv;
|
struct logical_volume *lv;
|
||||||
@ -31,10 +31,16 @@ static int _activate_lvs_in_vg(struct cmd_context *cmd,
|
|||||||
continue;
|
continue;
|
||||||
|
|
||||||
/* Can't deactive a pvmove LV */
|
/* Can't deactive a pvmove LV */
|
||||||
if ((lock == LCK_LV_DEACTIVATE) && (lv->status & PVMOVE))
|
if (!activate && (lv->status & PVMOVE))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (!lock_vol(cmd, lv->lvid.s, lock | LCK_NONBLOCK))
|
if (!activate) {
|
||||||
|
if (!deactivate_lv(cmd, lv->lvid.s))
|
||||||
|
continue;
|
||||||
|
} else if (lv_is_origin(lv)) {
|
||||||
|
if (!activate_lv_excl(cmd, lv->lvid.s))
|
||||||
|
continue;
|
||||||
|
} else if (!activate_lv(cmd, lv->lvid.s))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if ((lv->status & PVMOVE) &&
|
if ((lv->status & PVMOVE) &&
|
||||||
@ -67,11 +73,11 @@ static int _vgchange_available(struct cmd_context *cmd, struct volume_group *vg)
|
|||||||
log_verbose("%d logical volume(s) in volume group \"%s\" "
|
log_verbose("%d logical volume(s) in volume group \"%s\" "
|
||||||
"already active", active, vg->name);
|
"already active", active, vg->name);
|
||||||
|
|
||||||
if (available && _activate_lvs_in_vg(cmd, vg, LCK_LV_ACTIVATE))
|
if (available && _activate_lvs_in_vg(cmd, vg, 1))
|
||||||
log_verbose("Activated logical volumes in "
|
log_verbose("Activated logical volumes in "
|
||||||
"volume group \"%s\"", vg->name);
|
"volume group \"%s\"", vg->name);
|
||||||
|
|
||||||
if (!available && _activate_lvs_in_vg(cmd, vg, LCK_LV_DEACTIVATE))
|
if (!available && _activate_lvs_in_vg(cmd, vg, 0))
|
||||||
log_verbose("Deactivated logical volumes in "
|
log_verbose("Deactivated logical volumes in "
|
||||||
"volume group \"%s\"", vg->name);
|
"volume group \"%s\"", vg->name);
|
||||||
|
|
||||||
|
@ -61,8 +61,7 @@ static int _remove_lv(struct cmd_context *cmd, struct logical_volume *lv,
|
|||||||
log_verbose("Deactivating (if active) logical volume %s",
|
log_verbose("Deactivating (if active) logical volume %s",
|
||||||
lv->name);
|
lv->name);
|
||||||
|
|
||||||
if (!lock_vol(cmd, lv->lvid.s,
|
if (!deactivate_lv(cmd, lv->lvid.s)) {
|
||||||
LCK_LV_DEACTIVATE | LCK_NONBLOCK)) {
|
|
||||||
log_error("Failed to deactivate LV %s", lv->name);
|
log_error("Failed to deactivate LV %s", lv->name);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@ -70,8 +69,7 @@ static int _remove_lv(struct cmd_context *cmd, struct logical_volume *lv,
|
|||||||
log_verbose("Deactivating (if active) logical volume %s "
|
log_verbose("Deactivating (if active) logical volume %s "
|
||||||
"(origin of %s)", snap->origin->name, lv->name);
|
"(origin of %s)", snap->origin->name, lv->name);
|
||||||
|
|
||||||
if (!lock_vol(cmd, snap->origin->lvid.s,
|
if (!deactivate_lv(cmd, snap->origin->lvid.s)) {
|
||||||
LCK_LV_DEACTIVATE | LCK_NONBLOCK)) {
|
|
||||||
log_error("Failed to deactivate LV %s",
|
log_error("Failed to deactivate LV %s",
|
||||||
snap->origin->name);
|
snap->origin->name);
|
||||||
return 0;
|
return 0;
|
||||||
|
Loading…
Reference in New Issue
Block a user