From: Luiz Capitulino <lcapitulino@redhat.com>
To: Paolo Bonzini <pbonzini@redhat.com>
Cc: kwolf@redhat.com, stefanha@gmail.com, qemu-devel@nongnu.org
Subject: Re: [Qemu-devel] [RFC PATCH 11/13] hmp: add NBD server commands
Date: Tue, 18 Sep 2012 17:22:11 -0300 [thread overview]
Message-ID: <20120918172211.38ee17d2@doriath.home> (raw)
In-Reply-To: <1346079626-16386-12-git-send-email-pbonzini@redhat.com>
On Mon, 27 Aug 2012 17:00:24 +0200
Paolo Bonzini <pbonzini@redhat.com> wrote:
> At the HMP level there is no nbd_server_add command. nbd_server_start
> automatically exposes all of the VM's block devices, and an option -w
> makes them writable.
>
> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
> ---
> hmp-commands.hx | 29 +++++++++++++++++++++++++
> hmp.c | 66 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++
> hmp.h | 2 ++
> 3 file modificati, 97 inserzioni(+)
>
> diff --git a/hmp-commands.hx b/hmp-commands.hx
> index f6104b0..cabb886 100644
> --- a/hmp-commands.hx
> +++ b/hmp-commands.hx
> @@ -1248,6 +1248,35 @@ Remove all matches from the access control list, and set the default
> policy back to @code{deny}.
> ETEXI
>
> + {
> + .name = "nbd_server_start",
> + .args_type = "writable:-w,uri:s",
> + .params = "nbd_server_start [-w] host:port",
> + .help = "serve block devices on the given host and port",
> + .mhandler.cmd = hmp_nbd_server_start,
> + },
> +STEXI
> +@item nbd_server_start @var{host}:@var{port}
> +@findex nbd_server_start
> +Start an NBD server on the given host and/or port, and serve all of the
> +virtual machine's block devices that have an inserted media on it.
> +The @option{-w} option makes the devices writable.
> +ETEXI
> +
> + {
> + .name = "nbd_server_stop",
> + .args_type = "",
> + .params = "nbd_server_stop",
> + .help = "stop serving block devices using the NBD protocol",
> + .mhandler.cmd = hmp_nbd_server_stop,
> + },
> +STEXI
> +@item nbd_server_stop
> +@findex nbd_server_stop
> +Stop the QEMU embedded NBD server.
> +ETEXI
> +
> +
> #if defined(TARGET_I386)
>
> {
> diff --git a/hmp.c b/hmp.c
> index a9d5675..10ff50d 100644
> --- a/hmp.c
> +++ b/hmp.c
> @@ -18,6 +18,7 @@
> #include "qemu-option.h"
> #include "qemu-timer.h"
> #include "qmp-commands.h"
> +#include "qemu_socket.h"
> #include "monitor.h"
>
> static void hmp_handle_error(Monitor *mon, Error **errp)
> @@ -1102,3 +1103,68 @@ void hmp_closefd(Monitor *mon, const QDict *qdict)
> qmp_closefd(fdname, &errp);
> hmp_handle_error(mon, &errp);
> }
> +
> +void hmp_nbd_server_start(Monitor *mon, const QDict *qdict)
> +{
> + const char *uri = qdict_get_str(qdict, "uri");
> + int writable = qdict_get_try_bool(qdict, "writable", 0);
> + Error *errp = NULL;
> + QemuOpts *opts;
> + BlockDriverState *bs;
> + IPSocketAddress addr;
> +
> + /* First check if the address is available and start the server. */
> + opts = qemu_opts_create(&socket_opts, NULL, 0, NULL);
> + if (inet_parse(opts, uri) != 0) {
> + error_set(&errp, QERR_SOCKET_CREATE_FAILED);
> + goto exit;
> + }
> +
> + memset(&addr, 0, sizeof(addr));
> + addr.host = (char *) qemu_opt_get(opts, "host");
> + addr.port = (char *) qemu_opt_get(opts, "port");
> + addr.ipv4 = qemu_opt_get_bool(opts, "ipv4", 0);
> + addr.ipv6 = qemu_opt_get_bool(opts, "ipv6", 0);
> + addr.has_ipv4 = addr.has_ipv6 = true;
> +
> + if (addr.host == NULL || addr.port == NULL) {
> + error_set(&errp, QERR_SOCKET_CREATE_FAILED);
You can and should use monitor_printf() directly.
> + goto exit;
> + }
> +
> + qmp_nbd_server_start(&addr, &errp);
> + if (errp != NULL) {
Please, use error_is_set() instead.
> + goto exit;
> + }
> +
> + /* Then try adding all block devices. If one fails, close all and
> + * exit.
> + */
> + bs = NULL;
> + while ((bs = bdrv_next(bs))) {
To keep hmp.c an honest qmp client, you should use qmp_query_block() instead
of looping through BSs directly. You'll find other examples if you find for
qmp_query_block() in this file.
> + if (!bdrv_is_inserted(bs)) {
> + continue;
> + }
> +
> + qmp_nbd_server_add(bdrv_get_device_name(bs),
> + true, !bdrv_is_read_only(bs) && writable,
> + &errp);
> +
> + if (errp != NULL) {
> + qmp_nbd_server_stop(NULL);
> + break;
> + }
> + }
> +
> +exit:
> + qemu_opts_del(opts);
> + hmp_handle_error(mon, &errp);
> +}
> +
> +void hmp_nbd_server_stop(Monitor *mon, const QDict *qdict)
> +{
> + Error *errp = NULL;
> +
> + qmp_nbd_server_stop(&errp);
> + hmp_handle_error(mon, &errp);
> +}
> diff --git a/hmp.h b/hmp.h
> index 7dd93bf..89d3960 100644
> --- a/hmp.h
> +++ b/hmp.h
> @@ -71,5 +71,7 @@ void hmp_netdev_add(Monitor *mon, const QDict *qdict);
> void hmp_netdev_del(Monitor *mon, const QDict *qdict);
> void hmp_getfd(Monitor *mon, const QDict *qdict);
> void hmp_closefd(Monitor *mon, const QDict *qdict);
> +void hmp_nbd_server_start(Monitor *mon, const QDict *qdict);
> +void hmp_nbd_server_stop(Monitor *mon, const QDict *qdict);
>
> #endif
next prev parent reply other threads:[~2012-09-18 20:21 UTC|newest]
Thread overview: 28+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-08-27 15:00 [Qemu-devel] [RFC PATCH 00/13] Embedded NBD server Paolo Bonzini
2012-08-27 15:00 ` [Qemu-devel] [RFC PATCH 01/13] nbd: add more constants Paolo Bonzini
2012-08-27 15:00 ` [Qemu-devel] [RFC PATCH 02/13] nbd: pass NBDClient to nbd_send_negotiate Paolo Bonzini
2012-08-27 15:00 ` [Qemu-devel] [RFC PATCH 03/13] nbd: do not leak nbd_trip coroutines when a connection is torn down Paolo Bonzini
2012-08-27 15:00 ` [Qemu-devel] [RFC PATCH 04/13] nbd: close all clients on deleting export Paolo Bonzini
2012-08-27 15:00 ` [Qemu-devel] [RFC PATCH 05/13] nbd: register named exports Paolo Bonzini
2012-08-27 15:00 ` [Qemu-devel] [RFC PATCH 06/13] nbd: negotiate with " Paolo Bonzini
2012-08-27 15:00 ` [Qemu-devel] [RFC PATCH 07/13] nbd: do not close BlockDriverState in nbd_export_close Paolo Bonzini
2012-08-27 15:00 ` [Qemu-devel] [RFC PATCH 08/13] qemu-sockets: publish dummy_opts Paolo Bonzini
2012-08-27 15:00 ` [Qemu-devel] [RFC PATCH 09/13] qmp: add NBD server commands Paolo Bonzini
2012-09-18 20:11 ` Luiz Capitulino
2012-09-19 8:16 ` Paolo Bonzini
2012-08-27 15:00 ` [Qemu-devel] [RFC PATCH 10/13] qemu-sockets: make inet_parse public Paolo Bonzini
2012-08-27 15:00 ` [Qemu-devel] [RFC PATCH 11/13] hmp: add NBD server commands Paolo Bonzini
2012-09-18 20:22 ` Luiz Capitulino [this message]
2012-09-19 8:00 ` Paolo Bonzini
2012-08-27 15:00 ` [Qemu-devel] [RFC PATCH 12/13] block: add close notifiers Paolo Bonzini
2012-08-27 15:00 ` [Qemu-devel] [RFC PATCH 13/13] nbd: add notifier to close exports when the image is closed Paolo Bonzini
2012-09-07 15:50 ` [Qemu-devel] ping Re: [RFC PATCH 00/13] Embedded NBD server Paolo Bonzini
2012-09-07 16:11 ` Kevin Wolf
2012-09-17 16:43 ` Paolo Bonzini
2012-09-18 8:45 ` Kevin Wolf
2012-09-18 9:09 ` Paolo Bonzini
2012-09-18 9:40 ` Kevin Wolf
2012-09-18 9:48 ` Paolo Bonzini
2012-09-18 9:55 ` Kevin Wolf
2012-09-19 10:16 ` [Qemu-devel] " Daniel P. Berrange
2012-09-19 10:22 ` Paolo Bonzini
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20120918172211.38ee17d2@doriath.home \
--to=lcapitulino@redhat.com \
--cc=kwolf@redhat.com \
--cc=pbonzini@redhat.com \
--cc=qemu-devel@nongnu.org \
--cc=stefanha@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).