mrc0mmand / rpms / lvm2

Forked from rpms/lvm2 2 years ago
Clone

Blame SOURCES/lvm2-2_02_104-fix-lvconvert-swap-of-poolmetadata-volume-for-active-thin-pool.patch

191583
 WHATS_NEW         |  1 +
191583
 tools/lvconvert.c | 16 +++++++++++++++-
191583
 2 files changed, 16 insertions(+), 1 deletion(-)
191583
191583
diff --git a/WHATS_NEW b/WHATS_NEW
191583
index 2dfeada..5d3bb8b 100644
191583
--- a/WHATS_NEW
191583
+++ b/WHATS_NEW
191583
@@ -1,5 +1,6 @@
191583
 Version 2.02.104 - 
191583
 ===================================
191583
+  Fix lvconvert swap of poolmetadata volume for active thin pool.
191583
   Add configure --enable-udev-systemd-background-jobs.
191583
   Add lvm2-pvscan@.service to run pvscan as a service for lvmetad/autoactivation.
191583
   Fix possible race during daemon worker thread creation (lvmetad).
191583
diff --git a/tools/lvconvert.c b/tools/lvconvert.c
191583
index 1970ca3..1098642 100644
191583
--- a/tools/lvconvert.c
191583
+++ b/tools/lvconvert.c
191583
@@ -2271,6 +2271,7 @@ static int _lvconvert_thinpool(struct cmd_context *cmd,
191583
 	struct logical_volume *pool_metadata_lv;
191583
 	struct logical_volume *external_lv = NULL;
191583
 	char metadata_name[NAME_LEN], data_name[NAME_LEN];
191583
+	int activate_pool;
191583
 
191583
 	if (!lv_is_visible(pool_lv)) {
191583
 		log_error("Can't convert internal LV %s/%s.",
191583
@@ -2299,6 +2300,7 @@ static int _lvconvert_thinpool(struct cmd_context *cmd,
191583
 		}
191583
 
191583
 		if (lv_is_thin_pool(pool_lv)) {
191583
+			activate_pool = lv_is_active(pool_lv);
191583
 			r = 1; /* Already existing thin pool */
191583
 			goto out;
191583
 		}
191583
@@ -2311,6 +2313,9 @@ static int _lvconvert_thinpool(struct cmd_context *cmd,
191583
 		return 0;
191583
 	}
191583
 
191583
+	/* Allow to have only thinpool active and restore it's active state */
191583
+	activate_pool = lv_is_active(pool_lv);
191583
+
191583
 	/* We are changing target type, so deactivate first */
191583
 	if (!deactivate_lv(cmd, pool_lv)) {
191583
 		log_error("Aborting. Failed to deactivate logical volume %s/%s.",
191583
@@ -2318,6 +2323,13 @@ static int _lvconvert_thinpool(struct cmd_context *cmd,
191583
 		return 0;
191583
 	}
191583
 
191583
+	if (lv_is_thin_pool(pool_lv) && pool_is_active(pool_lv)) {
191583
+		/* If any thin volume is also active - abort here */
191583
+		log_error("Cannot convert pool %s/%s with active thin volumes.",
191583
+			  pool_lv->vg->name, pool_lv->name);
191583
+		return 0;
191583
+	}
191583
+
191583
 	if ((dm_snprintf(metadata_name, sizeof(metadata_name), "%s_tmeta",
191583
 			 pool_lv->name) < 0) ||
191583
 	    (dm_snprintf(data_name, sizeof(data_name), "%s_tdata",
191583
@@ -2419,6 +2431,7 @@ static int _lvconvert_thinpool(struct cmd_context *cmd,
191583
 			goto mda_write;
191583
 		}
191583
 
191583
+		metadata_lv->status |= LV_NOSCAN;
191583
 		if (!lv_is_active(metadata_lv) &&
191583
 		    !activate_lv_local(cmd, metadata_lv)) {
191583
 			log_error("Aborting. Failed to activate thin metadata lv.");
191583
@@ -2511,7 +2524,8 @@ mda_write:
191583
 	if (!vg_write(pool_lv->vg) || !vg_commit(pool_lv->vg))
191583
 		return_0;
191583
 
191583
-	if (!activate_lv_excl(cmd, pool_lv)) {
191583
+	if (activate_pool &&
191583
+	    !activate_lv_excl(cmd, pool_lv)) {
191583
 		log_error("Failed to activate pool logical volume %s/%s.",
191583
 			  pool_lv->vg->name, pool_lv->name);
191583
 		/* Deactivate subvolumes */