block: Don't call update_flags_from_options() if the options are wrong
PATCH 1/1 block: Don't call update_flags_from_options() if the options are wrong
If qemu_opts_absorb_qdict() fails and we carry on and call update_flags_from_options() then that can result on a failed assertion:
$ qemu-io -c 'reopen -o read-only=foo' hd.qcow2 block.c:1101: update_flags_from_options: Assertion `qemu_opt_find(opts, BDRV_OPT_CACHE_DIRECT)' failed. Aborted
This only happens in bdrv_reopen_queue_child(). Although this function doesn't return errors, we can simply keep the wrong options in the reopen queue and later bdrv_reopen_prepare() will fail.
Signed-off-by Alberto Garcia <[email protected]>
--- block.c | 11 +++++++++-- tests/qemu-iotests/133 | 6 ++++++ tests/qemu-iotests/133.out | 4 ++++ 3 files changed, 19 insertions(+), 2 deletions(-)
block.c +9 -2
@@ -2931,12 +2931,19 @@ static BlockReopenQueue *bdrv_reopen_queue_child(BlockReopenQueue *bs_queue,if (parent_options) {QemuOpts *opts;QDict *options_copy; +Error *local_err =NULL ;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_absorb_qdict (opts, options_copy, &local_err); +/* Don't call update_flags_from_options() if the options are wrong. +* bdrv_reopen_prepare() will later return an error. */ +if (!local_err) { +update_flags_from_options (&flags, opts); + }else { +error_free (local_err); + }qemu_opts_del (opts);qobject_unref (options_copy); }
tests/qemu-iotests/133 +6 -0
@@ -92,6 +92,12 @@ echo IMGOPTSSYNTAX=false $QEMU_IO -f null-co -c 'reopen' -c 'info' \ "json:{'driver': 'null-co', 'size': 65536}" +echo +echo "=== Check that invalid options are handled correctly ===" +echo + +$QEMU_IO -c 'reopen -o read-only=foo' $TEST_IMG + # success, all done echo "*** done" rm -f $seq.full
tests/qemu-iotests/133.out +4 -0
@@ -24,4 +24,8 @@ Cannot change the option 'driver' format name: null-co format name: null-co + +=== Check that invalid options are handled correctly === + +Parameter 'read-only' expects 'on' or 'off' *** done
Signature · 1 line
2.11.0