From: Harald Hoyer Date: Mon, 19 Apr 2021 14:30:50 +0000 (+0200) Subject: ci: add function to generate qemu disk arguments X-Git-Tag: 054~113 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=2cfd778a45d592b42852b90cdfaf1b700ba423bc;p=thirdparty%2Fdracut.git ci: add function to generate qemu disk arguments `qemu_add_drive_args` can be used to generate arguments to specify disks for a qemu machine (`-M q35`). This is mostly useful to address those raw disks via `/dev/disk/by-id`, because due to parallel probing in the kernel `/dev/sd*` can point to anything. --- diff --git a/test/test-functions b/test/test-functions index 73b478009..c77075321 100644 --- a/test/test-functions +++ b/test/test-functions @@ -37,6 +37,46 @@ check_root() { fi } +# generate qemu arguments for named raw disks +# +# qemu_add_drive_args [] +# +# index: name of the index variable (set to 0 at start) +# args: name of the argument array variable (set to () at start) +# filename: filename of the raw disk image +# id-name: name of the disk in /dev/disk/by-id -> /dev/disk/by-id/ata-disk_$name +# bootindex: optional bootindex number +# +# to be used later with `qemu … "${args[@]}" …` +# The variable will be incremented each time the function is called. +# +# can't be easier than this :-/ +# +# # EXAMPLES +# ``` +# declare -a disk_args=() +# declare -i disk_index=0 +# qemu_add_drive_args disk_index disk_args "$TESTDIR"/root.ext3 root 1 +# qemu_add_drive_args disk_index disk_args "$TESTDIR"/client.img client +# qemu_add_drive_args disk_index disk_args "$TESTDIR"/iscsidisk2.img iscsidisk2 +# qemu_add_drive_args disk_index disk_args "$TESTDIR"/iscsidisk3.img iscsidisk3 +# qemu "${disk_args[@]}" +# ``` +qemu_add_drive_args() { + local index=${!1} + local file=$3 + local name=${4:-$index} + local bootindex=$5 + + eval "${2}"'+=(' \ + -drive "if=none,format=raw,file=${file},id=drive-sata${index}" \ + -device "ide-hd,bus=ide.${index},drive=drive-sata${index},id=sata${index},${bootindex:+bootindex=$bootindex,}model=disk,serial=${name}" \ + ')' + + # shellcheck disable=SC2219 + let "${1}++" +} + while (($# > 0)); do case $1 in --run)