qemu: Convert passing of 'vhostfd' to 'qemuFDPassDirect'

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
This commit is contained in:
Peter Krempa 2022-05-16 15:08:05 +02:00
parent bca9047906
commit 7869eb9b31
6 changed files with 12 additions and 22 deletions

View File

@ -4224,7 +4224,7 @@ qemuBuildHostNetProps(virDomainNetDef *net)
nfds = 0; nfds = 0;
for (n = netpriv->vhostfds; n; n = n->next) { for (n = netpriv->vhostfds; n; n = n->next) {
virBufferAsprintf(&buf, "%s:", qemuFDPassGetPath(n->data)); virBufferAsprintf(&buf, "%s:", qemuFDPassDirectGetPath(n->data));
nfds++; nfds++;
} }
@ -8886,10 +8886,8 @@ qemuBuildInterfaceCommandLine(virQEMUDriver *driver,
return -1; return -1;
} }
for (n = netpriv->vhostfds; n; n = n->next) { for (n = netpriv->vhostfds; n; n = n->next)
if (qemuFDPassTransferCommand(n->data, cmd) < 0) qemuFDPassDirectTransferCommand(n->data, cmd);
return -1;
}
if (qemuFDPassTransferCommand(netpriv->slirpfd, cmd) < 0 || if (qemuFDPassTransferCommand(netpriv->slirpfd, cmd) < 0 ||
qemuFDPassTransferCommand(netpriv->vdpafd, cmd) < 0) qemuFDPassTransferCommand(netpriv->vdpafd, cmd) < 0)

View File

@ -1053,7 +1053,7 @@ qemuDomainNetworkPrivateClearFDs(qemuDomainNetworkPrivate *priv)
g_clear_pointer(&priv->slirpfd, qemuFDPassFree); g_clear_pointer(&priv->slirpfd, qemuFDPassFree);
g_clear_pointer(&priv->vdpafd, qemuFDPassFree); g_clear_pointer(&priv->vdpafd, qemuFDPassFree);
g_slist_free_full(g_steal_pointer(&priv->vhostfds), (GDestroyNotify) qemuFDPassFree); g_slist_free_full(g_steal_pointer(&priv->vhostfds), (GDestroyNotify) qemuFDPassDirectFree);
g_slist_free_full(g_steal_pointer(&priv->tapfds), (GDestroyNotify) qemuFDPassFree); g_slist_free_full(g_steal_pointer(&priv->tapfds), (GDestroyNotify) qemuFDPassFree);
} }

View File

@ -405,7 +405,7 @@ struct _qemuDomainNetworkPrivate {
/* file descriptor transfer helpers */ /* file descriptor transfer helpers */
qemuFDPass *slirpfd; qemuFDPass *slirpfd;
GSList *tapfds; GSList *tapfds;
GSList *vhostfds; GSList *vhostfds; /* qemuFDPassDirect */
qemuFDPass *vdpafd; qemuFDPass *vdpafd;
}; };

View File

