All of lore.kernel.org
 help / color / mirror / Atom feed
From: Nilay Shroff <nilay@linux.ibm.com>
To: linux-nvme@lists.infradead.org
Cc: shinichiro.kawasaki@wdc.com, hare@suse.de, gjoyce@ibm.com
Subject: [PATCHv2 blktests] nvme/058: detach loop device after test finish
Date: Fri, 24 Jan 2025 13:17:29 +0530	[thread overview]
Message-ID: <20250124074753.9802-1-nilay@linux.ibm.com> (raw)

The nvme/058 creates three (temp file backed) namespaces and
attach each namespace to a loop device while starting the test.
However it never detach those namespaces from the loop device
once test finishes. Ideally, we should detach loop device from
namespace so that the associated loop device is later destroyed
and its resources are released. This patch helps detach each
namespace from its associated loop device after test finishes.

Signed-off-by: Nilay Shroff <nilay@linux.ibm.com>
---
Changes from v1:
    - keep blkdevs, which are used for setting up ns, in an array
      and then later access the array to free/detach each blkdev
      (Shinichiro Kawasaki)
    - use longer option name instead of short name for readability
      (Shinichiro Kawasaki)
---
 tests/nvme/058 | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/tests/nvme/058 b/tests/nvme/058
index d230a21..815503f 100755
--- a/tests/nvme/058
+++ b/tests/nvme/058
@@ -65,11 +65,13 @@ test() {
 	for ((d = 1; d <= num_namespaces; d++)); do
 		local file_path
 		local blkdev
+		local -a blkdevs
 		local uuid
 
 		file_path="${TMPDIR}/img${d}"
 		truncate -s "${NVME_IMG_SIZE}" "${file_path}"
 		blkdev="$(losetup -f --show "${file_path}")"
+		blkdevs+=("$blkdev")
 		uuid="$(uuidgen)"
 		_create_nvmet_ns --nsid "${d}" --blkdev "${blkdev}" \
 				 --uuid "${uuid}" --grpid "${d}" > /dev/null
@@ -99,6 +101,11 @@ test() {
 	done
 
 	_nvme_disconnect_subsys
+
+	for blkdev in "${blkdevs[@]}"; do
+		losetup --detach "$blkdev"
+	done
+
 	_nvmet_target_cleanup
 
 	echo "Test complete"
-- 
2.47.1



             reply	other threads:[~2025-01-24  7:48 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-01-24  7:47 Nilay Shroff [this message]
2025-01-24  8:28 ` [PATCHv2 blktests] nvme/058: detach loop device after test finish Hannes Reinecke
2025-01-24 11:02 ` Sagi Grimberg
2025-01-26 23:25 ` Chaitanya Kulkarni
2025-01-27  7:01 ` Hannes Reinecke
2025-01-27  9:01 ` Shinichiro Kawasaki

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=20250124074753.9802-1-nilay@linux.ibm.com \
    --to=nilay@linux.ibm.com \
    --cc=gjoyce@ibm.com \
    --cc=hare@suse.de \
    --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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.