Blame SOURCES/lvm2-2_02_181-reject-conversions-trackchanges-SubLVs.patch

5e29a5
 WHATS_NEW                                        |  1 +
5e29a5
 test/shell/lvconvert-raid1-split-trackchanges.sh | 36 +++++++++++++++++++
5e29a5
 tools/lvconvert.c                                | 45 ++++++++++++++++++++++++
5e29a5
 3 files changed, 82 insertions(+)
5e29a5
 create mode 100644 test/shell/lvconvert-raid1-split-trackchanges.sh
5e29a5
5e29a5
diff --git a/WHATS_NEW b/WHATS_NEW
5e29a5
index bdd2fa6..7c74c50 100644
5e29a5
--- a/WHATS_NEW
5e29a5
+++ b/WHATS_NEW
5e29a5
@@ -1,5 +1,6 @@
5e29a5
 Version 2.02.181 - 
5e29a5
 =================================
5e29a5
+  lvconvert: reject conversions on raid1 split tracked SubLVs
5e29a5
 
5e29a5
 Version 2.02.180 - 19th July 2018
5e29a5
 =================================
5e29a5
diff --git a/test/shell/lvconvert-raid1-split-trackchanges.sh b/test/shell/lvconvert-raid1-split-trackchanges.sh
5e29a5
new file mode 100644
5e29a5
index 0000000..e25a632
5e29a5
--- /dev/null
5e29a5
+++ b/test/shell/lvconvert-raid1-split-trackchanges.sh
5e29a5
@@ -0,0 +1,36 @@
5e29a5
+#!/usr/bin/env bash
5e29a5
+
5e29a5
+# Copyright (C) 2018 Red Hat, Inc. All rights reserved.
5e29a5
+#
5e29a5
+# This copyrighted material is made available to anyone wishing to use,
5e29a5
+# modify, copy, or redistribute it subject to the terms and conditions
5e29a5
+# of the GNU General Public License v.2.
5e29a5
+#
5e29a5
+# You should have received a copy of the GNU General Public License
5e29a5
+# along with this program; if not, write to the Free Software Foundation,
5e29a5
+# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
5e29a5
+
5e29a5
+
5e29a5
+SKIP_WITH_LVMPOLLD=1
5e29a5
+
5e29a5
+. lib/inittest
5e29a5
+
5e29a5
+# rhbz1579072/rhbz1579438
5e29a5
+
5e29a5
+aux have_raid 1 3 0 || skip
5e29a5
+
5e29a5
+# 8 PVs needed for RAID10 testing (4-stripes/2-mirror)
5e29a5
+aux prepare_pvs 4 2
5e29a5
+get_devs
5e29a5
+vgcreate $SHARED -s 512k "$vg" "${DEVICES[@]}"
5e29a5
+
5e29a5
+lvcreate -y --ty raid1 -m 2 -n $lv1 -l 1 $vg
5e29a5
+lvconvert -y --splitmirrors 1 --trackchanges $vg/$lv1
5e29a5
+
5e29a5
+not lvconvert -y --ty striped -m 1 $vg/${lv1}_rimage_2
5e29a5
+not lvconvert -y --ty raid1 -m 1 $vg/${lv1}_rimage_2
5e29a5
+not lvconvert -y --ty mirror -m 1 $vg/${lv1}_rimage_2
5e29a5
+not lvconvert -y --ty cache-pool $vg/${lv1}_rimage_2
5e29a5
+not lvconvert -y --ty thin-pool $vg/${lv1}_rimage_2
5e29a5
+
5e29a5
+vgremove -ff $vg
5e29a5
diff --git a/tools/lvconvert.c b/tools/lvconvert.c
5e29a5
index 3fad02c..079c3cd 100644
5e29a5
--- a/tools/lvconvert.c
5e29a5
+++ b/tools/lvconvert.c
5e29a5
@@ -1165,6 +1165,36 @@ static int _lvconvert_validate_thin(struct logical_volume *lv,
5e29a5
 	return 0;
5e29a5
 }
5e29a5
 
