1
0

qemuBuildInterfaceConnect: Connect to 'vdpa' netdev

Move the setup of the 'vdpa' netdev into the new helper shared between
commandline and hotplug code.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Jonathon Jongsma <jjongsma@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
This commit is contained in:
Peter Krempa 2022-05-09 15:34:09 +02:00
parent 29d022b1eb
commit 96d6fec8dc
3 changed files with 22 additions and 35 deletions

View File

@ -4213,13 +4213,12 @@ qemuBuildHostNetProps(virDomainNetDef *net,
size_t tapfdSize, size_t tapfdSize,
char **vhostfd, char **vhostfd,
size_t vhostfdSize, size_t vhostfdSize,
const char *slirpfd, const char *slirpfd)
const char *vdpadev)
{ {
bool is_tap = false; bool is_tap = false;
virDomainNetType netType = virDomainNetGetActualType(net); virDomainNetType netType = virDomainNetGetActualType(net);
size_t i; size_t i;
qemuDomainNetworkPrivate *netpriv = QEMU_DOMAIN_NETWORK_PRIVATE(net);
g_autoptr(virJSONValue) netprops = NULL; g_autoptr(virJSONValue) netprops = NULL;
if (net->script && netType != VIR_DOMAIN_NET_TYPE_ETHERNET) { if (net->script && netType != VIR_DOMAIN_NET_TYPE_ETHERNET) {
@ -4354,8 +4353,10 @@ qemuBuildHostNetProps(virDomainNetDef *net,
case VIR_DOMAIN_NET_TYPE_VDPA: case VIR_DOMAIN_NET_TYPE_VDPA:
/* Caller will pass the fd to qemu with add-fd */ /* Caller will pass the fd to qemu with add-fd */
if (virJSONValueObjectAdd(&netprops, "s:type", "vhost-vdpa", NULL) < 0 || if (virJSONValueObjectAdd(&netprops,
virJSONValueObjectAppendString(netprops, "vhostdev", vdpadev) < 0) "s:type", "vhost-vdpa",
"s:vhostdev", qemuFDPassGetPath(netpriv->vdpafd),
NULL) < 0)
return NULL; return NULL;
if (net->driver.virtio.queues > 1 && if (net->driver.virtio.queues > 1 &&
@ -8676,11 +8677,15 @@ qemuInterfaceVhostuserConnect(virCommand *cmd,
int int
qemuBuildInterfaceConnect(virDomainObj *vm G_GNUC_UNUSED, qemuBuildInterfaceConnect(virDomainObj *vm,
virDomainNetDef *net, virDomainNetDef *net,
bool standalone G_GNUC_UNUSED) bool standalone G_GNUC_UNUSED)
{ {
qemuDomainObjPrivate *priv = vm->privateData;
virDomainNetType actualType = virDomainNetGetActualType(net); virDomainNetType actualType = virDomainNetGetActualType(net);
qemuDomainNetworkPrivate *netpriv = QEMU_DOMAIN_NETWORK_PRIVATE(net);
VIR_AUTOCLOSE vdpafd = -1;
switch (actualType) { switch (actualType) {
case VIR_DOMAIN_NET_TYPE_NETWORK: case VIR_DOMAIN_NET_TYPE_NETWORK:
@ -8697,6 +8702,11 @@ qemuBuildInterfaceConnect(virDomainObj *vm G_GNUC_UNUSED,
break; break;
case VIR_DOMAIN_NET_TYPE_VDPA: case VIR_DOMAIN_NET_TYPE_VDPA:
if ((vdpafd = qemuInterfaceVDPAConnect(net)) < 0)
return -1;
netpriv->vdpafd = qemuFDPassNew(net->info.alias, priv);
qemuFDPassAddFD(netpriv->vdpafd, &vdpafd, "-vdpa");
break; break;
case VIR_DOMAIN_NET_TYPE_HOSTDEV: case VIR_DOMAIN_NET_TYPE_HOSTDEV:
@ -8725,7 +8735,6 @@ qemuBuildInterfaceCommandLine(virQEMUDriver *driver,
size_t *nnicindexes, size_t *nnicindexes,
int **nicindexes) int **nicindexes)
{ {
qemuDomainObjPrivate *priv = vm->privateData;
virDomainDef *def = vm->def; virDomainDef *def = vm->def;
int ret = -1; int ret = -1;
g_autoptr(virJSONValue) nicprops = NULL; g_autoptr(virJSONValue) nicprops = NULL;
@ -8737,7 +8746,6 @@ qemuBuildInterfaceCommandLine(virQEMUDriver *driver,
char **tapfdName = NULL; char **tapfdName = NULL;
char **vhostfdName = NULL; char **vhostfdName = NULL;
g_autofree char *slirpfdName = NULL; g_autofree char *slirpfdName = NULL;
g_autoptr(qemuFDPass) vdpa = NULL;
virDomainNetType actualType = virDomainNetGetActualType(net); virDomainNetType actualType = virDomainNetGetActualType(net);
const virNetDevBandwidth *actualBandwidth; const virNetDevBandwidth *actualBandwidth;
bool requireNicdev = false; bool requireNicdev = false;
@ -8820,16 +8828,7 @@ qemuBuildInterfaceCommandLine(virQEMUDriver *driver,
break; break;
case VIR_DOMAIN_NET_TYPE_VDPA: { case VIR_DOMAIN_NET_TYPE_VDPA:
VIR_AUTOCLOSE vdpafd = -1;
if ((vdpafd = qemuInterfaceVDPAConnect(net)) < 0)
goto cleanup;
vdpa = qemuFDPassNew(net->info.alias, priv);
qemuFDPassAddFD(vdpa, &vdpafd, "-vdpa");
}
break; break;
case VIR_DOMAIN_NET_TYPE_USER: case VIR_DOMAIN_NET_TYPE_USER:
@ -8962,14 +8961,13 @@ qemuBuildInterfaceCommandLine(virQEMUDriver *driver,
vhostfd[i] = -1; vhostfd[i] = -1;
} }
if (qemuFDPassTransferCommand(vdpa, cmd) < 0) if (qemuFDPassTransferCommand(netpriv->vdpafd, cmd) < 0)
return -1; return -1;
if (!(hostnetprops = qemuBuildHostNetProps(net, if (!(hostnetprops = qemuBuildHostNetProps(net,
tapfdName, tapfdSize, tapfdName, tapfdSize,
vhostfdName, vhostfdSize, vhostfdName, vhostfdSize,
slirpfdName, slirpfdName)))
qemuFDPassGetPath(vdpa))))
goto cleanup; goto cleanup;
if (qemuBuildNetdevCommandlineFromJSON(cmd, hostnetprops, qemuCaps) < 0) if (qemuBuildNetdevCommandlineFromJSON(cmd, hostnetprops, qemuCaps) < 0)

View File

@ -91,8 +91,7 @@ qemuBuildHostNetProps(virDomainNetDef *net,
size_t tapfdSize, size_t tapfdSize,
char **vhostfd, char **vhostfd,
size_t vhostfdSize, size_t vhostfdSize,
const char *slirpfd, const char *slirpfd);
const char *vdpadev);
int int
qemuBuildInterfaceConnect(virDomainObj *vm, qemuBuildInterfaceConnect(virDomainObj *vm,

View File

@ -1185,8 +1185,6 @@ qemuDomainAttachNetDevice(virQEMUDriver *driver,
virErrorPtr originalError = NULL; virErrorPtr originalError = NULL;
g_autofree char *slirpfdName = NULL; g_autofree char *slirpfdName = NULL;
int slirpfd = -1; int slirpfd = -1;
int vdpafd = -1;
g_autoptr(qemuFDPass) vdpa = NULL;
char **tapfdName = NULL; char **tapfdName = NULL;
int *tapfd = NULL; int *tapfd = NULL;
size_t tapfdSize = 0; size_t tapfdSize = 0;
@ -1395,13 +1393,6 @@ qemuDomainAttachNetDevice(virQEMUDriver *driver,
if (qemuDomainAdjustMaxMemLock(vm, false) < 0) if (qemuDomainAdjustMaxMemLock(vm, false) < 0)
goto cleanup; goto cleanup;
adjustmemlock = true; adjustmemlock = true;
if ((vdpafd = qemuInterfaceVDPAConnect(net)) < 0)
goto cleanup;
vdpa = qemuFDPassNew(net->info.alias, priv);
qemuFDPassAddFD(vdpa, &vdpafd, "-vdpa");
break; break;
case VIR_DOMAIN_NET_TYPE_SERVER: case VIR_DOMAIN_NET_TYPE_SERVER:
@ -1463,7 +1454,7 @@ qemuDomainAttachNetDevice(virQEMUDriver *driver,
qemuDomainObjEnterMonitor(driver, vm); qemuDomainObjEnterMonitor(driver, vm);
if (qemuFDPassTransferMonitor(vdpa, priv->mon) < 0) { if (qemuFDPassTransferMonitor(netpriv->vdpafd, priv->mon) < 0) {
qemuDomainObjExitMonitor(vm); qemuDomainObjExitMonitor(vm);
goto cleanup; goto cleanup;
} }
@ -1471,7 +1462,7 @@ qemuDomainAttachNetDevice(virQEMUDriver *driver,
if (!(netprops = qemuBuildHostNetProps(net, if (!(netprops = qemuBuildHostNetProps(net,
tapfdName, tapfdSize, tapfdName, tapfdSize,
vhostfdName, vhostfdSize, vhostfdName, vhostfdSize,
slirpfdName, qemuFDPassGetPath(vdpa)))) { slirpfdName))) {
qemuDomainObjExitMonitor(vm); qemuDomainObjExitMonitor(vm);
goto cleanup; goto cleanup;
} }
@ -1611,7 +1602,6 @@ qemuDomainAttachNetDevice(virQEMUDriver *driver,
VIR_FREE(vhostfdName); VIR_FREE(vhostfdName);
virDomainCCWAddressSetFree(ccwaddrs); virDomainCCWAddressSetFree(ccwaddrs);
VIR_FORCE_CLOSE(slirpfd); VIR_FORCE_CLOSE(slirpfd);
VIR_FORCE_CLOSE(vdpafd);
return ret; return ret;