From a8fb89adafedf64ef0915635785b25fd36bbbdaa Mon Sep 17 00:00:00 2001 From: Alasdair Kergon Date: Tue, 3 Nov 2009 15:50:42 +0000 Subject: [PATCH] Tidy some uses of arg_count and introduce arg_is_set. --- WHATS_NEW | 1 + WHATS_NEW_DM | 1 + tools/dumpconfig.c | 5 +---- tools/lvconvert.c | 4 +--- tools/lvcreate.c | 17 +++++------------ tools/lvmcmdline.c | 31 ++++++++++++++----------------- tools/lvresize.c | 4 ++-- tools/polldaemon.c | 2 +- tools/pvmove.c | 3 +-- tools/reporter.c | 6 ++---- tools/tools.h | 3 ++- 11 files changed, 31 insertions(+), 46 deletions(-) diff --git a/WHATS_NEW b/WHATS_NEW index d87f84a4e..668b4989f 100644 --- a/WHATS_NEW +++ b/WHATS_NEW @@ -1,5 +1,6 @@ Version 2.02.55 - =================================== + Tidy some uses of arg_count and introduce arg_is_set. Export outnl and indent functions for modules. Flush stdout after yes/no prompt. Update vgsplit and vgcreate to use vg_set_clustered. diff --git a/WHATS_NEW_DM b/WHATS_NEW_DM index 3e4517247..71b0223ac 100644 --- a/WHATS_NEW_DM +++ b/WHATS_NEW_DM @@ -1,5 +1,6 @@ Version 1.02.40 - =================================== + Fix hash lookup segfault when keys compared are different lengths. Version 1.02.39 - 26th October 2009 =================================== diff --git a/tools/dumpconfig.c b/tools/dumpconfig.c index c7c58c15e..981147c58 100644 --- a/tools/dumpconfig.c +++ b/tools/dumpconfig.c @@ -17,10 +17,7 @@ int dumpconfig(struct cmd_context *cmd, int argc, char **argv) { - const char *file = NULL; - - if (arg_count(cmd, file_ARG)) - file = arg_str_value(cmd, file_ARG, ""); + const char *file = arg_str_value(cmd, file_ARG, NULL); if (!write_config_file(cmd->cft, file, argc, argv)) { stack; diff --git a/tools/lvconvert.c b/tools/lvconvert.c index 1ec28bcea..0821c3067 100644 --- a/tools/lvconvert.c +++ b/tools/lvconvert.c @@ -129,9 +129,7 @@ static int _read_params(struct lvconvert_params *lp, struct cmd_context *cmd, lp->mirrors_sign = arg_sign_value(cmd, mirrors_ARG, 0); } - lp->alloc = ALLOC_INHERIT; - if (arg_count(cmd, alloc_ARG)) - lp->alloc = arg_uint_value(cmd, alloc_ARG, lp->alloc); + lp->alloc = arg_uint_value(cmd, alloc_ARG, ALLOC_INHERIT); if (lp->snapshot) { if (arg_count(cmd, regionsize_ARG)) { diff --git a/tools/lvcreate.c b/tools/lvcreate.c index be6b5ccea..c677d6bb9 100644 --- a/tools/lvcreate.c +++ b/tools/lvcreate.c @@ -33,8 +33,7 @@ static int _lvcreate_name_params(struct lvcreate_params *lp, char **argv = *pargv, *ptr; char *vg_name; - if (arg_count(cmd, name_ARG)) - lp->lv_name = arg_value(cmd, name_ARG); + lp->lv_name = arg_str_value(cmd, name_ARG, NULL); if (lp->snapshot && !arg_count(cmd, virtualsize_ARG)) { if (!argc) { @@ -347,7 +346,7 @@ static int _read_mirror_params(struct lvcreate_params *lp, log_verbose("Setting logging type to %s", mirrorlog); - lp->nosync = arg_count(cmd, nosync_ARG) ? 1 : 0; + lp->nosync = arg_is_set(cmd, nosync_ARG); if (arg_count(cmd, regionsize_ARG)) { if (arg_sign_value(cmd, regionsize_ARG, 0) == SIGN_MINUS) { @@ -521,10 +520,8 @@ static int _lvcreate_params(struct lvcreate_params *lp, /* * Permissions. */ - if (arg_count(cmd, permission_ARG)) - lp->permission = arg_uint_value(cmd, permission_ARG, 0); - else - lp->permission = LVM_READ | LVM_WRITE; + lp->permission = arg_uint_value(cmd, permission_ARG, + LVM_READ | LVM_WRITE); /* Must not zero read only volume */ if (!(lp->permission & LVM_WRITE)) @@ -558,11 +555,7 @@ static int _lvcreate_params(struct lvcreate_params *lp, return 0; } - if (arg_count(cmd, addtag_ARG) && - !(lp->tag = arg_str_value(cmd, addtag_ARG, NULL))) { - log_error("Failed to get tag"); - return 0; - } + lp->tag = arg_str_value(cmd, addtag_ARG, NULL); lcp->pv_count = argc; lcp->pvs = argv; diff --git a/tools/lvmcmdline.c b/tools/lvmcmdline.c index 31ebd1243..e92675f0d 100644 --- a/tools/lvmcmdline.c +++ b/tools/lvmcmdline.c @@ -54,61 +54,58 @@ static struct arg _the_args[ARG_COUNT + 1] = { static struct cmdline_context _cmdline; /* Command line args */ -/* FIXME: struct cmd_context * is unnecessary (large # files ) */ +/* FIXME: Move static _the_args into cmd? */ unsigned arg_count(const struct cmd_context *cmd __attribute((unused)), int a) { return _the_args[a].count; } +unsigned arg_is_set(const struct cmd_context *cmd, int a) +{ + return arg_count(cmd, a) ? 1 : 0; +} + const char *arg_value(struct cmd_context *cmd __attribute((unused)), int a) { return _the_args[a].value; } -const char *arg_str_value(struct cmd_context *cmd __attribute((unused)), - int a, const char *def) +const char *arg_str_value(struct cmd_context *cmd, int a, const char *def) { return arg_count(cmd, a) ? _the_args[a].value : def; } -int32_t arg_int_value(struct cmd_context *cmd __attribute((unused)), - int a, const int32_t def) +int32_t arg_int_value(struct cmd_context *cmd, int a, const int32_t def) { return arg_count(cmd, a) ? _the_args[a].i_value : def; } -uint32_t arg_uint_value(struct cmd_context *cmd __attribute((unused)), - int a, const uint32_t def) +uint32_t arg_uint_value(struct cmd_context *cmd, int a, const uint32_t def) { return arg_count(cmd, a) ? _the_args[a].ui_value : def; } -int64_t arg_int64_value(struct cmd_context *cmd __attribute((unused)), - int a, const int64_t def) +int64_t arg_int64_value(struct cmd_context *cmd, int a, const int64_t def) { return arg_count(cmd, a) ? _the_args[a].i64_value : def; } -uint64_t arg_uint64_value(struct cmd_context *cmd __attribute((unused)), - int a, const uint64_t def) +uint64_t arg_uint64_value(struct cmd_context *cmd, int a, const uint64_t def) { return arg_count(cmd, a) ? _the_args[a].ui64_value : def; } -const void *arg_ptr_value(struct cmd_context *cmd __attribute((unused)), - int a, const void *def) +const void *arg_ptr_value(struct cmd_context *cmd, int a, const void *def) { return arg_count(cmd, a) ? _the_args[a].ptr : def; } -sign_t arg_sign_value(struct cmd_context *cmd __attribute((unused)), - int a, const sign_t def) +sign_t arg_sign_value(struct cmd_context *cmd, int a, const sign_t def) { return arg_count(cmd, a) ? _the_args[a].sign : def; } -percent_t arg_percent_value(struct cmd_context *cmd __attribute((unused)), - int a, const percent_t def) +percent_t arg_percent_value(struct cmd_context *cmd, int a, const percent_t def) { return arg_count(cmd, a) ? _the_args[a].percent : def; } diff --git a/tools/lvresize.c b/tools/lvresize.c index 033078f38..2a4177954 100644 --- a/tools/lvresize.c +++ b/tools/lvresize.c @@ -240,8 +240,8 @@ static int _lvresize_params(struct cmd_context *cmd, int argc, char **argv, return 0; } - lp->resizefs = arg_count(cmd, resizefs_ARG) ? 1 : 0; - lp->nofsck = arg_count(cmd, nofsck_ARG) ? 1 : 0; + lp->resizefs = arg_is_set(cmd, resizefs_ARG); + lp->nofsck = arg_is_set(cmd, nofsck_ARG); if (!argc) { log_error("Please provide the logical volume name"); diff --git a/tools/polldaemon.c b/tools/polldaemon.c index 2ac286a06..577850d85 100644 --- a/tools/polldaemon.c +++ b/tools/polldaemon.c @@ -239,7 +239,7 @@ int poll_daemon(struct cmd_context *cmd, const char *name, const char *uuid, { struct daemon_parms parms; - parms.aborting = arg_count(cmd, abort_ARG) ? 1 : 0; + parms.aborting = arg_is_set(cmd, abort_ARG); parms.background = background; parms.interval = arg_uint_value(cmd, interval_ARG, DEFAULT_INTERVAL); parms.progress_display = 1; diff --git a/tools/pvmove.c b/tools/pvmove.c index 7a63862d2..ac09d6a58 100644 --- a/tools/pvmove.c +++ b/tools/pvmove.c @@ -608,6 +608,5 @@ int pvmove(struct cmd_context *cmd, int argc, char **argv) } } - return pvmove_poll(cmd, pv_name, - arg_count(cmd, background_ARG) ? 1U : 0); + return pvmove_poll(cmd, pv_name, arg_is_set(cmd, background_ARG)); } diff --git a/tools/reporter.c b/tools/reporter.c index 1e936896e..056e71180 100644 --- a/tools/reporter.c +++ b/tools/reporter.c @@ -327,11 +327,9 @@ static int _report(struct cmd_context *cmd, int argc, char **argv, } /* -O overrides default sort settings */ - if (arg_count(cmd, sort_ARG)) - keys = arg_str_value(cmd, sort_ARG, ""); + keys = arg_str_value(cmd, sort_ARG, keys); - if (arg_count(cmd, separator_ARG)) - separator = arg_str_value(cmd, separator_ARG, " "); + separator = arg_str_value(cmd, separator_ARG, separator); if (arg_count(cmd, separator_ARG)) aligned = 0; if (arg_count(cmd, aligned_ARG)) diff --git a/tools/tools.h b/tools/tools.h index 3afa1a1cf..578e32fa2 100644 --- a/tools/tools.h +++ b/tools/tools.h @@ -153,7 +153,8 @@ int alloc_arg(struct cmd_context *cmd, struct arg *a); int readahead_arg(struct cmd_context *cmd, struct arg *a); /* we use the enums to access the switches */ -unsigned int arg_count(const struct cmd_context *cmd, int a); +unsigned arg_count(const struct cmd_context *cmd, int a); +unsigned arg_is_set(const struct cmd_context *cmd, int a); const char *arg_value(struct cmd_context *cmd, int a); const char *arg_str_value(struct cmd_context *cmd, int a, const char *def); int32_t arg_int_value(struct cmd_context *cmd, int a, const int32_t def); -- 2.43.5