From nobody Fri Apr 26 10:01:57 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; dkim=fail; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=fail(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1570571358; cv=none; d=zoho.com; s=zohoarc; b=nkYYjkWTvJSAoZLqqOTg/Yo8UVtcUKqs7o3OronlnvcHHPXUpAY8ZcIZDH6D2MZoqjyYdzBEWWIoHJn1WYbnzxnMMYGaDT59zmihhtWMazwIX96bz1ZxHNA+4i3ZcHi1HB9VJdfNZUstaz/giGkW7hSmPiPxqxxxuP+6kCXOi34= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1570571358; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=b1Z6vXofyH9Lsj8QVNFQilmT31GWRH/dk6MI3hcall8=; b=DVwkz7Kt5COJXzs/w+60QZRf/z7LyEX2fFoPPgGfuY6NfwIm7/GmdxrNSFe4qJ4YxBOHf9Np5HrZ/3x658YlPWijxjgl1+E5+5jeFYFJ+r5B7Uu3pczmA8tiem0B3HaY0lGfiXgh1Qisb/srcPU+rk5aJ/ROfcoN0tS2H/gIwLE= ARC-Authentication-Results: i=1; mx.zoho.com; dkim=fail; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1570571358408511.3023119242814; Tue, 8 Oct 2019 14:49:18 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 5B2AD4E924; Tue, 8 Oct 2019 21:49:16 +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 1786460BE0; Tue, 8 Oct 2019 21:49:14 +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 7859E18089DC; Tue, 8 Oct 2019 21:49:13 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x98LnAia026728 for ; Tue, 8 Oct 2019 17:49:10 -0400 Received: by smtp.corp.redhat.com (Postfix) id 8C50C5C21F; Tue, 8 Oct 2019 21:49:10 +0000 (UTC) Received: from mx1.redhat.com (ext-mx19.extmail.prod.ext.phx2.redhat.com [10.5.110.48]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 3A3AA5C223; Tue, 8 Oct 2019 21:49:08 +0000 (UTC) Received: from mail-qt1-f195.google.com (mail-qt1-f195.google.com [209.85.160.195]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 5FD07306729D; Tue, 8 Oct 2019 21:49:07 +0000 (UTC) Received: by mail-qt1-f195.google.com with SMTP id 3so456499qta.1; Tue, 08 Oct 2019 14:49:07 -0700 (PDT) Received: from rekt.ibmuc.com ([2804:431:c7c6:e8e7:3739:3e28:be31:8030]) by smtp.gmail.com with ESMTPSA id l189sm16994qke.69.2019.10.08.14.49.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Oct 2019 14:49:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=MKmC7UcTWk586x/ZNHBob3T+S+eKAPExTonXvwGbiqU=; b=Rwt87cb9qjFsEuUUn/pRhA/gIuMpid/pXxR2cG2F+3Pa0y6rque7uKvQNe0w3wJpBa 05RE6l3z2mFaimWhZFW+wpYA5cM9rzg0svVc3haXd4K4X9kyneSUciW3GVcf+97mLMdQ w3dSRTxT87ae8HL9MdI7ADaC9hKesuExQzLLcSebfqB0CLsJPG02s1bE3RhFJXBUHArf gV9D33Kz1YgJpwVTDcIL/AavDMHffsov3g4i07u0a9Kb5vRbR/ZjyQwVPkiJZFLFVuL4 LUv7h35m1x6jUszR80XFZw+R3nXFMXQMBRuNk2p8ejTz6QyncCAOVN3HddbyG9E46LCb mnvA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=MKmC7UcTWk586x/ZNHBob3T+S+eKAPExTonXvwGbiqU=; b=nVbm/u3C2Gjq1u4EA9T0JHUtbuzIVR6ScEWlnr+OZFqcNqvpzTUF+DtSvSAgCGrB7T ehkSQ5AKqYDOuwoNAO/p/6oyKGqEUEfSrm3XotWCHH2QKEdKTmtgDQy/nYqL7NVuzC4a LEp2385q0Q51+BoshmDgy1IR7BvJ0eZ2b5BknUe/eE3sPZrYxt+NFbyek5JaQCpQAqDi yg4ryLCCfIkZqqoz8lg6c9wqN7oG65IHCYr0IYkpJ1BGKNJnFrMcTIsQ9pJRfAjc0I9P Lyybk5zqY3N622goDdmSPz9KqkTpj+50ljMdA/6pRufIG8vh93Vq1C9cJNrnhRNxTjC4 UDVw== X-Gm-Message-State: APjAAAXZEN13VCsytyaSkBaKslHM6i2i0nf9bsCHrezKYLLvfj7S2bwF dZvE3+gytBo+2H8LfTnKLC1LqZd4 X-Google-Smtp-Source: APXvYqyxSa95ZjQEVGBkjSndAG2vCNFkm9kx04bz/7ogyDHgZrRUEPzWhSykMS5Ocbm0dlo3aKp8qw== X-Received: by 2002:ac8:2813:: with SMTP id 19mr34973qtq.375.1570571346490; Tue, 08 Oct 2019 14:49:06 -0700 (PDT) From: Daniel Henrique Barboza To: libvir-list@redhat.com Date: Tue, 8 Oct 2019 18:48:56 -0300 Message-Id: <20191008214856.16838-2-danielhb413@gmail.com> In-Reply-To: <20191008214856.16838-1-danielhb413@gmail.com> References: <20191008214856.16838-1-danielhb413@gmail.com> MIME-Version: 1.0 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.48]); Tue, 08 Oct 2019 21:49:07 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.48]); Tue, 08 Oct 2019 21:49:07 +0000 (UTC) for IP:'209.85.160.195' DOMAIN:'mail-qt1-f195.google.com' HELO:'mail-qt1-f195.google.com' FROM:'danielhb413@gmail.com' RCPT:'' X-RedHat-Spam-Score: 0.153 (DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, FREEMAIL_ENVFROM_END_DIGIT, FREEMAIL_FROM, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_PASS) 209.85.160.195 mail-qt1-f195.google.com 209.85.160.195 mail-qt1-f195.google.com X-Scanned-By: MIMEDefang 2.84 on 10.5.110.48 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-loop: libvir-list@redhat.com Cc: Daniel Henrique Barboza , jtomko@redhat.com Subject: [libvirt] [PATCH v2 1/1] qemu_command: tidy up qemuBuildHostdevCommandLine loop 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: , Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.38]); Tue, 08 Oct 2019 21:49:17 +0000 (UTC) X-ZohoMail-DKIM: fail (Header signature does not verify) The current 'for' loop with 5 consecutive 'ifs' inside qemuBuildHostdevCommandLine can be a bit smarter: - all 5 'ifs' fails if hostdev->mode is not equal to VIR_DOMAIN_HOSTDEV_MODE_SUBSYS. This check can be moved to the start of the loop, failing to the next element immediately in case it fails; - all 5 'ifs' checks for a specific subsys->type to build the proper command line argument (virHostdevIsSCSIDevice and virHostdevIsMdevDevice do that but within a helper). Problem is that the code will keep checking for matches even if one was already found, and there is no way a hostdev will fit more than one 'if' (i.e. a hostdev can't have 2+ different types). This means that a SUBSYS_TYPE_USB will create its command line argument in the first 'if', then all other conditionals will surely fail but will end up being checked anyway. All of this can be avoided by moving the hostdev->mode comparing to the start of the loop and using a switch statement with subsys->type to execute the proper code for a given hostdev type. Suggested-by: J=C3=A1n Tomko Signed-off-by: Daniel Henrique Barboza --- src/qemu/qemu_command.c | 48 +++++++++++++++++++++++------------------ 1 file changed, 27 insertions(+), 21 deletions(-) diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c index cbf25d5f07..9c3471256c 100644 --- a/src/qemu/qemu_command.c +++ b/src/qemu/qemu_command.c @@ -5463,23 +5463,31 @@ qemuBuildHostdevCommandLine(virCommandPtr cmd, for (i =3D 0; i < def->nhostdevs; i++) { virDomainHostdevDefPtr hostdev =3D def->hostdevs[i]; virDomainHostdevSubsysPtr subsys =3D &hostdev->source.subsys; + virDomainHostdevSubsysSCSIPtr scsisrc; + virDomainHostdevSubsysMediatedDevPtr mdevsrc; VIR_AUTOFREE(char *) devstr =3D NULL; + VIR_AUTOFREE(char *) drvstr =3D NULL; + VIR_AUTOFREE(char *) vhostfdName =3D NULL; + unsigned int bootIndex; + int backend, vhostfd =3D -1; =20 - /* USB */ - if (hostdev->mode =3D=3D VIR_DOMAIN_HOSTDEV_MODE_SUBSYS && - subsys->type =3D=3D VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_USB) { + if (hostdev->mode !=3D VIR_DOMAIN_HOSTDEV_MODE_SUBSYS) + continue; =20 + switch (subsys->type) { + /* USB */ + case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_USB: virCommandAddArg(cmd, "-device"); if (!(devstr =3D qemuBuildUSBHostdevDevStr(def, hostdev, qemuCaps))) return -1; virCommandAddArg(cmd, devstr); - } + + break; =20 /* PCI */ - if (hostdev->mode =3D=3D VIR_DOMAIN_HOSTDEV_MODE_SUBSYS && - subsys->type =3D=3D VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_PCI) { - int backend =3D subsys->u.pci.backend; + case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_PCI: + backend =3D subsys->u.pci.backend; =20 if (backend =3D=3D VIR_DOMAIN_HOSTDEV_PCI_BACKEND_VFIO) { if (!virQEMUCapsGet(qemuCaps, QEMU_CAPS_DEVICE_VFIO_PCI)) { @@ -5490,7 +5498,7 @@ qemuBuildHostdevCommandLine(virCommandPtr cmd, } } =20 - unsigned int bootIndex =3D hostdev->info->bootIndex; + bootIndex =3D hostdev->info->bootIndex; =20 /* bootNet will be non-0 if boot order was set and no other * net devices were encountered @@ -5508,13 +5516,12 @@ qemuBuildHostdevCommandLine(virCommandPtr cmd, if (!devstr) return -1; virCommandAddArg(cmd, devstr); - } + + break; =20 /* SCSI */ - if (virHostdevIsSCSIDevice(hostdev)) { - virDomainHostdevSubsysSCSIPtr scsisrc =3D - &hostdev->source.subsys.u.scsi; - VIR_AUTOFREE(char *) drvstr =3D NULL; + case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_SCSI: + scsisrc =3D &hostdev->source.subsys.u.scsi; =20 if (scsisrc->protocol =3D=3D VIR_DOMAIN_HOSTDEV_SCSI_PROTOCOL_= TYPE_ISCSI) { virDomainHostdevSubsysSCSIiSCSIPtr iscsisrc =3D @@ -5537,15 +5544,13 @@ qemuBuildHostdevCommandLine(virCommandPtr cmd, if (!(devstr =3D qemuBuildSCSIHostdevDevStr(def, hostdev))) return -1; virCommandAddArg(cmd, devstr); - } + + break; =20 /* SCSI_host */ - if (hostdev->mode =3D=3D VIR_DOMAIN_HOSTDEV_MODE_SUBSYS && - subsys->type =3D=3D VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_SCSI_HOST) { + case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_SCSI_HOST: if (hostdev->source.subsys.u.scsi_host.protocol =3D=3D VIR_DOMAIN_HOSTDEV_SUBSYS_SCSI_HOST_PROTOCOL_TYPE_VHOST) { - VIR_AUTOFREE(char *) vhostfdName =3D NULL; - int vhostfd =3D -1; =20 if (virSCSIVHostOpenVhostSCSI(&vhostfd) < 0) return -1; @@ -5567,11 +5572,12 @@ qemuBuildHostdevCommandLine(virCommandPtr cmd, =20 virCommandAddArg(cmd, devstr); } - } + + break; =20 /* MDEV */ - if (virHostdevIsMdevDevice(hostdev)) { - virDomainHostdevSubsysMediatedDevPtr mdevsrc =3D &subsys->u.md= ev; + case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_MDEV: + mdevsrc =3D &subsys->u.mdev; =20 switch ((virMediatedDeviceModelType) mdevsrc->model) { case VIR_MDEV_MODEL_TYPE_VFIO_PCI: --=20 2.21.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list