From 0fb173aa3a1c710022d888bee16a45d8a33d2bed Mon Sep 17 00:00:00 2001 From: Alasdair Kergon Date: Mon, 15 Aug 2005 12:00:04 +0000 Subject: [PATCH] Change LV locking macros to take lv instead of lvid. --- WHATS_NEW | 1 + lib/locking/locking.c | 10 +++++----- lib/locking/locking.h | 20 ++++++++++---------- tools/lvchange.c | 34 +++++++++++++++++----------------- tools/lvconvert.c | 6 +++--- tools/lvcreate.c | 12 ++++++------ tools/lvremove.c | 2 +- tools/lvrename.c | 6 +++--- tools/lvresize.c | 12 ++++++------ tools/pvmove.c | 18 +++++++++--------- tools/vgchange.c | 10 +++++----- tools/vgreduce.c | 4 ++-- 12 files changed, 68 insertions(+), 67 deletions(-) diff --git a/WHATS_NEW b/WHATS_NEW index 4af0990fb..d309658ee 100644 --- a/WHATS_NEW +++ b/WHATS_NEW @@ -1,5 +1,6 @@ Version 2.01.15 - ================================= + Change LV locking macros to take lv instead of lvid. Prepend 'cluster' activation parameter to mirror log when appropriate. Pass exclusive flag to lv_activate and on to target activation code. Prevent snapshot creation in a clustered VG for now. diff --git a/lib/locking/locking.c b/lib/locking/locking.c index 0e90aa3a8..4437c3d5f 100644 --- a/lib/locking/locking.c +++ b/lib/locking/locking.c @@ -268,7 +268,7 @@ int resume_lvs(struct cmd_context *cmd, struct list *lvs) struct lv_list *lvl; list_iterate_items(lvl, lvs) - resume_lv(cmd, lvl->lv->lvid.s); + resume_lv(cmd, lvl->lv); return 1; } @@ -280,11 +280,11 @@ int suspend_lvs(struct cmd_context *cmd, struct list *lvs) struct lv_list *lvl; list_iterate_items(lvl, lvs) { - if (!suspend_lv(cmd, lvl->lv->lvid.s)) { + if (!suspend_lv(cmd, lvl->lv)) { log_error("Failed to suspend %s", lvl->lv->name); list_uniterate(lvh, lvs, &lvl->list) { lvl = list_item(lvh, struct lv_list); - resume_lv(cmd, lvl->lv->lvid.s); + resume_lv(cmd, lvl->lv); } return 0; @@ -301,11 +301,11 @@ int activate_lvs_excl(struct cmd_context *cmd, struct list *lvs) struct lv_list *lvl; list_iterate_items(lvl, lvs) { - if (!activate_lv_excl(cmd, lvl->lv->lvid.s)) { + if (!activate_lv_excl(cmd, lvl->lv)) { log_error("Failed to activate %s", lvl->lv->name); list_uniterate(lvh, lvs, &lvl->list) { lvl = list_item(lvh, struct lv_list); - activate_lv(cmd, lvl->lv->lvid.s); + activate_lv(cmd, lvl->lv); } return 0; diff --git a/lib/locking/locking.h b/lib/locking/locking.h index c2fcb5a9b..ad0cada06 100644 --- a/lib/locking/locking.h +++ b/lib/locking/locking.h @@ -81,16 +81,16 @@ int check_lvm1_vg_inactive(struct cmd_context *cmd, const char *vgname); #define unlock_vg(cmd, vol) lock_vol(cmd, vol, LCK_VG_UNLOCK) -#define resume_lv(cmd, vol) lock_vol(cmd, vol, LCK_LV_RESUME) -#define suspend_lv(cmd, vol) lock_vol(cmd, vol, LCK_LV_SUSPEND | LCK_HOLD) -#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) -#define activate_lv_local(cmd, vol) \ - lock_vol(cmd, vol, LCK_LV_ACTIVATE | LCK_HOLD | LCK_LOCAL) -#define deactivate_lv_local(cmd, vol) \ - lock_vol(cmd, vol, LCK_LV_DEACTIVATE | LCK_LOCAL) +#define resume_lv(cmd, lv) lock_vol(cmd, (lv)->lvid.s, LCK_LV_RESUME) +#define suspend_lv(cmd, lv) lock_vol(cmd, (lv)->lvid.s, LCK_LV_SUSPEND | LCK_HOLD) +#define deactivate_lv(cmd, lv) lock_vol(cmd, (lv)->lvid.s, LCK_LV_DEACTIVATE) +#define activate_lv(cmd, lv) lock_vol(cmd, (lv)->lvid.s, LCK_LV_ACTIVATE | LCK_HOLD) +#define activate_lv_excl(cmd, lv) \ + lock_vol(cmd, (lv)->lvid.s, LCK_LV_EXCLUSIVE | LCK_HOLD) +#define activate_lv_local(cmd, lv) \ + lock_vol(cmd, (lv)->lvid.s, LCK_LV_ACTIVATE | LCK_HOLD | LCK_LOCAL) +#define deactivate_lv_local(cmd, lv) \ + lock_vol(cmd, (lv)->lvid.s, LCK_LV_DEACTIVATE | LCK_LOCAL) /* Process list of LVs */ int suspend_lvs(struct cmd_context *cmd, struct list *lvs); diff --git a/tools/lvchange.c b/tools/lvchange.c index 036ba6092..b1b1434e5 100644 --- a/tools/lvchange.c +++ b/tools/lvchange.c @@ -52,19 +52,19 @@ static int lvchange_permission(struct cmd_context *cmd, backup(lv->vg); - if (!suspend_lv(cmd, lv->lvid.s)) { + if (!suspend_lv(cmd, lv)) { log_error("Failed to lock %s", lv->name); vg_revert(lv->vg); return 0; } if (!vg_commit(lv->vg)) { - resume_lv(cmd, lv->lvid.s); + resume_lv(cmd, lv); return 0; } log_very_verbose("Updating permissions for \"%s\" in kernel", lv->name); - if (!resume_lv(cmd, lv->lvid.s)) { + if (!resume_lv(cmd, lv)) { log_error("Problem reactivating %s", lv->name); return 0; } @@ -83,13 +83,13 @@ static int lvchange_availability(struct cmd_context *cmd, if (activate == CHANGE_ALN) { log_verbose("Deactivating logical volume \"%s\" locally", lv->name); - if (!deactivate_lv_local(cmd, lv->lvid.s)) { + if (!deactivate_lv_local(cmd, lv)) { stack; return 0; } } else if (activate == CHANGE_AN) { log_verbose("Deactivating logical volume \"%s\"", lv->name); - if (!deactivate_lv(cmd, lv->lvid.s)) { + if (!deactivate_lv(cmd, lv)) { stack; return 0; } @@ -103,21 +103,21 @@ static int lvchange_availability(struct cmd_context *cmd, if (lv_is_origin(lv) || (activate == CHANGE_AE)) { log_verbose("Activating logical volume \"%s\" " "exclusively", lv->name); - if (!activate_lv_excl(cmd, lv->lvid.s)) { + if (!activate_lv_excl(cmd, lv)) { stack; return 0; } } else if (activate == CHANGE_ALY) { log_verbose("Activating logical volume \"%s\" locally", lv->name); - if (!activate_lv_local(cmd, lv->lvid.s)) { + if (!activate_lv_local(cmd, lv)) { stack; return 0; } } else { log_verbose("Activating logical volume \"%s\"", lv->name); - if (!activate_lv(cmd, lv->lvid.s)) { + if (!activate_lv(cmd, lv)) { stack; return 0; } @@ -137,7 +137,7 @@ static int lvchange_availability(struct cmd_context *cmd, static int lvchange_refresh(struct cmd_context *cmd, struct logical_volume *lv) { log_verbose("Refreshing logical volume \"%s\" (if active)", lv->name); - if (!suspend_lv(cmd, lv->lvid.s) || !resume_lv(cmd, lv->lvid.s)) + if (!suspend_lv(cmd, lv) || !resume_lv(cmd, lv)) return 0; return 1; @@ -216,19 +216,19 @@ static int lvchange_readahead(struct cmd_context *cmd, backup(lv->vg); - if (!suspend_lv(cmd, lv->lvid.s)) { + if (!suspend_lv(cmd, lv)) { log_error("Failed to lock %s", lv->name); vg_revert(lv->vg); return 0; } if (!vg_commit(lv->vg)) { - resume_lv(cmd, lv->lvid.s); + resume_lv(cmd, lv); return 0; } log_very_verbose("Updating permissions for \"%s\" in kernel", lv->name); - if (!resume_lv(cmd, lv->lvid.s)) { + if (!resume_lv(cmd, lv)) { log_error("Problem reactivating %s", lv->name); return 0; } @@ -274,7 +274,7 @@ static int lvchange_persistent(struct cmd_context *cmd, active = 1; } log_verbose("Ensuring %s is inactive.", lv->name); - if (!deactivate_lv(cmd, lv->lvid.s)) { + if (!deactivate_lv(cmd, lv)) { log_error("%s: deactivation failed", lv->name); return 0; } @@ -286,7 +286,7 @@ static int lvchange_persistent(struct cmd_context *cmd, if (active) { log_verbose("Re-activating logical volume \"%s\"", lv->name); - if (!activate_lv(cmd, lv->lvid.s)) { + if (!activate_lv(cmd, lv)) { log_error("%s: reactivation failed", lv->name); return 0; } @@ -301,19 +301,19 @@ static int lvchange_persistent(struct cmd_context *cmd, backup(lv->vg); - if (!suspend_lv(cmd, lv->lvid.s)) { + if (!suspend_lv(cmd, lv)) { log_error("Failed to lock %s", lv->name); vg_revert(lv->vg); return 0; } if (!vg_commit(lv->vg)) { - resume_lv(cmd, lv->lvid.s); + resume_lv(cmd, lv); return 0; } log_very_verbose("Updating permissions for \"%s\" in kernel", lv->name); - if (!resume_lv(cmd, lv->lvid.s)) { + if (!resume_lv(cmd, lv)) { log_error("Problem reactivating %s", lv->name); return 0; } diff --git a/tools/lvconvert.c b/tools/lvconvert.c index 8f2ba8e51..d1d01b737 100644 --- a/tools/lvconvert.c +++ b/tools/lvconvert.c @@ -93,20 +93,20 @@ static int lvconvert_mirrors(struct cmd_context * cmd, struct logical_volume * l backup(lv->vg); - if (!suspend_lv(cmd, lv->lvid.s)) { + if (!suspend_lv(cmd, lv)) { log_error("Failed to lock %s", lv->name); vg_revert(lv->vg); return 0; } if (!vg_commit(lv->vg)) { - resume_lv(cmd, lv->lvid.s); + resume_lv(cmd, lv); return 0; } log_very_verbose("Updating \"%s\" in kernel", lv->name); - if (!resume_lv(cmd, lv->lvid.s)) { + if (!resume_lv(cmd, lv)) { log_error("Problem reactivating %s", lv->name); return 0; } diff --git a/tools/lvcreate.c b/tools/lvcreate.c index 74a4ce68c..aa3440d95 100644 --- a/tools/lvcreate.c +++ b/tools/lvcreate.c @@ -623,7 +623,7 @@ static int _lvcreate(struct cmd_context *cmd, struct lvcreate_params *lp) goto error; } - if (!activate_lv(cmd, log_lv->lvid.s)) { + if (!activate_lv(cmd, log_lv)) { log_error("Aborting. Failed to activate mirror log. " "Remove new LVs and retry."); goto error; @@ -635,7 +635,7 @@ static int _lvcreate(struct cmd_context *cmd, struct lvcreate_params *lp) goto error; } - if (!deactivate_lv(cmd, log_lv->lvid.s)) { + if (!deactivate_lv(cmd, log_lv)) { log_error("Aborting. Failed to deactivate mirror log. " "Remove new LV and retry."); goto error; @@ -711,7 +711,7 @@ static int _lvcreate(struct cmd_context *cmd, struct lvcreate_params *lp) return 0; } - if (!activate_lv(cmd, lv->lvid.s)) { + if (!activate_lv(cmd, lv)) { if (lp->snapshot) /* FIXME Remove the failed lv we just added */ log_error("Aborting. Failed to activate snapshot " @@ -737,13 +737,13 @@ static int _lvcreate(struct cmd_context *cmd, struct lvcreate_params *lp) /* Reset permission after zeroing */ if (!(lp->permission & LVM_WRITE)) lv->status &= ~LVM_WRITE; - if (!deactivate_lv(cmd, lv->lvid.s)) { + if (!deactivate_lv(cmd, lv)) { log_err("Couldn't deactivate new snapshot."); return 0; } /* FIXME write/commit/backup sequence issue */ - if (!suspend_lv(cmd, org->lvid.s)) { + if (!suspend_lv(cmd, org)) { log_error("Failed to suspend origin %s", org->name); return 0; } @@ -758,7 +758,7 @@ static int _lvcreate(struct cmd_context *cmd, struct lvcreate_params *lp) if (!vg_write(vg) || !vg_commit(vg)) return 0; - if (!resume_lv(cmd, org->lvid.s)) { + if (!resume_lv(cmd, org)) { log_error("Problem reactivating origin %s", org->name); return 0; } diff --git a/tools/lvremove.c b/tools/lvremove.c index 18cac809c..a523c7084 100644 --- a/tools/lvremove.c +++ b/tools/lvremove.c @@ -74,7 +74,7 @@ static int lvremove_single(struct cmd_context *cmd, struct logical_volume *lv, if (!archive(vg)) return ECMD_FAILED; - if (!deactivate_lv(cmd, lv->lvid.s)) { + if (!deactivate_lv(cmd, lv)) { log_error("Unable to deactivate logical volume \"%s\"", lv->name); return ECMD_FAILED; diff --git a/tools/lvrename.c b/tools/lvrename.c index bc042acbd..a86385d0c 100644 --- a/tools/lvrename.c +++ b/tools/lvrename.c @@ -158,18 +158,18 @@ int lvrename(struct cmd_context *cmd, int argc, char **argv) backup(lv->vg); - if (!suspend_lv(cmd, lv->lvid.s)) { + if (!suspend_lv(cmd, lv)) { stack; goto error; } if (!vg_commit(vg)) { stack; - resume_lv(cmd, lv->lvid.s); + resume_lv(cmd, lv); goto error; } - resume_lv(cmd, lv->lvid.s); + resume_lv(cmd, lv); unlock_vg(cmd, vg_name); diff --git a/tools/lvresize.c b/tools/lvresize.c index 6ee149c0b..f32801f5e 100644 --- a/tools/lvresize.c +++ b/tools/lvresize.c @@ -124,7 +124,7 @@ static int _lvresize(struct cmd_context *cmd, struct lvresize_params *lp) uint32_t extents_used = 0; uint32_t size_rest; alloc_policy_t alloc; - char *lock_lvid; + struct logical_volume *lock_lv; struct lv_list *lvl; int consistent = 1; struct lv_segment *seg; @@ -518,11 +518,11 @@ static int _lvresize(struct cmd_context *cmd, struct lvresize_params *lp) /* If snapshot, must suspend all associated devices */ if ((snap_seg = find_cow(lv))) - lock_lvid = snap_seg->origin->lvid.s; + lock_lv = snap_seg->origin; else - lock_lvid = lv->lvid.s; + lock_lv = lv; - if (!suspend_lv(cmd, lock_lvid)) { + if (!suspend_lv(cmd, lock_lv)) { log_error("Failed to suspend %s", lp->lv_name); vg_revert(vg); return ECMD_FAILED; @@ -530,11 +530,11 @@ static int _lvresize(struct cmd_context *cmd, struct lvresize_params *lp) if (!vg_commit(vg)) { stack; - resume_lv(cmd, lock_lvid); + resume_lv(cmd, lock_lv); return ECMD_FAILED; } - if (!resume_lv(cmd, lock_lvid)) { + if (!resume_lv(cmd, lock_lv)) { log_error("Problem reactivating %s", lp->lv_name); return ECMD_FAILED; } diff --git a/tools/pvmove.c b/tools/pvmove.c index b51164598..4348c4eed 100644 --- a/tools/pvmove.c +++ b/tools/pvmove.c @@ -219,7 +219,7 @@ static int _update_metadata(struct cmd_context *cmd, struct volume_group *vg, /* Suspend mirrors on subsequent calls */ if (!first_time) { - if (!suspend_lv(cmd, lv_mirr->lvid.s)) { + if (!suspend_lv(cmd, lv_mirr)) { stack; resume_lvs(cmd, lvs_changed); vg_revert(vg); @@ -231,7 +231,7 @@ static int _update_metadata(struct cmd_context *cmd, struct volume_group *vg, if (!vg_commit(vg)) { log_error("ABORTING: Volume group metadata update failed."); if (!first_time) - resume_lv(cmd, lv_mirr->lvid.s); + resume_lv(cmd, lv_mirr); resume_lvs(cmd, lvs_changed); return 0; } @@ -240,7 +240,7 @@ static int _update_metadata(struct cmd_context *cmd, struct volume_group *vg, /* Only the first mirror segment gets activated as a mirror */ /* FIXME: Add option to use a log */ if (first_time) { - if (!activate_lv_excl(cmd, lv_mirr->lvid.s)) { + if (!activate_lv_excl(cmd, lv_mirr)) { if (!test_mode()) log_error("ABORTING: Temporary mirror " "activation failed. " @@ -249,7 +249,7 @@ static int _update_metadata(struct cmd_context *cmd, struct volume_group *vg, resume_lvs(cmd, lvs_changed); return 0; } - } else if (!resume_lv(cmd, lv_mirr->lvid.s)) { + } else if (!resume_lv(cmd, lv_mirr)) { log_error("Unable to reactivate logical volume \"%s\"", lv_mirr->name); resume_lvs(cmd, lvs_changed); @@ -318,7 +318,7 @@ static int _set_up_pvmove(struct cmd_context *cmd, const char *pv_name, } /* Ensure mirror LV is active */ - if (!activate_lv_excl(cmd, lv_mirr->lvid.s)) { + if (!activate_lv_excl(cmd, lv_mirr)) { log_error ("ABORTING: Temporary mirror activation failed."); unlock_vg(cmd, pv->vg_name); @@ -415,7 +415,7 @@ static int _finish_pvmove(struct cmd_context *cmd, struct volume_group *vg, } /* Suspend mirror LV to flush pending I/O */ - if (!suspend_lv(cmd, lv_mirr->lvid.s)) { + if (!suspend_lv(cmd, lv_mirr)) { log_error("Suspension of temporary mirror LV failed"); r = 0; } @@ -425,13 +425,13 @@ static int _finish_pvmove(struct cmd_context *cmd, struct volume_group *vg, log_error("ABORTING: Failed to write new data locations " "to disk."); vg_revert(vg); - resume_lv(cmd, lv_mirr->lvid.s); + resume_lv(cmd, lv_mirr); resume_lvs(cmd, lvs_changed); return 0; } /* Release mirror LV. (No pending I/O because it's been suspended.) */ - if (!resume_lv(cmd, lv_mirr->lvid.s)) { + if (!resume_lv(cmd, lv_mirr)) { log_error("Unable to reactivate logical volume \"%s\"", lv_mirr->name); r = 0; @@ -441,7 +441,7 @@ static int _finish_pvmove(struct cmd_context *cmd, struct volume_group *vg, resume_lvs(cmd, lvs_changed); /* Deactivate mirror LV */ - if (!deactivate_lv(cmd, lv_mirr->lvid.s)) { + if (!deactivate_lv(cmd, lv_mirr)) { log_error("ABORTING: Unable to deactivate temporary logical " "volume \"%s\"", lv_mirr->name); r = 0; diff --git a/tools/vgchange.c b/tools/vgchange.c index a1c9c80a5..461caa940 100644 --- a/tools/vgchange.c +++ b/tools/vgchange.c @@ -37,18 +37,18 @@ static int _activate_lvs_in_vg(struct cmd_context *cmd, continue; if (activate == CHANGE_AN) { - if (!deactivate_lv(cmd, lv->lvid.s)) + if (!deactivate_lv(cmd, lv)) continue; } else if (activate == CHANGE_ALN) { - if (!deactivate_lv_local(cmd, lv->lvid.s)) + if (!deactivate_lv_local(cmd, lv)) continue; } else if (lv_is_origin(lv) || (activate == CHANGE_AE)) { - if (!activate_lv_excl(cmd, lv->lvid.s)) + if (!activate_lv_excl(cmd, lv)) continue; } else if (activate == CHANGE_ALY) { - if (!activate_lv_local(cmd, lv->lvid.s)) + if (!activate_lv_local(cmd, lv)) continue; - } else if (!activate_lv(cmd, lv->lvid.s)) + } else if (!activate_lv(cmd, lv)) continue; if ((lv->status & PVMOVE) && diff --git a/tools/vgreduce.c b/tools/vgreduce.c index 64b797d39..c75b195a5 100644 --- a/tools/vgreduce.c +++ b/tools/vgreduce.c @@ -61,7 +61,7 @@ static int _remove_lv(struct cmd_context *cmd, struct logical_volume *lv, log_verbose("Deactivating (if active) logical volume %s", lv->name); - if (!deactivate_lv(cmd, lv->lvid.s)) { + if (!deactivate_lv(cmd, lv)) { log_error("Failed to deactivate LV %s", lv->name); return 0; } @@ -69,7 +69,7 @@ static int _remove_lv(struct cmd_context *cmd, struct logical_volume *lv, log_verbose("Deactivating (if active) logical volume %s " "(origin of %s)", snap_seg->origin->name, lv->name); - if (!deactivate_lv(cmd, snap_seg->origin->lvid.s)) { + if (!deactivate_lv(cmd, snap_seg->origin)) { log_error("Failed to deactivate LV %s", snap_seg->origin->name); return 0; -- 2.43.5