[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[RFC PATCH 22/22] block/export: Add query-block-exports
From: |
Kevin Wolf |
Subject: |
[RFC PATCH 22/22] block/export: Add query-block-exports |
Date: |
Thu, 13 Aug 2020 18:29:35 +0200 |
This adds a simple QMP command to query the list of block exports.
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
---
qapi/block-export.json | 33 +++++++++++++++++++++++++++++++++
block/export/export.c | 23 +++++++++++++++++++++++
2 files changed, 56 insertions(+)
diff --git a/qapi/block-export.json b/qapi/block-export.json
index a067de2ba3..0b184bbd7c 100644
--- a/qapi/block-export.json
+++ b/qapi/block-export.json
@@ -226,3 +226,36 @@
##
{ 'command': 'block-export-del',
'data': { 'id': 'str', '*mode': 'BlockExportRemoveMode' } }
+
+##
+# @BlockExportInfo:
+#
+# Information about a single block export.
+#
+# @id: The unique identifier for the block export
+#
+# @type: This field is returned only for compatibility reasons, it should
+# not be used (always returns 'unknown')
+#
+# @node-name: The node name of the block node that is exported
+#
+# @shutting-down: True if the export is shutting down (e.g. after a
+# block-export-del command, but before the shutdown has
+# completed)
+#
+# Since: 5.2
+##
+{ 'struct': 'BlockExportInfo',
+ 'data': { 'id': 'str',
+ 'type': 'BlockExportType',
+ 'node-name': 'str',
+ 'shutting-down': 'bool' } }
+
+##
+# @query-block-exports:
+#
+# Returns: A list of BlockExportInfo describing all block exports
+#
+# Since: 5.2
+##
+{ 'command': 'query-block-exports', 'returns': ['BlockExportInfo'] }
diff --git a/block/export/export.c b/block/export/export.c
index 3cd448ba72..71d17bd440 100644
--- a/block/export/export.c
+++ b/block/export/export.c
@@ -272,3 +272,26 @@ void qmp_nbd_server_remove(const char *name,
qmp_block_export_del(name, has_mode, mode, errp);
}
+
+BlockExportInfoList *qmp_query_block_exports(Error **errp)
+{
+ BlockExportInfoList *head = NULL, **p_next = &head;
+ BlockExport *exp;
+
+ QLIST_FOREACH(exp, &block_exports, next) {
+ BlockExportInfoList *entry = g_new0(BlockExportInfoList, 1);
+ BlockExportInfo *info = g_new(BlockExportInfo, 1);
+ *info = (BlockExportInfo) {
+ .id = g_strdup(exp->id),
+ .type = exp->drv->type,
+ .node_name = g_strdup(bdrv_get_node_name(blk_bs(exp->blk))),
+ .shutting_down = !exp->user_owned,
+ };
+
+ entry->value = info;
+ *p_next = entry;
+ p_next = &entry->next;
+ }
+
+ return head;
+}
--
2.25.4
- Re: [RFC PATCH 19/22] block/export: Move strong user reference to block_exports, (continued)
[RFC PATCH 18/22] block/export: Add 'id' option to block-export-add, Kevin Wolf, 2020/08/13
[RFC PATCH 17/22] block/export: Add blk_exp_close_all(_type), Kevin Wolf, 2020/08/13
[RFC PATCH 20/22] block/export: Add block-export-del, Kevin Wolf, 2020/08/13
[RFC PATCH 22/22] block/export: Add query-block-exports,
Kevin Wolf <=
[RFC PATCH 21/22] block/export: Move blk to BlockExport, Kevin Wolf, 2020/08/13