Add the monitor code, corresponding generator of properties for NBD and
tests validating it against the schema.
Signed-off-by: Peter Krempa <pkrempa(a)redhat.com>
---
src/qemu/qemu_block.c | 25 +++++++++++++++++++++++++
src/qemu/qemu_block.h | 7 +++++++
src/qemu/qemu_monitor.c | 10 ++++++++++
src/qemu/qemu_monitor.h | 4 ++++
src/qemu/qemu_monitor_json.c | 21 +++++++++++++++++++++
src/qemu/qemu_monitor_json.h | 4 ++++
tests/qemumonitorjsontest.c | 23 +++++++++++++++++++++++
7 files changed, 94 insertions(+)
diff --git a/src/qemu/qemu_block.c b/src/qemu/qemu_block.c
index 0be612eb1f..85a0320520 100644
--- a/src/qemu/qemu_block.c
+++ b/src/qemu/qemu_block.c
@@ -3365,6 +3365,31 @@ qemuBlockUpdateRelativeBacking(virDomainObjPtr vm,
}
+virJSONValuePtr
+qemuBlockExportGetNBDProps(const char *nodename,
+ const char *exportname,
+ bool writable,
+ const char *bitmap)
+{
+ g_autofree char *exportid = NULL;
+ virJSONValuePtr ret = NULL;
+
+ exportid = g_strdup_printf("libvirt-nbd-%s", nodename);
+
+ if (virJSONValueObjectCreate(&ret,
+ "s:type", "nbd",
+ "s:id", exportid,
+ "s:node-name", nodename,
+ "b:writable", writable,
+ "s:name", exportname,
+ "S:bitmap", bitmap,
+ NULL) < 0)
+ return NULL;
+
+ return ret;
+}
+
+
/**
* qemuBlockExportAddNBD:
* @vm: domain object
diff --git a/src/qemu/qemu_block.h b/src/qemu/qemu_block.h
index 0fc95fa6f6..64a95951f7 100644
--- a/src/qemu/qemu_block.h
+++ b/src/qemu/qemu_block.h
@@ -277,6 +277,13 @@ qemuBlockUpdateRelativeBacking(virDomainObjPtr vm,
virStorageSourcePtr src,
virStorageSourcePtr topsrc);
+virJSONValuePtr
+qemuBlockExportGetNBDProps(const char *nodename,
+ const char *exportname,
+ bool writable,
+ const char *bitmap);
+
+
int
qemuBlockExportAddNBD(virDomainObjPtr vm,
const char *drivealias,
diff --git a/src/qemu/qemu_monitor.c b/src/qemu/qemu_monitor.c
index 8c991fefbb..834e1c9e8f 100644
--- a/src/qemu/qemu_monitor.c
+++ b/src/qemu/qemu_monitor.c
@@ -3925,6 +3925,16 @@ qemuMonitorNBDServerStop(qemuMonitorPtr mon)
}
+int
+qemuMonitorBlockExportAdd(qemuMonitorPtr mon,
+ virJSONValuePtr *props)
+{
+ QEMU_CHECK_MONITOR(mon);
+
+ return qemuMonitorJSONBlockExportAdd(mon, props);
+}
+
+
int
qemuMonitorGetTPMModels(qemuMonitorPtr mon,
char ***tpmmodels)
diff --git a/src/qemu/qemu_monitor.h b/src/qemu/qemu_monitor.h
index a744c8975b..f2c632a7ac 100644
--- a/src/qemu/qemu_monitor.h
+++ b/src/qemu/qemu_monitor.h
@@ -1232,6 +1232,10 @@ int qemuMonitorNBDServerAdd(qemuMonitorPtr mon,
bool writable,
const char *bitmap);
int qemuMonitorNBDServerStop(qemuMonitorPtr);
+
+int qemuMonitorBlockExportAdd(qemuMonitorPtr mon,
+ virJSONValuePtr *props);
+
int qemuMonitorGetTPMModels(qemuMonitorPtr mon,
char ***tpmmodels);
diff --git a/src/qemu/qemu_monitor_json.c b/src/qemu/qemu_monitor_json.c
index 26ac499fc5..e88e6aebaf 100644
--- a/src/qemu/qemu_monitor_json.c
+++ b/src/qemu/qemu_monitor_json.c
@@ -7284,6 +7284,27 @@ qemuMonitorJSONNBDServerStop(qemuMonitorPtr mon)
}
+int
+qemuMonitorJSONBlockExportAdd(qemuMonitorPtr mon,
+ virJSONValuePtr *props)
+{
+ g_autoptr(virJSONValue) cmd = NULL;
+ g_autoptr(virJSONValue) reply = NULL;
+ virJSONValuePtr pr = g_steal_pointer(props);
+
+ if (!(cmd = qemuMonitorJSONMakeCommandInternal("block-export-add", pr)))
+ return -1;
+
+ if (qemuMonitorJSONCommand(mon, cmd, &reply) < 0)
+ return -1;
+
+ if (qemuMonitorJSONCheckError(cmd, reply) < 0)
+ return -1;
+
+ return 0;
+}
+
+
static int
qemuMonitorJSONGetStringArray(qemuMonitorPtr mon, const char *qmpCmd,
char ***array)
diff --git a/src/qemu/qemu_monitor_json.h b/src/qemu/qemu_monitor_json.h
index 098ab857be..e9107eaade 100644
--- a/src/qemu/qemu_monitor_json.h
+++ b/src/qemu/qemu_monitor_json.h
@@ -505,6 +505,10 @@ int qemuMonitorJSONNBDServerAdd(qemuMonitorPtr mon,
bool writable,
const char *bitmap);
int qemuMonitorJSONNBDServerStop(qemuMonitorPtr mon);
+
+int qemuMonitorJSONBlockExportAdd(qemuMonitorPtr mon,
+ virJSONValuePtr *props);
+
int qemuMonitorJSONGetTPMModels(qemuMonitorPtr mon,
char ***tpmmodels)
ATTRIBUTE_NONNULL(2);
diff --git a/tests/qemumonitorjsontest.c b/tests/qemumonitorjsontest.c
index a6e14a1b00..d65af6fadc 100644
--- a/tests/qemumonitorjsontest.c
+++ b/tests/qemumonitorjsontest.c
@@ -3046,6 +3046,28 @@ testQemuMonitorJSONTransaction(const void *opaque)
}
+static int
+testQemuMonitorJSONBlockExportAdd(const void *opaque)
+{
+ const testGenericData *data = opaque;
+ g_autoptr(qemuMonitorTest) test = NULL;
+ g_autoptr(virJSONValue) nbddata = NULL;
+
+ if (!(test = qemuMonitorTestNewSchema(data->xmlopt, data->schema)))
+ return -1;
+
+ if (!(nbddata = qemuBlockExportGetNBDProps("nodename",
"exportname", true, "bitmapname")))
+ return -1;
+
+ if (qemuMonitorTestAddItem(test, "block-export-add",
"{\"return\":{}}") < 0)
+ return -1;
+
+ if (qemuMonitorJSONBlockExportAdd(qemuMonitorTestGetMonitor(test), &nbddata) <
0)
+ return -1;
+
+ return 0;
+}
+
static int
testQemuMonitorJSONqemuMonitorJSONGetCPUModelComparison(const void *opaque)
{
@@ -3243,6 +3265,7 @@ mymain(void)
DO_TEST(GetNonExistingCPUData);
DO_TEST(GetIOThreads);
DO_TEST(Transaction);
+ DO_TEST(BlockExportAdd);
DO_TEST_SIMPLE("qmp_capabilities", qemuMonitorJSONSetCapabilities);
DO_TEST_SIMPLE("system_powerdown", qemuMonitorJSONSystemPowerdown);
DO_TEST_SIMPLE("system_reset", qemuMonitorJSONSystemReset);
--
2.26.2