master - lvconvert: Set lp->segtype in only one place.
by Alasdair Kergon
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=d0df1ff995f327...
Commit: d0df1ff995f3270232ec5179057482c558119a92
Parent: 1ce958bc5ea2827fdb945b2177616e8f253486a1
Author: Alasdair G Kergon <agk(a)redhat.com>
AuthorDate: Sat Jul 30 18:12:57 2016 +0100
Committer: Alasdair G Kergon <agk(a)redhat.com>
CommitterDate: Sat Jul 30 18:20:04 2016 +0100
lvconvert: Set lp->segtype in only one place.
---
tools/lvconvert.c | 30 ++++++++++++++----------------
1 files changed, 14 insertions(+), 16 deletions(-)
diff --git a/tools/lvconvert.c b/tools/lvconvert.c
index ed3bd88..dd0102f 100644
--- a/tools/lvconvert.c
+++ b/tools/lvconvert.c
@@ -331,6 +331,7 @@ static int _read_pool_params(struct cmd_context *cmd, int *pargc, char ***pargv,
{
int cachepool = 0;
int thinpool = 0;
+ struct segment_type *segtype;
if ((lp->pool_data_name = arg_str_value(cmd, cachepool_ARG, NULL))) {
if (lp->type_str[0] &&
@@ -388,10 +389,10 @@ static int _read_pool_params(struct cmd_context *cmd, int *pargc, char ***pargv,
splitmirrors_ARG, splitsnapshot_ARG, -1))
return_0;
- if (!(lp->segtype = get_segtype_from_string(cmd, lp->type_str)))
+ if (!(segtype = get_segtype_from_string(cmd, lp->type_str)))
return_0;
- if (!get_pool_params(cmd, lp->segtype, &lp->passed_args,
+ if (!get_pool_params(cmd, segtype, &lp->passed_args,
&lp->pool_metadata_size,
&lp->poolmetadataspare,
&lp->chunk_size, &lp->discards,
@@ -528,7 +529,6 @@ static int _read_params(struct cmd_context *cmd, int argc, char **argv,
lp->type_str = SEG_TYPE_NAME_THIN;
}
- /* May set lp->segtype */
if (!_read_pool_params(cmd, &argc, &argv, lp))
return_0;
@@ -797,17 +797,6 @@ static int _read_params(struct cmd_context *cmd, int argc, char **argv,
lp->pv_count = argc;
lp->pvs = argv;
- /* If we have type_str, set up the segtype to match. */
- if (*lp->type_str && !(lp->segtype = get_segtype_from_string(cmd, lp->type_str)))
- return_0;
-
- if (activation() && lp->segtype && lp->segtype->ops->target_present &&
- !lp->segtype->ops->target_present(cmd, NULL, &lp->target_attr)) {
- log_error("%s: Required device-mapper target(s) not "
- "detected in your kernel.", lp->segtype->name);
- return 0;
- }
-
return 1;
}
@@ -4372,9 +4361,18 @@ static int _lvconvert(struct cmd_context *cmd, struct logical_volume *lv,
}
}
- /* If we don't have a specific new segtype to use, keep the existing one. */
- if (!lp->segtype)
+ /* Set up segtype either from type_str or else to match the existing one. */
+ if (!*lp->type_str)
lp->segtype = seg->segtype;
+ else if (!(lp->segtype = get_segtype_from_string(cmd, lp->type_str)))
+ return_0;
+
+ if (activation() && lp->segtype && lp->segtype->ops->target_present &&
+ !lp->segtype->ops->target_present(cmd, NULL, &lp->target_attr)) {
+ log_error("%s: Required device-mapper target(s) not "
+ "detected in your kernel.", lp->segtype->name);
+ return 0;
+ }
/* Process striping parameters */
/* FIXME This is incomplete */
7 years, 4 months
master - lvconvert: Rely upon lp->thin and lp->cache.
by Alasdair Kergon
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=1ce958bc5ea282...
Commit: 1ce958bc5ea2827fdb945b2177616e8f253486a1
Parent: 48d9c46daabd73c694404c48d3820c2a229f1ad2
Author: Alasdair G Kergon <agk(a)redhat.com>
AuthorDate: Sat Jul 30 15:56:17 2016 +0100
Committer: Alasdair G Kergon <agk(a)redhat.com>
CommitterDate: Sat Jul 30 15:58:09 2016 +0100
lvconvert: Rely upon lp->thin and lp->cache.
---
tools/lvconvert.c | 10 +++++-----
1 files changed, 5 insertions(+), 5 deletions(-)
diff --git a/tools/lvconvert.c b/tools/lvconvert.c
index 822df53..ed3bd88 100644
--- a/tools/lvconvert.c
+++ b/tools/lvconvert.c
@@ -4072,7 +4072,7 @@ static int _convert_thin_pool(struct cmd_context *cmd, struct logical_volume *lv
if (arg_is_set(cmd, uncache_ARG))
return _convert_thin_pool_uncache(cmd, lv, lp);
- if (!strcmp(lp->type_str, SEG_TYPE_NAME_CACHE) || arg_is_set(cmd, cache_ARG))
+ if (lp->cache)
return _convert_thin_pool_cache(cmd, lv, lp);
if (arg_is_set(cmd, repair_ARG))
@@ -4216,10 +4216,10 @@ static int _convert_raid(struct cmd_context *cmd, struct logical_volume *lv,
if (!strcmp(lp->type_str, SEG_TYPE_NAME_SNAPSHOT) || arg_is_set(cmd, snapshot_ARG))
return _convert_raid_snapshot(cmd, lv, lp);
- if (!strcmp(lp->type_str, SEG_TYPE_NAME_THIN) || arg_is_set(cmd, thin_ARG))
+ if (lp->thin)
return _convert_raid_thin(cmd, lv, lp);
- if (!strcmp(lp->type_str, SEG_TYPE_NAME_CACHE) || arg_is_set(cmd, cache_ARG))
+ if (lp->cache)
return _convert_raid_cache(cmd, lv, lp);
/* Using --thinpool is ambiguous and not preferred. */
@@ -4273,10 +4273,10 @@ static int _convert_striped(struct cmd_context *cmd, struct logical_volume *lv,
if (!strcmp(lp->type_str, SEG_TYPE_NAME_SNAPSHOT) || arg_is_set(cmd, snapshot_ARG))
return _convert_striped_snapshot(cmd, lv, lp);
- if (!strcmp(lp->type_str, SEG_TYPE_NAME_THIN) || lp->thin)
+ if (lp->thin)
return _convert_striped_thin(cmd, lv, lp);
- if (!strcmp(lp->type_str, SEG_TYPE_NAME_CACHE) || arg_is_set(cmd, cache_ARG))
+ if (lp->cache)
return _convert_striped_cache(cmd, lv, lp);
/* Using --thinpool is ambiguous and not preferred. */
7 years, 4 months
master - lvconvert: Fix --type thin recognition.
by Alasdair Kergon
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=48d9c46daabd73...
Commit: 48d9c46daabd73c694404c48d3820c2a229f1ad2
Parent: 52d2fa7022c48791d003554e5e656a94c5970af8
Author: Alasdair G Kergon <agk(a)redhat.com>
AuthorDate: Sat Jul 30 15:08:50 2016 +0100
Committer: Alasdair G Kergon <agk(a)redhat.com>
CommitterDate: Sat Jul 30 15:08:50 2016 +0100
lvconvert: Fix --type thin recognition.
lp->thin already holds the result of the cmdline arg resolution.
---
tools/lvconvert.c | 2 +-
1 files changed, 1 insertions(+), 1 deletions(-)
diff --git a/tools/lvconvert.c b/tools/lvconvert.c
index b9aef53..822df53 100644
--- a/tools/lvconvert.c
+++ b/tools/lvconvert.c
@@ -4273,7 +4273,7 @@ static int _convert_striped(struct cmd_context *cmd, struct logical_volume *lv,
if (!strcmp(lp->type_str, SEG_TYPE_NAME_SNAPSHOT) || arg_is_set(cmd, snapshot_ARG))
return _convert_striped_snapshot(cmd, lv, lp);
- if (!strcmp(lp->type_str, SEG_TYPE_NAME_THIN) || arg_is_set(cmd, thin_ARG))
+ if (!strcmp(lp->type_str, SEG_TYPE_NAME_THIN) || lp->thin)
return _convert_striped_thin(cmd, lv, lp);
if (!strcmp(lp->type_str, SEG_TYPE_NAME_CACHE) || arg_is_set(cmd, cache_ARG))
7 years, 4 months
master - tools: Also recognise segtype with thin and cache.
by Alasdair Kergon
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=52d2fa7022c487...
Commit: 52d2fa7022c48791d003554e5e656a94c5970af8
Parent: d1ff254c3cca0eed959095aa02ef9bfe36481065
Author: Alasdair G Kergon <agk(a)redhat.com>
AuthorDate: Sat Jul 30 04:12:58 2016 +0100
Committer: Alasdair G Kergon <agk(a)redhat.com>
CommitterDate: Sat Jul 30 04:12:58 2016 +0100
tools: Also recognise segtype with thin and cache.
(--type thin still needs this for lvcreate - more logic should be
shared between lvcreate and lvconvert)
---
lib/metadata/segtype.h | 2 ++
1 files changed, 2 insertions(+), 0 deletions(-)
diff --git a/lib/metadata/segtype.h b/lib/metadata/segtype.h
index 2fc7a12..bf7c5eb 100644
--- a/lib/metadata/segtype.h
+++ b/lib/metadata/segtype.h
@@ -133,6 +133,8 @@ struct dev_manager;
#define segtype_supports_stripe_size(segtype) \
((segtype_is_striped(segtype) || segtype_is_mirror(segtype) || \
+ segtype_is_cache(segtype) || segtype_is_cache_pool(segtype) || \
+ segtype_is_thin(segtype) || segtype_is_snapshot(segtype) || \
(segtype_is_raid(segtype) && !segtype_is_raid1(segtype))) ? 1 : 0)
#define seg_is_cache(seg) segtype_is_cache((seg)->segtype)
7 years, 4 months
master - tools: mirror also supports stripesize
by Alasdair Kergon
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=d1ff254c3cca0e...
Commit: d1ff254c3cca0eed959095aa02ef9bfe36481065
Parent: b3fbcd1ff7cae307b2796fe0df9ef32655f6f87a
Author: Alasdair G Kergon <agk(a)redhat.com>
AuthorDate: Sat Jul 30 03:52:49 2016 +0100
Committer: Alasdair G Kergon <agk(a)redhat.com>
CommitterDate: Sat Jul 30 03:52:49 2016 +0100
tools: mirror also supports stripesize
---
lib/metadata/segtype.h | 3 ++-
1 files changed, 2 insertions(+), 1 deletions(-)
diff --git a/lib/metadata/segtype.h b/lib/metadata/segtype.h
index f39007f..2fc7a12 100644
--- a/lib/metadata/segtype.h
+++ b/lib/metadata/segtype.h
@@ -132,7 +132,8 @@ struct dev_manager;
#define segtype_is_unknown(segtype) ((segtype)->flags & SEG_UNKNOWN ? 1 : 0)
#define segtype_supports_stripe_size(segtype) \
- ((segtype_is_striped(segtype) || (segtype_is_raid(segtype) && !segtype_is_raid1(segtype))) ? 1 : 0)
+ ((segtype_is_striped(segtype) || segtype_is_mirror(segtype) || \
+ (segtype_is_raid(segtype) && !segtype_is_raid1(segtype))) ? 1 : 0)
#define seg_is_cache(seg) segtype_is_cache((seg)->segtype)
#define seg_is_cache_pool(seg) segtype_is_cache_pool((seg)->segtype)
7 years, 4 months
master - lvconvert: Move stripe validation code later.
by Alasdair Kergon
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=b3fbcd1ff7cae3...
Commit: b3fbcd1ff7cae307b2796fe0df9ef32655f6f87a
Parent: 4ffe15bf6aec1ef8a14d3c070fc6b9bbb40cd4b0
Author: Alasdair G Kergon <agk(a)redhat.com>
AuthorDate: Sat Jul 30 02:52:06 2016 +0100
Committer: Alasdair G Kergon <agk(a)redhat.com>
CommitterDate: Sat Jul 30 02:52:06 2016 +0100
lvconvert: Move stripe validation code later.
Simpler to delay it all until the actual LV being changed is available,
rather than having it split in two parts.
---
tools/lvconvert.c | 34 +++++++++++++++++-----------------
1 files changed, 17 insertions(+), 17 deletions(-)
diff --git a/tools/lvconvert.c b/tools/lvconvert.c
index 33c7ffb..b9aef53 100644
--- a/tools/lvconvert.c
+++ b/tools/lvconvert.c
@@ -808,23 +808,6 @@ static int _read_params(struct cmd_context *cmd, int argc, char **argv,
return 0;
}
- /* Process striping parameters */
- /* FIXME This is incomplete */
- if (_mirror_or_raid_type_requested(cmd, lp->type_str) || _raid0_type_requested(lp->type_str) ||
- _striped_type_requested(lp->type_str) || lp->repair || lp->mirrorlog || lp->corelog) {
- if (!get_stripe_params(cmd, lp->segtype, &lp->stripes, &lp->stripe_size))
- return_0;
-
- if (_raid0_type_requested(lp->type_str) || _striped_type_requested(lp->type_str))
- /* FIXME Shouldn't need to override get_stripe_params which defaults to 1 stripe (i.e. linear)! */
- /* The default keeps existing number of stripes, handled inside the library code */
- if (!arg_is_set(cmd, stripes_long_ARG) && !_linear_type_requested(lp->type_str))
- lp->stripes = 0;
- }
-
- if (lp->snapshot)
- lp->zero = (lp->segtype->flags & SEG_CANNOT_BE_ZEROED) ? 0 : arg_int_value(cmd, zero_ARG, 1);
-
return 1;
}
@@ -4393,6 +4376,23 @@ static int _lvconvert(struct cmd_context *cmd, struct logical_volume *lv,
if (!lp->segtype)
lp->segtype = seg->segtype;
+ /* Process striping parameters */
+ /* FIXME This is incomplete */
+ if (_mirror_or_raid_type_requested(cmd, lp->type_str) || _raid0_type_requested(lp->type_str) ||
+ _striped_type_requested(lp->type_str) || lp->repair || lp->mirrorlog || lp->corelog) {
+ if (!get_stripe_params(cmd, lp->segtype, &lp->stripes, &lp->stripe_size))
+ return_0;
+
+ if (_raid0_type_requested(lp->type_str) || _striped_type_requested(lp->type_str))
+ /* FIXME Shouldn't need to override get_stripe_params which defaults to 1 stripe (i.e. linear)! */
+ /* The default keeps existing number of stripes, handled inside the library code */
+ if (!arg_is_set(cmd, stripes_long_ARG) && !_linear_type_requested(lp->type_str))
+ lp->stripes = 0;
+ }
+
+ if (lp->snapshot)
+ lp->zero = (lp->segtype->flags & SEG_CANNOT_BE_ZEROED) ? 0 : arg_int_value(cmd, zero_ARG, 1);
+
/*
* Each LV type that can be converted.
* (The existing type of the LV, not a requested type.)
7 years, 4 months
master - tools: Unify stripesize parameter validation.
by Alasdair Kergon
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=4ffe15bf6aec1e...
Commit: 4ffe15bf6aec1ef8a14d3c070fc6b9bbb40cd4b0
Parent: d01b1b6cc14885670516653771077fefc9e94788
Author: Alasdair G Kergon <agk(a)redhat.com>
AuthorDate: Sat Jul 30 02:05:50 2016 +0100
Committer: Alasdair G Kergon <agk(a)redhat.com>
CommitterDate: Sat Jul 30 02:05:50 2016 +0100
tools: Unify stripesize parameter validation.
Move it all into get_stripe_params().
Some code paths missed --stripesize checks.
E.g. lvcreate --type raid4 -i1
---
WHATS_NEW | 1 +
lib/metadata/segtype.h | 3 +++
tools/lvconvert.c | 6 +++---
tools/lvcreate.c | 14 ++------------
tools/toollib.c | 40 ++++++++++++++++++++++++----------------
tools/toollib.h | 4 ++--
6 files changed, 35 insertions(+), 33 deletions(-)
diff --git a/WHATS_NEW b/WHATS_NEW
index 8474644..2e81ab0 100644
--- a/WHATS_NEW
+++ b/WHATS_NEW
@@ -1,5 +1,6 @@
Version 2.02.163 -
=================================
+ Unify stripe size validation into get_stripe_params to catch missing cases.
Further lvconvert validation logic refactoring.
Version 2.02.162 - 28th July 2016
diff --git a/lib/metadata/segtype.h b/lib/metadata/segtype.h
index 2afb02a..f39007f 100644
--- a/lib/metadata/segtype.h
+++ b/lib/metadata/segtype.h
@@ -131,6 +131,9 @@ struct dev_manager;
#define segtype_is_virtual(segtype) ((segtype)->flags & SEG_VIRTUAL ? 1 : 0)
#define segtype_is_unknown(segtype) ((segtype)->flags & SEG_UNKNOWN ? 1 : 0)
+#define segtype_supports_stripe_size(segtype) \
+ ((segtype_is_striped(segtype) || (segtype_is_raid(segtype) && !segtype_is_raid1(segtype))) ? 1 : 0)
+
#define seg_is_cache(seg) segtype_is_cache((seg)->segtype)
#define seg_is_cache_pool(seg) segtype_is_cache_pool((seg)->segtype)
#define seg_is_linear(seg) (seg_is_striped(seg) && ((seg)->area_count == 1))
diff --git a/tools/lvconvert.c b/tools/lvconvert.c
index 4a5956e..33c7ffb 100644
--- a/tools/lvconvert.c
+++ b/tools/lvconvert.c
@@ -812,11 +812,10 @@ static int _read_params(struct cmd_context *cmd, int argc, char **argv,
/* FIXME This is incomplete */
if (_mirror_or_raid_type_requested(cmd, lp->type_str) || _raid0_type_requested(lp->type_str) ||
_striped_type_requested(lp->type_str) || lp->repair || lp->mirrorlog || lp->corelog) {
- if (!get_stripe_params(cmd, &lp->stripes, &lp->stripe_size))
+ if (!get_stripe_params(cmd, lp->segtype, &lp->stripes, &lp->stripe_size))
return_0;
if (_raid0_type_requested(lp->type_str) || _striped_type_requested(lp->type_str))
-
/* FIXME Shouldn't need to override get_stripe_params which defaults to 1 stripe (i.e. linear)! */
/* The default keeps existing number of stripes, handled inside the library code */
if (!arg_is_set(cmd, stripes_long_ARG) && !_linear_type_requested(lp->type_str))
@@ -3145,7 +3144,8 @@ static int _lvconvert_pool(struct cmd_context *cmd,
if (!_lvconvert_update_pool_params(pool_lv, lp))
return_0;
- if (!get_stripe_params(cmd, &lp->stripes, &lp->stripe_size))
+ if (!get_stripe_params(cmd, get_segtype_from_string(cmd, SEG_TYPE_NAME_STRIPED),
+ &lp->stripes, &lp->stripe_size))
return_0;
if (!archive(vg))
diff --git a/tools/lvcreate.c b/tools/lvcreate.c
index 5e3ddbb..253fab8 100644
--- a/tools/lvcreate.c
+++ b/tools/lvcreate.c
@@ -495,9 +495,7 @@ static int _read_raid_params(struct cmd_context *cmd,
lp->segtype->name);
return 0;
}
-
- } else if (!lp->stripe_size)
- lp->stripe_size = find_config_tree_int(cmd, metadata_stripesize_CFG, NULL) * 2;
+ }
if (arg_is_set(cmd, mirrors_ARG) && segtype_is_raid(lp->segtype) &&
!segtype_is_raid1(lp->segtype) && !segtype_is_raid10(lp->segtype)) {
@@ -572,14 +570,6 @@ static int _read_mirror_and_raid_params(struct cmd_context *cmd,
return 0;
}
- /*
- * FIXME This is working around a bug in get_stripe_params() where
- * stripes is incorrectly assumed to be 1 when it is not supplied
- * leading to the actual value of stripesize getting lost.
- */
- if (arg_is_set(cmd, stripesize_ARG))
- lp->stripe_size = arg_uint_value(cmd, stripesize_ARG, 0);
-
if (!is_power_of_2(lp->region_size)) {
log_error("Region size (%" PRIu32 ") must be a power of 2",
lp->region_size);
@@ -1044,7 +1034,7 @@ static int _lvcreate_params(struct cmd_context *cmd,
if (!_lvcreate_name_params(cmd, &argc, &argv, lp) ||
!_read_size_params(cmd, lp, lcp) ||
- !get_stripe_params(cmd, &lp->stripes, &lp->stripe_size) ||
+ !get_stripe_params(cmd, lp->segtype, &lp->stripes, &lp->stripe_size) ||
(lp->create_pool &&
!get_pool_params(cmd, lp->segtype, &lp->passed_args,
&lp->pool_metadata_size, &lp->pool_metadata_spare,
diff --git a/tools/toollib.c b/tools/toollib.c
index a76599c..4cd9020 100644
--- a/tools/toollib.c
+++ b/tools/toollib.c
@@ -1273,18 +1273,32 @@ int get_pool_params(struct cmd_context *cmd,
/*
* Generic stripe parameter checks.
*/
-static int _validate_stripe_params(struct cmd_context *cmd, uint32_t *stripes,
- uint32_t *stripe_size)
+static int _validate_stripe_params(struct cmd_context *cmd, const struct segment_type *segtype,
+ uint32_t *stripes, uint32_t *stripe_size)
{
- if (*stripes == 1 && *stripe_size) {
+ int stripe_size_required = segtype_supports_stripe_size(segtype);
+
+ if (!stripe_size_required && *stripe_size) {
+ log_print_unless_silent("Ignoring stripesize argument for %s devices.", segtype->name);
+ *stripe_size = 0;
+ } else if (segtype_is_striped(segtype) && *stripes == 1 && *stripe_size) {
log_print_unless_silent("Ignoring stripesize argument with single stripe.");
+ stripe_size_required = 0;
*stripe_size = 0;
}
- if (*stripes > 1 && !*stripe_size) {
- *stripe_size = find_config_tree_int(cmd, metadata_stripesize_CFG, NULL) * 2;
- log_print_unless_silent("Using default stripesize %s.",
- display_size(cmd, (uint64_t) *stripe_size));
+ if (stripe_size_required) {
+ if (!*stripe_size) {
+ *stripe_size = find_config_tree_int(cmd, metadata_stripesize_CFG, NULL) * 2;
+ log_print_unless_silent("Using default stripesize %s.",
+ display_size(cmd, (uint64_t) *stripe_size));
+ }
+
+ if (*stripe_size < STRIPE_SIZE_MIN || !is_power_of_2(*stripe_size)) {
+ log_error("Invalid stripe size %s.",
+ display_size(cmd, (uint64_t) *stripe_size));
+ return 0;
+ }
}
if (*stripes < 1 || *stripes > MAX_STRIPES) {
@@ -1293,13 +1307,6 @@ static int _validate_stripe_params(struct cmd_context *cmd, uint32_t *stripes,
return 0;
}
- if (*stripes > 1 && (*stripe_size < STRIPE_SIZE_MIN ||
- !is_power_of_2(*stripe_size))) {
- log_error("Invalid stripe size %s.",
- display_size(cmd, (uint64_t) *stripe_size));
- return 0;
- }
-
return 1;
}
@@ -1309,9 +1316,10 @@ static int _validate_stripe_params(struct cmd_context *cmd, uint32_t *stripes,
* power of 2, we must divide UINT_MAX by four and add 1 (to round it
* up to the power of 2)
*/
-int get_stripe_params(struct cmd_context *cmd, uint32_t *stripes, uint32_t *stripe_size)
+int get_stripe_params(struct cmd_context *cmd, const struct segment_type *segtype, uint32_t *stripes, uint32_t *stripe_size)
{
/* stripes_long_ARG takes precedence (for lvconvert) */
+ /* FIXME Cope with relative +/- changes for lvconvert. */
*stripes = arg_uint_value(cmd, arg_is_set(cmd, stripes_long_ARG) ? stripes_long_ARG : stripes_ARG, 1);
*stripe_size = arg_uint_value(cmd, stripesize_ARG, 0);
@@ -1328,7 +1336,7 @@ int get_stripe_params(struct cmd_context *cmd, uint32_t *stripes, uint32_t *stri
}
}
- return _validate_stripe_params(cmd, stripes, stripe_size);
+ return _validate_stripe_params(cmd, segtype, stripes, stripe_size);
}
static int _validate_cachepool_params(const char *name,
diff --git a/tools/toollib.h b/tools/toollib.h
index 42e7f7a..ed5ec76 100644
--- a/tools/toollib.h
+++ b/tools/toollib.h
@@ -201,8 +201,8 @@ int get_pool_params(struct cmd_context *cmd,
thin_discards_t *discards,
int *zero);
-int get_stripe_params(struct cmd_context *cmd, uint32_t *stripes,
- uint32_t *stripe_size);
+int get_stripe_params(struct cmd_context *cmd, const struct segment_type *segtype,
+ uint32_t *stripes, uint32_t *stripe_size);
int get_cache_params(struct cmd_context *cmd,
cache_mode_t *cache_mode,
7 years, 4 months
master - lvconvert: Rearrange code that decides segtype.
by Alasdair Kergon
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=d01b1b6cc14885...
Commit: d01b1b6cc14885670516653771077fefc9e94788
Parent: a8e479081088d0649e93a24b8f3bc852eb396226
Author: Alasdair G Kergon <agk(a)redhat.com>
AuthorDate: Sat Jul 30 00:22:13 2016 +0100
Committer: Alasdair G Kergon <agk(a)redhat.com>
CommitterDate: Sat Jul 30 00:22:13 2016 +0100
lvconvert: Rearrange code that decides segtype.
---
WHATS_NEW | 1 +
tools/lvconvert.c | 91 ++++++++++++++++++++++-------------------------------
2 files changed, 39 insertions(+), 53 deletions(-)
diff --git a/WHATS_NEW b/WHATS_NEW
index 2ef2e09..8474644 100644
--- a/WHATS_NEW
+++ b/WHATS_NEW
@@ -1,5 +1,6 @@
Version 2.02.163 -
=================================
+ Further lvconvert validation logic refactoring.
Version 2.02.162 - 28th July 2016
=================================
diff --git a/tools/lvconvert.c b/tools/lvconvert.c
index 0f9286c..4a5956e 100644
--- a/tools/lvconvert.c
+++ b/tools/lvconvert.c
@@ -155,9 +155,9 @@ static int _lvconvert_name_params(struct lvconvert_params *lp,
}
if (!strstr((*pargv)[0], "_rimage_")) { /* Snapshot */
- if (!(lp->segtype = get_segtype_from_string(cmd, SEG_TYPE_NAME_SNAPSHOT)))
- return_0;
+ lp->type_str = SEG_TYPE_NAME_SNAPSHOT;
lp->merge_snapshot = 1;
+
return 1;
}
@@ -702,10 +702,6 @@ static int _read_params(struct cmd_context *cmd, int argc, char **argv,
log_verbose("Setting chunk size to %s.", display_size(cmd, lp->chunk_size));
lp->type_str = SEG_TYPE_NAME_SNAPSHOT;
- if (!(lp->segtype = get_segtype_from_string(cmd, lp->type_str)))
- return_0;
-
- lp->zero = (lp->segtype->flags & SEG_CANNOT_BE_ZEROED) ? 0 : arg_int_value(cmd, zero_ARG, 1);
} else if (lp->replace) { /* RAID device replacement */
lp->replace_pv_count = arg_count(cmd, replace_ARG);
@@ -784,36 +780,27 @@ static int _read_params(struct cmd_context *cmd, int argc, char **argv,
/* down-converting to linear/stripe? */
lp->type_str = SEG_TYPE_NAME_STRIPED;
- if (*lp->type_str)
- /* changing mirror type? */
- if (!(lp->segtype = get_segtype_from_string(cmd, lp->type_str)))
- return_0;
-
- /* Default is never striped, regardless of existing LV configuration. */
- if (!get_stripe_params(cmd, &lp->stripes, &lp->stripe_size))
- return_0;
} else if (_raid0_type_requested(lp->type_str) || _striped_type_requested(lp->type_str)) { /* striped or linear or raid0 */
if (arg_from_list_is_set(cmd, "cannot be used with --type raid0 or --type striped or --type linear",
chunksize_ARG, corelog_ARG, mirrors_ARG, mirrorlog_ARG, regionsize_ARG, zero_ARG,
-1))
return_0;
- if (!(lp->segtype = get_segtype_from_string(cmd, lp->type_str)))
- return_0;
-
- if (!get_stripe_params(cmd, &lp->stripes, &lp->stripe_size))
- return_0;
-
- /* FIXME Shouldn't need to override get_stripe_params which defaults to 1 stripe (i.e. linear)! */
- /* The default keeps existing number of stripes, handled inside the library code */
- if (!arg_is_set(cmd, stripes_long_ARG) && !_linear_type_requested(lp->type_str))
- lp->stripes = 0;
-
} /* else segtype will default to current type */
lp->force = arg_count(cmd, force_ARG);
lp->yes = arg_count(cmd, yes_ARG);
+ if (!_lvconvert_name_params(lp, cmd, &argc, &argv))
+ return_0;
+
+ lp->pv_count = argc;
+ lp->pvs = argv;
+
+ /* If we have type_str, set up the segtype to match. */
+ if (*lp->type_str && !(lp->segtype = get_segtype_from_string(cmd, lp->type_str)))
+ return_0;
+
if (activation() && lp->segtype && lp->segtype->ops->target_present &&
!lp->segtype->ops->target_present(cmd, NULL, &lp->target_attr)) {
log_error("%s: Required device-mapper target(s) not "
@@ -821,11 +808,23 @@ static int _read_params(struct cmd_context *cmd, int argc, char **argv,
return 0;
}
- if (!_lvconvert_name_params(lp, cmd, &argc, &argv))
- return_0;
+ /* Process striping parameters */
+ /* FIXME This is incomplete */
+ if (_mirror_or_raid_type_requested(cmd, lp->type_str) || _raid0_type_requested(lp->type_str) ||
+ _striped_type_requested(lp->type_str) || lp->repair || lp->mirrorlog || lp->corelog) {
+ if (!get_stripe_params(cmd, &lp->stripes, &lp->stripe_size))
+ return_0;
- lp->pv_count = argc;
- lp->pvs = argv;
+ if (_raid0_type_requested(lp->type_str) || _striped_type_requested(lp->type_str))
+
+ /* FIXME Shouldn't need to override get_stripe_params which defaults to 1 stripe (i.e. linear)! */
+ /* The default keeps existing number of stripes, handled inside the library code */
+ if (!arg_is_set(cmd, stripes_long_ARG) && !_linear_type_requested(lp->type_str))
+ lp->stripes = 0;
+ }
+
+ if (lp->snapshot)
+ lp->zero = (lp->segtype->flags & SEG_CANNOT_BE_ZEROED) ? 0 : arg_int_value(cmd, zero_ARG, 1);
return 1;
}
@@ -1848,9 +1847,6 @@ static int _lvconvert_raid(struct logical_volume *lv, struct lvconvert_params *l
struct lv_segment *seg = first_seg(lv);
dm_percent_t sync_percent;
- if (!lp->segtype)
- lp->segtype = seg->segtype;
-
if (_linear_type_requested(lp->type_str)) {
if (arg_is_set(cmd, mirrors_ARG) && (arg_uint_value(cmd, mirrors_ARG, 0) != 0)) {
log_error("Cannot specify mirrors with linear type.");
@@ -4169,11 +4165,6 @@ static int _convert_cache_pool(struct cmd_context *cmd, struct logical_volume *l
static int _convert_mirror(struct cmd_context *cmd, struct logical_volume *lv,
struct lvconvert_params *lp)
{
- const struct segment_type *new_segtype = NULL;
-
- if (*lp->type_str)
- new_segtype = get_segtype_from_string(cmd, lp->type_str);
-
if (arg_is_set(cmd, mirrors_ARG))
return _convert_mirror_number(cmd, lv, lp);
@@ -4189,7 +4180,7 @@ static int _convert_mirror(struct cmd_context *cmd, struct logical_volume *lv,
if (_linear_type_requested(lp->type_str))
return _convert_mirror_linear(cmd, lv, lp);
- if (new_segtype && segtype_is_raid(new_segtype))
+ if (segtype_is_raid(lp->segtype))
return _convert_mirror_raid(cmd, lv, lp);
/*
@@ -4224,11 +4215,6 @@ static int _convert_mirror(struct cmd_context *cmd, struct logical_volume *lv,
static int _convert_raid(struct cmd_context *cmd, struct logical_volume *lv,
struct lvconvert_params *lp)
{
- const struct segment_type *new_segtype = NULL;
-
- if (*lp->type_str)
- new_segtype = get_segtype_from_string(cmd, lp->type_str);
-
if (arg_is_set(cmd, mirrors_ARG))
return _convert_raid_number(cmd, lv, lp);
@@ -4263,7 +4249,7 @@ static int _convert_raid(struct cmd_context *cmd, struct logical_volume *lv,
if (!strcmp(lp->type_str, SEG_TYPE_NAME_CACHE_POOL) || arg_is_set(cmd, cachepool_ARG))
return _convert_raid_cache_pool(cmd, lv, lp);
- if (new_segtype && segtype_is_raid(new_segtype))
+ if (segtype_is_raid(lp->segtype))
return _convert_raid_raid(cmd, lv, lp);
if (!strcmp(lp->type_str, SEG_TYPE_NAME_STRIPED))
@@ -4295,12 +4281,8 @@ static int _convert_raid(struct cmd_context *cmd, struct logical_volume *lv,
static int _convert_striped(struct cmd_context *cmd, struct logical_volume *lv,
struct lvconvert_params *lp)
{
- const struct segment_type *new_segtype = NULL;
const char *mirrors_type = find_config_tree_str(cmd, global_mirror_segtype_default_CFG, NULL);
- if (*lp->type_str)
- new_segtype = get_segtype_from_string(cmd, lp->type_str);
-
/* FIXME: add --merge-mirror to make this distinct from --merge-snapshot. */
if (arg_is_set(cmd, merge_ARG))
return _convert_striped_merge(cmd, lv, lp);
@@ -4327,7 +4309,7 @@ static int _convert_striped(struct cmd_context *cmd, struct logical_volume *lv,
if (!strcmp(lp->type_str, SEG_TYPE_NAME_MIRROR))
return _convert_striped_mirror(cmd, lv, lp);
- if (new_segtype && segtype_is_raid(new_segtype))
+ if (segtype_is_raid(lp->segtype))
return _convert_striped_raid(cmd, lv, lp);
/* --mirrors can mean --type mirror or --type raid1 depending on config setting. */
@@ -4369,7 +4351,7 @@ static int _convert_striped(struct cmd_context *cmd, struct logical_volume *lv,
static int _lvconvert(struct cmd_context *cmd, struct logical_volume *lv,
struct lvconvert_params *lp)
{
- struct lv_segment *lv_seg = first_seg(lv);
+ struct lv_segment *seg = first_seg(lv);
int ret = 0;
/*
@@ -4407,11 +4389,14 @@ static int _lvconvert(struct cmd_context *cmd, struct logical_volume *lv,
}
}
+ /* If we don't have a specific new segtype to use, keep the existing one. */
+ if (!lp->segtype)
+ lp->segtype = seg->segtype;
+
/*
* Each LV type that can be converted.
* (The existing type of the LV, not a requested type.)
*/
-
if (lv_is_cow(lv)) {
ret = _convert_cow_snapshot(cmd, lv, lp);
goto out;
@@ -4449,10 +4434,10 @@ static int _lvconvert(struct cmd_context *cmd, struct logical_volume *lv,
/*
* FIXME: add lv_is_striped() and lv_is_linear()?
- * This does not include raid0.
+ * This does not include raid0 which is caught by the test above.
* If operations differ between striped and linear, split this case.
*/
- if (segtype_is_striped(lv_seg->segtype) || segtype_is_linear(lv_seg->segtype)) {
+ if (segtype_is_striped(seg->segtype) || segtype_is_linear(seg->segtype)) {
ret = _convert_striped(cmd, lv, lp);
goto out;
}
7 years, 4 months
master - lvconvert: Only obtain --type parameter once.
by Alasdair Kergon
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=a8e479081088d0...
Commit: a8e479081088d0649e93a24b8f3bc852eb396226
Parent: 800c0d3dd696b8574494788f38d61ca26ba68159
Author: Alasdair G Kergon <agk(a)redhat.com>
AuthorDate: Fri Jul 29 21:45:22 2016 +0100
Committer: Alasdair G Kergon <agk(a)redhat.com>
CommitterDate: Fri Jul 29 21:45:22 2016 +0100
lvconvert: Only obtain --type parameter once.
---
tools/lvconvert.c | 106 +++++++++++++++++++++++++---------------------------
1 files changed, 51 insertions(+), 55 deletions(-)
diff --git a/tools/lvconvert.c b/tools/lvconvert.c
index 9e850b3..0f9286c 100644
--- a/tools/lvconvert.c
+++ b/tools/lvconvert.c
@@ -440,7 +440,7 @@ static int _read_params(struct cmd_context *cmd, int argc, char **argv,
lp->type_str = arg_str_value(cmd, type_ARG, "");
- if (arg_is_set(cmd, type_ARG) && !_check_conversion_type(cmd, lp->type_str))
+ if (*lp->type_str && !_check_conversion_type(cmd, lp->type_str))
return_0;
/* If --repair, check for incompatible args. */
@@ -625,6 +625,13 @@ static int _read_params(struct cmd_context *cmd, int argc, char **argv,
lp->alloc = (alloc_policy_t) arg_uint_value(cmd, alloc_ARG, ALLOC_INHERIT);
+ /* We should have caught all these cases already. */
+ if (lp->merge + lp->splitsnapshot + lp->splitcache + lp->split + lp->uncache +
+ lp->cache + lp->thin + lp->keep_mimages + lp->snapshot + lp->replace > 1) {
+ log_error(INTERNAL_ERROR "Unexpected combination of incompatible options selected.");
+ return 0;
+ }
+
/*
* Final checking of each case:
* lp->merge
@@ -634,6 +641,7 @@ static int _read_params(struct cmd_context *cmd, int argc, char **argv,
* lp->uncache
* lp->cache
* lp->thin
+ * lp->keep_mimages
* lp->snapshot
* lp->replace
* --type mirror|raid lp->repair lp->mirrorlog lp->corelog
@@ -693,11 +701,11 @@ static int _read_params(struct cmd_context *cmd, int argc, char **argv,
}
log_verbose("Setting chunk size to %s.", display_size(cmd, lp->chunk_size));
- if (!(lp->segtype = get_segtype_from_string(cmd, SEG_TYPE_NAME_SNAPSHOT)))
+ lp->type_str = SEG_TYPE_NAME_SNAPSHOT;
+ if (!(lp->segtype = get_segtype_from_string(cmd, lp->type_str)))
return_0;
- lp->zero = (lp->segtype->flags & SEG_CANNOT_BE_ZEROED)
- ? 0 : arg_int_value(cmd, zero_ARG, 1);
+ lp->zero = (lp->segtype->flags & SEG_CANNOT_BE_ZEROED) ? 0 : arg_int_value(cmd, zero_ARG, 1);
} else if (lp->replace) { /* RAID device replacement */
lp->replace_pv_count = arg_count(cmd, replace_ARG);
@@ -771,27 +779,28 @@ static int _read_params(struct cmd_context *cmd, int argc, char **argv,
return 0;
}
- /* Default is never striped, regardless of existing LV configuration. */
- if (!get_stripe_params(cmd, &lp->stripes, &lp->stripe_size))
- return_0;
-
/* FIXME man page says in one place that --type and --mirrors can't be mixed */
- if (lp->mirrors_supplied && !lp->mirrors) {
+ if (lp->mirrors_supplied && !lp->mirrors)
/* down-converting to linear/stripe? */
- if (!(lp->segtype =
- get_segtype_from_string(cmd, SEG_TYPE_NAME_STRIPED)))
- return_0;
- } else if (arg_is_set(cmd, type_ARG)) {
+ lp->type_str = SEG_TYPE_NAME_STRIPED;
+
+ if (*lp->type_str)
/* changing mirror type? */
- if (!(lp->segtype = get_segtype_from_string(cmd, arg_str_value(cmd, type_ARG, find_config_tree_str(cmd, global_mirror_segtype_default_CFG, NULL)))))
+ if (!(lp->segtype = get_segtype_from_string(cmd, lp->type_str)))
return_0;
- }
+
+ /* Default is never striped, regardless of existing LV configuration. */
+ if (!get_stripe_params(cmd, &lp->stripes, &lp->stripe_size))
+ return_0;
} else if (_raid0_type_requested(lp->type_str) || _striped_type_requested(lp->type_str)) { /* striped or linear or raid0 */
if (arg_from_list_is_set(cmd, "cannot be used with --type raid0 or --type striped or --type linear",
chunksize_ARG, corelog_ARG, mirrors_ARG, mirrorlog_ARG, regionsize_ARG, zero_ARG,
-1))
return_0;
+ if (!(lp->segtype = get_segtype_from_string(cmd, lp->type_str)))
+ return_0;
+
if (!get_stripe_params(cmd, &lp->stripes, &lp->stripe_size))
return_0;
@@ -800,8 +809,6 @@ static int _read_params(struct cmd_context *cmd, int argc, char **argv,
if (!arg_is_set(cmd, stripes_long_ARG) && !_linear_type_requested(lp->type_str))
lp->stripes = 0;
- if (!(lp->segtype = get_segtype_from_string(cmd, lp->type_str)))
- return_0;
} /* else segtype will default to current type */
lp->force = arg_count(cmd, force_ARG);
@@ -1717,7 +1724,6 @@ static int _lvconvert_mirrors(struct cmd_context *cmd,
struct logical_volume *lv,
struct lvconvert_params *lp)
{
- const char *new_type;
uint32_t old_mimage_count;
uint32_t old_log_count;
uint32_t new_mimage_count;
@@ -1746,8 +1752,7 @@ static int _lvconvert_mirrors(struct cmd_context *cmd,
return 0;
}
- if ((new_type = arg_str_value(cmd, type_ARG, NULL)) &&
- !strcmp(new_type, SEG_TYPE_NAME_LINEAR)) {
+ if (_linear_type_requested(lp->type_str)) {
if (arg_is_set(cmd, mirrors_ARG) && (arg_uint_value(cmd, mirrors_ARG, 0) != 0)) {
log_error("Cannot specify mirrors with linear type.");
return 0;
@@ -1837,7 +1842,6 @@ static void _lvconvert_raid_repair_ask(struct cmd_context *cmd,
static int _lvconvert_raid(struct logical_volume *lv, struct lvconvert_params *lp)
{
- const char *new_type;
int replace = 0, image_count = 0;
struct dm_list *failed_pvs;
struct cmd_context *cmd = lv->vg->cmd;
@@ -1847,8 +1851,7 @@ static int _lvconvert_raid(struct logical_volume *lv, struct lvconvert_params *l
if (!lp->segtype)
lp->segtype = seg->segtype;
- if ((new_type = arg_str_value(cmd, type_ARG, NULL)) &&
- !strcmp(new_type, SEG_TYPE_NAME_LINEAR)) {
+ if (_linear_type_requested(lp->type_str)) {
if (arg_is_set(cmd, mirrors_ARG) && (arg_uint_value(cmd, mirrors_ARG, 0) != 0)) {
log_error("Cannot specify mirrors with linear type.");
return 0;
@@ -4081,8 +4084,6 @@ static int _convert_thin_volume(struct cmd_context *cmd, struct logical_volume *
static int _convert_thin_pool(struct cmd_context *cmd, struct logical_volume *lv,
struct lvconvert_params *lp)
{
- const char *new_type = arg_str_value(cmd, type_ARG, NULL);
-
if (arg_is_set(cmd, splitcache_ARG))
return _convert_thin_pool_splitcache(cmd, lv, lp);
@@ -4092,7 +4093,7 @@ static int _convert_thin_pool(struct cmd_context *cmd, struct logical_volume *lv
if (arg_is_set(cmd, uncache_ARG))
return _convert_thin_pool_uncache(cmd, lv, lp);
- if ((new_type && !strcmp(new_type, SEG_TYPE_NAME_CACHE)) || arg_is_set(cmd, cache_ARG))
+ if (!strcmp(lp->type_str, SEG_TYPE_NAME_CACHE) || arg_is_set(cmd, cache_ARG))
return _convert_thin_pool_cache(cmd, lv, lp);
if (arg_is_set(cmd, repair_ARG))
@@ -4116,8 +4117,6 @@ static int _convert_thin_pool(struct cmd_context *cmd, struct logical_volume *lv
static int _convert_cache_volume(struct cmd_context *cmd, struct logical_volume *lv,
struct lvconvert_params *lp)
{
- const char *new_type = arg_str_value(cmd, type_ARG, NULL);
-
if (arg_is_set(cmd, splitcache_ARG))
return _convert_cache_volume_splitcache(cmd, lv, lp);
@@ -4132,7 +4131,7 @@ static int _convert_cache_volume(struct cmd_context *cmd, struct logical_volume
/* Using --thinpool is ambiguous and not preferred. */
- if ((new_type && !strcmp(new_type, SEG_TYPE_NAME_THIN_POOL)) || arg_is_set(cmd, thinpool_ARG))
+ if (!strcmp(lp->type_str, SEG_TYPE_NAME_THIN_POOL) || arg_is_set(cmd, thinpool_ARG))
return _convert_cache_volume_thin_pool(cmd, lv, lp);
/* The --thinpool alternative for --type thin-pool is not preferred, so not shown. */
@@ -4170,11 +4169,10 @@ static int _convert_cache_pool(struct cmd_context *cmd, struct logical_volume *l
static int _convert_mirror(struct cmd_context *cmd, struct logical_volume *lv,
struct lvconvert_params *lp)
{
- const char *new_type = arg_str_value(cmd, type_ARG, NULL);
const struct segment_type *new_segtype = NULL;
- if (new_type)
- new_segtype = get_segtype_from_string(cmd, new_type);
+ if (*lp->type_str)
+ new_segtype = get_segtype_from_string(cmd, lp->type_str);
if (arg_is_set(cmd, mirrors_ARG))
return _convert_mirror_number(cmd, lv, lp);
@@ -4188,10 +4186,10 @@ static int _convert_mirror(struct cmd_context *cmd, struct logical_volume *lv,
if (arg_is_set(cmd, repair_ARG))
return _convert_mirror_repair(cmd, lv, lp);
- if (new_type && !strcmp(new_type, SEG_TYPE_NAME_LINEAR))
+ if (_linear_type_requested(lp->type_str))
return _convert_mirror_linear(cmd, lv, lp);
- if (new_type && new_segtype && segtype_is_raid(new_segtype))
+ if (new_segtype && segtype_is_raid(new_segtype))
return _convert_mirror_raid(cmd, lv, lp);
/*
@@ -4226,11 +4224,10 @@ static int _convert_mirror(struct cmd_context *cmd, struct logical_volume *lv,
static int _convert_raid(struct cmd_context *cmd, struct logical_volume *lv,
struct lvconvert_params *lp)
{
- const char *new_type = arg_str_value(cmd, type_ARG, NULL);
const struct segment_type *new_segtype = NULL;
- if (new_type)
- new_segtype = get_segtype_from_string(cmd, new_type);
+ if (*lp->type_str)
+ new_segtype = get_segtype_from_string(cmd, lp->type_str);
if (arg_is_set(cmd, mirrors_ARG))
return _convert_raid_number(cmd, lv, lp);
@@ -4247,32 +4244,32 @@ static int _convert_raid(struct cmd_context *cmd, struct logical_volume *lv,
if (arg_is_set(cmd, replace_ARG))
return _convert_raid_replace(cmd, lv, lp);
- if ((new_type && !strcmp(new_type, SEG_TYPE_NAME_SNAPSHOT)) || arg_is_set(cmd, snapshot_ARG))
+ if (!strcmp(lp->type_str, SEG_TYPE_NAME_SNAPSHOT) || arg_is_set(cmd, snapshot_ARG))
return _convert_raid_snapshot(cmd, lv, lp);
- if ((new_type && !strcmp(new_type, SEG_TYPE_NAME_THIN)) || arg_is_set(cmd, thin_ARG))
+ if (!strcmp(lp->type_str, SEG_TYPE_NAME_THIN) || arg_is_set(cmd, thin_ARG))
return _convert_raid_thin(cmd, lv, lp);
- if ((new_type && !strcmp(new_type, SEG_TYPE_NAME_CACHE)) || arg_is_set(cmd, cache_ARG))
+ if (!strcmp(lp->type_str, SEG_TYPE_NAME_CACHE) || arg_is_set(cmd, cache_ARG))
return _convert_raid_cache(cmd, lv, lp);
/* Using --thinpool is ambiguous and not preferred. */
- if ((new_type && !strcmp(new_type, SEG_TYPE_NAME_THIN_POOL)) || arg_is_set(cmd, thinpool_ARG))
+ if (!strcmp(lp->type_str, SEG_TYPE_NAME_THIN_POOL) || arg_is_set(cmd, thinpool_ARG))
return _convert_raid_thin_pool(cmd, lv, lp);
/* Using --cachepool is ambiguous and not preferred. */
- if ((new_type && !strcmp(new_type, SEG_TYPE_NAME_CACHE_POOL)) || arg_is_set(cmd, cachepool_ARG))
+ if (!strcmp(lp->type_str, SEG_TYPE_NAME_CACHE_POOL) || arg_is_set(cmd, cachepool_ARG))
return _convert_raid_cache_pool(cmd, lv, lp);
- if (new_type && new_segtype && segtype_is_raid(new_segtype))
+ if (new_segtype && segtype_is_raid(new_segtype))
return _convert_raid_raid(cmd, lv, lp);
- if (new_type && !strcmp(new_type, SEG_TYPE_NAME_STRIPED))
+ if (!strcmp(lp->type_str, SEG_TYPE_NAME_STRIPED))
return _convert_raid_striped(cmd, lv, lp);
- if (new_type && !strcmp(new_type, SEG_TYPE_NAME_LINEAR))
+ if (_linear_type_requested(lp->type_str))
return _convert_raid_linear(cmd, lv, lp);
/* The --thinpool alternative for --type thin-pool is not preferred, so not shown. */
@@ -4298,40 +4295,39 @@ static int _convert_raid(struct cmd_context *cmd, struct logical_volume *lv,
static int _convert_striped(struct cmd_context *cmd, struct logical_volume *lv,
struct lvconvert_params *lp)
{
- const char *new_type = arg_str_value(cmd, type_ARG, NULL);
const struct segment_type *new_segtype = NULL;
const char *mirrors_type = find_config_tree_str(cmd, global_mirror_segtype_default_CFG, NULL);
- if (new_type)
- new_segtype = get_segtype_from_string(cmd, new_type);
+ if (*lp->type_str)
+ new_segtype = get_segtype_from_string(cmd, lp->type_str);
/* FIXME: add --merge-mirror to make this distinct from --merge-snapshot. */
if (arg_is_set(cmd, merge_ARG))
return _convert_striped_merge(cmd, lv, lp);
- if ((new_type && !strcmp(new_type, SEG_TYPE_NAME_SNAPSHOT)) || arg_is_set(cmd, snapshot_ARG))
+ if (!strcmp(lp->type_str, SEG_TYPE_NAME_SNAPSHOT) || arg_is_set(cmd, snapshot_ARG))
return _convert_striped_snapshot(cmd, lv, lp);
- if ((new_type && !strcmp(new_type, SEG_TYPE_NAME_THIN)) || arg_is_set(cmd, thin_ARG))
+ if (!strcmp(lp->type_str, SEG_TYPE_NAME_THIN) || arg_is_set(cmd, thin_ARG))
return _convert_striped_thin(cmd, lv, lp);
- if ((new_type && !strcmp(new_type, SEG_TYPE_NAME_CACHE)) || arg_is_set(cmd, cache_ARG))
+ if (!strcmp(lp->type_str, SEG_TYPE_NAME_CACHE) || arg_is_set(cmd, cache_ARG))
return _convert_striped_cache(cmd, lv, lp);
/* Using --thinpool is ambiguous and not preferred. */
- if ((new_type && !strcmp(new_type, SEG_TYPE_NAME_THIN_POOL)) || arg_is_set(cmd, thinpool_ARG))
+ if (!strcmp(lp->type_str, SEG_TYPE_NAME_THIN_POOL) || arg_is_set(cmd, thinpool_ARG))
return _convert_striped_thin_pool(cmd, lv, lp);
/* Using --cachepool is ambiguous and not preferred. */
- if ((new_type && !strcmp(new_type, SEG_TYPE_NAME_CACHE_POOL)) || arg_is_set(cmd, cachepool_ARG))
+ if (!strcmp(lp->type_str, SEG_TYPE_NAME_CACHE_POOL) || arg_is_set(cmd, cachepool_ARG))
return _convert_striped_cache_pool(cmd, lv, lp);
- if (new_type && !strcmp(new_type, SEG_TYPE_NAME_MIRROR))
+ if (!strcmp(lp->type_str, SEG_TYPE_NAME_MIRROR))
return _convert_striped_mirror(cmd, lv, lp);
- if (new_type && new_segtype && segtype_is_raid(new_segtype))
+ if (new_segtype && segtype_is_raid(new_segtype))
return _convert_striped_raid(cmd, lv, lp);
/* --mirrors can mean --type mirror or --type raid1 depending on config setting. */
7 years, 4 months
master - lvconvert: Remove hard-coded segment names.
by Alasdair Kergon
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=800c0d3dd696b8...
Commit: 800c0d3dd696b8574494788f38d61ca26ba68159
Parent: 237f84e0383c7e3003050be7c072ee0a092fd426
Author: Alasdair G Kergon <agk(a)redhat.com>
AuthorDate: Fri Jul 29 21:11:12 2016 +0100
Committer: Alasdair G Kergon <agk(a)redhat.com>
CommitterDate: Fri Jul 29 21:11:12 2016 +0100
lvconvert: Remove hard-coded segment names.
---
tools/lvconvert.c | 116 ++++++++++++++++++++++++++--------------------------
1 files changed, 58 insertions(+), 58 deletions(-)
diff --git a/tools/lvconvert.c b/tools/lvconvert.c
index 62c21bd..9e850b3 100644
--- a/tools/lvconvert.c
+++ b/tools/lvconvert.c
@@ -53,8 +53,9 @@ struct lvconvert_params {
int thin;
int uncache;
const char *type_str; /* When this is set, mirrors_supplied may optionally also be set */
+ /* Holds what you asked for based on --type or other arguments, else "" */
- const struct segment_type *segtype;
+ const struct segment_type *segtype; /* Holds what segment type you will get */
int merge_snapshot; /* merge is also set */
int merge_mirror; /* merge is also set */
@@ -273,57 +274,56 @@ static int _lvconvert_name_params(struct lvconvert_params *lp,
return 1;
}
-static int _check_conversion_type(struct cmd_context *cmd, const char *type_str)
-{
- if (!type_str || !*type_str)
- return 1;
-
- if (!strcmp(type_str, "mirror")) {
- if (!arg_is_set(cmd, mirrors_ARG)) {
- log_error("Conversions to --type mirror require -m/--mirrors");
- return 0;
- }
- return 1;
- }
-
- /* FIXME: Check thin-pool and thin more thoroughly! */
- if (!strcmp(type_str, "snapshot") || !strcmp(type_str, "linear") ||
- !strcmp(type_str, "striped") ||
- !strncmp(type_str, "raid", 4) ||
- !strcmp(type_str, "cache-pool") || !strcmp(type_str, "cache") ||
- !strcmp(type_str, "thin-pool") || !strcmp(type_str, "thin"))
- return 1;
-
- log_error("Conversion using --type %s is not supported.", type_str);
- return 0;
-}
-
/* -s/--snapshot and --type snapshot are synonyms */
static int _snapshot_type_requested(struct cmd_context *cmd, const char *type_str)
{
- return (arg_is_set(cmd, snapshot_ARG) || !strcmp(type_str, "snapshot"));
+ return (arg_is_set(cmd, snapshot_ARG) || !strcmp(type_str, SEG_TYPE_NAME_SNAPSHOT));
}
-static int _raid0_type_requested(struct cmd_context *cmd, const char *type_str)
+static int _raid0_type_requested(const char *type_str)
{
- return (!strcmp(type_str, "raid0") || !strcmp(type_str, "raid0_meta"));
+ return (!strcmp(type_str, SEG_TYPE_NAME_RAID0) || !strcmp(type_str, SEG_TYPE_NAME_RAID0_META));
}
/* mirror/raid* (1,10,4,5,6 and their variants) reshape */
static int _mirror_or_raid_type_requested(struct cmd_context *cmd, const char *type_str)
{
- return (arg_is_set(cmd, mirrors_ARG) || !strcmp(type_str, "mirror") ||
- (!strncmp(type_str, "raid", 4) && !_raid0_type_requested(cmd, type_str)));
+ return (arg_is_set(cmd, mirrors_ARG) || !strcmp(type_str, SEG_TYPE_NAME_MIRROR) ||
+ (!strncmp(type_str, SEG_TYPE_NAME_RAID, 4) && !_raid0_type_requested(type_str)));
}
-static int _striped_type_requested(struct cmd_context *cmd, const char *type_str)
+static int _linear_type_requested(const char *type_str)
{
- return (!strcmp(type_str, SEG_TYPE_NAME_STRIPED) || !strcmp(type_str, SEG_TYPE_NAME_LINEAR));
+ return (!strcmp(type_str, SEG_TYPE_NAME_LINEAR));
}
-static int _linear_type_requested(const char *type_str)
+static int _striped_type_requested(const char *type_str)
{
- return (!strcmp(type_str, SEG_TYPE_NAME_LINEAR));
+ return (!strcmp(type_str, SEG_TYPE_NAME_STRIPED) || _linear_type_requested(type_str));
+}
+
+static int _check_conversion_type(struct cmd_context *cmd, const char *type_str)
+{
+ if (!type_str || !*type_str)
+ return 1;
+
+ if (!strcmp(type_str, SEG_TYPE_NAME_MIRROR)) {
+ if (!arg_is_set(cmd, mirrors_ARG)) {
+ log_error("Conversions to --type mirror require -m/--mirrors");
+ return 0;
+ }
+ return 1;
+ }
+
+ /* FIXME: Check thin-pool and thin more thoroughly! */
+ if (!strcmp(type_str, SEG_TYPE_NAME_SNAPSHOT) || _striped_type_requested(type_str) ||
+ !strncmp(type_str, SEG_TYPE_NAME_RAID, 4) ||
+ !strcmp(type_str, SEG_TYPE_NAME_CACHE_POOL) || !strcmp(type_str, SEG_TYPE_NAME_CACHE) ||
+ !strcmp(type_str, SEG_TYPE_NAME_THIN_POOL) || !strcmp(type_str, SEG_TYPE_NAME_THIN))
+ return 1;
+
+ log_error("Conversion using --type %s is not supported.", type_str);
+ return 0;
}
static int _read_pool_params(struct cmd_context *cmd, int *pargc, char ***pargv,
@@ -334,27 +334,27 @@ static int _read_pool_params(struct cmd_context *cmd, int *pargc, char ***pargv,
if ((lp->pool_data_name = arg_str_value(cmd, cachepool_ARG, NULL))) {
if (lp->type_str[0] &&
- strcmp(lp->type_str, "cache") &&
- strcmp(lp->type_str, "cache-pool")) {
+ strcmp(lp->type_str, SEG_TYPE_NAME_CACHE) &&
+ strcmp(lp->type_str, SEG_TYPE_NAME_CACHE_POOL)) {
log_error("--cachepool argument is only valid with "
"the cache or cache-pool segment type.");
return 0;
}
cachepool = 1;
- lp->type_str = "cache-pool";
- } else if (!strcmp(lp->type_str, "cache-pool"))
+ lp->type_str = SEG_TYPE_NAME_CACHE_POOL;
+ } else if (!strcmp(lp->type_str, SEG_TYPE_NAME_CACHE_POOL))
cachepool = 1;
else if ((lp->pool_data_name = arg_str_value(cmd, thinpool_ARG, NULL))) {
if (lp->type_str[0] &&
- strcmp(lp->type_str, "thin") &&
- strcmp(lp->type_str, "thin-pool")) {
+ strcmp(lp->type_str, SEG_TYPE_NAME_THIN) &&
+ strcmp(lp->type_str, SEG_TYPE_NAME_THIN_POOL)) {
log_error("--thinpool argument is only valid with "
"the thin or thin-pool segment type.");
return 0;
}
thinpool = 1;
- lp->type_str = "thin-pool";
- } else if (!strcmp(lp->type_str, "thin-pool"))
+ lp->type_str = SEG_TYPE_NAME_THIN_POOL;
+ } else if (!strcmp(lp->type_str, SEG_TYPE_NAME_THIN_POOL))
thinpool = 1;
if (lp->cache && !cachepool) {
@@ -505,27 +505,27 @@ static int _read_params(struct cmd_context *cmd, int argc, char **argv,
if (arg_is_set(cmd, cache_ARG))
lp->cache = 1;
- if (!strcmp(lp->type_str, "cache"))
+ if (!strcmp(lp->type_str, SEG_TYPE_NAME_CACHE))
lp->cache = 1;
else if (lp->cache) {
if (lp->type_str[0]) {
log_error("--cache is incompatible with --type %s", lp->type_str);
return 0;
}
- lp->type_str = "cache";
+ lp->type_str = SEG_TYPE_NAME_CACHE;
}
if (arg_is_set(cmd, thin_ARG))
lp->thin = 1;
- if (!strcmp(lp->type_str, "thin"))
+ if (!strcmp(lp->type_str, SEG_TYPE_NAME_THIN))
lp->thin = 1;
else if (lp->thin) {
if (lp->type_str[0]) {
log_error("--thin is incompatible with --type %s", lp->type_str);
return 0;
}
- lp->type_str = "thin";
+ lp->type_str = SEG_TYPE_NAME_THIN;
}
/* May set lp->segtype */
@@ -594,12 +594,12 @@ static int _read_params(struct cmd_context *cmd, int argc, char **argv,
!lp->splitcache && !lp->split && !lp->snapshot && !lp->uncache && !lp->cache && !lp->thin &&
!lp->replace && !lp->repair && !lp->mirrorlog && !lp->corelog &&
(arg_is_set(cmd, stripes_long_ARG) || arg_is_set(cmd, stripesize_ARG)))
- lp->type_str = "striped";
+ lp->type_str = SEG_TYPE_NAME_STRIPED;
if ((_snapshot_type_requested(cmd, lp->type_str) || lp->merge) &&
(lp->mirrorlog || _mirror_or_raid_type_requested(cmd, lp->type_str) ||
- lp->repair || arg_is_set(cmd, thinpool_ARG) || _raid0_type_requested(cmd, lp->type_str) ||
- _striped_type_requested(cmd, lp->type_str))) {
+ lp->repair || arg_is_set(cmd, thinpool_ARG) || _raid0_type_requested(lp->type_str) ||
+ _striped_type_requested(lp->type_str))) {
log_error("--snapshot/--type snapshot or --merge argument "
"cannot be mixed with --mirrors/--type mirror/--type raid*/--stripes/--type striped/--type linear, "
"--mirrorlog, --repair or --thinpool.");
@@ -607,8 +607,8 @@ static int _read_params(struct cmd_context *cmd, int argc, char **argv,
}
if ((arg_is_set(cmd, stripes_long_ARG) || arg_is_set(cmd, stripesize_ARG)) &&
- !(_mirror_or_raid_type_requested(cmd, lp->type_str) || _striped_type_requested(cmd, lp->type_str) ||
- _raid0_type_requested(cmd, lp->type_str) || lp->repair || arg_is_set(cmd, thinpool_ARG))) {
+ !(_mirror_or_raid_type_requested(cmd, lp->type_str) || _striped_type_requested(lp->type_str) ||
+ _raid0_type_requested(lp->type_str) || lp->repair || arg_is_set(cmd, thinpool_ARG))) {
log_error("--stripes or --stripesize argument is only valid "
"with --mirrors/--type mirror/--type raid*/--type striped/--type linear, --repair and --thinpool");
return 0;
@@ -786,7 +786,7 @@ static int _read_params(struct cmd_context *cmd, int argc, char **argv,
if (!(lp->segtype = get_segtype_from_string(cmd, arg_str_value(cmd, type_ARG, find_config_tree_str(cmd, global_mirror_segtype_default_CFG, NULL)))))
return_0;
}
- } else if (_raid0_type_requested(cmd, lp->type_str) || _striped_type_requested(cmd, lp->type_str)) { /* striped or linear or raid0 */
+ } else if (_raid0_type_requested(lp->type_str) || _striped_type_requested(lp->type_str)) { /* striped or linear or raid0 */
if (arg_from_list_is_set(cmd, "cannot be used with --type raid0 or --type striped or --type linear",
chunksize_ARG, corelog_ARG, mirrors_ARG, mirrorlog_ARG, regionsize_ARG, zero_ARG,
-1))
@@ -1897,10 +1897,10 @@ static int _lvconvert_raid(struct logical_volume *lv, struct lvconvert_params *l
/* --trackchanges requires --splitmirrors which always has SIGN_MINUS */
if (lp->track_changes && lp->mirrors != 1) {
- log_error("Exactly one image must be split off from %s when tracking changes.",
+ log_error("Exactly one image must be split off from %s when tracking changes.",
display_lvname(lv));
- return 0;
- }
+ return 0;
+ }
}
if (lp->merge_mirror)
@@ -4366,8 +4366,8 @@ static int _convert_striped(struct cmd_context *cmd, struct logical_volume *lv,
*
* for each lvtype,
* _convert_lvtype();
- * for each arg_is_set(operation)
- * _convert_lvtype_operation();
+ * for each arg_is_set(operation)
+ * _convert_lvtype_operation();
*
*/
static int _lvconvert(struct cmd_context *cmd, struct logical_volume *lv,
7 years, 4 months