Linux-NVME Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: John Garry <john.garry@linux.dev>
To: Shin'ichiro Kawasaki <shinichiro.kawasaki@wdc.com>,
	John Garry <john.g.garry@oracle.com>
Cc: linux-nvme@lists.infradead.org
Subject: Re: [PATCH blktests v2] nvme/068: check module reference count with patience
Date: Fri, 7 Aug 2026 09:32:15 +0100	[thread overview]
Message-ID: <a6c21f02-da8c-42bb-a6b8-4c20d14b2197@linux.dev> (raw)
In-Reply-To: <anRtGO3CBTh8Sjxj@shinmob>

On 8/6/26 12:30, Shin'ichiro Kawasaki wrote:
>>> +_check_nvme_core_ref_count() {
>>> +	local refcnt i
>>> +
>>> +	for ((i = 0; i < 10; i++)); do
>>> +		refcnt=$(_module_use_count nvme_core)
>>> +		if [ "$refcnt" == "" ] || [ "$refcnt" -eq "$refcnt_orig" ]; then
>> I thought that refcnt_orig was local to test(), so I am unsure how it is
>> accessible in this function...but it seems to work.
> This is a bash uniqueness. Here I quote a relevant paragraph from the Bash
> manual [*]. Some paragraphs follow and explain how bash handles local variable
> scope.
> 
>    Variables local to the function are declared with the local builtin (local
>    variables). Ordinarily, variables and their values are shared between a
>    function and its caller. These variables are visible only to the function and
>    the commands it invokes. This is particularly important when a shell function
>    calls other functions.
> 
> refcnt_orig was declared as a local variable by the caller of
> _check_nvme_core_ref_count(), then it is visible in _check_nvme_core_ref_count()
> also. I used this feature intentionally, but I understand it looks weird. If you
> like, I will update the patch to pass refcnt_orig as a function argument
> instead.
> 
> [*]https://www.gnu.org/software/bash/manual/bash.html#Shell-Functions

Understood, thanks for the info.

BTW, on another topic, it seems to be a common pattern to loop waiting 
for a condition to be true in the blktests codebase, like:

+_check_nvme_core_ref_count() {
+	local refcnt i
+
+	for ((i = 0; i < 10; i++)); do
+		refcnt=$(_module_use_count nvme_core)
+		if [ "$refcnt" == "" ] || [ "$refcnt" -eq "$refcnt_orig" ]; then
+			return 0
+		fi
+		sleep 1
+	done
+	return 1
+}

In the kernel, we have functions like wait_event_timeout(wq_head, 
condition, timeout), which calls @condition and checks the result to 
break the loop and determine success. Could it be possible to have such 
a helper in blktests? I don't know how...


      reply	other threads:[~2026-08-07  8:32 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-08-06  3:31 [PATCH blktests v2] nvme/068: check module reference count with patience Shin'ichiro Kawasaki
2026-08-06  7:24 ` John Garry
2026-08-06 11:30   ` Shin'ichiro Kawasaki
2026-08-07  8:32     ` John Garry [this message]

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=a6c21f02-da8c-42bb-a6b8-4c20d14b2197@linux.dev \
    --to=john.garry@linux.dev \
    --cc=john.g.garry@oracle.com \
    --cc=linux-nvme@lists.infradead.org \
    --cc=shinichiro.kawasaki@wdc.com \
    /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