qemu: Add infrastructure for 'block-export-add' to export NBD

Add the monitor code, corresponding generator of properties for NBD and
tests validating it against the schema.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
This commit is contained in:
Peter Krempa 2020-10-14 11:33:06 +02:00
parent adb9f7123a
commit f70e9c6cb8
7 changed files with 94 additions and 0 deletions

View File

@ -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

View File

@ -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,

View File

@ -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)

View File

@ -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);

View File

@ -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)

View File

@ -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);

View File

@ -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);