Blame SOURCES/0047-vdo-support-vdosettings.patch

ab86b0
From 9c6954bc61b22ca03df8897d88eb9618e65fc3c6 Mon Sep 17 00:00:00 2001
ab86b0
From: Zdenek Kabelac <zkabelac@redhat.com>
ab86b0
Date: Wed, 13 Apr 2022 15:09:08 +0200
ab86b0
Subject: [PATCH 47/54] vdo: support --vdosettings
ab86b0
ab86b0
Allow to use --vdosettings with lvcreate,lvconvert,lvchange.
ab86b0
Support settings currenly only configurable via lvm.conf.
ab86b0
With lvchange we require inactivate LV for changes to be applied.
ab86b0
ab86b0
Settings block_map_era_length has supported alias block_map_period.
ab86b0
---
ab86b0
 device_mapper/vdo/target.h  |   6 +-
ab86b0
 man/lvmvdo.7_main           |  39 ++++++--
ab86b0
 test/shell/lvchange-vdo.sh  |   8 ++
ab86b0
 test/shell/lvconvert-vdo.sh |   8 +-
ab86b0
 test/shell/lvcreate-vdo.sh  |   6 +-
ab86b0
 tools/args.h                |   9 ++
ab86b0
 tools/command-lines.in      |   6 +-
ab86b0
 tools/lvchange.c            |  43 ++++++++-
ab86b0
 tools/lvconvert.c           |   9 +-
ab86b0
 tools/lvcreate.c            |  34 ++++---
ab86b0
 tools/toollib.c             | 177 ++++++++++++++++++++++++++++++++++++
ab86b0
 tools/toollib.h             |   6 ++
ab86b0
 12 files changed, 312 insertions(+), 39 deletions(-)
