Move the setup of the 'vdpa' netdev into the new helper shared between
commandline and hotplug code.
Signed-off-by: Peter Krempa <pkrempa(a)redhat.com>
---
src/qemu/qemu_command.c | 40 +++++++++++++++++++---------------------
src/qemu/qemu_command.h | 3 +--
src/qemu/qemu_hotplug.c | 14 ++------------
3 files changed, 22 insertions(+), 35 deletions(-)
diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c
index 2c4a1a582a..c86ab3f438 100644
--- a/src/qemu/qemu_command.c
+++ b/src/qemu/qemu_command.c
@@ -4192,13 +4192,12 @@ qemuBuildHostNetProps(virDomainNetDef *net,
size_t tapfdSize,
char **vhostfd,
size_t vhostfdSize,
- const char *slirpfd,
- const char *vdpadev)
+ const char *slirpfd)
{
bool is_tap = false;
virDomainNetType netType = virDomainNetGetActualType(net);
size_t i;
-
+ qemuDomainNetworkPrivate *netpriv = QEMU_DOMAIN_NETWORK_PRIVATE(net);
g_autoptr(virJSONValue) netprops = NULL;
if (net->script && netType != VIR_DOMAIN_NET_TYPE_ETHERNET) {
@@ -4333,8 +4332,10 @@ qemuBuildHostNetProps(virDomainNetDef *net,
case VIR_DOMAIN_NET_TYPE_VDPA:
/* Caller will pass the fd to qemu with add-fd */
- if (virJSONValueObjectAdd(&netprops, "s:type",
"vhost-vdpa", NULL) < 0 ||
- virJSONValueObjectAppendString(netprops, "vhostdev", vdpadev) <
0)
+ if (virJSONValueObjectAdd(&netprops,
+ "s:type", "vhost-vdpa",
+ "s:vhostdev",
qemuFDPassGetPath(netpriv->vdpafd),
+ NULL) < 0)
return NULL;
if (net->driver.virtio.queues > 1 &&
@@ -8654,11 +8655,15 @@ qemuInterfaceVhostuserConnect(virCommand *cmd,
int
-qemuBuildInterfaceConnect(virDomainObj *vm G_GNUC_UNUSED,
+qemuBuildInterfaceConnect(virDomainObj *vm,
virDomainNetDef *net,
bool standalone G_GNUC_UNUSED)
{
+
+ qemuDomainObjPrivate *priv = vm->privateData;
virDomainNetType actualType = virDomainNetGetActualType(net);
+ qemuDomainNetworkPrivate *netpriv = QEMU_DOMAIN_NETWORK_PRIVATE(net);
+ VIR_AUTOCLOSE vdpafd = -1;
switch (actualType) {
case VIR_DOMAIN_NET_TYPE_NETWORK:
@@ -8675,6 +8680,11 @@ qemuBuildInterfaceConnect(virDomainObj *vm G_GNUC_UNUSED,
break;
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;
case VIR_DOMAIN_NET_TYPE_HOSTDEV:
@@ -8703,7 +8713,6 @@ qemuBuildInterfaceCommandLine(virQEMUDriver *driver,
size_t *nnicindexes,
int **nicindexes)
{
- qemuDomainObjPrivate *priv = vm->privateData;
virDomainDef *def = vm->def;
int ret = -1;
g_autoptr(virJSONValue) nicprops = NULL;
@@ -8715,7 +8724,6 @@ qemuBuildInterfaceCommandLine(virQEMUDriver *driver,
char **tapfdName = NULL;
char **vhostfdName = NULL;
g_autofree char *slirpfdName = NULL;
- g_autoptr(qemuFDPass) vdpa = NULL;
virDomainNetType actualType = virDomainNetGetActualType(net);
const virNetDevBandwidth *actualBandwidth;
bool requireNicdev = false;
@@ -8798,16 +8806,7 @@ qemuBuildInterfaceCommandLine(virQEMUDriver *driver,
break;
- 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");
- }
+ case VIR_DOMAIN_NET_TYPE_VDPA:
break;
case VIR_DOMAIN_NET_TYPE_USER:
@@ -8940,14 +8939,13 @@ qemuBuildInterfaceCommandLine(virQEMUDriver *driver,
vhostfd[i] = -1;
}
- if (qemuFDPassTransferCommand(vdpa, cmd) < 0)
+ if (qemuFDPassTransferCommand(netpriv->vdpafd, cmd) < 0)
return -1;
if (!(hostnetprops = qemuBuildHostNetProps(net,
tapfdName, tapfdSize,
vhostfdName, vhostfdSize,
- slirpfdName,
- qemuFDPassGetPath(vdpa))))
+ slirpfdName)))
goto cleanup;
if (qemuBuildNetdevCommandlineFromJSON(cmd, hostnetprops, qemuCaps) < 0)
diff --git a/src/qemu/qemu_command.h b/src/qemu/qemu_command.h
index 4b4e0bb456..cae0541445 100644
--- a/src/qemu/qemu_command.h
+++ b/src/qemu/qemu_command.h
@@ -91,8 +91,7 @@ qemuBuildHostNetProps(virDomainNetDef *net,
size_t tapfdSize,
char **vhostfd,
size_t vhostfdSize,
- const char *slirpfd,
- const char *vdpadev);
+ const char *slirpfd);
int
qemuBuildInterfaceConnect(virDomainObj *vm,
diff --git a/src/qemu/qemu_hotplug.c b/src/qemu/qemu_hotplug.c
index 221815568b..d5bdeb83ae 100644
--- a/src/qemu/qemu_hotplug.c
+++ b/src/qemu/qemu_hotplug.c
@@ -1185,8 +1185,6 @@ qemuDomainAttachNetDevice(virQEMUDriver *driver,
virErrorPtr originalError = NULL;
g_autofree char *slirpfdName = NULL;
int slirpfd = -1;
- int vdpafd = -1;
- g_autoptr(qemuFDPass) vdpa = NULL;
char **tapfdName = NULL;
int *tapfd = NULL;
size_t tapfdSize = 0;
@@ -1395,13 +1393,6 @@ qemuDomainAttachNetDevice(virQEMUDriver *driver,
if (qemuDomainAdjustMaxMemLock(vm, false) < 0)
goto cleanup;
adjustmemlock = true;
-
- if ((vdpafd = qemuInterfaceVDPAConnect(net)) < 0)
- goto cleanup;
-
- vdpa = qemuFDPassNew(net->info.alias, priv);
-
- qemuFDPassAddFD(vdpa, &vdpafd, "-vdpa");
break;
case VIR_DOMAIN_NET_TYPE_SERVER:
@@ -1463,7 +1454,7 @@ qemuDomainAttachNetDevice(virQEMUDriver *driver,
qemuDomainObjEnterMonitor(driver, vm);
- if (qemuFDPassTransferMonitor(vdpa, priv->mon) < 0) {
+ if (qemuFDPassTransferMonitor(netpriv->vdpafd, priv->mon) < 0) {
qemuDomainObjExitMonitor(vm);
goto cleanup;
}
@@ -1471,7 +1462,7 @@ qemuDomainAttachNetDevice(virQEMUDriver *driver,
if (!(netprops = qemuBuildHostNetProps(net,
tapfdName, tapfdSize,
vhostfdName, vhostfdSize,
- slirpfdName, qemuFDPassGetPath(vdpa)))) {
+ slirpfdName))) {
qemuDomainObjExitMonitor(vm);
goto cleanup;
}
@@ -1611,7 +1602,6 @@ qemuDomainAttachNetDevice(virQEMUDriver *driver,
VIR_FREE(vhostfdName);
virDomainCCWAddressSetFree(ccwaddrs);
VIR_FORCE_CLOSE(slirpfd);
- VIR_FORCE_CLOSE(vdpafd);
return ret;
--
2.35.1