From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:33401) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1X8Cq6-0006oc-IC for qemu-devel@nongnu.org; Fri, 18 Jul 2014 14:25:08 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1X8Cpy-0006RN-7S for qemu-devel@nongnu.org; Fri, 18 Jul 2014 14:25:02 -0400 Received: from mx1.redhat.com ([209.132.183.28]:17651) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1X8Cpx-0006RJ-PU for qemu-devel@nongnu.org; Fri, 18 Jul 2014 14:24:54 -0400 Received: from int-mx14.intmail.prod.int.phx2.redhat.com (int-mx14.intmail.prod.int.phx2.redhat.com [10.5.11.27]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id s6IIOruU005023 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Fri, 18 Jul 2014 14:24:53 -0400 From: Max Reitz Date: Fri, 18 Jul 2014 20:24:59 +0200 Message-Id: <1405707901-8253-5-git-send-email-mreitz@redhat.com> In-Reply-To: <1405707901-8253-1-git-send-email-mreitz@redhat.com> References: <1405707901-8253-1-git-send-email-mreitz@redhat.com> Subject: [Qemu-devel] [PATCH 4/6] nbd: Implement bdrv_refresh_filename() List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: Kevin Wolf , Stefan Hajnoczi , Max Reitz Signed-off-by: Max Reitz --- block/nbd.c | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/block/nbd.c b/block/nbd.c index 4eda095..89775e1 100644 --- a/block/nbd.c +++ b/block/nbd.c @@ -31,8 +31,10 @@ #include "block/block_int.h" #include "qemu/module.h" #include "qemu/sockets.h" +#include "qapi/qmp/qdict.h" #include "qapi/qmp/qjson.h" #include "qapi/qmp/qint.h" +#include "qapi/qmp/qstring.h" #include #include @@ -338,6 +340,37 @@ static void nbd_attach_aio_context(BlockDriverState *bs, nbd_client_session_attach_aio_context(&s->client, new_context); } +static void nbd_refresh_filename(BlockDriverState *bs) +{ + BDRVNBDState *s = bs->opaque; + QDict *opts = qdict_new(); + const char *path = qemu_opt_get(s->socket_opts, "path"); + const char *host = qemu_opt_get(s->socket_opts, "host"); + const char *port = qemu_opt_get(s->socket_opts, "port"); + const char *export = qemu_opt_get(s->socket_opts, "export"); + + qdict_put_obj(opts, "driver", QOBJECT(qstring_from_str("nbd"))); + + if (path) { + snprintf(bs->exact_filename, sizeof(bs->exact_filename), + "nbd+unix:%s", path); + qdict_put_obj(opts, "path", QOBJECT(qstring_from_str(path))); + } else if (export) { + snprintf(bs->exact_filename, sizeof(bs->exact_filename), + "nbd:%s:%s/%s", host, port, export); + qdict_put_obj(opts, "host", QOBJECT(qstring_from_str(host))); + qdict_put_obj(opts, "port", QOBJECT(qstring_from_str(port))); + qdict_put_obj(opts, "export", QOBJECT(qstring_from_str(export))); + } else { + snprintf(bs->exact_filename, sizeof(bs->exact_filename), + "nbd:%s:%s", host, port); + qdict_put_obj(opts, "host", QOBJECT(qstring_from_str(host))); + qdict_put_obj(opts, "port", QOBJECT(qstring_from_str(port))); + } + + bs->full_open_options = opts; +} + static BlockDriver bdrv_nbd = { .format_name = "nbd", .protocol_name = "nbd", @@ -352,6 +385,7 @@ static BlockDriver bdrv_nbd = { .bdrv_getlength = nbd_getlength, .bdrv_detach_aio_context = nbd_detach_aio_context, .bdrv_attach_aio_context = nbd_attach_aio_context, + .bdrv_refresh_filename = nbd_refresh_filename, }; static BlockDriver bdrv_nbd_tcp = { @@ -368,6 +402,7 @@ static BlockDriver bdrv_nbd_tcp = { .bdrv_getlength = nbd_getlength, .bdrv_detach_aio_context = nbd_detach_aio_context, .bdrv_attach_aio_context = nbd_attach_aio_context, + .bdrv_refresh_filename = nbd_refresh_filename, }; static BlockDriver bdrv_nbd_unix = { @@ -384,6 +419,7 @@ static BlockDriver bdrv_nbd_unix = { .bdrv_getlength = nbd_getlength, .bdrv_detach_aio_context = nbd_detach_aio_context, .bdrv_attach_aio_context = nbd_attach_aio_context, + .bdrv_refresh_filename = nbd_refresh_filename, }; static void bdrv_nbd_init(void) -- 2.0.1