mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-01-11 09:17:52 +03:00
qemu: Dissolve qemuBuildVhostuserCommandLine in qemuBuildInterfaceCommandLine
https://bugzilla.redhat.com/show_bug.cgi?id=1524230 The qemuBuildVhostuserCommandLine builds command line for vhostuser type interfaces. It is duplicating some code of the function it is called from (qemuBuildInterfaceCommandLine) because of the way it's called. If we merge it into the caller not only we save a few lines but we also enable checks that we would have to duplicate otherwise (e.g. QoS availability). Signed-off-by: Michal Privoznik <mprivozn@redhat.com> Reviewed-by: Erik Skultety <eskultet@redhat.com>
This commit is contained in:
parent
e7b7b61768
commit
4de4e4bc99
@ -8224,34 +8224,24 @@ qemuBuildGraphicsCommandLine(virQEMUDriverConfigPtr cfg,
|
|||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
qemuBuildVhostuserCommandLine(virQEMUDriverPtr driver,
|
qemuInterfaceVhostuserConnect(virQEMUDriverPtr driver,
|
||||||
virLogManagerPtr logManager,
|
virLogManagerPtr logManager,
|
||||||
virSecurityManagerPtr secManager,
|
virSecurityManagerPtr secManager,
|
||||||
virCommandPtr cmd,
|
virCommandPtr cmd,
|
||||||
virDomainDefPtr def,
|
virDomainDefPtr def,
|
||||||
virDomainNetDefPtr net,
|
virDomainNetDefPtr net,
|
||||||
virQEMUCapsPtr qemuCaps,
|
virQEMUCapsPtr qemuCaps,
|
||||||
unsigned int bootindex)
|
char **chardev)
|
||||||
{
|
{
|
||||||
virQEMUDriverConfigPtr cfg = virQEMUDriverGetConfig(driver);
|
virQEMUDriverConfigPtr cfg = virQEMUDriverGetConfig(driver);
|
||||||
char *chardev = NULL;
|
|
||||||
char *netdev = NULL;
|
|
||||||
unsigned int queues = net->driver.virtio.queues;
|
|
||||||
char *nic = NULL;
|
|
||||||
int ret = -1;
|
int ret = -1;
|
||||||
|
|
||||||
if (!qemuDomainSupportsNicdev(def, net)) {
|
|
||||||
virReportError(VIR_ERR_INTERNAL_ERROR,
|
|
||||||
"%s", _("Nicdev support unavailable"));
|
|
||||||
goto cleanup;
|
|
||||||
}
|
|
||||||
|
|
||||||
switch ((virDomainChrType)net->data.vhostuser->type) {
|
switch ((virDomainChrType)net->data.vhostuser->type) {
|
||||||
case VIR_DOMAIN_CHR_TYPE_UNIX:
|
case VIR_DOMAIN_CHR_TYPE_UNIX:
|
||||||
if (!(chardev = qemuBuildChrChardevStr(logManager, secManager,
|
if (!(*chardev = qemuBuildChrChardevStr(logManager, secManager,
|
||||||
cmd, cfg, def,
|
cmd, cfg, def,
|
||||||
net->data.vhostuser,
|
net->data.vhostuser,
|
||||||
net->info.alias, qemuCaps, 0)))
|
net->info.alias, qemuCaps, 0)))
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@ -8274,42 +8264,9 @@ qemuBuildVhostuserCommandLine(virQEMUDriverPtr driver,
|
|||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (queues > 1 &&
|
|
||||||
!virQEMUCapsGet(qemuCaps, QEMU_CAPS_VHOSTUSER_MULTIQUEUE)) {
|
|
||||||
virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
|
|
||||||
_("multi-queue is not supported for vhost-user "
|
|
||||||
"with this QEMU binary"));
|
|
||||||
goto cleanup;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!(netdev = qemuBuildHostNetStr(net, driver,
|
|
||||||
NULL, 0, NULL, 0)))
|
|
||||||
goto cleanup;
|
|
||||||
|
|
||||||
if (virNetDevOpenvswitchGetVhostuserIfname(net->data.vhostuser->data.nix.path,
|
|
||||||
&net->ifname) < 0)
|
|
||||||
goto cleanup;
|
|
||||||
|
|
||||||
virCommandAddArg(cmd, "-chardev");
|
|
||||||
virCommandAddArg(cmd, chardev);
|
|
||||||
|
|
||||||
virCommandAddArg(cmd, "-netdev");
|
|
||||||
virCommandAddArg(cmd, netdev);
|
|
||||||
|
|
||||||
if (!(nic = qemuBuildNicDevStr(def, net, bootindex,
|
|
||||||
queues, qemuCaps))) {
|
|
||||||
goto cleanup;
|
|
||||||
}
|
|
||||||
|
|
||||||
virCommandAddArgList(cmd, "-device", nic, NULL);
|
|
||||||
|
|
||||||
ret = 0;
|
ret = 0;
|
||||||
cleanup:
|
cleanup:
|
||||||
virObjectUnref(cfg);
|
virObjectUnref(cfg);
|
||||||
VIR_FREE(netdev);
|
|
||||||
VIR_FREE(chardev);
|
|
||||||
VIR_FREE(nic);
|
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -8330,6 +8287,7 @@ qemuBuildInterfaceCommandLine(virQEMUDriverPtr driver,
|
|||||||
int ret = -1;
|
int ret = -1;
|
||||||
char *nic = NULL;
|
char *nic = NULL;
|
||||||
char *host = NULL;
|
char *host = NULL;
|
||||||
|
char *chardev = NULL;
|
||||||
int *tapfd = NULL;
|
int *tapfd = NULL;
|
||||||
size_t tapfdSize = 0;
|
size_t tapfdSize = 0;
|
||||||
int *vhostfd = NULL;
|
int *vhostfd = NULL;
|
||||||
@ -8338,6 +8296,7 @@ qemuBuildInterfaceCommandLine(virQEMUDriverPtr driver,
|
|||||||
char **vhostfdName = NULL;
|
char **vhostfdName = NULL;
|
||||||
virDomainNetType actualType = virDomainNetGetActualType(net);
|
virDomainNetType actualType = virDomainNetGetActualType(net);
|
||||||
virNetDevBandwidthPtr actualBandwidth;
|
virNetDevBandwidthPtr actualBandwidth;
|
||||||
|
bool requireNicdev = false;
|
||||||
size_t i;
|
size_t i;
|
||||||
|
|
||||||
|
|
||||||
@ -8448,9 +8407,24 @@ qemuBuildInterfaceCommandLine(virQEMUDriverPtr driver,
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case VIR_DOMAIN_NET_TYPE_VHOSTUSER:
|
case VIR_DOMAIN_NET_TYPE_VHOSTUSER:
|
||||||
ret = qemuBuildVhostuserCommandLine(driver, logManager, secManager, cmd, def,
|
requireNicdev = true;
|
||||||
net, qemuCaps, bootindex);
|
|
||||||
goto cleanup;
|
if (net->driver.virtio.queues > 1 &&
|
||||||
|
!virQEMUCapsGet(qemuCaps, QEMU_CAPS_VHOSTUSER_MULTIQUEUE)) {
|
||||||
|
virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
|
||||||
|
_("multi-queue is not supported for vhost-user "
|
||||||
|
"with this QEMU binary"));
|
||||||
|
goto cleanup;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (qemuInterfaceVhostuserConnect(driver, logManager, secManager,
|
||||||
|
cmd, def, net, qemuCaps, &chardev) < 0)
|
||||||
|
goto cleanup;
|
||||||
|
|
||||||
|
if (virNetDevOpenvswitchGetVhostuserIfname(net->data.vhostuser->data.nix.path,
|
||||||
|
&net->ifname) < 0)
|
||||||
|
goto cleanup;
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case VIR_DOMAIN_NET_TYPE_USER:
|
case VIR_DOMAIN_NET_TYPE_USER:
|
||||||
@ -8565,6 +8539,9 @@ qemuBuildInterfaceCommandLine(virQEMUDriverPtr driver,
|
|||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (chardev)
|
||||||
|
virCommandAddArgList(cmd, "-chardev", chardev, NULL);
|
||||||
|
|
||||||
if (!(host = qemuBuildHostNetStr(net, driver,
|
if (!(host = qemuBuildHostNetStr(net, driver,
|
||||||
tapfdName, tapfdSize,
|
tapfdName, tapfdSize,
|
||||||
vhostfdName, vhostfdSize)))
|
vhostfdName, vhostfdSize)))
|
||||||
@ -8579,13 +8556,17 @@ qemuBuildInterfaceCommandLine(virQEMUDriverPtr driver,
|
|||||||
*/
|
*/
|
||||||
if (qemuDomainSupportsNicdev(def, net)) {
|
if (qemuDomainSupportsNicdev(def, net)) {
|
||||||
if (!(nic = qemuBuildNicDevStr(def, net, bootindex,
|
if (!(nic = qemuBuildNicDevStr(def, net, bootindex,
|
||||||
vhostfdSize, qemuCaps)))
|
net->driver.virtio.queues, qemuCaps)))
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
virCommandAddArgList(cmd, "-device", nic, NULL);
|
virCommandAddArgList(cmd, "-device", nic, NULL);
|
||||||
} else {
|
} else if (!requireNicdev) {
|
||||||
if (!(nic = qemuBuildLegacyNicStr(net)))
|
if (!(nic = qemuBuildLegacyNicStr(net)))
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
virCommandAddArgList(cmd, "-net", nic, NULL);
|
virCommandAddArgList(cmd, "-net", nic, NULL);
|
||||||
|
} else {
|
||||||
|
virReportError(VIR_ERR_INTERNAL_ERROR,
|
||||||
|
"%s", _("Nicdev support unavailable"));
|
||||||
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = 0;
|
ret = 0;
|
||||||
@ -8612,6 +8593,7 @@ qemuBuildInterfaceCommandLine(virQEMUDriverPtr driver,
|
|||||||
VIR_FREE(tapfdName);
|
VIR_FREE(tapfdName);
|
||||||
VIR_FREE(vhostfd);
|
VIR_FREE(vhostfd);
|
||||||
VIR_FREE(tapfd);
|
VIR_FREE(tapfd);
|
||||||
|
VIR_FREE(chardev);
|
||||||
VIR_FREE(host);
|
VIR_FREE(host);
|
||||||
VIR_FREE(nic);
|
VIR_FREE(nic);
|
||||||
return ret;
|
return ret;
|
||||||
|
Loading…
Reference in New Issue
Block a user