@ -1380,7 +1380,7 @@ qemuDomainAttachNetDevice(virQEMUDriver *driver,
} }
for (n = netpriv->vhostfds; n; n = n->next) { for (n = netpriv->vhostfds; n; n = n->next) {
if (qemuFDPassTransferMonitor(n->data, priv->mon) < 0) { if (qemuFDPassDirectTransferMonitor(n->data, priv->mon) < 0) {
qemuDomainObjExitMonitor(vm); qemuDomainObjExitMonitor(vm);
goto cleanup; goto cleanup;
} }
@ -1528,7 +1528,7 @@ qemuDomainAttachNetDevice(virQEMUDriver *driver,
qemuFDPassTransferMonitorRollback(n->data, priv->mon); qemuFDPassTransferMonitorRollback(n->data, priv->mon);
for (n = netpriv->vhostfds; n; n = n->next) for (n = netpriv->vhostfds; n; n = n->next)
qemuFDPassTransferMonitorRollback(n->data, priv->mon); qemuFDPassDirectTransferMonitorRollback(n->data, priv->mon);
qemuDomainObjExitMonitor(vm); qemuDomainObjExitMonitor(vm);
virErrorRestore(&originalError); virErrorRestore(&originalError);

View File

@ -700,12 +700,10 @@ int
qemuInterfaceOpenVhostNet(virDomainObj *vm, qemuInterfaceOpenVhostNet(virDomainObj *vm,
virDomainNetDef *net) virDomainNetDef *net)
{ {
qemuDomainObjPrivate *priv = vm->privateData;
qemuDomainNetworkPrivate *netpriv = QEMU_DOMAIN_NETWORK_PRIVATE(net); qemuDomainNetworkPrivate *netpriv = QEMU_DOMAIN_NETWORK_PRIVATE(net);
size_t i; size_t i;
const char *vhostnet_path = net->backend.vhost; const char *vhostnet_path = net->backend.vhost;
size_t vhostfdSize = net->driver.virtio.queues; size_t vhostfdSize = net->driver.virtio.queues;
g_autofree char *prefix = g_strdup_printf("vhostfd-%s", net->info.alias);
if (!vhostfdSize) if (!vhostfdSize)
vhostfdSize = 1; vhostfdSize = 1;
@ -743,8 +741,7 @@ qemuInterfaceOpenVhostNet(virDomainObj *vm,
for (i = 0; i < vhostfdSize; i++) { for (i = 0; i < vhostfdSize; i++) {
VIR_AUTOCLOSE fd = open(vhostnet_path, O_RDWR); VIR_AUTOCLOSE fd = open(vhostnet_path, O_RDWR);
g_autoptr(qemuFDPass) pass = qemuFDPassNewDirect(prefix, priv); g_autofree char *name = g_strdup_printf("vhostfd-%s%zu", net->info.alias, i);
g_autofree char *suffix = g_strdup_printf("%zu", i);
/* If the config says explicitly to use vhost and we couldn't open it, /* If the config says explicitly to use vhost and we couldn't open it,
* report an error. * report an error.
@ -761,8 +758,7 @@ qemuInterfaceOpenVhostNet(virDomainObj *vm,
break; break;
} }
qemuFDPassAddFD(pass, &fd, suffix); netpriv->vhostfds = g_slist_prepend(netpriv->vhostfds, qemuFDPassDirectNew(name, &fd));
netpriv->vhostfds = g_slist_prepend(netpriv->vhostfds, g_steal_pointer(&pass));
} }
netpriv->vhostfds = g_slist_reverse(netpriv->vhostfds); netpriv->vhostfds = g_slist_reverse(netpriv->vhostfds);

View File

@ -226,12 +226,10 @@ virNetDevOpenvswitchGetVhostuserIfname(const char *path G_GNUC_UNUSED,
} }
int int
qemuInterfaceOpenVhostNet(virDomainObj *vm, qemuInterfaceOpenVhostNet(virDomainObj *vm G_GNUC_UNUSED,
virDomainNetDef *net) virDomainNetDef *net)
{ {
qemuDomainObjPrivate *priv = vm->privateData;
qemuDomainNetworkPrivate *netpriv = QEMU_DOMAIN_NETWORK_PRIVATE(net); qemuDomainNetworkPrivate *netpriv = QEMU_DOMAIN_NETWORK_PRIVATE(net);
g_autofree char *prefix = g_strdup_printf("vhostfd-%s", net->info.alias);
size_t vhostfdSize = net->driver.virtio.queues; size_t vhostfdSize = net->driver.virtio.queues;
size_t i; size_t i;
@ -242,12 +240,10 @@ qemuInterfaceOpenVhostNet(virDomainObj *vm,
return 0; return 0;
for (i = 0; i < vhostfdSize; i++) { for (i = 0; i < vhostfdSize; i++) {
g_autoptr(qemuFDPass) pass = qemuFDPassNewDirect(prefix, priv); g_autofree char *name = g_strdup_printf("vhostfd-%s%zu", net->info.alias, i);
g_autofree char *suffix = g_strdup_printf("%zu", i);
int fd = STDERR_FILENO + 42 + i; int fd = STDERR_FILENO + 42 + i;
qemuFDPassAddFD(pass, &fd, suffix); netpriv->vhostfds = g_slist_prepend(netpriv->vhostfds, qemuFDPassDirectNew(name, &fd));
netpriv->vhostfds = g_slist_prepend(netpriv->vhostfds, g_steal_pointer(&pass));
} }
netpriv->vhostfds = g_slist_reverse(netpriv->vhostfds); netpriv->vhostfds = g_slist_reverse(netpriv->vhostfds);