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 the same struct that backup_conf.c chose for tracking both TCP and Unix sockets. Signed-off-by: Eric Blake <eblake@xxxxxxxxxx> --- src/qemu/qemu_monitor.h | 6 +++--- src/qemu/qemu_monitor_json.h | 3 +-- src/qemu/qemu_migration.c | 7 ++++++- src/qemu/qemu_monitor.c | 7 +++---- src/qemu/qemu_monitor_json.c | 23 +++++++++++++++++------ tests/qemumonitorjsontest.c | 30 +++++++++++++++++++++++++++++- 6 files changed, 59 insertions(+), 17 deletions(-) diff --git a/src/qemu/qemu_monitor.h b/src/qemu/qemu_monitor.h index caf62af5e2..1237c14a84 100644 --- a/src/qemu/qemu_monitor.h +++ b/src/qemu/qemu_monitor.h @@ -1093,9 +1093,9 @@ int qemuMonitorGetObjectProps(qemuMonitorPtr mon, char *qemuMonitorGetTargetArch(qemuMonitorPtr mon); int qemuMonitorNBDServerStart(qemuMonitorPtr mon, - const char *host, - unsigned int port, - const char *tls_alias); + const virStorageNetHostDef *server, + const char *tls_alias) + ATTRIBUTE_NONNULL(2); int qemuMonitorNBDServerAdd(qemuMonitorPtr mon, const char *deviceID, bool writable); diff --git a/src/qemu/qemu_monitor_json.h b/src/qemu/qemu_monitor_json.h index c10513da15..e8472948b5 100644 --- a/src/qemu/qemu_monitor_json.h +++ b/src/qemu/qemu_monitor_json.h @@ -458,8 +458,7 @@ int qemuMonitorJSONGetObjectProps(qemuMonitorPtr mon, char *qemuMonitorJSONGetTargetArch(qemuMonitorPtr mon); int qemuMonitorJSONNBDServerStart(qemuMonitorPtr mon, - const char *host, - unsigned int port, + const virStorageNetHostDef *server, const char *tls_alias); int qemuMonitorJSONNBDServerAdd(qemuMonitorPtr mon, const char *deviceID, diff --git a/src/qemu/qemu_migration.c b/src/qemu/qemu_migration.c index e3ad4e52a7..09bd6fbb63 100644 --- a/src/qemu/qemu_migration.c +++ b/src/qemu/qemu_migration.c @@ -380,6 +380,10 @@ qemuMigrationDstStartNBDServer(virQEMUDriverPtr driver, unsigned short port = 0; char *diskAlias = NULL; size_t i; + virStorageNetHostDef server = { + .name = (char *)listenAddr, /* cast away const */ + .transport = VIR_STORAGE_NET_HOST_TRANS_TCP, + }; if (nbdPort < 0 || nbdPort > USHRT_MAX) { virReportError(VIR_ERR_INVALID_ARG, "%s", @@ -415,7 +419,8 @@ qemuMigrationDstStartNBDServer(virQEMUDriverPtr driver, else if (virPortAllocatorAcquire(driver->migrationPorts, &port) < 0) 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; } diff --git a/src/qemu/qemu_monitor.c b/src/qemu/qemu_monitor.c index babcbde878..694ed90622 100644 --- a/src/qemu/qemu_monitor.c +++ b/src/qemu/qemu_monitor.c @@ -3924,15 +3924,14 @@ qemuMonitorGetSEVCapabilities(qemuMonitorPtr mon, int qemuMonitorNBDServerStart(qemuMonitorPtr mon, - const char *host, - unsigned int port, + const virStorageNetHostDef *server, const char *tls_alias) { - VIR_DEBUG("host=%s port=%u tls_alias=%s", host, port, NULLSTR(tls_alias)); + VIR_DEBUG("server=%p tls_alias=%s", server, NULLSTR(tls_alias)); QEMU_CHECK_MONITOR(mon); - return qemuMonitorJSONNBDServerStart(mon, host, port, tls_alias); + return qemuMonitorJSONNBDServerStart(mon, server, tls_alias); } diff --git a/src/qemu/qemu_monitor_json.c b/src/qemu/qemu_monitor_json.c index e7d063a5a8..fc2d193ae2 100644 --- a/src/qemu/qemu_monitor_json.c +++ b/src/qemu/qemu_monitor_json.c @@ -6694,8 +6694,7 @@ qemuMonitorJSONBuildUnixSocketAddress(const char *path) int qemuMonitorJSONNBDServerStart(qemuMonitorPtr mon, - const char *host, - unsigned int port, + const virStorageNetHostDef *server, const char *tls_alias) { int ret = -1; @@ -6704,10 +6703,22 @@ qemuMonitorJSONNBDServerStart(qemuMonitorPtr mon, virJSONValuePtr addr = NULL; char *port_str = NULL; - if (virAsprintf(&port_str, "%u", port) < 0) - return ret; - - if (!(addr = qemuMonitorJSONBuildInetSocketAddress(host, port_str))) + switch ((virStorageNetHostTransport)server->transport) { + case VIR_STORAGE_NET_HOST_TRANS_TCP: + if (virAsprintf(&port_str, "%u", server->port) < 0) + return ret; + addr = qemuMonitorJSONBuildInetSocketAddress(server->name, 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; if (!(cmd = qemuMonitorJSONMakeCommand("nbd-server-start", diff --git a/tests/qemumonitorjsontest.c b/tests/qemumonitorjsontest.c index f5ad3f6a73..dd3259494a 100644 --- a/tests/qemumonitorjsontest.c +++ b/tests/qemumonitorjsontest.c @@ -1350,7 +1350,6 @@ GEN_TEST_FUNC(qemuMonitorJSONBlockCommit, "vdb", "/foo/bar1", "/foo/bar2", "back GEN_TEST_FUNC(qemuMonitorJSONDrivePivot, "vdb") GEN_TEST_FUNC(qemuMonitorJSONScreendump, "devicename", 1, "/foo/bar") GEN_TEST_FUNC(qemuMonitorJSONOpenGraphics, "spice", "spicefd", false) -GEN_TEST_FUNC(qemuMonitorJSONNBDServerStart, "localhost", 12345, "test-alias") GEN_TEST_FUNC(qemuMonitorJSONNBDServerAdd, "vda", true) GEN_TEST_FUNC(qemuMonitorJSONDetachCharDev, "serial1") GEN_TEST_FUNC(qemuMonitorJSONBlockdevTrayOpen, "foodev", true) @@ -1358,6 +1357,35 @@ GEN_TEST_FUNC(qemuMonitorJSONBlockdevTrayClose, "foodev") GEN_TEST_FUNC(qemuMonitorJSONBlockdevMediumRemove, "foodev") GEN_TEST_FUNC(qemuMonitorJSONBlockdevMediumInsert, "foodev", "newnode") +static int +testQemuMonitorJSONqemuMonitorJSONNBDServerStart(const void *data) +{ + virDomainXMLOptionPtr xmlopt = (virDomainXMLOptionPtr)data; + qemuMonitorTestPtr test = qemuMonitorTestNewSimple(true, xmlopt); + int ret = -1; + virStorageNetHostDef server = { + .name = (char *)"localhost", + .port = 12345, + .transport = VIR_STORAGE_NET_HOST_TRANS_TCP, + }; + + if (!test) + return -1; + + if (qemuMonitorTestAddItem(test, "nbd-server-start", "{\"return\":{}}") < 0) + goto cleanup; + + if (qemuMonitorJSONNBDServerStart(qemuMonitorTestGetMonitor(test), + &server, "test-alias") < 0) + goto cleanup; + + ret = 0; + + cleanup: + qemuMonitorTestFree(test); + return ret; +} + static bool testQemuMonitorJSONqemuMonitorJSONQueryCPUsEqual(struct qemuMonitorQueryCpusEntry *a, struct qemuMonitorQueryCpusEntry *b) -- 2.20.1 -- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list