mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-12-22 21:55:25 +00:00
backup: Prepare for Unix sockets in QMP nbd-server-start
Migration always uses a TCP socket for NBD servers, because we don't support same-host migration. But upcoming pull-mode incremental backup needs to also support a Unix socket, for retrieving the backup from the same host. Support this by plumbing virStorageNetHostDef through the monitor calls, since that is a nice reusable struct that can track both TCP and Unix sockets. Update qemumonitorjsontest to verify both forms of the QMP command. Signed-off-by: Eric Blake <eblake@redhat.com> Acked-by: Peter Krempa <pkrempa@redhat.com>
This commit is contained in:
parent
1ddc7e0363
commit
73bf0a9c28
@ -380,6 +380,10 @@ qemuMigrationDstStartNBDServer(virQEMUDriverPtr driver,
|
|||||||
unsigned short port = 0;
|
unsigned short port = 0;
|
||||||
char *diskAlias = NULL;
|
char *diskAlias = NULL;
|
||||||
size_t i;
|
size_t i;
|
||||||
|
virStorageNetHostDef server = {
|
||||||
|
.name = (char *)listenAddr, /* cast away const */
|
||||||
|
.transport = VIR_STORAGE_NET_HOST_TRANS_TCP,
|
||||||
|
};
|
||||||
|
|
||||||
if (nbdPort < 0 || nbdPort > USHRT_MAX) {
|
if (nbdPort < 0 || nbdPort > USHRT_MAX) {
|
||||||
virReportError(VIR_ERR_INVALID_ARG, "%s",
|
virReportError(VIR_ERR_INVALID_ARG, "%s",
|
||||||
@ -415,7 +419,8 @@ qemuMigrationDstStartNBDServer(virQEMUDriverPtr driver,
|
|||||||
else if (virPortAllocatorAcquire(driver->migrationPorts, &port) < 0)
|
else if (virPortAllocatorAcquire(driver->migrationPorts, &port) < 0)
|
||||||
goto exit_monitor;
|
goto exit_monitor;
|
||||||
|
|
||||||
if (qemuMonitorNBDServerStart(priv->mon, listenAddr, port, tls_alias) < 0)
|
server.port = port;
|
||||||
|
if (qemuMonitorNBDServerStart(priv->mon, &server, tls_alias) < 0)
|
||||||
goto exit_monitor;
|
goto exit_monitor;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3925,15 +3925,20 @@ qemuMonitorGetSEVCapabilities(qemuMonitorPtr mon,
|
|||||||
|
|
||||||
int
|
int
|
||||||
qemuMonitorNBDServerStart(qemuMonitorPtr mon,
|
qemuMonitorNBDServerStart(qemuMonitorPtr mon,
|
||||||
const char *host,
|
const virStorageNetHostDef *server,
|
||||||
unsigned int port,
|
|
||||||
const char *tls_alias)
|
const char *tls_alias)
|
||||||
{
|
{
|
||||||
VIR_DEBUG("host=%s port=%u tls_alias=%s", host, port, NULLSTR(tls_alias));
|
/* Peek inside the struct for nicer logging */
|
||||||
|
if (server->transport == VIR_STORAGE_NET_HOST_TRANS_TCP)
|
||||||
|
VIR_DEBUG("server={tcp host=%s port=%u} tls_alias=%s",
|
||||||
|
NULLSTR(server->name), server->port, NULLSTR(tls_alias));
|
||||||
|
else
|
||||||
|
VIR_DEBUG("server={unix socket=%s} tls_alias=%s",
|
||||||
|
NULLSTR(server->socket), NULLSTR(tls_alias));
|
||||||
|
|
||||||
QEMU_CHECK_MONITOR(mon);
|
QEMU_CHECK_MONITOR(mon);
|
||||||
|
|
||||||
return qemuMonitorJSONNBDServerStart(mon, host, port, tls_alias);
|
return qemuMonitorJSONNBDServerStart(mon, server, tls_alias);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -1094,9 +1094,9 @@ int qemuMonitorGetObjectProps(qemuMonitorPtr mon,
|
|||||||
char *qemuMonitorGetTargetArch(qemuMonitorPtr mon);
|
char *qemuMonitorGetTargetArch(qemuMonitorPtr mon);
|
||||||
|
|
||||||
int qemuMonitorNBDServerStart(qemuMonitorPtr mon,
|
int qemuMonitorNBDServerStart(qemuMonitorPtr mon,
|
||||||
const char *host,
|
const virStorageNetHostDef *server,
|
||||||
unsigned int port,
|
const char *tls_alias)
|
||||||
const char *tls_alias);
|
ATTRIBUTE_NONNULL(2);
|
||||||
int qemuMonitorNBDServerAdd(qemuMonitorPtr mon,
|
int qemuMonitorNBDServerAdd(qemuMonitorPtr mon,
|
||||||
const char *deviceID,
|
const char *deviceID,
|
||||||
bool writable);
|
bool writable);
|
||||||
|
@ -6684,8 +6684,7 @@ qemuMonitorJSONBuildUnixSocketAddress(const char *path)
|
|||||||
|
|
||||||
int
|
int
|
||||||
qemuMonitorJSONNBDServerStart(qemuMonitorPtr mon,
|
qemuMonitorJSONNBDServerStart(qemuMonitorPtr mon,
|
||||||
const char *host,
|
const virStorageNetHostDef *server,
|
||||||
unsigned int port,
|
|
||||||
const char *tls_alias)
|
const char *tls_alias)
|
||||||
{
|
{
|
||||||
int ret = -1;
|
int ret = -1;
|
||||||
@ -6694,10 +6693,22 @@ qemuMonitorJSONNBDServerStart(qemuMonitorPtr mon,
|
|||||||
virJSONValuePtr addr = NULL;
|
virJSONValuePtr addr = NULL;
|
||||||
char *port_str = NULL;
|
char *port_str = NULL;
|
||||||
|
|
||||||
if (virAsprintf(&port_str, "%u", port) < 0)
|
switch ((virStorageNetHostTransport)server->transport) {
|
||||||
|
case VIR_STORAGE_NET_HOST_TRANS_TCP:
|
||||||
|
if (virAsprintf(&port_str, "%u", server->port) < 0)
|
||||||
return ret;
|
return ret;
|
||||||
|
addr = qemuMonitorJSONBuildInetSocketAddress(server->name, port_str);
|
||||||
if (!(addr = qemuMonitorJSONBuildInetSocketAddress(host, port_str)))
|
break;
|
||||||
|
case VIR_STORAGE_NET_HOST_TRANS_UNIX:
|
||||||
|
addr = qemuMonitorJSONBuildUnixSocketAddress(server->socket);
|
||||||
|
break;
|
||||||
|
case VIR_STORAGE_NET_HOST_TRANS_RDMA:
|
||||||
|
case VIR_STORAGE_NET_HOST_TRANS_LAST:
|
||||||
|
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
||||||
|
_("invalid server address"));
|
||||||
|
goto cleanup;
|
||||||
|
}
|
||||||
|
if (!addr)
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
if (!(cmd = qemuMonitorJSONMakeCommand("nbd-server-start",
|
if (!(cmd = qemuMonitorJSONMakeCommand("nbd-server-start",
|
||||||
|
@ -459,8 +459,7 @@ int qemuMonitorJSONGetObjectProps(qemuMonitorPtr mon,
|
|||||||
char *qemuMonitorJSONGetTargetArch(qemuMonitorPtr mon);
|
char *qemuMonitorJSONGetTargetArch(qemuMonitorPtr mon);
|
||||||
|
|
||||||
int qemuMonitorJSONNBDServerStart(qemuMonitorPtr mon,
|
int qemuMonitorJSONNBDServerStart(qemuMonitorPtr mon,
|
||||||
const char *host,
|
const virStorageNetHostDef *server,
|
||||||
unsigned int port,
|
|
||||||
const char *tls_alias);
|
const char *tls_alias);
|
||||||
int qemuMonitorJSONNBDServerAdd(qemuMonitorPtr mon,
|
int qemuMonitorJSONNBDServerAdd(qemuMonitorPtr mon,
|
||||||
const char *deviceID,
|
const char *deviceID,
|
||||||
|
@ -1331,7 +1331,6 @@ GEN_TEST_FUNC(qemuMonitorJSONBlockCommit, "vdb", "/foo/bar1", "/foo/bar2", "back
|
|||||||
GEN_TEST_FUNC(qemuMonitorJSONDrivePivot, "vdb")
|
GEN_TEST_FUNC(qemuMonitorJSONDrivePivot, "vdb")
|
||||||
GEN_TEST_FUNC(qemuMonitorJSONScreendump, "devicename", 1, "/foo/bar")
|
GEN_TEST_FUNC(qemuMonitorJSONScreendump, "devicename", 1, "/foo/bar")
|
||||||
GEN_TEST_FUNC(qemuMonitorJSONOpenGraphics, "spice", "spicefd", false)
|
GEN_TEST_FUNC(qemuMonitorJSONOpenGraphics, "spice", "spicefd", false)
|
||||||
GEN_TEST_FUNC(qemuMonitorJSONNBDServerStart, "localhost", 12345, "test-alias")
|
|
||||||
GEN_TEST_FUNC(qemuMonitorJSONNBDServerAdd, "vda", true)
|
GEN_TEST_FUNC(qemuMonitorJSONNBDServerAdd, "vda", true)
|
||||||
GEN_TEST_FUNC(qemuMonitorJSONDetachCharDev, "serial1")
|
GEN_TEST_FUNC(qemuMonitorJSONDetachCharDev, "serial1")
|
||||||
GEN_TEST_FUNC(qemuMonitorJSONBlockdevTrayOpen, "foodev", true)
|
GEN_TEST_FUNC(qemuMonitorJSONBlockdevTrayOpen, "foodev", true)
|
||||||
@ -1339,6 +1338,44 @@ GEN_TEST_FUNC(qemuMonitorJSONBlockdevTrayClose, "foodev")
|
|||||||
GEN_TEST_FUNC(qemuMonitorJSONBlockdevMediumRemove, "foodev")
|
GEN_TEST_FUNC(qemuMonitorJSONBlockdevMediumRemove, "foodev")
|
||||||
GEN_TEST_FUNC(qemuMonitorJSONBlockdevMediumInsert, "foodev", "newnode")
|
GEN_TEST_FUNC(qemuMonitorJSONBlockdevMediumInsert, "foodev", "newnode")
|
||||||
|
|
||||||
|
static int
|
||||||
|
testQemuMonitorJSONqemuMonitorJSONNBDServerStart(const void *opaque)
|
||||||
|
{
|
||||||
|
const testGenericData *data = opaque;
|
||||||
|
virDomainXMLOptionPtr xmlopt = data->xmlopt;
|
||||||
|
virStorageNetHostDef server_tcp = {
|
||||||
|
.name = (char *)"localhost",
|
||||||
|
.port = 12345,
|
||||||
|
.transport = VIR_STORAGE_NET_HOST_TRANS_TCP,
|
||||||
|
};
|
||||||
|
virStorageNetHostDef server_unix = {
|
||||||
|
.socket = (char *)"/tmp/sock",
|
||||||
|
.transport = VIR_STORAGE_NET_HOST_TRANS_UNIX,
|
||||||
|
};
|
||||||
|
VIR_AUTOPTR(qemuMonitorTest) test = NULL;
|
||||||
|
|
||||||
|
if (!(test = qemuMonitorTestNewSchema(xmlopt, data->schema)))
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
if (qemuMonitorTestAddItem(test, "nbd-server-start",
|
||||||
|
"{\"return\":{}}") < 0)
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
if (qemuMonitorTestAddItem(test, "nbd-server-start",
|
||||||
|
"{\"return\":{}}") < 0)
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
if (qemuMonitorJSONNBDServerStart(qemuMonitorTestGetMonitor(test),
|
||||||
|
&server_tcp, "test-alias") < 0)
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
if (qemuMonitorJSONNBDServerStart(qemuMonitorTestGetMonitor(test),
|
||||||
|
&server_unix, "test-alias") < 0)
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
static bool
|
static bool
|
||||||
testQemuMonitorJSONqemuMonitorJSONQueryCPUsEqual(struct qemuMonitorQueryCpusEntry *a,
|
testQemuMonitorJSONqemuMonitorJSONQueryCPUsEqual(struct qemuMonitorQueryCpusEntry *a,
|
||||||
struct qemuMonitorQueryCpusEntry *b)
|
struct qemuMonitorQueryCpusEntry *b)
|
||||||
@ -2976,7 +3013,6 @@ mymain(void)
|
|||||||
DO_TEST_GEN(qemuMonitorJSONDrivePivot);
|
DO_TEST_GEN(qemuMonitorJSONDrivePivot);
|
||||||
DO_TEST_GEN(qemuMonitorJSONScreendump);
|
DO_TEST_GEN(qemuMonitorJSONScreendump);
|
||||||
DO_TEST_GEN(qemuMonitorJSONOpenGraphics);
|
DO_TEST_GEN(qemuMonitorJSONOpenGraphics);
|
||||||
DO_TEST_GEN(qemuMonitorJSONNBDServerStart);
|
|
||||||
DO_TEST_GEN(qemuMonitorJSONNBDServerAdd);
|
DO_TEST_GEN(qemuMonitorJSONNBDServerAdd);
|
||||||
DO_TEST_GEN(qemuMonitorJSONDetachCharDev);
|
DO_TEST_GEN(qemuMonitorJSONDetachCharDev);
|
||||||
DO_TEST_GEN(qemuMonitorJSONBlockdevTrayOpen);
|
DO_TEST_GEN(qemuMonitorJSONBlockdevTrayOpen);
|
||||||
@ -2998,6 +3034,7 @@ mymain(void)
|
|||||||
DO_TEST(qemuMonitorJSONGetDumpGuestMemoryCapability);
|
DO_TEST(qemuMonitorJSONGetDumpGuestMemoryCapability);
|
||||||
DO_TEST(qemuMonitorJSONSendKeyHoldtime);
|
DO_TEST(qemuMonitorJSONSendKeyHoldtime);
|
||||||
DO_TEST(qemuMonitorSupportsActiveCommit);
|
DO_TEST(qemuMonitorSupportsActiveCommit);
|
||||||
|
DO_TEST(qemuMonitorJSONNBDServerStart);
|
||||||
|
|
||||||
DO_TEST_CPU_DATA("host");
|
DO_TEST_CPU_DATA("host");
|
||||||
DO_TEST_CPU_DATA("full");
|
DO_TEST_CPU_DATA("full");
|
||||||
|
Loading…
Reference in New Issue
Block a user