From 9beea2db69a51f58c5d22a294784852845ca6856 Mon Sep 17 00:00:00 2001 From: David Teigland Date: Thu, 5 Dec 2024 13:40:44 -0600 Subject: [PATCH] lvdisplay: split code for variants using command defs --- tools/command-lines.in | 1 + tools/lvdisplay.c | 68 +++++++++++++++++++----------------------- tools/lvmcmdline.c | 1 + tools/tools.h | 1 + 4 files changed, 33 insertions(+), 38 deletions(-) diff --git a/tools/command-lines.in b/tools/command-lines.in index 37a4aec75..5697ba2ce 100644 --- a/tools/command-lines.in +++ b/tools/command-lines.in @@ -1411,6 +1411,7 @@ OO: OO_REPORTING, --history, --segments, --maps OP: VG|LV|Tag ... IO: --partial, --ignoreskippedcluster ID: lvdisplay_general +DESC: Display Logical Volumes. --- diff --git a/tools/lvdisplay.c b/tools/lvdisplay.c index 1e26abe37..d38b24389 100644 --- a/tools/lvdisplay.c +++ b/tools/lvdisplay.c @@ -15,58 +15,50 @@ #include "tools.h" -static int _lvdisplay_single(struct cmd_context *cmd, struct logical_volume *lv, - struct processing_handle *handle __attribute__ ((unused))) +static int _lvdisplay_colon_single(struct cmd_context *cmd, struct logical_volume *lv, + struct processing_handle *handle __attribute__ ((unused))) { if (!arg_is_set(cmd, all_ARG) && !lv_is_visible(lv)) return ECMD_PROCESSED; - if (arg_is_set(cmd, colon_ARG)) - lvdisplay_colons(lv); - else { - lvdisplay_full(cmd, lv, NULL); - if (arg_is_set(cmd, maps_ARG)) - lvdisplay_segments(lv); - } + lvdisplay_colons(lv); return ECMD_PROCESSED; } -int lvdisplay(struct cmd_context *cmd, int argc, char **argv) +static int _lvdisplay_general_single(struct cmd_context *cmd, struct logical_volume *lv, + struct processing_handle *handle __attribute__ ((unused))) { - if (arg_is_set(cmd, columns_ARG)) { - if (arg_is_set(cmd, colon_ARG) || arg_is_set(cmd, maps_ARG)) { - log_error("Incompatible options selected"); - return EINVALID_CMD_LINE; - } - return lvs(cmd, argc, argv); - } + if (!arg_is_set(cmd, all_ARG) && !lv_is_visible(lv)) + return ECMD_PROCESSED; - if (arg_is_set(cmd, aligned_ARG) || - arg_is_set(cmd, binary_ARG) || - arg_is_set(cmd, noheadings_ARG) || - arg_is_set(cmd, options_ARG) || - arg_is_set(cmd, separator_ARG) || - arg_is_set(cmd, sort_ARG) || - arg_is_set(cmd, unbuffered_ARG)) { - log_error("Incompatible options selected."); - return EINVALID_CMD_LINE; - } + lvdisplay_full(cmd, lv, NULL); - if (arg_is_set(cmd, colon_ARG) && arg_is_set(cmd, maps_ARG)) { - log_error("Options -c and -m are incompatible."); - return EINVALID_CMD_LINE; - } + if (arg_is_set(cmd, maps_ARG)) + lvdisplay_segments(lv); - return process_each_lv(cmd, argc, argv, NULL, NULL, 0, NULL, NULL, &_lvdisplay_single); -} - -int lvdisplay_columns_cmd(struct cmd_context *cmd, int argc, char **argv) -{ - return lvdisplay(cmd, argc, argv); + return ECMD_PROCESSED; } int lvdisplay_colon_cmd(struct cmd_context *cmd, int argc, char **argv) { - return lvdisplay(cmd, argc, argv); + return process_each_lv(cmd, argc, argv, NULL, NULL, 0, NULL, NULL, &_lvdisplay_colon_single); } + +int lvdisplay_general_cmd(struct cmd_context *cmd, int argc, char **argv) +{ + return process_each_lv(cmd, argc, argv, NULL, NULL, 0, NULL, NULL, &_lvdisplay_general_single); +} + +int lvdisplay_columns_cmd(struct cmd_context *cmd, int argc, char **argv) +{ + return lvs(cmd, argc, argv); +} + +int lvdisplay(struct cmd_context *cmd, int argc, char **argv) +{ + log_error(INTERNAL_ERROR "Missing function for command definition %d:%s.", + cmd->command->command_index, command_enum(cmd->command->command_enum)); + return ECMD_FAILED; +} + diff --git a/tools/lvmcmdline.c b/tools/lvmcmdline.c index dee8933fd..2fe739c3f 100644 --- a/tools/lvmcmdline.c +++ b/tools/lvmcmdline.c @@ -91,6 +91,7 @@ static const struct command_function _command_functions[CMD_COUNT] = { /* lvdisplay variants */ { lvdisplay_columns_CMD, lvdisplay_columns_cmd }, { lvdisplay_colon_CMD, lvdisplay_colon_cmd }, + { lvdisplay_general_CMD, lvdisplay_general_cmd }, /* pvdisplay variants */ { pvdisplay_columns_CMD, pvdisplay_columns_cmd }, diff --git a/tools/tools.h b/tools/tools.h index 0fa00671c..ec8557996 100644 --- a/tools/tools.h +++ b/tools/tools.h @@ -190,6 +190,7 @@ int lvchange_persistent_cmd(struct cmd_context *cmd, int argc, char **argv); int lvdisplay_columns_cmd(struct cmd_context *cmd, int argc, char **argv); int lvdisplay_colon_cmd(struct cmd_context *cmd, int argc, char **argv); +int lvdisplay_general_cmd(struct cmd_context *cmd, int argc, char **argv); int pvdisplay_columns_cmd(struct cmd_context *cmd, int argc, char **argv); int pvdisplay_colon_cmd(struct cmd_context *cmd, int argc, char **argv); int vgdisplay_columns_cmd(struct cmd_context *cmd, int argc, char **argv);