ab86b0
ab86b0
diff --git a/device_mapper/vdo/target.h b/device_mapper/vdo/target.h
ab86b0
index 51dde3f4d..60c5bff56 100644
ab86b0
--- a/device_mapper/vdo/target.h
ab86b0
+++ b/device_mapper/vdo/target.h
ab86b0
@@ -77,8 +77,10 @@ enum dm_vdo_write_policy {
ab86b0
 struct dm_vdo_target_params {
ab86b0
 	uint32_t minimum_io_size;       // in sectors
ab86b0
 	uint32_t block_map_cache_size_mb;
ab86b0
-	uint32_t block_map_era_length;	// format period
ab86b0
-
ab86b0
+	union {
ab86b0
+		uint32_t block_map_era_length;	// format period
ab86b0
+		uint32_t block_map_period;      // supported alias
ab86b0
+	};
ab86b0
 	uint32_t check_point_frequency;
ab86b0
 	uint32_t index_memory_size_mb;  // format
ab86b0
 
ab86b0
diff --git a/man/lvmvdo.7_main b/man/lvmvdo.7_main
ab86b0
index 3b77173c4..14bd640b5 100644
ab86b0
--- a/man/lvmvdo.7_main
ab86b0
+++ b/man/lvmvdo.7_main
ab86b0
@@ -132,6 +132,19 @@ that can keep 100% incompressible data there.
ab86b0
 # lvconvert --type vdo-pool -n vdo0 -V10G vg/ExistingLV
ab86b0
 .fi
ab86b0
 .
ab86b0
+.SS \n+[step]. Change the compression and deduplication of a VDOPoolLV
ab86b0
+.
ab86b0
+Disable or enable the compression and deduplication for VDOPoolLV
ab86b0
+(the volume that maintains all VDO LV(s) associated with it).
ab86b0
+.P
ab86b0
+.B lvchange --compression y|n --deduplication y|n VG/VDOPoolLV
ab86b0
+.P
ab86b0
+.I Example
ab86b0
+.nf
ab86b0
+# lvchange --compression n  vg/vdopool0
ab86b0
+# lvchange --deduplication y vg/vdopool1
ab86b0
+.fi
ab86b0
+.
ab86b0
 .SS \n+[step]. Change the default settings used for creating a VDOPoolLV
ab86b0
 .
ab86b0
 VDO allows to set a large variety of options. Lots of these settings
ab86b0
@@ -173,17 +186,27 @@ EOF
ab86b0
 # lvcreate --vdo -L10G --config 'allocation/vdo_cpu_threads=4' vg/vdopool1
ab86b0
 .fi
ab86b0
 .
ab86b0
-.SS \n+[step]. Change the compression and deduplication of a VDOPoolLV
ab86b0
-.
ab86b0
-Disable or enable the compression and deduplication for VDOPoolLV
ab86b0
-(the volume that maintains all VDO LV(s) associated with it).
ab86b0
-.P
ab86b0
-.B lvchange --compression y|n --deduplication y|n VG/VDOPoolLV
ab86b0
+.SS \n+[step]. Set or change VDO settings with option --vdosettings
ab86b0
+.
ab86b0
+Use the form 'option=value' or 'option1=value option2=value',
ab86b0
+or repeat --vdosettings for each option being set.
ab86b0
+Options are listed in the Example section above, for the full description see
ab86b0
+.BR lvm.conf (5).
ab86b0
+Options can omit 'vdo_' and 'vdo_use_' prefixes and all its underscores.
ab86b0
+So i.e.  vdo_use_metadata_hints=1  and  metadatahints=1 are equivalent.
ab86b0
+To change the option for an already existing VDOPoolLV use
ab86b0
+.BR lvchange (8)
ab86b0
+command. However not all option can be changed.
ab86b0
+Only compression and deduplication options can be also changed for an active VDO LV.
ab86b0
+Lowest priority options are specified with configuration file,
ab86b0
+then with --vdosettings and highest are expliction option --compression
ab86b0
+and --deduplication.
ab86b0
 .P
ab86b0
 .I Example
ab86b0
+.P
ab86b0
 .nf
ab86b0
-# lvchange --compression n  vg/vdopool0
ab86b0
-# lvchange --deduplication y vg/vdopool1
ab86b0
+# lvcreate --vdo -L10G --vdosettings 'ack_threads=1 hash_zone_threads=2' vg/vdopool0
ab86b0
+# lvchange --vdosettings 'bio_threads=2 deduplication=1' vg/vdopool0
ab86b0
 .fi
ab86b0
 .
ab86b0
 .SS \n+[step]. Checking the usage of VDOPoolLV
ab86b0
diff --git a/test/shell/lvchange-vdo.sh b/test/shell/lvchange-vdo.sh
ab86b0
index 461b7821f..7cc44d6bc 100644
ab86b0
--- a/test/shell/lvchange-vdo.sh
ab86b0
+++ b/test/shell/lvchange-vdo.sh
ab86b0
@@ -48,9 +48,17 @@ check grep_dmsetup status $vg-vdopool-vpool " online online "
ab86b0
 lvchange --compression n --deduplication n $vg/vdopool
ab86b0
 check grep_dmsetup status $vg-vdopool-vpool " offline offline "
ab86b0
 
ab86b0
+# --vdosettings needs inactive LV
ab86b0
+not lvchange --vdosettings 'ack_threads=8' $vg/vdopool
ab86b0
 
ab86b0
 lvchange -an $vg/$lv1
ab86b0
 
ab86b0
+# With inactive vdo-pool changes are applied
ab86b0
+# explicit option --compression has highest priority
ab86b0
+lvchange --vdosettings 'ack_threads=5 compression=0' --compression y $vg/vdopool
ab86b0
+check lv_field $vg/$lv1 vdo_ack_threads "5"
ab86b0
+check lv_field $vg/$lv1 vdo_compression "enabled"
ab86b0
+
ab86b0
 # Test activation
ab86b0
 lvchange -aly $vg/$lv1
ab86b0
 check active $vg $lv1
ab86b0
diff --git a/test/shell/lvconvert-vdo.sh b/test/shell/lvconvert-vdo.sh
ab86b0
index 529f325bd..c42d8f25a 100644
ab86b0
--- a/test/shell/lvconvert-vdo.sh
ab86b0
+++ b/test/shell/lvconvert-vdo.sh
ab86b0
@@ -28,12 +28,12 @@ lvcreate -L5G -n $lv1 $vg
ab86b0
 not lvconvert --type vdo-pool $vg/$lv1 |& tee out
ab86b0
 grep "WARNING" out
ab86b0
 
ab86b0
-
ab86b0
-lvconvert -y --type vdo-pool $vg/$lv1
ab86b0
+# Check --vdosettings is also applied to converted vdo-pool
ab86b0
+lvconvert -y --type vdo-pool --vdosettings 'ack_threads=5' $vg/$lv1
ab86b0
+check lv_field $vg/$lv1 vdo_ack_threads "5"
ab86b0
 lvremove -f $vg
ab86b0
 
ab86b0
-
ab86b0
-# 
ab86b0
+#
ab86b0
 lvcreate -L5G -n $lv1 $vg
ab86b0
 lvconvert -y --vdopool $vg/$lv1
ab86b0
 lvremove -f $vg
ab86b0
diff --git a/test/shell/lvcreate-vdo.sh b/test/shell/lvcreate-vdo.sh
ab86b0
index 44f8bf094..3e807ac94 100644
ab86b0
--- a/test/shell/lvcreate-vdo.sh
ab86b0
+++ b/test/shell/lvcreate-vdo.sh
ab86b0
@@ -79,8 +79,12 @@ not fsck -n "$DM_DEV_DIR/mapper/$vg-${lv2}"
ab86b0
 
ab86b0
 lvremove -ff $vg
ab86b0
 
ab86b0
+# Unknown settings does not pass
ab86b0
+# TODO: try to catch this in parser and 'fail'
ab86b0
+not lvcreate --type vdo --vdosettings 'ack_Xthreads=4' -L10G -V1T -ky -n $lv1 $vg
ab86b0
 
ab86b0
-lvcreate --type vdo -L10G -V1T -ky -n $lv1 $vg
ab86b0
+lvcreate --type vdo --vdosettings 'ack_threads=4' -L10G -V1T -ky -n $lv1 $vg
ab86b0
+check lv_field $vg/$lv1 vdo_ack_threads "4"
ab86b0
 lvs -a $vg
ab86b0
 lvremove -ff $vg
ab86b0
 
ab86b0
diff --git a/tools/args.h b/tools/args.h
ab86b0
index 00a2ec817..bfd848ce9 100644
ab86b0
--- a/tools/args.h
ab86b0
+++ b/tools/args.h
ab86b0
@@ -900,6 +900,15 @@ arg(vdopool_ARG, '\0', "vdopool", lv_VAL, 0, 0,
ab86b0
     "The name of a VDO pool LV.\n"
ab86b0
     "See \\fBlvmvdo\\fP(7) for more information about VDO usage.\n")
ab86b0
 
ab86b0
+arg(vdosettings_ARG, '\0', "vdosettings", string_VAL, ARG_GROUPABLE, 0,
ab86b0
+    "Specifies tunable VDO options for VDO LVs.\n"
ab86b0
+    "Use the form 'option=value' or 'option1=value option2=value', or\n"
ab86b0
+    "repeat --vdosettings for each option being set.\n"
ab86b0
+    "These settings override the default VDO behaviors.\n"
ab86b0
+    "To remove vdosettings and revert to the default\n"
ab86b0
+    "VDO behaviors, use --vdosettings 'default'.\n"
ab86b0
+    "See \\fBlvmvdo\\fP(7) for more information.\n")
ab86b0
+
ab86b0
 arg(version_ARG, '\0', "version", 0, 0, 0,
ab86b0
     "Display version information.\n")
ab86b0
 
ab86b0
diff --git a/tools/command-lines.in b/tools/command-lines.in
ab86b0
index 00ac08934..08302b34f 100644
ab86b0
--- a/tools/command-lines.in
ab86b0
+++ b/tools/command-lines.in
ab86b0
@@ -243,6 +243,7 @@ OO_LVCHANGE_META: --addtag Tag, --deltag Tag,
ab86b0
 --setautoactivation Bool, --errorwhenfull Bool, --discards Discards, --zero Bool,
ab86b0
 --cachemode CacheMode, --cachepolicy String, --cachesettings String,
ab86b0
 --minrecoveryrate SizeKB, --maxrecoveryrate SizeKB,
ab86b0
+--vdosettings String,
ab86b0
 --writebehind Number, --writemostly WriteMostlyPV, --persistent n
ab86b0
 
ab86b0
 # It's unfortunate that activate needs to be optionally allowed here;
ab86b0
@@ -341,7 +342,8 @@ OO_LVCONVERT_CACHE: --cachemetadataformat CacheMetadataFormat,
ab86b0
 --cachesettings String, --zero Bool
ab86b0
 
ab86b0
 OO_LVCONVERT_VDO: --metadataprofile String, --readahead Readahead,
ab86b0
---compression Bool, --deduplication Bool, --zero Bool
ab86b0
+--compression Bool, --deduplication Bool, --vdosettings String,
ab86b0
+--zero Bool
ab86b0
 
ab86b0
 OO_LVCONVERT: --alloc Alloc, --background, --force, --noudevsync
ab86b0
 
ab86b0
@@ -839,7 +841,7 @@ OO_LVCREATE_POOL: --poolmetadatasize SizeMB, --poolmetadataspare Bool, --chunksi
ab86b0
 
ab86b0
 OO_LVCREATE_THINPOOL: --discards Discards, --errorwhenfull Bool
ab86b0
 
ab86b0
-OO_LVCREATE_VDO: --compression Bool, --deduplication Bool
ab86b0
+OO_LVCREATE_VDO: --compression Bool, --deduplication Bool, --vdosettings String
ab86b0
 ---
ab86b0
 
ab86b0
 lvcreate --type error --size SizeMB VG
ab86b0
diff --git a/tools/lvchange.c b/tools/lvchange.c
ab86b0
index 0525bc53c..dc51786d7 100644
ab86b0
--- a/tools/lvchange.c
ab86b0
+++ b/tools/lvchange.c
ab86b0
@@ -755,6 +755,43 @@ out:
ab86b0
 	return r;
ab86b0
 }
ab86b0
 
ab86b0
+static int _lvchange_vdo(struct cmd_context *cmd,
ab86b0
+			 struct logical_volume *lv,
ab86b0
+			 uint32_t *mr)
ab86b0
+{
ab86b0
+	struct lv_segment *seg;
ab86b0
+	int updated = 0;
ab86b0
+
ab86b0
+	seg = first_seg(lv);
ab86b0
+
ab86b0
+	// With VDO LV given flip to VDO pool
ab86b0
+	if (seg_is_vdo(seg))
ab86b0
+		seg = first_seg(seg_lv(seg, 0));
ab86b0
+
ab86b0
+	if (!get_vdo_settings(cmd, &seg->vdo_params, &updated))
ab86b0
+		return_0;
ab86b0
+
ab86b0
+	if ((updated & VDO_CHANGE_OFFLINE) &&
ab86b0
+	    lv_info(cmd, seg->lv, 1, NULL, 0, 0)) {
ab86b0
+		log_error("Cannot change VDO settings for active VDO pool %s.",
ab86b0
+			  display_lvname(seg->lv));
ab86b0
+		// TODO maybe add --force support with prompt here
ab86b0
+		log_print_unless_silent("VDO pool %s with all its LVs needs to be deactivated.",
ab86b0
+					display_lvname(seg->lv));
ab86b0
+		return 0;
ab86b0
+	}
ab86b0
+
ab86b0
+	if (updated) {
ab86b0
+		if (!dm_vdo_validate_target_params(&seg->vdo_params, 0 /* vdo_size */))
ab86b0
+			return_0;
ab86b0
+
ab86b0
+		/* Request caller to commit and reload metadata */
ab86b0
+		*mr |= MR_RELOAD;
ab86b0
+	}
ab86b0
+
ab86b0
+	return 1;
ab86b0
+}
ab86b0
+
ab86b0
 static int _lvchange_tag(struct cmd_context *cmd, struct logical_volume *lv,
ab86b0
 			 int arg, uint32_t *mr)
ab86b0
 {
ab86b0
@@ -1154,6 +1191,7 @@ static int _option_requires_direct_commit(int opt_enum)
ab86b0
 		cachemode_ARG,
ab86b0
 		cachepolicy_ARG,
ab86b0
 		cachesettings_ARG,
ab86b0
+		vdosettings_ARG,
ab86b0
 		-1
ab86b0
 	};
ab86b0
 
ab86b0
@@ -1354,7 +1392,10 @@ static int _lvchange_properties_single(struct cmd_context *cmd,
ab86b0
 			docmds++;
ab86b0
 			doit += _lvchange_cache(cmd, lv, &mr;;
ab86b0
 			break;
ab86b0
-
ab86b0
+		case vdosettings_ARG:
ab86b0
+			docmds++;
ab86b0
+			doit += _lvchange_vdo(cmd, lv, &mr;;
ab86b0
+			break;
ab86b0
 		default:
ab86b0
 			log_error(INTERNAL_ERROR "Failed to check for option %s",
ab86b0
 				  arg_long_option_name(i));
ab86b0
diff --git a/tools/lvconvert.c b/tools/lvconvert.c
ab86b0
index a90946173..3d4b24fe3 100644
ab86b0
--- a/tools/lvconvert.c
ab86b0
+++ b/tools/lvconvert.c
ab86b0
@@ -5456,13 +5456,8 @@ static int _lvconvert_to_vdopool_single(struct cmd_context *cmd,
ab86b0
 	if (!fill_vdo_target_params(cmd, &vdo_params, &vdo_pool_header_size, vg->profile))
ab86b0
 		goto_out;
ab86b0
 
ab86b0
-	if (arg_is_set(cmd, compression_ARG))
ab86b0
-		vdo_params.use_compression =
ab86b0
-			arg_int_value(cmd, compression_ARG, 0);
ab86b0
-
ab86b0
-	if (arg_is_set(cmd, deduplication_ARG))
ab86b0
-		vdo_params.use_deduplication =
ab86b0
-			arg_int_value(cmd, deduplication_ARG, 0);
ab86b0
+	if (!get_vdo_settings(cmd, &vdo_params, NULL))
ab86b0
+		return_0;
ab86b0
 
ab86b0
 	if (!activate_lv(cmd, lv)) {
ab86b0
 		log_error("Cannot activate %s.", display_lvname(lv));
ab86b0
diff --git a/tools/lvcreate.c b/tools/lvcreate.c
ab86b0
index 79af42685..8de6f3408 100644
ab86b0
--- a/tools/lvcreate.c
ab86b0
+++ b/tools/lvcreate.c
ab86b0
@@ -698,6 +698,23 @@ static int _read_cache_params(struct cmd_context *cmd,
ab86b0
 	return 1;
ab86b0
 }
ab86b0
 
ab86b0
+static int _read_vdo_params(struct cmd_context *cmd,
ab86b0
+			    struct lvcreate_params *lp)
ab86b0
+{
ab86b0
+	if (!seg_is_vdo(lp))
ab86b0
+		return 1;
ab86b0
+
ab86b0
+	// prefiling settings here
ab86b0
+	if (!fill_vdo_target_params(cmd, &lp->vdo_params,  &lp->vdo_pool_header_size, NULL))
ab86b0
+		return_0;
ab86b0
+
ab86b0
+	// override with optional vdo settings
ab86b0
+	if (!get_vdo_settings(cmd, &lp->vdo_params, NULL))
ab86b0
+		return_0;
ab86b0
+
ab86b0
+	return 1;
ab86b0
+}
ab86b0
+
ab86b0
 static int _read_activation_params(struct cmd_context *cmd,
ab86b0
 				   struct volume_group *vg,
ab86b0
 				   struct lvcreate_params *lp)
ab86b0
@@ -888,7 +905,8 @@ static int _lvcreate_params(struct cmd_context *cmd,
ab86b0
 #define VDO_POOL_ARGS \
ab86b0
 	vdopool_ARG,\
ab86b0
 	compression_ARG,\
ab86b0
-	deduplication_ARG
ab86b0
+	deduplication_ARG,\
ab86b0
+	vdosettings_ARG
ab86b0
 
ab86b0
 	/* Cache and cache-pool segment type */
ab86b0
 	if (seg_is_cache(lp)) {
ab86b0
@@ -1098,19 +1116,6 @@ static int _lvcreate_params(struct cmd_context *cmd,
ab86b0
 						zero_ARG,
ab86b0
 						-1))
ab86b0
 			return_0;
ab86b0
-
ab86b0
-		// FIXME: prefiling here - this is wrong place
ab86b0
-		// but will work for this moment
ab86b0
-		if (!fill_vdo_target_params(cmd, &lp->vdo_params, &lp->vdo_pool_header_size, NULL))
ab86b0
-			return_0;
ab86b0
-
ab86b0
-		if (arg_is_set(cmd, compression_ARG))
ab86b0
-			lp->vdo_params.use_compression =
ab86b0
-				arg_int_value(cmd, compression_ARG, 0);
ab86b0
-
ab86b0
-		if (arg_is_set(cmd, deduplication_ARG))
ab86b0
-			lp->vdo_params.use_deduplication =
ab86b0
-				arg_int_value(cmd, deduplication_ARG, 0);
ab86b0
 	}
ab86b0
 
ab86b0
 	/* Check options shared between more segment types */
ab86b0
@@ -1198,6 +1203,7 @@ static int _lvcreate_params(struct cmd_context *cmd,
ab86b0
 			      &lp->pool_metadata_size, &lp->pool_metadata_spare,
ab86b0
 			      &lp->chunk_size, &lp->discards, &lp->zero_new_blocks)) ||
ab86b0
 	    !_read_cache_params(cmd, lp) ||
ab86b0
+	    !_read_vdo_params(cmd, lp) ||
ab86b0
 	    !_read_mirror_and_raid_params(cmd, lp))
ab86b0
 		return_0;
ab86b0
 
ab86b0
diff --git a/tools/toollib.c b/tools/toollib.c
ab86b0
index 16be336d4..697baee82 100644
ab86b0
--- a/tools/toollib.c
ab86b0
+++ b/tools/toollib.c
ab86b0
@@ -1192,6 +1192,183 @@ out:
ab86b0
 	return ok;
ab86b0
 }
ab86b0
 
ab86b0
+/*
ab86b0
+ * Compare VDO option name, skip any '_' in name
ab86b0
+ * and also allow to use it without  vdo_[use_] prefix
ab86b0
+ */
ab86b0
+static int _compare_vdo_option(const char *b1, const char *b2)
ab86b0
+{
ab86b0
+	if (strncasecmp(b1, "vdo", 3) == 0) // skip vdo prefix
ab86b0
+		b1 += 3;
ab86b0
+
ab86b0
+	if ((tolower(*b1) != tolower(*b2)) &&
ab86b0
+	    (strncmp(b2, "use_", 4) == 0))
ab86b0
+		b2 += 4;  // try again with skipped prefix 'use_'
ab86b0
+
ab86b0
+	while (*b1 && *b2) {
ab86b0
+		if (tolower(*b1) == tolower(*b2)) {
ab86b0
+			++b1;
ab86b0
+			++b2;
ab86b0
+			continue;	// matching char
ab86b0
+		}
ab86b0
+
ab86b0
+		if (*b1 == '_')
ab86b0
+			++b1;           // skip to next char
ab86b0
+		else if (*b2 == '_')
ab86b0
+			++b2;           // skip to next char
ab86b0
+		else
ab86b0
+			break;          // mismatch
ab86b0
+	}
ab86b0
+
ab86b0
+	return (*b1 || *b2) ? 0 : 1;
ab86b0
+}
ab86b0
+
ab86b0
+#define CHECK_AND_SET(var, onoff) \
ab86b0
+	option = #var;\
ab86b0
+	if (_compare_vdo_option(cn->key, option)) {\
ab86b0
+		if (is_lvchange || !cn->v || (cn->v->type != DM_CFG_INT))\
ab86b0
+			goto err;\
ab86b0
+		if (vtp->var != cn->v->v.i) {\
ab86b0
+			vtp->var = cn->v->v.i;\
ab86b0
+			u |= onoff;\
ab86b0
+		}\
ab86b0
+		continue;\
ab86b0
+	}
ab86b0
+
ab86b0
+#define DO_OFFLINE(var) \
ab86b0
+	CHECK_AND_SET(var, VDO_CHANGE_OFFLINE)
ab86b0
+
ab86b0
+#define DO_ONLINE(var) \
ab86b0
+	CHECK_AND_SET(var, VDO_CHANGE_ONLINE)
ab86b0
+
ab86b0
+int get_vdo_settings(struct cmd_context *cmd,
ab86b0
+		     struct dm_vdo_target_params *vtp,
ab86b0
+		     int *updated)
ab86b0
+{
ab86b0
+	const char *str, *option = NULL;
ab86b0
+	struct arg_value_group_list *group;
ab86b0
+	struct dm_config_tree *result = NULL, *prev = NULL, *current = NULL;
ab86b0
+	struct dm_config_node *cn;
ab86b0
+	int r = 0, u = 0, is_lvchange;
ab86b0
+	int use_compression = vtp->use_compression;
ab86b0
+	int use_deduplication = vtp->use_deduplication;
ab86b0
+	int checked_lvchange;
ab86b0
+
ab86b0
+	if (updated)
ab86b0
+		*updated = 0;
ab86b0
+
ab86b0
+	// Group all --vdosettings
ab86b0
+	dm_list_iterate_items(group, &cmd->arg_value_groups) {
ab86b0
+		if (!grouped_arg_is_set(group->arg_values, vdosettings_ARG))
ab86b0
+			continue;
ab86b0
+
ab86b0
+		if (!(current = dm_config_create()))
ab86b0
+			goto_out;
ab86b0
+		if (prev)
ab86b0
+			current->cascade = prev;
ab86b0
+		prev = current;
ab86b0
+
ab86b0
+		if (!(str = grouped_arg_str_value(group->arg_values,
ab86b0
+						  vdosettings_ARG,
ab86b0
+						  NULL)))
ab86b0
+			goto_out;
ab86b0
+
ab86b0
+		if (!dm_config_parse_without_dup_node_check(current, str, str + strlen(str)))
ab86b0
+			goto_out;
ab86b0
+	}
ab86b0
+
ab86b0
+	if (current) {
ab86b0
+		if (!(result = dm_config_flatten(current)))
ab86b0
+			goto_out;
ab86b0
+
ab86b0
+		checked_lvchange = !strcmp(cmd->name, "lvchange");
ab86b0
+
ab86b0
+		/* Use all acceptable VDO options */
ab86b0
+		for (cn = result->root; cn; cn = cn->sib) {
ab86b0
+			is_lvchange = 0;
ab86b0
+			DO_OFFLINE(ack_threads);
ab86b0
+			DO_OFFLINE(bio_rotation);
ab86b0
+			DO_OFFLINE(bio_threads);
ab86b0
+			DO_OFFLINE(block_map_cache_size_mb);
ab86b0
+			DO_OFFLINE(block_map_era_length);
ab86b0
+			DO_OFFLINE(block_map_period); // alias for block_map_era_length
ab86b0
+			DO_OFFLINE(cpu_threads);
ab86b0
+			DO_OFFLINE(hash_zone_threads);
ab86b0
+			DO_OFFLINE(logical_threads);
ab86b0
+			DO_OFFLINE(max_discard);
ab86b0
+			DO_OFFLINE(physical_threads);
ab86b0
+
ab86b0
+			// Support also these - even when we have regular opts for them
ab86b0
+			DO_ONLINE(use_compression);
ab86b0
+			DO_ONLINE(use_deduplication);
ab86b0
+
ab86b0
+			// Settings bellow cannot be changed with lvchange command
ab86b0
+			is_lvchange = checked_lvchange;
ab86b0
+
ab86b0
+			DO_OFFLINE(check_point_frequency);
ab86b0
+			DO_OFFLINE(index_memory_size_mb);
ab86b0
+			DO_OFFLINE(minimum_io_size);
ab86b0
+			DO_OFFLINE(slab_size_mb);
ab86b0
+			DO_OFFLINE(use_metadata_hints);
ab86b0
+			DO_OFFLINE(use_sparse_index);
ab86b0
+
ab86b0
+			option = "write_policy";
ab86b0
+			if (_compare_vdo_option(cn->key, option)) {
ab86b0
+				if (is_lvchange || !cn->v || (cn->v->type != DM_CFG_STRING))
ab86b0
+					goto err;
ab86b0
+				if (!set_vdo_write_policy(&vtp->write_policy, cn->v->v.str))
ab86b0
+					goto_out;
ab86b0
+				u |= VDO_CHANGE_OFFLINE;
ab86b0
+				continue;
ab86b0
+			}
ab86b0
+
ab86b0
+			log_error("Unknown VDO setting \"%s\".", cn->key);
ab86b0
+			goto out;
ab86b0
+		}
ab86b0
+	}
ab86b0
+
ab86b0
+	if (arg_is_set(cmd, compression_ARG)) {
ab86b0
+		vtp->use_compression = arg_int_value(cmd, compression_ARG, 0);
ab86b0
+		if (vtp->use_compression != use_compression)
ab86b0
+			u |= VDO_CHANGE_ONLINE;
ab86b0
+	}
ab86b0
+
ab86b0
+	if (arg_is_set(cmd, deduplication_ARG)) {
ab86b0
+		vtp->use_deduplication = arg_int_value(cmd, deduplication_ARG, 0);
ab86b0
+		if (vtp->use_deduplication != use_deduplication)
ab86b0
+			u |= VDO_CHANGE_ONLINE;
ab86b0
+	}
ab86b0
+
ab86b0
+	if (updated) {
ab86b0
+		// validation of updated VDO option
ab86b0
+		if (!dm_vdo_validate_target_params(vtp, 0 /* vdo_size */)) {
ab86b0
+err:
ab86b0
+			if (is_lvchange)
ab86b0
+				log_error("Cannot change VDO setting \"vdo_%s\" in existing VDO pool.",
ab86b0
+					  option);
ab86b0
+			else
ab86b0
+				log_error("Invalid argument for VDO setting \"vdo_%s\".",
ab86b0
+					  option);
ab86b0
+			goto out;
ab86b0
+		}
ab86b0
+
ab86b0
+		*updated = u;
ab86b0
+	}
ab86b0
+
ab86b0
+	r = 1;
ab86b0
+out:
ab86b0
+	if (result)
ab86b0
+		dm_config_destroy(result);
ab86b0
+
ab86b0
+	while (prev) {
ab86b0
+		current = prev->cascade;
ab86b0
+		dm_config_destroy(prev);
ab86b0
+		prev = current;
ab86b0
+	}
ab86b0
+
ab86b0
+	return r;
ab86b0
+}
ab86b0
+
ab86b0
 static int _get_one_writecache_setting(struct cmd_context *cmd, struct writecache_settings *settings,
ab86b0
 				       char *key, char *val, uint32_t *block_size_sectors)
ab86b0
 {
ab86b0
diff --git a/tools/toollib.h b/tools/toollib.h
ab86b0
index f3a60fbc4..2b38e4e4f 100644
ab86b0
--- a/tools/toollib.h
ab86b0
+++ b/tools/toollib.h
ab86b0
@@ -217,6 +217,12 @@ int get_cache_params(struct cmd_context *cmd,
ab86b0
 		     const char **name,
ab86b0
 		     struct dm_config_tree **settings);
ab86b0
 
ab86b0
+#define VDO_CHANGE_ONLINE  1
ab86b0
+#define VDO_CHANGE_OFFLINE 2
ab86b0
+int get_vdo_settings(struct cmd_context *cmd,
ab86b0
+		     struct dm_vdo_target_params *vtp,
ab86b0
+		     int *updated);
ab86b0
+
ab86b0
 int get_writecache_settings(struct cmd_context *cmd, struct writecache_settings *settings,
ab86b0
                             uint32_t *block_size_sectors);
ab86b0
 
ab86b0
-- 
ab86b0
2.34.3
ab86b0