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

lvconvert: use command defs for mergemirrors

and route the generic --merge to one of the
specific merge functions
This commit is contained in:
David Teigland 2016-12-09 14:39:57 -06:00
parent 2231082e49
commit c5de28381e
5 changed files with 105 additions and 34 deletions

View File

@ -60,6 +60,7 @@ arg(locktype_ARG, '\0', "locktype", locktype_VAL, 0, 0)
arg(logonly_ARG, '\0', "logonly", 0, 0, 0)
arg(maxrecoveryrate_ARG, '\0', "maxrecoveryrate", sizekb_VAL, 0, 0)
arg(merge_ARG, '\0', "merge", 0, 0, 0)
arg(mergemirrors_ARG, '\0', "mergemirrors", 0, 0, 0)
arg(mergesnapshot_ARG, '\0', "mergesnapshot", 0, 0, 0)
arg(mergethin_ARG, '\0', "mergethin", 0, 0, 0)
arg(mergedconfig_ARG, '\0', "mergedconfig", 0, 0, 0)

View File

@ -373,6 +373,12 @@ OP: PV ...
ID: lvconvert_split_mirror_images
DESC: Split images from a raid1 LV and track changes to origin.
lvconvert --mergemirrors LV_linear_raid|VG|Tag ...
OO: OO_LVCONVERT
ID: lvconvert_merge_mirror_images
DESC: Merge LV images that were split from a raid1 LV.
RULE: all not lv_is_locked lv_is_pvmove lv_is_merging_origin lv_is_virtual_origin lv_is_external_origin lv_is_merging_cow
lvconvert --mirrorlog MirrorLog LV_mirror
OO: OO_LVCONVERT
OP: PV ...
@ -486,37 +492,21 @@ DESC: Swap metadata LV in a thin pool or cache pool (for repair only).
---
# FIXME: lvconvert --merge is an extremely ambiguous command.
# lvconvert --merge is an extremely ambiguous command.
# It can do very different operations, but which one depends
# on knowing the LV type. So, the command doesn't know what
# it's actually doing until quite late, when processing a
# single LV.
#
# Use different option names for different merge operations
# so that we can have different command definitions,
# different behaviors, different optional options, etc:
#
# lvconvert --merge-mirror LV_linear_striped_raid ...
# DESC: Merge LV that was previously split from a mirror.
#
# lvconvert --merge-thin LV_thin
# DESC: Merge thin LV into its origin LV.
#
# lvconvert --merge-snapshot LV_snapshot
# DESC: Merge COW snapshot LV into its origin.
#
# Then we could add VG|Tag to --merge-mirror arg pos 1, because
# "lvconvert --merge VG|Tag" is a terrible command. It will do
# different operations on each LV it finds, depending on the
# current LV type.
# single LV. When passed a VG or tag, it will do different
# operations on each LV it finds, depending on the current LV type.
lvconvert --merge LV_linear_striped_raid_thin_snapshot|VG|Tag ...
OO: --background, --interval Number, OO_LVCONVERT
ID: lvconvert_merge
DESC: Merge LV that was previously split from a mirror.
DESC: Merge thin LV into its origin LV.
DESC: Merge COW snapshot LV into its origin.
DESC: Merge LV that was split from a mirror (variant, use --mergemirrors).
DESC: Merge thin LV into its origin LV (variant, use --mergethin).
DESC: Merge COW snapshot LV into its origin (variant, use --mergesnapshot).
RULE: all not lv_is_locked lv_is_pvmove lv_is_merging_origin lv_is_virtual_origin lv_is_external_origin lv_is_merging_cow
FLAGS: SECONDARY_SYNTAX
---
@ -526,7 +516,7 @@ RULE: all not lv_is_locked lv_is_pvmove lv_is_merging_origin lv_is_virtual_origi
lvconvert --mergesnapshot LV_snapshot ...
OO: --background, --interval Number, OO_LVCONVERT
ID: lvconvert_merge_snapshot
DESC: Merge LV that was previously split from a mirror.
DESC: Merge COW snapshot LV into its origin.
RULE: all not lv_is_locked lv_is_pvmove lv_is_merging_origin lv_is_virtual_origin lv_is_external_origin lv_is_merging_cow
---
@ -884,7 +874,7 @@ DESC: (infers --type thin).
---
lvconvert --mergethin LV_thin ...
OO: --background, --interval Number, OO_LVCONVERT
OO: OO_LVCONVERT
ID: lvconvert_merge_thin
DESC: Merge thin LV into its origin LV.
RULE: all not lv_is_locked lv_is_pvmove lv_is_merging_origin lv_is_virtual_origin lv_is_external_origin lv_is_merging_cow

View File

