Skip to content

run_qemu.sh: replace "grep root.img" with losetup --associated #184

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 30, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions run_qemu.sh
Original file line number Diff line number Diff line change
Expand Up @@ -225,14 +225,14 @@ guest_alive()
[ -e "$qmp_sock" ]
}

rootfs_loop_devs()
loop_devs()
{
sudo losetup --list | grep "$_arg_rootfs" | awk '{ print $1 }'
sudo losetup --noheadings --output NAME --associated "$1"
}

loop_teardown()
{
for loopdev in $(rootfs_loop_devs); do
for loopdev in $(loop_devs "$abs_rootfs"); do
if [ -b "$loopdev" ]; then
sudo umount "${loopdev}p1" || true
sudo umount "${loopdev}p2" || true
Expand Down Expand Up @@ -422,6 +422,8 @@ process_options_logic()
set -x
fi

abs_rootfs=$(realpath "${builddir}/${_arg_rootfs}")

arch_init

if [[ $_arg_cxl_test_run == "on" ]]; then
Expand Down Expand Up @@ -714,15 +716,15 @@ get_loopdev()
{
local loopdev num_loopdev

loopdev=$(rootfs_loop_devs)
loopdev=$(loop_devs "$abs_rootfs")
# We cannot count newlines with `wc -l` because $( ) trims the trailing
# newline which makes 0 and 1 loopback device give the same count.
num_loopdev=$(grep -c dev/loop <<<"$loopdev")

if (( num_loopdev != 1 )); then
{ lsblk -f || true
sudo losetup --list
fail "Expected 1 loopdev for $_arg_rootfs, found $num_loopdev.
fail "Expected 1 loopdev for $abs_rootfs, found $num_loopdev.
\tTry 'sudo losetup -D' to remove any stale loopdevs"
} >&2 # get_loopdev() stdout is normally captured
fi
Expand Down