Skip to contentSkip to conversation

master - lvchange: allow change of cache mode

PATCH Zdenek Kabelac 1 participant 1 message May 19, 2016

lore
Share & tools
lore
#0 lore raw
Gitweb:        http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=197066c863607a884c0eef2f16d969aa00adcab1
Commit:        197066c863607a884c0eef2f16d969aa00adcab1
Parent:        8fd886f735125de4b3e32fc0a188af0192a0d173
Author:        Zdenek Kabelac <[email protected]>
AuthorDate:    Mon Apr 25 13:39:30 2016 +0200
Committer:     Zdenek Kabelac <[email protected]>
CommitterDate: Thu May 19 18:40:14 2016 +0200

lvchange: allow change of cache mode

Add support for active cache LV.
Handle --cachemode args validation during command line processing. Rework some lvm2 internal to use lvm2 defined CACHE_MODE enums indepently on libdm defines and use enum around the code instead of passing and comparing strings.

---
 WHATS_NEW                        |    1 +
 lib/cache_segtype/cache.c        |   61 ++++++++++++------
 lib/metadata/cache_manip.c       |  132 ++++++++++++++++++++++---------------
 lib/metadata/merge.c             |   21 +++----
 lib/metadata/metadata-exported.h |   18 ++++--
 lib/report/report.c              |   13 +----
 man/lvchange.8.in                |   18 +++++
 test/shell/lvconvert-cache.sh    |    4 +-
 tools/args.h                     |    2 +-
 tools/commands.h                 |    4 +-
 tools/lvchange.c                 |   50 +++++++++++---
 tools/lvconvert.c                |    8 +-
 tools/lvmcmdline.c               |   13 ++++
 tools/toollib.c                  |    6 +-
 tools/toollib.h                  |    2 +-
 tools/tools.h                    |    1 +
 16 files changed, 227 insertions(+), 127 deletions(-)
WHATS_NEW +1 -0
index 9b9265c..645e87e 100644
@@ -1,5 +1,6 @@
 Version 2.02.155 - 
 ================================
+  Add support for lvchange --cachemode for cached LV.
   Fix liblvm2app error handling when setting up context.
   Delay liblvm2app init in python code until it is needed.
   Simplify thread locking in lvmetad to fix locking problems.
lib/cache_segtype/cache.c +40 -21

126 lines not on this page · raw message

lib/metadata/cache_manip.c +78 -54

219 lines not on this page · raw message