5e29a5
+/* Check for raid1 split trackchanges image to reject conversions on it. */
5e29a5
+static int _raid_split_image_conversion(struct logical_volume *lv)
5e29a5
+{
5e29a5
+	const char *s;
5e29a5
+
5e29a5
+	if (lv_is_raid_image(lv) &&
5e29a5
+	    (s = strstr(lv->name, "_rimage_"))) {
5e29a5
+		size_t len = s - lv->name;
5e29a5
+		char raidlv_name[len + 1];
5e29a5
+		const struct logical_volume *tmp_lv;
5e29a5
+
5e29a5
+		strncpy(raidlv_name, lv->name, len);
5e29a5
+		raidlv_name[len] = '\0';
5e29a5
+
5e29a5
+		if (!(tmp_lv = find_lv(lv->vg, raidlv_name))) {
5e29a5
+			log_error(INTERNAL_ERROR "Failed to find RaidLV of RAID subvolume %s.",
5e29a5
+				  display_lvname(lv));
5e29a5
+			return 1;
5e29a5
+		}
5e29a5
+
5e29a5
+		if (lv_is_raid_with_tracking(tmp_lv)) {
5e29a5
+			log_error("Conversion of tracked raid1 subvolume %s is not supported.",
5e29a5
+				  display_lvname(lv));
5e29a5
+			return 1;
5e29a5
+		}
5e29a5
+	}
5e29a5
+
5e29a5
+	return 0;
5e29a5
+}
5e29a5
+
5e29a5
 /*
5e29a5
  * _lvconvert_mirrors
5e29a5
  *
5e29a5
@@ -1180,6 +1210,9 @@ static int _lvconvert_mirrors(struct cmd_context *cmd,
5e29a5
 	uint32_t new_mimage_count = 0;
5e29a5
 	uint32_t new_log_count = 0;
5e29a5
 
5e29a5
+	if (_raid_split_image_conversion(lv))
5e29a5
+		return 0;
5e29a5
+
5e29a5
 	if ((lp->corelog || lp->mirrorlog) && *lp->type_str && strcmp(lp->type_str, SEG_TYPE_NAME_MIRROR)) {
5e29a5
 		log_error("--corelog and --mirrorlog are only compatible with mirror devices.");
5e29a5
 		return 0;
5e29a5
@@ -1296,6 +1329,9 @@ static int _lvconvert_raid(struct logical_volume *lv, struct lvconvert_params *l
5e29a5
 	struct cmd_context *cmd = lv->vg->cmd;
5e29a5
 	struct lv_segment *seg = first_seg(lv);
5e29a5
 
5e29a5
+	if (_raid_split_image_conversion(lv))
5e29a5
+		return 0;
5e29a5
+
5e29a5
 	if (_linear_type_requested(lp->type_str)) {
5e29a5
 		if (arg_is_set(cmd, mirrors_ARG) && (arg_uint_value(cmd, mirrors_ARG, 0) != 0)) {
5e29a5
 			log_error("Cannot specify mirrors with linear type.");
5e29a5
@@ -2579,6 +2615,9 @@ static int _lvconvert_to_thin_with_external(struct cmd_context *cmd,
5e29a5
 		.virtual_extents = lv->le_count,
5e29a5
 	};
5e29a5
 
5e29a5
+	if (_raid_split_image_conversion(lv))
5e29a5
+		return 0;
5e29a5
+
5e29a5
 	if (lv == thinpool_lv) {
5e29a5
 		log_error("Can't use same LV %s for thin pool and thin volume.",
5e29a5
 			  display_lvname(thinpool_lv));
5e29a5
@@ -2888,6 +2927,9 @@ static int _lvconvert_to_pool(struct cmd_context *cmd,
5e29a5
 	struct id lockd_meta_id;
5e29a5
 	const char *str_seg_type = to_cachepool ? SEG_TYPE_NAME_CACHE_POOL : SEG_TYPE_NAME_THIN_POOL;
5e29a5
 
5e29a5
+	if (_raid_split_image_conversion(lv))
5e29a5
+		return 0;
5e29a5
+
5e29a5
 	if (lv_is_thin_pool(lv) || lv_is_cache_pool(lv)) {
5e29a5
 		log_error(INTERNAL_ERROR "LV %s is already a pool.", display_lvname(lv));
5e29a5
 		return 0;
5e29a5
@@ -3339,6 +3381,9 @@ static int _lvconvert_to_cache_vol(struct cmd_context *cmd,
5e29a5
 	struct dm_config_tree *policy_settings = NULL;
5e29a5
 	int r = 0;
5e29a5
 
5e29a5
+	if (_raid_split_image_conversion(lv))
5e29a5
+		return 0;
5e29a5
+
5e29a5
 	/* If LV is inactive here, ensure it's not active elsewhere. */
5e29a5
 	if (!lockd_lv(cmd, lv, "ex", 0))
5e29a5
 		return_0;