[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-block] [PATCH v3 12/21] block: Split out parse_json_protocol()
From: |
Kevin Wolf |
Subject: |
[Qemu-block] [PATCH v3 12/21] block: Split out parse_json_protocol() |
Date: |
Fri, 4 Dec 2015 14:35:15 +0100 |
The next patch distinguishes options that were explicitly set and
options that were derived. bdrv_fill_option() added options of both
types: Options given by json: syntax should be counted as explicit, but
the rest is derived.
In preparation for the distinction, move json: parse to a separate
function.
Signed-off-by: Kevin Wolf <address@hidden>
Reviewed-by: Max Reitz <address@hidden>
---
block.c | 50 ++++++++++++++++++++++++++++++++------------------
1 file changed, 32 insertions(+), 18 deletions(-)
diff --git a/block.c b/block.c
index 5b0183e..8ac1669 100644
--- a/block.c
+++ b/block.c
@@ -1018,37 +1018,45 @@ static QDict *parse_json_filename(const char *filename,
Error **errp)
return options;
}
+static void parse_json_protocol(QDict *options, const char **pfilename,
+ Error **errp)
+{
+ QDict *json_options;
+ Error *local_err = NULL;
+
+ /* Parse json: pseudo-protocol */
+ if (!*pfilename || !g_str_has_prefix(*pfilename, "json:")) {
+ return;
+ }
+
+ json_options = parse_json_filename(*pfilename, &local_err);
+ if (local_err) {
+ error_propagate(errp, local_err);
+ return;
+ }
+
+ /* Options given in the filename have lower priority than options
+ * specified directly */
+ qdict_join(options, json_options, false);
+ QDECREF(json_options);
+ *pfilename = NULL;
+}
+
/*
* Fills in default options for opening images and converts the legacy
* filename/flags pair to option QDict entries.
* The BDRV_O_PROTOCOL flag in *flags will be set or cleared accordingly if a
* block driver has been specified explicitly.
*/
-static int bdrv_fill_options(QDict **options, const char **pfilename,
+static int bdrv_fill_options(QDict **options, const char *filename,
int *flags, Error **errp)
{
- const char *filename = *pfilename;
const char *drvname;
bool protocol = *flags & BDRV_O_PROTOCOL;
bool parse_filename = false;
BlockDriver *drv = NULL;
Error *local_err = NULL;
- /* Parse json: pseudo-protocol */
- if (filename && g_str_has_prefix(filename, "json:")) {
- QDict *json_options = parse_json_filename(filename, &local_err);
- if (local_err) {
- error_propagate(errp, local_err);
- return -EINVAL;
- }
-
- /* Options given in the filename have lower priority than options
- * specified directly */
- qdict_join(*options, json_options, false);
- QDECREF(json_options);
- *pfilename = filename = NULL;
- }
-
drvname = qdict_get_try_str(*options, "driver");
if (drvname) {
drv = bdrv_find_format(drvname);
@@ -1487,13 +1495,19 @@ static int bdrv_open_inherit(BlockDriverState **pbs,
const char *filename,
options = qdict_new();
}
+ parse_json_protocol(options, &filename, &local_err);
+ if (local_err) {
+ ret = -EINVAL;
+ goto fail;
+ }
+
if (child_role) {
bs->inherits_from = parent;
child_role->inherit_options(&flags, options,
parent->open_flags, parent->options);
}
- ret = bdrv_fill_options(&options, &filename, &flags, &local_err);
+ ret = bdrv_fill_options(&options, filename, &flags, &local_err);
if (local_err) {
goto fail;
}
--
1.8.3.1
- [Qemu-block] [PATCH v3 05/21] block: Consider all block layer options in append_open_options, (continued)
- [Qemu-block] [PATCH v3 05/21] block: Consider all block layer options in append_open_options, Kevin Wolf, 2015/12/04
- [Qemu-block] [PATCH v3 06/21] block: Exclude nested options only for children in append_open_options(), Kevin Wolf, 2015/12/04
- [Qemu-block] [PATCH v3 07/21] block: Pass driver-specific options to .bdrv_refresh_filename(), Kevin Wolf, 2015/12/04
- [Qemu-block] [PATCH v3 09/21] block: Allow specifying child options in reopen, Kevin Wolf, 2015/12/04
- [Qemu-block] [PATCH v3 10/21] block: reopen: Document option precedence and refactor accordingly, Kevin Wolf, 2015/12/04
- [Qemu-block] [PATCH v3 08/21] block: Keep "driver" in bs->options, Kevin Wolf, 2015/12/04
- [Qemu-block] [PATCH v3 11/21] block: Add infrastructure for option inheritance, Kevin Wolf, 2015/12/04
- [Qemu-block] [PATCH v3 13/21] block: Introduce bs->explicit_options, Kevin Wolf, 2015/12/04
- [Qemu-block] [PATCH v3 12/21] block: Split out parse_json_protocol(),
Kevin Wolf <=
- [Qemu-block] [PATCH v3 14/21] blockdev: Set 'format' indicates non-empty drive, Kevin Wolf, 2015/12/04
- [Qemu-block] [PATCH v3 15/21] qemu-iotests: Remove cache mode test without medium, Kevin Wolf, 2015/12/04
- [Qemu-block] [PATCH v3 16/21] block: reopen: Extract QemuOpts for generic block layer options, Kevin Wolf, 2015/12/04
- [Qemu-block] [PATCH v3 18/21] blkdebug: Enable reopen, Kevin Wolf, 2015/12/04
- [Qemu-block] [PATCH v3 17/21] block: Move cache options into options QDict, Kevin Wolf, 2015/12/04
- [Qemu-block] [PATCH v3 19/21] qemu-iotests: Try setting cache mode for children, Kevin Wolf, 2015/12/04
- [Qemu-block] [PATCH v3 21/21] qemu-iotests: Test reopen with node-name/driver options, Kevin Wolf, 2015/12/04
- [Qemu-block] [PATCH v3 20/21] qemu-iotests: Test cache mode option inheritance, Kevin Wolf, 2015/12/04