Skip to contentSkip to conversation

nvme/058: detach loop device after test finish

PATCH In review Nilay Shroff 5 participants 6 messages Jan 24, 2025 – Jan 27, 2025 NVMe

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 nvme/058: detach loop device after test finish

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.

---
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(+)
tests/nvme/058 +7 -0
index d230a21..815503f 100755
@@ -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"
Signature · 1 line
2.47.1
Reviewed-by on v2 1/1
#1 lore raw
Quoted 16 lines · Nilay Shroff

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.

---
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)

Quoted 4 lines
---
  tests/nvme/058 | 7 +++++++
  1 file changed, 7 insertions(+)

Cheers,

Hannes

Signature · 4 lines
Dr. Hannes Reinecke                  Kernel Storage Architect
[email protected]                                +49 911 74053 688
SUSE Software Solutions GmbH, Frankenstr. 146, 90461 Nürnberg
HRB 36809 (AG Nürnberg), GF: I. Totev, A. McDonald, W. Knoblich
Reviewed-by on v2 1/1
#3 lore raw
In reply to Nilay Shroff
Quoted 9 lines · Nilay Shroff

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.

Looks good.

-ck

Reviewed-by on v2 1/1
#4 lore raw
In reply to Nilay Shroff
Quoted 16 lines · Nilay Shroff

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.

---
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)

Quoted 4 lines
---
  tests/nvme/058 | 7 +++++++
  1 file changed, 7 insertions(+)

Cheers,

Hannes

Signature · 4 lines
Dr. Hannes Reinecke                  Kernel Storage Architect
[email protected]                                +49 911 74053 688
SUSE Software Solutions GmbH, Frankenstr. 146, 90461 Nürnberg
HRB 36809 (AG Nürnberg), GF: I. Totev, A. McDonald, W. Knoblich
#5 lore raw
In reply to Nilay Shroff
Quoted 9 lines · Nilay Shroff

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.

FYI, I applied this patch with a slight edit to move local variable declarations. Thanks!