diff options
author | Zdenek Kabelac <zkabelac@redhat.com> | 2014-11-24 00:35:27 +0100 |
---|---|---|
committer | Zdenek Kabelac <zkabelac@redhat.com> | 2014-11-24 14:39:04 +0100 |
commit | 1e80265c368f135bf7a92c5bb4ed49948a76f712 (patch) | |
tree | 1933fad08ccd931ee7bd39b7e3ef4634f00af765 | |
parent | a058fab118b74ddddc8492752748f0a68c014ce6 (diff) | |
download | lvm2-1e80265c368f135bf7a92c5bb4ed49948a76f712.tar.gz |
lvconvert: earlier detection of conflicting names
Detect same LV names for lvconvert prior opening VG.
i.e. lvconvert --thinpool vg/lvol0 -T lvol0
-rw-r--r-- | test/shell/lvconvert-thin.sh | 4 | ||||
-rw-r--r-- | tools/lvconvert.c | 25 |
2 files changed, 27 insertions, 2 deletions
diff --git a/test/shell/lvconvert-thin.sh b/test/shell/lvconvert-thin.sh index 74484b1ed..951f6943e 100644 --- a/test/shell/lvconvert-thin.sh +++ b/test/shell/lvconvert-thin.sh @@ -53,7 +53,7 @@ lvchange -an $vg/$lv1 # conversion fails for mirror segment type fail lvconvert --thinpool $vg/$lv1 # cannot use same LV -fail lvconvert --yes --thinpool $vg/$lv2 --poolmetadata $vg/$lv2 +invalid lvconvert --yes --thinpool $vg/$lv2 --poolmetadata $vg/$lv2 prepare_lvs @@ -104,7 +104,7 @@ invalid lvconvert -c -256 --thinpool $vg/$lv1 --poolmetadata $vg/$lv2 invalid lvconvert -c 88 --thinpool $vg/$lv1 --poolmetadata $vg/$lv2 # cannot use same LV for pool and convertion -fail lvconvert --yes --thinpool $vg/$lv3 -T $vg/$lv3 +invalid lvconvert --yes --thinpool $vg/$lv3 -T $vg/$lv3 # Warning about smaller then suggested lvconvert --yes -c 256 --thinpool $vg/$lv1 --poolmetadata $vg/$lv2 |& tee err diff --git a/tools/lvconvert.c b/tools/lvconvert.c index 8436c24fd..c7acd5d16 100644 --- a/tools/lvconvert.c +++ b/tools/lvconvert.c @@ -76,6 +76,28 @@ struct lvconvert_params { thin_discards_t discards; }; +static int _lvconvert_validate_names(struct lvconvert_params *lp) +{ + int i, j; + const char *names[] = { + (lp->lv_name == lp->pool_data_name) ? NULL : lp->lv_name, "converted", + lp->pool_data_name, "pool", + lp->pool_metadata_name, "pool metadata", + lp->origin_name, "origin", + }; + + for (i = 0; i < DM_ARRAY_SIZE(names); i += 2) + if (names[i]) + for (j = i + 2; j < DM_ARRAY_SIZE(names); j += 2) + if (names[j] && !strcmp(names[i], names[j])) { + log_error("Can't use same name %s for %s and %s volume.", + names[i], names[i + 1], names[j + 1]); + return 0; + } + + return 1; +} + static int _lvconvert_name_params(struct lvconvert_params *lp, struct cmd_context *cmd, int *pargc, char ***pargv) @@ -195,6 +217,9 @@ static int _lvconvert_name_params(struct lvconvert_params *lp, } } + if (!_lvconvert_validate_names(lp)) + return_0; + return 1; } |