From: Kevin Wolf <kwolf@redhat.com>
To: qemu-block@nongnu.org
Cc: kwolf@redhat.com, armbru@redhat.com, eblake@redhat.com,
mreitz@redhat.com, berrange@redhat.com, qemu-devel@nongnu.org
Subject: [Qemu-devel] [PATCH 1/3] block: Add '-blockdev' command line option
Date: Thu, 22 Sep 2016 17:42:09 +0200 [thread overview]
Message-ID: <1474558931-8968-2-git-send-email-kwolf@redhat.com> (raw)
In-Reply-To: <1474558931-8968-1-git-send-email-kwolf@redhat.com>
This is an option that is directly mapped to the blockdev-add QMP
command. It works more or less like -drive, except that it doesn't
create a BlockBackend and doesn't support legacy options.
This patch adds minimal documentation, the next patches will improve it.
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
---
blockdev.c | 12 +++++++++++
include/sysemu/sysemu.h | 1 +
qemu-options.hx | 12 +++++++++++
vl.c | 57 +++++++++++++++++++++++++++++++++++++++++++++++++
4 files changed, 82 insertions(+)
diff --git a/blockdev.c b/blockdev.c
index 76b86ab..5931383 100644
--- a/blockdev.c
+++ b/blockdev.c
@@ -4075,3 +4075,15 @@ QemuOptsList qemu_drive_opts = {
{ /* end of list */ }
},
};
+
+QemuOptsList qemu_blockdev_opts = {
+ .name = "blockdev",
+ .head = QTAILQ_HEAD_INITIALIZER(qemu_blockdev_opts.head),
+ .desc = {
+ /*
+ * no elements => accept any params
+ * validation will happen later
+ */
+ { /* end of list */ }
+ },
+};
diff --git a/include/sysemu/sysemu.h b/include/sysemu/sysemu.h
index ee7c760..1a2013a 100644
--- a/include/sysemu/sysemu.h
+++ b/include/sysemu/sysemu.h
@@ -238,6 +238,7 @@ bool defaults_enabled(void);
extern QemuOptsList qemu_legacy_drive_opts;
extern QemuOptsList qemu_common_drive_opts;
extern QemuOptsList qemu_drive_opts;
+extern QemuOptsList qemu_blockdev_opts;
extern QemuOptsList qemu_chardev_opts;
extern QemuOptsList qemu_device_opts;
extern QemuOptsList qemu_netdev_opts;
diff --git a/qemu-options.hx b/qemu-options.hx
index 0b621bb..542c483 100644
--- a/qemu-options.hx
+++ b/qemu-options.hx
@@ -513,6 +513,18 @@ Use @var{file} as CD-ROM image (you cannot use @option{-hdc} and
using @file{/dev/cdrom} as filename (@pxref{host_drives}).
ETEXI
+DEF("blockdev", HAS_ARG, QEMU_OPTION_blockdev,
+ "-blockdev driver=driver[,node-name=n][,read-only=on|off]\n"
+ " [,cache.direct=on|off][,cache.no-flush=on|off]\n"
+ " [,discard=ignore|unmap][,detect-zeroes=on|off|unmap]\n"
+ " [,...driver specific...]\n", QEMU_ARCH_ALL)
+STEXI
+@item -blockdev @var{option}[,@var{option}[,@var{option}[,...]]]
+@findex -blockdev
+
+Define a new block driver node.
+ETEXI
+
DEF("drive", HAS_ARG, QEMU_OPTION_drive,
"-drive [file=file][,if=type][,bus=n][,unit=m][,media=d][,index=i]\n"
" [,cyls=c,heads=h,secs=s[,trans=t]][,snapshot=on|off]\n"
diff --git a/vl.c b/vl.c
index fca0487..dbf7849 100644
--- a/vl.c
+++ b/vl.c
@@ -122,6 +122,9 @@ int main(int argc, char **argv)
#include "sysemu/replay.h"
#include "qapi/qmp/qerror.h"
#include "sysemu/iothread.h"
+#include "qapi-visit.h"
+#include "qapi/qobject-input-visitor.h"
+#include "qapi/dealloc-visitor.h"
#define MAX_VIRTIO_CONSOLES 1
#define MAX_SCLP_CONSOLES 1
@@ -1132,6 +1135,46 @@ static int cleanup_add_fd(void *opaque, QemuOpts *opts, Error **errp)
#define MTD_OPTS ""
#define SD_OPTS ""
+static int blockdev_init_func(void *opaque, QemuOpts *opts, Error **errp)
+{
+ BlockdevOptions *options;
+ Visitor *v = NULL;
+ Error *local_err = NULL;
+
+ QDict *opts_dict = qemu_opts_to_qdict(opts, NULL);
+ QObject *crumpled = qdict_crumple(opts_dict, true, &local_err);
+ if (local_err) {
+ goto fail;
+ }
+
+ v = qobject_string_input_visitor_new(crumpled);
+ visit_type_BlockdevOptions(v, NULL, &options, &local_err);
+ if (local_err) {
+ goto fail;
+ }
+ visit_complete(v, opts);
+
+ qmp_blockdev_add(options, &local_err);
+ if (local_err) {
+ goto fail;
+ }
+
+fail:
+ QDECREF(opts_dict);
+ qobject_decref(crumpled);
+
+ visit_free(v);
+
+ v = qapi_dealloc_visitor_new();
+ visit_type_BlockdevOptions(v, NULL, &options, NULL);
+ visit_free(v);
+
+ if (local_err) {
+ error_propagate(errp, local_err);
+ }
+ return !!local_err;
+}
+
static int drive_init_func(void *opaque, QemuOpts *opts, Error **errp)
{
BlockInterfaceType *block_default_type = opaque;
@@ -2990,6 +3033,7 @@ int main(int argc, char **argv, char **envp)
module_call_init(MODULE_INIT_QAPI);
qemu_add_opts(&qemu_drive_opts);
+ qemu_add_opts(&qemu_blockdev_opts);
qemu_add_drive_opts(&qemu_legacy_drive_opts);
qemu_add_drive_opts(&qemu_common_drive_opts);
qemu_add_drive_opts(&qemu_drive_opts);
@@ -3122,6 +3166,13 @@ int main(int argc, char **argv, char **envp)
exit(1);
}
break;
+ case QEMU_OPTION_blockdev:
+ opts = qemu_opts_parse_noisily(qemu_find_opts("blockdev"),
+ optarg, false);
+ if (opts == NULL) {
+ exit(1);
+ }
+ break;
case QEMU_OPTION_set:
if (qemu_set_option(optarg) != 0)
exit(1);
@@ -4409,6 +4460,12 @@ int main(int argc, char **argv, char **envp)
}
/* open the virtual block devices */
+ if (qemu_opts_foreach(qemu_find_opts("blockdev"), blockdev_init_func,
+ NULL, &err)) {
+ error_report_err(err);
+ exit(1);
+ }
+
if (snapshot || replay_mode != REPLAY_MODE_NONE) {
qemu_opts_foreach(qemu_find_opts("drive"), drive_enable_snapshot,
NULL, NULL);
--
1.8.3.1
next prev parent reply other threads:[~2016-09-22 15:42 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-09-22 15:42 [Qemu-devel] [PATCH 0/3] Add -blockdev command line option Kevin Wolf
2016-09-22 15:42 ` Kevin Wolf [this message]
2016-09-22 18:45 ` [Qemu-devel] [PATCH 1/3] block: Add '-blockdev' " Eric Blake
2016-09-23 9:37 ` Kevin Wolf
2016-09-23 14:09 ` Eric Blake
2016-09-22 15:42 ` [Qemu-devel] [PATCH 2/3] doc: Document generic -blockdev options Kevin Wolf
2016-09-22 18:56 ` Eric Blake
2016-09-22 15:42 ` [Qemu-devel] [PATCH 3/3] doc: Document driver-specific " Kevin Wolf
2016-09-22 19:02 ` Eric Blake
2016-09-23 9:46 ` Kevin Wolf
2016-09-22 17:12 ` [Qemu-devel] [PATCH 0/3] Add -blockdev command line option no-reply
2016-09-22 18:58 ` Eric Blake
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=1474558931-8968-2-git-send-email-kwolf@redhat.com \
--to=kwolf@redhat.com \
--cc=armbru@redhat.com \
--cc=berrange@redhat.com \
--cc=eblake@redhat.com \
--cc=mreitz@redhat.com \
--cc=qemu-block@nongnu.org \
--cc=qemu-devel@nongnu.org \
/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).