From nobody Sat Apr 20 09:31:54 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 15411645946729.735143240816114; Fri, 2 Nov 2018 06:16:34 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id AC055C02833B; Fri, 2 Nov 2018 13:16:32 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id B514F26324; Fri, 2 Nov 2018 13:16:30 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 030D2180B5B7; Fri, 2 Nov 2018 13:16:30 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id wA2CudM5017352 for ; Fri, 2 Nov 2018 08:56:39 -0400 Received: by smtp.corp.redhat.com (Postfix) id 23CB65D965; Fri, 2 Nov 2018 12:56:39 +0000 (UTC) Received: from moe.brq.redhat.com (unknown [10.43.2.192]) by smtp.corp.redhat.com (Postfix) with ESMTP id 7715018BAA; Fri, 2 Nov 2018 12:56:35 +0000 (UTC) From: Michal Privoznik To: libvir-list@redhat.com Date: Fri, 2 Nov 2018 13:56:17 +0100 Message-Id: <9424bef1ccf873c1718e6117e2e5976d5904e454.1541163377.git.mprivozn@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-loop: libvir-list@redhat.com Cc: eskultet@redhat.com Subject: [libvirt] [PATCH] qemu: Dissolve qemuBuildVhostuserCommandLine in qemuBuildInterfaceCommandLine X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.31]); Fri, 02 Nov 2018 13:16:33 +0000 (UTC) Content-Type: text/plain; charset="utf-8" https://bugzilla.redhat.com/show_bug.cgi?id=3D1524230 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). While at it, reorder some VIR_FREE() in qemuBuildInterfaceCommandLine so that it is easier to track which variables are freed and which are not. Signed-off-by: Michal Privoznik Reviewed-by: Erik Skultety --- src/qemu/qemu_command.c | 113 +++++++++++++++++----------------------- 1 file changed, 48 insertions(+), 65 deletions(-) diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c index 6e3ff67660..e338d3172e 100644 --- a/src/qemu/qemu_command.c +++ b/src/qemu/qemu_command.c @@ -8224,34 +8224,24 @@ qemuBuildGraphicsCommandLine(virQEMUDriverConfigPtr= cfg, } =20 static int -qemuBuildVhostuserCommandLine(virQEMUDriverPtr driver, +qemuInterfaceVhostuserConnect(virQEMUDriverPtr driver, virLogManagerPtr logManager, virSecurityManagerPtr secManager, virCommandPtr cmd, virDomainDefPtr def, virDomainNetDefPtr net, virQEMUCapsPtr qemuCaps, - unsigned int bootindex) + char **chardev) { virQEMUDriverConfigPtr cfg =3D virQEMUDriverGetConfig(driver); - char *chardev =3D NULL; - char *netdev =3D NULL; - unsigned int queues =3D net->driver.virtio.queues; - char *nic =3D NULL; int ret =3D -1; =20 - if (!qemuDomainSupportsNicdev(def, net)) { - virReportError(VIR_ERR_INTERNAL_ERROR, - "%s", _("Nicdev support unavailable")); - goto cleanup; - } - switch ((virDomainChrType)net->data.vhostuser->type) { case VIR_DOMAIN_CHR_TYPE_UNIX: - if (!(chardev =3D qemuBuildChrChardevStr(logManager, secManager, - cmd, cfg, def, - net->data.vhostuser, - net->info.alias, qemuCaps, = 0))) + if (!(*chardev =3D qemuBuildChrChardevStr(logManager, secManager, + cmd, cfg, def, + net->data.vhostuser, + net->info.alias, qemuCaps,= 0))) goto cleanup; break; =20 @@ -8274,42 +8264,9 @@ qemuBuildVhostuserCommandLine(virQEMUDriverPtr drive= r, goto cleanup; } =20 - 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 =3D qemuBuildHostNetStr(net, driver, - NULL, 0, NULL, 0))) - goto cleanup; - - if (virNetDevOpenvswitchGetVhostuserIfname(net->data.vhostuser->data.n= ix.path, - &net->ifname) < 0) - goto cleanup; - - virCommandAddArg(cmd, "-chardev"); - virCommandAddArg(cmd, chardev); - - virCommandAddArg(cmd, "-netdev"); - virCommandAddArg(cmd, netdev); - - if (!(nic =3D qemuBuildNicDevStr(def, net, bootindex, - queues, qemuCaps))) { - goto cleanup; - } - - virCommandAddArgList(cmd, "-device", nic, NULL); - ret =3D 0; cleanup: virObjectUnref(cfg); - VIR_FREE(netdev); - VIR_FREE(chardev); - VIR_FREE(nic); - return ret; } =20 @@ -8328,7 +8285,9 @@ qemuBuildInterfaceCommandLine(virQEMUDriverPtr driver, int **nicindexes) { int ret =3D -1; - char *nic =3D NULL, *host =3D NULL; + char *nic =3D NULL; + char *host =3D NULL; + char *chardev =3D NULL; int *tapfd =3D NULL; size_t tapfdSize =3D 0; int *vhostfd =3D NULL; @@ -8337,6 +8296,7 @@ qemuBuildInterfaceCommandLine(virQEMUDriverPtr driver, char **vhostfdName =3D NULL; virDomainNetType actualType =3D virDomainNetGetActualType(net); virNetDevBandwidthPtr actualBandwidth; + bool requireNicdev =3D false; size_t i; =20 =20 @@ -8447,9 +8407,24 @@ qemuBuildInterfaceCommandLine(virQEMUDriverPtr drive= r, break; =20 case VIR_DOMAIN_NET_TYPE_VHOSTUSER: - ret =3D qemuBuildVhostuserCommandLine(driver, logManager, secManag= er, cmd, def, - net, qemuCaps, bootindex); - goto cleanup; + requireNicdev =3D true; + + 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, &charde= v) < 0) + goto cleanup; + + if (virNetDevOpenvswitchGetVhostuserIfname(net->data.vhostuser->da= ta.nix.path, + &net->ifname) < 0) + goto cleanup; + break; =20 case VIR_DOMAIN_NET_TYPE_USER: @@ -8564,6 +8539,9 @@ qemuBuildInterfaceCommandLine(virQEMUDriverPtr driver, goto cleanup; } =20 + if (chardev) + virCommandAddArgList(cmd, "-chardev", chardev, NULL); + if (!(host =3D qemuBuildHostNetStr(net, driver, tapfdName, tapfdSize, vhostfdName, vhostfdSize))) @@ -8578,13 +8556,17 @@ qemuBuildInterfaceCommandLine(virQEMUDriverPtr driv= er, */ if (qemuDomainSupportsNicdev(def, net)) { if (!(nic =3D qemuBuildNicDevStr(def, net, bootindex, - vhostfdSize, qemuCaps))) + net->driver.virtio.queues, qemuCaps= ))) goto cleanup; virCommandAddArgList(cmd, "-device", nic, NULL); - } else { + } else if (!requireNicdev) { if (!(nic =3D qemuBuildLegacyNicStr(net))) goto cleanup; virCommandAddArgList(cmd, "-net", nic, NULL); + } else { + virReportError(VIR_ERR_INTERNAL_ERROR, + "%s", _("Nicdev support unavailable")); + goto cleanup; } =20 ret =3D 0; @@ -8595,24 +8577,25 @@ qemuBuildInterfaceCommandLine(virQEMUDriverPtr driv= er, virSetError(saved_err); virFreeError(saved_err); } - for (i =3D 0; tapfd && i < tapfdSize && tapfd[i] >=3D 0; i++) { - if (ret < 0) - VIR_FORCE_CLOSE(tapfd[i]); - if (tapfdName) - VIR_FREE(tapfdName[i]); - } for (i =3D 0; vhostfd && i < vhostfdSize && vhostfd[i] >=3D 0; i++) { if (ret < 0) VIR_FORCE_CLOSE(vhostfd[i]); if (vhostfdName) VIR_FREE(vhostfdName[i]); } - VIR_FREE(tapfd); + VIR_FREE(vhostfdName); + for (i =3D 0; tapfd && i < tapfdSize && tapfd[i] >=3D 0; i++) { + if (ret < 0) + VIR_FORCE_CLOSE(tapfd[i]); + if (tapfdName) + VIR_FREE(tapfdName[i]); + } + VIR_FREE(tapfdName); VIR_FREE(vhostfd); - VIR_FREE(nic); + VIR_FREE(tapfd); + VIR_FREE(chardev); VIR_FREE(host); - VIR_FREE(tapfdName); - VIR_FREE(vhostfdName); + VIR_FREE(nic); return ret; } =20 --=20 2.18.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list