Skip to contentSkip to conversation

master - lvmlockd: add full changing of lock type

PATCH David Teigland 1 participant 1 message Aug 26, 2015

lore
Share & tools
lore
#0 lore raw
Gitweb:        http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=b9ca9d73c1037657660bb3c966e9039ff75144c1
Commit:        b9ca9d73c1037657660bb3c966e9039ff75144c1
Parent:        8740b7cb77699dbb78e80ed4e8bd6c742626558e
Author:        David Teigland <[email protected]>
AuthorDate:    Mon Aug 24 15:06:23 2015 -0500
Committer:     David Teigland <[email protected]>
CommitterDate: Wed Aug 26 15:22:31 2015 -0500

lvmlockd: add full changing of lock type

Remove the existing lock type using the same functions used to remove the lockd components during vgremove. This results in a "clean" VG and lvmlockd state after the vgchange, i.e. no bits left over from previous lock type.

---
 lib/locking/lvmlockd.c |   45 +++++++++++++++++++++++++++++++--------------
 lib/locking/lvmlockd.h |    2 +-
 tools/vgchange.c       |   41 ++++++++++++++++++++++++++---------------
 tools/vgremove.c       |    2 +-
 4 files changed, 59 insertions(+), 31 deletions(-)
lib/locking/lvmlockd.c +31 -14
index 5918de3..3f73cf3 100644
@@ -868,10 +868,37 @@ int lockd_init_vg(struct cmd_context *cmd, struct volume_group *vg,
 	}
 }
 
+static int _lockd_all_lvs(struct cmd_context *cmd, struct volume_group *vg)
+{
+	struct lv_list *lvl;
+
+	dm_list_iterate_items(lvl, &vg->lvs) {
+		if (!lockd_lv(cmd, lvl->lv, "ex", 0)) {
+			log_error("LV %s/%s must be inactive on all hosts.",
+				  vg->name, lvl->lv->name);
+			return 0;
+		}
+
+		if (!lockd_lv(cmd, lvl->lv, "un", 0)) {
+			log_error("Failed to unlock LV %s/%s.", vg->name, lvl->lv->name);
+			return 0;
+		}
+	}
+
+	return 1;
+}
+
 /* vgremove before the vg is removed */
 
-int lockd_free_vg_before(struct cmd_context *cmd, struct volume_group *vg)
+int lockd_free_vg_before(struct cmd_context *cmd, struct volume_group *vg,
+			 int changing)
 {
+	/* Check that no LVs are active on other hosts. */
+	if (changing && !_lockd_all_lvs(cmd, vg)) {
+		log_error("Cannot change VG %s with active LVs", vg->name);
+		return 0;
+	}
+
 	switch (get_lock_type_from_string(vg->lock_type)) {
 	case LOCK_TYPE_NONE:
 	case LOCK_TYPE_CLVM:
@@ -2374,7 +2401,6 @@ int lockd_free_lv(struct cmd_context *cmd, struct volume_group *vg,
 
 int lockd_rename_vg_before(struct cmd_context *cmd, struct volume_group *vg)
 {
-	struct lv_list *lvl;
 	daemon_reply reply;
 	int result;
 	int ret;
@@ -2392,18 +2418,9 @@ int lockd_rename_vg_before(struct cmd_context *cmd, struct volume_group *vg)
 	}
 
 	/* Check that no LVs are active on other hosts. */
-
-	dm_list_iterate_items(lvl, &vg->lvs) {
-		if (!lockd_lv(cmd, lvl->lv, "ex", 0)) {
-			log_error("LV %s/%s must be inactive on all hosts before vgrename.",
-				  vg->name, lvl->lv->name);
-			return 0;
-		}
-
-		if (!lockd_lv(cmd, lvl->lv, "un", 0)) {
-			log_error("Failed to unlock LV %s/%s.", vg->name, lvl->lv->name);
-			return 0;
-		}
+	if (!_lockd_all_lvs(cmd, vg)) {
+		log_error("Cannot rename VG %s with active LVs", vg->name);
+		return 0;
 	}
 
 	/*
lib/locking/lvmlockd.h +1 -1
index 64b3ce9..ec36ff8 100644
@@ -54,7 +54,7 @@ void lvmlockd_disconnect(void);
 /* vgcreate/vgremove use init/free */
 
 int lockd_init_vg(struct cmd_context *cmd, struct volume_group *vg, const char *lock_type, int lv_lock_count);
-int lockd_free_vg_before(struct cmd_context *cmd, struct volume_group *vg);
+int lockd_free_vg_before(struct cmd_context *cmd, struct volume_group *vg, int changing);
 void lockd_free_vg_final(struct cmd_context *cmd, struct volume_group *vg);
 
 /* vgrename */
tools/vgchange.c +26 -15

71 lines not on this page · raw message

tools/vgremove.c +1 -1
index 692d114..219149e 100644
@@ -68,7 +68,7 @@ static int vgremove_single(struct cmd_context *cmd, const char *vg_name,
 		}
 	}
 
-	if (!lockd_free_vg_before(cmd, vg))
+	if (!lockd_free_vg_before(cmd, vg, 0))
 		return_ECMD_FAILED;
 
 	if (!force && !vg_remove_check(vg))