[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH v2 01/14] block: Don't call update_flags_from_option
From: |
Alberto Garcia |
Subject: |
[Qemu-devel] [PATCH v2 01/14] block: Don't call update_flags_from_options() if the options are wrong |
Date: |
Wed, 17 Oct 2018 15:57:17 +0300 |
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 <address@hidden>
Reviewed-by: Max Reitz <address@hidden>
---
block.c | 11 +++++++++--
tests/qemu-iotests/133 | 6 ++++++
tests/qemu-iotests/133.out | 4 ++++
3 files changed, 19 insertions(+), 2 deletions(-)
diff --git a/block.c b/block.c
index 7710b399a3..47d5fe2f91 100644
--- a/block.c
+++ b/block.c
@@ -2942,12 +2942,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);
}
diff --git a/tests/qemu-iotests/133 b/tests/qemu-iotests/133
index af6b3e1dd4..b9f17c996f 100755
--- a/tests/qemu-iotests/133
+++ b/tests/qemu-iotests/133
@@ -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
diff --git a/tests/qemu-iotests/133.out b/tests/qemu-iotests/133.out
index f4a85aeb63..570f623b6b 100644
--- a/tests/qemu-iotests/133.out
+++ b/tests/qemu-iotests/133.out
@@ -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
--
2.11.0
- [Qemu-devel] [PATCH v2 00/14] Don't pass flags to bdrv_reopen_queue(), Alberto Garcia, 2018/10/17
- [Qemu-devel] [PATCH v2 06/14] block: Use bdrv_reopen_set_read_only() in stream_start/complete(), Alberto Garcia, 2018/10/17
- [Qemu-devel] [PATCH v2 07/14] block: Use bdrv_reopen_set_read_only() in qmp_change_backing_file(), Alberto Garcia, 2018/10/17
- [Qemu-devel] [PATCH v2 03/14] block: Use bdrv_reopen_set_read_only() in bdrv_backing_update_filename(), Alberto Garcia, 2018/10/17
- [Qemu-devel] [PATCH v2 09/14] block: Use bdrv_reopen_set_read_only() in the mirror driver, Alberto Garcia, 2018/10/17
- [Qemu-devel] [PATCH v2 02/14] block: Add bdrv_reopen_set_read_only(), Alberto Garcia, 2018/10/17
- [Qemu-devel] [PATCH v2 01/14] block: Don't call update_flags_from_options() if the options are wrong,
Alberto Garcia <=
- [Qemu-devel] [PATCH v2 08/14] block: Use bdrv_reopen_set_read_only() in external_snapshot_commit(), Alberto Garcia, 2018/10/17
- [Qemu-devel] [PATCH v2 04/14] block: Use bdrv_reopen_set_read_only() in commit_start/complete(), Alberto Garcia, 2018/10/17
- [Qemu-devel] [PATCH v2 05/14] block: Use bdrv_reopen_set_read_only() in bdrv_commit(), Alberto Garcia, 2018/10/17
- [Qemu-devel] [PATCH v2 11/14] qemu-io: Put flag changes in the options QDict in reopen_f(), Alberto Garcia, 2018/10/17
- [Qemu-devel] [PATCH v2 10/14] block: Drop bdrv_reopen(), Alberto Garcia, 2018/10/17
- [Qemu-devel] [PATCH v2 13/14] block: Remove flags parameter from bdrv_reopen_queue(), Alberto Garcia, 2018/10/17
- [Qemu-devel] [PATCH v2 12/14] block: Clean up reopen_backing_file() in block/replication.c, Alberto Garcia, 2018/10/17
- [Qemu-devel] [PATCH v2 14/14] block: Stop passing flags to bdrv_reopen_queue_child(), Alberto Garcia, 2018/10/17