[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PULL 10/15] sheepdog: Fix blockdev-add
From: |
Max Reitz |
Subject: |
[Qemu-devel] [PULL 10/15] sheepdog: Fix blockdev-add |
Date: |
Mon, 3 Apr 2017 17:33:50 +0200 |
From: Markus Armbruster <address@hidden>
Commit 831acdc "sheepdog: Implement bdrv_parse_filename()" and commit
d282f34 "sheepdog: Support blockdev-add" have different ideas on how
the QemuOpts parameters for the server address are named. Fix that.
While there, rename BlockdevOptionsSheepdog member addr to server, for
consistency with BlockdevOptionsSsh, BlockdevOptionsGluster,
BlockdevOptionsNbd.
Commit 831acdc's example becomes
--drive
driver=sheepdog,server.type=inet,server.host=fido,server.port=7000,vdi=dolly
instead of
--drive driver=sheepdog,host=fido,vdi=dolly
Signed-off-by: Markus Armbruster <address@hidden>
Reviewed-by: Eric Blake <address@hidden>
Tested-by: Kashyap Chamarthy <address@hidden>
Message-id: address@hidden
Signed-off-by: Max Reitz <address@hidden>
---
qapi/block-core.json | 4 +--
block/sheepdog.c | 90 +++++++++++++++++++++++++++++++++-------------------
2 files changed, 60 insertions(+), 34 deletions(-)
diff --git a/qapi/block-core.json b/qapi/block-core.json
index e4d8a63575..033457ce86 100644
--- a/qapi/block-core.json
+++ b/qapi/block-core.json
@@ -2623,7 +2623,7 @@
# Driver specific block device options for sheepdog
#
# @vdi: Virtual disk image name
-# @addr: The Sheepdog server to connect to
+# @server: The Sheepdog server to connect to
# @snap-id: Snapshot ID
# @tag: Snapshot tag name
#
@@ -2632,7 +2632,7 @@
# Since: 2.9
##
{ 'struct': 'BlockdevOptionsSheepdog',
- 'data': { 'addr': 'SocketAddressFlat',
+ 'data': { 'server': 'SocketAddressFlat',
'vdi': 'str',
'*snap-id': 'uint32',
'*tag': 'str' } }
diff --git a/block/sheepdog.c b/block/sheepdog.c
index 89e98edab6..1b71fc81ec 100644
--- a/block/sheepdog.c
+++ b/block/sheepdog.c
@@ -13,9 +13,11 @@
*/
#include "qemu/osdep.h"
+#include "qapi-visit.h"
#include "qapi/error.h"
#include "qapi/qmp/qdict.h"
#include "qapi/qmp/qint.h"
+#include "qapi/qobject-input-visitor.h"
#include "qemu/uri.h"
#include "qemu/error-report.h"
#include "qemu/sockets.h"
@@ -547,6 +549,47 @@ static SocketAddress *sd_socket_address(const char *path,
return addr;
}
+static SocketAddress *sd_server_config(QDict *options, Error **errp)
+{
+ QDict *server = NULL;
+ QObject *crumpled_server = NULL;
+ Visitor *iv = NULL;
+ SocketAddressFlat *saddr_flat = NULL;
+ SocketAddress *saddr = NULL;
+ Error *local_err = NULL;
+
+ qdict_extract_subqdict(options, &server, "server.");
+
+ crumpled_server = qdict_crumple(server, errp);
+ if (!crumpled_server) {
+ goto done;
+ }
+
+ /*
+ * FIXME .numeric, .to, .ipv4 or .ipv6 don't work with -drive
+ * server.type=inet. .to doesn't matter, it's ignored anyway.
+ * That's because when @options come from -blockdev or
+ * blockdev_add, members are typed according to the QAPI schema,
+ * but when they come from -drive, they're all QString. The
+ * visitor expects the former.
+ */
+ iv = qobject_input_visitor_new(crumpled_server);
+ visit_type_SocketAddressFlat(iv, NULL, &saddr_flat, &local_err);
+ if (local_err) {
+ error_propagate(errp, local_err);
+ goto done;
+ }
+
+ saddr = socket_address_crumple(saddr_flat);
+
+done:
+ qapi_free_SocketAddressFlat(saddr_flat);
+ visit_free(iv);
+ qobject_decref(crumpled_server);
+ QDECREF(server);
+ return saddr;
+}
+
/* Return -EIO in case of error, file descriptor on success */
static int connect_to_sdog(BDRVSheepdogState *s, Error **errp)
{
@@ -1174,15 +1217,15 @@ static void sd_parse_filename(const char *filename,
QDict *options,
return;
}
- if (cfg.host) {
- qdict_set_default_str(options, "host", cfg.host);
- }
- if (cfg.port) {
- snprintf(buf, sizeof(buf), "%d", cfg.port);
- qdict_set_default_str(options, "port", buf);
- }
if (cfg.path) {
- qdict_set_default_str(options, "path", cfg.path);
+ qdict_set_default_str(options, "server.path", cfg.path);
+ qdict_set_default_str(options, "server.type", "unix");
+ } else {
+ qdict_set_default_str(options, "server.type", "inet");
+ qdict_set_default_str(options, "server.host",
+ cfg.host ?: SD_DEFAULT_ADDR);
+ snprintf(buf, sizeof(buf), "%d", cfg.port ?: SD_DEFAULT_PORT);
+ qdict_set_default_str(options, "server.port", buf);
}
qdict_set_default_str(options, "vdi", cfg.vdi);
qdict_set_default_str(options, "tag", cfg.tag);
@@ -1510,18 +1553,6 @@ static QemuOptsList runtime_opts = {
.head = QTAILQ_HEAD_INITIALIZER(runtime_opts.head),
.desc = {
{
- .name = "host",
- .type = QEMU_OPT_STRING,
- },
- {
- .name = "port",
- .type = QEMU_OPT_STRING,
- },
- {
- .name = "path",
- .type = QEMU_OPT_STRING,
- },
- {
.name = "vdi",
.type = QEMU_OPT_STRING,
},
@@ -1543,7 +1574,7 @@ static int sd_open(BlockDriverState *bs, QDict *options,
int flags,
int ret, fd;
uint32_t vid = 0;
BDRVSheepdogState *s = bs->opaque;
- const char *host, *port, *path, *vdi, *snap_id_str, *tag;
+ const char *vdi, *snap_id_str, *tag;
uint64_t snap_id;
char *buf = NULL;
QemuOpts *opts;
@@ -1560,20 +1591,17 @@ static int sd_open(BlockDriverState *bs, QDict
*options, int flags,
goto err_no_fd;
}
- host = qemu_opt_get(opts, "host");
- port = qemu_opt_get(opts, "port");
- path = qemu_opt_get(opts, "path");
+ s->addr = sd_server_config(options, errp);
+ if (!s->addr) {
+ ret = -EINVAL;
+ goto err_no_fd;
+ }
+
vdi = qemu_opt_get(opts, "vdi");
snap_id_str = qemu_opt_get(opts, "snap-id");
snap_id = qemu_opt_get_number(opts, "snap-id", CURRENT_VDI_ID);
tag = qemu_opt_get(opts, "tag");
- if ((host || port) && path) {
- error_setg(errp, "can't use 'path' together with 'host' or 'port'");
- ret = -EINVAL;
- goto err_no_fd;
- }
-
if (!vdi) {
error_setg(errp, "parameter 'vdi' is missing");
ret = -EINVAL;
@@ -1604,8 +1632,6 @@ static int sd_open(BlockDriverState *bs, QDict *options,
int flags,
goto err_no_fd;
}
- s->addr = sd_socket_address(path, host, port);
-
QLIST_INIT(&s->inflight_aio_head);
QLIST_INIT(&s->failed_aio_head);
QLIST_INIT(&s->inflight_aiocb_head);
--
2.12.1
- [Qemu-devel] [PULL 02/15] nbd sockets vnc: Mark problematic address family tests TODO, (continued)
- [Qemu-devel] [PULL 02/15] nbd sockets vnc: Mark problematic address family tests TODO, Max Reitz, 2017/04/03
- [Qemu-devel] [PULL 01/15] block: add missed aio_context_acquire into release_drive, Max Reitz, 2017/04/03
- [Qemu-devel] [PULL 03/15] char: Fix socket with "type": "vsock" address, Max Reitz, 2017/04/03
- [Qemu-devel] [PULL 04/15] io vnc sockets: Clean up SocketAddressKind switches, Max Reitz, 2017/04/03
- [Qemu-devel] [PULL 05/15] block: Document -drive problematic code and bugs, Max Reitz, 2017/04/03
- [Qemu-devel] [PULL 06/15] gluster: Prepare for SocketAddressFlat extension, Max Reitz, 2017/04/03
- [Qemu-devel] [PULL 07/15] qapi-schema: SocketAddressFlat variants 'vsock' and 'fd', Max Reitz, 2017/04/03
- [Qemu-devel] [PULL 08/15] sockets: New helper socket_address_crumple(), Max Reitz, 2017/04/03
- [Qemu-devel] [PULL 09/15] nbd: Tidy up blockdev-add interface, Max Reitz, 2017/04/03
- [Qemu-devel] [PULL 11/15] qemu-io-cmds: Assert that global and nofile commands don't use ct->perms, Max Reitz, 2017/04/03
- [Qemu-devel] [PULL 10/15] sheepdog: Fix blockdev-add,
Max Reitz <=
- [Qemu-devel] [PULL 13/15] qcow2: Discard unaligned tail when wiping image, Max Reitz, 2017/04/03
- [Qemu-devel] [PULL 12/15] iotests: fix 097 when run with qcow, Max Reitz, 2017/04/03
- [Qemu-devel] [PULL 15/15] block/parallels: Avoid overflows, Max Reitz, 2017/04/03
- [Qemu-devel] [PULL 14/15] iotests: Improve image-clear tests on non-aligned image, Max Reitz, 2017/04/03
- Re: [Qemu-devel] [PULL 00/15] Block patches for rc3, Peter Maydell, 2017/04/03