iotests/qsd-jobs: Use common.qemu for the QSD
cover iotests/qsd-jobs: Use common.qemu for the QSD
(Alternative to: “iotests/qsd-jobs: Filter events in the first test”)
Hi,
The qsd-jobs test has kind of unreliable output, because sometimes the job is ready before ‘quit’, and sometimes it is not. This series presents one approach to fix that, which is to extend common.qemu to allow running the storage daemon instead of qemu, and then to use that in qsd-jobs to wait for the BLOCK_JOB_READY event before issuing the ‘quit’ command.
I took patch 1 from my “qcow2: Improve refcount structure rebuilding” series.
(https://lists.nongnu.org/archive/html/qemu-block/2021-03/msg00654.html)
As noted above, this series is an alternative to “iotests/qsd-jobs:
Filter events in the first test”. I like this series here better because I’d prefer it if tests that do QMP actually check the output so they control what’s really happening.
On the other hand, this may be too complicated for 6.0, and we might want to fix qsd-jobs in 6.0.
Max Reitz (2):
iotests/common.qemu: Allow using the QSD
iotests/qsd-jobs: Use common.qemu for the QSD
tests/qemu-iotests/common.qemu | 53 +++++++++++++++++++++----- tests/qemu-iotests/tests/qsd-jobs | 55 ++++++++++++++++++++------- tests/qemu-iotests/tests/qsd-jobs.out | 10 ++++- 3 files changed, 92 insertions(+), 26 deletions(-)
Signature · 1 line
2.29.2
PATCH 1/2 iotests/common.qemu: Allow using the QSD
For block things, we often do not need to run all of qemu, so allow using the qemu-storage-daemon instead.
--- tests/qemu-iotests/common.qemu | 53 +++++++++++++++++++++++++++------- 1 file changed, 43 insertions(+), 10 deletions(-)
tests/qemu-iotests/common.qemu +43 -10
@@ -291,6 +291,8 @@ _wait_event() # $qmp_pretty: Set this variable to 'y' to enable QMP pretty printing. # $keep_stderr: Set this variable to 'y' to keep QEMU's stderr output on stderr. # If this variable is empty, stderr will be redirected to stdout. +# $qsd: Set this variable to 'y' to use the QSD instead of QEMU. +# stdout and stderr are never redirected when using the QSD. # Returns: # $QEMU_HANDLE: set to a handle value to communicate with this QEMU instance. #
@@ -300,18 +302,31 @@ _launch_qemu() local fifo_out= local fifo_in= + if [[ $qsd = 'y' ]]; then + mon_arg='--monitor' + else + mon_arg='-mon' + fi + if (shopt -s nocasematch; [[ "${qemu_comm_method}" == "monitor" ]]) then - comm="-monitor stdio" + comm=(--chardev stdio,id=pipe + $mon_arg pipe,mode=readline) else local qemu_comm_method="qmp" if [ "$qmp_pretty" = "y" ]; then - comm="-monitor none -qmp-pretty stdio" + comm=(--chardev stdio,id=pipe + $mon_arg pipe,mode=control,pretty=on) else - comm="-monitor none -qmp stdio" + comm=(--chardev stdio,id=pipe + $mon_arg pipe,mode=control,pretty=off) fi fi + if [[ $qsd != 'y' ]]; then + comm=(-monitor none "${comm[@]}") + fi + fifo_out=${QEMU_FIFO_OUT}_${_QEMU_HANDLE} fifo_in=${QEMU_FIFO_IN}_${_QEMU_HANDLE} mkfifo "${fifo_out}"
@@ -322,15 +337,23 @@ _launch_qemu() object_options="--object secret,id=keysec0,data=$IMGKEYSECRET" fi + if [[ $qsd = 'y' ]]; then + cmd=$QSD + args=() + else + cmd=$QEMU + args=(-nographic -serial none) + fi + args+=(${object_options} "${comm[@]}") + args+=("$@") + + # Just set both QEMU_NEED_PID and QSD_NEED_PID, it can't hurt. if [ -z "$keep_stderr" ]; then - QEMU_NEED_PID='y'\ - ${QEMU} ${object_options} -nographic -serial none ${comm} "${@}" >"${fifo_out}" \ - 2>&1 \ - <"${fifo_in}" & + QEMU_NEED_PID='y' QSD_NEED_PID='y' $cmd "${args[@]}" \ + >"$fifo_out" 2>&1 <"$fifo_in" & elif [ "$keep_stderr" = "y" ]; then - QEMU_NEED_PID='y'\ - ${QEMU} ${object_options} -nographic -serial none ${comm} "${@}" >"${fifo_out}" \ - <"${fifo_in}" & + QEMU_NEED_PID='y' QSD_NEED_PID='y' $cmd "${args[@]}" \ + >"$fifo_out" <"$fifo_in" & else exit 1 fi
@@ -360,6 +383,16 @@ _launch_qemu() silent=yes _timed_wait_for ${_QEMU_HANDLE} "^}" fi fi + + if [[ $qsd = 'y' ]]; then + # Wait for PID file, then move it to where qemu would put it + pidfile="$QEMU_TEST_DIR/qemu-storage-daemon.pid" + while [[ ! -f $pidfile ]]; do + sleep 0.5 + done + mv "$pidfile" "$QEMU_TEST_DIR/qemu-${_QEMU_HANDLE}.pid" + fi + QEMU_HANDLE=${_QEMU_HANDLE} let _QEMU_HANDLE++ }
Signature · 1 line
2.29.2
PATCH 2/2 iotests/qsd-jobs: Use common.qemu for the QSD
In reply to Max ReitzUsing common.qemu allows us to wait for specific replies, so we can for example wait for events. This allows starting the active commit job and then wait for it to be ready before quitting the QSD, so we the output is always the same.
(Strictly speaking, this is only necessary for the first test in qsd-jobs, but we might as well make the second one use common.qemu's infrastructure, too.)
--- tests/qemu-iotests/tests/qsd-jobs | 55 ++++++++++++++++++++------- tests/qemu-iotests/tests/qsd-jobs.out | 10 ++++- 2 files changed, 49 insertions(+), 16 deletions(-)
tests/qemu-iotests/tests/qsd-jobs +41 -14
@@ -38,6 +38,7 @@ trap "_cleanup; exit \$status" 0 1 2 3 15 cd .. . ./common.rc . ./common.filter +. ./common.qemu _supported_fmt qcow2 _supported_proto generic
@@ -52,32 +53,58 @@ echo "=== Job still present at shutdown ===" echo # Just make sure that this doesn't crash -$QSD --chardev stdio,id=stdio --monitor chardev=stdio \ +qsd=y _launch_qemu \ --blockdev node-name=file0,driver=file,filename="$TEST_IMG" \ - --blockdev node-name=fmt0,driver=qcow2,file=file0 <<EOF | _filter_qmp -{"execute":"qmp_capabilities"} -{"execute": "block-commit", "arguments": {"device": "fmt0", "job-id": "job0"}} -{"execute": "quit"} -EOF + --blockdev node-name=fmt0,driver=qcow2,file=file0 + +_send_qemu_cmd \ + $QEMU_HANDLE \ + '{"execute":"qmp_capabilities"}' \ + 'return' + +_send_qemu_cmd \ + $QEMU_HANDLE \ + '{"execute": "block-commit", + "arguments": {"device": "fmt0", "job-id": "job0"}}' \ + 'BLOCK_JOB_READY' + +_send_qemu_cmd \ + $QEMU_HANDLE \ + '{"execute": "quit"}' \ + 'return' + +wait=y _cleanup_qemu echo echo "=== Streaming can't get permission on base node ===" echo # Just make sure that this doesn't crash -$QSD --chardev stdio,id=stdio --monitor chardev=stdio \ +qsd=y _launch_qemu \ --blockdev node-name=file_base,driver=file,filename="$TEST_IMG.base" \ --blockdev node-name=fmt_base,driver=qcow2,file=file_base \ --blockdev node-name=file_overlay,driver=file,filename="$TEST_IMG" \ --blockdev node-name=fmt_overlay,driver=qcow2,file=file_overlay,backing=fmt_base \ --nbd-server addr.type=unix,addr.path="$SOCK_DIR/nbd.sock" \ - --export type=nbd,id=export1,node-name=fmt_base,writable=on,name=export1 \ - <<EOF | _filter_qmp -{"execute": "qmp_capabilities"} -{"execute": "block-stream", - "arguments": {"device": "fmt_overlay", "job-id": "job0"}} -{"execute": "quit"} -EOF + --export type=nbd,id=export1,node-name=fmt_base,writable=on,name=export1 + +_send_qemu_cmd \ + $QEMU_HANDLE \ + '{"execute": "qmp_capabilities"}' \ + 'return' + +_send_qemu_cmd \ + $QEMU_HANDLE \ + '{"execute": "block-stream", + "arguments": {"device": "fmt_overlay", "job-id": "job0"}}' \ + 'error' + +_send_qemu_cmd \ + $QEMU_HANDLE \ + '{"execute": "quit"}' \ + 'return' + +wait=y _cleanup_qemu # success, all done echo "*** done"
tests/qemu-iotests/tests/qsd-jobs.out +8 -2
@@ -4,13 +4,16 @@ Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=134217728 backing_file=TEST_DIR/ === Job still present at shutdown === -QMP_VERSION +{"execute":"qmp_capabilities"} {"return": {}} +{"execute": "block-commit", + "arguments": {"device": "fmt0", "job-id": "job0"}} {"timestamp": {"seconds": TIMESTAMP, "microseconds": TIMESTAMP}, "event": "JOB_STATUS_CHANGE", "data": {"status": "created", "id": "job0"}} {"timestamp": {"seconds": TIMESTAMP, "microseconds": TIMESTAMP}, "event": "JOB_STATUS_CHANGE", "data": {"status": "running", "id": "job0"}} {"return": {}} {"timestamp": {"seconds": TIMESTAMP, "microseconds": TIMESTAMP}, "event": "JOB_STATUS_CHANGE", "data": {"status": "ready", "id": "job0"}} {"timestamp": {"seconds": TIMESTAMP, "microseconds": TIMESTAMP}, "event": "BLOCK_JOB_READY", "data": {"device": "job0", "len": 0, "offset": 0, "speed": 0, "type": "commit"}} +{"execute": "quit"} {"return": {}} {"timestamp": {"seconds": TIMESTAMP, "microseconds": TIMESTAMP}, "event": "JOB_STATUS_CHANGE", "data": {"status": "standby", "id": "job0"}} {"timestamp": {"seconds": TIMESTAMP, "microseconds": TIMESTAMP}, "event": "JOB_STATUS_CHANGE", "data": {"status": "ready", "id": "job0"}}
@@ -22,11 +25,14 @@ QMP_VERSION === Streaming can't get permission on base node === -QMP_VERSION +{"execute": "qmp_capabilities"} {"return": {}} +{"execute": "block-stream", + "arguments": {"device": "fmt_overlay", "job-id": "job0"}} {"timestamp": {"seconds": TIMESTAMP, "microseconds": TIMESTAMP}, "event": "JOB_STATUS_CHANGE", "data": {"status": "created", "id": "job0"}} {"timestamp": {"seconds": TIMESTAMP, "microseconds": TIMESTAMP}, "event": "JOB_STATUS_CHANGE", "data": {"status": "null", "id": "job0"}} {"error": {"class": "GenericError", "desc": "Conflicts with use by a block device as 'root', which uses 'write' on fmt_base"}} +{"execute": "quit"} {"return": {}} {"timestamp": {"seconds": TIMESTAMP, "microseconds": TIMESTAMP}, "event": "BLOCK_EXPORT_DELETED", "data": {"id": "export1"}} *** done
Signature · 1 line
2.29.2
Quoted 9 lines · Max Reitz
Using common.qemu allows us to wait for specific replies, so we can for example wait for events. This allows starting the active commit job and then wait for it to be ready before quitting the QSD, so we the output is always the same.
(Strictly speaking, this is only necessary for the first test in qsd-jobs, but we might as well make the second one use common.qemu's infrastructure, too.)
Quoted 20 lines
Reported-by Peter Maydell <[email protected]>Signed-off-by Max Reitz <[email protected]>--- tests/qemu-iotests/tests/qsd-jobs | 55 ++++++++++++++++++++------- tests/qemu-iotests/tests/qsd-jobs.out | 10 ++++- 2 files changed, 49 insertions(+), 16 deletions(-)tests/qemu-iotests/tests/qsd-jobs +1
-0@@ -38,6 +38,7 @@ trap "_cleanup; exit \$status" 0 1 2 3 15 cd .. . ./common.rc . ./common.filter +. ./common.qemu _supported_fmt qcow2 _supported_proto generic
tests/qemu-iotests/tests/qsd-jobs echo "=== Job still present at shutdown ===" · line 56
Quoted 5 lines
tests/qemu-iotests/tests/qsd-jobs +1
-1@@ -52,32 +53,58 @@ echo "=== Job still present at shutdown ===" echo # Just make sure that this doesn't crash -$QSD --chardev stdio,id=stdio --monitor chardev=stdio \ +qsd=y _launch_qemu \
sounds a bit strange.. Like we are starting qemu.
Quoted 106 lines
tests/qemu-iotests/tests/qsd-jobs +39
-13--blockdev node-name=file0,driver=file,filename="$TEST_IMG" \ - --blockdev node-name=fmt0,driver=qcow2,file=file0 <<EOF | _filter_qmp -{"execute":"qmp_capabilities"} -{"execute": "block-commit", "arguments": {"device": "fmt0", "job-id": "job0"}} -{"execute": "quit"} -EOF + --blockdev node-name=fmt0,driver=qcow2,file=file0 + +_send_qemu_cmd \ + $QEMU_HANDLE \ + '{"execute":"qmp_capabilities"}' \ + 'return' + +_send_qemu_cmd \ + $QEMU_HANDLE \ + '{"execute": "block-commit", + "arguments": {"device": "fmt0", "job-id": "job0"}}' \ + 'BLOCK_JOB_READY' + +_send_qemu_cmd \ + $QEMU_HANDLE \ + '{"execute": "quit"}' \ + 'return' + +wait=y _cleanup_qemu echo echo "=== Streaming can't get permission on base node ===" echo # Just make sure that this doesn't crash -$QSD --chardev stdio,id=stdio --monitor chardev=stdio \ +qsd=y _launch_qemu \ --blockdev node-name=file_base,driver=file,filename="$TEST_IMG.base" \ --blockdev node-name=fmt_base,driver=qcow2,file=file_base \ --blockdev node-name=file_overlay,driver=file,filename="$TEST_IMG" \ --blockdev node-name=fmt_overlay,driver=qcow2,file=file_overlay,backing=fmt_base \ --nbd-server addr.type=unix,addr.path="$SOCK_DIR/nbd.sock" \ - --export type=nbd,id=export1,node-name=fmt_base,writable=on,name=export1 \ - <<EOF | _filter_qmp -{"execute": "qmp_capabilities"} -{"execute": "block-stream", - "arguments": {"device": "fmt_overlay", "job-id": "job0"}} -{"execute": "quit"} -EOF + --export type=nbd,id=export1,node-name=fmt_base,writable=on,name=export1 + +_send_qemu_cmd \ + $QEMU_HANDLE \ + '{"execute": "qmp_capabilities"}' \ + 'return' + +_send_qemu_cmd \ + $QEMU_HANDLE \ + '{"execute": "block-stream", + "arguments": {"device": "fmt_overlay", "job-id": "job0"}}' \ + 'error' + +_send_qemu_cmd \ + $QEMU_HANDLE \ + '{"execute": "quit"}' \ + 'return' + +wait=y _cleanup_qemu # success, all done echo "*** done"tests/qemu-iotests/tests/qsd-jobs.out +8
-2@@ -4,13 +4,16 @@ Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=134217728 backing_file=TEST_DIR/ === Job still present at shutdown === -QMP_VERSION +{"execute":"qmp_capabilities"} {"return": {}} +{"execute": "block-commit", + "arguments": {"device": "fmt0", "job-id": "job0"}} {"timestamp": {"seconds": TIMESTAMP, "microseconds": TIMESTAMP}, "event": "JOB_STATUS_CHANGE", "data": {"status": "created", "id": "job0"}} {"timestamp": {"seconds": TIMESTAMP, "microseconds": TIMESTAMP}, "event": "JOB_STATUS_CHANGE", "data": {"status": "running", "id": "job0"}} {"return": {}} {"timestamp": {"seconds": TIMESTAMP, "microseconds": TIMESTAMP}, "event": "JOB_STATUS_CHANGE", "data": {"status": "ready", "id": "job0"}} {"timestamp": {"seconds": TIMESTAMP, "microseconds": TIMESTAMP}, "event": "BLOCK_JOB_READY", "data": {"device": "job0", "len": 0, "offset": 0, "speed": 0, "type": "commit"}} +{"execute": "quit"} {"return": {}} {"timestamp": {"seconds": TIMESTAMP, "microseconds": TIMESTAMP}, "event": "JOB_STATUS_CHANGE", "data": {"status": "standby", "id": "job0"}} {"timestamp": {"seconds": TIMESTAMP, "microseconds": TIMESTAMP}, "event": "JOB_STATUS_CHANGE", "data": {"status": "ready", "id": "job0"}}@@ -22,11 +25,14 @@ QMP_VERSION === Streaming can't get permission on base node === -QMP_VERSION +{"execute": "qmp_capabilities"} {"return": {}} +{"execute": "block-stream", + "arguments": {"device": "fmt_overlay", "job-id": "job0"}} {"timestamp": {"seconds": TIMESTAMP, "microseconds": TIMESTAMP}, "event": "JOB_STATUS_CHANGE", "data": {"status": "created", "id": "job0"}} {"timestamp": {"seconds": TIMESTAMP, "microseconds": TIMESTAMP}, "event": "JOB_STATUS_CHANGE", "data": {"status": "null", "id": "job0"}} {"error": {"class": "GenericError", "desc": "Conflicts with use by a block device as 'root', which uses 'write' on fmt_base"}} +{"execute": "quit"} {"return": {}} {"timestamp": {"seconds": TIMESTAMP, "microseconds": TIMESTAMP}, "event": "BLOCK_EXPORT_DELETED", "data": {"id": "export1"}} *** done
Signature · 2 lines
Best regards, Vladimir
Quoted 30 lines · Vladimir Sementsov-Ogievskiy
Quoted 9 lines · Max Reitz
Using common.qemu allows us to wait for specific replies, so we can for example wait for events. This allows starting the active commit job and then wait for it to be ready before quitting the QSD, so we the output is always the same.
(Strictly speaking, this is only necessary for the first test in qsd-jobs, but we might as well make the second one use common.qemu's infrastructure, too.)
Reviewed-by Vladimir Sementsov-Ogievskiy <[email protected]>Quoted 17 lines
Reported-by Peter Maydell <[email protected]>Signed-off-by Max Reitz <[email protected]>---
tests/qemu-iotests/tests/qsd-jobs | 55 ++++++++++++++++++++------- tests/qemu-iotests/tests/qsd-jobs.out | 10 ++++-2 files changed, 49 insertions(+), 16 deletions(-)tests/qemu-iotests/tests/qsd-jobs +0
-0@@ -38,6 +38,7 @@ trap "_cleanup; exit \$status" 0 1 2 3 15cd ..
. ./common.rc
. ./common.filter
+. ./common.qemu
_supported_fmtqcow2
Quoted 8 lines
Quoted 6 lines
_supported_protogenerictests/qemu-iotests/tests/qsd-jobs +0
-0@@ -52,32 +53,58 @@ echo "=== Job still present at shutdown ==="echo
# Just make sure that this doesn't crash -$QSD --chardev stdio,id=stdio --monitor chardev=stdio \
+qsd=y_launch_qemu\sounds a bit strange.. Like we are starting qemu.
Yeah, well. Yeah. We could have a
_launch_qsd()
{
qsd=y _launch_qemu
}
But this would still make it weird for all the other commands from common.qemu, and I don’t think it makes much sense to introduce aliases for all of them. So I think it’d be best to live with that bit of weirdness.
Max
Quoted 23 lines · Max Reitz
(Alternative to: “iotests/qsd-jobs: Filter events in the first test”)
Hi,
The qsd-jobs test has kind of unreliable output, because sometimes the job is ready before ‘quit’, and sometimes it is not. This series presents one approach to fix that, which is to extend common.qemu to allow running the storage daemon instead of qemu, and then to use that in qsd-jobs to wait for the
BLOCK_JOB_READYevent before issuing the ‘quit’ command.I took patch 1 from my “qcow2: Improve refcount structure rebuilding” series.
(https://lists.nongnu.org/archive/html/qemu-block/2021-03/msg00654.html)As noted above, this series is an alternative to “iotests/qsd-jobs:
Filter events in the first test”. I like this series here better because I’d prefer it if tests that do QMP actually check the output so they control what’s really happening.
On the other hand, this may be too complicated for 6.0, and we might want to fix qsd-jobs in 6.0.
Quoted 12 lines
Max Reitz (2):
iotests/common.qemu: Allow using the QSD
iotests/qsd-jobs: Use common.qemu for the QSDtests/qemu-iotests/common.qemu | 53 +++++++++++++++++++++----- tests/qemu-iotests/tests/qsd-jobs | 55 ++++++++++++++++++++------- tests/qemu-iotests/tests/qsd-jobs.out | 10 ++++- 3 files changed, 92 insertions(+), 26 deletions(-)Signature · 1 line
2.29.2