[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-block] [PULL 13/25] block: qobject_is_equal() in bdrv_reopen_prepa
From: |
Kevin Wolf |
Subject: |
[Qemu-block] [PULL 13/25] block: qobject_is_equal() in bdrv_reopen_prepare() |
Date: |
Fri, 17 Nov 2017 19:16:41 +0100 |
From: Max Reitz <address@hidden>
Currently, bdrv_reopen_prepare() assumes that all BDS options are
strings. However, this is not the case if the BDS has been created
through the json: pseudo-protocol or blockdev-add.
Note that the user-invokable reopen command is an HMP command, so you
can only specify strings there. Therefore, specifying a non-string
option with the "same" value as it was when originally created will now
return an error because the values are supposedly similar (and there is
no way for the user to circumvent this but to just not specify the
option again -- however, this is still strictly better than just
crashing).
Signed-off-by: Max Reitz <address@hidden>
Reviewed-by: Eric Blake <address@hidden>
Message-id: address@hidden
Signed-off-by: Max Reitz <address@hidden>
---
block.c | 29 ++++++++++++++++++-----------
1 file changed, 18 insertions(+), 11 deletions(-)
diff --git a/block.c b/block.c
index 752fe6192b..70c6d7cf94 100644
--- a/block.c
+++ b/block.c
@@ -3074,19 +3074,26 @@ int bdrv_reopen_prepare(BDRVReopenState *reopen_state,
BlockReopenQueue *queue,
const QDictEntry *entry = qdict_first(reopen_state->options);
do {
- QString *new_obj = qobject_to_qstring(entry->value);
- const char *new = qstring_get_str(new_obj);
+ QObject *new = entry->value;
+ QObject *old = qdict_get(reopen_state->bs->options, entry->key);
+
/*
- * Caution: while qdict_get_try_str() is fine, getting
- * non-string types would require more care. When
- * bs->options come from -blockdev or blockdev_add, its
- * members are typed according to the QAPI schema, but
- * when they come from -drive, they're all QString.
+ * TODO: When using -drive to specify blockdev options, all values
+ * will be strings; however, when using -blockdev, blockdev-add or
+ * filenames using the json:{} pseudo-protocol, they will be
+ * correctly typed.
+ * In contrast, reopening options are (currently) always strings
+ * (because you can only specify them through qemu-io; all other
+ * callers do not specify any options).
+ * Therefore, when using anything other than -drive to create a
BDS,
+ * this cannot detect non-string options as unchanged, because
+ * qobject_is_equal() always returns false for objects of different
+ * type. In the future, this should be remedied by correctly
typing
+ * all options. For now, this is not too big of an issue because
+ * the user can simply omit options which cannot be changed anyway,
+ * so they will stay unchanged.
*/
- const char *old = qdict_get_try_str(reopen_state->bs->options,
- entry->key);
-
- if (!old || strcmp(new, old)) {
+ if (!qobject_is_equal(new, old)) {
error_setg(errp, "Cannot change the option '%s'", entry->key);
ret = -EINVAL;
goto error;
--
2.13.6
- [Qemu-block] [PULL 02/25] qemu-iotests: Use -nographic in 182, (continued)
- [Qemu-block] [PULL 02/25] qemu-iotests: Use -nographic in 182, Kevin Wolf, 2017/11/17
- [Qemu-block] [PULL 04/25] qcow2: don't permit changing encryption parameters, Kevin Wolf, 2017/11/17
- [Qemu-block] [PULL 03/25] block: Fix error path in bdrv_backing_update_filename(), Kevin Wolf, 2017/11/17
- [Qemu-block] [PULL 05/25] block: Deprecate bdrv_set_read_only() and users, Kevin Wolf, 2017/11/17
- [Qemu-block] [PULL 07/25] block: Fix permissions in image activation, Kevin Wolf, 2017/11/17
- [Qemu-block] [PULL 06/25] qcow2: fix image corruption after committing qcow2 image into base, Kevin Wolf, 2017/11/17
- [Qemu-block] [PULL 08/25] iotests: test clearing unknown autoclear_features by qcow2, Kevin Wolf, 2017/11/17
- [Qemu-block] [PULL 11/25] qapi/qlist: Add qlist_append_null() macro, Kevin Wolf, 2017/11/17
- [Qemu-block] [PULL 10/25] qapi/qnull: Add own header, Kevin Wolf, 2017/11/17
- [Qemu-block] [PULL 12/25] qapi: Add qobject_is_equal(), Kevin Wolf, 2017/11/17
- [Qemu-block] [PULL 13/25] block: qobject_is_equal() in bdrv_reopen_prepare(),
Kevin Wolf <=
- [Qemu-block] [PULL 09/25] qcow2: fix image corruption on commit with persistent bitmap, Kevin Wolf, 2017/11/17
- [Qemu-block] [PULL 14/25] iotests: Add test for non-string option reopening, Kevin Wolf, 2017/11/17
- [Qemu-block] [PULL 16/25] iotests: Add test for failing qemu-img commit, Kevin Wolf, 2017/11/17
- [Qemu-block] [PULL 19/25] qcow2: Unaligned zero cluster in handle_alloc(), Kevin Wolf, 2017/11/17
- [Qemu-block] [PULL 15/25] tests: Add check-qobject for equality tests, Kevin Wolf, 2017/11/17
- [Qemu-block] [PULL 17/25] qcow2: reject unaligned offsets in write compressed, Kevin Wolf, 2017/11/17
- [Qemu-block] [PULL 18/25] qcow2: check_errors are fatal, Kevin Wolf, 2017/11/17
- [Qemu-block] [PULL 23/25] qcow2: Fix overly broad madvise(), Kevin Wolf, 2017/11/17
- [Qemu-block] [PULL 20/25] block: Guard against NULL bs->drv, Kevin Wolf, 2017/11/17
- [Qemu-block] [PULL 22/25] qcow2: Refuse to get unaligned offsets from cache, Kevin Wolf, 2017/11/17