[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[RFC PATCH 08/18] qemu-storage-daemon: Add --export option
From: |
Kevin Wolf |
Subject: |
[RFC PATCH 08/18] qemu-storage-daemon: Add --export option |
Date: |
Thu, 17 Oct 2019 15:01:54 +0200 |
Add a --export option to qemu-storage-daemon to export a block node. For
now, only NBD exports are implemented. Apart from the 'type' option
(which is the implied key), it maps the arguments for nbd-server-add to
the command line. Example:
--export nbd,device=disk,name=test-export,writable=on
Signed-off-by: Kevin Wolf <address@hidden>
---
qapi/block.json | 27 +++++++++++++++++++++++++++
qemu-storage-daemon.c | 31 +++++++++++++++++++++++++++++++
2 files changed, 58 insertions(+)
diff --git a/qapi/block.json b/qapi/block.json
index 567f116875..d9b1f16fbf 100644
--- a/qapi/block.json
+++ b/qapi/block.json
@@ -481,3 +481,30 @@
{ 'event': 'QUORUM_REPORT_BAD',
'data': { 'type': 'QuorumOpType', '*error': 'str', 'node-name': 'str',
'sector-num': 'int', 'sectors-count': 'int' } }
+
+##
+# @BlockExportType:
+#
+# An enumeration of block export types
+#
+# @nbd: NBD export
+#
+# Since: 4.2
+##
+{ 'enum': 'BlockExportType',
+ 'data': [ 'nbd' ] }
+
+##
+# @BlockExport:
+#
+# Describes a block export, i.e. how single node should be exported on an
+# external interface.
+#
+# Since: 4.2
+##
+{ 'union': 'BlockExport',
+ 'base': { 'type': 'BlockExportType' },
+ 'discriminator': 'type',
+ 'data': {
+ 'nbd': 'BlockExportNbd'
+ } }
diff --git a/qemu-storage-daemon.c b/qemu-storage-daemon.c
index 51882452f3..9e5f474fd0 100644
--- a/qemu-storage-daemon.c
+++ b/qemu-storage-daemon.c
@@ -67,6 +67,11 @@ static void help(void)
" [,driver specific parameters...]\n"
" configure a block backend\n"
"\n"
+" --export [type=]nbd,device=<node-name>[,name=<export-name>]\n"
+" [,writable=on|off][,bitmap=<name>]\n"
+" export the specified block node over NBD\n"
+" (requires --nbd-server)\n"
+"\n"
" --nbd-server addr.type=inet,addr.host=<host>,addr.port=<port>\n"
" [,tls-creds=<id>][,tls-authz=<id>]\n"
" --nbd-server addr.type=unix,addr.path=<path>\n"
@@ -84,6 +89,7 @@ enum {
OPTION_OBJECT = 256,
OPTION_BLOCKDEV,
OPTION_NBD_SERVER,
+ OPTION_EXPORT,
};
static QemuOptsList qemu_object_opts = {
@@ -95,6 +101,17 @@ static QemuOptsList qemu_object_opts = {
},
};
+static void init_export(BlockExport *export, Error **errp)
+{
+ switch (export->type) {
+ case BLOCK_EXPORT_TYPE_NBD:
+ qmp_nbd_server_add(&export->u.nbd, errp);
+ break;
+ default:
+ g_assert_not_reached();
+ }
+}
+
static int process_options(int argc, char *argv[], Error **errp)
{
int c;
@@ -106,6 +123,7 @@ static int process_options(int argc, char *argv[], Error
**errp)
{"object", required_argument, 0, OPTION_OBJECT},
{"blockdev", required_argument, 0, OPTION_BLOCKDEV},
{"nbd-server", required_argument, 0, OPTION_NBD_SERVER},
+ {"export", required_argument, 0, OPTION_EXPORT},
{"version", no_argument, 0, 'V'},
{"trace", required_argument, NULL, 'T'},
{0, 0, 0, 0}
@@ -176,6 +194,19 @@ static int process_options(int argc, char *argv[], Error
**errp)
qapi_free_NbdServerOptions(options);
break;
}
+ case OPTION_EXPORT:
+ {
+ Visitor *v;
+ BlockExport *export;
+
+ v = qobject_input_visitor_new_str(optarg, "type",
&error_fatal);
+ visit_type_BlockExport(v, NULL, &export, &error_fatal);
+ visit_free(v);
+
+ init_export(export, &error_fatal);
+ qapi_free_BlockExport(export);
+ break;
+ }
}
}
if (optind != argc) {
--
2.20.1
- [RFC PATCH 00/18] Add qemu-storage-daemon, Kevin Wolf, 2019/10/17
- [RFC PATCH 01/18] qemu-storage-daemon: Add barebone tool, Kevin Wolf, 2019/10/17
- [RFC PATCH 02/18] qemu-storage-daemon: Add --object option, Kevin Wolf, 2019/10/17
- [RFC PATCH 05/18] qemu-storage-daemon: Add --blockdev option, Kevin Wolf, 2019/10/17
- [RFC PATCH 03/18] stubs: Add arch_type, Kevin Wolf, 2019/10/17
- [RFC PATCH 04/18] stubs: Add blk_by_qdev_id(), Kevin Wolf, 2019/10/17
- [RFC PATCH 06/18] qemu-storage-daemon: Add --nbd-server option, Kevin Wolf, 2019/10/17
- [RFC PATCH 08/18] qemu-storage-daemon: Add --export option,
Kevin Wolf <=
- [RFC PATCH 11/18] monitor: Move monitor option parsing to monitor/monitor.c, Kevin Wolf, 2019/10/17
- [RFC PATCH 10/18] qemu-storage-daemon: Add --chardev option, Kevin Wolf, 2019/10/17
- [RFC PATCH 12/18] stubs: Update monitor stubs for qemu-storage-daemon, Kevin Wolf, 2019/10/17
- [RFC PATCH 09/18] qemu-storage-daemon: Add main loop, Kevin Wolf, 2019/10/17
- [RFC PATCH 07/18] blockdev-nbd: Boxed argument type for nbd-server-add, Kevin Wolf, 2019/10/17
- [RFC PATCH 15/18] qapi: Support empty modules, Kevin Wolf, 2019/10/17
- [RFC PATCH 16/18] qapi: Create 'pragma' module, Kevin Wolf, 2019/10/17
- [RFC PATCH 14/18] monitor: Create monitor/qmp-cmds-monitor.c, Kevin Wolf, 2019/10/17
- [RFC PATCH 13/18] qapi: Create module 'monitor', Kevin Wolf, 2019/10/17
- [RFC PATCH 17/18] monitor: Move qmp_query_qmp_schema to qmp-cmds-monitor.c, Kevin Wolf, 2019/10/17