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

Tidy some uses of arg_count and introduce arg_is_set.

This commit is contained in:
Alasdair Kergon 2009-11-03 15:50:42 +00:00
parent badfe1cfd2
commit a8fb89adaf
11 changed files with 31 additions and 46 deletions

View File

@ -1,5 +1,6 @@
Version 2.02.55 - Version 2.02.55 -
=================================== ===================================
Tidy some uses of arg_count and introduce arg_is_set.
Export outnl and indent functions for modules. Export outnl and indent functions for modules.
Flush stdout after yes/no prompt. Flush stdout after yes/no prompt.
Update vgsplit and vgcreate to use vg_set_clustered. Update vgsplit and vgcreate to use vg_set_clustered.

View File

@ -1,5 +1,6 @@
Version 1.02.40 - Version 1.02.40 -
=================================== ===================================
Fix hash lookup segfault when keys compared are different lengths.
Version 1.02.39 - 26th October 2009 Version 1.02.39 - 26th October 2009
=================================== ===================================

View File

@ -17,10 +17,7 @@
int dumpconfig(struct cmd_context *cmd, int argc, char **argv) int dumpconfig(struct cmd_context *cmd, int argc, char **argv)
{ {
const char *file = NULL; const char *file = arg_str_value(cmd, file_ARG, NULL);
if (arg_count(cmd, file_ARG))
file = arg_str_value(cmd, file_ARG, "");
if (!write_config_file(cmd->cft, file, argc, argv)) { if (!write_config_file(cmd->cft, file, argc, argv)) {
stack; stack;

View File

@ -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->mirrors_sign = arg_sign_value(cmd, mirrors_ARG, 0);
} }
lp->alloc = ALLOC_INHERIT; lp->alloc = arg_uint_value(cmd, alloc_ARG, ALLOC_INHERIT);
if (arg_count(cmd, alloc_ARG))
lp->alloc = arg_uint_value(cmd, alloc_ARG, lp->alloc);
if (lp->snapshot) { if (lp->snapshot) {
if (arg_count(cmd, regionsize_ARG)) { if (arg_count(cmd, regionsize_ARG)) {

View File

@ -33,8 +33,7 @@ static int _lvcreate_name_params(struct lvcreate_params *lp,
char **argv = *pargv, *ptr; char **argv = *pargv, *ptr;
char *vg_name; char *vg_name;
if (arg_count(cmd, name_ARG)) lp->lv_name = arg_str_value(cmd, name_ARG, NULL);
lp->lv_name = arg_value(cmd, name_ARG);
if (lp->snapshot && !arg_count(cmd, virtualsize_ARG)) { if (lp->snapshot && !arg_count(cmd, virtualsize_ARG)) {
if (!argc) { if (!argc) {
@ -347,7 +346,7 @@ static int _read_mirror_params(struct lvcreate_params *lp,
log_verbose("Setting logging type to %s", mirrorlog); 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_count(cmd, regionsize_ARG)) {
if (arg_sign_value(cmd, regionsize_ARG, 0) == SIGN_MINUS) { if (arg_sign_value(cmd, regionsize_ARG, 0) == SIGN_MINUS) {
@ -521,10 +520,8 @@ static int _lvcreate_params(struct lvcreate_params *lp,
/* /*
* Permissions. * Permissions.
*/ */
if (arg_count(cmd, permission_ARG)) lp->permission = arg_uint_value(cmd, permission_ARG,
lp->permission = arg_uint_value(cmd, permission_ARG, 0); LVM_READ | LVM_WRITE);
else
lp->permission = LVM_READ | LVM_WRITE;
/* Must not zero read only volume */ /* Must not zero read only volume */
if (!(lp->permission & LVM_WRITE)) if (!(lp->permission & LVM_WRITE))
@ -558,11 +555,7 @@ static int _lvcreate_params(struct lvcreate_params *lp,
return 0; return 0;
} }
if (arg_count(cmd, addtag_ARG) && lp->tag = arg_str_value(cmd, addtag_ARG, NULL);
!(lp->tag = arg_str_value(cmd, addtag_ARG, NULL))) {
log_error("Failed to get tag");
return 0;
}
lcp->pv_count = argc; lcp->pv_count = argc;
lcp->pvs = argv; lcp->pvs = argv;

View File

@ -54,61 +54,58 @@ static struct arg _the_args[ARG_COUNT + 1] = {
static struct cmdline_context _cmdline; static struct cmdline_context _cmdline;
/* Command line args */ /* 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) unsigned arg_count(const struct cmd_context *cmd __attribute((unused)), int a)
{ {
return _the_args[a].count; 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) const char *arg_value(struct cmd_context *cmd __attribute((unused)), int a)
{ {
return _the_args[a].value; return _the_args[a].value;
} }
const char *arg_str_value(struct cmd_context *cmd __attribute((unused)), const char *arg_str_value(struct cmd_context *cmd, int a, const char *def)
int a, const char *def)
{ {
return arg_count(cmd, a) ? _the_args[a].value : def; return arg_count(cmd, a) ? _the_args[a].value : def;
} }
int32_t arg_int_value(struct cmd_context *cmd __attribute((unused)), int32_t arg_int_value(struct cmd_context *cmd, int a, const int32_t def)
int a, const int32_t def)
{ {
return arg_count(cmd, a) ? _the_args[a].i_value : def; return arg_count(cmd, a) ? _the_args[a].i_value : def;
} }
uint32_t arg_uint_value(struct cmd_context *cmd __attribute((unused)), uint32_t arg_uint_value(struct cmd_context *cmd, int a, const uint32_t def)
int a, const uint32_t def)
{ {
return arg_count(cmd, a) ? _the_args[a].ui_value : def; return arg_count(cmd, a) ? _the_args[a].ui_value : def;
} }
int64_t arg_int64_value(struct cmd_context *cmd __attribute((unused)), int64_t arg_int64_value(struct cmd_context *cmd, int a, const int64_t def)
int a, const int64_t def)
{ {
return arg_count(cmd, a) ? _the_args[a].i64_value : def; return arg_count(cmd, a) ? _the_args[a].i64_value : def;
} }
uint64_t arg_uint64_value(struct cmd_context *cmd __attribute((unused)), uint64_t arg_uint64_value(struct cmd_context *cmd, int a, const uint64_t def)
int a, const uint64_t def)
{ {
return arg_count(cmd, a) ? _the_args[a].ui64_value : def; return arg_count(cmd, a) ? _the_args[a].ui64_value : def;
} }
const void *arg_ptr_value(struct cmd_context *cmd __attribute((unused)), const void *arg_ptr_value(struct cmd_context *cmd, int a, const void *def)
int a, const void *def)
{ {
return arg_count(cmd, a) ? _the_args[a].ptr : def; return arg_count(cmd, a) ? _the_args[a].ptr : def;
} }
sign_t arg_sign_value(struct cmd_context *cmd __attribute((unused)), sign_t arg_sign_value(struct cmd_context *cmd, int a, const sign_t def)
int a, const sign_t def)
{ {
return arg_count(cmd, a) ? _the_args[a].sign : def; return arg_count(cmd, a) ? _the_args[a].sign : def;
} }
percent_t arg_percent_value(struct cmd_context *cmd __attribute((unused)), percent_t arg_percent_value(struct cmd_context *cmd, int a, const percent_t def)
int a, const percent_t def)
{ {
return arg_count(cmd, a) ? _the_args[a].percent : def; return arg_count(cmd, a) ? _the_args[a].percent : def;
} }

View File

@ -240,8 +240,8 @@ static int _lvresize_params(struct cmd_context *cmd, int argc, char **argv,
return 0; return 0;
} }
lp->resizefs = arg_count(cmd, resizefs_ARG) ? 1 : 0; lp->resizefs = arg_is_set(cmd, resizefs_ARG);
lp->nofsck = arg_count(cmd, nofsck_ARG) ? 1 : 0; lp->nofsck = arg_is_set(cmd, nofsck_ARG);
if (!argc) { if (!argc) {
log_error("Please provide the logical volume name"); log_error("Please provide the logical volume name");

View File

@ -239,7 +239,7 @@ int poll_daemon(struct cmd_context *cmd, const char *name, const char *uuid,
{ {
struct daemon_parms parms; 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.background = background;
parms.interval = arg_uint_value(cmd, interval_ARG, DEFAULT_INTERVAL); parms.interval = arg_uint_value(cmd, interval_ARG, DEFAULT_INTERVAL);
parms.progress_display = 1; parms.progress_display = 1;

View File

@ -608,6 +608,5 @@ int pvmove(struct cmd_context *cmd, int argc, char **argv)
} }
} }
return pvmove_poll(cmd, pv_name, return pvmove_poll(cmd, pv_name, arg_is_set(cmd, background_ARG));
arg_count(cmd, background_ARG) ? 1U : 0);
} }

View File

@ -327,11 +327,9 @@ static int _report(struct cmd_context *cmd, int argc, char **argv,
} }
/* -O overrides default sort settings */ /* -O overrides default sort settings */
if (arg_count(cmd, sort_ARG)) keys = arg_str_value(cmd, sort_ARG, keys);
keys = arg_str_value(cmd, sort_ARG, "");
if (arg_count(cmd, separator_ARG)) separator = arg_str_value(cmd, separator_ARG, separator);
separator = arg_str_value(cmd, separator_ARG, " ");
if (arg_count(cmd, separator_ARG)) if (arg_count(cmd, separator_ARG))
aligned = 0; aligned = 0;
if (arg_count(cmd, aligned_ARG)) if (arg_count(cmd, aligned_ARG))

View File

@ -153,7 +153,8 @@ int alloc_arg(struct cmd_context *cmd, struct arg *a);
int readahead_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 */ /* 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_value(struct cmd_context *cmd, int a);
const char *arg_str_value(struct cmd_context *cmd, int a, const char *def); 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); int32_t arg_int_value(struct cmd_context *cmd, int a, const int32_t def);