1
0
mirror of git://sourceware.org/git/lvm2.git synced 2024-12-21 13:34:40 +03:00

lvdisplay: split code for variants using command defs

This commit is contained in:
David Teigland 2024-12-05 13:40:44 -06:00
parent 275c9666b6
commit 9beea2db69
4 changed files with 33 additions and 38 deletions

View File

@ -1411,6 +1411,7 @@ OO: OO_REPORTING, --history, --segments, --maps
OP: VG|LV|Tag ...
IO: --partial, --ignoreskippedcluster
ID: lvdisplay_general
DESC: Display Logical Volumes.
---

View File

@ -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;
}

View File

@ -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 },

View File

@ -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);