|
|
9ae3a8 |
From c2eb29efe61ffe88d3aff449446a9ac0f0f045a5 Mon Sep 17 00:00:00 2001
|
|
|
9ae3a8 |
From: Richard Jones <rjones@redhat.com>
|
|
|
9ae3a8 |
Date: Tue, 2 Jun 2015 09:46:37 +0200
|
|
|
9ae3a8 |
Subject: [PATCH 3/4] block: Allow JSON filenames
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
Message-id: <1433238397-2500-3-git-send-email-rjones@redhat.com>
|
|
|
9ae3a8 |
Patchwork-id: 65279
|
|
|
9ae3a8 |
O-Subject: [RHEL-7.2 qemu-kvm PATCH 2/2] block: Allow JSON filenames
|
|
|
9ae3a8 |
Bugzilla: 1226697
|
|
|
9ae3a8 |
RH-Acked-by: Miroslav Rezanina <mrezanin@redhat.com>
|
|
|
9ae3a8 |
RH-Acked-by: Stefan Hajnoczi <stefanha@redhat.com>
|
|
|
9ae3a8 |
RH-Acked-by: Max Reitz <mreitz@redhat.com>
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
From: Max Reitz <mreitz@redhat.com>
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
If the filename given to bdrv_open() is prefixed with "json:", parse the
|
|
|
9ae3a8 |
rest as a JSON object and merge the result into the options QDict. If
|
|
|
9ae3a8 |
there are conflicts, the options QDict takes precedence.
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
Signed-off-by: Max Reitz <mreitz@redhat.com>
|
|
|
9ae3a8 |
Reviewed-by: Eric Blake <eblake@redhat.com>
|
|
|
9ae3a8 |
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
|
|
|
9ae3a8 |
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
|
|
|
9ae3a8 |
---
|
|
|
9ae3a8 |
block.c | 41 +++++++++++++++++++++++++++++++++++++++++
|
|
|
9ae3a8 |
1 file changed, 41 insertions(+)
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
diff --git a/block.c b/block.c
|
|
|
9ae3a8 |
index 45543d5..f2caf20 100644
|
|
|
9ae3a8 |
--- a/block.c
|
|
|
9ae3a8 |
+++ b/block.c
|
|
|
9ae3a8 |
@@ -1085,6 +1085,33 @@ static void extract_subqdict(QDict *src, QDict **dst, const char *start)
|
|
|
9ae3a8 |
}
|
|
|
9ae3a8 |
}
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
+static QDict *parse_json_filename(const char *filename, Error **errp)
|
|
|
9ae3a8 |
+{
|
|
|
9ae3a8 |
+ QObject *options_obj;
|
|
|
9ae3a8 |
+ QDict *options;
|
|
|
9ae3a8 |
+ int ret;
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
+ ret = strstart(filename, "json:", &filename);
|
|
|
9ae3a8 |
+ assert(ret);
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
+ options_obj = qobject_from_json(filename);
|
|
|
9ae3a8 |
+ if (!options_obj) {
|
|
|
9ae3a8 |
+ error_setg(errp, "Could not parse the JSON options");
|
|
|
9ae3a8 |
+ return NULL;
|
|
|
9ae3a8 |
+ }
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
+ if (qobject_type(options_obj) != QTYPE_QDICT) {
|
|
|
9ae3a8 |
+ qobject_decref(options_obj);
|
|
|
9ae3a8 |
+ error_setg(errp, "Invalid JSON object given");
|
|
|
9ae3a8 |
+ return NULL;
|
|
|
9ae3a8 |
+ }
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
+ options = qobject_to_qdict(options_obj);
|
|
|
9ae3a8 |
+ qdict_flatten(options);
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
+ return options;
|
|
|
9ae3a8 |
+}
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
/*
|
|
|
9ae3a8 |
* Opens a disk image (raw, qcow2, vmdk, ...)
|
|
|
9ae3a8 |
*
|
|
|
9ae3a8 |
@@ -1109,6 +1136,20 @@ int bdrv_open(BlockDriverState *bs, const char *filename, QDict *options,
|
|
|
9ae3a8 |
options = qdict_new();
|
|
|
9ae3a8 |
}
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
+ if (filename && g_str_has_prefix(filename, "json:")) {
|
|
|
9ae3a8 |
+ QDict *json_options = parse_json_filename(filename, &local_err);
|
|
|
9ae3a8 |
+ if (local_err) {
|
|
|
9ae3a8 |
+ ret = -EINVAL;
|
|
|
9ae3a8 |
+ goto fail;
|
|
|
9ae3a8 |
+ }
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
+ /* Options given in the filename have lower priority than options
|
|
|
9ae3a8 |
+ * specified directly */
|
|
|
9ae3a8 |
+ qdict_join(options, json_options, false);
|
|
|
9ae3a8 |
+ QDECREF(json_options);
|
|
|
9ae3a8 |
+ filename = NULL;
|
|
|
9ae3a8 |
+ }
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
bs->options = options;
|
|
|
9ae3a8 |
options = qdict_clone_shallow(options);
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
--
|
|
|
9ae3a8 |
1.8.3.1
|
|
|
9ae3a8 |
|