[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH 10/13] block: Add bdrv_reset_options_allowed()
From: |
Alberto Garcia |
Subject: |
[Qemu-devel] [PATCH 10/13] block: Add bdrv_reset_options_allowed() |
Date: |
Thu, 17 Jan 2019 17:34:01 +0200 |
bdrv_reopen_prepare() receives a BDRVReopenState with (among other
things) a new set of options to be applied to that BlockDriverState.
If an option is missing then it means that we want to reset it to its
default value rather than keep the previous one. This way the state
of the block device after being reopened is comparable to that of a
device added with "blockdev-add" using the same set of options.
Not all options from all drivers can be changed this way, however.
If the user attempts to reset an immutable option to its default value
using this method then we must forbid it.
This new function takes a QemuOptsList with the options of a block
driver and checks if there's any that was previously set but is
missing from the new set of options in the BDRVReopenState.
If the option is present in both sets we don't need to check that they
have the same value. The loop at the end of bdrv_reopen_prepare()
already takes care of that.
Signed-off-by: Alberto Garcia <address@hidden>
---
block.c | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 50 insertions(+)
diff --git a/block.c b/block.c
index 10847416b2..eea7aefa99 100644
--- a/block.c
+++ b/block.c
@@ -2909,6 +2909,43 @@ BlockDriverState *bdrv_open(const char *filename, const
char *reference,
}
/*
+ * For every option in @list, check that if it is set in the current
+ * set of options (@state->bs->options) then it is also set in the new
+ * set (@state->options). Options listed in @mutable_opts are skipped.
+ *
+ * @mutable_opts is either NULL or a NULL-terminated array of option
+ * names.
+ *
+ * Return 0 on success, -EINVAL otherwise.
+ */
+static int bdrv_reset_options_allowed(BDRVReopenState *state,
+ QemuOptsList *list,
+ const char *const mutable_opts[],
+ Error **errp)
+{
+ QemuOptDesc *desc = list->desc;
+ while (desc->name) {
+ unsigned i;
+ for (i = 0; mutable_opts != NULL && mutable_opts[i] != NULL; i++) {
+ if (!strcmp(desc->name, mutable_opts[i])) {
+ goto next;
+ }
+ }
+
+ if (!qdict_haskey(state->options, desc->name) &&
+ qdict_haskey(state->bs->options, desc->name)) {
+ error_setg(errp, "Option '%s' can't be reset to its default value",
+ desc->name);
+ return -EINVAL;
+ }
+ next:
+ desc++;
+ }
+
+ return 0;
+}
+
+/*
* Returns true if @child can be reached recursively from @bs
*/
static bool bdrv_recurse_has_child(BlockDriverState *bs,
@@ -3392,6 +3429,19 @@ int bdrv_reopen_prepare(BDRVReopenState *reopen_state,
BlockReopenQueue *queue,
}
if (drv->bdrv_reopen_prepare) {
+ /*
+ * If a driver-specific option is missing, it means that we
+ * should reset it to its default value.
+ * But not all options allow that, so we need to check it first.
+ */
+ if (drv->runtime_opts) {
+ ret = bdrv_reset_options_allowed(reopen_state, drv->runtime_opts,
+ drv->mutable_opts, errp);
+ if (ret) {
+ goto error;
+ }
+ }
+
ret = drv->bdrv_reopen_prepare(reopen_state, queue, &local_err);
if (ret) {
if (local_err != NULL) {
--
2.11.0
- [Qemu-devel] [PATCH 00/13] Add a 'x-blockdev-reopen' QMP command, Alberto Garcia, 2019/01/17
- [Qemu-devel] [PATCH 04/13] block: Freeze the backing chain for the duration of the stream job, Alberto Garcia, 2019/01/17
- [Qemu-devel] [PATCH 11/13] block: Remove the AioContext parameter from bdrv_reopen_multiple(), Alberto Garcia, 2019/01/17
- [Qemu-devel] [PATCH 03/13] block: Freeze the backing chain for the duration of the mirror job, Alberto Garcia, 2019/01/17
- [Qemu-devel] [PATCH 07/13] block: Allow omitting the 'backing' option in certain cases, Alberto Garcia, 2019/01/17
- [Qemu-devel] [PATCH 10/13] block: Add bdrv_reset_options_allowed(),
Alberto Garcia <=
- [Qemu-devel] [PATCH 08/13] block: Allow changing the backing file on reopen, Alberto Garcia, 2019/01/17
- [Qemu-devel] [PATCH 02/13] block: Freeze the backing chain for the duration of the commit job, Alberto Garcia, 2019/01/17
- [Qemu-devel] [PATCH 01/13] block: Allow freezing BdrvChild links, Alberto Garcia, 2019/01/17
- [Qemu-devel] [PATCH 06/13] block: Handle child references in bdrv_reopen_queue(), Alberto Garcia, 2019/01/17
- [Qemu-devel] [PATCH 12/13] block: Add an 'x-blockdev-reopen' QMP command, Alberto Garcia, 2019/01/17
- [Qemu-devel] [PATCH 09/13] block: Add 'runtime_opts' and 'mutable_opts' fields to BlockDriver, Alberto Garcia, 2019/01/17
- [Qemu-devel] [PATCH 05/13] block: Add 'keep_old_opts' parameter to bdrv_reopen_queue(), Alberto Garcia, 2019/01/17
- [Qemu-devel] [PATCH 13/13] qemu-iotests: Test the x-blockdev-reopen QMP command, Alberto Garcia, 2019/01/17
- Re: [Qemu-devel] [PATCH 00/13] Add a 'x-blockdev-reopen' QMP command, Eric Blake, 2019/01/17