1
0
mirror of git://sourceware.org/git/lvm2.git synced 2025-01-03 05:18:29 +03:00

lvconvert: vdo may convert already formated vdo

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.
This commit is contained in:
Zdenek Kabelac 2021-02-16 21:26:35 +01:00
parent f87ff95e32
commit a915cd5a46
6 changed files with 46 additions and 21 deletions

View 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->le_count = layer_lv->le_count;
lv_where->size = (uint64_t) lv_where->le_count * lv_where->vg->extent_size; 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 * recuresively rename sub LVs
* currently supported only for thin data layer * 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 (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; stack;
goto deactivate_and_revert_new_lv; goto deactivate_and_revert_new_lv;
} }

View 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); const char *params, struct lv_status_vdo *status);
struct logical_volume *convert_vdo_pool_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, 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 set_vdo_write_policy(enum dm_vdo_write_policy *vwp, const char *policy);
int fill_vdo_target_params(struct cmd_context *cmd, int fill_vdo_target_params(struct cmd_context *cmd,
struct dm_vdo_target_params *vtp, struct dm_vdo_target_params *vtp,

View 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, struct logical_volume *convert_vdo_pool_lv(struct logical_volume *data_lv,
const struct dm_vdo_target_params *vtp, 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 uint64_t header_size = DEFAULT_VDO_POOL_HEADER_SIZE;
const uint32_t extent_size = data_lv->vg->extent_size; const uint32_t extent_size = data_lv->vg->extent_size;
@ -384,10 +385,16 @@ struct logical_volume *convert_vdo_pool_lv(struct logical_volume *data_lv,
return_0; return_0;
/* Format data LV as VDO volume */ /* Format data LV as VDO volume */
if (format) {
if (!_format_vdo_pool_data_lv(data_lv, vtp, &vdo_logical_size)) { if (!_format_vdo_pool_data_lv(data_lv, vtp, &vdo_logical_size)) {
log_error("Cannot format VDO pool volume %s.", display_lvname(data_lv)); log_error("Cannot format VDO pool volume %s.", display_lvname(data_lv));
return NULL; 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)) { if (!deactivate_lv(data_lv->vg->cmd, data_lv)) {
log_error("Cannot deactivate formated VDO pool volume %s.", log_error("Cannot deactivate formated VDO pool volume %s.",

View File

@ -324,6 +324,10 @@ OO_LVCONVERT_CACHE: --cachemetadataformat CacheMetadataFormat,
--cachemode CacheMode, --cachepolicy String, --cachemode CacheMode, --cachepolicy String,
--cachesettings String, --zero Bool --cachesettings String, --zero Bool
OO_LVCONVERT_VDO: --metadataprofile String --readahead Readahead,
--compression Bool, --deduplication Bool
--zero Bool
OO_LVCONVERT: --alloc Alloc, --background, --force, --noudevsync 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 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 ID: lvconvert_to_vdopool
DESC: Convert LV to type vdopool. DESC: Convert LV to type vdopool.
RULE: all and lv_is_visible 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 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 lvconvert --vdopool LV_linear_striped_raid_cache
OO: --type vdo-pool, OO_LVCONVERT, OO: --type vdo-pool, OO_LVCONVERT_VDO, OO_LVCONVERT
--name LV_new, --virtualsize SizeMB, --compression Bool, --deduplication Bool --name LV_new, --virtualsize SizeMB,
ID: lvconvert_to_vdopool_param ID: lvconvert_to_vdopool_param
DESC: Convert LV to type vdopool. DESC: Convert LV to type vdopool.
RULE: all and lv_is_visible RULE: all and lv_is_visible

View File

@ -5443,6 +5443,7 @@ static int _lvconvert_to_vdopool_single(struct cmd_context *cmd,
struct processing_handle *handle) struct processing_handle *handle)
{ {
const char *vg_name = NULL; const char *vg_name = NULL;
unsigned int zero_vdopool;
struct volume_group *vg = lv->vg; struct volume_group *vg = lv->vg;
struct logical_volume *vdo_lv; struct logical_volume *vdo_lv;
struct dm_vdo_target_params vdo_params; /* vdo */ 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, .permission = LVM_READ | LVM_WRITE,
.pool_name = lv->name, .pool_name = lv->name,
.pvh = &vg->pvs, .pvh = &vg->pvs,
.read_ahead = DM_READ_AHEAD_AUTO, .read_ahead = arg_uint_value(cmd, readahead_ARG, DM_READ_AHEAD_AUTO),
.stripes = 1, .stripes = 1,
.lv_name = arg_str_value(cmd, name_ARG, NULL), .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; goto out;
} }
if (!fill_vdo_target_params(cmd, &vdo_params, NULL)) if (!fill_vdo_target_params(cmd, &vdo_params, vg->profile))
goto_out; goto_out;
if (arg_is_set(cmd, compression_ARG)) if (arg_is_set(cmd, compression_ARG))
@ -5493,28 +5494,36 @@ static int _lvconvert_to_vdopool_single(struct cmd_context *cmd,
goto out; goto out;
} }
log_warn("WARNING: Converting logical volume %s to VDO pool volume.", zero_vdopool = arg_int_value(cmd, zero_ARG, 1);
lv->name);
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.)"); 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) && if (!arg_count(cmd, yes_ARG) &&
yes_no_prompt("Do you really want to convert %s? [y/n]: ", yes_no_prompt("Do you really want to convert %s? [y/n]: ",
lv->name) == 'n') { display_lvname(lv)) == 'n') {
log_error("Conversion aborted."); log_error("Conversion aborted.");
goto out; goto out;
} }
if (zero_vdopool) {
if (!wipe_lv(lv, (struct wipe_params) { .do_zero = 1, .do_wipe_signatures = 1, if (!wipe_lv(lv, (struct wipe_params) { .do_zero = 1, .do_wipe_signatures = 1,
.yes = arg_count(cmd, yes_ARG), .yes = arg_count(cmd, yes_ARG),
.force = arg_count(cmd, force_ARG)})) { .force = arg_count(cmd, force_ARG)})) {
log_error("Aborting. Failed to wipe VDO data store."); log_error("Aborting. Failed to wipe VDO data store.");
goto out; goto out;
} }
}
if (!archive(vg)) if (!archive(vg))
goto_out; 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; goto_out;
dm_list_init(&lvc.tags); dm_list_init(&lvc.tags);

View File

@ -2699,6 +2699,7 @@ static int _prepare_profiles(struct cmd_context *cmd)
* The --commandprofile is assumed otherwise. * The --commandprofile is assumed otherwise.
*/ */
if (!strcmp(cmd->command->name, "lvcreate") || if (!strcmp(cmd->command->name, "lvcreate") ||
!strcmp(cmd->command->name, "lvconvert") ||
!strcmp(cmd->command->name, "vgcreate") || !strcmp(cmd->command->name, "vgcreate") ||
!strcmp(cmd->command->name, "lvchange") || !strcmp(cmd->command->name, "lvchange") ||
!strcmp(cmd->command->name, "vgchange")) { !strcmp(cmd->command->name, "vgchange")) {