lib/metadata/merge.c +9 -12
index 17227c1..4f730e0 100644
@@ -223,18 +223,15 @@ int check_lv_segments(struct logical_volume *lv, int complete_vg)
 			}
 			if (seg_is_cache_pool(seg) &&
 			    !dm_list_empty(&seg->lv->segs_using_this_lv)) {
-				switch (seg->feature_flags &
-					(DM_CACHE_FEATURE_PASSTHROUGH |
-					 DM_CACHE_FEATURE_WRITETHROUGH |
-					 DM_CACHE_FEATURE_WRITEBACK)) {
-					 case DM_CACHE_FEATURE_PASSTHROUGH:
-					 case DM_CACHE_FEATURE_WRITETHROUGH:
-					 case DM_CACHE_FEATURE_WRITEBACK:
-						 break;
-					 default:
-						 log_error("LV %s has invalid cache's feature flag.",
-							   lv->name);
-						 inc_error_count;
+				switch (seg->cache_mode) {
+				case CACHE_MODE_WRITETHROUGH:
+				case CACHE_MODE_WRITEBACK:
+				case CACHE_MODE_PASSTHROUGH:
+					break;
+				default:
+					log_error("LV %s has invalid cache's feature flag.",
+						  lv->name);
+					inc_error_count;
 				}
 				if (!seg->policy_name) {
 					log_error("LV %s is missing cache policy name.", lv->name);
lib/metadata/metadata-exported.h +13 -5
index b3f450a..a850492 100644
@@ -274,6 +274,13 @@ typedef enum {
 } thin_discards_t;
 
 typedef enum {
+	CACHE_MODE_UNDEFINED = 0,
+	CACHE_MODE_WRITETHROUGH,
+	CACHE_MODE_WRITEBACK,
+	CACHE_MODE_PASSTHROUGH,
+} cache_mode_t;
+
+typedef enum {
 	LOCK_TYPE_INVALID = -1,
 	LOCK_TYPE_NONE = 0,
 	LOCK_TYPE_CLVM = 1,
@@ -472,7 +479,7 @@ struct lv_segment {
 	struct logical_volume *pool_lv;		/* For thin, cache */
 	uint32_t device_id;			/* For thin, 24bit */
 
-	uint64_t feature_flags;			/* For cache_pool */
+	cache_mode_t cache_mode;		/* For cache_pool */
 	const char *policy_name;		/* For cache_pool */
 	struct dm_config_node *policy_settings;	/* For cache_pool */
 	unsigned cleaner_policy;		/* For cache */
@@ -948,7 +955,7 @@ struct lvcreate_params {
 	uint32_t min_recovery_rate; /* RAID */
 	uint32_t max_recovery_rate; /* RAID */
 
-	const char *cache_mode; /* cache */
+	cache_mode_t cache_mode; /* cache */
 	const char *policy_name; /* cache */
 	struct dm_config_tree *policy_settings; /* cache */
 
@@ -1211,13 +1218,14 @@ struct lv_status_cache {
 	dm_percent_t dirty_usage;
 };
 
+const char *display_cache_mode(const struct lv_segment *seg);
 const char *get_cache_mode_name(const struct lv_segment *cache_seg);
-int cache_mode_is_set(const struct lv_segment *seg);
-int cache_set_mode(struct lv_segment *cache_seg, const char *str);
+int set_cache_mode(cache_mode_t *mode, const char *cache_mode);
+int cache_set_cache_mode(struct lv_segment *cache_seg, cache_mode_t mode);
 int cache_set_policy(struct lv_segment *cache_seg, const char *name,
 		     const struct dm_config_tree *settings);
 int cache_set_params(struct lv_segment *seg,
-		     const char *cache_mode,
+		     cache_mode_t mode,
 		     const char *policy_name,
 		     const struct dm_config_tree *policy_settings,
 		     uint32_t chunk_size);
lib/report/report.c +1 -12
index 3a58cee..92eb64c 100644
@@ -2504,19 +2504,8 @@ static int _cachemode_disp(struct dm_report *rh, struct dm_pool *mem,
 			   const void *data, void *private)
 {
 	const struct lv_segment *seg = (const struct lv_segment *) data;
-	const char *cachemode_str;
 
-	if (seg_is_cache(seg))
-		seg = first_seg(seg->pool_lv);
-
-	if (seg_is_cache_pool(seg) && cache_mode_is_set(seg)) {
-		if (!(cachemode_str = get_cache_mode_name(seg)))
-			return_0;
-
-		return _field_string(rh, field, cachemode_str);
-	}
-
-	return _field_set_value(field, "", NULL);
+	return _field_string(rh, field, display_cache_mode(seg));
 }
 
 static int _originsize_disp(struct dm_report *rh, struct dm_pool *mem,
man/lvchange.8.in +18 -0
index 34ce583..2bfe7c0 100644
@@ -25,6 +25,8 @@ lvchange \(em change attributes of a logical volume
 .IR AllocationPolicy ]
 .RB [ \-A | \-\-autobackup
 .RB { y | n }]
+.RB [ \-\-cachemode
+.RB { passthrough | writeback | writethrough }]
 .RB [ \-\-cachepolicy
 .IR Policy ]
 .RB [ \-\-cachesettings
@@ -186,6 +188,22 @@ the flag is attached, use \fBlvs\fP(8) command where the state
 of the flag is reported within \fBlv_attr\fP bits.
 .
 .HP
+.BR \-\-cachemode
+.RB { passthrough | writeback | writethrough }
+.br
+Specifying a cache mode determines when the writes to a cache LV
+are considered complete.  When \fBwriteback\fP is specified, a write is
+considered complete as soon as it is stored in the cache pool LV.
+If \fBwritethough\fP is specified, a write is considered complete only
+when it has been stored in the cache pool LV and on the origin LV.
+While \fBwritethrough\fP may be slower for writes, it is more
+resilient if something should happen to a device associated with the
+cache pool LV. With \fBpassthrough\fP mode, all reads are served
+from origin LV (all reads miss the cache) and all writes are
+forwarded to the origin LV; additionally, write hits cause cache
+block invalidates. See \fBlvmcache(7)\fP for more details.
+.
+.HP
 .BR  \-\-cachepolicy
 .IR Policy ,
 .BR \-\-cachesettings
test/shell/lvconvert-cache.sh +2 -2
index 8e38050..cab5964 100644
@@ -1,5 +1,5 @@
 #!/bin/sh
-# Copyright (C) 2014-2015 Red Hat, Inc. All rights reserved.
+# Copyright (C) 2014-2016 Red Hat, Inc. All rights reserved.
 #
 # This copyrighted material is made available to anyone wishing to use,
 # modify, copy, or redistribute it subject to the terms and conditions
@@ -39,7 +39,7 @@ lvcreate -an -Zn -L 8 -n $lv4 $vg
 lvcreate -an -Zn -L 16 -n $lv5 $vg
 
 # check validation of cachemode arg works
-fail lvconvert --yes --type cache-pool --cachemode writethroughX --cachepool $vg/$lv1
+invalid lvconvert --yes --type cache-pool --cachemode writethroughX --cachepool $vg/$lv1
 
 # by default no cache settings are attached to converted cache-pool
 lvconvert --yes --type cache-pool --chunksize 256 $vg/$lv1
tools/args.h +1 -1
index ebddd2e..ef9dbc9 100644
@@ -27,7 +27,7 @@ arg(atversion_ARG, '\0', "atversion", string_arg, 0)
 arg(binary_ARG, '\0', "binary", NULL, 0)
 arg(bootloaderareasize_ARG, '\0', "bootloaderareasize", size_mb_arg, 0)
 arg(cache_long_ARG, '\0', "cache", NULL, 0)
-arg(cachemode_ARG, '\0', "cachemode", string_arg, 0)
+arg(cachemode_ARG, '\0', "cachemode", cachemode_arg, 0)
 arg(cachepool_ARG, '\0', "cachepool", string_arg, 0)
 arg(commandprofile_ARG, '\0', "commandprofile", string_arg, 0)
 arg(config_ARG, '\0', "config", string_arg, 0)
tools/commands.h +3 -1
index 7b32835..da432a7 100644
@@ -146,6 +146,7 @@ xx(lvchange,
    "\t[--addtag <Tag>]\n"
    "\t[--alloc <AllocationPolicy>]\n"
    "\t[-C|--contiguous {y|n}]\n"
+   "\t[--cachemode <CacheMode>]\n"
    "\t[--cachepolicy <policyname>] [--cachesettings <parameter=value>]\n"
    "\t[--commandprofile <ProfileName>]\n"
    "\t[-d|--debug]\n"
@@ -185,7 +186,8 @@ xx(lvchange,
    "\t<LogicalVolume[Path]> [<LogicalVolume[Path]>...]\n",
 
    activationmode_ARG, addtag_ARG, alloc_ARG, autobackup_ARG, activate_ARG,
-   available_ARG, cachepolicy_ARG, cachesettings_ARG, contiguous_ARG, deltag_ARG,
+   available_ARG, cachemode_ARG, cachepolicy_ARG, cachesettings_ARG,
+   contiguous_ARG, deltag_ARG,
    discards_ARG, detachprofile_ARG, errorwhenfull_ARG, force_ARG,
    ignorelockingfailure_ARG, ignoremonitoring_ARG, ignoreactivationskip_ARG,
    ignoreskippedcluster_ARG, major_ARG, metadataprofile_ARG, minor_ARG,
tools/lvchange.c +39 -11

84 lines not on this page · raw message

tools/lvconvert.c +4 -4
index c544e36..39ce759 100644
@@ -51,7 +51,7 @@ struct lvconvert_params {
 	uint32_t stripes;
 	uint32_t stripe_size;
 	uint32_t read_ahead;
-	const char *cache_mode; /* cache */
+	cache_mode_t cache_mode; /* cache */
 	const char *policy_name; /* cache */
 	struct dm_config_tree *policy_settings; /* cache */
 
@@ -2024,7 +2024,7 @@ static int _lvconvert_uncache(struct cmd_context *cmd,
 
 	/* TODO: Check for failed cache as well to get prompting? */
 	if (lv_is_partial(lv)) {
-		if (strcmp("writethrough", get_cache_mode_name(first_seg(seg->pool_lv)))) {
+		if (first_seg(seg->pool_lv)->cache_mode != CACHE_MODE_WRITETHROUGH) {
 			if (!lp->force) {
 				log_error("Conversion aborted.");
 				log_error("Cannot uncache writethrough cache volume %s without --force.",
@@ -3116,7 +3116,7 @@ mda_write:
 	seg->zero_new_blocks = lp->zero ? 1 : 0;
 
 	if (lp->cache_mode &&
-	    !cache_set_mode(seg, lp->cache_mode))
+	    !cache_set_cache_mode(seg, lp->cache_mode))
 		return_0;
 
 	if ((lp->policy_name || lp->policy_settings) &&
@@ -3228,7 +3228,7 @@ static int _lvconvert_cache(struct cmd_context *cmd,
 	if (!(cache_lv = lv_cache_create(pool_lv, origin_lv)))
 		return_0;
 
-	if (!cache_set_mode(first_seg(cache_lv), lp->cache_mode))
+	if (!cache_set_cache_mode(first_seg(cache_lv), lp->cache_mode))
 		return_0;
 
 	if (!cache_set_policy(first_seg(cache_lv), lp->policy_name, lp->policy_settings))
tools/lvmcmdline.c +13 -0
index fa9cd8f..4009921 100644
@@ -328,6 +328,19 @@ int activation_arg(struct cmd_context *cmd __attribute__((unused)), struct arg_v
 	return 1;
 }
 
+int cachemode_arg(struct cmd_context *cmd __attribute__((unused)), struct arg_values *av)
+{
+	cache_mode_t mode;
+
+	if (!set_cache_mode(&mode, av->value))
+		return_0;
+
+	av->i_value = mode;
+	av->ui_value = mode;
+
+	return 1;
+}
+
 int discards_arg(struct cmd_context *cmd __attribute__((unused)), struct arg_values *av)
 {
 	thin_discards_t discards;
tools/toollib.c +3 -3
index ab1361d..4859ec0 100644
@@ -1334,7 +1334,7 @@ static int _validate_cachepool_params(const char *name,
 }
 
 int get_cache_params(struct cmd_context *cmd,
-		     const char **mode,
+		     cache_mode_t *cache_mode,
 		     const char **name,
 		     struct dm_config_tree **settings)
 {
@@ -1344,8 +1344,8 @@ int get_cache_params(struct cmd_context *cmd,
 	struct dm_config_node *cn;
 	int ok = 0;
 
-	if (mode)
-		*mode = arg_str_value(cmd, cachemode_ARG, NULL);
+	if (cache_mode)
+		*cache_mode = (cache_mode_t) arg_uint_value(cmd, cachemode_ARG, CACHE_MODE_UNDEFINED);
 
 	if (name)
 		*name = arg_str_value(cmd, cachepolicy_ARG, NULL);
tools/toollib.h +1 -1
index 19f4dd0..2b3ca6e 100644
@@ -194,7 +194,7 @@ int get_stripe_params(struct cmd_context *cmd, uint32_t *stripes,
 		      uint32_t *stripe_size);
 
 int get_cache_params(struct cmd_context *cmd,
-		     const char **mode,
+		     cache_mode_t *cache_mode,
 		     const char **name,
 		     struct dm_config_tree **settings);
 
tools/tools.h +1 -0
index cfb79de..2abc750 100644
@@ -133,6 +133,7 @@ void usage(const char *name);
 /* the argument verify/normalise functions */
 int yes_no_arg(struct cmd_context *cmd, struct arg_values *av);
 int activation_arg(struct cmd_context *cmd, struct arg_values *av);
+int cachemode_arg(struct cmd_context *cmd, struct arg_values *av);
 int discards_arg(struct cmd_context *cmd, struct arg_values *av);
 int mirrorlog_arg(struct cmd_context *cmd, struct arg_values *av);
 int size_kb_arg(struct cmd_context *cmd, struct arg_values *av);