public inbox for linux-block@vger.kernel.org
 help / color / mirror / Atom feed
From: Shinichiro Kawasaki <shinichiro.kawasaki@wdc.com>
To: Luis Chamberlain <mcgrof@kernel.org>
Cc: "linux-block@vger.kernel.org" <linux-block@vger.kernel.org>,
	"patches@lists.linux.dev" <patches@lists.linux.dev>,
	"gost.dev@samsung.com" <gost.dev@samsung.com>,
	"sw.prabhu6@gmail.com" <sw.prabhu6@gmail.com>,
	"kernel@pankajraghav.com" <kernel@pankajraghav.com>,
	"bvanassche@acm.org" <bvanassche@acm.org>,
	Chaitanya Kulkarni <kch@nvidia.com>
Subject: Re: [PATCH v4 1/2] blktests: replace module removal with patient module removal
Date: Thu, 25 Dec 2025 12:05:10 +0000	[thread overview]
Message-ID: <aU0nXPx638RKJAjw@shinmob> (raw)
In-Reply-To: <20251126171102.3663957-2-mcgrof@kernel.org>

On Nov 26, 2025 / 09:11, Luis Chamberlain wrote:
[...]
> diff --git a/common/rc b/common/rc
> index ea92970..556581f 100644
> --- a/common/rc
> +++ b/common/rc
[...]
> +# Tries to wait patiently to remove a module by ensuring first
> +# the refcnt is 0 and then trying to remove the module over and over
> +# again within the time allowed. The timeout is configurable per test, just set
> +# MODPROBE_PATIENT_RM_TIMEOUT_SECONDS prior to calling this function.
> +# This applies to both cases where kmod supports the patient module remover
> +# (modprobe --wait) and where it does not.
> +#
> +# If your version of kmod supports modprobe --wait, we use that instead.
> +# Otherwise we have to implement a patient module remover ourselves.
> +_patient_rmmod()
> +{
> +	local module=$1
> +	local max_tries_max=$MODPROBE_PATIENT_RM_TIMEOUT_SECONDS
> +	local max_tries=0
> +	local mod_ret=0
> +	local refcnt_is_zero=0
> +	# Since we are looking for a directory we must adopt the
> +	# specific directory used by scripts/Makefile.lib for
> +	# KBUILD_MODNAME
> +	local module_sys=${module//-/_}
> +
> +	# Check if module is built-in or not loaded
> +	if [[ ! -d "/sys/module/$module_sys" ]]; then
> +		return 0
> +	fi
> +
> +	# Check if this is a built-in module (no refcnt file means built-in)
> +	if [[ ! -f "/sys/module/$module_sys/refcnt" ]]; then
> +		return 0
> +	fi
> +
> +	if [[ -n $MODPROBE_HAS_WAIT ]]; then
> +		local timeout_ms=$((MODPROBE_PATIENT_RM_TIMEOUT_SECONDS * 1000))
> +		modprobe -r --wait="${timeout_ms}" "$module"

While I evaluated this patch, I noticed that the modprobe command above can
return zero status code, even when it fails to remove the target module. I will
add a follow-up patch to the v5 series to check the reference count even when
the command above success to catch such cases.

Also, I will replace the short option -r with the long option --remove for
script readability and stability.

> +		mod_ret=$?
> +		if [[ $mod_ret -ne 0 ]]; then
> +			echo "kmod patient module removal for $module timed out waiting for refcnt to become 0 using timeout of $max_tries_max returned $mod_ret"
> +		fi
> +		return $mod_ret
> +	fi

  parent reply	other threads:[~2025-12-25 12:05 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-11-26 17:11 [PATCH v4 0/2] blktests: use patient module remover Luis Chamberlain
2025-11-26 17:11 ` [PATCH v4 1/2] blktests: replace module removal with patient module removal Luis Chamberlain
2025-11-26 17:44   ` Bart Van Assche
2025-12-19  5:29     ` Shinichiro Kawasaki
2025-12-22 18:11       ` Swarna Prabhu
2025-12-25 12:00         ` Shinichiro Kawasaki
2025-12-18 10:44   ` Shinichiro Kawasaki
2025-12-19  3:06     ` Luis Chamberlain
2025-12-25 12:05   ` Shinichiro Kawasaki [this message]
2025-11-26 17:11 ` [PATCH v4 2/2] tests/srp/rc: " Luis Chamberlain

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=aU0nXPx638RKJAjw@shinmob \
    --to=shinichiro.kawasaki@wdc.com \
    --cc=bvanassche@acm.org \
    --cc=gost.dev@samsung.com \
    --cc=kch@nvidia.com \
    --cc=kernel@pankajraghav.com \
    --cc=linux-block@vger.kernel.org \
    --cc=mcgrof@kernel.org \
    --cc=patches@lists.linux.dev \
    --cc=sw.prabhu6@gmail.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