@ -6167,3 +6167,75 @@ int lvconvert_split_cachepool_cmd(struct cmd_context *cmd, int argc, char **argv
NULL, NULL, &_lvconvert_split_cachepool_single);
}
static int _lvconvert_merge_mirror_images_single(struct cmd_context *cmd,
struct logical_volume *lv,
struct processing_handle *handle)
{
if (!lv_raid_merge(lv))
return ECMD_FAILED;
return ECMD_PROCESSED;
}
int lvconvert_merge_mirror_images_cmd(struct cmd_context *cmd, int argc, char **argv)
{
cmd->command->flags &= ~GET_VGNAME_FROM_OPTIONS;
return process_each_lv(cmd, cmd->position_argc, cmd->position_argv, NULL, NULL, READ_FOR_UPDATE,
NULL, NULL, &_lvconvert_merge_mirror_images_single);
}
static int _lvconvert_merge_generic_single(struct cmd_context *cmd,
struct logical_volume *lv,
struct processing_handle *handle)
{
int ret;
if (lv_is_cow(lv))
ret = _lvconvert_merge_snapshot_single(cmd, lv, handle);
else if (lv_is_thin_volume(lv))
ret = _lvconvert_merge_thin_single(cmd, lv, handle);
else
ret = _lvconvert_merge_mirror_images_single(cmd, lv, handle);
return ret;
}
int lvconvert_merge_cmd(struct cmd_context *cmd, int argc, char **argv)
{
struct processing_handle *handle;
struct lvconvert_result lr = { 0 };
struct convert_poll_id_list *idl;
int ret, poll_ret;
dm_list_init(&lr.poll_idls);
if (!(handle = init_processing_handle(cmd, NULL))) {
log_error("Failed to initialize processing handle.");
return ECMD_FAILED;
}
handle->custom_handle = &lr;
cmd->command->flags &= ~GET_VGNAME_FROM_OPTIONS;
ret = process_each_lv(cmd, cmd->position_argc, cmd->position_argv, NULL, NULL, READ_FOR_UPDATE,
handle, NULL, &_lvconvert_merge_generic_single);
/* polling is only used by merge_snapshot */
if (lr.need_polling) {
dm_list_iterate_items(idl, &lr.poll_idls) {
poll_ret = _lvconvert_poll_by_id(cmd, idl->id,
arg_is_set(cmd, background_ARG), 1, 0);
if (poll_ret > ret)
ret = poll_ret;
}
}
destroy_processing_handle(cmd, handle);
return ret;
}

View File

@ -146,19 +146,23 @@ struct command_function command_functions[COMMAND_ID_COUNT] = {
{ lvconvert_merge_thin_CMD, lvconvert_merge_thin_cmd },
{ lvconvert_split_and_keep_cachepool_CMD, lvconvert_split_cachepool_cmd },
{ lvconvert_split_and_remove_cachepool_CMD, lvconvert_split_cachepool_cmd },
};
/* lvconvert utilities for raid/mirror */
{ lvconvert_merge_mirror_images_CMD, lvconvert_merge_mirror_images_cmd },
#if 0
{ lvconvert_split_mirror_images_CMD, lvconvert_split_mirror_images_cmd },
{ lvconvert_change_mirrorlog_CMD, lvconvert_change_mirrorlog_cmd },
#endif
/* redirected to merge_snapshot/merge_thin/merge_mirrors */
{ lvconvert_merge_CMD, lvconvert_merge_cmd },
#if 0
/* all raid-related type conversions */
{ lvconvert_raid_types_CMD, lvconvert_raid_types_fn },
/* raid-related utilities (move into lvconvert_raid_types?) */
{ lvconvert_split_mirror_images_CMD, lvconvert_split_mirror_images_fn },
{ lvconvert_change_mirrorlog_CMD, lvconvert_change_mirrorlog_fn },
/* directed to one of the other merges (snap,thin,mirror) when all are implemented */
{ lvconvert_merge_CMD, lvconvert_merge_fn },
{ lvconvert_raid_types_CMD, lvconvert_raid_types_cmd },
#endif
};
/* Command line args */
unsigned arg_count(const struct cmd_context *cmd, int a)

View File

@ -270,4 +270,8 @@ int lvconvert_swap_pool_metadata_cmd(struct cmd_context *cmd, int argc, char **a
int lvconvert_merge_thin_cmd(struct cmd_context *cmd, int argc, char **argv);
int lvconvert_split_cachepool_cmd(struct cmd_context *cmd, int argc, char **argv);
int lvconvert_merge_mirror_images_cmd(struct cmd_context *cmd, int argc, char **argv);
int lvconvert_merge_cmd(struct cmd_context *cmd, int argc, char **argv);
#endif