1
0
mirror of git://sourceware.org/git/lvm2.git synced 2025-03-11 20:58:50 +03:00

cov: use arg_count for unchecked usage

Reserve usage of  'arg_is_set()' to tested use case and use
arg_count() for unchecked one.
This commit is contained in:
Zdenek Kabelac 2025-02-23 19:48:39 +01:00
parent 56398a2180
commit 0fe1613c9b
8 changed files with 32 additions and 32 deletions

View File

@ -689,7 +689,7 @@ static int _lvchange_writecache(struct cmd_context *cmd,
* Empty settings can be used to clear all current settings,
* lvchange --cachesettings "" vg/lv
*/
if (!arg_count(cmd, yes_ARG) &&
if (!arg_is_set(cmd, yes_ARG) &&
yes_no_prompt("Clear all writecache settings? ") == 'n') {
log_print("No settings changed.");
return 1;
@ -738,7 +738,7 @@ static int _lvchange_cache(struct cmd_context *cmd,
if (seg_is_cache(seg) && lv_is_cache_vol(seg->pool_lv) && (mode == CACHE_MODE_WRITEBACK)) {
log_warn("WARNING: repairing a damaged cachevol is not yet possible.");
log_warn("WARNING: cache mode writethrough is suggested for safe operation.");
if (!arg_count(cmd, yes_ARG) &&
if (!arg_is_set(cmd, yes_ARG) &&
yes_no_prompt("Continue using writeback without repair?") == 'n')
goto_out;
}
@ -888,7 +888,7 @@ static int _lvchange_integrity(struct cmd_context *cmd,
if (set_count)
goto out;
if (!arg_count(cmd, yes_ARG) &&
if (!arg_is_set(cmd, yes_ARG) &&
yes_no_prompt("Clear all integrity settings? ") == 'n') {
log_print("No settings changed.");
return 1;

View File

@ -1854,7 +1854,7 @@ static int _lvconvert_splitsnapshot(struct cmd_context *cmd, struct logical_volu
return_0;
if ((arg_count(cmd, force_ARG) == PROMPT) &&
!arg_count(cmd, yes_ARG) &&
!arg_is_set(cmd, yes_ARG) &&
lv_is_visible(cow) &&
lv_is_active(cow)) {
if (yes_no_prompt("Do you really want to split off active "
@ -1895,7 +1895,7 @@ static int _lvconvert_split_and_keep_cachevol(struct cmd_context *cmd,
* This would generally be done to rescue data from
* the origin if the cache could not be repaired.
*/
if (!lv_is_active(lv) && arg_count(cmd, force_ARG))
if (!lv_is_active(lv) && arg_is_set(cmd, force_ARG))
direct_detach = 1;
/*
@ -1906,7 +1906,7 @@ static int _lvconvert_split_and_keep_cachevol(struct cmd_context *cmd,
* detach the cache in this case.
*/
if ((cache_mode != CACHE_MODE_WRITETHROUGH) && lv_is_partial(lv_fast)) {
if (!arg_count(cmd, force_ARG)) {
if (!arg_is_set(cmd, force_ARG)) {
log_warn("WARNING: writeback cache on %s is not complete and cannot be flushed.", display_lvname(lv_fast));
log_warn("WARNING: cannot detach writeback cache from %s without --force.", display_lvname(lv));
log_error("Conversion aborted.");
@ -1918,7 +1918,7 @@ static int _lvconvert_split_and_keep_cachevol(struct cmd_context *cmd,
if (direct_detach) {
log_warn("WARNING: Data may be lost by detaching writeback cache without flushing.");
if (!arg_count(cmd, yes_ARG) &&
if (!arg_is_set(cmd, yes_ARG) &&
yes_no_prompt("Detach writeback cache %s from %s without flushing data?",
display_lvname(lv_fast), display_lvname(lv)) == 'n') {
log_error("Conversion aborted.");
@ -2022,7 +2022,7 @@ static int _lvconvert_split_and_remove_cachepool(struct cmd_context *cmd,
/* TODO: Check for failed cache as well to get prompting? */
if (lv_is_partial(lv)) {
if (first_seg(seg->pool_lv)->cache_mode != CACHE_MODE_WRITETHROUGH) {
if (!arg_count(cmd, force_ARG)) {
if (!arg_is_set(cmd, force_ARG)) {
log_error("Conversion aborted.");
log_error("Cannot uncache writeback cache volume %s without --force.",
display_lvname(lv));
@ -2032,7 +2032,7 @@ static int _lvconvert_split_and_remove_cachepool(struct cmd_context *cmd,
cache_mode_num_to_str(first_seg(seg->pool_lv)->cache_mode), display_lvname(lv));
}
if (!arg_count(cmd, yes_ARG) &&
if (!arg_is_set(cmd, yes_ARG) &&
yes_no_prompt("Do you really want to uncache %s with missing LVs? [y/n]: ",
display_lvname(lv)) == 'n') {
log_error("Conversion aborted.");
@ -2105,7 +2105,7 @@ static int _lvconvert_snapshot(struct cmd_context *cmd,
snap_name);
log_warn("THIS WILL DESTROY CONTENT OF LOGICAL VOLUME (filesystem etc.)");
if (!arg_count(cmd, yes_ARG) &&
if (!arg_is_set(cmd, yes_ARG) &&
yes_no_prompt("Do you really want to convert %s? [y/n]: ",
snap_name) == 'n') {
log_error("Conversion aborted.");
@ -2980,7 +2980,7 @@ static int _lvconvert_swap_pool_metadata(struct cmd_context *cmd,
display_lvname(lv));
/* Ok, user has likely some serious reason for this */
if (!arg_count(cmd, yes_ARG) &&
if (!arg_is_set(cmd, yes_ARG) &&
yes_no_prompt("Do you really want to change chunk size for %s pool volume? [y/n]: ",
display_lvname(lv)) == 'n') {
log_error("Conversion aborted.");
@ -2991,7 +2991,7 @@ static int _lvconvert_swap_pool_metadata(struct cmd_context *cmd,
seg->chunk_size = chunk_size;
}
if (!arg_count(cmd, yes_ARG) &&
if (!arg_is_set(cmd, yes_ARG) &&
yes_no_prompt("Do you want to swap metadata of %s pool with metadata volume %s? [y/n]: ",
display_lvname(lv),
display_lvname(metadata_lv)) == 'n') {
@ -3321,7 +3321,7 @@ static int _lvconvert_to_pool(struct cmd_context *cmd,
} else if (to_cachepool)
log_warn("WARNING: Using mismatched cache pool metadata MAY DESTROY YOUR DATA!");
if (!arg_count(cmd, yes_ARG) &&
if (!arg_is_set(cmd, yes_ARG) &&
yes_no_prompt("Do you really want to convert %s? [y/n]: ",
converted_names) == 'n') {
log_error("Conversion aborted.");
@ -3683,7 +3683,7 @@ static int _cache_vol_attach(struct cmd_context *cmd,
if (cache_mode == CACHE_MODE_WRITEBACK) {
log_warn("WARNING: repairing a damaged cachevol is not yet possible.");
log_warn("WARNING: cache mode writethrough is suggested for safe operation.");
if (!arg_count(cmd, yes_ARG) &&
if (!arg_is_set(cmd, yes_ARG) &&
yes_no_prompt("Continue using writeback without repair?") == 'n')
goto_out;
}
@ -3857,7 +3857,7 @@ static void _lvconvert_repair_pvs_raid_ask(struct cmd_context *cmd, int *do_it)
return;
}
if (!arg_count(cmd, yes_ARG) &&
if (!arg_is_set(cmd, yes_ARG) &&
yes_no_prompt("Attempt to replace failed RAID images "
"(requires full device resync)? [y/n]: ") == 'n') {
*do_it = 0;
@ -5653,8 +5653,8 @@ static int _lvconvert_detach_writecache(struct cmd_context *cmd,
*/
active_begin = lv_is_active(lv);
if (lv_is_partial(lv_fast) || (!active_begin && arg_count(cmd, force_ARG))) {
if (!arg_count(cmd, force_ARG)) {
if (lv_is_partial(lv_fast) || (!active_begin && arg_is_set(cmd, force_ARG))) {
if (!arg_is_set(cmd, force_ARG)) {
log_warn("WARNING: writecache on %s is not complete and cannot be flushed.", display_lvname(lv_fast));
log_warn("WARNING: cannot detach writecache from %s without --force.", display_lvname(lv));
log_error("Conversion aborted.");
@ -5663,7 +5663,7 @@ static int _lvconvert_detach_writecache(struct cmd_context *cmd,
log_warn("WARNING: Data may be lost by detaching writecache without flushing.");
if (!arg_count(cmd, yes_ARG) &&
if (!arg_is_set(cmd, yes_ARG) &&
yes_no_prompt("Detach writecache %s from %s without flushing data?",
display_lvname(lv_fast), display_lvname(lv)) == 'n') {
log_error("Conversion aborted.");

View File

@ -2661,7 +2661,7 @@ static int _process_common_commands(struct cmd_context *cmd)
if (arg_is_set(cmd, help_ARG) ||
arg_is_set(cmd, longhelp_ARG) ||
arg_is_set(cmd, help2_ARG)) {
_usage(cmd->name, arg_is_set(cmd, longhelp_ARG), 0);
_usage(cmd->name, arg_count(cmd, longhelp_ARG), 0);
return ECMD_PROCESSED;
}

View File

@ -725,7 +725,7 @@ int lvmdevices(struct cmd_context *cmd, int argc, char **argv)
* moved to a new WWID.
*/
cmd->search_for_devnames = "all";
device_ids_search(cmd, &found_devs, arg_is_set(cmd, refresh_ARG), 1, &update_needed);
device_ids_search(cmd, &found_devs, arg_count(cmd, refresh_ARG), 1, &update_needed);
_print_check(cmd);
@ -908,7 +908,7 @@ int lvmdevices(struct cmd_context *cmd, int argc, char **argv)
* and sets this flag is so.
*/
if (dev_is_used_by_active_lv(cmd, dev, NULL, NULL, NULL, NULL)) {
if (!arg_count(cmd, yes_ARG) &&
if (!arg_is_set(cmd, yes_ARG) &&
yes_no_prompt("Device %s is used by an active LV, continue to remove? ", devname) == 'n') {
log_error("Device not removed.");
goto bad;
@ -958,7 +958,7 @@ int lvmdevices(struct cmd_context *cmd, int argc, char **argv)
dev = du->dev;
if (dev && dev_is_used_by_active_lv(cmd, dev, NULL, NULL, NULL, NULL)) {
if (!arg_count(cmd, yes_ARG) &&
if (!arg_is_set(cmd, yes_ARG) &&
yes_no_prompt("Device %s is used by an active LV, continue to remove? ", dev_name(dev)) == 'n') {
log_error("Device not removed.");
goto bad;
@ -999,7 +999,7 @@ int lvmdevices(struct cmd_context *cmd, int argc, char **argv)
if (du->devname && (du->devname[0] != '.')) {
if ((dev = dev_cache_get(cmd, du->devname, NULL)) &&
dev_is_used_by_active_lv(cmd, dev, NULL, NULL, NULL, NULL)) {
if (!arg_count(cmd, yes_ARG) &&
if (!arg_is_set(cmd, yes_ARG) &&
yes_no_prompt("Device %s is used by an active LV, continue to remove? ", du->devname) == 'n') {
log_error("Device not removed.");
goto bad;

View File

@ -1915,7 +1915,7 @@ static int _repair_label_header(struct cmd_context *cmd, const char *repair,
if (!found_label) {
log_warn("WARNING: No LVM label found on %s. It may not be an LVM device.", dev_name(dev));
if (!arg_count(cmd, yes_ARG) &&
if (!arg_is_set(cmd, yes_ARG) &&
yes_no_prompt("Write LVM header to device? ") == 'n')
return 0;
}
@ -1952,7 +1952,7 @@ static int _repair_label_header(struct cmd_context *cmd, const char *repair,
return 1;
}
if (!arg_count(cmd, yes_ARG) &&
if (!arg_is_set(cmd, yes_ARG) &&
yes_no_prompt("Write new LVM header to %s? ", dev_name(dev)) == 'n')
return 0;
@ -2289,7 +2289,7 @@ static int _repair_pv_header(struct cmd_context *cmd, const char *repair,
} else if (!mda_count) {
log_warn("WARNING: no previous metadata areas found on device.");
if (arg_count(cmd, yes_ARG) ||
if (arg_is_set(cmd, yes_ARG) ||
yes_no_prompt("Should a metadata area be included? ") == 'y') {
/* mda1_offset/mda1_size are set below */
mda_count = 1;
@ -2474,7 +2474,7 @@ static int _repair_pv_header(struct cmd_context *cmd, const char *repair,
return 1;
}
if (!arg_count(cmd, yes_ARG) &&
if (!arg_is_set(cmd, yes_ARG) &&
yes_no_prompt("Write new LVM header to %s? ", dev_name(dev)) == 'n')
goto fail;
@ -2551,7 +2551,7 @@ static int _update_mda(struct cmd_context *cmd, struct metadata_file *mf, struct
return 1;
}
if (!arg_count(cmd, yes_ARG) &&
if (!arg_is_set(cmd, yes_ARG) &&
yes_no_prompt("Write new LVM metadata to %s? ", dev_name(dev)) == 'n')
goto fail;
@ -2921,7 +2921,7 @@ static int _check_metadata_file(struct cmd_context *cmd, struct metadata_file *m
log_warn("WARNING: file data does not begin with a VG name and may be invalid.");
if (!arg_count(cmd, yes_ARG) &&
if (!arg_is_set(cmd, yes_ARG) &&
yes_no_prompt("Write input file data to disk?") == 'n') {
log_error("Invalid raw text metadata in file.");
return 0;

View File

@ -46,7 +46,7 @@ static int _pvresize_single(struct cmd_context *cmd,
return_ECMD_FAILED;
}
if (!pv_resize_single(cmd, vg, pv, params->new_size, arg_is_set(cmd, yes_ARG)))
if (!pv_resize_single(cmd, vg, pv, params->new_size, arg_count(cmd, yes_ARG)))
return_ECMD_FAILED;
params->done++;

View File

@ -114,7 +114,7 @@ static int _activate_lvs_in_vg(struct cmd_context *cmd, struct volume_group *vg,
if (lv_is_vdo_pool(lv))
continue;
if (lv_activation_skip(lv, activate, arg_is_set(cmd, ignoreactivationskip_ARG)))
if (lv_activation_skip(lv, activate, arg_count(cmd, ignoreactivationskip_ARG)))
continue;
if ((activate == CHANGE_AAY) &&

View File

@ -70,7 +70,7 @@ static int _vgremove_single(struct cmd_context *cmd, const char *vg_name,
!lvremove_single(cmd, vg->pool_metadata_spare_lv, &void_handle))
return_ECMD_FAILED;
if (!lockd_free_vg_before(cmd, vg, 0, arg_is_set(cmd, yes_ARG)))
if (!lockd_free_vg_before(cmd, vg, 0, arg_count(cmd, yes_ARG)))
return_ECMD_FAILED;
if (!force && !vg_remove_check(vg))