]> sourceware.org Git - lvm2.git/commitdiff
lvconvert: vdo may convert already formated vdo
authorZdenek Kabelac <zkabelac@redhat.com>
Tue, 16 Feb 2021 20:26:35 +0000 (21:26 +0100)
committerZdenek Kabelac <zkabelac@redhat.com>
Wed, 17 Feb 2021 10:21:35 +0000 (11:21 +0100)
User use 'lvconvert -Zn --type vdo-pool' to convert an existing
vdo formated volume and skip lvm2 internal formating.
This however requires user is passing proper matching parameters.
For them user can use --profile|--metadataprofile option whos
support has been also enhanced.

TODO: add support to read values directly from formated volume.

lib/metadata/lv_manip.c
lib/metadata/metadata-exported.h
lib/metadata/vdo_manip.c
tools/command-lines.in
tools/lvconvert.c
tools/lvmcmdline.c

index 5784e407d3084bb62269990448e6418882a8845c..5cad4e07a86cebef900450f8cf09776107c3c6a2 100644 (file)
@@ -7469,6 +7469,9 @@ struct logical_volume *insert_layer_for_lv(struct cmd_context *cmd,
        lv_where->le_count = layer_lv->le_count;
        lv_where->size = (uint64_t) lv_where->le_count * lv_where->vg->extent_size;
 
+       if (lv_where->vg->fid->fmt->features & FMT_CONFIG_PROFILE)
+               lv_where->profile = lv_where->vg->cmd->profile_params->global_metadata_profile;
+
        /*
         * recuresively rename sub LVs
         *   currently supported only for thin data layer
@@ -8693,7 +8696,7 @@ static struct logical_volume *_lv_create_an_lv(struct volume_group *vg,
        }
 
        if (seg_is_vdo_pool(lp)) {
-               if (!convert_vdo_pool_lv(lv, &lp->vdo_params, &lp->virtual_extents)) {
+               if (!convert_vdo_pool_lv(lv, &lp->vdo_params, &lp->virtual_extents, 1)) {
                        stack;
                        goto deactivate_and_revert_new_lv;
                }
index ac384497b5e27644f86603b76dd481cfbd51c176..8740889939fa74e6a9cc21ae7b8cbffe5ccd4647 100644 (file)
@@ -1355,7 +1355,8 @@ int parse_vdo_pool_status(struct dm_pool *mem, const struct logical_volume *vdo_
                          const char *params, struct lv_status_vdo *status);
 struct logical_volume *convert_vdo_pool_lv(struct logical_volume *data_lv,
                                           const struct dm_vdo_target_params *vtp,
-                                          uint32_t *virtual_extents);
+                                          uint32_t *virtual_extents,
+                                          int format);
 int set_vdo_write_policy(enum dm_vdo_write_policy *vwp, const char *policy);
 int fill_vdo_target_params(struct cmd_context *cmd,
                           struct dm_vdo_target_params *vtp,
index 30682449c042abb2c943b939c1943c57fde9c052..7d5a2cb5a9b81836dab0ab47f6c2efbc93b48cb0 100644 (file)
@@ -355,7 +355,8 @@ static int _format_vdo_pool_data_lv(struct logical_volume *data_lv,
  */
 struct logical_volume *convert_vdo_pool_lv(struct logical_volume *data_lv,
                                           const struct dm_vdo_target_params *vtp,
-                                          uint32_t *virtual_extents)
+                                          uint32_t *virtual_extents,
+                                          int format)
 {
        const uint64_t header_size = DEFAULT_VDO_POOL_HEADER_SIZE;
        const uint32_t extent_size = data_lv->vg->extent_size;
@@ -384,9 +385,15 @@ struct logical_volume *convert_vdo_pool_lv(struct logical_volume *data_lv,
                return_0;
 
        /* Format data LV as VDO volume */
-       if (!_format_vdo_pool_data_lv(data_lv, vtp, &vdo_logical_size)) {
-               log_error("Cannot format VDO pool volume %s.", display_lvname(data_lv));
-               return NULL;
+       if (format) {
+               if (!_format_vdo_pool_data_lv(data_lv, vtp, &vdo_logical_size)) {
+                       log_error("Cannot format VDO pool volume %s.", display_lvname(data_lv));
+                       return NULL;
+               }
+       } else {
+               log_verbose("Skiping VDO formating %s.", display_lvname(data_lv));
+               /* TODO: parse existing VDO data and retrieve vdo_logical_size */
+               vdo_logical_size = data_lv->size;
        }
 
        if (!deactivate_lv(data_lv->vg->cmd, data_lv)) {
index 7c7551405f7136bd44e610afd933f47af55268b6..2aadd5f40b22bef469d6aaff98057f46ec9ef0b1 100644 (file)
@@ -324,6 +324,10 @@ OO_LVCONVERT_CACHE: --cachemetadataformat CacheMetadataFormat,
 --cachemode CacheMode, --cachepolicy String,
 --cachesettings String, --zero Bool
 
+OO_LVCONVERT_VDO: --metadataprofile String --readahead Readahead,
+--compression Bool, --deduplication Bool
+--zero Bool
+
 OO_LVCONVERT: --alloc Alloc, --background, --force, --noudevsync
 
 ---
@@ -604,15 +608,15 @@ RULE: --poolmetadata not --readahead --stripesize --stripes_long
 ---
 
 lvconvert --type vdo-pool LV_linear_striped_raid_cache
-OO: --name LV_new, --virtualsize SizeMB, --compression Bool, --deduplication Bool, OO_LVCONVERT
+OO: --name LV_new, --virtualsize SizeMB, OO_LVCONVERT_VDO, OO_LVCONVERT
 ID: lvconvert_to_vdopool
 DESC: Convert LV to type vdopool.
 RULE: all and lv_is_visible
 RULE: all not lv_is_locked lv_is_origin lv_is_merging_origin lv_is_external_origin lv_is_virtual lv_is_raid_with_integrity
 
 lvconvert --vdopool LV_linear_striped_raid_cache
-OO: --type vdo-pool, OO_LVCONVERT,
---name LV_new, --virtualsize SizeMB, --compression Bool, --deduplication Bool
+OO: --type vdo-pool, OO_LVCONVERT_VDO, OO_LVCONVERT
+--name LV_new, --virtualsize SizeMB,
 ID: lvconvert_to_vdopool_param
 DESC: Convert LV to type vdopool.
 RULE: all and lv_is_visible
index 8df30ff02505275b1a1d3041a9bbcf277f66693b..ef31799fa3530a30fb6828919d1b4bc8a7c49442 100644 (file)
@@ -5443,6 +5443,7 @@ static int _lvconvert_to_vdopool_single(struct cmd_context *cmd,
                                        struct processing_handle *handle)
 {
        const char *vg_name = NULL;
+       unsigned int zero_vdopool;
        struct volume_group *vg = lv->vg;
        struct logical_volume *vdo_lv;
        struct dm_vdo_target_params vdo_params; /* vdo */
@@ -5455,7 +5456,7 @@ static int _lvconvert_to_vdopool_single(struct cmd_context *cmd,
                .permission = LVM_READ | LVM_WRITE,
                .pool_name = lv->name,
                .pvh = &vg->pvs,
-               .read_ahead = DM_READ_AHEAD_AUTO,
+               .read_ahead = arg_uint_value(cmd, readahead_ARG, DM_READ_AHEAD_AUTO),
                .stripes = 1,
                .lv_name = arg_str_value(cmd, name_ARG, NULL),
        };
@@ -5477,7 +5478,7 @@ static int _lvconvert_to_vdopool_single(struct cmd_context *cmd,
                goto out;
        }
 
-       if (!fill_vdo_target_params(cmd, &vdo_params, NULL))
+       if (!fill_vdo_target_params(cmd, &vdo_params, vg->profile))
                goto_out;
 
        if (arg_is_set(cmd, compression_ARG))
@@ -5493,28 +5494,36 @@ static int _lvconvert_to_vdopool_single(struct cmd_context *cmd,
                goto out;
        }
 
-       log_warn("WARNING: Converting logical volume %s to VDO pool volume.",
-                lv->name);
-       log_warn("THIS WILL DESTROY CONTENT OF LOGICAL VOLUME (filesystem etc.)");
+       zero_vdopool = arg_int_value(cmd, zero_ARG, 1);
+
+       log_warn("WARNING: Converting logical volume %s to VDO pool volume %s formating.",
+                display_lvname(lv), zero_vdopool ? "with" : "WITHOUT");
+
+       if (zero_vdopool)
+               log_warn("THIS WILL DESTROY CONTENT OF LOGICAL VOLUME (filesystem etc.)");
+       else
+               log_warn("WARNING: Using invalid VDO pool data MAY DESTROY YOUR DATA!");
 
        if (!arg_count(cmd, yes_ARG) &&
            yes_no_prompt("Do you really want to convert %s? [y/n]: ",
-                         lv->name) == 'n') {
+                         display_lvname(lv)) == 'n') {
                log_error("Conversion aborted.");
                goto out;
        }
 
-       if (!wipe_lv(lv, (struct wipe_params) { .do_zero = 1, .do_wipe_signatures = 1,
-                    .yes = arg_count(cmd, yes_ARG),
-                    .force = arg_count(cmd, force_ARG)})) {
-               log_error("Aborting. Failed to wipe VDO data store.");
-               goto out;
+       if (zero_vdopool) {
+               if (!wipe_lv(lv, (struct wipe_params) { .do_zero = 1, .do_wipe_signatures = 1,
+                            .yes = arg_count(cmd, yes_ARG),
+                            .force = arg_count(cmd, force_ARG)})) {
+                       log_error("Aborting. Failed to wipe VDO data store.");
+                       goto out;
+               }
        }
 
        if (!archive(vg))
                goto_out;
 
-       if (!convert_vdo_pool_lv(lv, &vdo_params, &lvc.virtual_extents))
+       if (!convert_vdo_pool_lv(lv, &vdo_params, &lvc.virtual_extents, zero_vdopool))
                goto_out;
 
        dm_list_init(&lvc.tags);
index 5b7951f3befd8168414445da9e47867ba71c1711..560c78a77fef325ed3bc661e8177c7b2972f6f38 100644 (file)
@@ -2699,6 +2699,7 @@ static int _prepare_profiles(struct cmd_context *cmd)
                 * The --commandprofile is assumed otherwise.
                 */
                if (!strcmp(cmd->command->name, "lvcreate") ||
+                   !strcmp(cmd->command->name, "lvconvert") ||
                    !strcmp(cmd->command->name, "vgcreate") ||
                    !strcmp(cmd->command->name, "lvchange") ||
                    !strcmp(cmd->command->name, "vgchange")) {
This page took 0.054263 seconds and 5 git commands to generate.