linux-nvme.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
From: Shin'ichiro Kawasaki <shinichiro.kawasaki@wdc.com>
To: linux-block@vger.kernel.org
Cc: linux-nvme@lists.infradead.org, Daniel Wagner <dwagern@suse.de>,
	Chaitanya Kulkarni <kch@nvidia.com>,
	Sagi Grimberg <sagi@grimberg.me>
Subject: [PATCH blktests v3 05/15] common/rc: introduce _check_conflict_and_set_default()
Date: Wed, 24 Apr 2024 16:59:45 +0900	[thread overview]
Message-ID: <20240424075955.3604997-6-shinichiro.kawasaki@wdc.com> (raw)
In-Reply-To: <20240424075955.3604997-1-shinichiro.kawasaki@wdc.com>

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.

Signed-off-by: Shin'ichiro Kawasaki <shinichiro.kawasaki@wdc.com>
---
 common/rc | 27 +++++++++++++++++++++++++++
 1 file changed, 27 insertions(+)

diff --git a/common/rc b/common/rc
index c3680f5..9ff31cf 100644
--- a/common/rc
+++ b/common/rc
@@ -470,3 +470,30 @@ convert_to_mb()
 		echo "$((res * 1024))"
 	fi
 }
+
+# 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



  parent reply	other threads:[~2024-04-24  8:00 UTC|newest]

Thread overview: 28+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-04-24  7:59 [PATCH blktests v3 00/15] support test case repeat by different conditions Shin'ichiro Kawasaki
2024-04-24  7:59 ` [PATCH blktests v3 01/15] check: factor out _run_test() Shin'ichiro Kawasaki
2024-04-24  7:59 ` [PATCH blktests v3 02/15] check: support test case repeat by different conditions Shin'ichiro Kawasaki
2024-04-24  7:59 ` [PATCH blktests v3 03/15] check: use set_conditions() for the CAN_BE_ZONED test cases Shin'ichiro Kawasaki
2024-04-24  7:59 ` [PATCH blktests v3 04/15] meta/{016,017}: add test cases to check repeated test case runs Shin'ichiro Kawasaki
2024-04-24  7:59 ` Shin'ichiro Kawasaki [this message]
2024-04-24 12:27   ` [PATCH blktests v3 05/15] common/rc: introduce _check_conflict_and_set_default() Daniel Wagner
2024-04-24  7:59 ` [PATCH blktests v3 06/15] nvme/rc: introduce NVMET_TRTYPES Shin'ichiro Kawasaki
2024-04-24 12:28   ` Daniel Wagner
2024-04-24  7:59 ` [PATCH blktests v3 07/15] nvme/rc: add blkdev type environment variable Shin'ichiro Kawasaki
2024-04-24  7:59 ` [PATCH blktests v3 08/15] nvme/rc: introduce NVMET_BLKDEV_TYPES Shin'ichiro Kawasaki
2024-04-24  7:59 ` [PATCH blktests v3 09/15] nvme/{002-031,033-038,040-045,047,048}: support NMVET_TRTYPES Shin'ichiro Kawasaki
2024-04-24  7:59 ` [PATCH blktests v3 10/15] nvme/{006,008,010,012,014,019,023}: support NVMET_BLKDEV_TYPES Shin'ichiro Kawasaki
2024-04-28  8:58   ` Sagi Grimberg
2024-04-28 10:32     ` Shinichiro Kawasaki
2024-04-28 13:12       ` Sagi Grimberg
2024-04-28 23:58         ` Shinichiro Kawasaki
2024-04-30 12:00           ` Sagi Grimberg
2024-05-03  6:23             ` Shinichiro Kawasaki
2024-05-03  7:33               ` Sagi Grimberg
2024-04-24  7:59 ` [PATCH blktests v3 11/15] nvme/{007,009,011,013,015,020,024}: drop duplicate nvmet blkdev type tests Shin'ichiro Kawasaki
2024-04-24  7:59 ` [PATCH blktests v3 12/15] nvme/{021,022,025,026,027,028}: do not hard code target blkdev type Shin'ichiro Kawasaki
2024-04-24  7:59 ` [PATCH blktests v3 13/15] nvme/{rc,010,017,031,034,035}: rename nvme_img_size to NVME_IMG_SIZE Shin'ichiro Kawasaki
2024-04-24 12:29   ` Daniel Wagner
2024-04-24  7:59 ` [PATCH blktests v3 14/15] nvme/{rc,016,017}: rename nvme_num_iter to NVME_NUM_ITER Shin'ichiro Kawasaki
2024-04-24 12:30   ` Daniel Wagner
2024-04-24  7:59 ` [PATCH blktests v3 15/15] nvme/rc,srp/rc,common/multipath-over-rdma: rename use_rxe to USE_RXE Shin'ichiro Kawasaki
2024-04-24 12:33   ` Daniel Wagner

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20240424075955.3604997-6-shinichiro.kawasaki@wdc.com \
    --to=shinichiro.kawasaki@wdc.com \
    --cc=dwagern@suse.de \
    --cc=kch@nvidia.com \
    --cc=linux-block@vger.kernel.org \
    --cc=linux-nvme@lists.infradead.org \
    --cc=sagi@grimberg.me \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).