mrc0mmand / rpms / lvm2

Forked from rpms/lvm2 2 years ago
Clone

Blame SOURCES/lvm2-2_02_187-lvconvert-improve-validation-thin-and-cache-pool-con.patch

2b52f6
From 0cef052646dc4a1338a3febf38c3085cfa636cca Mon Sep 17 00:00:00 2001
2b52f6
From: Zdenek Kabelac <zkabelac@redhat.com>
2b52f6
Date: Fri, 6 Sep 2019 18:09:40 +0200
2b52f6
Subject: [PATCH 5/6] lvconvert: improve validation thin and cache pool
2b52f6
 conversion
2b52f6
2b52f6
Limit convertible LVs to thin-pool and cache-pools.
2b52f6
Also fix return code on  interal error path to return ECMD_FAILED.
2b52f6
2b52f6
(cherry picked from commit e147786bac52fea240955329963c9eed0eebfb18)
2b52f6
2b52f6
Conflicts:
2b52f6
	WHATS_NEW
2b52f6
---
2b52f6
 WHATS_NEW         |  1 +
2b52f6
 tools/lvconvert.c | 52 +++++++++++++++++++++++++++++++++++++++++++++++-----
2b52f6
 2 files changed, 48 insertions(+), 5 deletions(-)
2b52f6
2b52f6
diff --git a/WHATS_NEW b/WHATS_NEW
2b52f6
index 399864d..d1f4530 100644
2b52f6
--- a/WHATS_NEW
2b52f6
+++ b/WHATS_NEW
2b52f6
@@ -2,6 +2,7 @@ Version 2.02.187 -
2b52f6
 ===================================
2b52f6
   Prevent creating VGs with PVs with different logical block sizes.
2b52f6
   Pvmove runs in exlusively activating mode for exclusively active LVs.
2b52f6
+  Enhance validation for thin and cache pool conversion and swapping.
2b52f6
 
2b52f6
 Version 2.02.186 - 27th August 2019
2b52f6
 ===================================
2b52f6
diff --git a/tools/lvconvert.c b/tools/lvconvert.c
2b52f6
index e66f063..799e746 100644
2b52f6
--- a/tools/lvconvert.c
2b52f6
+++ b/tools/lvconvert.c
2b52f6
@@ -4309,24 +4309,66 @@ static int _lvconvert_to_pool_or_swap_metadata_single(struct cmd_context *cmd,
2b52f6
 	struct dm_list *use_pvh = NULL;
2b52f6
 	int to_thinpool = 0;
2b52f6
 	int to_cachepool = 0;
2b52f6
+	int lvt_enum = get_lvt_enum(lv);
2b52f6
+	struct lv_type *lvtype;
2b52f6
 
2b52f6
 	switch (cmd->command->command_enum) {
2b52f6
 	case lvconvert_to_thinpool_or_swap_metadata_CMD:
2b52f6
+		if (lv_is_cache(lv))
2b52f6
+			/* For cached LV check the cache origin LV type */
2b52f6
+			lvt_enum = get_lvt_enum(seg_lv(first_seg(lv), 0));
2b52f6
 		to_thinpool = 1;
2b52f6
 		break;
2b52f6
 	case lvconvert_to_cachepool_or_swap_metadata_CMD:
2b52f6
+		if (lv_is_cache(lv))
2b52f6
+			goto_bad; /* Cache over cache is not supported */
2b52f6
 		to_cachepool = 1;
2b52f6
 		break;
2b52f6
 	default:
2b52f6
-		log_error(INTERNAL_ERROR "Invalid lvconvert pool command");
2b52f6
-		return 0;
2b52f6
-	};
2b52f6
+		log_error(INTERNAL_ERROR "Invalid lvconvert pool command.");
2b52f6
+		return ECMD_FAILED;
2b52f6
+	}
2b52f6
+
2b52f6
+	switch (lvt_enum) {
2b52f6
+	case thinpool_LVT:
2b52f6
+		if (!to_thinpool)
2b52f6
+			goto_bad; /* can't accept cache-pool */
2b52f6
+		break; /* swap thin-pool */
2b52f6
+	case cachepool_LVT:
2b52f6
+		if (!to_cachepool)
2b52f6
+			goto_bad; /* can't accept thin-pool */
2b52f6
+		break; /* swap cache-pool */
2b52f6
+	case linear_LVT:
2b52f6
+	case raid_LVT:
2b52f6
+	case striped_LVT:
2b52f6
+	case zero_LVT:
2b52f6
+		break;
2b52f6
+	default:
2b52f6
+bad:
2b52f6
+		lvtype = get_lv_type(lvt_enum);
2b52f6
+		log_error("LV %s with type %s cannot be used as a %s pool LV.",
2b52f6
+			  display_lvname(lv), lvtype ? lvtype->name : "unknown",
2b52f6
+			  to_thinpool ? "thin" : "cache");
2b52f6
+		return ECMD_FAILED;
2b52f6
+	}
2b52f6
 
2b52f6
 	if (lv_is_origin(lv)) {
2b52f6
 		log_error("Cannot convert logical volume %s under snapshot.",
2b52f6
 			  display_lvname(lv));
2b52f6
-		return 0;
2b52f6
-	};
2b52f6
+		return ECMD_FAILED;
2b52f6
+	}
2b52f6
+
2b52f6
+	if (!lv_is_visible(lv)) {
2b52f6
+		log_error("Can't convert internal LV %s.",
2b52f6
+			  display_lvname(lv));
2b52f6
+		return ECMD_FAILED;
2b52f6
+	}
2b52f6
+
2b52f6
+	if (lv_is_locked(lv)) {
2b52f6
+		log_error("Can't convert locked LV %s.",
2b52f6
+			  display_lvname(lv));
2b52f6
+		return ECMD_FAILED;
2b52f6
+	}
2b52f6
 
2b52f6
 	if (cmd->position_argc > 1) {
2b52f6
 		/* First pos arg is required LV, remaining are optional PVs. */
2b52f6
-- 
2b52f6
1.8.3.1
2b52f6