nvme/058: detach loop device after test finish
PATCH 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.
--- tests/nvme/058 | 11 +++++++++++ 1 file changed, 11 insertions(+)
tests/nvme/058 +11 -0
@@ -99,6 +99,17 @@ test() { done _nvme_disconnect_subsys + + for ((d = 1; d <= num_namespaces; d++)); do + local file_path + local blkdev + + file_path="${TMPDIR}/img${d}" + blkdev="$(losetup -l | awk -v path="${file_path}" '$6 == path { print $1 }')" + + losetup -d "${blkdev}" + done + _nvmet_target_cleanup echo "Test complete"
Signature · 1 line
2.47.1
Quoted 7 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.
Thank you for catching this issue. This needs a fix.
Quoted 14 lines
Signed-off-by Nilay Shroff <[email protected]>--- tests/nvme/058 | 11 +++++++++++ 1 file changed, 11 insertions(+)tests/nvme/058 +0
-0@@ -99,6 +99,17 @@ test() { done _nvme_disconnect_subsys
tests/nvme/058 test() { · line 111
Quoted 10 lines
tests/nvme/058 +10
-0+ + for ((d = 1; d <= num_namespaces; d++)); do + local file_path + local blkdev + + file_path="${TMPDIR}/img${d}" + blkdev="$(losetup -l | awk -v path="${file_path}" '$6 == path { print $1 }')" + + losetup -d "${blkdev}" + done
This for loop looks similar and redundant with the other for loop to set up the namespaces. How about to keep the blkdevs in an array, and refer to them to detach? The pseudo code below shows this approach:
local blkdev
local -a blkdevs
...
(in the 1st loop)
...
blkdevs+=$("$blkdev")
... ...
(after _nvme_disconnect_subsys)
for blkdev in "${blkdevs[@]}"; do
losetup --detach "$blkdev"
done
...Also I suggest to use long option names instead of short names for readability and code stability: e.g., instead of "losetup -d", let's use "losetup --detach". (No need to replace short option names in existing code. I'm suggesting this for the new lines to add.)
Quoted 7 lines
tests/nvme/058 +1
-0+ _nvmet_target_cleanup echo "Test complete"Signature · 1 line
2.47.1
Quoted 11 lines · Shinichiro Kawasaki
Quoted 7 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.
Thank you for catching this issue. This needs a fix.
Thank you for your review and comments!
Quoted 37 lines
Quoted 14 lines
Signed-off-by Nilay Shroff <[email protected]>--- tests/nvme/058 | 11 +++++++++++ 1 file changed, 11 insertions(+)tests/nvme/058 +0
-0@@ -99,6 +99,17 @@ test() { done _nvme_disconnect_subsystests/nvme/058 test() { · line 111
Quoted 10 lines
tests/nvme/058 +10
-0+ + for ((d = 1; d <= num_namespaces; d++)); do + local file_path + local blkdev + + file_path="${TMPDIR}/img${d}" + blkdev="$(losetup -l | awk -v path="${file_path}" '$6 == path { print $1 }')" + + losetup -d "${blkdev}" + doneThis for loop looks similar and redundant with the other for loop to set up the namespaces. How about to keep the blkdevs in an array, and refer to them to detach? The pseudo code below shows this approach:
local blkdev
local -a blkdevs
...
(in the 1st loop)... blkdevs+=$("$blkdev") ...
Quoted 8 lines
...
(after_nvme_disconnect_subsys)for blkdev in "${blkdevs[@]}"; do losetup --detach "$blkdev" done ...
Yes this looks good! I will incorporate this in the next patch.
Quoted 6 lines
Also I suggest to use long option names instead of short names for readability and code stability: e.g., instead of "losetup -d", let's use "losetup --detach". (No need to replace short option names in existing code. I'm suggesting this for the new lines to add.)
Sure, will do the needful.
Thanks,
--Nilay