Add alternative code paths for passing of the FDs using the new
infrastructure. This way we'll be able to refactor the code
incrementally.
Signed-off-by: Peter Krempa <pkrempa(a)redhat.com>
---
src/qemu/qemu_command.c | 45 ++++++++++++++++++++++++++++++++++++-----
src/qemu/qemu_hotplug.c | 22 ++++++++++++++++++++
2 files changed, 62 insertions(+), 5 deletions(-)
diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c
index c412bc50e0..fc8e209976 100644
--- a/src/qemu/qemu_command.c
+++ b/src/qemu/qemu_command.c
@@ -4223,17 +4223,41 @@ qemuBuildHostNetProps(virDomainNetDef *net,
const char *vhostfd_field = "S:vhostfd";
g_autofree char *vhostfd_arg = NULL;
bool vhost = false;
+ size_t nfds;
+ GSList *n;
+
+ if (netpriv->tapfds) {
+ nfds = 0;
+ for (n = netpriv->tapfds; n; n = n->next) {
+ virBufferAsprintf(&buf, "%s:",
qemuFDPassGetPath(n->data));
+ nfds++;
+ }
- for (i = 0; i < tapfdSize; i++)
- virBufferAsprintf(&buf, "%s:", tapfd[i]);
+ if (nfds > 1)
+ tapfd_field = "s:fds";
+ } else {
+ for (i = 0; i < tapfdSize; i++)
+ virBufferAsprintf(&buf, "%s:", tapfd[i]);
- if (tapfdSize > 1)
- tapfd_field = "s:fds";
+ if (tapfdSize > 1)
+ tapfd_field = "s:fds";
+ }
virBufferTrim(&buf, ":");
tapfd_arg = virBufferContentAndReset(&buf);
- if (vhostfdSize > 0) {
+ if (netpriv->vhostfds) {
+ vhost = true;
+
+ nfds = 0;
+ for (n = netpriv->vhostfds; n; n = n->next) {
+ virBufferAsprintf(&buf, "%s:",
qemuFDPassGetPath(n->data));
+ nfds++;
+ }
+
+ if (nfds > 1)
+ vhostfd_field = "s:vhostfds";
+ } else if (vhostfdSize > 0) {
vhost = true;
for (i = 0; i < vhostfdSize; i++)
@@ -8722,6 +8746,7 @@ qemuBuildInterfaceCommandLine(virQEMUDriver *driver,
size_t i;
g_autoptr(virJSONValue) hostnetprops = NULL;
qemuDomainNetworkPrivate *netpriv = QEMU_DOMAIN_NETWORK_PRIVATE(net);
+ GSList *n;
if (qemuDomainValidateActualNetDef(net, qemuCaps) < 0)
return -1;
@@ -8930,6 +8955,16 @@ qemuBuildInterfaceCommandLine(virQEMUDriver *driver,
vhostfd[i] = -1;
}
+ for (n = netpriv->tapfds; n; n = n->next) {
+ if (qemuFDPassTransferCommand(n->data, cmd) < 0)
+ return -1;
+ }
+
+ for (n = netpriv->vhostfds; n; n = n->next) {
+ if (qemuFDPassTransferCommand(n->data, cmd) < 0)
+ return -1;
+ }
+
if (qemuFDPassTransferCommand(netpriv->vdpafd, cmd) < 0)
return -1;
diff --git a/src/qemu/qemu_hotplug.c b/src/qemu/qemu_hotplug.c
index 525c55baf2..28868cf3d0 100644
--- a/src/qemu/qemu_hotplug.c
+++ b/src/qemu/qemu_hotplug.c
@@ -1210,6 +1210,7 @@ qemuDomainAttachNetDevice(virQEMUDriver *driver,
g_autoptr(virConnect) conn = NULL;
virErrorPtr save_err = NULL;
bool teardownlabel = false;
+ GSList *n;
/* If appropriate, grab a physical device from the configured
* network's pool of devices, or resolve bridge device name
@@ -1460,6 +1461,20 @@ qemuDomainAttachNetDevice(virQEMUDriver *driver,
qemuDomainObjEnterMonitor(driver, vm);
+ for (n = netpriv->tapfds; n; n = n->next) {
+ if (qemuFDPassTransferMonitor(n->data, priv->mon) < 0) {
+ qemuDomainObjExitMonitor(vm);
+ goto cleanup;
+ }
+ }
+
+ for (n = netpriv->vhostfds; n; n = n->next) {
+ if (qemuFDPassTransferMonitor(n->data, priv->mon) < 0) {
+ qemuDomainObjExitMonitor(vm);
+ goto cleanup;
+ }
+ }
+
if (qemuFDPassTransferMonitor(netpriv->vdpafd, priv->mon) < 0) {
qemuDomainObjExitMonitor(vm);
goto cleanup;
@@ -1619,6 +1634,13 @@ qemuDomainAttachNetDevice(virQEMUDriver *driver,
qemuMonitorRemoveNetdev(priv->mon, netdev_name) < 0)
VIR_WARN("Failed to remove network backend for netdev %s",
netdev_name);
+
+ for (n = netpriv->tapfds; n; n = n->next)
+ qemuFDPassTransferMonitorRollback(n->data, priv->mon);
+
+ for (n = netpriv->vhostfds; n; n = n->next)
+ qemuFDPassTransferMonitorRollback(n->data, priv->mon);
+
qemuDomainObjExitMonitor(vm);
virErrorRestore(&originalError);
goto cleanup;
--
2.35.1