[PATCH blktests v4 07/17] common/rc: introduce _check_conflict_and_set_default()
Shin'ichiro Kawasaki
shinichiro.kawasaki at wdc.com
Sat May 4 01:14:38 PDT 2024
Following commits are going to rename some config option parameters from
lowercase letters to uppercase. The old lowercase options will be
deprecated but still be kept usable to not cause confusions. When these
changes are made, it will be required to check that both new and old
parameters are not set at once and ensure they do not have two different
values.
To simplify the code to check the two parameters, introduce the helper
_check_conflict_and_set_default(). If the both two parameters are
set, it errors out. If the old option is set, it propagates the old
option value to the new option. Also, when neither of them is set, it
sets the default value to the new option.
Reviewed-by: Daniel Wagner <dwagner at suse.de>
Signed-off-by: Shin'ichiro Kawasaki <shinichiro.kawasaki at wdc.com>
---
common/rc | 27 +++++++++++++++++++++++++++
1 file changed, 27 insertions(+)
diff --git a/common/rc b/common/rc
index fa61cc6..6a9a26c 100644
--- a/common/rc
+++ b/common/rc
@@ -515,3 +515,30 @@ _set_combined_conditions()
done
COND_DESC="$_cond_desc"
}
+
+# Check both old and new parameters are not configured. If the old parameter is
+# set, propagate to the new parameter. If neither is set, set the default value
+# to the new parameter.
+_check_conflict_and_set_default()
+{
+ local new_name="$1"
+ local old_name="$2"
+ local default_val="$3"
+ local new_name_checked="$new_name"_checked
+
+ if [[ -n ${!new_name_checked} ]]; then
+ return
+ fi
+
+ if [[ -n ${!old_name} ]]; then
+ if [[ -n ${!new_name} ]]; then
+ echo "Both ${old_name} and ${new_name} are specified"
+ exit 1
+ fi
+ eval "${new_name}=\"${!old_name}\""
+ elif [[ -z ${!new_name} ]]; then
+ eval "${new_name}=\"${default_val}\""
+ fi
+
+ eval "${new_name_checked}=true"
+}
--
2.44.0
More information about the Linux-nvme
mailing list