block: Fix permission during reopen
v2 cover block: Fix permission during reopen
v2: Use update_flags_from_options. [Kevin]
We write open the whole backing chain during reopen. It is not necessary and will cause image locking problems if the backing image is shared.
Fam Zheng (2):
block: Fix flags in reopen queue
iotests: Add regression test for commit base locking
block.c | 7 +++++++ tests/qemu-iotests/153 | 8 ++++++++ tests/qemu-iotests/153.out | 4 ++++ 3 files changed, 19 insertions(+)
Signature · 1 line
2.14.3
PATCH v2 1/2 block: Fix flags in reopen queue
Reopen flags are not synchronized according to the bdrv_reopen_queue_child precedence until bdrv_reopen_prepare. It is a bit too late: we already check the consistency in bdrv_check_perm before that.
This fixes the bug that when bdrv_reopen a RO node as RW, the flags for backing child are wrong. Before, we could recurse with flags.rw=1; now, role->inherit_options + update_flags_from_options will make sure to clear the bit when necessary. Note that this will not clear an explicitly set bit, as in the case of parallel block jobs (e.g. test_stream_parallel in 030), because the explicit options include 'read-only=false' (for an intermediate node used by a different job).
--- block.c | 7 +++++++ 1 file changed, 7 insertions(+)
block.c +7 -0
@@ -2883,8 +2883,15 @@ static BlockReopenQueue *bdrv_reopen_queue_child(BlockReopenQueue *bs_queue,/* Inherit from parent node */ if (parent_options) { +QemuOpts *opts; +QDict *options_copy;assert (!flags); role->inherit_options (&flags, options, parent_flags, parent_options); + options_copy =qdict_clone_shallow (options); + opts =qemu_opts_create (&bdrv_runtime_opts,NULL ,0 , &error_abort); +qemu_opts_absorb_qdict (opts, options_copy,NULL ); +update_flags_from_options (&flags, opts); +qemu_opts_del (opts); }/* Old values are used for options that aren't set yet */
Signature · 1 line
2.14.3
Re: [Qemu-devel] [PATCH v2 1/2] block: Fix flags in reopen queue
Quoted 13 lines · Fam Zheng
Reopen flags are not synchronized according to the
bdrv_reopen_queue_childprecedence untilbdrv_reopen_prepare. It is a bit too late: we already check the consistency inbdrv_check_permbefore that.This fixes the bug that when
bdrv_reopena RO node as RW, the flags for backing child are wrong. Before, we could recurse with flags.rw=1; now,role->inherit_options+update_flags_from_optionswill make sure to clear the bit when necessary. Note that this will not clear an explicitly set bit, as in the case of parallel block jobs (e.g.test_stream_parallelin 030), because the explicit options include 'read-only=false' (for an intermediate node used by a different job).
Quoted 4 lines
Signed-off-by Fam Zheng <[email protected]>--- block.c | 7 +++++++ 1 file changed, 7 insertions(+)
PATCH v2 2/2 iotests: Add regression test for commit base locking
In reply to Fam Zheng--- tests/qemu-iotests/153 | 8 ++++++++ tests/qemu-iotests/153.out | 4 ++++ 2 files changed, 12 insertions(+)
tests/qemu-iotests/153 +8 -0
@@ -178,6 +178,14 @@ rm -f "${TEST_IMG}.lnk" &>/dev/null ln -s ${TEST_IMG} "${TEST_IMG}.lnk" || echo "Failed to create link" _run_qemu_with_images "${TEST_IMG}.lnk" "${TEST_IMG}" +echo +echo "== Active commit to intermediate layer should work when base in use ==" +_launch_qemu -drive format=$IMGFMT,file="${TEST_IMG}.a",id=drive0 \ + -device virtio-blk,drive=drive0 +_run_cmd $QEMU_IMG commit -b "${TEST_IMG}.b" "${TEST_IMG}.c" + +_cleanup_qemu + _launch_qemu _send_qemu_cmd $QEMU_HANDLE \
tests/qemu-iotests/153.out +4 -0
@@ -372,6 +372,10 @@ Is another process using the image? == Symbolic link == QEMU_PROG: -drive if=none,file=TEST_DIR/t.qcow2: Failed to get "write" lock Is another process using the image? + +== Active commit to intermediate layer should work when base in use == + +_qemu_img_wrapper commit -b TEST_DIR/t.qcow2.b TEST_DIR/t.qcow2.c {"return": {}} Adding drive
Signature · 1 line
2.14.3
Re: [Qemu-devel] [PATCH v2 2/2] iotests: Add regression test for commit base locking
Quoted 30 lines · Fam Zheng
Signed-off-by Fam Zheng <[email protected]>--- tests/qemu-iotests/153 | 8 ++++++++ tests/qemu-iotests/153.out | 4 ++++ 2 files changed, 12 insertions(+)tests/qemu-iotests/153 +8
-0@@ -178,6 +178,14 @@ rm -f "${TEST_IMG}.lnk" &>/dev/null ln -s ${TEST_IMG} "${TEST_IMG}.lnk" || echo "Failed to create link" _run_qemu_with_images "${TEST_IMG}.lnk" "${TEST_IMG}" +echo +echo "== Active commit to intermediate layer should work when base in use ==" +_launch_qemu -drive format=$IMGFMT,file="${TEST_IMG}.a",id=drive0 \ + -device virtio-blk,drive=drive0 +_run_cmd $QEMU_IMG commit -b "${TEST_IMG}.b" "${TEST_IMG}.c" + +_cleanup_qemu + _launch_qemu _send_qemu_cmd $QEMU_HANDLE \tests/qemu-iotests/153.out +0
-0
tests/qemu-iotests/153.out Is another process using the image? · line 380
Quoted 9 lines
tests/qemu-iotests/153.out +4
-0@@ -372,6 +372,10 @@ Is another process using the image? == Symbolic link == QEMU_PROG: -drive if=none,file=TEST_DIR/t.qcow2: Failed to get "write" lock Is another process using the image? + +== Active commit to intermediate layer should work when base in use == + +_qemu_img_wrapper commit -b TEST_DIR/t.qcow2.b TEST_DIR/t.qcow2.c {"return": {}} Adding drive
Hmmm... I don't know, but this just passes on my machine without your previous patch.
[Two minutes later]
Now I do know why, qemu simply isn't properly started at the time $QEMU_IMG commit runs (see also 6bfc907deed83af7). Therefore, no error here.
So if I just add a
_send_qemu_cmd $QEMU_HANDLE \
"{ 'execute': 'qmp_capabilities' }" \
'return'after the _launch_qemu, this is what I get:
QEMU_PROG: -device virtio-blk,drive=drive0: Drive 'drive0' is already in use because it has been automatically connected to another device (did you need 'if=none' in the drive options?)
With if=none (or just -blockdev instead of -drive), I get the error message I was hoping for.
Max