Skip to content

Commit

Permalink
nvme/058: detach loop device after test finish
Browse files Browse the repository at this point in the history
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 <[email protected]>
Reviewed-by: Hannes Reinecke <[email protected]>
Reviewed-by: Sagi Grimberg <[email protected]>
Reviewed-by: Chaitanya Kulkarni <[email protected]>
[Shin'ichiro: moved local variable declarations out of if block]
Signed-off-by: Shin'ichiro Kawasaki <[email protected]>
  • Loading branch information
shroffni authored and kawasaki committed Jan 27, 2025
1 parent d5a0612 commit 67aff55
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion tests/nvme/058
Original file line number Diff line number Diff line change
Expand Up @@ -58,18 +58,20 @@ test() {

local d i n port
local -a ports
local blkdev
local -a blkdevs
local num_namespaces=3

_nvmet_target_setup --ports 6 --blkdev none

for ((d = 1; d <= num_namespaces; d++)); do
local file_path
local blkdev
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
Expand Down Expand Up @@ -99,6 +101,11 @@ test() {
done

_nvme_disconnect_subsys

for blkdev in "${blkdevs[@]}"; do
losetup --detach "$blkdev"
done

_nvmet_target_cleanup

echo "Test complete"
Expand Down

0 comments on commit 67aff55

Please sign in to comment.