From nobody Sun May 19 20:29:53 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 ARC-Seal: i=1; a=rsa-sha256; t=1569514436; cv=none; d=zoho.com; s=zohoarc; b=LmI/ey1M/2we2mocb6zOA2XPzfHOFiMNyeK8RBab5c8lw+scU34TsCER7rX/p1AFr9hr8BtPgryGExZHtSQ/Lo7IHaAjs492LiSlHIipNKmU3mX4VlveAGLEJ+kdHQfsxFFuJOvI6eezyCX7rLRLAr5lRThab2GC86JGePaBdYg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1569514436; h=Content-Type:Content-Transfer-Encoding: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:ARC-Authentication-Results; bh=jrDRYogcv7EOwJcPF1ecSaPgrOUEUni3o3z+Chf2w5o=; b=CRGYl1qzac7cT4JyTx4dyAtkioLLH9ctMjeYZkC/OKH1XeOj6jeE7thJ2fhKC4PJkOlvRCbMAiyljiVwnnF82SiOIwf1xCzIE0JGfnbTIiVHsS7088OW7VZ/nivmr72bmFHSXKPWwJmdvlv+klQngta8QWvuB4V6L5GJLxzvgqQ= ARC-Authentication-Results: i=1; mx.zoho.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 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 1569514436544525.4857044745808; Thu, 26 Sep 2019 09:13:56 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id ED5EE8A1CA9; Thu, 26 Sep 2019 16:13:53 +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 C2AF660566; Thu, 26 Sep 2019 16:13:53 +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 7F4EB180B780; Thu, 26 Sep 2019 16:13:53 +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 x8QGDVcm003202 for ; Thu, 26 Sep 2019 12:13:31 -0400 Received: by smtp.corp.redhat.com (Postfix) id E448A5D9CD; Thu, 26 Sep 2019 16:13:31 +0000 (UTC) Received: from moe.brq.redhat.com (unknown [10.43.2.30]) by smtp.corp.redhat.com (Postfix) with ESMTP id 6C5EC5D9C3 for ; Thu, 26 Sep 2019 16:13:31 +0000 (UTC) From: Michal Privoznik To: libvir-list@redhat.com Date: Thu, 26 Sep 2019 18:11:57 +0200 Message-Id: <2589fee8324d470a7c18fcca8acac7cdba40581a.1569514291.git.mprivozn@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v2 01/39] virhostdev: Fix const correctness of virHostdevIs{PCINet, SCSI, Mdev}Device() 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-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.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.6.2 (mx1.redhat.com [10.5.110.69]); Thu, 26 Sep 2019 16:13:55 +0000 (UTC) Content-Type: text/plain; charset="utf-8" These functions do not change any of the passed hostdevs. They just read them. Signed-off-by: Michal Privoznik Reviewed-by: Cole Robinson --- src/util/virhostdev.c | 6 +++--- src/util/virhostdev.h | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/util/virhostdev.c b/src/util/virhostdev.c index 41fcab7222..90967b7c7a 100644 --- a/src/util/virhostdev.c +++ b/src/util/virhostdev.c @@ -354,7 +354,7 @@ virHostdevNetDevice(virDomainHostdevDefPtr hostdev, =20 =20 static bool -virHostdevIsPCINetDevice(virDomainHostdevDefPtr hostdev) +virHostdevIsPCINetDevice(const virDomainHostdevDef *hostdev) { return hostdev->mode =3D=3D VIR_DOMAIN_HOSTDEV_MODE_SUBSYS && hostdev->source.subsys.type =3D=3D VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_= PCI && @@ -369,7 +369,7 @@ virHostdevIsPCINetDevice(virDomainHostdevDefPtr hostdev) * Returns true if @hostdev is a SCSI device, false otherwise. */ bool -virHostdevIsSCSIDevice(virDomainHostdevDefPtr hostdev) +virHostdevIsSCSIDevice(const virDomainHostdevDef *hostdev) { return hostdev->mode =3D=3D VIR_DOMAIN_HOSTDEV_MODE_SUBSYS && hostdev->source.subsys.type =3D=3D VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_= SCSI; @@ -383,7 +383,7 @@ virHostdevIsSCSIDevice(virDomainHostdevDefPtr hostdev) * Returns true if @hostdev is a Mediated device, false otherwise. */ bool -virHostdevIsMdevDevice(virDomainHostdevDefPtr hostdev) +virHostdevIsMdevDevice(const virDomainHostdevDef *hostdev) { return hostdev->mode =3D=3D VIR_DOMAIN_HOSTDEV_MODE_SUBSYS && hostdev->source.subsys.type =3D=3D VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_= MDEV; diff --git a/src/util/virhostdev.h b/src/util/virhostdev.h index 88501e2743..8d7b8c3284 100644 --- a/src/util/virhostdev.h +++ b/src/util/virhostdev.h @@ -185,10 +185,10 @@ virHostdevReAttachDomainDevices(virHostdevManagerPtr = mgr, const char *oldStateDir) ATTRIBUTE_NONNULL(2) ATTRIBUTE_NONNULL(3); bool -virHostdevIsSCSIDevice(virDomainHostdevDefPtr hostdev) +virHostdevIsSCSIDevice(const virDomainHostdevDef *hostdev) ATTRIBUTE_NONNULL(1); bool -virHostdevIsMdevDevice(virDomainHostdevDefPtr hostdev) +virHostdevIsMdevDevice(const virDomainHostdevDef *hostdev) ATTRIBUTE_NONNULL(1); =20 /* functions used by NodeDevDetach/Reattach/Reset */ --=20 2.21.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Sun May 19 20:29:53 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 ARC-Seal: i=1; a=rsa-sha256; t=1569514420; cv=none; d=zoho.com; s=zohoarc; b=k7jc85AYJMvl7meQqrS397vV8wCvwWYOubP7z/kU0nw/7jOYXi26Gr4cHWKhnMeVbs/EGCBwe/kwGG1BBG0SDst0nm21uqyFljc6zkBEtSut0Y07HvEGCFuwZm1klYCtymjdsJd4HEQWXY1/eTjrHypRN/UbikETijH75S35mTY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1569514420; h=Content-Type:Content-Transfer-Encoding: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:ARC-Authentication-Results; bh=s48qBkBKfcBfAww9PkLb0neFOLrb8Gva4Z0i7w7zs54=; b=XOi97MkH28AXzgbuvYU7hBeY/EUsRfiwriZYQwfSAsjz7Lb51rTCpmyH8hNVKsWj423TRaB1rSk/OzKMk/DB80Dofxdpq9AzN1ZOFmJRg9ElzBaMjyBNapFQtL7YqlBLfESALa1wn7OavoV48/x1i1SN2q7+caff4MEubxMk/5E= ARC-Authentication-Results: i=1; mx.zoho.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 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 156951442043513.878241171643936; Thu, 26 Sep 2019 09:13:40 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id C839B2A09A1; Thu, 26 Sep 2019 16:13:38 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id A41055D6B0; Thu, 26 Sep 2019 16:13:38 +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 5A9834EE6A; Thu, 26 Sep 2019 16:13:38 +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 x8QGDbF0003223 for ; Thu, 26 Sep 2019 12:13:37 -0400 Received: by smtp.corp.redhat.com (Postfix) id 10E165D9C3; Thu, 26 Sep 2019 16:13:37 +0000 (UTC) Received: from moe.brq.redhat.com (unknown [10.43.2.30]) by smtp.corp.redhat.com (Postfix) with ESMTP id 8E0DE5D9D5 for ; Thu, 26 Sep 2019 16:13:32 +0000 (UTC) From: Michal Privoznik To: libvir-list@redhat.com Date: Thu, 26 Sep 2019 18:11:58 +0200 Message-Id: <7f6e1636b3c231c955656e83de32772c3d3b93c0.1569514291.git.mprivozn@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v2 02/39] virhostdev: Introduce and use virHostdevIsVFIODevice 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-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.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.38]); Thu, 26 Sep 2019 16:13:39 +0000 (UTC) Content-Type: text/plain; charset="utf-8" In some places we need to check if a hostdev has VFIO backend. Because of how complicated virDomainHostdevDef structure is, the check consists of three lines. Move them to a function and replace all checks with the function call. Signed-off-by: Michal Privoznik Reviewed-by: Cole Robinson --- src/conf/domain_conf.c | 5 +---- src/libvirt_private.syms | 1 + src/qemu/qemu_cgroup.c | 4 +--- src/qemu/qemu_domain.c | 12 +++--------- src/qemu/qemu_hotplug.c | 8 +------- src/util/virhostdev.c | 15 +++++++++++++++ src/util/virhostdev.h | 3 +++ 7 files changed, 25 insertions(+), 23 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index c290baf953..adf8455579 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -31550,10 +31550,7 @@ virDomainDefHasVFIOHostdev(const virDomainDef *def) size_t i; =20 for (i =3D 0; i < def->nhostdevs; i++) { - const virDomainHostdevDef *tmp =3D def->hostdevs[i]; - if (tmp->mode =3D=3D VIR_DOMAIN_HOSTDEV_MODE_SUBSYS && - tmp->source.subsys.type =3D=3D VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_= PCI && - tmp->source.subsys.u.pci.backend =3D=3D VIR_DOMAIN_HOSTDEV_PCI= _BACKEND_VFIO) + if (virHostdevIsVFIODevice(def->hostdevs[i])) return true; } =20 diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index 287e63bffa..ac37aea626 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -2104,6 +2104,7 @@ virHostCPUStatsAssign; virHostdevFindUSBDevice; virHostdevIsMdevDevice; virHostdevIsSCSIDevice; +virHostdevIsVFIODevice; virHostdevManagerGetDefault; virHostdevPCINodeDeviceDetach; virHostdevPCINodeDeviceReAttach; diff --git a/src/qemu/qemu_cgroup.c b/src/qemu/qemu_cgroup.c index 740a1b33dc..318157dab0 100644 --- a/src/qemu/qemu_cgroup.c +++ b/src/qemu/qemu_cgroup.c @@ -413,9 +413,7 @@ qemuTeardownHostdevCgroup(virDomainObjPtr vm, if (!virCgroupHasController(priv->cgroup, VIR_CGROUP_CONTROLLER_DEVICE= S)) return 0; =20 - if (dev->mode =3D=3D VIR_DOMAIN_HOSTDEV_MODE_SUBSYS && - dev->source.subsys.type =3D=3D VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_PCI = && - dev->source.subsys.u.pci.backend =3D=3D VIR_DOMAIN_HOSTDEV_PCI_BAC= KEND_VFIO && + if (virHostdevIsVFIODevice(dev) && qemuDomainGetHostdevPath(vm->def, dev, true, &npaths, &path, NULL) < 0) goto cleanup; diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c index 2aa2164953..824bca89f4 100644 --- a/src/qemu/qemu_domain.c +++ b/src/qemu/qemu_domain.c @@ -11871,9 +11871,7 @@ getPPC64MemLockLimitBytes(virDomainDefPtr def) for (i =3D 0; i < def->nhostdevs; i++) { virDomainHostdevDefPtr dev =3D def->hostdevs[i]; =20 - if (dev->mode =3D=3D VIR_DOMAIN_HOSTDEV_MODE_SUBSYS && - dev->source.subsys.type =3D=3D VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_= PCI && - dev->source.subsys.u.pci.backend =3D=3D VIR_DOMAIN_HOSTDEV_PCI= _BACKEND_VFIO) { + if (virHostdevIsVFIODevice(dev)) { usesVFIO =3D true; =20 pciAddr =3D &dev->source.subsys.u.pci.addr; @@ -12025,12 +12023,8 @@ qemuDomainGetMemLockLimitBytes(virDomainDefPtr def) * Note that this may not be valid for all platforms. */ for (i =3D 0; i < def->nhostdevs; i++) { - virDomainHostdevSubsysPtr subsys =3D &def->hostdevs[i]->source.sub= sys; - - if (def->hostdevs[i]->mode =3D=3D VIR_DOMAIN_HOSTDEV_MODE_SUBSYS && - (subsys->type =3D=3D VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_MDEV || - (subsys->type =3D=3D VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_PCI && - subsys->u.pci.backend =3D=3D VIR_DOMAIN_HOSTDEV_PCI_BACKEND_= VFIO))) { + if (virHostdevIsVFIODevice(def->hostdevs[i]) || + virHostdevIsMdevDevice(def->hostdevs[i])) { memKB =3D virDomainDefGetMemoryTotal(def) + 1024 * 1024; goto done; } diff --git a/src/qemu/qemu_hotplug.c b/src/qemu/qemu_hotplug.c index e9285f0964..5f92c61aa9 100644 --- a/src/qemu/qemu_hotplug.c +++ b/src/qemu/qemu_hotplug.c @@ -4440,16 +4440,10 @@ qemuDomainRemoveHostDevice(virQEMUDriverPtr driver, qemuDomainObjPrivatePtr priv =3D vm->privateData; VIR_AUTOFREE(char *) drivealias =3D NULL; VIR_AUTOFREE(char *) objAlias =3D NULL; - bool is_vfio =3D false; =20 VIR_DEBUG("Removing host device %s from domain %p %s", hostdev->info->alias, vm, vm->def->name); =20 - if (hostdev->source.subsys.type =3D=3D VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_= PCI) { - int backend =3D hostdev->source.subsys.u.pci.backend; - is_vfio =3D backend =3D=3D VIR_DOMAIN_HOSTDEV_PCI_BACKEND_VFIO; - } - if (hostdev->source.subsys.type =3D=3D VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_= SCSI) { virDomainHostdevSubsysSCSIPtr scsisrc =3D &hostdev->source.subsys.= u.scsi; virDomainHostdevSubsysSCSIiSCSIPtr iscsisrc =3D &scsisrc->u.iscsi; @@ -4497,7 +4491,7 @@ qemuDomainRemoveHostDevice(virQEMUDriverPtr driver, =20 virDomainAuditHostdev(vm, hostdev, "detach", true); =20 - if (!is_vfio && + if (!virHostdevIsVFIODevice(hostdev) && qemuSecurityRestoreHostdevLabel(driver, vm, hostdev) < 0) VIR_WARN("Failed to restore host device labelling"); =20 diff --git a/src/util/virhostdev.c b/src/util/virhostdev.c index 90967b7c7a..85812423b5 100644 --- a/src/util/virhostdev.c +++ b/src/util/virhostdev.c @@ -390,6 +390,21 @@ virHostdevIsMdevDevice(const virDomainHostdevDef *host= dev) } =20 =20 +/** + * virHostdevIsVFIODevice: + * @hostdev: host device to check + * + * Returns true if @hostdev is a PCI device with VFIO backend, false other= wise. + */ +bool +virHostdevIsVFIODevice(const virDomainHostdevDef *hostdev) +{ + return hostdev->mode =3D=3D VIR_DOMAIN_HOSTDEV_MODE_SUBSYS && + hostdev->source.subsys.type =3D=3D VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_= PCI && + hostdev->source.subsys.u.pci.backend =3D=3D VIR_DOMAIN_HOSTDEV_PCI= _BACKEND_VFIO; +} + + static int virHostdevNetConfigVirtPortProfile(const char *linkdev, int vf, virNetDevVPortProfilePtr virtPort, diff --git a/src/util/virhostdev.h b/src/util/virhostdev.h index 8d7b8c3284..c7ef2055c1 100644 --- a/src/util/virhostdev.h +++ b/src/util/virhostdev.h @@ -190,6 +190,9 @@ virHostdevIsSCSIDevice(const virDomainHostdevDef *hostd= ev) bool virHostdevIsMdevDevice(const virDomainHostdevDef *hostdev) ATTRIBUTE_NONNULL(1); +bool +virHostdevIsVFIODevice(const virDomainHostdevDef *hostdev) + ATTRIBUTE_NONNULL(1); =20 /* functions used by NodeDevDetach/Reattach/Reset */ int virHostdevPCINodeDeviceDetach(virHostdevManagerPtr mgr, --=20 2.21.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Sun May 19 20:29:53 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 ARC-Seal: i=1; a=rsa-sha256; t=1569514449; cv=none; d=zoho.com; s=zohoarc; b=KtLIvzqMZRelTPkL6YaK0s//GYjTVUpndD41DA9EXKHmdBD3EnIVM/++x1HtsV6UBE1Y9MFOXvETAXyQZhs4k8ilc/XIa6klE821W8AFKwhsVEeOnmlczJDOwdQsl2kP7VKHdASE6cUj5xYPGwRSMIydj22X71jAntDeMUPRnLw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1569514449; h=Content-Type:Content-Transfer-Encoding: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:ARC-Authentication-Results; bh=UFreNzBjVLLW5B7gaXwcdVTMpUsaN9//GcG1xOtmWig=; b=lPq5sexPwrqd1APQy2TP70xVce1SHOPBdWmYE/pqXuHJ5OT2fQ0UqTosho7PCcILRey3EwNVdpq1uJ+tWSHn9jpuEDF/+jIlkr2gZvpECtyxSOYDHf/1W4dk3g8zsf+KXW3tSPJG71HzptGfag7ImmSe9I+AILH3hoktCaKxBS0= ARC-Authentication-Results: i=1; mx.zoho.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 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 1569514449165654.0272595878462; Thu, 26 Sep 2019 09:14:09 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 8F05F7BDA1; Thu, 26 Sep 2019 16:14:06 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 700715D6B2; Thu, 26 Sep 2019 16:14:06 +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 376E24EE72; Thu, 26 Sep 2019 16:14:06 +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 x8QGDdtn003234 for ; Thu, 26 Sep 2019 12:13:39 -0400 Received: by smtp.corp.redhat.com (Postfix) id 81F715D9C3; Thu, 26 Sep 2019 16:13:39 +0000 (UTC) Received: from moe.brq.redhat.com (unknown [10.43.2.30]) by smtp.corp.redhat.com (Postfix) with ESMTP id 0CC9D5D9CD for ; Thu, 26 Sep 2019 16:13:37 +0000 (UTC) From: Michal Privoznik To: libvir-list@redhat.com Date: Thu, 26 Sep 2019 18:11:59 +0200 Message-Id: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v2 03/39] conf: Introduce virDomainDefHasMdevHostdev 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-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.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Thu, 26 Sep 2019 16:14:07 +0000 (UTC) Content-Type: text/plain; charset="utf-8" Signed-off-by: Michal Privoznik Reviewed-by: Cole Robinson --- src/conf/domain_conf.c | 14 ++++++++++++++ src/conf/domain_conf.h | 3 +++ src/libvirt_private.syms | 1 + 3 files changed, 18 insertions(+) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index adf8455579..c1769f743b 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -31558,6 +31558,20 @@ virDomainDefHasVFIOHostdev(const virDomainDef *def) } =20 =20 +bool +virDomainDefHasMdevHostdev(const virDomainDef *def) +{ + size_t i; + + for (i =3D 0; i < def->nhostdevs; i++) { + if (virHostdevIsMdevDevice(def->hostdevs[i])) + return true; + } + + return false; +} + + /** * virDomainGraphicsDefHasOpenGL: * @def: domain definition diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h index 53bdee22fb..bf5d1a154b 100644 --- a/src/conf/domain_conf.h +++ b/src/conf/domain_conf.h @@ -3669,6 +3669,9 @@ virDomainDefHasManagedPR(const virDomainDef *def); bool virDomainDefHasVFIOHostdev(const virDomainDef *def); =20 +bool +virDomainDefHasMdevHostdev(const virDomainDef *def); + bool virDomainGraphicsDefHasOpenGL(const virDomainDef *def); =20 diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index ac37aea626..de124eb37b 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -294,6 +294,7 @@ virDomainDefGetVcpusMax; virDomainDefGetVcpusTopology; virDomainDefHasDeviceAddress; virDomainDefHasManagedPR; +virDomainDefHasMdevHostdev; virDomainDefHasMemballoon; virDomainDefHasMemoryHotplug; virDomainDefHasUSB; --=20 2.21.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Sun May 19 20:29:53 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 ARC-Seal: i=1; a=rsa-sha256; t=1569514425; cv=none; d=zoho.com; s=zohoarc; b=Yh1JTvCHcjO9eCSgXgvh1a9RAyAFJgTi8Bblv8I/Uoe7jwRjrH1ARt6je1r3AdcWRRi9YIKKfpoVD4cIK24X/pezwUs421SLEu2mSsX8eroKbTaTVo39CQop0F000lodZ2vNoYmBWfcKEATQChbnT7H6p/yNe60S+z2NUvOh2x8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1569514425; h=Content-Type:Content-Transfer-Encoding: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:ARC-Authentication-Results; bh=uwMXdBMXok60BlKq5XUP0ZbiRaWwru5Nfiiw7crx5Wk=; b=a9w9Q0IxvQLOq64U5Aw+6iNsFxd6pHCGnB1OTuE4mtH98iBHI/WSp/A1M7DHpIybt76LtK57NB+t3C5GXyIO85caL4jVHnVyvU99kcV844lQv7sjI7FtSsAZKrtCONGLuYdP0ZiYdSSGm96ecLrMe74d6sFDOf57HHk5dnrWUd4= ARC-Authentication-Results: i=1; mx.zoho.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 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 1569514425339218.9353245553243; Thu, 26 Sep 2019 09:13:45 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id C0E49A44AE6; Thu, 26 Sep 2019 16:13:43 +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 9A3EA5D6B0; Thu, 26 Sep 2019 16:13:43 +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 547DC1803517; Thu, 26 Sep 2019 16:13:43 +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 x8QGDe9F003240 for ; Thu, 26 Sep 2019 12:13:40 -0400 Received: by smtp.corp.redhat.com (Postfix) id 509215D9CD; Thu, 26 Sep 2019 16:13:40 +0000 (UTC) Received: from moe.brq.redhat.com (unknown [10.43.2.30]) by smtp.corp.redhat.com (Postfix) with ESMTP id CECEC5D9C3 for ; Thu, 26 Sep 2019 16:13:39 +0000 (UTC) From: Michal Privoznik To: libvir-list@redhat.com Date: Thu, 26 Sep 2019 18:12:00 +0200 Message-Id: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v2 04/39] qemu_hostdev: Introduce qemuHostdevNeedsVFIO() 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-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.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.6.2 (mx1.redhat.com [10.5.110.68]); Thu, 26 Sep 2019 16:13:44 +0000 (UTC) Content-Type: text/plain; charset="utf-8" There are two types of host devices that require /dev/vfio/vfio access: 1) PCI devices with VFIO backend 2) Mediated devices Introduce a simple helper that returns true if passed @hostdev falls in either of the categories. Signed-off-by: Michal Privoznik Reviewed-by: Cole Robinson --- src/qemu/qemu_hostdev.c | 9 +++++++++ src/qemu/qemu_hostdev.h | 2 ++ 2 files changed, 11 insertions(+) diff --git a/src/qemu/qemu_hostdev.c b/src/qemu/qemu_hostdev.c index af41c32679..ebbca817b8 100644 --- a/src/qemu/qemu_hostdev.c +++ b/src/qemu/qemu_hostdev.c @@ -118,6 +118,15 @@ qemuHostdevUpdateActiveDomainDevices(virQEMUDriverPtr = driver, return 0; } =20 + +bool +qemuHostdevNeedsVFIO(const virDomainHostdevDef *hostdev) +{ + return virHostdevIsVFIODevice(hostdev) || + virHostdevIsMdevDevice(hostdev); +} + + bool qemuHostdevHostSupportsPassthroughVFIO(void) { diff --git a/src/qemu/qemu_hostdev.h b/src/qemu/qemu_hostdev.h index e99c204961..536069fe8a 100644 --- a/src/qemu/qemu_hostdev.h +++ b/src/qemu/qemu_hostdev.h @@ -24,6 +24,8 @@ #include "qemu_conf.h" #include "domain_conf.h" =20 +bool qemuHostdevNeedsVFIO(const virDomainHostdevDef *hostdev); + bool qemuHostdevHostSupportsPassthroughVFIO(void); =20 int qemuHostdevUpdateActiveMediatedDevices(virQEMUDriverPtr driver, --=20 2.21.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Sun May 19 20:29:53 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 ARC-Seal: i=1; a=rsa-sha256; t=1569514439; cv=none; d=zoho.com; s=zohoarc; b=ImSzydZtWEkLzNqJL8qqXNoePDqZcbf3sA7BCSbTUR5Pbrq07outUVu98axS0NWAwEXTcSwHakzpvK0uyhBR0wIzRzeipiuEcjwwHFzouHa57K76m/k8aJ/2/jfJR2gL479xQl6mrcezsuZJD/b5MMgOoytlOsozC1IJ67JW3T4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1569514439; h=Content-Type:Content-Transfer-Encoding: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:ARC-Authentication-Results; bh=VM91zfHBSQ7FXgk/A/C/6nd5TUXybx0qvtBFCwHDca0=; b=moq+khoXe26YMuEnPCMiy1n9OHQNP62daxlDBpv811iSFiQe63SU+ESUBnVKjBupGOAdsJ8j+CkuRAv8gfYVyvvYxGg4H2o7rRuIKFT90oCNpCk4xNpDUUubcz4Z0EXdt3exNxd7K0WW9XHy34xM2fHVq7UrKhXZcSKe8Li3Q7g= ARC-Authentication-Results: i=1; mx.zoho.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 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 156951443903766.34975269854874; Thu, 26 Sep 2019 09:13:59 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 939F87FDFF; Thu, 26 Sep 2019 16:13:57 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 6BB445DA21; Thu, 26 Sep 2019 16:13:57 +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 2D8E84EE6E; Thu, 26 Sep 2019 16:13:57 +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 x8QGDgU1003258 for ; Thu, 26 Sep 2019 12:13:42 -0400 Received: by smtp.corp.redhat.com (Postfix) id AA5D05D9E2; Thu, 26 Sep 2019 16:13:42 +0000 (UTC) Received: from moe.brq.redhat.com (unknown [10.43.2.30]) by smtp.corp.redhat.com (Postfix) with ESMTP id 326E65D9D5 for ; Thu, 26 Sep 2019 16:13:40 +0000 (UTC) From: Michal Privoznik To: libvir-list@redhat.com Date: Thu, 26 Sep 2019 18:12:01 +0200 Message-Id: <083cce894b788ad95dadc042896c6dbd578088da.1569514291.git.mprivozn@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v2 05/39] qemu: Introduce qemuDomainNeedsVFIO 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-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.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.27]); Thu, 26 Sep 2019 16:13:58 +0000 (UTC) Content-Type: text/plain; charset="utf-8" Signed-off-by: Michal Privoznik Reviewed-by: Cole Robinson --- src/qemu/qemu_domain.c | 9 +++++++++ src/qemu/qemu_domain.h | 2 ++ 2 files changed, 11 insertions(+) diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c index 824bca89f4..6502c6191c 100644 --- a/src/qemu/qemu_domain.c +++ b/src/qemu/qemu_domain.c @@ -29,6 +29,7 @@ #include "qemu_dbus.h" #include "qemu_process.h" #include "qemu_capabilities.h" +#include "qemu_hostdev.h" #include "qemu_migration.h" #include "qemu_migration_params.h" #include "qemu_security.h" @@ -12825,6 +12826,14 @@ qemuDomainSupportsVideoVga(virDomainVideoDefPtr vi= deo, } =20 =20 +bool +qemuDomainNeedsVFIO(const virDomainDef *def) +{ + return virDomainDefHasVFIOHostdev(def) || + virDomainDefHasMdevHostdev(def); +} + + /** * qemuDomainGetHostdevPath: * @def: domain definition diff --git a/src/qemu/qemu_domain.h b/src/qemu/qemu_domain.h index 6c490bd9d8..8e3917c205 100644 --- a/src/qemu/qemu_domain.h +++ b/src/qemu/qemu_domain.h @@ -1084,6 +1084,8 @@ int qemuDomainCheckMonitor(virQEMUDriverPtr driver, bool qemuDomainSupportsVideoVga(virDomainVideoDefPtr video, virQEMUCapsPtr qemuCaps); =20 +bool qemuDomainNeedsVFIO(const virDomainDef *def); + int qemuDomainGetHostdevPath(virDomainDefPtr def, virDomainHostdevDefPtr dev, bool teardown, --=20 2.21.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Sun May 19 20:29:53 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 ARC-Seal: i=1; a=rsa-sha256; t=1569514461; cv=none; d=zoho.com; s=zohoarc; b=Ljz+7GNgTM3hW6xgvtmBQoxTaZ1x55EJasizNOeLgAsI4jWJBto/pF74hmrYGg+q0ZmbfnwSjQ1YyyF8mbe1PU45qKC/6q9+oN2TYd+4Fn95/yeJPjlUnTiHvv2NsgNNamiZDHLBW8VWEeHpUSYz/E34CaFYt6pvNtKEirS6FzY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1569514461; h=Content-Type:Content-Transfer-Encoding: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:ARC-Authentication-Results; bh=x3v8C0DQZj0RGXnrBhHHGfa9RAC5oQmxOP2ZvFzTLGI=; b=MOthK1lIX8iH2uEk+lhag8+oBk/TEcPEXT6rE+rOEuxN84PP03oE4yiJD9l1u1foSrEvIrTUWtwsS+vhMCQ3A55q2zh12NbbXjdpKeTQRX1+Zed6wE+x8M60oL7y9sDKzyThVsYoUBzKYLdAUyjJwtzZCqPavHh0NOjgNukaUjg= ARC-Authentication-Results: i=1; mx.zoho.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 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 1569514461599616.7028855646463; Thu, 26 Sep 2019 09:14:21 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id D7EEE30604B1; Thu, 26 Sep 2019 16:14:19 +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 AF5805D9D5; Thu, 26 Sep 2019 16:14:19 +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 6D5F218089C8; Thu, 26 Sep 2019 16:14:19 +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 x8QGDhuf003267 for ; Thu, 26 Sep 2019 12:13:43 -0400 Received: by smtp.corp.redhat.com (Postfix) id 76F9B5D9D5; Thu, 26 Sep 2019 16:13:43 +0000 (UTC) Received: from moe.brq.redhat.com (unknown [10.43.2.30]) by smtp.corp.redhat.com (Postfix) with ESMTP id 013B05D9E2 for ; Thu, 26 Sep 2019 16:13:42 +0000 (UTC) From: Michal Privoznik To: libvir-list@redhat.com Date: Thu, 26 Sep 2019 18:12:02 +0200 Message-Id: <4402acb06d84267b8a5a08b61fd0062686421da6.1569514291.git.mprivozn@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v2 06/39] qemu_cgroup: Teardown Cgroup for more host device types 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-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.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.46]); Thu, 26 Sep 2019 16:14:20 +0000 (UTC) Content-Type: text/plain; charset="utf-8" Since its introduction in v1.0.5-rc1-19-g6e13860cb4 the qemuTeardownHostdevCgroup() does nothing unless the passed hostdev is a PCI device with VFIO backend. This seems unnecessary. Signed-off-by: Michal Privoznik Reviewed-by: Cole Robinson --- src/qemu/qemu_cgroup.c | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/src/qemu/qemu_cgroup.c b/src/qemu/qemu_cgroup.c index 318157dab0..4d6f0c33cd 100644 --- a/src/qemu/qemu_cgroup.c +++ b/src/qemu/qemu_cgroup.c @@ -405,16 +405,10 @@ qemuTeardownHostdevCgroup(virDomainObjPtr vm, size_t i, npaths =3D 0; int rv, ret =3D -1; =20 - /* currently this only does something for PCI devices using vfio - * for device assignment, but it is called for *all* hostdev - * devices. - */ - if (!virCgroupHasController(priv->cgroup, VIR_CGROUP_CONTROLLER_DEVICE= S)) return 0; =20 - if (virHostdevIsVFIODevice(dev) && - qemuDomainGetHostdevPath(vm->def, dev, true, + if (qemuDomainGetHostdevPath(vm->def, dev, true, &npaths, &path, NULL) < 0) goto cleanup; =20 --=20 2.21.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Sun May 19 20:29:53 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 ARC-Seal: i=1; a=rsa-sha256; t=1569514657; cv=none; d=zoho.com; s=zohoarc; b=RYwPh0us2WnGoe6s/M3+MDRJVDK4yzoNbFYiWVKBZFL7gufvHHOFwtrq9i7g1aDwFo4Vm+bV9deipkXswYInJPRK+ya2Cw38yQ6/UdWOS3rkpA0MNYRlNk2z/07reerImYdHkJ3UvisnwNcIV3FrP3tuiYYvFy4HitN1bRo5Z5o= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1569514657; h=Content-Type:Content-Transfer-Encoding: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:ARC-Authentication-Results; bh=Ud8wsB6Nr7L+e4uELG/V41Pqm98T6sQ02PCWO2D7zaA=; b=T/kYedCeG7Ki1LW28GPpvK/7UCjc2eo1GB6fiRur0kl20ny+ghMMNx/aTlWahouOMUk1qFK1ij4WlR+R5QENVdBOHt2x3pvruDjs5dMC8HiNtyhAgdUFdR+u7HqnysEKye16G6x8lXNXiHwISr8LY7uXYSFGz5czey5ffeYWkKY= ARC-Authentication-Results: i=1; mx.zoho.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 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 1569514657316827.6612947685339; Thu, 26 Sep 2019 09:17:37 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 89AC618C4285; Thu, 26 Sep 2019 16:17:35 +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 0D7655D9C3; Thu, 26 Sep 2019 16:17:35 +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 B13BB1803517; Thu, 26 Sep 2019 16:17:34 +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 x8QGDi5B003278 for ; Thu, 26 Sep 2019 12:13:44 -0400 Received: by smtp.corp.redhat.com (Postfix) id 47A365D9CD; Thu, 26 Sep 2019 16:13:44 +0000 (UTC) Received: from moe.brq.redhat.com (unknown [10.43.2.30]) by smtp.corp.redhat.com (Postfix) with ESMTP id C482A5D9C3 for ; Thu, 26 Sep 2019 16:13:43 +0000 (UTC) From: Michal Privoznik To: libvir-list@redhat.com Date: Thu, 26 Sep 2019 18:12:03 +0200 Message-Id: <17d2042edbd096d9c7c550306f785fed229098ee.1569514291.git.mprivozn@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v2 07/39] qemu: Explicitly add/remove /dev/vfio/vfio to/from NS/CGroups 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-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.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.6.2 (mx1.redhat.com [10.5.110.62]); Thu, 26 Sep 2019 16:17:36 +0000 (UTC) Content-Type: text/plain; charset="utf-8" In near future, the decision what to do with /dev/vfio/vfio with respect to domain namespace and CGroup is going to be moved out of qemuDomainGetHostdevPath() because there will be some other types of devices than hostdevs that need access to VFIO. All functions that I'm changing assume that hostdev we are adding/removing to VM is not in the definition yet (because of how qemuDomainNeedsVFIO() is written). Fortunately, this assumption is true. Signed-off-by: Michal Privoznik --- src/qemu/qemu_cgroup.c | 48 +++++++++++++++++++++++++++++++++++++++++- src/qemu/qemu_domain.c | 36 +++++++++++++++++++++++++++++++ 2 files changed, 83 insertions(+), 1 deletion(-) diff --git a/src/qemu/qemu_cgroup.c b/src/qemu/qemu_cgroup.c index 4d6f0c33cd..f110b49d16 100644 --- a/src/qemu/qemu_cgroup.c +++ b/src/qemu/qemu_cgroup.c @@ -25,6 +25,7 @@ #include "qemu_domain.h" #include "qemu_process.h" #include "qemu_extdevice.h" +#include "qemu_hostdev.h" #include "vircgroup.h" #include "virlog.h" #include "viralloc.h" @@ -360,6 +361,17 @@ qemuTeardownInputCgroup(virDomainObjPtr vm, } =20 =20 +/** + * qemuSetupHostdevCgroup: + * vm: domain object + * @dev: device to allow + * + * For given host device @dev allow access to in Cgroups. + * Note, @dev must not be in @vm's definition. + * + * Returns: 0 on success, + * -1 otherwise. + */ int qemuSetupHostdevCgroup(virDomainObjPtr vm, virDomainHostdevDefPtr dev) @@ -386,6 +398,17 @@ qemuSetupHostdevCgroup(virDomainObjPtr vm, goto cleanup; } =20 + if (qemuHostdevNeedsVFIO(dev) && + !qemuDomainNeedsVFIO(vm->def)) { + VIR_DEBUG("Cgroup allow %s perms=3D%d", QEMU_DEV_VFIO, VIR_CGROUP_= DEVICE_RW); + rv =3D virCgroupAllowDevicePath(priv->cgroup, QEMU_DEV_VFIO, + VIR_CGROUP_DEVICE_RW, false); + virDomainAuditCgroupPath(vm, priv->cgroup, "allow", + QEMU_DEV_VFIO, "rw", rv); + if (rv < 0) + goto cleanup; + } + ret =3D 0; =20 cleanup: @@ -396,9 +419,21 @@ qemuSetupHostdevCgroup(virDomainObjPtr vm, return ret; } =20 + +/** + * qemuTeardownHostdevCgroup: + * @vm: doamin object + * @dev: device to tear down + * + * For given host device @dev deny access to it in CGroups. + * Note, @dev must not be in @vm's definition. + * + * Returns: 0 on success, + * -1 otherwise. + */ int qemuTeardownHostdevCgroup(virDomainObjPtr vm, - virDomainHostdevDefPtr dev) + virDomainHostdevDefPtr dev) { qemuDomainObjPrivatePtr priv =3D vm->privateData; char **path =3D NULL; @@ -422,6 +457,17 @@ qemuTeardownHostdevCgroup(virDomainObjPtr vm, goto cleanup; } =20 + if (qemuHostdevNeedsVFIO(dev) && + !qemuDomainNeedsVFIO(vm->def)) { + VIR_DEBUG("Cgroup deny " QEMU_DEV_VFIO); + rv =3D virCgroupDenyDevicePath(priv->cgroup, QEMU_DEV_VFIO, + VIR_CGROUP_DEVICE_RWM, false); + virDomainAuditCgroupPath(vm, priv->cgroup, "deny", + QEMU_DEV_VFIO, "rwm", rv); + if (rv < 0) + goto cleanup; + } + ret =3D 0; cleanup: for (i =3D 0; i < npaths; i++) diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c index 6502c6191c..02b6e590cd 100644 --- a/src/qemu/qemu_domain.c +++ b/src/qemu/qemu_domain.c @@ -13540,6 +13540,10 @@ qemuDomainSetupHostdev(virQEMUDriverConfigPtr cfg = ATTRIBUTE_UNUSED, goto cleanup; } =20 + if (qemuHostdevNeedsVFIO(dev) && + qemuDomainCreateDevice(QEMU_DEV_VFIO, data, false) < 0) + goto cleanup; + ret =3D 0; cleanup: for (i =3D 0; i < npaths; i++) @@ -14576,6 +14580,17 @@ qemuDomainNamespaceTeardownDisk(virDomainObjPtr vm= ATTRIBUTE_UNUSED, } =20 =20 +/** + * qemuDomainNamespaceSetupHostdev: + * @vm: domain object + * @hostdev: hostdev to create in @vm's namespace + * + * For given @hostdev, create its devfs representation (if it has one) in + * domain namespace. Note, @hostdev must not be in @vm's definition. + * + * Returns: 0 on success, + * -1 otherwise. + */ int qemuDomainNamespaceSetupHostdev(virDomainObjPtr vm, virDomainHostdevDefPtr hostdev) @@ -14590,6 +14605,11 @@ qemuDomainNamespaceSetupHostdev(virDomainObjPtr vm, if (qemuDomainNamespaceMknodPaths(vm, (const char **)paths, npaths) < = 0) goto cleanup; =20 + if (qemuHostdevNeedsVFIO(hostdev) && + !qemuDomainNeedsVFIO(vm->def) && + qemuDomainNamespaceMknodPath(vm, QEMU_DEV_VFIO) < 0) + goto cleanup; + ret =3D 0; cleanup: for (i =3D 0; i < npaths; i++) @@ -14599,6 +14619,17 @@ qemuDomainNamespaceSetupHostdev(virDomainObjPtr vm, } =20 =20 +/** + * qemuDomainNamespaceTeardownHostdev: + * @vm: domain object + * @hostdev: hostdev to remove in @vm's namespace + * + * For given @hostdev, remove its devfs representation (if it has one) in + * domain namespace. Note, @hostdev must not be in @vm's definition. + * + * Returns: 0 on success, + * -1 otherwise. + */ int qemuDomainNamespaceTeardownHostdev(virDomainObjPtr vm, virDomainHostdevDefPtr hostdev) @@ -14614,6 +14645,11 @@ qemuDomainNamespaceTeardownHostdev(virDomainObjPtr= vm, if (qemuDomainNamespaceUnlinkPaths(vm, (const char **)paths, npaths) <= 0) goto cleanup; =20 + if (qemuHostdevNeedsVFIO(hostdev) && + !qemuDomainNeedsVFIO(vm->def) && + qemuDomainNamespaceUnlinkPath(vm, QEMU_DEV_VFIO) < 0) + goto cleanup; + ret =3D 0; cleanup: for (i =3D 0; i < npaths; i++) --=20 2.21.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Sun May 19 20:29:53 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 ARC-Seal: i=1; a=rsa-sha256; t=1569514435; cv=none; d=zoho.com; s=zohoarc; b=lIQJ4EITSaHWe3yS4Kf4iVmREk1doa47rbi30F8WQMYw1btF1NsejSpgxJj9SSAdwRqvTWGkWpGg7BIwJyf1ZDHfY8MChTnNVXffWbjw0wSke5FOECso+Am+IkvRa9vPNX2AdPfxIIdvl0KzzZdpKvgv7O2oFZCLjzaxPlJrShU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1569514435; h=Content-Type:Content-Transfer-Encoding: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:ARC-Authentication-Results; bh=LHjj08MylIdUXyEfyMpCz08E1S9lAnoaSN9rn7Klono=; b=ZwyN4UJ/8+SNcM3nJ1/zLeiYG/A0BzgE/FGM0eNjCxfvaMflFtUwJ2o+zwrw/89lB486qL/tgD9eITxPoUObKuZPs3DbYSA0IP6/ZPJojHHojpefC9IKk5ZoapSpxnoyn7FlPQNYF+d6QZszdepM2xg5+bvT+QcZsIM9J3iHiDs= ARC-Authentication-Results: i=1; mx.zoho.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 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 1569514435477831.8051577335099; Thu, 26 Sep 2019 09:13:55 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id B3F1B316D791; Thu, 26 Sep 2019 16:13:53 +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 8EE4161F40; Thu, 26 Sep 2019 16:13:53 +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 4D988180B761; Thu, 26 Sep 2019 16:13:53 +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 x8QGDnGc003299 for ; Thu, 26 Sep 2019 12:13:49 -0400 Received: by smtp.corp.redhat.com (Postfix) id 6F9B05D9DC; Thu, 26 Sep 2019 16:13:49 +0000 (UTC) Received: from moe.brq.redhat.com (unknown [10.43.2.30]) by smtp.corp.redhat.com (Postfix) with ESMTP id EC11D5D9D5 for ; Thu, 26 Sep 2019 16:13:44 +0000 (UTC) From: Michal Privoznik To: libvir-list@redhat.com Date: Thu, 26 Sep 2019 18:12:04 +0200 Message-Id: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v2 08/39] qemu_domain: Drop few useless checks in qemuDomainGetHostdevPath 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-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.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.41]); Thu, 26 Sep 2019 16:13:54 +0000 (UTC) Content-Type: text/plain; charset="utf-8" There are three cases where vir*DeviceGetPath() returns a const string. In these cases, the string is initialized in corresponding vir*DeviceNew() calls which fail if string couldn't be allocated. There's no point in checking the second time if the string is NULL. Signed-off-by: Michal Privoznik Reviewed-by: Cole Robinson --- src/qemu/qemu_domain.c | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c index 02b6e590cd..ca6de24e68 100644 --- a/src/qemu/qemu_domain.c +++ b/src/qemu/qemu_domain.c @@ -12915,8 +12915,7 @@ qemuDomainGetHostdevPath(virDomainDefPtr def, if (!usb) goto cleanup; =20 - if (!(tmpPath =3D (char *)virUSBDeviceGetPath(usb))) - goto cleanup; + tmpPath =3D (char *)virUSBDeviceGetPath(usb); perm =3D VIR_CGROUP_DEVICE_RW; break; =20 @@ -12937,8 +12936,7 @@ qemuDomainGetHostdevPath(virDomainDefPtr def, if (!scsi) goto cleanup; =20 - if (!(tmpPath =3D (char *)virSCSIDeviceGetPath(scsi))) - goto cleanup; + tmpPath =3D (char *)virSCSIDeviceGetPath(scsi); perm =3D virSCSIDeviceGetReadonly(scsi) ? VIR_CGROUP_DEVICE_READ : VIR_CGROUP_DEVICE_RW; } @@ -12950,8 +12948,7 @@ qemuDomainGetHostdevPath(virDomainDefPtr def, if (!(host =3D virSCSIVHostDeviceNew(hostsrc->wwpn))) goto cleanup; =20 - if (!(tmpPath =3D (char *)virSCSIVHostDeviceGetPath(host))) - goto cleanup; + tmpPath =3D (char *)virSCSIVHostDeviceGetPath(host); perm =3D VIR_CGROUP_DEVICE_RW; } break; --=20 2.21.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Sun May 19 20:29:53 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 ARC-Seal: i=1; a=rsa-sha256; t=1569514673; cv=none; d=zoho.com; s=zohoarc; b=Ijw0WZt1QoCFkRuUAfIcf92uRcLNAj64pY70LC5k+V2apbijkY0hmNwNFH358xCYeMgunJ7zpkiwaUi6GWfai2i8rcctWaEl1V7n0eZSO8HiAA+WtxfWkKrNfKZvtEw5DX0jS8P4H2d3Z0suQD1JWOu9PphxX4TplfTJVlkHwz4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1569514673; h=Content-Type:Content-Transfer-Encoding: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:ARC-Authentication-Results; bh=OXWnwFLX0OtucvidpWSxtbP5qa/H6jfc/A4ajujW6u8=; b=J3IknzwOfUWse0DELw1YkL/Wt6zGqihDY2KuWOdN8uTPJWCrS4/R5bEcZEb4O9sworBUlOKjYfNy7xZguOIW/O8lELL5Wsg/2JQemaqBXkUIKhvUmm8/cE8BxG7FPFYQXL/OUHwaLd5bhWGyfwOTLXw5LIBQ9HIu6RUrBndpbIo= ARC-Authentication-Results: i=1; mx.zoho.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 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 1569514673501407.85026990656604; Thu, 26 Sep 2019 09:17:53 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 7A9D7307D851; Thu, 26 Sep 2019 16:17:51 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 54B551001E85; Thu, 26 Sep 2019 16:17:51 +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 127F04EE68; Thu, 26 Sep 2019 16:17:51 +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 x8QGDoig003308 for ; Thu, 26 Sep 2019 12:13:50 -0400 Received: by smtp.corp.redhat.com (Postfix) id 3E7685D9DC; Thu, 26 Sep 2019 16:13:50 +0000 (UTC) Received: from moe.brq.redhat.com (unknown [10.43.2.30]) by smtp.corp.redhat.com (Postfix) with ESMTP id BB8195D9D5 for ; Thu, 26 Sep 2019 16:13:49 +0000 (UTC) From: Michal Privoznik To: libvir-list@redhat.com Date: Thu, 26 Sep 2019 18:12:05 +0200 Message-Id: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v2 09/39] qemuDomainGetHostdevPath: Drop @freeTmpPath 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-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.22 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.48]); Thu, 26 Sep 2019 16:17:51 +0000 (UTC) Content-Type: text/plain; charset="utf-8" The @freeTmpPath boolean is used to determine if @tmpPath holds an allocated memory or is a pointer to a constant string and therefore if it needs to be freed or not when returning from the function. Well, we can unify the way we set @tmpPath so that it always holds an allocated memory and thus always must be freed. Signed-off-by: Michal Privoznik Reviewed-by: Cole Robinson --- src/qemu/qemu_domain.c | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c index ca6de24e68..c903750fa0 100644 --- a/src/qemu/qemu_domain.c +++ b/src/qemu/qemu_domain.c @@ -12871,7 +12871,6 @@ qemuDomainGetHostdevPath(virDomainDefPtr def, virSCSIDevicePtr scsi =3D NULL; virSCSIVHostDevicePtr host =3D NULL; char *tmpPath =3D NULL; - bool freeTmpPath =3D false; bool includeVFIO =3D false; char **tmpPaths =3D NULL; int *tmpPerms =3D NULL; @@ -12894,7 +12893,6 @@ qemuDomainGetHostdevPath(virDomainDefPtr def, =20 if (!(tmpPath =3D virPCIDeviceGetIOMMUGroupDev(pci))) goto cleanup; - freeTmpPath =3D true; =20 perm =3D VIR_CGROUP_DEVICE_RW; if (teardown) { @@ -12915,7 +12913,8 @@ qemuDomainGetHostdevPath(virDomainDefPtr def, if (!usb) goto cleanup; =20 - tmpPath =3D (char *)virUSBDeviceGetPath(usb); + if (VIR_STRDUP(tmpPath, virUSBDeviceGetPath(usb)) < 0) + goto cleanup; perm =3D VIR_CGROUP_DEVICE_RW; break; =20 @@ -12936,7 +12935,8 @@ qemuDomainGetHostdevPath(virDomainDefPtr def, if (!scsi) goto cleanup; =20 - tmpPath =3D (char *)virSCSIDeviceGetPath(scsi); + if (VIR_STRDUP(tmpPath, virSCSIDeviceGetPath(scsi)) < 0) + goto cleanup; perm =3D virSCSIDeviceGetReadonly(scsi) ? VIR_CGROUP_DEVICE_READ : VIR_CGROUP_DEVICE_RW; } @@ -12948,7 +12948,8 @@ qemuDomainGetHostdevPath(virDomainDefPtr def, if (!(host =3D virSCSIVHostDeviceNew(hostsrc->wwpn))) goto cleanup; =20 - tmpPath =3D (char *)virSCSIVHostDeviceGetPath(host); + if (VIR_STRDUP(tmpPath, virSCSIVHostDeviceGetPath(host)) <= 0) + goto cleanup; perm =3D VIR_CGROUP_DEVICE_RW; } break; @@ -12958,7 +12959,6 @@ qemuDomainGetHostdevPath(virDomainDefPtr def, if (!(tmpPath =3D virMediatedDeviceGetIOMMUGroupDev(mdevsrc->u= uidstr))) goto cleanup; =20 - freeTmpPath =3D true; includeVFIO =3D true; perm =3D VIR_CGROUP_DEVICE_RW; break; @@ -13009,8 +13009,7 @@ qemuDomainGetHostdevPath(virDomainDefPtr def, virUSBDeviceFree(usb); virSCSIDeviceFree(scsi); virSCSIVHostDeviceFree(host); - if (freeTmpPath) - VIR_FREE(tmpPath); + VIR_FREE(tmpPath); return ret; } =20 --=20 2.21.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Sun May 19 20:29:53 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 ARC-Seal: i=1; a=rsa-sha256; t=1569514448; cv=none; d=zoho.com; s=zohoarc; b=R2KZ+C1nKiWR6Tgf+U/E157kiOafdZB6eTVlXxuRXM2mjntNglSV0NWicHkklxiVaXCLSRcTI59maKvIXmgeqqIRITTEySW8+4pxJHiRl3Va3wErvxFa5UCSRDn1c8RpcdZHLgz5GGvVtJwYBjAecJDLdHkMV3kukWWyPisHYPY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1569514448; h=Content-Type:Content-Transfer-Encoding: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:ARC-Authentication-Results; bh=m/82C8sTiCVatVpDWDOtHhoTRFrNGUcYXeaCd7zxAuk=; b=auQuMclBAlsv1VnANwg+GMGM5Hj4Cq9gjpvkMguEwtSySk+ErIJb0jZ5mM7K96i8tgrxRsxALG3GY6U/Ed02cGynQAeOnVTO4l/thrOfxj3AsyTwL9BIaGmFitka/3tVkQVlnpaEbL5LBCpdPRqYK/MVfOhgXvimhdSpEDpKBwA= ARC-Authentication-Results: i=1; mx.zoho.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 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 1569514448507496.5552688235699; Thu, 26 Sep 2019 09:14:08 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 94386116BB26; Thu, 26 Sep 2019 16:14:06 +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 711D85D9C3; Thu, 26 Sep 2019 16:14:06 +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 33C351803518; Thu, 26 Sep 2019 16:14:06 +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 x8QGDpvV003316 for ; Thu, 26 Sep 2019 12:13:51 -0400 Received: by smtp.corp.redhat.com (Postfix) id 0FB355D9DC; Thu, 26 Sep 2019 16:13:51 +0000 (UTC) Received: from moe.brq.redhat.com (unknown [10.43.2.30]) by smtp.corp.redhat.com (Postfix) with ESMTP id 8B9335D9D5 for ; Thu, 26 Sep 2019 16:13:50 +0000 (UTC) From: Michal Privoznik To: libvir-list@redhat.com Date: Thu, 26 Sep 2019 18:12:06 +0200 Message-Id: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v2 10/39] qemuDomainGetHostdevPath: Use more VIR_AUTOFREE/VIR_AUTOPTR 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-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.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.6.2 (mx1.redhat.com [10.5.110.65]); Thu, 26 Sep 2019 16:14:07 +0000 (UTC) Content-Type: text/plain; charset="utf-8" There are several variables which could be automatically freed upon return from the function. I'm not changing @tmpPaths (which is a string list) because it is going to be removed in next commit. Signed-off-by: Michal Privoznik Reviewed-by: Cole Robinson --- src/qemu/qemu_domain.c | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c index c903750fa0..d8d2f72bcc 100644 --- a/src/qemu/qemu_domain.c +++ b/src/qemu/qemu_domain.c @@ -12866,14 +12866,14 @@ qemuDomainGetHostdevPath(virDomainDefPtr def, virDomainHostdevSubsysSCSIPtr scsisrc =3D &dev->source.subsys.u.scsi; virDomainHostdevSubsysSCSIVHostPtr hostsrc =3D &dev->source.subsys.u.s= csi_host; virDomainHostdevSubsysMediatedDevPtr mdevsrc =3D &dev->source.subsys.u= .mdev; - virPCIDevicePtr pci =3D NULL; - virUSBDevicePtr usb =3D NULL; - virSCSIDevicePtr scsi =3D NULL; - virSCSIVHostDevicePtr host =3D NULL; - char *tmpPath =3D NULL; + VIR_AUTOPTR(virPCIDevice) pci =3D NULL; + VIR_AUTOPTR(virUSBDevice) usb =3D NULL; + VIR_AUTOPTR(virSCSIDevice) scsi =3D NULL; + VIR_AUTOPTR(virSCSIVHostDevice) host =3D NULL; + VIR_AUTOFREE(char *) tmpPath =3D NULL; bool includeVFIO =3D false; char **tmpPaths =3D NULL; - int *tmpPerms =3D NULL; + VIR_AUTOFREE(int *) tmpPerms =3D NULL; size_t tmpNpaths =3D 0; int perm =3D 0; =20 @@ -13004,12 +13004,6 @@ qemuDomainGetHostdevPath(virDomainDefPtr def, ret =3D 0; cleanup: virStringListFreeCount(tmpPaths, tmpNpaths); - VIR_FREE(tmpPerms); - virPCIDeviceFree(pci); - virUSBDeviceFree(usb); - virSCSIDeviceFree(scsi); - virSCSIVHostDeviceFree(host); - VIR_FREE(tmpPath); return ret; } =20 --=20 2.21.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Sun May 19 20:29:53 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 ARC-Seal: i=1; a=rsa-sha256; t=1569514461; cv=none; d=zoho.com; s=zohoarc; b=homJY/Z9XflxIFD/5pJRp0iHSvm5TaoPCCc10CETEULlM+DJ5Y9oNVYfQG/IIXqHzZ2IvcfQC2SbrikXHGlEoi2U4KslnAh80I+xKfljz/zJ3yuOzet/KMaPNVuV6x1iGu4EQ+XhlGGQYajqFDyyUtsBrB7iNClmIaRNb0M3q1w= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1569514461; h=Content-Type:Content-Transfer-Encoding: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:ARC-Authentication-Results; bh=hHbkPwaO9AyM5yEvl4n00wgt72otsCi5K125XRsSAck=; b=h3JJOTw7EHQuTYpe9XAkZhWMgbPWV5g/g981aQf0Jyb3Cg1/fZc+Xvv7husIcmlfAIkiFygVGiTkYWUCqx+/gE9TzjNBkIFn9MYWtEuSDMABlxxiPhpOqa9AQ0dq2BKvo4z0t12OTU53olnxuW0Ecq5sgsZuf6NYQAZPtNhJrJU= ARC-Authentication-Results: i=1; mx.zoho.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 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 1569514461342727.6837356142686; Thu, 26 Sep 2019 09:14:21 -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 D1AFD10C0958; Thu, 26 Sep 2019 16:14:19 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id ACB9C60F80; Thu, 26 Sep 2019 16:14:19 +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 6A4A24EE69; Thu, 26 Sep 2019 16:14:19 +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 x8QGDpLL003330 for ; Thu, 26 Sep 2019 12:13:51 -0400 Received: by smtp.corp.redhat.com (Postfix) id D182B5D9DC; Thu, 26 Sep 2019 16:13:51 +0000 (UTC) Received: from moe.brq.redhat.com (unknown [10.43.2.30]) by smtp.corp.redhat.com (Postfix) with ESMTP id 597925D9D5 for ; Thu, 26 Sep 2019 16:13:51 +0000 (UTC) From: Michal Privoznik To: libvir-list@redhat.com Date: Thu, 26 Sep 2019 18:12:07 +0200 Message-Id: <520d59ac4fd75c6e3cb3746086d3b1fedf629361.1569514291.git.mprivozn@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v2 11/39] qemuDomainGetHostdevPath: Don't include /dev/vfio/vfio in returned paths 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-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.6.2 (mx1.redhat.com [10.5.110.66]); Thu, 26 Sep 2019 16:14:20 +0000 (UTC) Content-Type: text/plain; charset="utf-8" Now that all callers of qemuDomainGetHostdevPath() handle /dev/vfio/vfio on their own, we can safely drop handling in this function. In near future the decision whether domain needs VFIO file is going to include more device types than just virDomainHostdev. Signed-off-by: Michal Privoznik --- src/qemu/qemu_cgroup.c | 52 ++++++++------------- src/qemu/qemu_domain.c | 100 +++++++++-------------------------------- src/qemu/qemu_domain.h | 9 ++-- 3 files changed, 42 insertions(+), 119 deletions(-) diff --git a/src/qemu/qemu_cgroup.c b/src/qemu/qemu_cgroup.c index f110b49d16..e3ea1e30ab 100644 --- a/src/qemu/qemu_cgroup.c +++ b/src/qemu/qemu_cgroup.c @@ -377,26 +377,23 @@ qemuSetupHostdevCgroup(virDomainObjPtr vm, virDomainHostdevDefPtr dev) { qemuDomainObjPrivatePtr priv =3D vm->privateData; - char **path =3D NULL; - int *perms =3D NULL; - size_t i, npaths =3D 0; + VIR_AUTOFREE(char *) path =3D NULL; + int perms; int rv, ret =3D -1; =20 if (!virCgroupHasController(priv->cgroup, VIR_CGROUP_CONTROLLER_DEVICE= S)) return 0; =20 - if (qemuDomainGetHostdevPath(NULL, dev, false, &npaths, &path, &perms)= < 0) + if (qemuDomainGetHostdevPath(dev, &path, &perms) < 0) goto cleanup; =20 - for (i =3D 0; i < npaths; i++) { - VIR_DEBUG("Cgroup allow %s perms=3D%d", path[i], perms[i]); - rv =3D virCgroupAllowDevicePath(priv->cgroup, path[i], perms[i], f= alse); - virDomainAuditCgroupPath(vm, priv->cgroup, "allow", path[i], - virCgroupGetDevicePermsString(perms[i]), - rv); - if (rv < 0) - goto cleanup; - } + VIR_DEBUG("Cgroup allow %s perms=3D%d", path, perms); + rv =3D virCgroupAllowDevicePath(priv->cgroup, path, perms, false); + virDomainAuditCgroupPath(vm, priv->cgroup, "allow", path, + virCgroupGetDevicePermsString(perms), + rv); + if (rv < 0) + goto cleanup; =20 if (qemuHostdevNeedsVFIO(dev) && !qemuDomainNeedsVFIO(vm->def)) { @@ -412,10 +409,6 @@ qemuSetupHostdevCgroup(virDomainObjPtr vm, ret =3D 0; =20 cleanup: - for (i =3D 0; i < npaths; i++) - VIR_FREE(path[i]); - VIR_FREE(path); - VIR_FREE(perms); return ret; } =20 @@ -436,26 +429,22 @@ qemuTeardownHostdevCgroup(virDomainObjPtr vm, virDomainHostdevDefPtr dev) { qemuDomainObjPrivatePtr priv =3D vm->privateData; - char **path =3D NULL; - size_t i, npaths =3D 0; + VIR_AUTOFREE(char *) path =3D NULL; int rv, ret =3D -1; =20 if (!virCgroupHasController(priv->cgroup, VIR_CGROUP_CONTROLLER_DEVICE= S)) return 0; =20 - if (qemuDomainGetHostdevPath(vm->def, dev, true, - &npaths, &path, NULL) < 0) + if (qemuDomainGetHostdevPath(dev, &path, NULL) < 0) goto cleanup; =20 - for (i =3D 0; i < npaths; i++) { - VIR_DEBUG("Cgroup deny %s", path[i]); - rv =3D virCgroupDenyDevicePath(priv->cgroup, path[i], - VIR_CGROUP_DEVICE_RWM, false); - virDomainAuditCgroupPath(vm, priv->cgroup, - "deny", path[i], "rwm", rv); - if (rv < 0) - goto cleanup; - } + VIR_DEBUG("Cgroup deny %s", path); + rv =3D virCgroupDenyDevicePath(priv->cgroup, path, + VIR_CGROUP_DEVICE_RWM, false); + virDomainAuditCgroupPath(vm, priv->cgroup, + "deny", path, "rwm", rv); + if (rv < 0) + goto cleanup; =20 if (qemuHostdevNeedsVFIO(dev) && !qemuDomainNeedsVFIO(vm->def)) { @@ -470,9 +459,6 @@ qemuTeardownHostdevCgroup(virDomainObjPtr vm, =20 ret =3D 0; cleanup: - for (i =3D 0; i < npaths; i++) - VIR_FREE(path[i]); - VIR_FREE(path); return ret; } =20 diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c index d8d2f72bcc..bfe7838220 100644 --- a/src/qemu/qemu_domain.c +++ b/src/qemu/qemu_domain.c @@ -12836,29 +12836,23 @@ qemuDomainNeedsVFIO(const virDomainDef *def) =20 /** * qemuDomainGetHostdevPath: - * @def: domain definition * @dev: host device definition - * @teardown: true if device will be removed - * @npaths: number of items in @path and @perms arrays * @path: resulting path to @dev * @perms: Optional pointer to VIR_CGROUP_DEVICE_* perms * * For given device @dev fetch its host path and store it at - * @path. If a device requires other paths to be present/allowed - * they are stored in the @path array after the actual path. - * Optionally, caller can get @perms on the path (e.g. rw/ro). + * @path. Optionally, caller can get @perms on the path (e.g. + * rw/ro). * - * The caller is responsible for freeing the memory. + * The caller is responsible for freeing the @path when no longer + * needed. * * Returns 0 on success, -1 otherwise. */ int -qemuDomainGetHostdevPath(virDomainDefPtr def, - virDomainHostdevDefPtr dev, - bool teardown, - size_t *npaths, - char ***path, - int **perms) +qemuDomainGetHostdevPath(virDomainHostdevDefPtr dev, + char **path, + int *perms) { int ret =3D -1; virDomainHostdevSubsysUSBPtr usbsrc =3D &dev->source.subsys.u.usb; @@ -12871,14 +12865,8 @@ qemuDomainGetHostdevPath(virDomainDefPtr def, VIR_AUTOPTR(virSCSIDevice) scsi =3D NULL; VIR_AUTOPTR(virSCSIVHostDevice) host =3D NULL; VIR_AUTOFREE(char *) tmpPath =3D NULL; - bool includeVFIO =3D false; - char **tmpPaths =3D NULL; - VIR_AUTOFREE(int *) tmpPerms =3D NULL; - size_t tmpNpaths =3D 0; int perm =3D 0; =20 - *npaths =3D 0; - switch ((virDomainHostdevMode) dev->mode) { case VIR_DOMAIN_HOSTDEV_MODE_SUBSYS: switch ((virDomainHostdevSubsysType)dev->source.subsys.type) { @@ -12895,12 +12883,6 @@ qemuDomainGetHostdevPath(virDomainDefPtr def, goto cleanup; =20 perm =3D VIR_CGROUP_DEVICE_RW; - if (teardown) { - if (!virDomainDefHasVFIOHostdev(def)) - includeVFIO =3D true; - } else { - includeVFIO =3D true; - } } break; =20 @@ -12959,7 +12941,6 @@ qemuDomainGetHostdevPath(virDomainDefPtr def, if (!(tmpPath =3D virMediatedDeviceGetIOMMUGroupDev(mdevsrc->u= uidstr))) goto cleanup; =20 - includeVFIO =3D true; perm =3D VIR_CGROUP_DEVICE_RW; break; case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_LAST: @@ -12973,37 +12954,11 @@ qemuDomainGetHostdevPath(virDomainDefPtr def, break; } =20 - if (tmpPath) { - size_t toAlloc =3D 1; - - if (includeVFIO) - toAlloc =3D 2; - - if (VIR_ALLOC_N(tmpPaths, toAlloc) < 0 || - VIR_ALLOC_N(tmpPerms, toAlloc) < 0 || - VIR_STRDUP(tmpPaths[0], tmpPath) < 0) - goto cleanup; - tmpNpaths =3D toAlloc; - tmpPerms[0] =3D perm; - - if (includeVFIO) { - if (VIR_STRDUP(tmpPaths[1], QEMU_DEV_VFIO) < 0) - goto cleanup; - tmpPerms[1] =3D VIR_CGROUP_DEVICE_RW; - } - } - - *npaths =3D tmpNpaths; - tmpNpaths =3D 0; - *path =3D tmpPaths; - tmpPaths =3D NULL; - if (perms) { - *perms =3D tmpPerms; - tmpPerms =3D NULL; - } + VIR_STEAL_PTR(*path, tmpPath); + if (perms) + *perms =3D perm; ret =3D 0; cleanup: - virStringListFreeCount(tmpPaths, tmpNpaths); return ret; } =20 @@ -13519,16 +13474,13 @@ qemuDomainSetupHostdev(virQEMUDriverConfigPtr cfg= ATTRIBUTE_UNUSED, const struct qemuDomainCreateDeviceData *data) { int ret =3D -1; - char **path =3D NULL; - size_t i, npaths =3D 0; + VIR_AUTOFREE(char *) path =3D NULL; =20 - if (qemuDomainGetHostdevPath(NULL, dev, false, &npaths, &path, NULL) <= 0) + if (qemuDomainGetHostdevPath(dev, &path, NULL) < 0) goto cleanup; =20 - for (i =3D 0; i < npaths; i++) { - if (qemuDomainCreateDevice(path[i], data, false) < 0) - goto cleanup; - } + if (qemuDomainCreateDevice(path, data, false) < 0) + goto cleanup; =20 if (qemuHostdevNeedsVFIO(dev) && qemuDomainCreateDevice(QEMU_DEV_VFIO, data, false) < 0) @@ -13536,9 +13488,6 @@ qemuDomainSetupHostdev(virQEMUDriverConfigPtr cfg A= TTRIBUTE_UNUSED, =20 ret =3D 0; cleanup: - for (i =3D 0; i < npaths; i++) - VIR_FREE(path[i]); - VIR_FREE(path); return ret; } =20 @@ -14586,13 +14535,12 @@ qemuDomainNamespaceSetupHostdev(virDomainObjPtr v= m, virDomainHostdevDefPtr hostdev) { int ret =3D -1; - char **paths =3D NULL; - size_t i, npaths =3D 0; + VIR_AUTOFREE(char *) path =3D NULL; =20 - if (qemuDomainGetHostdevPath(NULL, hostdev, false, &npaths, &paths, NU= LL) < 0) + if (qemuDomainGetHostdevPath(hostdev, &path, NULL) < 0) goto cleanup; =20 - if (qemuDomainNamespaceMknodPaths(vm, (const char **)paths, npaths) < = 0) + if (qemuDomainNamespaceMknodPath(vm, path) < 0) goto cleanup; =20 if (qemuHostdevNeedsVFIO(hostdev) && @@ -14602,9 +14550,6 @@ qemuDomainNamespaceSetupHostdev(virDomainObjPtr vm, =20 ret =3D 0; cleanup: - for (i =3D 0; i < npaths; i++) - VIR_FREE(paths[i]); - VIR_FREE(paths); return ret; } =20 @@ -14625,14 +14570,12 @@ qemuDomainNamespaceTeardownHostdev(virDomainObjPt= r vm, virDomainHostdevDefPtr hostdev) { int ret =3D -1; - char **paths =3D NULL; - size_t i, npaths =3D 0; + VIR_AUTOFREE(char *) path =3D NULL; =20 - if (qemuDomainGetHostdevPath(vm->def, hostdev, true, - &npaths, &paths, NULL) < 0) + if (qemuDomainGetHostdevPath(hostdev, &path, NULL) < 0) goto cleanup; =20 - if (qemuDomainNamespaceUnlinkPaths(vm, (const char **)paths, npaths) <= 0) + if (qemuDomainNamespaceUnlinkPath(vm, path) < 0) goto cleanup; =20 if (qemuHostdevNeedsVFIO(hostdev) && @@ -14642,9 +14585,6 @@ qemuDomainNamespaceTeardownHostdev(virDomainObjPtr = vm, =20 ret =3D 0; cleanup: - for (i =3D 0; i < npaths; i++) - VIR_FREE(paths[i]); - VIR_FREE(paths); return ret; } =20 diff --git a/src/qemu/qemu_domain.h b/src/qemu/qemu_domain.h index 8e3917c205..de6479f8e0 100644 --- a/src/qemu/qemu_domain.h +++ b/src/qemu/qemu_domain.h @@ -1086,12 +1086,9 @@ bool qemuDomainSupportsVideoVga(virDomainVideoDefPtr= video, =20 bool qemuDomainNeedsVFIO(const virDomainDef *def); =20 -int qemuDomainGetHostdevPath(virDomainDefPtr def, - virDomainHostdevDefPtr dev, - bool teardown, - size_t *npaths, - char ***path, - int **perms); +int qemuDomainGetHostdevPath(virDomainHostdevDefPtr dev, + char **path, + int *perms); =20 int qemuDomainBuildNamespace(virQEMUDriverConfigPtr cfg, virSecurityManagerPtr mgr, --=20 2.21.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Sun May 19 20:29:53 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 ARC-Seal: i=1; a=rsa-sha256; t=1569514474; cv=none; d=zoho.com; s=zohoarc; b=QggNgjMSoGdQL3axupK56rwokijloCFX5xOpIs1XUonhJjn57I1+GW7aKOa2CxwUVi17v8t26fmf/Q76E4UNfNgl976UGJ9vSE2Vs5Suzp6cpA7C/onCXyLw5EBdJoAnryJarxh1VEaX10AH6Vyg12bnhg5OzILbnQjF10jFiEw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1569514474; h=Content-Type:Content-Transfer-Encoding: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:ARC-Authentication-Results; bh=JF4Kf/Pu+l+92TEjAIuz0vbViKPC16gV0bX4nMy9mf8=; b=Iz9dHjhm7SUUtpNgSnRyO5N1zSeWOsMyBDwsn24A6UPLrL4ULmyNq01AmBFFJ6NNIWTWze2tbbRYdXvvhML7ZdHRDkUu1vNI8GH+hI1Aw+VFveAKPYyYPxSzQhQAa2vteqO6UWrN8kp6XMeHEUYvqpvS+pLkmFrGBX3hQ2ug574= ARC-Authentication-Results: i=1; mx.zoho.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 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 1569514474177612.2815288077353; Thu, 26 Sep 2019 09:14:34 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 8CD1010DCC8B; Thu, 26 Sep 2019 16:14:32 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 5F2995D9C3; Thu, 26 Sep 2019 16:14:32 +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 151214EE6D; Thu, 26 Sep 2019 16:14:32 +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 x8QGDs5H003346 for ; Thu, 26 Sep 2019 12:13:54 -0400 Received: by smtp.corp.redhat.com (Postfix) id CAD435D9DC; Thu, 26 Sep 2019 16:13:54 +0000 (UTC) Received: from moe.brq.redhat.com (unknown [10.43.2.30]) by smtp.corp.redhat.com (Postfix) with ESMTP id 5232B5D9E1 for ; Thu, 26 Sep 2019 16:13:52 +0000 (UTC) From: Michal Privoznik To: libvir-list@redhat.com Date: Thu, 26 Sep 2019 18:12:08 +0200 Message-Id: <46d69387570ae2843c186fc53e57ae29be4fe7cd.1569514291.git.mprivozn@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v2 12/39] qemu: Drop some 'cleanup' labels 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-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.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.6.2 (mx1.redhat.com [10.5.110.64]); Thu, 26 Sep 2019 16:14:33 +0000 (UTC) Content-Type: text/plain; charset="utf-8" Previous patches rendered some of 'cleanup' labels needless. Drop them. Signed-off-by: Michal Privoznik --- src/qemu/qemu_cgroup.c | 25 ++++++++----------- src/qemu/qemu_domain.c | 56 +++++++++++++++++------------------------- 2 files changed, 32 insertions(+), 49 deletions(-) diff --git a/src/qemu/qemu_cgroup.c b/src/qemu/qemu_cgroup.c index e3ea1e30ab..9684bf3662 100644 --- a/src/qemu/qemu_cgroup.c +++ b/src/qemu/qemu_cgroup.c @@ -379,13 +379,13 @@ qemuSetupHostdevCgroup(virDomainObjPtr vm, qemuDomainObjPrivatePtr priv =3D vm->privateData; VIR_AUTOFREE(char *) path =3D NULL; int perms; - int rv, ret =3D -1; + int rv; =20 if (!virCgroupHasController(priv->cgroup, VIR_CGROUP_CONTROLLER_DEVICE= S)) return 0; =20 if (qemuDomainGetHostdevPath(dev, &path, &perms) < 0) - goto cleanup; + return -1; =20 VIR_DEBUG("Cgroup allow %s perms=3D%d", path, perms); rv =3D virCgroupAllowDevicePath(priv->cgroup, path, perms, false); @@ -393,7 +393,7 @@ qemuSetupHostdevCgroup(virDomainObjPtr vm, virCgroupGetDevicePermsString(perms), rv); if (rv < 0) - goto cleanup; + return -1; =20 if (qemuHostdevNeedsVFIO(dev) && !qemuDomainNeedsVFIO(vm->def)) { @@ -403,13 +403,10 @@ qemuSetupHostdevCgroup(virDomainObjPtr vm, virDomainAuditCgroupPath(vm, priv->cgroup, "allow", QEMU_DEV_VFIO, "rw", rv); if (rv < 0) - goto cleanup; + return -1; } =20 - ret =3D 0; - - cleanup: - return ret; + return 0; } =20 =20 @@ -430,13 +427,13 @@ qemuTeardownHostdevCgroup(virDomainObjPtr vm, { qemuDomainObjPrivatePtr priv =3D vm->privateData; VIR_AUTOFREE(char *) path =3D NULL; - int rv, ret =3D -1; + int rv; =20 if (!virCgroupHasController(priv->cgroup, VIR_CGROUP_CONTROLLER_DEVICE= S)) return 0; =20 if (qemuDomainGetHostdevPath(dev, &path, NULL) < 0) - goto cleanup; + return -1; =20 VIR_DEBUG("Cgroup deny %s", path); rv =3D virCgroupDenyDevicePath(priv->cgroup, path, @@ -444,7 +441,7 @@ qemuTeardownHostdevCgroup(virDomainObjPtr vm, virDomainAuditCgroupPath(vm, priv->cgroup, "deny", path, "rwm", rv); if (rv < 0) - goto cleanup; + return -1; =20 if (qemuHostdevNeedsVFIO(dev) && !qemuDomainNeedsVFIO(vm->def)) { @@ -454,12 +451,10 @@ qemuTeardownHostdevCgroup(virDomainObjPtr vm, virDomainAuditCgroupPath(vm, priv->cgroup, "deny", QEMU_DEV_VFIO, "rwm", rv); if (rv < 0) - goto cleanup; + return -1; } =20 - ret =3D 0; - cleanup: - return ret; + return 0; } =20 =20 diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c index bfe7838220..e92c2053c1 100644 --- a/src/qemu/qemu_domain.c +++ b/src/qemu/qemu_domain.c @@ -12854,7 +12854,6 @@ qemuDomainGetHostdevPath(virDomainHostdevDefPtr dev, char **path, int *perms) { - int ret =3D -1; virDomainHostdevSubsysUSBPtr usbsrc =3D &dev->source.subsys.u.usb; virDomainHostdevSubsysPCIPtr pcisrc =3D &dev->source.subsys.u.pci; virDomainHostdevSubsysSCSIPtr scsisrc =3D &dev->source.subsys.u.scsi; @@ -12877,10 +12876,10 @@ qemuDomainGetHostdevPath(virDomainHostdevDefPtr d= ev, pcisrc->addr.slot, pcisrc->addr.function); if (!pci) - goto cleanup; + return -1; =20 if (!(tmpPath =3D virPCIDeviceGetIOMMUGroupDev(pci))) - goto cleanup; + return -1; =20 perm =3D VIR_CGROUP_DEVICE_RW; } @@ -12893,10 +12892,10 @@ qemuDomainGetHostdevPath(virDomainHostdevDefPtr d= ev, usbsrc->device, NULL); if (!usb) - goto cleanup; + return -1; =20 if (VIR_STRDUP(tmpPath, virUSBDeviceGetPath(usb)) < 0) - goto cleanup; + return -1; perm =3D VIR_CGROUP_DEVICE_RW; break; =20 @@ -12915,10 +12914,10 @@ qemuDomainGetHostdevPath(virDomainHostdevDefPtr d= ev, dev->shareable); =20 if (!scsi) - goto cleanup; + return -1; =20 if (VIR_STRDUP(tmpPath, virSCSIDeviceGetPath(scsi)) < 0) - goto cleanup; + return -1; perm =3D virSCSIDeviceGetReadonly(scsi) ? VIR_CGROUP_DEVICE_READ : VIR_CGROUP_DEVICE_RW; } @@ -12928,10 +12927,10 @@ qemuDomainGetHostdevPath(virDomainHostdevDefPtr d= ev, if (hostsrc->protocol =3D=3D VIR_DOMAIN_HOSTDEV_SUBSYS_SCSI_HOST_PROTOCOL_TYPE_VHOST) { if (!(host =3D virSCSIVHostDeviceNew(hostsrc->wwpn))) - goto cleanup; + return -1; =20 if (VIR_STRDUP(tmpPath, virSCSIVHostDeviceGetPath(host)) <= 0) - goto cleanup; + return -1; perm =3D VIR_CGROUP_DEVICE_RW; } break; @@ -12939,7 +12938,7 @@ qemuDomainGetHostdevPath(virDomainHostdevDefPtr dev, =20 case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_MDEV: if (!(tmpPath =3D virMediatedDeviceGetIOMMUGroupDev(mdevsrc->u= uidstr))) - goto cleanup; + return -1; =20 perm =3D VIR_CGROUP_DEVICE_RW; break; @@ -12957,9 +12956,7 @@ qemuDomainGetHostdevPath(virDomainHostdevDefPtr dev, VIR_STEAL_PTR(*path, tmpPath); if (perms) *perms =3D perm; - ret =3D 0; - cleanup: - return ret; + return 0; } =20 =20 @@ -13473,22 +13470,19 @@ qemuDomainSetupHostdev(virQEMUDriverConfigPtr cfg= ATTRIBUTE_UNUSED, virDomainHostdevDefPtr dev, const struct qemuDomainCreateDeviceData *data) { - int ret =3D -1; VIR_AUTOFREE(char *) path =3D NULL; =20 if (qemuDomainGetHostdevPath(dev, &path, NULL) < 0) - goto cleanup; + return -1; =20 if (qemuDomainCreateDevice(path, data, false) < 0) - goto cleanup; + return -1; =20 if (qemuHostdevNeedsVFIO(dev) && qemuDomainCreateDevice(QEMU_DEV_VFIO, data, false) < 0) - goto cleanup; + return -1; =20 - ret =3D 0; - cleanup: - return ret; + return 0; } =20 =20 @@ -14534,23 +14528,20 @@ int qemuDomainNamespaceSetupHostdev(virDomainObjPtr vm, virDomainHostdevDefPtr hostdev) { - int ret =3D -1; VIR_AUTOFREE(char *) path =3D NULL; =20 if (qemuDomainGetHostdevPath(hostdev, &path, NULL) < 0) - goto cleanup; + return -1; =20 if (qemuDomainNamespaceMknodPath(vm, path) < 0) - goto cleanup; + return -1; =20 if (qemuHostdevNeedsVFIO(hostdev) && !qemuDomainNeedsVFIO(vm->def) && qemuDomainNamespaceMknodPath(vm, QEMU_DEV_VFIO) < 0) - goto cleanup; + return -1; =20 - ret =3D 0; - cleanup: - return ret; + return 0; } =20 =20 @@ -14569,23 +14560,20 @@ int qemuDomainNamespaceTeardownHostdev(virDomainObjPtr vm, virDomainHostdevDefPtr hostdev) { - int ret =3D -1; VIR_AUTOFREE(char *) path =3D NULL; =20 if (qemuDomainGetHostdevPath(hostdev, &path, NULL) < 0) - goto cleanup; + return -1; =20 if (qemuDomainNamespaceUnlinkPath(vm, path) < 0) - goto cleanup; + return -1; =20 if (qemuHostdevNeedsVFIO(hostdev) && !qemuDomainNeedsVFIO(vm->def) && qemuDomainNamespaceUnlinkPath(vm, QEMU_DEV_VFIO) < 0) - goto cleanup; + return -1; =20 - ret =3D 0; - cleanup: - return ret; + return 0; } =20 =20 --=20 2.21.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Sun May 19 20:29:53 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 ARC-Seal: i=1; a=rsa-sha256; t=1569514688; cv=none; d=zoho.com; s=zohoarc; b=fwjNOI7hyEeXBY8eLkZc373GayuZvWsjdnPx7DbhT7PKzNOctAVivrFv/P+Ra8cpH8OEekOyzSXS9J3oDJdy0eGXG9oGQG7QJnNfVV1o+OocDieqAjpNFqxo4LQtTflr6DrooAutmDXN8Lp+r1H9hmtDYtNpnRVeXY+ZZxCHx8g= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1569514688; h=Content-Type:Content-Transfer-Encoding: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:ARC-Authentication-Results; bh=MZMhQUnmWPCEfkEAWEneLQM1gWEr0U+8ohfqXUgbf1s=; b=mVfBsC+AHlUenKQecvz2TwzxjAYxgSDUIg/wm3GULpk6XErAeVmeWC4d2KEfqOzmG8J7/6Z1rH61necOH9p0KMbK5dnZTkbB6Rd6Q+kVhysaqCz600eZoKUDQCW7IyfdjP98efGmFtLR/TFINBSW6d1NXiLym9tNaAETbHHDzpY= ARC-Authentication-Results: i=1; mx.zoho.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 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 1569514688505611.7771973783532; Thu, 26 Sep 2019 09:18:08 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 02F3C307BCC4; Thu, 26 Sep 2019 16:18:07 +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 C9ADE1001DCD; Thu, 26 Sep 2019 16:18:06 +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 882D51803517; Thu, 26 Sep 2019 16:18:06 +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 x8QGDvLc003369 for ; Thu, 26 Sep 2019 12:13:57 -0400 Received: by smtp.corp.redhat.com (Postfix) id CE1875D9D5; Thu, 26 Sep 2019 16:13:57 +0000 (UTC) Received: from moe.brq.redhat.com (unknown [10.43.2.30]) by smtp.corp.redhat.com (Postfix) with ESMTP id 544135D9E1 for ; Thu, 26 Sep 2019 16:13:54 +0000 (UTC) From: Michal Privoznik To: libvir-list@redhat.com Date: Thu, 26 Sep 2019 18:12:09 +0200 Message-Id: <847c08199c8d2f7b87fcee7d9325df9631b4c501.1569514291.git.mprivozn@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v2 13/39] virpci: Introduce and use virPCIDeviceAddressGetIOMMUGroupDev 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-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.22 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.49]); Thu, 26 Sep 2019 16:18:07 +0000 (UTC) Content-Type: text/plain; charset="utf-8" Sometimes, we have a PCI address and not fully allocated virPCIDevice and yet we still want to know its /dev/vfio/N path. Introduce virPCIDeviceAddressGetIOMMUGroupDev() function exactly for that. Signed-off-by: Michal Privoznik --- src/libvirt_private.syms | 1 + src/qemu/qemu_domain.c | 10 +--------- src/util/virpci.c | 15 +++++++++++++++ src/util/virpci.h | 1 + 4 files changed, 18 insertions(+), 9 deletions(-) diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index de124eb37b..4b726b3139 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -2658,6 +2658,7 @@ virPCIDeviceAddressAsString; virPCIDeviceAddressEqual; virPCIDeviceAddressFree; virPCIDeviceAddressGetIOMMUGroupAddresses; +virPCIDeviceAddressGetIOMMUGroupDev; virPCIDeviceAddressGetIOMMUGroupNum; virPCIDeviceAddressGetSysfsFile; virPCIDeviceAddressIOMMUGroupIterate; diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c index e92c2053c1..f8fe430a7f 100644 --- a/src/qemu/qemu_domain.c +++ b/src/qemu/qemu_domain.c @@ -12859,7 +12859,6 @@ qemuDomainGetHostdevPath(virDomainHostdevDefPtr dev, virDomainHostdevSubsysSCSIPtr scsisrc =3D &dev->source.subsys.u.scsi; virDomainHostdevSubsysSCSIVHostPtr hostsrc =3D &dev->source.subsys.u.s= csi_host; virDomainHostdevSubsysMediatedDevPtr mdevsrc =3D &dev->source.subsys.u= .mdev; - VIR_AUTOPTR(virPCIDevice) pci =3D NULL; VIR_AUTOPTR(virUSBDevice) usb =3D NULL; VIR_AUTOPTR(virSCSIDevice) scsi =3D NULL; VIR_AUTOPTR(virSCSIVHostDevice) host =3D NULL; @@ -12871,14 +12870,7 @@ qemuDomainGetHostdevPath(virDomainHostdevDefPtr de= v, switch ((virDomainHostdevSubsysType)dev->source.subsys.type) { case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_PCI: if (pcisrc->backend =3D=3D VIR_DOMAIN_HOSTDEV_PCI_BACKEND_VFIO= ) { - pci =3D virPCIDeviceNew(pcisrc->addr.domain, - pcisrc->addr.bus, - pcisrc->addr.slot, - pcisrc->addr.function); - if (!pci) - return -1; - - if (!(tmpPath =3D virPCIDeviceGetIOMMUGroupDev(pci))) + if (!(tmpPath =3D virPCIDeviceAddressGetIOMMUGroupDev(&pci= src->addr))) return -1; =20 perm =3D VIR_CGROUP_DEVICE_RW; diff --git a/src/util/virpci.c b/src/util/virpci.c index ee78151e74..fc620d49ce 100644 --- a/src/util/virpci.c +++ b/src/util/virpci.c @@ -1974,6 +1974,21 @@ virPCIDeviceAddressGetIOMMUGroupNum(virPCIDeviceAddr= essPtr addr) } =20 =20 +char * +virPCIDeviceAddressGetIOMMUGroupDev(const virPCIDeviceAddress *devAddr) +{ + VIR_AUTOPTR(virPCIDevice) pci =3D NULL; + + if (!(pci =3D virPCIDeviceNew(devAddr->domain, + devAddr->bus, + devAddr->slot, + devAddr->function))) + return NULL; + + return virPCIDeviceGetIOMMUGroupDev(pci); +} + + /* virPCIDeviceGetIOMMUGroupDev - return the name of the device used * to control this PCI device's group (e.g. "/dev/vfio/15") */ diff --git a/src/util/virpci.h b/src/util/virpci.h index dc20f91710..293d10b3ab 100644 --- a/src/util/virpci.h +++ b/src/util/virpci.h @@ -193,6 +193,7 @@ int virPCIDeviceAddressGetIOMMUGroupAddresses(virPCIDev= iceAddressPtr devAddr, virPCIDeviceAddressPtr **iom= muGroupDevices, size_t *nIommuGroupDevices); int virPCIDeviceAddressGetIOMMUGroupNum(virPCIDeviceAddressPtr addr); +char *virPCIDeviceAddressGetIOMMUGroupDev(const virPCIDeviceAddress *devAd= dr); char *virPCIDeviceGetIOMMUGroupDev(virPCIDevicePtr dev); =20 int virPCIDeviceIsAssignable(virPCIDevicePtr dev, --=20 2.21.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Sun May 19 20:29:53 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 ARC-Seal: i=1; a=rsa-sha256; t=1569514704; cv=none; d=zoho.com; s=zohoarc; b=YlRcH8LDYdNdPSZ+ExiLaWNwc7eqIUr0cOULR0pk7WAhHhG7qg6sqUskF7J4fqY5Us++3L0yYMI5EYC9UqY/6n0+R/qFyQZ9/lkIyjRs26OE7u/rPPnII0zImxVU4KuFhlNTuwIyGeiiD7QSToZ6FZ7+MhLEDv26bKtcoGYCZ4Q= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1569514704; h=Content-Type:Content-Transfer-Encoding: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:ARC-Authentication-Results; bh=1ksSlQboTNv1f67ATKvIUN2HzZhghj46nIkbXje15FE=; b=L4LFYhoiEI9OvFHwdo7rijennmK04djScD+tXznyb512BNLMyCGkXNhngxlKLk48cWO6ZPHDp67HCDnGpc1BkjzzJ5rbQIFoH2283trbcsJnIAdrnYh7mg9RliN3SvJrIj8qtCi4FHCRNXuRVuJ6JQkx/+PVPzZzezZafwfZ5xs= ARC-Authentication-Results: i=1; mx.zoho.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 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 1569514704745778.8948177792183; Thu, 26 Sep 2019 09:18:24 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 122D3305C3A4; Thu, 26 Sep 2019 16:18:23 +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 DE5A2600C6; Thu, 26 Sep 2019 16:18:22 +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 8C650180B536; Thu, 26 Sep 2019 16:18:22 +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 x8QGE0Kg003384 for ; Thu, 26 Sep 2019 12:14:00 -0400 Received: by smtp.corp.redhat.com (Postfix) id 21FA35DA60; Thu, 26 Sep 2019 16:14:00 +0000 (UTC) Received: from moe.brq.redhat.com (unknown [10.43.2.30]) by smtp.corp.redhat.com (Postfix) with ESMTP id 9B9CC5D9D5 for ; Thu, 26 Sep 2019 16:13:57 +0000 (UTC) From: Michal Privoznik To: libvir-list@redhat.com Date: Thu, 26 Sep 2019 18:12:10 +0200 Message-Id: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v2 14/39] virHostdevPreparePCIDevices: Separate out function body 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-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.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.45]); Thu, 26 Sep 2019 16:18:23 +0000 (UTC) Content-Type: text/plain; charset="utf-8" In near future we will have a list of PCI devices we want to detach (held in virPCIDeviceListPtr) but we don't have virDomainHostdevDefPtr. That's okay because virHostdevPreparePCIDevices() works with virPCIDeviceListPtr mostly anyway. And in very few places where it needs virDomainHostdevDefPtr are not interesting for our case. Signed-off-by: Michal Privoznik ACKed-by: Peter Krempa --- src/util/virhostdev.c | 48 +++++++++++++++++++++++++++++-------------- 1 file changed, 33 insertions(+), 15 deletions(-) diff --git a/src/util/virhostdev.c b/src/util/virhostdev.c index 85812423b5..d2c881bddf 100644 --- a/src/util/virhostdev.c +++ b/src/util/virhostdev.c @@ -719,27 +719,22 @@ virHostdevReattachAllPCIDevices(virHostdevManagerPtr = mgr, } } =20 -int -virHostdevPreparePCIDevices(virHostdevManagerPtr mgr, - const char *drv_name, - const char *dom_name, - const unsigned char *uuid, - virDomainHostdevDefPtr *hostdevs, - int nhostdevs, - unsigned int flags) + +static int +virHostdevPreparePCIDevicesImpl(virHostdevManagerPtr mgr, + const char *drv_name, + const char *dom_name, + const unsigned char *uuid, + virPCIDeviceListPtr pcidevs, + virDomainHostdevDefPtr *hostdevs, + int nhostdevs, + unsigned int flags) { - VIR_AUTOUNREF(virPCIDeviceListPtr) pcidevs =3D NULL; int last_processed_hostdev_vf =3D -1; size_t i; int ret =3D -1; virPCIDeviceAddressPtr devAddr =3D NULL; =20 - if (!nhostdevs) - return 0; - - if (!(pcidevs =3D virHostdevGetPCIHostDeviceList(hostdevs, nhostdevs))) - return -1; - virObjectLock(mgr->activePCIHostdevs); virObjectLock(mgr->inactivePCIHostdevs); =20 @@ -989,6 +984,29 @@ virHostdevPreparePCIDevices(virHostdevManagerPtr mgr, return ret; } =20 + +int +virHostdevPreparePCIDevices(virHostdevManagerPtr mgr, + const char *drv_name, + const char *dom_name, + const unsigned char *uuid, + virDomainHostdevDefPtr *hostdevs, + int nhostdevs, + unsigned int flags) +{ + VIR_AUTOUNREF(virPCIDeviceListPtr) pcidevs =3D NULL; + + if (!nhostdevs) + return 0; + + if (!(pcidevs =3D virHostdevGetPCIHostDeviceList(hostdevs, nhostdevs))) + return -1; + + return virHostdevPreparePCIDevicesImpl(mgr, drv_name, dom_name, uuid, + pcidevs, hostdevs, nhostdevs, f= lags); +} + + /* @oldStateDir: * For upgrade purpose: see virHostdevRestoreNetConfig */ --=20 2.21.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Sun May 19 20:29:53 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 ARC-Seal: i=1; a=rsa-sha256; t=1569514963; cv=none; d=zoho.com; s=zohoarc; b=Db42IcbNYKJNOhUehwStXVBlygwulYeBlaPDyBPdO+A+4UuZTQMAUR7L2RwrwJEpqB5S6gkIA3MDmvPc5gDaf5FKDlsBKxXn1897jfKOf3iLpuMDw5ZzqUn9EfmBWpS0sJvro6HCj32Y+PUD/YB+qpPpcGreOlNQILYydpFjg4w= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1569514963; h=Content-Type:Content-Transfer-Encoding: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:ARC-Authentication-Results; bh=izvpBLVGpiTo1h2J6YI8vei8+8obtY1NDtRyVwiZCEE=; b=SAZ9vkLnSyXpzc0dCvekBytNKY6z+JuqlBOZGd2da4pSzmR48XWzeH3xwZmP9QIbrWioTo9gaiHwH4xHJSgl2BtPyM8oec1jFI8IQ0Hm3dGZFGUfud1Ji/Sx9ZYRGk62PHwJDwDZlT9C/+wakhWrTDulBKrpivumyXhDWwjM7vs= ARC-Authentication-Results: i=1; mx.zoho.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 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 1569514963982517.6752649852651; Thu, 26 Sep 2019 09:22:43 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 67255793F4; Thu, 26 Sep 2019 16:22:42 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 35D9D1001DC2; Thu, 26 Sep 2019 16:22:42 +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 E73374EE50; Thu, 26 Sep 2019 16:22:41 +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 x8QGE2uM003394 for ; Thu, 26 Sep 2019 12:14:02 -0400 Received: by smtp.corp.redhat.com (Postfix) id 6D45D5D9D5; Thu, 26 Sep 2019 16:14:02 +0000 (UTC) Received: from moe.brq.redhat.com (unknown [10.43.2.30]) by smtp.corp.redhat.com (Postfix) with ESMTP id EADBD5D9E1 for ; Thu, 26 Sep 2019 16:14:00 +0000 (UTC) From: Michal Privoznik To: libvir-list@redhat.com Date: Thu, 26 Sep 2019 18:12:11 +0200 Message-Id: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v2 15/39] virHostdevReAttachPCIDevices: Separate out function body 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-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.22 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.25]); Thu, 26 Sep 2019 16:22:42 +0000 (UTC) Content-Type: text/plain; charset="utf-8" In near future we will have a list of PCI devices we want to re-attach to the host (held in virPCIDeviceListPtr) but we don't have virDomainHostdevDefPtr. That's okay because virHostdevReAttachPCIDevices() works with virPCIDeviceListPtr mostly anyway. And in very few places where it needs virDomainHostdevDefPtr are not interesting for our case. Signed-off-by: Michal Privoznik ACKed-by: Peter Krempa --- src/util/virhostdev.c | 58 +++++++++++++++++++++++++++---------------- 1 file changed, 37 insertions(+), 21 deletions(-) diff --git a/src/util/virhostdev.c b/src/util/virhostdev.c index d2c881bddf..f0c97ca887 100644 --- a/src/util/virhostdev.c +++ b/src/util/virhostdev.c @@ -1007,30 +1007,17 @@ virHostdevPreparePCIDevices(virHostdevManagerPtr mg= r, } =20 =20 -/* @oldStateDir: - * For upgrade purpose: see virHostdevRestoreNetConfig - */ -void -virHostdevReAttachPCIDevices(virHostdevManagerPtr mgr, - const char *drv_name, - const char *dom_name, - virDomainHostdevDefPtr *hostdevs, - int nhostdevs, - const char *oldStateDir) +static void +virHostdevReAttachPCIDevicesImpl(virHostdevManagerPtr mgr, + const char *drv_name, + const char *dom_name, + virPCIDeviceListPtr pcidevs, + virDomainHostdevDefPtr *hostdevs, + int nhostdevs, + const char *oldStateDir) { - VIR_AUTOUNREF(virPCIDeviceListPtr) pcidevs =3D NULL; size_t i; =20 - if (!nhostdevs) - return; - - if (!(pcidevs =3D virHostdevGetPCIHostDeviceList(hostdevs, nhostdevs))= ) { - VIR_ERROR(_("Failed to allocate PCI device list: %s"), - virGetLastErrorMessage()); - virResetLastError(); - return; - } - virObjectLock(mgr->activePCIHostdevs); virObjectLock(mgr->inactivePCIHostdevs); =20 @@ -1126,6 +1113,35 @@ virHostdevReAttachPCIDevices(virHostdevManagerPtr mg= r, virObjectUnlock(mgr->inactivePCIHostdevs); } =20 + +/* @oldStateDir: + * For upgrade purpose: see virHostdevRestoreNetConfig + */ +void +virHostdevReAttachPCIDevices(virHostdevManagerPtr mgr, + const char *drv_name, + const char *dom_name, + virDomainHostdevDefPtr *hostdevs, + int nhostdevs, + const char *oldStateDir) +{ + VIR_AUTOUNREF(virPCIDeviceListPtr) pcidevs =3D NULL; + + if (!nhostdevs) + return; + + if (!(pcidevs =3D virHostdevGetPCIHostDeviceList(hostdevs, nhostdevs))= ) { + VIR_ERROR(_("Failed to allocate PCI device list: %s"), + virGetLastErrorMessage()); + virResetLastError(); + return; + } + + virHostdevReAttachPCIDevicesImpl(mgr, drv_name, dom_name, pcidevs, + hostdevs, nhostdevs, oldStateDir); +} + + int virHostdevUpdateActivePCIDevices(virHostdevManagerPtr mgr, virDomainHostdevDefPtr *hostdevs, --=20 2.21.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Sun May 19 20:29:53 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 ARC-Seal: i=1; a=rsa-sha256; t=1569514843; cv=none; d=zoho.com; s=zohoarc; b=Vdkn1lGVT1RIBBd3wOmiHMOELE+HudjHqJRgzARsDyj6+rtNmpAajnzzObKT3ZLHVQIB0/Qd22eqWKl4v1U/n0zN8blZ26YuNSkCyBsjDHdCLB8WZ843HTdndshdM3WQAI2gUR6YEvIoe2nbjG2p9NPVM4OigLLH6KU9AaY/bXE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1569514843; h=Content-Type:Content-Transfer-Encoding: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:ARC-Authentication-Results; bh=256KngtlCFr84waVVcCJlFJ7+vowrEN/+jRpXYP0d10=; b=QhHxvmBoGjVYFZvXhjUki8Sr3yVH04cXxeRuquRmypyZIgxrtc5Ic+UhPoDw3+j+8Gs38Mpy7xxIeUTJjF+jYyVfOsCi0ltsPAcN2rNVtBOL4NfxoEjADILlhbJXPxiIuBXkpL/kCZd3hLNxMjpnUxBASO5U73w285mWRiI6Kbo= ARC-Authentication-Results: i=1; mx.zoho.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 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 15695148439051003.9471723965813; Thu, 26 Sep 2019 09:20:43 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 2365BC0578F8; Thu, 26 Sep 2019 16:20:42 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id ED6C660126; Thu, 26 Sep 2019 16:20:41 +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 A5C3F4EE68; Thu, 26 Sep 2019 16:20:41 +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 x8QGE7TK003415 for ; Thu, 26 Sep 2019 12:14:07 -0400 Received: by smtp.corp.redhat.com (Postfix) id 160295D9E1; Thu, 26 Sep 2019 16:14:07 +0000 (UTC) Received: from moe.brq.redhat.com (unknown [10.43.2.30]) by smtp.corp.redhat.com (Postfix) with ESMTP id 931465D9CD for ; Thu, 26 Sep 2019 16:14:02 +0000 (UTC) From: Michal Privoznik To: libvir-list@redhat.com Date: Thu, 26 Sep 2019 18:12:12 +0200 Message-Id: <8390e6ee21712f96d032c228ecadd005e79c8dc2.1569514291.git.mprivozn@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v2 16/39] virpci: Introduce virPCIDeviceAddressCopy 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-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.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.31]); Thu, 26 Sep 2019 16:20:42 +0000 (UTC) Content-Type: text/plain; charset="utf-8" This helper is cleaner than plain memcpy() because one doesn't have to look into virPCIDeviceAddress struct to see if it contains any strings / pointers. Signed-off-by: Michal Privoznik ACKed-by: Peter Krempa --- src/libvirt_private.syms | 1 + src/util/virpci.c | 14 ++++++++++++++ src/util/virpci.h | 4 ++++ 3 files changed, 19 insertions(+) diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index 4b726b3139..b3c95495c3 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -2655,6 +2655,7 @@ virObjectUnref; =20 # util/virpci.h virPCIDeviceAddressAsString; +virPCIDeviceAddressCopy; virPCIDeviceAddressEqual; virPCIDeviceAddressFree; virPCIDeviceAddressGetIOMMUGroupAddresses; diff --git a/src/util/virpci.c b/src/util/virpci.c index fc620d49ce..9bf081540a 100644 --- a/src/util/virpci.c +++ b/src/util/virpci.c @@ -1350,6 +1350,20 @@ virPCIDeviceAddressEqual(const virPCIDeviceAddress *= addr1, return false; } =20 +/** + * virPCIDeviceAddressCopy: + * @dst: where to store address + * @src: source address to copy + * + * Creates a deep copy of given @src address and stores it into + * @dst which has to be pre-allocated by caller. + */ +void virPCIDeviceAddressCopy(virPCIDeviceAddressPtr dst, + const virPCIDeviceAddress *src) +{ + memcpy(dst, src, sizeof(*src)); +} + char * virPCIDeviceAddressAsString(const virPCIDeviceAddress *addr) { diff --git a/src/util/virpci.h b/src/util/virpci.h index 293d10b3ab..0a89bc9dcf 100644 --- a/src/util/virpci.h +++ b/src/util/virpci.h @@ -42,6 +42,7 @@ typedef virZPCIDeviceAddress *virZPCIDeviceAddressPtr; struct _virZPCIDeviceAddress { unsigned int uid; /* exempt from syntax-check */ unsigned int fid; + /* Don't forget to update virPCIDeviceAddressCopy if needed. */ }; =20 #define VIR_PCI_DEVICE_ADDRESS_FMT "%04x:%02x:%02x.%d" @@ -54,6 +55,7 @@ struct _virPCIDeviceAddress { int multi; /* virTristateSwitch */ int extFlags; /* enum virPCIDeviceAddressExtensionFlags */ virZPCIDeviceAddress zpci; + /* Don't forget to update virPCIDeviceAddressCopy if needed. */ }; =20 typedef enum { @@ -234,6 +236,8 @@ bool virPCIDeviceAddressIsEmpty(const virPCIDeviceAddre= ss *addr); =20 bool virPCIDeviceAddressEqual(const virPCIDeviceAddress *addr1, const virPCIDeviceAddress *addr2); +void virPCIDeviceAddressCopy(virPCIDeviceAddressPtr dst, + const virPCIDeviceAddress *src); =20 char *virPCIDeviceAddressAsString(const virPCIDeviceAddress *addr) ATTRIBUTE_NONNULL(1); --=20 2.21.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Sun May 19 20:29:53 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 ARC-Seal: i=1; a=rsa-sha256; t=1569514816; cv=none; d=zoho.com; s=zohoarc; b=JIBQvPHq95ba1BTZXCNF9pfDg+g2QS+7aPX8DAEXSQ3XrRUwE2ML2Z0FC5s6tTpKzCEIrQLRbsMyHwLddIzcTJmOvBkuBBPuUcZGE5mEG7Y7VslWoP6nw10CbPHh1PSKEfznC7Ld0DkUM/fM1eJA+mLrfzcXKUmGebFpBE4lf5E= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1569514816; h=Content-Type:Content-Transfer-Encoding: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:ARC-Authentication-Results; bh=WgNZGb2YUlmiqHdH8uboFQJNaBcsICzj0ofbOKA5spY=; b=SHMxDzPXaeBf55SNhUM9LLgyB/l78KrORGYlA+toKsHGRmLYDMvGleqeOgtZgHpl0hLo10Pq4SRObH8BoBIOynGWBFA9aZJr+/q6GVpt8ievx4bhF6mTPZLDY0/prIIEee+0rjCWqeblqEOddANdDyxMtqjxICn4UlOxw/rU0C4= ARC-Authentication-Results: i=1; mx.zoho.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 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 1569514816540753.2270911922627; Thu, 26 Sep 2019 09:20:16 -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 EA93C10DCCA4; Thu, 26 Sep 2019 16:20:14 +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 4BD3F60C80; Thu, 26 Sep 2019 16:20: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 6A5311803517; Thu, 26 Sep 2019 16:20:13 +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 x8QGE97o003451 for ; Thu, 26 Sep 2019 12:14:09 -0400 Received: by smtp.corp.redhat.com (Postfix) id 5599E5D9CD; Thu, 26 Sep 2019 16:14:09 +0000 (UTC) Received: from moe.brq.redhat.com (unknown [10.43.2.30]) by smtp.corp.redhat.com (Postfix) with ESMTP id D28175D9C3 for ; Thu, 26 Sep 2019 16:14:07 +0000 (UTC) From: Michal Privoznik To: libvir-list@redhat.com Date: Thu, 26 Sep 2019 18:12:13 +0200 Message-Id: <06b78b6eef635bf33751f2fab3930c4ed8ad53ef.1569514291.git.mprivozn@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v2 17/39] qemuMigrationSrcIsSafe: Rework slightly 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-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.6.2 (mx1.redhat.com [10.5.110.64]); Thu, 26 Sep 2019 16:20:15 +0000 (UTC) Content-Type: text/plain; charset="utf-8" There are going to be more disk types that are considered unsafe with respect to migration. Therefore, move the error reporting call outside of if() body and rework if-else combo to switch(). Signed-off-by: Michal Privoznik --- src/qemu/qemu_migration.c | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/src/qemu/qemu_migration.c b/src/qemu/qemu_migration.c index a98ec2d55a..693240ed3d 100644 --- a/src/qemu/qemu_migration.c +++ b/src/qemu/qemu_migration.c @@ -1239,6 +1239,8 @@ qemuMigrationSrcIsSafe(virDomainDefPtr def, for (i =3D 0; i < def->ndisks; i++) { virDomainDiskDefPtr disk =3D def->disks[i]; const char *src =3D virDomainDiskGetSource(disk); + int actualType =3D virStorageSourceGetActualType(disk->src); + bool unsafe =3D false; =20 /* Disks without any source (i.e. floppies and CD-ROMs) * OR readonly are safe. */ @@ -1252,21 +1254,34 @@ qemuMigrationSrcIsSafe(virDomainDefPtr def, continue; =20 /* However, disks on local FS (e.g. ext4) are not safe. */ - if (virStorageSourceGetActualType(disk->src) =3D=3D VIR_STORAGE_TY= PE_FILE) { + switch ((virStorageType) actualType) { + case VIR_STORAGE_TYPE_FILE: if ((rc =3D virFileIsSharedFS(src)) < 0) { return false; } else if (rc =3D=3D 0) { - virReportError(VIR_ERR_MIGRATE_UNSAFE, "%s", - _("Migration without shared storage is unsa= fe")); - return false; + unsafe =3D true; } if ((rc =3D virStorageFileIsClusterFS(src)) < 0) return false; else if (rc =3D=3D 1) continue; - } else if (virStorageSourceGetActualType(disk->src) =3D=3D VIR_STO= RAGE_TYPE_NETWORK) { + break; + case VIR_STORAGE_TYPE_NETWORK: /* But network disks are safe again. */ continue; + + case VIR_STORAGE_TYPE_NONE: + case VIR_STORAGE_TYPE_BLOCK: + case VIR_STORAGE_TYPE_DIR: + case VIR_STORAGE_TYPE_VOLUME: + case VIR_STORAGE_TYPE_LAST: + break; + } + + if (unsafe) { + virReportError(VIR_ERR_MIGRATE_UNSAFE, "%s", + _("Migration without shared storage is unsafe")= ); + return false; } =20 /* Our code elsewhere guarantees shared disks are either readonly = (in --=20 2.21.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Sun May 19 20:29:53 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 ARC-Seal: i=1; a=rsa-sha256; t=1569514978; cv=none; d=zoho.com; s=zohoarc; b=FE30dgbdq5p4JxFy4JxuI/RIVf2tfiS800+vOFYEI+higuq1PK1Z6i71BT2L3d/BSfOgbtwiuAGR08Pxsb2h6fhF58bGJv7Inf9S8nMI9QeZPzvNR38ib4TrNJPDbC4rBiR5gxikTfXkS2uW7oshi8brxjDdLvQgK3U1IfHE1lA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1569514978; h=Content-Type:Content-Transfer-Encoding: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:ARC-Authentication-Results; bh=j/Geh90PZTHgCw+iBegYOh7W4i3KvONoJqKURJCkXeA=; b=QmWv1nO+DQCPPU1PfDs/YcwHu4GtxsoGpOPMXZ8dlZMZs6g3y3ecQqUMnUkGtqKGVGNaM3xoj9h+sLNYsVJEvdh3rxPhXQapn0zTa9dSrNGst7YRnF3NPbOBfvlXTz5wO6JWar0drAyRQQvkiHewskKI1AyKJEhx7VXwUcRbVPU= ARC-Authentication-Results: i=1; mx.zoho.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 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 1569514978007414.0356137020044; Thu, 26 Sep 2019 09:22:58 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 5BBBC8980E5; Thu, 26 Sep 2019 16:22:56 +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 37A1C1001DCD; Thu, 26 Sep 2019 16:22:56 +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 EB04A180B76F; Thu, 26 Sep 2019 16:22:55 +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 x8QGEBUY003482 for ; Thu, 26 Sep 2019 12:14:11 -0400 Received: by smtp.corp.redhat.com (Postfix) id 90F375D9C3; Thu, 26 Sep 2019 16:14:11 +0000 (UTC) Received: from moe.brq.redhat.com (unknown [10.43.2.30]) by smtp.corp.redhat.com (Postfix) with ESMTP id 1A5505D9CD for ; Thu, 26 Sep 2019 16:14:09 +0000 (UTC) From: Michal Privoznik To: libvir-list@redhat.com Date: Thu, 26 Sep 2019 18:12:14 +0200 Message-Id: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v2 18/39] schemas: Introduce disk type NVMe 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-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.22 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.6.2 (mx1.redhat.com [10.5.110.67]); Thu, 26 Sep 2019 16:22:56 +0000 (UTC) Content-Type: text/plain; charset="utf-8" There is this class of PCI devices that act like disks: NVMe. Therefore, they are both PCI devices and disks. While we already have (and can assign a NVMe device to a domain successfully) we don't have disk representation. There are three problems with PCI assignment in case of a NVMe device: 1) domains with can't be migrated 2) NVMe device is assigned whole, there's no way to assign only a namespace 3) Because hypervisors see they don't put block layer on top of it - users don't get all the fancy features like snapshots NVMe namespaces are way of splitting one continuous NVDIMM memory into smaller ones, effectively creating smaller NVMe-s (which can then be partitioned, LVMed, etc.) Because of all of this the following XML was chosen to model a NVMe device:
Signed-off-by: Michal Privoznik --- docs/formatdomain.html.in | 57 +++++++++++++++++++++++-- docs/schemas/domaincommon.rng | 32 ++++++++++++++ tests/qemuxml2argvdata/disk-nvme.xml | 63 ++++++++++++++++++++++++++++ 3 files changed, 149 insertions(+), 3 deletions(-) create mode 100644 tests/qemuxml2argvdata/disk-nvme.xml diff --git a/docs/formatdomain.html.in b/docs/formatdomain.html.in index 93991aa3d1..ad116ff509 100644 --- a/docs/formatdomain.html.in +++ b/docs/formatdomain.html.in @@ -2934,6 +2934,13 @@ </backingStore> <target dev=3D'vdd' bus=3D'virtio'/> </disk> + <disk type=3D'nvme' device=3D'disk'> + <driver name=3D'qemu' type=3D'raw'/> + <source type=3D'pci' managed=3D'yes' namespace=3D'1'> + <address domain=3D'0x0000' bus=3D'0x01' slot=3D'0x00' function=3D= '0x0'/> + </source> + <target dev=3D'vde' bus=3D'virtio'/> + </disk> </devices> ... =20 @@ -2947,7 +2954,8 @@ Valid values are "file", "block", "dir" (since 0.7.5), "network" (since 0.8.7), or - "volume" (since 1.0.5) + "volume" (since 1.0.5), or + "nvme" (since 5.6.0) and refer to the underlying source for the disk. Since 0.0.3 @@ -3130,6 +3138,43 @@ Since 1.0.5

+
nvme
+
+ To specify disk source for NVMe disk the source + element has the following attributes: +
+
type
+
The type of address specified in address + sub-element. Currently, only pci value is + accepted. +
+ +
managed
+
This attribute instructs libvirt to detach NVMe + controller automatically on domain startup (yes) + or expect the controller to be detached by system + administrator (no). +
+ +
namespace
+
The namespace ID which should be assigned to the domai= n. + According to NVMe standard, namespace numbers start from 1, + including. +
+
+ + The difference between <disk type=3D'nvme'> + and <hostdev/> is that the latter is plain + host device assignment with all its limitations (e.g. no live + migration), while the former makes hypervisor to run the NVMe + disk through hypervisor's block layer thus enabling all + features provided by the layer (e.g. snapshots, domain + migration, etc.). Moreover, since the NVMe disk is unbinded + from its PCI driver, the host kernel storage stack is not + involved (compared to passing say /dev/nvme0n1 = via + <disk type=3D'block'> and therefore lower + latencies can be achieved. +
With "file", "block", and "volume", one or more optional sub-elements seclabel, described @@ -3292,11 +3337,17 @@ initiator IQN needed to access the source via mandatory attribute name. +
address
+
For disk of type nvme this element + specifies the PCI address of the host NVMe + controller. + Since 5.6.0 +
=20

- For a "file" or "volume" disk type which represents a cdrom or flo= ppy - (the device attribute), it is possible to define + For a "file" or "volume" disk type which represents a cdrom or + floppy (the device attribute), it is possible to defi= ne policy what to do with the disk if the source file is not accessib= le. (NB, startupPolicy is not valid for "volume" disk unl= ess the specified storage volume is of "file" type). This is done by = the diff --git a/docs/schemas/domaincommon.rng b/docs/schemas/domaincommon.rng index 40eb4a2d75..4871a4c4d4 100644 --- a/docs/schemas/domaincommon.rng +++ b/docs/schemas/domaincommon.rng @@ -1603,6 +1603,7 @@ + =20 @@ -1918,6 +1919,37 @@ =20 + + + nvme + + + + + pci + + + + + + + + + + + + + + + + + + + + + + + (ioemu:)?(fd|hd|sd|vd|xvd|ubd)[a-zA-Z0-9_]+<= /param> diff --git a/tests/qemuxml2argvdata/disk-nvme.xml b/tests/qemuxml2argvdata/= disk-nvme.xml new file mode 100644 index 0000000000..66b2d8450e --- /dev/null +++ b/tests/qemuxml2argvdata/disk-nvme.xml @@ -0,0 +1,63 @@ + + QEMUGuest1 + c7a5fdbd-edaf-9455-926a-d65c16db1809 + 219136 + 219136 + 1 + + hvm + + + + destroy + restart + destroy + + /usr/bin/qemu-system-i686 + + + +

+ + +
+ + + + +
+ + +
+ + + + +
+ + +
+ + + + +
+ + + + + +
+ + +
+ + + +
+ + + + + + --=20 2.21.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Sun May 19 20:29:53 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 ARC-Seal: i=1; a=rsa-sha256; t=1569514855; cv=none; d=zoho.com; s=zohoarc; b=LwC9SbjY+5yBsMTP52s6AIlhk00OArc9NHcKdyVrC6HBmF1Q6T2RybrrEGNTX/Ig7QeiYJVgdGWtzIz+arrMj7gX0ORfZmJuXXvKpyea1G6q43o1aPWhRKg9I3tfmFEvEiW8v/4IdCQXbKLIm8lqMgJY6tWpZ35Ps7M0JlIzrYU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1569514855; h=Content-Type:Content-Transfer-Encoding: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:ARC-Authentication-Results; bh=jbEIlqLbb85G4QJbWhNiajQPfC9uRFQFo6QRVjHBdDE=; b=NYYOYvZRzCYQg2B0dYSTTU9GhwrxxAjXHZPdLwvCeF1P2R6ppvphecgikNzYDci65Qwd9AKpgSIXaEmMwRZRW5jeuuN6HmBHMlgR+vF9ThbOuPB1ttTWyGXEoG4rzfN4aXAG2SkAJqbY9UJhcYR/rh2KxvuI/i0wfsnYR2+Yz+U= ARC-Authentication-Results: i=1; mx.zoho.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 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 1569514855940272.649207951588; Thu, 26 Sep 2019 09:20:55 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 2926888302; Thu, 26 Sep 2019 16:20:54 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 02D9C5C21F; Thu, 26 Sep 2019 16:20:54 +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 B9A704EE6D; Thu, 26 Sep 2019 16:20:53 +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 x8QGEDmc003504 for ; Thu, 26 Sep 2019 12:14:13 -0400 Received: by smtp.corp.redhat.com (Postfix) id CF5B25D9D5; Thu, 26 Sep 2019 16:14:13 +0000 (UTC) Received: from moe.brq.redhat.com (unknown [10.43.2.30]) by smtp.corp.redhat.com (Postfix) with ESMTP id 589945D9C3 for ; Thu, 26 Sep 2019 16:14:11 +0000 (UTC) From: Michal Privoznik To: libvir-list@redhat.com Date: Thu, 26 Sep 2019 18:12:15 +0200 Message-Id: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v2 19/39] conf: Format and parse NVMe type disk 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-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.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.28]); Thu, 26 Sep 2019 16:20:54 +0000 (UTC) Content-Type: text/plain; charset="utf-8" To simplify implementation, some restrictions are added. For instance, an NVMe disk can't go to any bus but virtio and has to be type of 'disk' and can't have startupPolicy set. Signed-off-by: Michal Privoznik --- src/conf/domain_conf.c | 96 ++++++++++++++++++++++++++ src/libvirt_private.syms | 1 + src/libxl/xen_xl.c | 1 + src/qemu/qemu_block.c | 2 + src/qemu/qemu_command.c | 1 + src/qemu/qemu_driver.c | 4 ++ src/qemu/qemu_migration.c | 5 ++ src/util/virstoragefile.c | 59 ++++++++++++++++ src/util/virstoragefile.h | 17 +++++ tests/qemuxml2xmloutdata/disk-nvme.xml | 1 + tests/qemuxml2xmltest.c | 1 + 11 files changed, 188 insertions(+) create mode 120000 tests/qemuxml2xmloutdata/disk-nvme.xml diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index c1769f743b..fe540c195e 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -5118,6 +5118,11 @@ virDomainDiskDefPostParse(virDomainDiskDefPtr disk, return -1; } =20 + if (disk->src->type =3D=3D VIR_STORAGE_TYPE_NVME) { + if (disk->src->nvme->managed =3D=3D VIR_TRISTATE_BOOL_ABSENT) + disk->src->nvme->managed =3D VIR_TRISTATE_BOOL_YES; + } + if (disk->info.type =3D=3D VIR_DOMAIN_DEVICE_ADDRESS_TYPE_NONE && virDomainDiskDefAssignAddress(xmlopt, disk, def) < 0) { return -1; @@ -9251,6 +9256,76 @@ virDomainDiskSourceNetworkParse(xmlNodePtr node, } =20 =20 +static int +virDomainDiskSourceNVMeParse(xmlNodePtr node, + xmlXPathContextPtr ctxt, + virStorageSourcePtr src) +{ + VIR_AUTOPTR(virStorageSourceNVMeDef) nvme =3D NULL; + VIR_AUTOFREE(char *) type =3D NULL; + VIR_AUTOFREE(char *) namespace =3D NULL; + VIR_AUTOFREE(char *) managed =3D NULL; + xmlNodePtr address; + + if (VIR_ALLOC(nvme) < 0) + return -1; + + if (!(type =3D virXMLPropString(node, "type"))) { + virReportError(VIR_ERR_XML_ERROR, "%s", + _("missing 'type' attribute to disk source")); + return -1; + } + + if (STRNEQ(type, "pci")) { + virReportError(VIR_ERR_XML_ERROR, + _("unsupported source type '%s'"), + type); + return -1; + } + + if (!(namespace =3D virXMLPropString(node, "namespace"))) { + virReportError(VIR_ERR_XML_ERROR, "%s", + _("missing 'namespace' attribute to disk source")); + return -1; + } + + if (virStrToLong_ull(namespace, NULL, 10, &nvme->namespace) < 0) { + virReportError(VIR_ERR_XML_ERROR, + _("malformed namespace '%s'"), + namespace); + return -1; + } + + /* NVMe namespaces start from 1 */ + if (nvme->namespace =3D=3D 0) { + virReportError(VIR_ERR_XML_ERROR, "%s", + _("NVMe namespace can't be zero")); + return -1; + } + + if ((managed =3D virXMLPropString(node, "managed"))) { + if ((nvme->managed =3D virTristateBoolTypeFromString(managed)) <= =3D 0) { + virReportError(VIR_ERR_XML_ERROR, + _("malformed managed value '%s'"), + managed); + return -1; + } + } + + if (!(address =3D virXPathNode("./address", ctxt))) { + virReportError(VIR_ERR_XML_ERROR, "%s", + _("NVMe disk source is missing address")); + return -1; + } + + if (virPCIDeviceAddressParseXML(address, &nvme->pciAddr) < 0) + return -1; + + VIR_STEAL_PTR(src->nvme, nvme); + return 0; +} + + static int virDomainDiskSourcePRParse(xmlNodePtr node, xmlXPathContextPtr ctxt, @@ -9351,6 +9426,10 @@ virDomainStorageSourceParse(xmlNodePtr node, if (virDomainDiskSourcePoolDefParse(node, &src->srcpool) < 0) return -1; break; + case VIR_STORAGE_TYPE_NVME: + if (virDomainDiskSourceNVMeParse(node, ctxt, src) < 0) + return -1; + break; case VIR_STORAGE_TYPE_NONE: case VIR_STORAGE_TYPE_LAST: virReportError(VIR_ERR_INTERNAL_ERROR, @@ -24088,6 +24167,19 @@ virDomainDiskSourceFormatNetwork(virBufferPtr attr= Buf, } =20 =20 +static void +virDomainDiskSourceNVMeFormat(virBufferPtr attrBuf, + virBufferPtr childBuf, + const virStorageSourceNVMeDef *nvme) +{ + virBufferAddLit(attrBuf, " type=3D'pci'"); + virBufferAsprintf(attrBuf, " managed=3D'%s'", + virTristateBoolTypeToString(nvme->managed)); + virBufferAsprintf(attrBuf, " namespace=3D'%llu'", nvme->namespace); + virPCIDeviceAddressFormat(childBuf, nvme->pciAddr, false); +} + + static int virDomainDiskSourceFormatPrivateData(virBufferPtr buf, virStorageSourcePtr src, @@ -24174,6 +24266,10 @@ virDomainDiskSourceFormat(virBufferPtr buf, =20 break; =20 + case VIR_STORAGE_TYPE_NVME: + virDomainDiskSourceNVMeFormat(&attrBuf, &childBuf, src->nvme); + break; + case VIR_STORAGE_TYPE_NONE: case VIR_STORAGE_TYPE_LAST: virReportError(VIR_ERR_INTERNAL_ERROR, diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index b3c95495c3..91b03afb17 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -3045,6 +3045,7 @@ virStorageSourceNetworkAssignDefaultPorts; virStorageSourceNew; virStorageSourceNewFromBacking; virStorageSourceNewFromBackingAbsolute; +virStorageSourceNVMeDefFree; virStorageSourceParseRBDColonString; virStorageSourcePoolDefFree; virStorageSourcePoolModeTypeFromString; diff --git a/src/libxl/xen_xl.c b/src/libxl/xen_xl.c index 3a41a4ad00..5b69812f40 100644 --- a/src/libxl/xen_xl.c +++ b/src/libxl/xen_xl.c @@ -1662,6 +1662,7 @@ xenFormatXLDiskSrc(virStorageSourcePtr src, char **sr= cstr) break; =20 case VIR_STORAGE_TYPE_VOLUME: + case VIR_STORAGE_TYPE_NVME: case VIR_STORAGE_TYPE_NONE: case VIR_STORAGE_TYPE_LAST: break; diff --git a/src/qemu/qemu_block.c b/src/qemu/qemu_block.c index 4b5dd30e17..99b2a4efaa 100644 --- a/src/qemu/qemu_block.c +++ b/src/qemu/qemu_block.c @@ -1077,6 +1077,7 @@ qemuBlockStorageSourceGetBackendProps(virStorageSourc= ePtr src, break; =20 case VIR_STORAGE_TYPE_VOLUME: + case VIR_STORAGE_TYPE_NVME: case VIR_STORAGE_TYPE_NONE: case VIR_STORAGE_TYPE_LAST: return NULL; @@ -2367,6 +2368,7 @@ qemuBlockStorageSourceCreateGetStorageProps(virStorag= eSourcePtr src, case VIR_STORAGE_TYPE_BLOCK: case VIR_STORAGE_TYPE_DIR: case VIR_STORAGE_TYPE_VOLUME: + case VIR_STORAGE_TYPE_NVME: return 0; =20 case VIR_STORAGE_TYPE_NONE: diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c index 77470a6037..b2519465ba 100644 --- a/src/qemu/qemu_command.c +++ b/src/qemu/qemu_command.c @@ -1144,6 +1144,7 @@ qemuGetDriveSourceString(virStorageSourcePtr src, break; =20 case VIR_STORAGE_TYPE_VOLUME: + case VIR_STORAGE_TYPE_NVME: case VIR_STORAGE_TYPE_NONE: case VIR_STORAGE_TYPE_LAST: break; diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index 0c65414a1a..ecfccae92e 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -14906,6 +14906,7 @@ qemuDomainSnapshotPrepareDiskExternalInactive(virDo= mainSnapshotDiskDefPtr snapdi =20 case VIR_STORAGE_TYPE_DIR: case VIR_STORAGE_TYPE_VOLUME: + case VIR_STORAGE_TYPE_NVME: case VIR_STORAGE_TYPE_NONE: case VIR_STORAGE_TYPE_LAST: virReportError(VIR_ERR_INTERNAL_ERROR, @@ -14922,6 +14923,7 @@ qemuDomainSnapshotPrepareDiskExternalInactive(virDo= mainSnapshotDiskDefPtr snapdi case VIR_STORAGE_TYPE_NETWORK: case VIR_STORAGE_TYPE_DIR: case VIR_STORAGE_TYPE_VOLUME: + case VIR_STORAGE_TYPE_NVME: case VIR_STORAGE_TYPE_NONE: case VIR_STORAGE_TYPE_LAST: virReportError(VIR_ERR_INTERNAL_ERROR, @@ -14989,6 +14991,7 @@ qemuDomainSnapshotPrepareDiskExternalActive(virDoma= inSnapshotDiskDefPtr snapdisk =20 case VIR_STORAGE_TYPE_DIR: case VIR_STORAGE_TYPE_VOLUME: + case VIR_STORAGE_TYPE_NVME: case VIR_STORAGE_TYPE_NONE: case VIR_STORAGE_TYPE_LAST: virReportError(VIR_ERR_INTERNAL_ERROR, @@ -15116,6 +15119,7 @@ qemuDomainSnapshotPrepareDiskInternal(virDomainDisk= DefPtr disk, =20 case VIR_STORAGE_TYPE_DIR: case VIR_STORAGE_TYPE_VOLUME: + case VIR_STORAGE_TYPE_NVME: case VIR_STORAGE_TYPE_NONE: case VIR_STORAGE_TYPE_LAST: virReportError(VIR_ERR_INTERNAL_ERROR, diff --git a/src/qemu/qemu_migration.c b/src/qemu/qemu_migration.c index 693240ed3d..4fa989ff79 100644 --- a/src/qemu/qemu_migration.c +++ b/src/qemu/qemu_migration.c @@ -228,6 +228,7 @@ qemuMigrationDstPrecreateDisk(virConnectPtr conn, =20 case VIR_STORAGE_TYPE_BLOCK: case VIR_STORAGE_TYPE_DIR: + case VIR_STORAGE_TYPE_NVME: case VIR_STORAGE_TYPE_NONE: case VIR_STORAGE_TYPE_LAST: virReportError(VIR_ERR_INTERNAL_ERROR, @@ -1270,6 +1271,10 @@ qemuMigrationSrcIsSafe(virDomainDefPtr def, /* But network disks are safe again. */ continue; =20 + case VIR_STORAGE_TYPE_NVME: + unsafe =3D true; + break; + case VIR_STORAGE_TYPE_NONE: case VIR_STORAGE_TYPE_BLOCK: case VIR_STORAGE_TYPE_DIR: diff --git a/src/util/virstoragefile.c b/src/util/virstoragefile.c index 3201f57e62..725d68a248 100644 --- a/src/util/virstoragefile.c +++ b/src/util/virstoragefile.c @@ -57,6 +57,7 @@ VIR_ENUM_IMPL(virStorage, "dir", "network", "volume", + "nvme", ); =20 VIR_ENUM_IMPL(virStorageFileFormat, @@ -2116,6 +2117,50 @@ virStoragePRDefCopy(virStoragePRDefPtr src) } =20 =20 +static virStorageSourceNVMeDefPtr +virStorageSourceNVMeDefCopy(const virStorageSourceNVMeDef *src) +{ + VIR_AUTOPTR(virStorageSourceNVMeDef) ret =3D NULL; + + if (VIR_ALLOC(ret) < 0) + return NULL; + + ret->namespace =3D src->namespace; + ret->managed =3D src->managed; + virPCIDeviceAddressCopy(&ret->pciAddr, &src->pciAddr); + VIR_RETURN_PTR(ret); +} + + +static bool +virStorageSourceNVMeDefIsEqual(const virStorageSourceNVMeDef *a, + const virStorageSourceNVMeDef *b) +{ + if (!a && !b) + return true; + + if (!a || !b) + return false; + + if (a->namespace !=3D b->namespace || + a->managed !=3D b->managed || + !virPCIDeviceAddressEqual(&a->pciAddr, &b->pciAddr)) + return false; + + return true; +} + + +void +virStorageSourceNVMeDefFree(virStorageSourceNVMeDefPtr def) +{ + if (!def) + return; + + VIR_FREE(def); +} + + virSecurityDeviceLabelDefPtr virStorageSourceGetSecurityLabelDef(virStorageSourcePtr src, const char *model) @@ -2325,6 +2370,10 @@ virStorageSourceCopy(const virStorageSource *src, !(def->pr =3D virStoragePRDefCopy(src->pr))) return NULL; =20 + if (src->nvme && + !(def->nvme =3D virStorageSourceNVMeDefCopy(src->nvme))) + return NULL; + if (virStorageSourceInitiatorCopy(&def->initiator, &src->initiator)) return NULL; =20 @@ -2378,6 +2427,10 @@ virStorageSourceIsSameLocation(virStorageSourcePtr a, } } =20 + if (a->type =3D=3D VIR_STORAGE_TYPE_NVME && + !virStorageSourceNVMeDefIsEqual(a->nvme, b->nvme)) + return false; + return true; } =20 @@ -2465,6 +2518,9 @@ virStorageSourceIsLocalStorage(const virStorageSource= *src) =20 case VIR_STORAGE_TYPE_NETWORK: case VIR_STORAGE_TYPE_VOLUME: + /* While NVMe disks are local, they are not accessible via src->pa= th. + * Therefore, we have to return false here. */ + case VIR_STORAGE_TYPE_NVME: case VIR_STORAGE_TYPE_LAST: case VIR_STORAGE_TYPE_NONE: return false; @@ -2550,6 +2606,7 @@ virStorageSourceClear(virStorageSourcePtr def) VIR_FREE(def->compat); virStorageEncryptionFree(def->encryption); virStoragePRDefFree(def->pr); + virStorageSourceNVMeDefFree(def->nvme); virStorageSourceSeclabelsClear(def); virStoragePermsFree(def->perms); VIR_FREE(def->timestamps); @@ -3807,6 +3864,7 @@ virStorageSourceUpdatePhysicalSize(virStorageSourcePt= r src, =20 /* We shouldn't get VOLUME, but the switch requires all cases */ case VIR_STORAGE_TYPE_VOLUME: + case VIR_STORAGE_TYPE_NVME: case VIR_STORAGE_TYPE_NONE: case VIR_STORAGE_TYPE_LAST: return -1; @@ -4268,6 +4326,7 @@ virStorageSourceIsRelative(virStorageSourcePtr src) =20 case VIR_STORAGE_TYPE_NETWORK: case VIR_STORAGE_TYPE_VOLUME: + case VIR_STORAGE_TYPE_NVME: case VIR_STORAGE_TYPE_NONE: case VIR_STORAGE_TYPE_LAST: return false; diff --git a/src/util/virstoragefile.h b/src/util/virstoragefile.h index 81b83a53ef..9e79c7c6ef 100644 --- a/src/util/virstoragefile.h +++ b/src/util/virstoragefile.h @@ -31,6 +31,7 @@ #include "virsecret.h" #include "virautoclean.h" #include "virenum.h" +#include "virpci.h" =20 /* Minimum header size required to probe all known formats with * virStorageFileProbeFormat, or obtain metadata from a known format. @@ -52,6 +53,7 @@ typedef enum { VIR_STORAGE_TYPE_DIR, VIR_STORAGE_TYPE_NETWORK, VIR_STORAGE_TYPE_VOLUME, + VIR_STORAGE_TYPE_NVME, =20 VIR_STORAGE_TYPE_LAST } virStorageType; @@ -231,6 +233,16 @@ struct _virStorageSourceInitiatorDef { char *iqn; /* Initiator IQN */ }; =20 +typedef struct _virStorageSourceNVMeDef virStorageSourceNVMeDef; +typedef virStorageSourceNVMeDef *virStorageSourceNVMeDefPtr; +struct _virStorageSourceNVMeDef { + unsigned long long namespace; + int managed; /* enum virTristateBool */ + virPCIDeviceAddress pciAddr; + + /* Don't forget to update virStorageSourceNVMeDefCopy */ +}; + typedef struct _virStorageDriverData virStorageDriverData; typedef virStorageDriverData *virStorageDriverDataPtr; =20 @@ -262,6 +274,8 @@ struct _virStorageSource { bool encryptionInherited; virStoragePRDefPtr pr; =20 + virStorageSourceNVMeDefPtr nvme; /* type =3D=3D VIR_STORAGE_TYPE_NVME = */ + virStorageSourceInitiatorDef initiator; =20 virObjectPtr privateData; @@ -416,6 +430,9 @@ bool virStoragePRDefIsManaged(virStoragePRDefPtr prd); bool virStorageSourceChainHasManagedPR(virStorageSourcePtr src); =20 +void virStorageSourceNVMeDefFree(virStorageSourceNVMeDefPtr def); +VIR_DEFINE_AUTOPTR_FUNC(virStorageSourceNVMeDef, virStorageSourceNVMeDefFr= ee); + virSecurityDeviceLabelDefPtr virStorageSourceGetSecurityLabelDef(virStorageSourcePtr src, const char *model); diff --git a/tests/qemuxml2xmloutdata/disk-nvme.xml b/tests/qemuxml2xmloutd= ata/disk-nvme.xml new file mode 120000 index 0000000000..ea9eb267ac --- /dev/null +++ b/tests/qemuxml2xmloutdata/disk-nvme.xml @@ -0,0 +1 @@ +../qemuxml2argvdata/disk-nvme.xml \ No newline at end of file diff --git a/tests/qemuxml2xmltest.c b/tests/qemuxml2xmltest.c index d5c66d8791..6202eed439 100644 --- a/tests/qemuxml2xmltest.c +++ b/tests/qemuxml2xmltest.c @@ -348,6 +348,7 @@ mymain(void) DO_TEST("disk-network-sheepdog", NONE); DO_TEST("disk-network-vxhs", NONE); DO_TEST("disk-network-tlsx509", NONE); + DO_TEST("disk-nvme", QEMU_CAPS_VIRTIO_SCSI, QEMU_CAPS_QCOW2_LUKS); DO_TEST("disk-scsi", QEMU_CAPS_SCSI_LSI, QEMU_CAPS_SCSI_MEGASAS, QEMU_CAPS_SCSI_MPTSAS1068, QEMU_CAPS_SCSI_DISK_WWN); DO_TEST("disk-virtio-scsi-reservations", --=20 2.21.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Sun May 19 20:29:53 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 ARC-Seal: i=1; a=rsa-sha256; t=1569514867; cv=none; d=zoho.com; s=zohoarc; b=gycF9+/ETR3MMbkCK8t0Dg1ivhdJtJ9oGngYJacPHOpwHjSrKGHM2DUOFAa3Nsia58vUsu+ctrhhdO9Qr+3thF7bjpalQbyA3u6e4um3D9GSBh16D9iZUgmrQzvQE0cTN6jZg0zMPOcQSOdeCGe/B5sfV9kb3Fz+wAl9GZTZCcU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1569514867; h=Content-Type:Content-Transfer-Encoding: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:ARC-Authentication-Results; bh=qSbLvOBgLwlRiZtQvpdadHzzZH7kKkbvB2xOb6708bQ=; b=HYAK+/XoOChZyD9H7sDUdWYfwBLP9HZ2qVDv4y4XQzfCIvmhroNLX45NCS/4Vo5z7dDIkN0ZtoQD1ldtBspR20SHY6LuoJZdBZEvPSIQWKnXgJPPUY8KKlU/0qw0YZDD6b3FhAfzsZ45IpFp5ru9tbsb4pfwKKJPw6q1RJHlwg4= ARC-Authentication-Results: i=1; mx.zoho.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 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 1569514867285991.9431164738128; Thu, 26 Sep 2019 09:21:07 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id C19B3309C0F5; Thu, 26 Sep 2019 16:21:05 +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 9E9545C8A6; Thu, 26 Sep 2019 16:21:05 +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 67924180B536; Thu, 26 Sep 2019 16:21:05 +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 x8QGEGbJ003526 for ; Thu, 26 Sep 2019 12:14:16 -0400 Received: by smtp.corp.redhat.com (Postfix) id 1C25F5D9DC; Thu, 26 Sep 2019 16:14:16 +0000 (UTC) Received: from moe.brq.redhat.com (unknown [10.43.2.30]) by smtp.corp.redhat.com (Postfix) with ESMTP id 992865D9C3 for ; Thu, 26 Sep 2019 16:14:13 +0000 (UTC) From: Michal Privoznik To: libvir-list@redhat.com Date: Thu, 26 Sep 2019 18:12:16 +0200 Message-Id: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v2 20/39] virstoragefile: Introduce virStorageSourceChainHasNVMe 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-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.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.45]); Thu, 26 Sep 2019 16:21:06 +0000 (UTC) Content-Type: text/plain; charset="utf-8" This function will return true if there's a storage source of type VIR_STORAGE_TYPE_NVME, or false otherwise. Signed-off-by: Michal Privoznik ACKed-by: Peter Krempa --- src/libvirt_private.syms | 1 + src/util/virstoragefile.c | 14 ++++++++++++++ src/util/virstoragefile.h | 2 ++ 3 files changed, 17 insertions(+) diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index 91b03afb17..4e2a74a31b 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -3024,6 +3024,7 @@ virStoragePRDefIsManaged; virStoragePRDefParseXML; virStorageSourceBackingStoreClear; virStorageSourceChainHasManagedPR; +virStorageSourceChainHasNVMe; virStorageSourceClear; virStorageSourceCopy; virStorageSourceFindByNodeName; diff --git a/src/util/virstoragefile.c b/src/util/virstoragefile.c index 725d68a248..093d2403de 100644 --- a/src/util/virstoragefile.c +++ b/src/util/virstoragefile.c @@ -2161,6 +2161,20 @@ virStorageSourceNVMeDefFree(virStorageSourceNVMeDefP= tr def) } =20 =20 +bool +virStorageSourceChainHasNVMe(const virStorageSource *src) +{ + const virStorageSource *n; + + for (n =3D src; virStorageSourceIsBacking(n); n =3D n->backingStore) { + if (n->type =3D=3D VIR_STORAGE_TYPE_NVME) + return true; + } + + return false; +} + + virSecurityDeviceLabelDefPtr virStorageSourceGetSecurityLabelDef(virStorageSourcePtr src, const char *model) diff --git a/src/util/virstoragefile.h b/src/util/virstoragefile.h index 9e79c7c6ef..306f84b383 100644 --- a/src/util/virstoragefile.h +++ b/src/util/virstoragefile.h @@ -433,6 +433,8 @@ virStorageSourceChainHasManagedPR(virStorageSourcePtr s= rc); void virStorageSourceNVMeDefFree(virStorageSourceNVMeDefPtr def); VIR_DEFINE_AUTOPTR_FUNC(virStorageSourceNVMeDef, virStorageSourceNVMeDefFr= ee); =20 +bool virStorageSourceChainHasNVMe(const virStorageSource *src); + virSecurityDeviceLabelDefPtr virStorageSourceGetSecurityLabelDef(virStorageSourcePtr src, const char *model); --=20 2.21.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Sun May 19 20:29:53 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 ARC-Seal: i=1; a=rsa-sha256; t=1569514991; cv=none; d=zoho.com; s=zohoarc; b=F5SQA+jsD5IXy7E+7AxvOm4nYdJKpHmObfweVdHlOakzxnDD51qSrZaX2kTqTKGfLUGeuTZ6F67G+zYe1Jqzyiaic9SL2N6R0DAfbipH2eHpz3p1dHmbt6ZI2UQ2IaNfIngkmy+3zr4BIK8Ka5ZQzSdZydhhocnsq1+ogV7Tg5Y= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1569514991; h=Content-Type:Content-Transfer-Encoding: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:ARC-Authentication-Results; bh=c3LfyF3l2+sTBH+++Chiq9NnRS5Mixvn1sWjCmuxtKk=; b=BEfq4+96IjHlnXBTLbSFg6sMbRvTSrOrxYUs6kXr+TTRim/yczfdGBLbV4YOGqk8ZD4sgjL8/naPRxnUjworAgtjYMWx/RFbLoBFVRj9h5tnQnyEEHOVloAJl06Vx1gZijiE4j78Bf2SHAGi/ziWnVnkcYWT0Bc0p5j2n8N5pE0= ARC-Authentication-Results: i=1; mx.zoho.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 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 1569514991908976.8973439787906; Thu, 26 Sep 2019 09:23:11 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 6209851EF4; Thu, 26 Sep 2019 16:23:10 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 3DFDE600CE; Thu, 26 Sep 2019 16:23:10 +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 020FA4EE6A; Thu, 26 Sep 2019 16:23:10 +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 x8QGEIPr003565 for ; Thu, 26 Sep 2019 12:14:18 -0400 Received: by smtp.corp.redhat.com (Postfix) id 603505D9D5; Thu, 26 Sep 2019 16:14:18 +0000 (UTC) Received: from moe.brq.redhat.com (unknown [10.43.2.30]) by smtp.corp.redhat.com (Postfix) with ESMTP id DEAAD5D9C3 for ; Thu, 26 Sep 2019 16:14:16 +0000 (UTC) From: Michal Privoznik To: libvir-list@redhat.com Date: Thu, 26 Sep 2019 18:12:17 +0200 Message-Id: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v2 21/39] domain_conf: Introduce virDomainDefHasNVMeDisk 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-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.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.30]); Thu, 26 Sep 2019 16:23:10 +0000 (UTC) Content-Type: text/plain; charset="utf-8" This function will return true if any of disks (or their backing chain) for given domain contains an NVMe disk. Signed-off-by: Michal Privoznik ACKed-by: Peter Krempa --- src/conf/domain_conf.c | 14 ++++++++++++++ src/conf/domain_conf.h | 3 +++ src/libvirt_private.syms | 1 + 3 files changed, 18 insertions(+) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index fe540c195e..98ee1f4058 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -31640,6 +31640,20 @@ virDomainDefHasManagedPR(const virDomainDef *def) } =20 =20 +bool +virDomainDefHasNVMeDisk(const virDomainDef *def) +{ + size_t i; + + for (i =3D 0; i < def->ndisks; i++) { + if (virStorageSourceChainHasNVMe(def->disks[i]->src)) + return true; + } + + return false; +} + + bool virDomainDefHasVFIOHostdev(const virDomainDef *def) { diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h index bf5d1a154b..ada2c70a8b 100644 --- a/src/conf/domain_conf.h +++ b/src/conf/domain_conf.h @@ -3666,6 +3666,9 @@ virDomainDiskGetDetectZeroesMode(virDomainDiskDiscard= discard, bool virDomainDefHasManagedPR(const virDomainDef *def); =20 +bool +virDomainDefHasNVMeDisk(const virDomainDef *def); + bool virDomainDefHasVFIOHostdev(const virDomainDef *def); =20 diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index 4e2a74a31b..d383dbe929 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -297,6 +297,7 @@ virDomainDefHasManagedPR; virDomainDefHasMdevHostdev; virDomainDefHasMemballoon; virDomainDefHasMemoryHotplug; +virDomainDefHasNVMeDisk; virDomainDefHasUSB; virDomainDefHasVcpusOffline; virDomainDefHasVFIOHostdev; --=20 2.21.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Sun May 19 20:29:53 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 ARC-Seal: i=1; a=rsa-sha256; t=1569514835; cv=none; d=zoho.com; s=zohoarc; b=mxLSXYR+ZfcjoyQT13px20vShgtLLIpJvQfz2pXukAHZRr8IuV9ts+0xXMvNBpUMU0DJDggPr5X1WeF6QsoadweQtfGMtnkiFi23ELbxsm/kJKOxwFFV0nKnzkZa7oOsmPWcXCcopgXO7QjunnI+EC4wmPODRXX48vNbWa9awDI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1569514835; h=Content-Type:Content-Transfer-Encoding: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:ARC-Authentication-Results; bh=zE6nhAWW7A7RiroGHV4w1EprraPFcoqyT+UAok/WboI=; b=JW9/P7c62W98HaharYgbXWdWofaGFcXRAZZyP7FdxMQgeSAV203i1FZ7+n7KofTzQYrfhjuvmHeoC73TaAAbqJ5pdR0fO+aaBZgWqjx19FALdKLF3sU8AOA1pojhP0UZXayPep6/9KDtW7fP4LeI+RMkA9/OW6jMFxG11/oojAY= ARC-Authentication-Results: i=1; mx.zoho.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 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 1569514835255977.1411480949613; Thu, 26 Sep 2019 09:20:35 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id B4B0D1918641; Thu, 26 Sep 2019 16:20:33 +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 6E4C15C21A; Thu, 26 Sep 2019 16:20:33 +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 1F7F518037CA; Thu, 26 Sep 2019 16:20:33 +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 x8QGEKEF003594 for ; Thu, 26 Sep 2019 12:14:20 -0400 Received: by smtp.corp.redhat.com (Postfix) id C09F15D9D5; Thu, 26 Sep 2019 16:14:20 +0000 (UTC) Received: from moe.brq.redhat.com (unknown [10.43.2.30]) by smtp.corp.redhat.com (Postfix) with ESMTP id 24AE25D9C3 for ; Thu, 26 Sep 2019 16:14:18 +0000 (UTC) From: Michal Privoznik To: libvir-list@redhat.com Date: Thu, 26 Sep 2019 18:12:18 +0200 Message-Id: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v2 22/39] util: Introduce virNVMeDevice module 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-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.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.6.2 (mx1.redhat.com [10.5.110.70]); Thu, 26 Sep 2019 16:20:34 +0000 (UTC) Content-Type: text/plain; charset="utf-8" This module will be used by virHostdevManager and it's inspired by virPCIDevice module. They are very similar except instead of what makes a NVMe device: PCI address AND namespace ID. This means that a NVMe device can appear in a domain multiple times, each time with a different namespace. Signed-off-by: Michal Privoznik --- src/libvirt_private.syms | 18 ++ src/util/Makefile.inc.am | 2 + src/util/virnvme.c | 454 +++++++++++++++++++++++++++++++++++++++ src/util/virnvme.h | 95 ++++++++ 4 files changed, 569 insertions(+) create mode 100644 src/util/virnvme.c create mode 100644 src/util/virnvme.h diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index d383dbe929..0c84b347db 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -2629,6 +2629,24 @@ virNumaSetPagePoolSize; virNumaSetupMemoryPolicy; =20 =20 +# util/virnvme.h +virNVMeDeviceAddressGet; +virNVMeDeviceCopy; +virNVMeDeviceFree; +virNVMeDeviceListAdd; +virNVMeDeviceListCount; +virNVMeDeviceListCreateDetachList; +virNVMeDeviceListDel; +virNVMeDeviceListGet; +virNVMeDeviceListLookup; +virNVMeDeviceListLookupIndex; +virNVMeDeviceListNew; +virNVMeDeviceNew; +virNVMeDeviceUsedByClear; +virNVMeDeviceUsedByGet; +virNVMeDeviceUsedBySet; + + # util/virobject.h virClassForObject; virClassForObjectLockable; diff --git a/src/util/Makefile.inc.am b/src/util/Makefile.inc.am index 482b657a90..7e677b891c 100644 --- a/src/util/Makefile.inc.am +++ b/src/util/Makefile.inc.am @@ -145,6 +145,8 @@ UTIL_SOURCES =3D \ util/virnetlink.h \ util/virnodesuspend.c \ util/virnodesuspend.h \ + util/virnvme.c \ + util/virnvme.h \ util/virkmod.c \ util/virkmod.h \ util/virnuma.c \ diff --git a/src/util/virnvme.c b/src/util/virnvme.c new file mode 100644 index 0000000000..f52955c615 --- /dev/null +++ b/src/util/virnvme.c @@ -0,0 +1,454 @@ +/* + * virnvme.c: helper APIs for managing NVMe devices + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library. If not, see + * . + */ + +#include + +#include "virnvme.h" +#include "virobject.h" +#include "virpci.h" +#include "viralloc.h" +#include "virlog.h" +#include "virstring.h" + +VIR_LOG_INIT("util.nvme"); +#define VIR_FROM_THIS VIR_FROM_NONE + +struct _virNVMeDevice { + virPCIDeviceAddress address; /* PCI address of controller */ + unsigned int namespace; /* Namespace ID */ + bool managed; + + char *drvname; + char *domname; +}; + + +struct _virNVMeDeviceList { + virObjectLockable parent; + + size_t count; + virNVMeDevicePtr *devs; +}; + + +static virClassPtr virNVMeDeviceListClass; + +static void virNVMeDeviceListDispose(void *obj); + +static int +virNVMeOnceInit(void) +{ + if (!VIR_CLASS_NEW(virNVMeDeviceList, virClassForObjectLockable())) + return -1; + + return 0; +} + +VIR_ONCE_GLOBAL_INIT(virNVMe); + + +virNVMeDevicePtr +virNVMeDeviceNew(const virPCIDeviceAddress *address, + unsigned long namespace, + bool managed) +{ + VIR_AUTOPTR(virNVMeDevice) dev =3D NULL; + + if (VIR_ALLOC(dev) < 0) + return NULL; + + virPCIDeviceAddressCopy(&dev->address, address); + dev->namespace =3D namespace; + dev->managed =3D managed; + + VIR_RETURN_PTR(dev); +} + + +void +virNVMeDeviceFree(virNVMeDevicePtr dev) +{ + if (!dev) + return; + + virNVMeDeviceUsedByClear(dev); + VIR_FREE(dev); +} + + +virNVMeDevicePtr +virNVMeDeviceCopy(const virNVMeDevice *dev) +{ + VIR_AUTOPTR(virNVMeDevice) copy =3D NULL; + + if (VIR_ALLOC(copy) < 0 || + VIR_STRDUP(copy->drvname, dev->drvname) < 0 || + VIR_STRDUP(copy->domname, dev->domname) < 0) + return NULL; + + virPCIDeviceAddressCopy(©->address, &dev->address); + copy->namespace =3D dev->namespace; + copy->managed =3D dev->managed; + + VIR_RETURN_PTR(copy); +} + + +const virPCIDeviceAddress * +virNVMeDeviceAddressGet(const virNVMeDevice *dev) +{ + return &dev->address; +} + + +void +virNVMeDeviceUsedByClear(virNVMeDevicePtr dev) +{ + VIR_FREE(dev->drvname); + VIR_FREE(dev->domname); +} + + +void +virNVMeDeviceUsedByGet(const virNVMeDevice *dev, + const char **drv, + const char **dom) +{ + *drv =3D dev->drvname; + *dom =3D dev->domname; +} + + +int +virNVMeDeviceUsedBySet(virNVMeDevicePtr dev, + const char *drv, + const char *dom) +{ + if (VIR_STRDUP(dev->drvname, drv) < 0 || + VIR_STRDUP(dev->domname, dom) < 0) { + virNVMeDeviceUsedByClear(dev); + return -1; + } + + return 0; +} + + +virNVMeDeviceListPtr +virNVMeDeviceListNew(void) +{ + virNVMeDeviceListPtr list; + + if (virNVMeInitialize() < 0) + return NULL; + + if (!(list =3D virObjectLockableNew(virNVMeDeviceListClass))) + return NULL; + + return list; +} + + +static void +virNVMeDeviceListDispose(void *obj) +{ + virNVMeDeviceListPtr list =3D obj; + size_t i; + + for (i =3D 0; i < list->count; i++) + virNVMeDeviceFree(list->devs[i]); + + VIR_FREE(list->devs); +} + + +size_t +virNVMeDeviceListCount(const virNVMeDeviceList *list) +{ + return list->count; +} + + +int +virNVMeDeviceListAdd(virNVMeDeviceListPtr list, + const virNVMeDevice *dev) +{ + virNVMeDevicePtr tmp; + + if ((tmp =3D virNVMeDeviceListLookup(list, dev))) { + VIR_AUTOFREE(char *) addrStr =3D virPCIDeviceAddressAsString(&tmp-= >address); + virReportError(VIR_ERR_INTERNAL_ERROR, + _("NVMe device %s namespace %u is already on the li= st"), + NULLSTR(addrStr), tmp->namespace); + return -1; + } + + if (!(tmp =3D virNVMeDeviceCopy(dev)) || + VIR_APPEND_ELEMENT(list->devs, list->count, tmp) < 0) { + virNVMeDeviceFree(tmp); + return -1; + } + + return 0; +} + + +int +virNVMeDeviceListDel(virNVMeDeviceListPtr list, + const virNVMeDevice *dev) +{ + ssize_t idx; + virNVMeDevicePtr tmp =3D NULL; + + if ((idx =3D virNVMeDeviceListLookupIndex(list, dev)) < 0) { + VIR_AUTOFREE(char *) addrStr =3D virPCIDeviceAddressAsString(&dev-= >address); + virReportError(VIR_ERR_INTERNAL_ERROR, + _("NVMe device %s namespace %u not found"), + NULLSTR(addrStr), dev->namespace); + return -1; + } + + tmp =3D list->devs[idx]; + VIR_DELETE_ELEMENT(list->devs, idx, list->count); + virNVMeDeviceFree(tmp); + return 0; +} + + +virNVMeDevicePtr +virNVMeDeviceListGet(virNVMeDeviceListPtr list, + size_t i) +{ + return i < list->count ? list->devs[i] : NULL; +} + + +virNVMeDevicePtr +virNVMeDeviceListLookup(virNVMeDeviceListPtr list, + const virNVMeDevice *dev) +{ + ssize_t idx; + + if ((idx =3D virNVMeDeviceListLookupIndex(list, dev)) < 0) + return NULL; + + return list->devs[idx]; +} + + +ssize_t +virNVMeDeviceListLookupIndex(virNVMeDeviceListPtr list, + const virNVMeDevice *dev) +{ + size_t i; + + if (!list) + return -1; + + for (i =3D 0; i < list->count; i++) { + virNVMeDevicePtr other =3D list->devs[i]; + + if (virPCIDeviceAddressEqual(&dev->address, &other->address) && + dev->namespace =3D=3D other->namespace) + return i; + } + + return -1; +} + + +static virNVMeDevicePtr +virNVMeDeviceListLookupByPCIAddress(virNVMeDeviceListPtr list, + const virPCIDeviceAddress *address) +{ + size_t i; + + if (!list) + return NULL; + + for (i =3D 0; i < list->count; i++) { + virNVMeDevicePtr other =3D list->devs[i]; + + if (virPCIDeviceAddressEqual(address, &other->address)) + return other; + } + + return NULL; +} + + +static virPCIDevicePtr +virNVMeDeviceCreatePCIDevice(const virNVMeDevice *nvme) +{ + VIR_AUTOPTR(virPCIDevice) pci =3D NULL; + + if (!(pci =3D virPCIDeviceNew(nvme->address.domain, + nvme->address.bus, + nvme->address.slot, + nvme->address.function))) + return NULL; + + /* NVMe devices must be bound to vfio */ + virPCIDeviceSetStubDriver(pci, VIR_PCI_STUB_DRIVER_VFIO); + virPCIDeviceSetManaged(pci, nvme->managed); + + VIR_RETURN_PTR(pci); +} + + +/** + * virNVMeDeviceListCreateDetachList: + * @activeList: list of active NVMe devices + * @toDetachList: list of NVMe devices to detach from the host + * + * This function creates a list of PCI devices which can then be + * reused by PCI device detach functions (e.g. + * virHostdevPreparePCIDevicesImpl()) as each PCI device from the + * returned list is initialized properly for detach. + * + * Basically, this just blindly collects unique PCI addresses + * from @toDetachList that don't appear on @activeList. + * + * Returns: a list on success, + * NULL otherwise. + */ +virPCIDeviceListPtr +virNVMeDeviceListCreateDetachList(virNVMeDeviceListPtr activeList, + virNVMeDeviceListPtr toDetachList) +{ + VIR_AUTOUNREF(virPCIDeviceListPtr) pciDevices =3D NULL; + size_t i; + + if (!(pciDevices =3D virPCIDeviceListNew())) + return NULL; + + for (i =3D 0; i < toDetachList->count; i++) { + const virNVMeDevice *d =3D toDetachList->devs[i]; + VIR_AUTOPTR(virPCIDevice) pci =3D NULL; + + /* If there is a NVMe device with the same PCI address on + * the activeList, the device is already detached. */ + if (virNVMeDeviceListLookupByPCIAddress(activeList, &d->address)) + continue; + + /* It may happen that we want to detach two namespaces + * from the same NVMe device. This will be represented as + * two different instances of virNVMeDevice, but + * obviously we want to put the PCI device on the detach + * list only once. */ + if (virPCIDeviceListFindByIDs(pciDevices, + d->address.domain, + d->address.bus, + d->address.slot, + d->address.function)) + continue; + + if (!(pci =3D virNVMeDeviceCreatePCIDevice(d))) + return NULL; + + if (virPCIDeviceListAdd(pciDevices, pci) < 0) + return NULL; + + /* avoid freeing the device */ + pci =3D NULL; + } + + VIR_RETURN_PTR(pciDevices); +} + + +/** + * virNVMeDeviceListCreateReAttachList: + * @activeList: list of active NVMe devices + * @toReAttachList: list of devices to reattach to the host + * + * This is a counterpart to virNVMeDeviceListCreateDetachList. + * + * This function creates a list of PCI devices which can then be + * reused by PCI device reattach functions (e.g. + * virHostdevReAttachPCIDevicesImpl()) as each PCI device from + * the returned list is initialized properly for reattach. + * + * Basically, this just collects unique PCI addresses + * of devices that appear on @toReAttachList and are used + * exactly once (i.e. no other namespaces are used from the same + * NVMe device). For that purpose, this function needs to know + * list of active NVMe devices (@activeList). + * + * Returns: a list on success, + * NULL otherwise. + */ +virPCIDeviceListPtr +virNVMeDeviceListCreateReAttachList(virNVMeDeviceListPtr activeList, + virNVMeDeviceListPtr toReAttachList) +{ + VIR_AUTOUNREF(virPCIDeviceListPtr) pciDevices =3D NULL; + size_t i; + + if (!(pciDevices =3D virPCIDeviceListNew())) + return NULL; + + for (i =3D 0; i < toReAttachList->count; i++) { + const virNVMeDevice *d =3D toReAttachList->devs[i]; + VIR_AUTOPTR(virPCIDevice) pci =3D NULL; + size_t nused =3D 0; + + /* Check if there is any other NVMe device with the same PCI addre= ss as + * @d. To simplify this, let's just count how many NVMe devices wi= th + * the same PCI address there are on the @activeList. */ + for (i =3D 0; i < activeList->count; i++) { + virNVMeDevicePtr other =3D activeList->devs[i]; + + if (!virPCIDeviceAddressEqual(&d->address, &other->address)) + continue; + + nused++; + } + + /* Now, the following cases can happen: + * nused > 1 -> there are other NVMe device active, do NOT detach= it + * nused =3D=3D 1 -> we've found only @d on the @activeList, detac= h it + * nused =3D=3D 0 -> huh, wait, what? @d is NOT on the @active lis= t, how can + * we reattach it? + */ + + if (nused =3D=3D 0) { + /* Shouldn't happen (TM) */ + VIR_AUTOFREE(char *) addrStr =3D virPCIDeviceAddressAsString(&= d->address); + virReportError(VIR_ERR_INTERNAL_ERROR, + _("NVMe device %s namespace %u not found"), + NULLSTR(addrStr), d->namespace); + return NULL; + } else if (nused > 1) { + /* NVMe device is still in use */ + continue; + } + + /* nused =3D=3D 1 -> detach the device */ + if (!(pci =3D virNVMeDeviceCreatePCIDevice(d))) + return NULL; + + if (virPCIDeviceListAdd(pciDevices, pci) < 0) + return NULL; + + /* avoid freeing the device */ + pci =3D NULL; + } + + VIR_RETURN_PTR(pciDevices); +} diff --git a/src/util/virnvme.h b/src/util/virnvme.h new file mode 100644 index 0000000000..e582f2b572 --- /dev/null +++ b/src/util/virnvme.h @@ -0,0 +1,95 @@ +/* + * virnvme.h: helper APIs for managing NVMe devices + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library. If not, see + * . + */ + +#pragma once + +#include "virpci.h" + +typedef struct _virNVMeDevice virNVMeDevice; +typedef virNVMeDevice *virNVMeDevicePtr; + +/* Note that this list is lockable, and in fact, it is caller's + * responsibility to acquire the lock and release it. The reason + * is that in a lot of cases the list must be locked between two + * API calls and therefore only caller knows when it is safe to + * finally release the lock. */ +typedef struct _virNVMeDeviceList virNVMeDeviceList; +typedef virNVMeDeviceList *virNVMeDeviceListPtr; + +virNVMeDevicePtr +virNVMeDeviceNew(const virPCIDeviceAddress *address, + unsigned long namespace, + bool managed); + +void +virNVMeDeviceFree(virNVMeDevicePtr dev); + +VIR_DEFINE_AUTOPTR_FUNC(virNVMeDevice, virNVMeDeviceFree); + +virNVMeDevicePtr +virNVMeDeviceCopy(const virNVMeDevice *dev); + +const virPCIDeviceAddress * +virNVMeDeviceAddressGet(const virNVMeDevice *dev); + +void +virNVMeDeviceUsedByClear(virNVMeDevicePtr dev); + +void +virNVMeDeviceUsedByGet(const virNVMeDevice *dev, + const char **drv, + const char **dom); + +int +virNVMeDeviceUsedBySet(virNVMeDevicePtr dev, + const char *drv, + const char *dom); + +virNVMeDeviceListPtr +virNVMeDeviceListNew(void); + +size_t +virNVMeDeviceListCount(const virNVMeDeviceList *list); + +int +virNVMeDeviceListAdd(virNVMeDeviceListPtr list, + const virNVMeDevice *dev); + +int +virNVMeDeviceListDel(virNVMeDeviceListPtr list, + const virNVMeDevice *dev); + +virNVMeDevicePtr +virNVMeDeviceListGet(virNVMeDeviceListPtr list, + size_t i); + +virNVMeDevicePtr +virNVMeDeviceListLookup(virNVMeDeviceListPtr list, + const virNVMeDevice *dev); + +ssize_t +virNVMeDeviceListLookupIndex(virNVMeDeviceListPtr list, + const virNVMeDevice *dev); + +virPCIDeviceListPtr +virNVMeDeviceListCreateDetachList(virNVMeDeviceListPtr activeList, + virNVMeDeviceListPtr toDetachList); + +virPCIDeviceListPtr +virNVMeDeviceListCreateReAttachList(virNVMeDeviceListPtr activeList, + virNVMeDeviceListPtr toReAttachList); --=20 2.21.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Sun May 19 20:29:53 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 ARC-Seal: i=1; a=rsa-sha256; t=1569514881; cv=none; d=zoho.com; s=zohoarc; b=MzU6iir6bIrFak6qaYdOtOXKKDYLI51Mnz8x8qFEnh1WDcOTJ1TQlXg7Xj8BisEy0P9rQkH2rYjOq+SpQONZnROG9dcOlhn6QkuCitLrIXRRRPjDeYpmH3Qk5Y3w4fCWiqe17XxMdmjnMilM9k65ctASggzMwMuQD1f5A+FJEgY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1569514881; h=Content-Type:Content-Transfer-Encoding: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:ARC-Authentication-Results; bh=Dk/HzvMX1LgxDZvJYu3g5eXDwjkDAM6uHTdDOZk79B4=; b=nYCT22IZ2H9Nhua96bYkD+GSakvs4dAXv5GX2ifs9xWdIQmzEC65/v1wO3DKmCh9yO27EqbEi/pSogdiNbXy5BJ08a+c/cyf5b9BGcCxLMN5pCVCd/Z78LcrS05Xdqy9Q8M+ZgawEkRWtPqMgN5YauKZCFvkiI1UHS9SSSIN/pQ= ARC-Authentication-Results: i=1; mx.zoho.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 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 1569514881616650.232761603927; Thu, 26 Sep 2019 09:21:21 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 107A9A44AE4; Thu, 26 Sep 2019 16:21:20 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id DEA225D9C3; Thu, 26 Sep 2019 16:21:19 +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 9EB1D4EE6A; Thu, 26 Sep 2019 16:21:19 +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 x8QGEPcO003621 for ; Thu, 26 Sep 2019 12:14:25 -0400 Received: by smtp.corp.redhat.com (Postfix) id 117765D9DC; Thu, 26 Sep 2019 16:14:25 +0000 (UTC) Received: from moe.brq.redhat.com (unknown [10.43.2.30]) by smtp.corp.redhat.com (Postfix) with ESMTP id 8E7365D9D5 for ; Thu, 26 Sep 2019 16:14:20 +0000 (UTC) From: Michal Privoznik To: libvir-list@redhat.com Date: Thu, 26 Sep 2019 18:12:19 +0200 Message-Id: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v2 23/39] virhostdev: Include virNVMeDevice module 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-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.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.6.2 (mx1.redhat.com [10.5.110.68]); Thu, 26 Sep 2019 16:21:20 +0000 (UTC) Content-Type: text/plain; charset="utf-8" Now that we have virNVMeDevice module (introduced in previous commit), let's use it int virHostdev to track which NVMe devices are free to be used by a domain and which are taken. Signed-off-by: Michal Privoznik --- src/libvirt_private.syms | 5 + src/util/virhostdev.c | 332 +++++++++++++++++++++++++++++++++++++++ src/util/virhostdev.h | 37 +++++ 3 files changed, 374 insertions(+) diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index 0c84b347db..ae8b41ce30 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -2113,18 +2113,23 @@ virHostdevPCINodeDeviceReAttach; virHostdevPCINodeDeviceReset; virHostdevPrepareDomainDevices; virHostdevPrepareMediatedDevices; +virHostdevPrepareNVMeDevices; +virHostdevPrepareOneNVMeDevice; virHostdevPreparePCIDevices; virHostdevPrepareSCSIDevices; virHostdevPrepareSCSIVHostDevices; virHostdevPrepareUSBDevices; virHostdevReAttachDomainDevices; virHostdevReAttachMediatedDevices; +virHostdevReAttachNVMeDevices; +virHostdevReAttachOneNVMeDevice; virHostdevReAttachPCIDevices; virHostdevReAttachSCSIDevices; virHostdevReAttachSCSIVHostDevices; virHostdevReAttachUSBDevices; virHostdevUpdateActiveDomainDevices; virHostdevUpdateActiveMediatedDevices; +virHostdevUpdateActiveNVMeDevices; virHostdevUpdateActivePCIDevices; virHostdevUpdateActiveSCSIDevices; virHostdevUpdateActiveUSBDevices; diff --git a/src/util/virhostdev.c b/src/util/virhostdev.c index f0c97ca887..9ccf79453c 100644 --- a/src/util/virhostdev.c +++ b/src/util/virhostdev.c @@ -138,6 +138,7 @@ virHostdevManagerDispose(void *obj) virObjectUnref(hostdevMgr->activeSCSIHostdevs); virObjectUnref(hostdevMgr->activeSCSIVHostHostdevs); virObjectUnref(hostdevMgr->activeMediatedHostdevs); + virObjectUnref(hostdevMgr->activeNVMeHostdevs); VIR_FREE(hostdevMgr->stateDir); } =20 @@ -168,6 +169,9 @@ virHostdevManagerNew(void) if (!(hostdevMgr->activeMediatedHostdevs =3D virMediatedDeviceListNew(= ))) return NULL; =20 + if (!(hostdevMgr->activeNVMeHostdevs =3D virNVMeDeviceListNew())) + return NULL; + if (privileged) { if (VIR_STRDUP(hostdevMgr->stateDir, HOSTDEV_STATE_DIR) < 0) return NULL; @@ -2240,3 +2244,331 @@ virHostdevUpdateActiveDomainDevices(virHostdevManag= erPtr mgr, =20 return 0; } + + +static int +virHostdevGetNVMeDeviceList(virNVMeDeviceListPtr nvmeDevices, + virStorageSourcePtr src, + const char *drv_name, + const char *dom_name) +{ + virStorageSourcePtr n; + + for (n =3D src; virStorageSourceIsBacking(n); n =3D n->backingStore) { + VIR_AUTOPTR(virNVMeDevice) dev =3D NULL; + const virStorageSourceNVMeDef *srcNVMe =3D n->nvme; + + if (n->type !=3D VIR_STORAGE_TYPE_NVME) + continue; + + if (!(dev =3D virNVMeDeviceNew(&srcNVMe->pciAddr, + srcNVMe->namespace, + srcNVMe->managed))) + return -1; + + if (virNVMeDeviceUsedBySet(dev, drv_name, dom_name) < 0) + return -1; + + if (virNVMeDeviceListAdd(nvmeDevices, dev) < 0) + return -1; + } + + return 0; +} + + +int +virHostdevPrepareOneNVMeDevice(virHostdevManagerPtr hostdev_mgr, + const char *drv_name, + const char *dom_name, + virStorageSourcePtr src) +{ + VIR_AUTOUNREF(virNVMeDeviceListPtr) nvmeDevices =3D NULL; + VIR_AUTOUNREF(virPCIDeviceListPtr) pciDevices =3D NULL; + const unsigned int pciFlags =3D 0; + virNVMeDevicePtr temp =3D NULL; + size_t i; + ssize_t lastGoodNVMeIdx =3D -1; + int ret =3D -1; + + if (!(nvmeDevices =3D virNVMeDeviceListNew())) + return -1; + + if (virHostdevGetNVMeDeviceList(nvmeDevices, src, drv_name, dom_name) = < 0) + return -1; + + if (virNVMeDeviceListCount(nvmeDevices) =3D=3D 0) + return 0; + + virObjectLock(hostdev_mgr->activeNVMeHostdevs); + + /* Firstly, let's check if all devices are free */ + for (i =3D 0; i < virNVMeDeviceListCount(nvmeDevices); i++) { + const virNVMeDevice *dev =3D virNVMeDeviceListGet(nvmeDevices, i); + const virPCIDeviceAddress *addr =3D NULL; + VIR_AUTOFREE(char *) addrStr =3D NULL; + const char *actual_drvname =3D NULL; + const char *actual_domname =3D NULL; + + temp =3D virNVMeDeviceListLookup(hostdev_mgr->activeNVMeHostdevs, = dev); + + /* Not on the list means not used */ + if (!temp) + continue; + + virNVMeDeviceUsedByGet(temp, &actual_drvname, &actual_domname); + addr =3D virNVMeDeviceAddressGet(dev); + addrStr =3D virPCIDeviceAddressAsString(addr); + + virReportError(VIR_ERR_OPERATION_INVALID, + _("NVMe device %s already in use by driver %s domai= n %s"), + NULLSTR(addrStr), actual_drvname, actual_domname); + goto cleanup; + } + + if (!(pciDevices =3D virNVMeDeviceListCreateDetachList(hostdev_mgr->ac= tiveNVMeHostdevs, + nvmeDevices))) + goto cleanup; + + /* Let's check if all PCI devices are NVMe disks. */ + for (i =3D 0; i < virPCIDeviceListCount(pciDevices); i++) { + virPCIDevicePtr pci =3D virPCIDeviceListGet(pciDevices, i); + VIR_AUTOFREE(char *) drvPath =3D NULL; + VIR_AUTOFREE(char *) drvName =3D NULL; + int stub =3D VIR_PCI_STUB_DRIVER_NONE; + + if (virPCIDeviceGetDriverPathAndName(pci, &drvPath, &drvName) < 0) + goto cleanup; + + if (drvName) + stub =3D virPCIStubDriverTypeFromString(drvName); + + if (stub =3D=3D VIR_PCI_STUB_DRIVER_VFIO || + STREQ_NULLABLE(drvName, "nvme")) + continue; + + VIR_WARN("Suspicious NVMe disk assignment. PCI device " + "%s is not an NVMe disk, it has %s driver", + virPCIDeviceGetName(pci), NULLSTR(drvName)); + } + + /* This looks like a good opportunity to merge inactive NVMe devices o= nto + * the active list. This, however, means that if something goes wrong = we + * have to perform a rollback before returning. */ + for (i =3D 0; i < virNVMeDeviceListCount(nvmeDevices); i++) { + temp =3D virNVMeDeviceListGet(nvmeDevices, i); + + if (virNVMeDeviceListAdd(hostdev_mgr->activeNVMeHostdevs, temp) < = 0) + goto rollback; + + lastGoodNVMeIdx =3D i; + } + + if (virHostdevPreparePCIDevicesImpl(hostdev_mgr, + drv_name, dom_name, NULL, + pciDevices, NULL, 0, pciFlags) < 0) + goto rollback; + + ret =3D 0; + cleanup: + virObjectUnlock(hostdev_mgr->activeNVMeHostdevs); + return ret; + + rollback: + while (lastGoodNVMeIdx >=3D 0) { + temp =3D virNVMeDeviceListGet(nvmeDevices, lastGoodNVMeIdx); + + virNVMeDeviceListDel(hostdev_mgr->activeNVMeHostdevs, temp); + + lastGoodNVMeIdx--; + } + goto cleanup; +} + + +int +virHostdevPrepareNVMeDevices(virHostdevManagerPtr hostdev_mgr, + const char *drv_name, + const char *dom_name, + virDomainDiskDefPtr *disks, + size_t ndisks) +{ + size_t i; + ssize_t lastGoodDiskIdx =3D -1; + + for (i =3D 0; i < ndisks; i++) { + if (virHostdevPrepareOneNVMeDevice(hostdev_mgr, drv_name, + dom_name, disks[i]->src) < 0) + goto rollback; + + lastGoodDiskIdx =3D i; + } + + return 0; + + rollback: + while (lastGoodDiskIdx >=3D 0) { + if (virHostdevReAttachOneNVMeDevice(hostdev_mgr, drv_name, dom_nam= e, + disks[lastGoodDiskIdx]->src) <= 0) { + VIR_ERROR(_("Failed to reattach NVMe for disk target: %s"), + disks[lastGoodDiskIdx]->dst); + } + + lastGoodDiskIdx--; + } + + return -1; +} + + +int +virHostdevReAttachOneNVMeDevice(virHostdevManagerPtr hostdev_mgr, + const char *drv_name, + const char *dom_name, + virStorageSourcePtr src) +{ + VIR_AUTOUNREF(virNVMeDeviceListPtr) nvmeDevices =3D NULL; + VIR_AUTOUNREF(virPCIDeviceListPtr) pciDevices =3D NULL; + size_t i; + int ret =3D -1; + + if (!(nvmeDevices =3D virNVMeDeviceListNew())) + return -1; + + if (virHostdevGetNVMeDeviceList(nvmeDevices, src, drv_name, dom_name) = < 0) + return -1; + + if (virNVMeDeviceListCount(nvmeDevices) =3D=3D 0) + return 0; + + virObjectLock(hostdev_mgr->activeNVMeHostdevs); + + if (!(pciDevices =3D virNVMeDeviceListCreateReAttachList(hostdev_mgr->= activeNVMeHostdevs, + nvmeDevices))) + goto cleanup; + + virHostdevReAttachPCIDevicesImpl(hostdev_mgr, + drv_name, dom_name, pciDevices, + NULL, 0, NULL); + + for (i =3D 0; i < virNVMeDeviceListCount(nvmeDevices); i++) { + virNVMeDevicePtr temp =3D virNVMeDeviceListGet(nvmeDevices, i); + + if (virNVMeDeviceListDel(hostdev_mgr->activeNVMeHostdevs, temp) < = 0) + goto cleanup; + } + + ret =3D 0; + cleanup: + virObjectUnlock(hostdev_mgr->activeNVMeHostdevs); + return ret; +} + + +int +virHostdevReAttachNVMeDevices(virHostdevManagerPtr hostdev_mgr, + const char *drv_name, + const char *dom_name, + virDomainDiskDefPtr *disks, + size_t ndisks) +{ + size_t i; + int ret =3D 0; + + /* Contrary to virHostdevPrepareNVMeDevices, this is a best + * effort approach. Just iterate over all disks and try to + * reattach them. Don't stop at the first failure. */ + for (i =3D 0; i < ndisks; i++) { + if (virHostdevReAttachOneNVMeDevice(hostdev_mgr, drv_name, + dom_name, disks[i]->src) < 0) { + VIR_ERROR(_("Failed to reattach NVMe for disk target: %s"), + disks[i]->dst); + ret =3D -1; + } + } + + return ret; +} + + +int +virHostdevUpdateActiveNVMeDevices(virHostdevManagerPtr hostdev_mgr, + const char *drv_name, + const char *dom_name, + virDomainDiskDefPtr *disks, + size_t ndisks) +{ + VIR_AUTOUNREF(virNVMeDeviceListPtr) nvmeDevices =3D NULL; + VIR_AUTOUNREF(virPCIDeviceListPtr) pciDevices =3D NULL; + virNVMeDevicePtr temp =3D NULL; + size_t i; + ssize_t lastGoodNVMeIdx =3D -1; + ssize_t lastGoodPCIIdx =3D -1; + int ret =3D -1; + + if (!(nvmeDevices =3D virNVMeDeviceListNew())) + return -1; + + for (i =3D 0; i < ndisks; i++) { + if (virHostdevGetNVMeDeviceList(nvmeDevices, disks[i]->src, drv_na= me, dom_name) < 0) + return -1; + } + + if (virNVMeDeviceListCount(nvmeDevices) =3D=3D 0) + return 0; + + virObjectLock(hostdev_mgr->activeNVMeHostdevs); + virObjectLock(hostdev_mgr->activePCIHostdevs); + virObjectLock(hostdev_mgr->inactivePCIHostdevs); + + if (!(pciDevices =3D virNVMeDeviceListCreateDetachList(hostdev_mgr->ac= tiveNVMeHostdevs, + nvmeDevices))) + goto cleanup; + + for (i =3D 0; i < virNVMeDeviceListCount(nvmeDevices); i++) { + temp =3D virNVMeDeviceListGet(nvmeDevices, i); + + if (virNVMeDeviceListAdd(hostdev_mgr->activeNVMeHostdevs, temp) < = 0) + goto rollback; + + lastGoodNVMeIdx =3D i; + } + + for (i =3D 0; i < virPCIDeviceListCount(pciDevices); i++) { + virPCIDevicePtr actual =3D virPCIDeviceListGet(pciDevices, i); + + /* We must restore some attributes that were lost on daemon restar= t. */ + virPCIDeviceSetUnbindFromStub(actual, true); + if (virPCIDeviceSetUsedBy(actual, drv_name, dom_name) < 0) + goto rollback; + + if (virPCIDeviceListAddCopy(hostdev_mgr->activePCIHostdevs, actual= ) < 0) + goto rollback; + + lastGoodPCIIdx =3D i; + } + + ret =3D 0; + cleanup: + virObjectUnlock(hostdev_mgr->inactivePCIHostdevs); + virObjectUnlock(hostdev_mgr->activePCIHostdevs); + virObjectUnlock(hostdev_mgr->activeNVMeHostdevs); + return ret; + + rollback: + while (lastGoodNVMeIdx >=3D 0) { + temp =3D virNVMeDeviceListGet(nvmeDevices, lastGoodNVMeIdx); + + virNVMeDeviceListDel(hostdev_mgr->activeNVMeHostdevs, temp); + + lastGoodNVMeIdx--; + } + while (lastGoodPCIIdx >=3D 0) { + virPCIDevicePtr actual =3D virPCIDeviceListGet(pciDevices, i); + + virPCIDeviceListDel(hostdev_mgr->activePCIHostdevs, actual); + + lastGoodPCIIdx--; + } + goto cleanup; +} diff --git a/src/util/virhostdev.h b/src/util/virhostdev.h index c7ef2055c1..372eca2751 100644 --- a/src/util/virhostdev.h +++ b/src/util/virhostdev.h @@ -29,6 +29,7 @@ #include "virscsivhost.h" #include "conf/domain_conf.h" #include "virmdev.h" +#include "virnvme.h" =20 typedef enum { VIR_HOSTDEV_STRICT_ACS_CHECK =3D (1 << 0), /* strict acs check */ @@ -53,6 +54,9 @@ struct _virHostdevManager { virSCSIDeviceListPtr activeSCSIHostdevs; virSCSIVHostDeviceListPtr activeSCSIVHostHostdevs; virMediatedDeviceListPtr activeMediatedHostdevs; + /* NVMe devices are PCI devices really, but one NVMe disk can + * have multiple namespaces. */ + virNVMeDeviceListPtr activeNVMeHostdevs; }; =20 virHostdevManagerPtr virHostdevManagerGetDefault(void); @@ -204,3 +208,36 @@ int virHostdevPCINodeDeviceReAttach(virHostdevManagerP= tr mgr, int virHostdevPCINodeDeviceReset(virHostdevManagerPtr mgr, virPCIDevicePtr pci) ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2); + +int +virHostdevPrepareOneNVMeDevice(virHostdevManagerPtr hostdev_mgr, + const char *drv_name, + const char *dom_name, + virStorageSourcePtr src); + +int +virHostdevPrepareNVMeDevices(virHostdevManagerPtr hostdev_mgr, + const char *drv_name, + const char *dom_name, + virDomainDiskDefPtr *disks, + size_t ndisks); + +int +virHostdevReAttachOneNVMeDevice(virHostdevManagerPtr hostdev_mgr, + const char *drv_name, + const char *dom_name, + virStorageSourcePtr src); + +int +virHostdevReAttachNVMeDevices(virHostdevManagerPtr hostdev_mgr, + const char *drv_name, + const char *dom_name, + virDomainDiskDefPtr *disks, + size_t ndisks); + +int +virHostdevUpdateActiveNVMeDevices(virHostdevManagerPtr hostdev_mgr, + const char *drv_name, + const char *dom_name, + virDomainDiskDefPtr *disks, + size_t ndisks); --=20 2.21.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Sun May 19 20:29:53 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 ARC-Seal: i=1; a=rsa-sha256; t=1569514894; cv=none; d=zoho.com; s=zohoarc; b=jgMSnknx2V02XZcR6Vk+HVdeVytQwnlDqJZ1nuokMpE4W9yb5MSq6rvIWQ2uDKTFchPABep+Yh3V9ET/JzhhvAJu1YWLqYfHww32CyHo80w1OOidjiHhR2OJ3NKFCLlZUP/rJ31DD25wy6LToBpcRq/ilmpvioN0p3QD9b8uIi0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1569514894; h=Content-Type:Content-Transfer-Encoding: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:ARC-Authentication-Results; bh=aLaNVdwD/oqRq/08qTjVcpOLZAD6gZiVC2FI3ZwgMr0=; b=gj4RaPaJY8u4lrqxENsZrAvTRhwjuy39WRwYppt4S+yV1IDWcCJNvo0pejrUEpPFR2Bryz67lWJvaVj6KCRzmCGpb2PPWsgxswakxQLcm4hTlUeyZsc0KDPYKe+7GYo7olqGq8wPyMBU6q/vY6uQvZmDSqYEBAk3PVk7cvBaHsY= ARC-Authentication-Results: i=1; mx.zoho.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 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 1569514894064537.429349129827; Thu, 26 Sep 2019 09:21:34 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 5B46430ADBAF; Thu, 26 Sep 2019 16:21: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 3511160923; Thu, 26 Sep 2019 16:21:32 +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 E66CE18089C8; Thu, 26 Sep 2019 16:21:31 +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 x8QGERvO003646 for ; Thu, 26 Sep 2019 12:14:27 -0400 Received: by smtp.corp.redhat.com (Postfix) id 4C3215D9CD; Thu, 26 Sep 2019 16:14:27 +0000 (UTC) Received: from moe.brq.redhat.com (unknown [10.43.2.30]) by smtp.corp.redhat.com (Postfix) with ESMTP id CA4BE5D9C3 for ; Thu, 26 Sep 2019 16:14:25 +0000 (UTC) From: Michal Privoznik To: libvir-list@redhat.com Date: Thu, 26 Sep 2019 18:12:20 +0200 Message-Id: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v2 24/39] virpcimock: Introduce NVMe driver and devices 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-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.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.47]); Thu, 26 Sep 2019 16:21:33 +0000 (UTC) Content-Type: text/plain; charset="utf-8" The device configs (which are actually the same one config) come from a NVMe disk of mine. Signed-off-by: Michal Privoznik ACKed-by: Peter Krempa --- tests/virpcimock.c | 3 +++ tests/virpcitestdata/0000-01-00.0.config | Bin 0 -> 4096 bytes tests/virpcitestdata/0000-02-00.0.config | Bin 0 -> 4096 bytes 3 files changed, 3 insertions(+) create mode 100644 tests/virpcitestdata/0000-01-00.0.config create mode 100644 tests/virpcitestdata/0000-02-00.0.config diff --git a/tests/virpcimock.c b/tests/virpcimock.c index edb558b6ec..c36d3e1371 100644 --- a/tests/virpcimock.c +++ b/tests/virpcimock.c @@ -1017,6 +1017,7 @@ init_env(void) MAKE_PCI_DRIVER("iwlwifi", 0x8086, 0x0044); MAKE_PCI_DRIVER("i915", 0x8086, 0x0046, 0x8086, 0x0047); MAKE_PCI_DRIVER("vfio-pci", -1, -1); + MAKE_PCI_DRIVER("nvme", 0x1cc1, 0x8201); =20 # define MAKE_PCI_DEVICE(Id, Vendor, Device, IommuGroup, ...) \ do { \ @@ -1052,6 +1053,8 @@ init_env(void) MAKE_PCI_DEVICE("0021:de:1f.1", 0x8086, 0x0047, 13, .physfn =3D "0021:de:1f.0"); /* Virtual Function */ =20 + MAKE_PCI_DEVICE("0000:01:00.0", 0x1cc1, 0x8201, 14, .klass =3D 0x01080= 2); + MAKE_PCI_DEVICE("0000:02:00.0", 0x1cc1, 0x8201, 15, .klass =3D 0x01080= 2); } =20 =20 diff --git a/tests/virpcitestdata/0000-01-00.0.config b/tests/virpcitestdat= a/0000-01-00.0.config new file mode 100644 index 0000000000000000000000000000000000000000..f92455e2ac5701ce60a51ae1982= 8658b80744399 GIT binary patch literal 4096 zcmeHIF;Buk6#lMP3WC_80!0h0vM?|ZHYb~)#L>jXKcF*Mr%9L>;{S2-*!p%x w=3Db5pKIZ+ec2|JnLT|5EZ*;+MDr9bc*RexLU6J#~1fK)&#@Fxm<1DBgMR{#J2 literal 0 HcmV?d00001 diff --git a/tests/virpcitestdata/0000-02-00.0.config b/tests/virpcitestdat= a/0000-02-00.0.config new file mode 100644 index 0000000000000000000000000000000000000000..ebb44d8f69c91809b82e8d26690= 26dfff42c3100 GIT binary patch literal 4096 zcmeHIJ5Iwu5Pj>-$HXLdfc(IT4QW!Oh|*DEDG*U2(QpB%)6hF9Xc0G{-~cHpZ9zfJ z322bGLCP>|J5DSjlp;bw+F5C5_RZVz>a9KYO*YD;3~)tdAWH!g;g^|DT!A}LQllO0 zfKOBAGo6v%Nj66qpz7dAnM2{>Nx zI9e@W7?nb%gO1$~!w=3Dvwj8>jg7)EtS6WUe7uo7>+ML1#rsDf3w!Hov7tz0X}jA<@| znO4!A1^^YZtw!BE*soP9<Vm(Pe#2&br`1}!)cEm@WPoIaHr{&J59pe0RNAZ%Qm+& w+Ruz#E{GcIPT1)j@8SvQ&et-M3anQFH~E3rsQUYQpCGGA1*8H}fj?2;8=3Dmzw{{R30 literal 0 HcmV?d00001 --=20 2.21.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Sun May 19 20:29:53 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 ARC-Seal: i=1; a=rsa-sha256; t=1569515005; cv=none; d=zoho.com; s=zohoarc; b=S3Hg49MHoZ9ussrWt6ksxfzwHycJMD81VGGpdJcFoZNF8YDMcet3KyVheJ7pwg3gzK7Bue2k8MHerAKkEy6NU7KPWb4sVurL+PR53zKAKPoh5d2ZCXAOoFYCBWK1Q3tvp3o+05O9vZi+bkerAWN2nQx5dn+KzMqd0+DEOqr1QCc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1569515005; h=Content-Type:Content-Transfer-Encoding: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:ARC-Authentication-Results; bh=2TJpZVtnH050qKMO7CC9/8MjI91kkT+XnTXpE6tEZ58=; b=ZBiGI02+sVphO87h8+IdMDDD0S8Nc9kE0mMAChZXDhLVYfPPJ7pwITZZNgAvN5iTMpxTcyI1hHn371NZztJSjB10/VzaC04XRcyt9eF9DeNMINuz+NsVQBHMljH3E5OgdgU+hjs1g4ANjPvqmwi55xjqWCGNUpn4/iK3nZxqpfg= ARC-Authentication-Results: i=1; mx.zoho.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 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 156951500538770.83089216094129; Thu, 26 Sep 2019 09:23:25 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id B84403086228; Thu, 26 Sep 2019 16:23:23 +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 8F4435C21A; Thu, 26 Sep 2019 16:23:23 +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 51FD21803518; Thu, 26 Sep 2019 16:23:23 +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 x8QGEUX4003659 for ; Thu, 26 Sep 2019 12:14:30 -0400 Received: by smtp.corp.redhat.com (Postfix) id 95D8D5D9C3; Thu, 26 Sep 2019 16:14:30 +0000 (UTC) Received: from moe.brq.redhat.com (unknown [10.43.2.30]) by smtp.corp.redhat.com (Postfix) with ESMTP id 1F20E5D9D5 for ; Thu, 26 Sep 2019 16:14:27 +0000 (UTC) From: Michal Privoznik To: libvir-list@redhat.com Date: Thu, 26 Sep 2019 18:12:21 +0200 Message-Id: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v2 25/39] virhostdevtest: Test virNVMeDevice assignment 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-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.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.42]); Thu, 26 Sep 2019 16:23:24 +0000 (UTC) Content-Type: text/plain; charset="utf-8" Signed-off-by: Michal Privoznik ACKed-by: Peter Krempa --- tests/virhostdevtest.c | 97 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 97 insertions(+) diff --git a/tests/virhostdevtest.c b/tests/virhostdevtest.c index 46627355c3..fde7f92bc4 100644 --- a/tests/virhostdevtest.c +++ b/tests/virhostdevtest.c @@ -48,6 +48,9 @@ VIR_LOG_INIT("tests.hostdevtest"); # define CHECK_PCI_LIST_COUNT(list, cnt) \ CHECK_LIST_COUNT(list, cnt, virPCIDeviceListCount) =20 +# define CHECK_NVME_LIST_COUNT(list, cnt) \ + CHECK_LIST_COUNT(list, cnt, virNVMeDeviceListCount) + # define TEST_STATE_DIR abs_builddir "/hostdevmgr" static const char *drv_name =3D "test_driver"; static const char *dom_name =3D "test_domain"; @@ -57,6 +60,36 @@ static int nhostdevs =3D 3; static virDomainHostdevDefPtr hostdevs[] =3D {NULL, NULL, NULL}; static virPCIDevicePtr dev[] =3D {NULL, NULL, NULL}; static virHostdevManagerPtr mgr; +static const size_t ndisks =3D 3; +static virDomainDiskDefPtr disks[] =3D {NULL, NULL, NULL}; +static const char *diskXML[] =3D { + "" + " " + " " + "
" + " " + " " + "
" + "", + + "" + " " + " " + "
" + " " + " " + "
" + "", + + "" + " " + " " + "
" + " " + " " + "
" + "" +}; =20 static void myCleanup(void) @@ -67,6 +100,9 @@ myCleanup(void) virDomainHostdevDefFree(hostdevs[i]); } =20 + for (i =3D 0; i < ndisks; i++) + virDomainDiskDefFree(disks[i]); + if (mgr) { if (!getenv("LIBVIRT_SKIP_CLEANUP")) virFileDeleteTree(mgr->stateDir); @@ -75,6 +111,7 @@ myCleanup(void) virObjectUnref(mgr->activeUSBHostdevs); virObjectUnref(mgr->inactivePCIHostdevs); virObjectUnref(mgr->activeSCSIHostdevs); + virObjectUnref(mgr->activeNVMeHostdevs); VIR_FREE(mgr->stateDir); VIR_FREE(mgr); } @@ -107,6 +144,11 @@ myInit(void) virPCIDeviceSetStubDriver(dev[i], VIR_PCI_STUB_DRIVER_VFIO); } =20 + for (i =3D 0; i < ndisks; i++) { + if (!(disks[i] =3D virDomainDiskDefParse(diskXML[i], NULL, NULL, 0= ))) + goto cleanup; + } + if (VIR_ALLOC(mgr) < 0) goto cleanup; if ((mgr->activePCIHostdevs =3D virPCIDeviceListNew()) =3D=3D NULL) @@ -117,6 +159,8 @@ myInit(void) goto cleanup; if ((mgr->activeSCSIHostdevs =3D virSCSIDeviceListNew()) =3D=3D NULL) goto cleanup; + if ((mgr->activeNVMeHostdevs =3D virNVMeDeviceListNew()) =3D=3D NULL) + goto cleanup; if (VIR_STRDUP(mgr->stateDir, TEST_STATE_DIR) < 0) goto cleanup; if (virFileMakePath(mgr->stateDir) < 0) @@ -493,6 +537,58 @@ testVirHostdevOther(const void *opaque ATTRIBUTE_UNUSE= D) return 0; } =20 +static int +testNVMeDiskRoundtrip(const void *opaque ATTRIBUTE_UNUSED) +{ + int ret =3D -1; + + /* Don't rely on a state that previous test cases might have + * left the manager in. Start with a clean slate. */ + virHostdevReAttachPCIDevices(mgr, drv_name, dom_name, + hostdevs, nhostdevs, NULL); + + CHECK_NVME_LIST_COUNT(mgr->activeNVMeHostdevs, 0); + CHECK_PCI_LIST_COUNT(mgr->activePCIHostdevs, 0); + CHECK_PCI_LIST_COUNT(mgr->inactivePCIHostdevs, 0); + + /* Firstly, attach all NVMe disks */ + if (virHostdevPrepareNVMeDevices(mgr, drv_name, dom_name, disks, ndisk= s) < 0) + goto cleanup; + + CHECK_NVME_LIST_COUNT(mgr->activeNVMeHostdevs, 3); + CHECK_PCI_LIST_COUNT(mgr->activePCIHostdevs, 2); + CHECK_PCI_LIST_COUNT(mgr->inactivePCIHostdevs, 0); + + /* Now, try to detach the first one. */ + if (virHostdevReAttachNVMeDevices(mgr, drv_name, dom_name, disks, 1) <= 0) + goto cleanup; + + CHECK_NVME_LIST_COUNT(mgr->activeNVMeHostdevs, 2); + CHECK_PCI_LIST_COUNT(mgr->activePCIHostdevs, 2); + CHECK_PCI_LIST_COUNT(mgr->inactivePCIHostdevs, 0); + + /* And the last one */ + if (virHostdevReAttachNVMeDevices(mgr, drv_name, dom_name, &disks[2], = 1) < 0) + goto cleanup; + + CHECK_NVME_LIST_COUNT(mgr->activeNVMeHostdevs, 1); + CHECK_PCI_LIST_COUNT(mgr->activePCIHostdevs, 1); + CHECK_PCI_LIST_COUNT(mgr->inactivePCIHostdevs, 0); + + /* Finally, detach the middle one */ + if (virHostdevReAttachNVMeDevices(mgr, drv_name, dom_name, &disks[1], = 1) < 0) + goto cleanup; + + CHECK_NVME_LIST_COUNT(mgr->activeNVMeHostdevs, 0); + CHECK_PCI_LIST_COUNT(mgr->activePCIHostdevs, 0); + CHECK_PCI_LIST_COUNT(mgr->inactivePCIHostdevs, 0); + + ret =3D 0; + cleanup: + return ret; +} + + # define FAKEROOTDIRTEMPLATE abs_builddir "/fakerootdir-XXXXXX" =20 static int @@ -530,6 +626,7 @@ mymain(void) DO_TEST(testVirHostdevRoundtripManaged); DO_TEST(testVirHostdevRoundtripMixed); DO_TEST(testVirHostdevOther); + DO_TEST(testNVMeDiskRoundtrip); =20 myCleanup(); =20 --=20 2.21.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Sun May 19 20:29:53 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 ARC-Seal: i=1; a=rsa-sha256; t=1569514847; cv=none; d=zoho.com; s=zohoarc; b=H8YBfDfzieMC9QAP1/BxgwycTFYBm8dz1kyng0FSQbwS8GCLAOw2va8NSLwxkxxE1s9F+/ROyPd8f6z5uzVPASNTykfWwIgM3alBNxddlvv3L5gAb+BdTPmZ+LB3S4xD5rYDOG+aMREFB8H6P80v9zK0b1qCQNSp/68WX9pxI0c= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1569514847; h=Content-Type:Content-Transfer-Encoding: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:ARC-Authentication-Results; bh=cDYCJIhYz6yJhTTdBAy6KFYOuOMfuSL6VbjUvR/WAVY=; b=kx/DDzGXIfy77Jdy8IdsR6DK+Cyn0lXH204IM+EVl5qTwWA+ewQo8YCdS+6kKanJhtbaPJG4O4SvxEowuy3CWKTzX6fYPOI1SXohwTkQK3Lcz7jRAO1cKj1ZivO0tDYWK/yL7t0ooZ7kKo+ISiOTgFpCP1xaP+s4wyJuD6jp56s= ARC-Authentication-Results: i=1; mx.zoho.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 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 1569514847637968.1027201254612; Thu, 26 Sep 2019 09:20:47 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 165788A1CAB; Thu, 26 Sep 2019 16:20:46 +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 E64C75D9CD; Thu, 26 Sep 2019 16:20:45 +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 B0350180BA99; Thu, 26 Sep 2019 16:20:45 +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 x8QGEWAO003679 for ; Thu, 26 Sep 2019 12:14:33 -0400 Received: by smtp.corp.redhat.com (Postfix) id EECDF5D9D5; Thu, 26 Sep 2019 16:14:32 +0000 (UTC) Received: from moe.brq.redhat.com (unknown [10.43.2.30]) by smtp.corp.redhat.com (Postfix) with ESMTP id 769CA5D9CD for ; Thu, 26 Sep 2019 16:14:30 +0000 (UTC) From: Michal Privoznik To: libvir-list@redhat.com Date: Thu, 26 Sep 2019 18:12:22 +0200 Message-Id: <1b35041a22b5fdf44759b7318ad9aa255834933e.1569514291.git.mprivozn@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v2 26/39] qemu: prepare NVMe devices too 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-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.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.6.2 (mx1.redhat.com [10.5.110.69]); Thu, 26 Sep 2019 16:20:46 +0000 (UTC) Content-Type: text/plain; charset="utf-8" The qemu driver has its own wrappers around virHostdev module (so that some arguments are filled in automatically). Extend these to include NVMe devices too. Signed-off-by: Michal Privoznik ACKed-by: Peter Krempa --- src/qemu/qemu_hostdev.c | 49 ++++++++++++++++++++++++++++++++++++++--- src/qemu/qemu_hostdev.h | 10 +++++++++ 2 files changed, 56 insertions(+), 3 deletions(-) diff --git a/src/qemu/qemu_hostdev.c b/src/qemu/qemu_hostdev.c index ebbca817b8..5ab0217858 100644 --- a/src/qemu/qemu_hostdev.c +++ b/src/qemu/qemu_hostdev.c @@ -96,13 +96,28 @@ qemuHostdevUpdateActiveMediatedDevices(virQEMUDriverPtr= driver, } =20 =20 +int +qemuHostdevUpdateActiveNVMeDisks(virQEMUDriverPtr driver, + virDomainDefPtr def) +{ + return virHostdevUpdateActiveNVMeDevices(driver->hostdevMgr, + QEMU_DRIVER_NAME, + def->name, + def->disks, + def->ndisks); +} + + int qemuHostdevUpdateActiveDomainDevices(virQEMUDriverPtr driver, virDomainDefPtr def) { - if (!def->nhostdevs) + if (!def->nhostdevs && !def->ndisks) return 0; =20 + if (qemuHostdevUpdateActiveNVMeDisks(driver, def) < 0) + return -1; + if (qemuHostdevUpdateActivePCIDevices(driver, def) < 0) return -1; =20 @@ -197,6 +212,17 @@ qemuHostdevPreparePCIDevicesCheckSupport(virDomainHost= devDefPtr *hostdevs, return true; } =20 +int +qemuHostdevPrepareNVMeDisks(virQEMUDriverPtr driver, + const char *name, + virDomainDiskDefPtr *disks, + size_t ndisks) +{ + return virHostdevPrepareNVMeDevices(driver->hostdevMgr, + QEMU_DRIVER_NAME, + name, disks, ndisks); +} + int qemuHostdevPreparePCIDevices(virQEMUDriverPtr driver, const char *name, @@ -313,9 +339,12 @@ qemuHostdevPrepareDomainDevices(virQEMUDriverPtr drive= r, virQEMUCapsPtr qemuCaps, unsigned int flags) { - if (!def->nhostdevs) + if (!def->nhostdevs && !def->ndisks) return 0; =20 + if (qemuHostdevPrepareNVMeDisks(driver, def->name, def->disks, def->nd= isks) < 0) + return -1; + if (qemuHostdevPreparePCIDevices(driver, def->name, def->uuid, def->hostdevs, def->nhostdevs, qemuCaps, flags) < 0) @@ -340,6 +369,17 @@ qemuHostdevPrepareDomainDevices(virQEMUDriverPtr drive= r, return 0; } =20 +void +qemuHostdevReAttachNVMeDisks(virQEMUDriverPtr driver, + const char *name, + virDomainDiskDefPtr *disks, + size_t ndisks) +{ + virHostdevReAttachNVMeDevices(driver->hostdevMgr, + QEMU_DRIVER_NAME, + name, disks, ndisks); +} + void qemuHostdevReAttachPCIDevices(virQEMUDriverPtr driver, const char *name, @@ -419,9 +459,12 @@ void qemuHostdevReAttachDomainDevices(virQEMUDriverPtr driver, virDomainDefPtr def) { - if (!def->nhostdevs) + if (!def->nhostdevs && !def->ndisks) return; =20 + qemuHostdevReAttachNVMeDisks(driver, def->name, def->disks, + def->ndisks); + qemuHostdevReAttachPCIDevices(driver, def->name, def->hostdevs, def->nhostdevs); =20 diff --git a/src/qemu/qemu_hostdev.h b/src/qemu/qemu_hostdev.h index 536069fe8a..735414b6aa 100644 --- a/src/qemu/qemu_hostdev.h +++ b/src/qemu/qemu_hostdev.h @@ -28,6 +28,8 @@ bool qemuHostdevNeedsVFIO(const virDomainHostdevDef *host= dev); =20 bool qemuHostdevHostSupportsPassthroughVFIO(void); =20 +int qemuHostdevUpdateActiveNVMeDisks(virQEMUDriverPtr driver, + virDomainDefPtr def); int qemuHostdevUpdateActiveMediatedDevices(virQEMUDriverPtr driver, virDomainDefPtr def); int qemuHostdevUpdateActivePCIDevices(virQEMUDriverPtr driver, @@ -39,6 +41,10 @@ int qemuHostdevUpdateActiveSCSIDevices(virQEMUDriverPtr = driver, int qemuHostdevUpdateActiveDomainDevices(virQEMUDriverPtr driver, virDomainDefPtr def); =20 +int qemuHostdevPrepareNVMeDisks(virQEMUDriverPtr driver, + const char *name, + virDomainDiskDefPtr *disks, + size_t ndisks); int qemuHostdevPreparePCIDevices(virQEMUDriverPtr driver, const char *name, const unsigned char *uuid, @@ -68,6 +74,10 @@ int qemuHostdevPrepareDomainDevices(virQEMUDriverPtr dri= ver, virQEMUCapsPtr qemuCaps, unsigned int flags); =20 +void qemuHostdevReAttachNVMeDisks(virQEMUDriverPtr driver, + const char *name, + virDomainDiskDefPtr *disks, + size_t ndisks); void qemuHostdevReAttachPCIDevices(virQEMUDriverPtr driver, const char *name, virDomainHostdevDefPtr *hostdevs, --=20 2.21.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Sun May 19 20:29:53 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 ARC-Seal: i=1; a=rsa-sha256; t=1569514858; cv=none; d=zoho.com; s=zohoarc; b=WwLuHOTRxS+ZF2l0GvM4BZ0QuwHxB54eRmaldfDfysCkvSuJMuhSo2fFMOgHU38UN/CrQZmwh3cc0pUKxKHLE1dIFOhaV3A9Jz+xcEeNMZY7EnYPHuCfXcSAoSC3TbZFHwSnVUbqblwl3x7NjViH8XVqG/x97b4+bX8TiJ3V9CA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1569514858; h=Content-Type:Content-Transfer-Encoding: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:ARC-Authentication-Results; bh=vETIFKJyZ67cGYOj5ufO9Z8rbBjOwtGapyDT1cWRcH8=; b=ckwJaLwDD+wxhxCCAzZlL8Zv7yoFxP3fVHlZkPP2HP0Wze3a96RVbxOBMMoJtIGHg1ZAuzM7oYqVGf6t9+XmhaO0FLWo3hUzWJpeyWo5/8XNMERU0LZ0ZaP//bB+ie5ffcuDxF+U877LCjE78hroAnyE4vSmGwjPS4AZX0wg1iU= ARC-Authentication-Results: i=1; mx.zoho.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 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 1569514858741595.7187876024567; Thu, 26 Sep 2019 09:20:58 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 4320B4FCDA; Thu, 26 Sep 2019 16:20:57 +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 16F5A5C224; Thu, 26 Sep 2019 16:20:57 +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 BDEC718037CA; Thu, 26 Sep 2019 16:20:56 +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 x8QGEZdb003713 for ; Thu, 26 Sep 2019 12:14:35 -0400 Received: by smtp.corp.redhat.com (Postfix) id 3A8765D9D5; Thu, 26 Sep 2019 16:14:35 +0000 (UTC) Received: from moe.brq.redhat.com (unknown [10.43.2.30]) by smtp.corp.redhat.com (Postfix) with ESMTP id B82E85D9C3 for ; Thu, 26 Sep 2019 16:14:33 +0000 (UTC) From: Michal Privoznik To: libvir-list@redhat.com Date: Thu, 26 Sep 2019 18:12:23 +0200 Message-Id: <3c65d8a075578d0a86983def736fc745c4ab8727.1569514291.git.mprivozn@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v2 27/39] qemu: Take NVMe disks into account when calculating memlock limit 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-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.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.30]); Thu, 26 Sep 2019 16:20:57 +0000 (UTC) Content-Type: text/plain; charset="utf-8" We have this beautiful function that does crystal ball divination. The function is named qemuDomainGetMemLockLimitBytes() and it calculates the upper limit of how much locked memory is given guest going to need. The function bases its guess on devices defined for a domain. For instance, if there is a VFIO hostdev defined then it adds 1GiB to the guessed maximum. Since NVMe disks are pretty much VFIO hostdevs (but not quite), we have to do the same sorcery. Signed-off-by: Michal Privoznik ACKed-by: Peter Krempa --- src/qemu/qemu_domain.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c index f8fe430a7f..33929ce3a8 100644 --- a/src/qemu/qemu_domain.c +++ b/src/qemu/qemu_domain.c @@ -11888,6 +11888,9 @@ getPPC64MemLockLimitBytes(virDomainDefPtr def) } } =20 + if (virDomainDefHasNVMeDisk(def)) + usesVFIO =3D true; + memory =3D virDomainDefGetMemoryTotal(def); =20 if (def->mem.max_memory) @@ -11986,6 +11989,7 @@ unsigned long long qemuDomainGetMemLockLimitBytes(virDomainDefPtr def) { unsigned long long memKB =3D 0; + bool usesVFIO =3D false; size_t i; =20 /* prefer the hard limit */ @@ -12026,11 +12030,17 @@ qemuDomainGetMemLockLimitBytes(virDomainDefPtr de= f) for (i =3D 0; i < def->nhostdevs; i++) { if (virHostdevIsVFIODevice(def->hostdevs[i]) || virHostdevIsMdevDevice(def->hostdevs[i])) { - memKB =3D virDomainDefGetMemoryTotal(def) + 1024 * 1024; - goto done; + usesVFIO =3D true; + break; } } =20 + if (virDomainDefHasNVMeDisk(def)) + usesVFIO =3D true; + + if (usesVFIO) + memKB =3D virDomainDefGetMemoryTotal(def) + 1024 * 1024; + done: return memKB << 10; } --=20 2.21.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Sun May 19 20:29:53 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 ARC-Seal: i=1; a=rsa-sha256; t=1569514907; cv=none; d=zoho.com; s=zohoarc; b=EPovZ/Ue3kGaInr3Den2ozuge0ItkaDd6nbDcQsOZjLcTZforJCDE2U/+0iKjbDd/kJ2WB+m5nyI/VZQyP6RHyVz2RhYoeV7sBFVKvPWOUw05TsOhzt+vtpn4uBUpou9PA2jrgNfoxwdGU2w784lk3OD4AR2vGajrnU+uWNwm5M= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1569514907; h=Content-Type:Content-Transfer-Encoding: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:ARC-Authentication-Results; bh=Qk8A2h7G55iYyTYFQUJeIc24LQ8+4SKkupHASZR2I4k=; b=jywng5hJkwfoeQ3XkhzmAdJVrxbTT/LCv9VONZmoosbZGmw/y7cYebN0HZ5WrDAZeN08WFW3GfDVDVUjEdUQVNObLbs183Afb+oj1oal5GLT4MnXFM3M3EUvXl2WNTJr6mVAekDZCpu2xhxthY4ife0+1zR+rA+HFrNLkfUqZYM= ARC-Authentication-Results: i=1; mx.zoho.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 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 156951490784592.95378198481012; Thu, 26 Sep 2019 09:21:47 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 14E11C05AA58; Thu, 26 Sep 2019 16:21:46 +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 E47BB5D9C3; Thu, 26 Sep 2019 16:21:45 +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 A298E180B536; Thu, 26 Sep 2019 16:21:45 +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 x8QGEb79003731 for ; Thu, 26 Sep 2019 12:14:37 -0400 Received: by smtp.corp.redhat.com (Postfix) id 8E1785D9C3; Thu, 26 Sep 2019 16:14:37 +0000 (UTC) Received: from moe.brq.redhat.com (unknown [10.43.2.30]) by smtp.corp.redhat.com (Postfix) with ESMTP id 17B465D9D5 for ; Thu, 26 Sep 2019 16:14:35 +0000 (UTC) From: Michal Privoznik To: libvir-list@redhat.com Date: Thu, 26 Sep 2019 18:12:24 +0200 Message-Id: <460e7d7c276f292675b61a077badc1517e73bab2.1569514291.git.mprivozn@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v2 28/39] qemu: Create NVMe disk in domain namespace 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-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.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.32]); Thu, 26 Sep 2019 16:21:46 +0000 (UTC) Content-Type: text/plain; charset="utf-8" If a domain has an NVMe disk configured, then we need to create /dev/vfio/* paths in domain's namespace so that qemu can open them. Signed-off-by: Michal Privoznik --- src/qemu/qemu_domain.c | 69 +++++++++++++++++++++++++++++++----------- 1 file changed, 52 insertions(+), 17 deletions(-) diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c index 33929ce3a8..9409d8de8d 100644 --- a/src/qemu/qemu_domain.c +++ b/src/qemu/qemu_domain.c @@ -13423,16 +13423,29 @@ qemuDomainSetupDisk(virQEMUDriverConfigPtr cfg AT= TRIBUTE_UNUSED, { virStorageSourcePtr next; char *dst =3D NULL; + bool hasNVMe =3D false; int ret =3D -1; =20 for (next =3D disk->src; virStorageSourceIsBacking(next); next =3D nex= t->backingStore) { - if (!next->path || !virStorageSourceIsLocalStorage(next)) { - /* Not creating device. Just continue. */ - continue; + if (next->type =3D=3D VIR_STORAGE_TYPE_NVME) { + VIR_AUTOFREE(char *) nvmePath =3D NULL; + + hasNVMe =3D true; + + if (!(nvmePath =3D virPCIDeviceAddressGetIOMMUGroupDev(&next->= nvme->pciAddr))) + goto cleanup; + + if (qemuDomainCreateDevice(nvmePath, data, false) < 0) + goto cleanup; + } else { + if (!next->path || !virStorageSourceIsLocalStorage(next)) { + /* Not creating device. Just continue. */ + continue; + } + + if (qemuDomainCreateDevice(next->path, data, false) < 0) + goto cleanup; } - - if (qemuDomainCreateDevice(next->path, data, false) < 0) - goto cleanup; } =20 /* qemu-pr-helper might require access to /dev/mapper/control. */ @@ -13440,6 +13453,10 @@ qemuDomainSetupDisk(virQEMUDriverConfigPtr cfg ATT= RIBUTE_UNUSED, qemuDomainCreateDevice(QEMU_DEVICE_MAPPER_CONTROL_PATH, data, true= ) < 0) goto cleanup; =20 + if (hasNVMe && + qemuDomainCreateDevice(QEMU_DEV_VFIO, data, false) < 0) + goto cleanup; + ret =3D 0; cleanup: VIR_FREE(dst); @@ -14468,35 +14485,53 @@ qemuDomainNamespaceSetupDisk(virDomainObjPtr vm, virStorageSourcePtr src) { virStorageSourcePtr next; - const char **paths =3D NULL; + char **paths =3D NULL; size_t npaths =3D 0; - char *dmPath =3D NULL; + bool hasNVMe =3D false; + VIR_AUTOFREE(char *) dmPath =3D NULL; + VIR_AUTOFREE(char *) vfioPath =3D NULL; int ret =3D -1; =20 for (next =3D src; virStorageSourceIsBacking(next); next =3D next->bac= kingStore) { - if (virStorageSourceIsEmpty(next) || - !virStorageSourceIsLocalStorage(next)) { - /* Not creating device. Just continue. */ - continue; + VIR_AUTOFREE(char *) tmpPath =3D NULL; + + if (next->type =3D=3D VIR_STORAGE_TYPE_NVME) { + hasNVMe =3D true; + + if (!(tmpPath =3D virPCIDeviceAddressGetIOMMUGroupDev(&next->n= vme->pciAddr))) + goto cleanup; + } else { + if (virStorageSourceIsEmpty(next) || + !virStorageSourceIsLocalStorage(next)) { + /* Not creating device. Just continue. */ + continue; + } + + if (VIR_STRDUP(tmpPath, next->path) < 0) + goto cleanup; } =20 - if (VIR_APPEND_ELEMENT_COPY(paths, npaths, next->path) < 0) + if (VIR_APPEND_ELEMENT(paths, npaths, tmpPath) < 0) goto cleanup; } =20 /* qemu-pr-helper might require access to /dev/mapper/control. */ if (src->pr && (VIR_STRDUP(dmPath, QEMU_DEVICE_MAPPER_CONTROL_PATH) < 0 || - VIR_APPEND_ELEMENT_COPY(paths, npaths, dmPath) < 0)) + VIR_APPEND_ELEMENT(paths, npaths, dmPath) < 0)) goto cleanup; =20 - if (qemuDomainNamespaceMknodPaths(vm, paths, npaths) < 0) + if (hasNVMe && + (VIR_STRDUP(vfioPath, QEMU_DEV_VFIO) < 0 || + VIR_APPEND_ELEMENT(paths, npaths, vfioPath) < 0)) + goto cleanup; + + if (qemuDomainNamespaceMknodPaths(vm, (const char **) paths, npaths) <= 0) goto cleanup; =20 ret =3D 0; cleanup: - VIR_FREE(dmPath); - VIR_FREE(paths); + virStringListFreeCount(paths, npaths); return ret; } =20 --=20 2.21.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Sun May 19 20:29:53 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 ARC-Seal: i=1; a=rsa-sha256; t=1569514872; cv=none; d=zoho.com; s=zohoarc; b=Qn0zpFCIX2kincSTttqa6QZuySEE8L+hBrETZ2YUmDSiOeW/LqJwWGc9EvGyES/tk1rxgahFw9MUaTTh32XttZg47Z2qtTs6TMldx0GzSwewSJqq7Vh28Oe/n53lGtPSaSo8iIaqO8kUomyTnlFnybUY+KMMVuQb/TZCQJkWetA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1569514872; h=Content-Type:Content-Transfer-Encoding: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:ARC-Authentication-Results; bh=cXpEaN4pERRqn0Vf7C580RSn3TsE8MDfV+7OiL0cKQE=; b=aiwumNAdNJQQMJ1/eauWPx28IIgS6V7L0HNnLzEnL+u2E3z7w4F7kHK4wlaBBghfGAxKoTezdyhpa4W6LOW/jJaZI4h+cRK1xExuXiX7XPjv0Fnmlft+G0QA52GVzYyQyzPsKv3HqhMK4CTYtAsZ4W6vxfcQIeIOYJchUgbctXk= ARC-Authentication-Results: i=1; mx.zoho.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 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 1569514872900875.7664267541869; Thu, 26 Sep 2019 09:21:12 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 68E6599C43; Thu, 26 Sep 2019 16:21:11 +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 40E0C60923; Thu, 26 Sep 2019 16:21:11 +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 02AD3180BA9B; Thu, 26 Sep 2019 16:21:11 +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 x8QGEdL7003744 for ; Thu, 26 Sep 2019 12:14:39 -0400 Received: by smtp.corp.redhat.com (Postfix) id D699C5D9D5; Thu, 26 Sep 2019 16:14:39 +0000 (UTC) Received: from moe.brq.redhat.com (unknown [10.43.2.30]) by smtp.corp.redhat.com (Postfix) with ESMTP id 60A075D9E1 for ; Thu, 26 Sep 2019 16:14:37 +0000 (UTC) From: Michal Privoznik To: libvir-list@redhat.com Date: Thu, 26 Sep 2019 18:12:25 +0200 Message-Id: <3fa8a014c592ca969317e7123aba1f3a5b102159.1569514291.git.mprivozn@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v2 29/39] qemu: Mark NVMe disks as 'need VFIO' 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-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.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.38]); Thu, 26 Sep 2019 16:21:11 +0000 (UTC) Content-Type: text/plain; charset="utf-8" There are couple of places where a domain with a VFIO device gets special treatment: in CGroups when enabling/disabling access to /dev/vfio/vfio, and when creating/removing nodes in domain mount namespace. Well, a NVMe disk is a VFIO device too. Fortunately, we have this qemuDomainNeedsVFIO() function which is the only place that needs adjustment. Signed-off-by: Michal Privoznik --- src/qemu/qemu_domain.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c index 9409d8de8d..e4e9d4e361 100644 --- a/src/qemu/qemu_domain.c +++ b/src/qemu/qemu_domain.c @@ -12840,7 +12840,8 @@ bool qemuDomainNeedsVFIO(const virDomainDef *def) { return virDomainDefHasVFIOHostdev(def) || - virDomainDefHasMdevHostdev(def); + virDomainDefHasMdevHostdev(def) || + virDomainDefHasNVMeDisk(def); } =20 =20 --=20 2.21.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Sun May 19 20:29:53 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 ARC-Seal: i=1; a=rsa-sha256; t=1569514894; cv=none; d=zoho.com; s=zohoarc; b=KgV64Ge2LcCc8AocR4XjqCBvX7e3kFfZq2ntyzN7uh0jnZ5GnBg3Hl1jrSGZi84trGcHe+TuZ/GFhiHMGGOq6KUDsRrgfmvngqa5Y2IefKDyoc0eZpRAOQ2MdLyAbirMwCkhelshozR86Zgf1gBtLZs6SxJuXIT/FkRQS20GWIA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1569514894; h=Content-Type:Content-Transfer-Encoding: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:ARC-Authentication-Results; bh=6YWPDjZbg51QWM0a1m7osD/b9hFGUvviciUdCdcfa0A=; b=Wh+gn/qlvr3iB83ui2Mepv4owOQPxE+BKpwbrgWFfgAU+FlDu7VCz0wOZva2/ohd6wd2wCb4pXbhzk4Jcpj8xcynOOE+jLfIpIh821hsr6sPiZv5Vx22u0n4lE/r12UVUrczX9DAmL+vJJ/xLIAjhuol741O8EKch+UelePsWBs= ARC-Authentication-Results: i=1; mx.zoho.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 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 156951489403040.21004498943546; Thu, 26 Sep 2019 09:21:34 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 488A03175296; Thu, 26 Sep 2019 16:21: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 215885D9C3; Thu, 26 Sep 2019 16:21:32 +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 CDFAE1803517; Thu, 26 Sep 2019 16:21:31 +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 x8QGEiIE003791 for ; Thu, 26 Sep 2019 12:14:44 -0400 Received: by smtp.corp.redhat.com (Postfix) id BCEB05D9C3; Thu, 26 Sep 2019 16:14:44 +0000 (UTC) Received: from moe.brq.redhat.com (unknown [10.43.2.30]) by smtp.corp.redhat.com (Postfix) with ESMTP id 46B105D9D5 for ; Thu, 26 Sep 2019 16:14:40 +0000 (UTC) From: Michal Privoznik To: libvir-list@redhat.com Date: Thu, 26 Sep 2019 18:12:26 +0200 Message-Id: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v2 30/39] qemu: Allow NVMe disk in CGroups 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-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.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.49]); Thu, 26 Sep 2019 16:21:33 +0000 (UTC) Content-Type: text/plain; charset="utf-8" If a domain has an NVMe disk configured, then we need to allow it on devices CGroup so that qemu can access it. There is one caveat though - if an NVMe disk is read only we need CGroup to allow write too. This is because when opening the device, qemu does couple of ioctl()-s which are considered as write. Signed-off-by: Michal Privoznik --- src/qemu/qemu_cgroup.c | 101 +++++++++++++++++++++++++++++------------ 1 file changed, 72 insertions(+), 29 deletions(-) diff --git a/src/qemu/qemu_cgroup.c b/src/qemu/qemu_cgroup.c index 9684bf3662..b9fb0ebca2 100644 --- a/src/qemu/qemu_cgroup.c +++ b/src/qemu/qemu_cgroup.c @@ -119,10 +119,30 @@ qemuSetupImageCgroupInternal(virDomainObjPtr vm, virStorageSourcePtr src, bool forceReadonly) { - if (!src->path || !virStorageSourceIsLocalStorage(src)) { - VIR_DEBUG("Not updating cgroups for disk path '%s', type: %s", - NULLSTR(src->path), virStorageTypeToString(src->type)); - return 0; + VIR_AUTOFREE(char *) path =3D NULL; + bool readonly =3D src->readonly || forceReadonly; + + if (src->type =3D=3D VIR_STORAGE_TYPE_NVME) { + /* Even though disk is R/O we can't make it so in + * CGroups. QEMU will try to do some ioctl()-s over the + * device and such operations are considered R/W by the + * kernel */ + readonly =3D false; + + if (!(path =3D virPCIDeviceAddressGetIOMMUGroupDev(&src->nvme->pci= Addr))) + return -1; + + if (qemuSetupImagePathCgroup(vm, QEMU_DEV_VFIO, false) < 0) + return -1; + } else { + if (!src->path || !virStorageSourceIsLocalStorage(src)) { + VIR_DEBUG("Not updating cgroups for disk path '%s', type: %s", + NULLSTR(src->path), virStorageTypeToString(src->type= )); + return 0; + } + + if (VIR_STRDUP(path, src->path) < 0) + return -1; } =20 if (virStoragePRDefIsManaged(src->pr) && @@ -130,7 +150,7 @@ qemuSetupImageCgroupInternal(virDomainObjPtr vm, qemuSetupImagePathCgroup(vm, QEMU_DEVICE_MAPPER_CONTROL_PATH, fals= e) < 0) return -1; =20 - return qemuSetupImagePathCgroup(vm, src->path, src->readonly || forceR= eadonly); + return qemuSetupImagePathCgroup(vm, path, readonly); } =20 =20 @@ -147,7 +167,10 @@ qemuTeardownImageCgroup(virDomainObjPtr vm, virStorageSourcePtr src) { qemuDomainObjPrivatePtr priv =3D vm->privateData; + VIR_AUTOFREE(char *path) =3D NULL; int perms =3D VIR_CGROUP_DEVICE_RWM; + bool hasPR =3D false; + bool hasNVMe =3D false; size_t i; int ret; =20 @@ -155,41 +178,61 @@ qemuTeardownImageCgroup(virDomainObjPtr vm, VIR_CGROUP_CONTROLLER_DEVICES)) return 0; =20 - if (!src->path || !virStorageSourceIsLocalStorage(src)) { - VIR_DEBUG("Not updating cgroups for disk path '%s', type: %s", - NULLSTR(src->path), virStorageTypeToString(src->type)); - return 0; + for (i =3D 0; i < vm->def->ndisks; i++) { + virStorageSourcePtr diskSrc =3D vm->def->disks[i]->src; + + if (src =3D=3D diskSrc) + continue; + + if (virStoragePRDefIsManaged(diskSrc->pr)) + hasPR =3D true; + + if (virStorageSourceChainHasNVMe(diskSrc)) + hasNVMe =3D true; } =20 - if (virFileExists(QEMU_DEVICE_MAPPER_CONTROL_PATH)) { - for (i =3D 0; i < vm->def->ndisks; i++) { - virStorageSourcePtr diskSrc =3D vm->def->disks[i]->src; + if (src->type =3D=3D VIR_STORAGE_TYPE_NVME) { + if (!(path =3D virPCIDeviceAddressGetIOMMUGroupDev(&src->nvme->pci= Addr))) + return -1; =20 - if (src =3D=3D diskSrc) - continue; - - if (virStoragePRDefIsManaged(diskSrc->pr)) - break; - } - - if (i =3D=3D vm->def->ndisks) { - VIR_DEBUG("Disabling device mapper control"); - ret =3D virCgroupDenyDevicePath(priv->cgroup, - QEMU_DEVICE_MAPPER_CONTROL_PATH, - perms, true); + if (!hasNVMe && + !qemuDomainNeedsVFIO(vm->def)) { + ret =3D virCgroupDenyDevicePath(priv->cgroup, QEMU_DEV_VFIO, p= erms, true); virDomainAuditCgroupPath(vm, priv->cgroup, "deny", - QEMU_DEVICE_MAPPER_CONTROL_PATH, + QEMU_DEV_VFIO, virCgroupGetDevicePermsString(perms),= ret); if (ret < 0) - return ret; + return -1; } + } else { + if (!src->path || !virStorageSourceIsLocalStorage(src)) { + VIR_DEBUG("Not updating cgroups for disk path '%s', type: %s", + NULLSTR(src->path), virStorageTypeToString(src->type= )); + return 0; + } + + if (VIR_STRDUP(path, src->path) < 0) + return -1; + } + + if (!hasPR && + virFileExists(QEMU_DEVICE_MAPPER_CONTROL_PATH)) { + VIR_DEBUG("Disabling device mapper control"); + ret =3D virCgroupDenyDevicePath(priv->cgroup, + QEMU_DEVICE_MAPPER_CONTROL_PATH, + perms, true); + virDomainAuditCgroupPath(vm, priv->cgroup, "deny", + QEMU_DEVICE_MAPPER_CONTROL_PATH, + virCgroupGetDevicePermsString(perms), ret= ); + if (ret < 0) + return ret; } =20 - VIR_DEBUG("Deny path %s", src->path); + VIR_DEBUG("Deny path %s", path); =20 - ret =3D virCgroupDenyDevicePath(priv->cgroup, src->path, perms, true); + ret =3D virCgroupDenyDevicePath(priv->cgroup, path, perms, true); =20 - virDomainAuditCgroupPath(vm, priv->cgroup, "deny", src->path, + virDomainAuditCgroupPath(vm, priv->cgroup, "deny", path, virCgroupGetDevicePermsString(perms), ret); =20 /* If you're looking for a counter part to --=20 2.21.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Sun May 19 20:29:53 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 ARC-Seal: i=1; a=rsa-sha256; t=1569514939; cv=none; d=zoho.com; s=zohoarc; b=e21xPYxfpt3x8BhE1NaU0HXWaChYcZuOkpn3jCi/oNOvG/LlLZhgV3R7zd4KkGKEcc8/Z4GshWI0mPza4EB5LZoTCYSM45Q/kevPH/BgsBGlb/VflJABKxcZm1pp7ehO/4GtzLF4aa2WhDeqhj1KBQM6nG4U3YE2mTspJeSMF4g= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1569514939; h=Content-Type:Content-Transfer-Encoding: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:ARC-Authentication-Results; bh=W4T8I2CKInGiOXZfXLg0a+zB0svj+9/CuiEbT5z9Uaw=; b=C1xXeBvpb1U2+pu25HGfog5W8rBFkhbFDSwW6yW+4k+rKv+csaiGBmke1XTCvOS+9jX5pfeENYD8OjM6eotgz2yUEj/Cg6fszWjksaHbeXVsWkhKTUUZBICl3N0Z+uBdJZL6oPoFF7az8nNQUu80R0ghS5liZI3Kc7Vtxlb1rfQ= ARC-Authentication-Results: i=1; mx.zoho.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 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 1569514939240336.0510951917679; Thu, 26 Sep 2019 09:22:19 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id B465411A2A; Thu, 26 Sep 2019 16:22:17 +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 8C77460605; Thu, 26 Sep 2019 16:22:17 +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 47111180BA9B; Thu, 26 Sep 2019 16:22:17 +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 x8QGElHO003836 for ; Thu, 26 Sep 2019 12:14:47 -0400 Received: by smtp.corp.redhat.com (Postfix) id D19D15D9CD; Thu, 26 Sep 2019 16:14:47 +0000 (UTC) Received: from moe.brq.redhat.com (unknown [10.43.2.30]) by smtp.corp.redhat.com (Postfix) with ESMTP id 5C87A5D9E1 for ; Thu, 26 Sep 2019 16:14:44 +0000 (UTC) From: Michal Privoznik To: libvir-list@redhat.com Date: Thu, 26 Sep 2019 18:12:27 +0200 Message-Id: <4f71d26b400cc9910910012e11cde8c2a65ac9b6.1569514291.git.mprivozn@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v2 31/39] security_selinux: Simplify virSecuritySELinuxSetImageLabelInternal 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-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.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.28]); Thu, 26 Sep 2019 16:22:18 +0000 (UTC) Content-Type: text/plain; charset="utf-8" This function calls virSecuritySELinuxSetFilecon() or virSecuritySELinuxSetFileconOptional() from a lot of places. It works, because in all places we're passing src->path which is what we wanted. But not anymore. We will want to be able to pass a different path and thus the function must be reworked a bit. Signed-off-by: Michal Privoznik ACKed-by: Peter Krempa --- src/security/security_selinux.c | 34 ++++++++++++--------------------- 1 file changed, 12 insertions(+), 22 deletions(-) diff --git a/src/security/security_selinux.c b/src/security/security_selinu= x.c index e879fa39ab..3a00666d26 100644 --- a/src/security/security_selinux.c +++ b/src/security/security_selinux.c @@ -1823,7 +1823,9 @@ virSecuritySELinuxSetImageLabelInternal(virSecurityMa= nagerPtr mgr, virSecurityDeviceLabelDefPtr disk_seclabel; virSecurityDeviceLabelDefPtr parent_seclabel =3D NULL; bool remember; - int ret; + const char *path =3D src->path; + const char *tcon =3D NULL; + int ret =3D -1; =20 if (!src->path || !virStorageSourceIsLocalStorage(src)) return 0; @@ -1856,40 +1858,28 @@ virSecuritySELinuxSetImageLabelInternal(virSecurity= ManagerPtr mgr, if (!disk_seclabel->relabel) return 0; =20 - ret =3D virSecuritySELinuxSetFilecon(mgr, src->path, - disk_seclabel->label, remember); + tcon =3D disk_seclabel->label; } else if (parent_seclabel && (!parent_seclabel->relabel || parent_sec= label->label)) { if (!parent_seclabel->relabel) return 0; =20 - ret =3D virSecuritySELinuxSetFilecon(mgr, src->path, - parent_seclabel->label, remembe= r); + tcon =3D parent_seclabel->label; } else if (!parent || parent =3D=3D src) { if (src->shared) { - ret =3D virSecuritySELinuxSetFilecon(mgr, - src->path, - data->file_context, - remember); + tcon =3D data->file_context; } else if (src->readonly) { - ret =3D virSecuritySELinuxSetFilecon(mgr, - src->path, - data->content_context, - remember); + tcon =3D data->content_context; } else if (secdef->imagelabel) { - ret =3D virSecuritySELinuxSetFilecon(mgr, - src->path, - secdef->imagelabel, - remember); + tcon =3D secdef->imagelabel; } else { - ret =3D 0; + return 0; } } else { - ret =3D virSecuritySELinuxSetFilecon(mgr, - src->path, - data->content_context, - remember); + tcon =3D data->content_context; } =20 + ret =3D virSecuritySELinuxSetFilecon(mgr, path, tcon, remember); + if (ret =3D=3D 1 && !disk_seclabel) { /* If we failed to set a label, but virt_use_nfs let us * proceed anyway, then we don't need to relabel later. */ --=20 2.21.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Sun May 19 20:29:53 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 ARC-Seal: i=1; a=rsa-sha256; t=1569514906; cv=none; d=zoho.com; s=zohoarc; b=OTN3lXUtxfcyqkm2E1CdNGleABFOcAodYntUNcFdeEaw/mGtcHglYc6YCRw448bbqO6x6YsM5KsTu2EwMJBMONvVL9VpfCK9Ms4d4UZsZgQ4uplKkGrZf50lkws1cxktTdgurPPmGgNo3vD71LpC2ljpm/Qu7f0QImXduCdHoFI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1569514906; h=Content-Type:Content-Transfer-Encoding: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:ARC-Authentication-Results; bh=QmXnrxzuHxGpAnZUVaXy643F/z+H6uCQMH2LWbwmzXE=; b=Uy0Kg/8CGwVYlNzi9e2PX0K6pt6qXtGQbckzyAm7shaImJPq6miGn3LGb7QxAcIINyEf5Yp/r5mi7KhdqyHJJT4krfUkuErSPXXFZr3pfyHXxFYPEfLxIDcTpMD+ylieI6C/FA5JTu28ST/uquKs7W/lVjAUSVck1FaAG6A51tI= ARC-Authentication-Results: i=1; mx.zoho.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 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 1569514906786623.7674252650249; Thu, 26 Sep 2019 09:21:46 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 19B1E2CD7E5; Thu, 26 Sep 2019 16:21:45 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id E60D360C4E; Thu, 26 Sep 2019 16:21:44 +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 9EA854EE6D; Thu, 26 Sep 2019 16:21:44 +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 x8QGEofh003862 for ; Thu, 26 Sep 2019 12:14:50 -0400 Received: by smtp.corp.redhat.com (Postfix) id DAD4D5D9CD; Thu, 26 Sep 2019 16:14:50 +0000 (UTC) Received: from moe.brq.redhat.com (unknown [10.43.2.30]) by smtp.corp.redhat.com (Postfix) with ESMTP id 641AC5D9DC for ; Thu, 26 Sep 2019 16:14:48 +0000 (UTC) From: Michal Privoznik To: libvir-list@redhat.com Date: Thu, 26 Sep 2019 18:12:28 +0200 Message-Id: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v2 32/39] virSecuritySELinuxRestoreImageLabelInt: Don't skip non-local storage 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-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.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.29]); Thu, 26 Sep 2019 16:21:45 +0000 (UTC) Content-Type: text/plain; charset="utf-8" This function is currently not called for any type of storage source that is not considered 'local' (as defined by virStorageSourceIsLocalStorage()). Well, NVMe disks are not 'local' from that point of view and therefore we will need to call this function more frequently. Signed-off-by: Michal Privoznik --- src/security/security_apparmor.c | 33 +++++++++++++++------- src/security/security_dac.c | 30 ++++++++++++++++++++ src/security/security_selinux.c | 48 +++++++++++++++++++++++++++----- 3 files changed, 94 insertions(+), 17 deletions(-) diff --git a/src/security/security_apparmor.c b/src/security/security_appar= mor.c index 77eee9410c..580cd72223 100644 --- a/src/security/security_apparmor.c +++ b/src/security/security_apparmor.c @@ -803,22 +803,35 @@ AppArmorSetSecurityImageLabel(virSecurityManagerPtr m= gr, { int rc =3D -1; char *profile_name =3D NULL; + VIR_AUTOFREE(char *) vfioGroupDev =3D NULL; + const char *path =3D NULL; virSecurityLabelDefPtr secdef; =20 - if (!src->path || !virStorageSourceIsLocalStorage(src)) - return 0; - secdef =3D virDomainDefGetSecurityLabelDef(def, SECURITY_APPARMOR_NAME= ); if (!secdef || !secdef->relabel) return 0; =20 if (secdef->imagelabel) { - /* if the device doesn't exist, error out */ - if (!virFileExists(src->path)) { - virReportError(VIR_ERR_INTERNAL_ERROR, - _("\'%s\' does not exist"), - src->path); - return -1; + if (src->type =3D=3D VIR_STORAGE_TYPE_NVME) { + const virStorageSourceNVMeDef *nvme =3D src->nvme; + + if (!(vfioGroupDev =3D virPCIDeviceAddressGetIOMMUGroupDev(&nv= me->pciAddr))) + return -1; + + path =3D vfioGroupDev; + } else { + if (!src->path || !virStorageSourceIsLocalStorage(src)) + return 0; + + /* if the device doesn't exist, error out */ + if (!virFileExists(src->path)) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("\'%s\' does not exist"), + src->path); + return -1; + } + + path =3D src->path; } =20 if ((profile_name =3D get_profile_name(def)) =3D=3D NULL) @@ -827,7 +840,7 @@ AppArmorSetSecurityImageLabel(virSecurityManagerPtr mgr, /* update the profile only if it is loaded */ if (profile_loaded(secdef->imagelabel) >=3D 0) { if (load_profile(mgr, secdef->imagelabel, def, - src->path, false) < 0) { + path, false) < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, _("cannot update AppArmor profile " "\'%s\'"), diff --git a/src/security/security_dac.c b/src/security/security_dac.c index 4b4afef18a..42d585500d 100644 --- a/src/security/security_dac.c +++ b/src/security/security_dac.c @@ -915,6 +915,19 @@ virSecurityDACSetImageLabelInternal(virSecurityManager= Ptr mgr, return -1; } =20 + /* This is not very clean. But so far we don't have NVMe + * storage pool backend so that its chownCallback would be + * called. And this place looks least offensive. */ + if (src->type =3D=3D VIR_STORAGE_TYPE_NVME) { + const virStorageSourceNVMeDef *nvme =3D src->nvme; + VIR_AUTOFREE(char *) vfioGroupDev =3D NULL; + + if (!(vfioGroupDev =3D virPCIDeviceAddressGetIOMMUGroupDev(&nvme->= pciAddr))) + return -1; + + return virSecurityDACSetOwnership(mgr, NULL, vfioGroupDev, user, g= roup, false); + } + /* We can't do restore on shared resources safely. Not even * with refcounting implemented in XATTRs because if there * was a domain running with the feature turned off the @@ -1004,6 +1017,23 @@ virSecurityDACRestoreImageLabelInt(virSecurityManage= rPtr mgr, } } =20 + /* This is not very clean. But so far we don't have NVMe + * storage pool backend so that its chownCallback would be + * called. And this place looks least offensive. */ + if (src->type =3D=3D VIR_STORAGE_TYPE_NVME) { + const virStorageSourceNVMeDef *nvme =3D src->nvme; + VIR_AUTOFREE(char *) vfioGroupDev =3D NULL; + + if (!(vfioGroupDev =3D virPCIDeviceAddressGetIOMMUGroupDev(&nvme->= pciAddr))) + return -1; + + /* Ideally, we would check if there is not another PCI + * device within domain def that is in the same IOMMU + * group. But we're not doing that for hostdevs yet. */ + + return virSecurityDACRestoreFileLabelInternal(mgr, NULL, vfioGroup= Dev, false); + } + return virSecurityDACRestoreFileLabelInternal(mgr, src, NULL, true); } =20 diff --git a/src/security/security_selinux.c b/src/security/security_selinu= x.c index 3a00666d26..f439ecec46 100644 --- a/src/security/security_selinux.c +++ b/src/security/security_selinux.c @@ -1754,9 +1754,8 @@ virSecuritySELinuxRestoreImageLabelInt(virSecurityMan= agerPtr mgr, { virSecurityLabelDefPtr seclabel; virSecurityDeviceLabelDefPtr disk_seclabel; - - if (!src->path || !virStorageSourceIsLocalStorage(src)) - return 0; + VIR_AUTOFREE(char *) vfioGroupDev =3D NULL; + const char *path =3D src->path; =20 seclabel =3D virDomainDefGetSecurityLabelDef(def, SECURITY_SELINUX_NAM= E); if (seclabel =3D=3D NULL) @@ -1788,9 +1787,16 @@ virSecuritySELinuxRestoreImageLabelInt(virSecurityMa= nagerPtr mgr, * ownership, because that kills access on the destination host which = is * sub-optimal for the guest VM's I/O attempts :-) */ if (migrated) { - int rc =3D virFileIsSharedFS(src->path); - if (rc < 0) - return -1; + int rc =3D 1; + + if (virStorageSourceIsLocalStorage(src)) { + if (!src->path) + return 0; + + if ((rc =3D virFileIsSharedFS(src->path)) < 0) + return -1; + } + if (rc =3D=3D 1) { VIR_DEBUG("Skipping image label restore on %s because FS is sh= ared", src->path); @@ -1798,7 +1804,22 @@ virSecuritySELinuxRestoreImageLabelInt(virSecurityMa= nagerPtr mgr, } } =20 - return virSecuritySELinuxRestoreFileLabel(mgr, src->path, true); + /* This is not very clean. But so far we don't have NVMe + * storage pool backend so that its chownCallback would be + * called. And this place looks least offensive. */ + if (src->type =3D=3D VIR_STORAGE_TYPE_NVME) { + const virStorageSourceNVMeDef *nvme =3D src->nvme; + + if (!(vfioGroupDev =3D virPCIDeviceAddressGetIOMMUGroupDev(&nvme->= pciAddr))) + return -1; + + /* Ideally, we would check if there is not another PCI + * device within domain def that is in the same IOMMU + * group. But we're not doing that for hostdevs yet. */ + path =3D vfioGroupDev; + } + + return virSecuritySELinuxRestoreFileLabel(mgr, path, true); } =20 =20 @@ -1823,6 +1844,7 @@ virSecuritySELinuxSetImageLabelInternal(virSecurityMa= nagerPtr mgr, virSecurityDeviceLabelDefPtr disk_seclabel; virSecurityDeviceLabelDefPtr parent_seclabel =3D NULL; bool remember; + VIR_AUTOFREE(char *) vfioGroupDev =3D NULL; const char *path =3D src->path; const char *tcon =3D NULL; int ret =3D -1; @@ -1878,6 +1900,18 @@ virSecuritySELinuxSetImageLabelInternal(virSecurityM= anagerPtr mgr, tcon =3D data->content_context; } =20 + /* This is not very clean. But so far we don't have NVMe + * storage pool backend so that its chownCallback would be + * called. And this place looks least offensive. */ + if (src->type =3D=3D VIR_STORAGE_TYPE_NVME) { + const virStorageSourceNVMeDef *nvme =3D src->nvme; + + if (!(vfioGroupDev =3D virPCIDeviceAddressGetIOMMUGroupDev(&nvme->= pciAddr))) + return -1; + + path =3D vfioGroupDev; + } + ret =3D virSecuritySELinuxSetFilecon(mgr, path, tcon, remember); =20 if (ret =3D=3D 1 && !disk_seclabel) { --=20 2.21.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Sun May 19 20:29:53 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 ARC-Seal: i=1; a=rsa-sha256; t=1569514951; cv=none; d=zoho.com; s=zohoarc; b=FRUTCLfbzh2BJB5qfakp8sHtrv0XH3e+OY4Q08iQqKNraeU/EBc3p1Fo7K9UGbcmOfII6uPIJ1Xbv3XzKtPtjtlNoXERzoh/j2O74mDWsXG+K/HXnh6F6cu0/JxsYZWc54QkO9Zxd8iPzG444IN7VIG1hQ9ibNphI4VsifSNVno= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1569514951; h=Content-Type:Content-Transfer-Encoding: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:ARC-Authentication-Results; bh=neAyOmW/aC3Ht4P7AobWN5CPz3L3m2SW9WljqQarEMQ=; b=BYzlgFWJHqx151Gdw6sMiqH0gdxUPAzQRiHC6jcpl4nr/Lhno4NhEbkwlbKjDnaMIDZkOM82tM31EJCHqCdcH0qVwKi/PhkyTzehS04sV9OrT/zF9MnFwQdOGGwWQtFUF5UEAr6HsKAYRblwqiztSuHdDejC76y+otzBRVMRrWw= ARC-Authentication-Results: i=1; mx.zoho.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 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 1569514951978868.9030285853802; Thu, 26 Sep 2019 09:22:31 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 1B6B6307C828; Thu, 26 Sep 2019 16:22:30 +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 A606C5F9CD; Thu, 26 Sep 2019 16:22:29 +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 687BA18037CA; Thu, 26 Sep 2019 16:22:29 +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 x8QGEpR9003870 for ; Thu, 26 Sep 2019 12:14:51 -0400 Received: by smtp.corp.redhat.com (Postfix) id AC1E45D9C3; Thu, 26 Sep 2019 16:14:51 +0000 (UTC) Received: from moe.brq.redhat.com (unknown [10.43.2.30]) by smtp.corp.redhat.com (Postfix) with ESMTP id 337025D9CD for ; Thu, 26 Sep 2019 16:14:51 +0000 (UTC) From: Michal Privoznik To: libvir-list@redhat.com Date: Thu, 26 Sep 2019 18:12:29 +0200 Message-Id: <59e3230b5d2dba73cdd76b034aef5644c035e34e.1569514291.git.mprivozn@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v2 33/39] qemu_capabilities: Introduce QEMU_CAPS_DRIVE_NVME 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-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.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.40]); Thu, 26 Sep 2019 16:22:30 +0000 (UTC) Content-Type: text/plain; charset="utf-8" This capability tracks if qemu is capable of: -drive file.driver=3Dnvme The feature was added in QEMU's commit of v2.12.0-rc0~104^2~2. Signed-off-by: Michal Privoznik --- src/qemu/qemu_capabilities.c | 4 ++++ src/qemu/qemu_capabilities.h | 3 +++ tests/qemucapabilitiesdata/caps_2.12.0.aarch64.xml | 1 + tests/qemucapabilitiesdata/caps_2.12.0.ppc64.xml | 1 + tests/qemucapabilitiesdata/caps_2.12.0.s390x.xml | 1 + tests/qemucapabilitiesdata/caps_2.12.0.x86_64.xml | 1 + tests/qemucapabilitiesdata/caps_3.0.0.ppc64.xml | 1 + tests/qemucapabilitiesdata/caps_3.0.0.riscv32.xml | 1 + tests/qemucapabilitiesdata/caps_3.0.0.riscv64.xml | 1 + tests/qemucapabilitiesdata/caps_3.0.0.s390x.xml | 1 + tests/qemucapabilitiesdata/caps_3.0.0.x86_64.xml | 1 + tests/qemucapabilitiesdata/caps_3.1.0.ppc64.xml | 1 + tests/qemucapabilitiesdata/caps_3.1.0.x86_64.xml | 1 + tests/qemucapabilitiesdata/caps_4.0.0.aarch64.xml | 1 + tests/qemucapabilitiesdata/caps_4.0.0.ppc64.xml | 1 + tests/qemucapabilitiesdata/caps_4.0.0.riscv32.xml | 1 + tests/qemucapabilitiesdata/caps_4.0.0.riscv64.xml | 1 + tests/qemucapabilitiesdata/caps_4.0.0.s390x.xml | 1 + tests/qemucapabilitiesdata/caps_4.0.0.x86_64.xml | 1 + tests/qemucapabilitiesdata/caps_4.1.0.x86_64.xml | 1 + 20 files changed, 25 insertions(+) diff --git a/src/qemu/qemu_capabilities.c b/src/qemu/qemu_capabilities.c index 72e070e8ab..17ee5e48c8 100644 --- a/src/qemu/qemu_capabilities.c +++ b/src/qemu/qemu_capabilities.c @@ -540,6 +540,9 @@ VIR_ENUM_IMPL(virQEMUCaps, "dbus-vmstate", "vhost-user-gpu", "vhost-user-vga", + + /* 340 */ + "drive-nvme", ); =20 =20 @@ -1287,6 +1290,7 @@ static struct virQEMUCapsStringFlags virQEMUCapsQMPSc= hemaQueries[] =3D { { "query-display-options/ret-type/+egl-headless/rendernode", QEMU_CAPS= _EGL_HEADLESS_RENDERNODE }, { "nbd-server-add/arg-type/bitmap", QEMU_CAPS_NBD_BITMAP }, { "blockdev-add/arg-type/+file/drop-cache", QEMU_CAPS_MIGRATION_FILE_D= ROP_CACHE }, + { "blockdev-add/arg-type/+nvme", QEMU_CAPS_DRIVE_NVME }, }; =20 typedef struct _virQEMUCapsObjectTypeProps virQEMUCapsObjectTypeProps; diff --git a/src/qemu/qemu_capabilities.h b/src/qemu/qemu_capabilities.h index 137b7161a5..5b6e7174d1 100644 --- a/src/qemu/qemu_capabilities.h +++ b/src/qemu/qemu_capabilities.h @@ -522,6 +522,9 @@ typedef enum { /* virQEMUCapsFlags grouping marker for = syntax-check */ QEMU_CAPS_DEVICE_VHOST_USER_GPU, /* -device vhost-user-gpu */ QEMU_CAPS_DEVICE_VHOST_USER_VGA, /* -device vhost-user-vga */ =20 + /* 340 */ + QEMU_CAPS_DRIVE_NVME, /* -drive file.driver=3Dnvme */ + QEMU_CAPS_LAST /* this must always be the last item */ } virQEMUCapsFlags; =20 diff --git a/tests/qemucapabilitiesdata/caps_2.12.0.aarch64.xml b/tests/qem= ucapabilitiesdata/caps_2.12.0.aarch64.xml index 614fd14fb1..ec6479de2a 100644 --- a/tests/qemucapabilitiesdata/caps_2.12.0.aarch64.xml +++ b/tests/qemucapabilitiesdata/caps_2.12.0.aarch64.xml @@ -153,6 +153,7 @@ + 2012000 0 61700807 diff --git a/tests/qemucapabilitiesdata/caps_2.12.0.ppc64.xml b/tests/qemuc= apabilitiesdata/caps_2.12.0.ppc64.xml index fd9ae0bcb8..d4ed7cea49 100644 --- a/tests/qemucapabilitiesdata/caps_2.12.0.ppc64.xml +++ b/tests/qemucapabilitiesdata/caps_2.12.0.ppc64.xml @@ -151,6 +151,7 @@ + 2011090 0 42900807 diff --git a/tests/qemucapabilitiesdata/caps_2.12.0.s390x.xml b/tests/qemuc= apabilitiesdata/caps_2.12.0.s390x.xml index 2930381068..91aee9f838 100644 --- a/tests/qemucapabilitiesdata/caps_2.12.0.s390x.xml +++ b/tests/qemucapabilitiesdata/caps_2.12.0.s390x.xml @@ -121,6 +121,7 @@ + 2012000 0 39100807 diff --git a/tests/qemucapabilitiesdata/caps_2.12.0.x86_64.xml b/tests/qemu= capabilitiesdata/caps_2.12.0.x86_64.xml index 61b3602c48..96fa7c43c9 100644 --- a/tests/qemucapabilitiesdata/caps_2.12.0.x86_64.xml +++ b/tests/qemucapabilitiesdata/caps_2.12.0.x86_64.xml @@ -195,6 +195,7 @@ + 2011090 0 43100807 diff --git a/tests/qemucapabilitiesdata/caps_3.0.0.ppc64.xml b/tests/qemuca= pabilitiesdata/caps_3.0.0.ppc64.xml index 61be1df782..7b7d101ee9 100644 --- a/tests/qemucapabilitiesdata/caps_3.0.0.ppc64.xml +++ b/tests/qemucapabilitiesdata/caps_3.0.0.ppc64.xml @@ -152,6 +152,7 @@ + 2012050 0 42900757 diff --git a/tests/qemucapabilitiesdata/caps_3.0.0.riscv32.xml b/tests/qemu= capabilitiesdata/caps_3.0.0.riscv32.xml index 865becc179..d50789711a 100644 --- a/tests/qemucapabilitiesdata/caps_3.0.0.riscv32.xml +++ b/tests/qemucapabilitiesdata/caps_3.0.0.riscv32.xml @@ -92,6 +92,7 @@ + 3000000 0 0 diff --git a/tests/qemucapabilitiesdata/caps_3.0.0.riscv64.xml b/tests/qemu= capabilitiesdata/caps_3.0.0.riscv64.xml index eb54aeaff3..06a2e98b90 100644 --- a/tests/qemucapabilitiesdata/caps_3.0.0.riscv64.xml +++ b/tests/qemucapabilitiesdata/caps_3.0.0.riscv64.xml @@ -92,6 +92,7 @@ + 3000000 0 0 diff --git a/tests/qemucapabilitiesdata/caps_3.0.0.s390x.xml b/tests/qemuca= pabilitiesdata/caps_3.0.0.s390x.xml index d511377262..a8fb99c9fd 100644 --- a/tests/qemucapabilitiesdata/caps_3.0.0.s390x.xml +++ b/tests/qemucapabilitiesdata/caps_3.0.0.s390x.xml @@ -123,6 +123,7 @@ + 3000000 0 39100757 diff --git a/tests/qemucapabilitiesdata/caps_3.0.0.x86_64.xml b/tests/qemuc= apabilitiesdata/caps_3.0.0.x86_64.xml index 7a322030bd..6f926f2eaa 100644 --- a/tests/qemucapabilitiesdata/caps_3.0.0.x86_64.xml +++ b/tests/qemucapabilitiesdata/caps_3.0.0.x86_64.xml @@ -199,6 +199,7 @@ + 3000000 0 43100757 diff --git a/tests/qemucapabilitiesdata/caps_3.1.0.ppc64.xml b/tests/qemuca= pabilitiesdata/caps_3.1.0.ppc64.xml index 400dc45be4..4992d6c7e3 100644 --- a/tests/qemucapabilitiesdata/caps_3.1.0.ppc64.xml +++ b/tests/qemucapabilitiesdata/caps_3.1.0.ppc64.xml @@ -157,6 +157,7 @@ + 3000091 0 42900758 diff --git a/tests/qemucapabilitiesdata/caps_3.1.0.x86_64.xml b/tests/qemuc= apabilitiesdata/caps_3.1.0.x86_64.xml index 434c644ad4..c5bd0a9b9e 100644 --- a/tests/qemucapabilitiesdata/caps_3.1.0.x86_64.xml +++ b/tests/qemucapabilitiesdata/caps_3.1.0.x86_64.xml @@ -202,6 +202,7 @@ + 3000092 0 43100758 diff --git a/tests/qemucapabilitiesdata/caps_4.0.0.aarch64.xml b/tests/qemu= capabilitiesdata/caps_4.0.0.aarch64.xml index 20f119665b..eca166d5f9 100644 --- a/tests/qemucapabilitiesdata/caps_4.0.0.aarch64.xml +++ b/tests/qemucapabilitiesdata/caps_4.0.0.aarch64.xml @@ -165,6 +165,7 @@ + 4000000 0 61700758 diff --git a/tests/qemucapabilitiesdata/caps_4.0.0.ppc64.xml b/tests/qemuca= pabilitiesdata/caps_4.0.0.ppc64.xml index 9ea6f4d046..8a0dcbf705 100644 --- a/tests/qemucapabilitiesdata/caps_4.0.0.ppc64.xml +++ b/tests/qemucapabilitiesdata/caps_4.0.0.ppc64.xml @@ -170,6 +170,7 @@ + 4000000 0 42900758 diff --git a/tests/qemucapabilitiesdata/caps_4.0.0.riscv32.xml b/tests/qemu= capabilitiesdata/caps_4.0.0.riscv32.xml index 7503c2dbcd..d71ce16bcb 100644 --- a/tests/qemucapabilitiesdata/caps_4.0.0.riscv32.xml +++ b/tests/qemucapabilitiesdata/caps_4.0.0.riscv32.xml @@ -168,6 +168,7 @@ + 4000000 0 0 diff --git a/tests/qemucapabilitiesdata/caps_4.0.0.riscv64.xml b/tests/qemu= capabilitiesdata/caps_4.0.0.riscv64.xml index 4a94179ee7..d4a33642d6 100644 --- a/tests/qemucapabilitiesdata/caps_4.0.0.riscv64.xml +++ b/tests/qemucapabilitiesdata/caps_4.0.0.riscv64.xml @@ -168,6 +168,7 @@ + 4000000 0 0 diff --git a/tests/qemucapabilitiesdata/caps_4.0.0.s390x.xml b/tests/qemuca= pabilitiesdata/caps_4.0.0.s390x.xml index ef802f3d1f..ee2ee0c1b0 100644 --- a/tests/qemucapabilitiesdata/caps_4.0.0.s390x.xml +++ b/tests/qemucapabilitiesdata/caps_4.0.0.s390x.xml @@ -132,6 +132,7 @@ + 4000000 0 39100758 diff --git a/tests/qemucapabilitiesdata/caps_4.0.0.x86_64.xml b/tests/qemuc= apabilitiesdata/caps_4.0.0.x86_64.xml index 87c95f4d18..ef4b6aecdd 100644 --- a/tests/qemucapabilitiesdata/caps_4.0.0.x86_64.xml +++ b/tests/qemucapabilitiesdata/caps_4.0.0.x86_64.xml @@ -207,6 +207,7 @@ + 4000000 0 43100758 diff --git a/tests/qemucapabilitiesdata/caps_4.1.0.x86_64.xml b/tests/qemuc= apabilitiesdata/caps_4.1.0.x86_64.xml index 5d4540b3f7..f7a020d905 100644 --- a/tests/qemucapabilitiesdata/caps_4.1.0.x86_64.xml +++ b/tests/qemucapabilitiesdata/caps_4.1.0.x86_64.xml @@ -211,6 +211,7 @@ + 4000050 0 43100759 --=20 2.21.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Sun May 19 20:29:53 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 ARC-Seal: i=1; a=rsa-sha256; t=1569515019; cv=none; d=zoho.com; s=zohoarc; b=V5q6YJu3Rg/1AhQXRL1e7eWWOk3w8godrSGVKxUj4ZZwNfxmpX5Qxm/ThqHtPDN/IaCrYcFShv/BFytrEhNTyb+MzhAJC7n8LzP6O+mkV/dtEPuV3zVAso0auvBPUNonTE/rggTSFtNJ5OPchY0Ja0ObLvmU2YxuuuW+zbnM3U8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1569515019; h=Content-Type:Content-Transfer-Encoding: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:ARC-Authentication-Results; bh=HPSgeYpteq7Nw23BzpBXtIeRuTioi9rWZupBWe4IoBQ=; b=RRUpNiXLQdF1QCOciiLRqI+kiRxvvC40tiHoNWFAHjgmTydfqcoGViOiX82x7mSncdAg6MS+Xx5P/qKz+YwewVULFXXruW6kIXnR5mO+Ap6BeVqjYl/fz0ciwoDg6wP+ADixIcsProe8A/888ucP3Q89DYM9SaQhyIzxOLFh0rY= ARC-Authentication-Results: i=1; mx.zoho.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 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 1569515019971168.90732914170826; Thu, 26 Sep 2019 09:23:39 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 47B4510CC1FE; Thu, 26 Sep 2019 16:23:37 +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 1D503600CE; Thu, 26 Sep 2019 16:23:37 +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 CBD50180B536; Thu, 26 Sep 2019 16:23:36 +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 x8QGEqtH003878 for ; Thu, 26 Sep 2019 12:14:52 -0400 Received: by smtp.corp.redhat.com (Postfix) id 7B68F5D9CD; Thu, 26 Sep 2019 16:14:52 +0000 (UTC) Received: from moe.brq.redhat.com (unknown [10.43.2.30]) by smtp.corp.redhat.com (Postfix) with ESMTP id 0417B5D9C3 for ; Thu, 26 Sep 2019 16:14:51 +0000 (UTC) From: Michal Privoznik To: libvir-list@redhat.com Date: Thu, 26 Sep 2019 18:12:30 +0200 Message-Id: <888c58824c4f5cba22b457a13154a5d0146680e4.1569514291.git.mprivozn@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v2 34/39] qemu: Generate command line of NVMe disks 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-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.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.6.2 (mx1.redhat.com [10.5.110.65]); Thu, 26 Sep 2019 16:23:38 +0000 (UTC) Content-Type: text/plain; charset="utf-8" Now, that we have everything prepared, we can generate command line for NVMe disks. Signed-off-by: Michal Privoznik --- src/qemu/qemu_block.c | 25 ++++++++- src/qemu/qemu_command.c | 3 ++ src/qemu/qemu_process.c | 7 +++ .../disk-nvme.x86_64-latest.args | 53 +++++++++++++++++++ tests/qemuxml2argvtest.c | 1 + 5 files changed, 88 insertions(+), 1 deletion(-) create mode 100644 tests/qemuxml2argvdata/disk-nvme.x86_64-latest.args diff --git a/src/qemu/qemu_block.c b/src/qemu/qemu_block.c index 99b2a4efaa..311f42e52f 100644 --- a/src/qemu/qemu_block.c +++ b/src/qemu/qemu_block.c @@ -994,6 +994,25 @@ qemuBlockStorageSourceGetVvfatProps(virStorageSourcePt= r src, } =20 =20 +static virJSONValuePtr +qemuBlockStorageSourceGetNVMeProps(virStorageSourcePtr src) +{ + const virStorageSourceNVMeDef *nvme =3D src->nvme; + VIR_AUTOFREE(char *) pciAddr =3D NULL; + virJSONValuePtr ret =3D NULL; + + if (!(pciAddr =3D virPCIDeviceAddressAsString(&nvme->pciAddr))) + return NULL; + + ignore_value(virJSONValueObjectCreate(&ret, + "s:driver", "nvme", + "s:device", pciAddr, + "U:namespace", nvme->namespace, + NULL)); + return ret; +} + + static int qemuBlockStorageSourceGetBlockdevGetCacheProps(virStorageSourcePtr src, virJSONValuePtr props) @@ -1076,8 +1095,12 @@ qemuBlockStorageSourceGetBackendProps(virStorageSour= cePtr src, return NULL; break; =20 - case VIR_STORAGE_TYPE_VOLUME: case VIR_STORAGE_TYPE_NVME: + if (!(fileprops =3D qemuBlockStorageSourceGetNVMeProps(src))) + return NULL; + break; + + case VIR_STORAGE_TYPE_VOLUME: case VIR_STORAGE_TYPE_NONE: case VIR_STORAGE_TYPE_LAST: return NULL; diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c index b2519465ba..ad6c1e7e8a 100644 --- a/src/qemu/qemu_command.c +++ b/src/qemu/qemu_command.c @@ -1548,6 +1548,9 @@ qemuDiskSourceNeedsProps(virStorageSourcePtr src, src->haveTLS =3D=3D VIR_TRISTATE_BOOL_YES) return true; =20 + if (actualType =3D=3D VIR_STORAGE_TYPE_NVME) + return true; + return false; } =20 diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c index a50cd54393..f20561c07b 100644 --- a/src/qemu/qemu_process.c +++ b/src/qemu/qemu_process.c @@ -5390,6 +5390,13 @@ qemuProcessStartValidateDisks(virDomainObjPtr vm, _("PowerPC pseries machines do not support flop= py device")); return -1; } + + if (src->type =3D=3D VIR_STORAGE_TYPE_NVME && + !virQEMUCapsGet(qemuCaps, QEMU_CAPS_DRIVE_NVME)) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", + _("NVMe disks are not supported with this QEMU = binary")); + return -1; + } } =20 return 0; diff --git a/tests/qemuxml2argvdata/disk-nvme.x86_64-latest.args b/tests/qe= muxml2argvdata/disk-nvme.x86_64-latest.args new file mode 100644 index 0000000000..b0f640b751 --- /dev/null +++ b/tests/qemuxml2argvdata/disk-nvme.x86_64-latest.args @@ -0,0 +1,53 @@ +LC_ALL=3DC \ +PATH=3D/bin \ +HOME=3D/tmp/lib/domain--1-QEMUGuest1 \ +USER=3Dtest \ +LOGNAME=3Dtest \ +XDG_DATA_HOME=3D/tmp/lib/domain--1-QEMUGuest1/.local/share \ +XDG_CACHE_HOME=3D/tmp/lib/domain--1-QEMUGuest1/.cache \ +XDG_CONFIG_HOME=3D/tmp/lib/domain--1-QEMUGuest1/.config \ +QEMU_AUDIO_DRV=3Dnone \ +/usr/bin/qemu-system-i686 \ +-name guest=3DQEMUGuest1,debug-threads=3Don \ +-S \ +-object secret,id=3DmasterKey0,format=3Draw,\ +file=3D/tmp/lib/domain--1-QEMUGuest1/master-key.aes \ +-machine pc,accel=3Dtcg,usb=3Doff,dump-guest-core=3Doff \ +-m 214 \ +-overcommit mem-lock=3Doff \ +-smp 1,sockets=3D1,cores=3D1,threads=3D1 \ +-uuid c7a5fdbd-edaf-9455-926a-d65c16db1809 \ +-display none \ +-no-user-config \ +-nodefaults \ +-chardev socket,id=3Dcharmonitor,fd=3D1729,server,nowait \ +-mon chardev=3Dcharmonitor,id=3Dmonitor,mode=3Dcontrol \ +-rtc base=3Dutc \ +-no-shutdown \ +-no-acpi \ +-boot strict=3Don \ +-device piix3-usb-uhci,id=3Dusb,bus=3Dpci.0,addr=3D0x1.0x2 \ +-device virtio-scsi-pci,id=3Dscsi0,bus=3Dpci.0,addr=3D0x3 \ +-drive file.driver=3Dnvme,file.device=3D0000:01:00.0,file.namespace=3D1,fo= rmat=3Draw,\ +if=3Dnone,id=3Ddrive-virtio-disk0 \ +-device virtio-blk-pci,scsi=3Doff,bus=3Dpci.0,addr=3D0x4,drive=3Ddrive-vir= tio-disk0,\ +id=3Dvirtio-disk0,bootindex=3D1 \ +-drive file.driver=3Dnvme,file.device=3D0000:01:00.0,file.namespace=3D2,fo= rmat=3Draw,\ +if=3Dnone,id=3Ddrive-virtio-disk1 \ +-device virtio-blk-pci,scsi=3Doff,bus=3Dpci.0,addr=3D0x5,drive=3Ddrive-vir= tio-disk1,\ +id=3Dvirtio-disk1 \ +-drive file.driver=3Dnvme,file.device=3D0000:02:00.0,file.namespace=3D1,fo= rmat=3Draw,\ +if=3Dnone,id=3Ddrive-virtio-disk2 \ +-device virtio-blk-pci,scsi=3Doff,bus=3Dpci.0,addr=3D0x6,drive=3Ddrive-vir= tio-disk2,\ +id=3Dvirtio-disk2 \ +-object secret,id=3Dvirtio-disk3-luks-secret0,\ +data=3D9eao5F8qtkGt+seB1HYivWIxbtwUu6MQtg1zpj/oDtUsPr1q8wBYM91uEHCn6j/1,\ +keyid=3DmasterKey0,iv=3DAAECAwQFBgcICQoLDA0ODw=3D=3D,format=3Dbase64 \ +-drive file.driver=3Dnvme,file.device=3D0001:02:00.0,file.namespace=3D2,\ +encrypt.format=3Dluks,encrypt.key-secret=3Dvirtio-disk3-luks-secret0,forma= t=3Dqcow2,\ +if=3Dnone,id=3Ddrive-virtio-disk3,cache=3Dnone \ +-device virtio-blk-pci,scsi=3Doff,bus=3Dpci.0,addr=3D0x7,drive=3Ddrive-vir= tio-disk3,\ +id=3Dvirtio-disk3,write-cache=3Don \ +-sandbox on,obsolete=3Ddeny,elevateprivileges=3Ddeny,spawn=3Ddeny,\ +resourcecontrol=3Ddeny \ +-msg timestamp=3Don diff --git a/tests/qemuxml2argvtest.c b/tests/qemuxml2argvtest.c index 5bbac1c8b8..896c05b267 100644 --- a/tests/qemuxml2argvtest.c +++ b/tests/qemuxml2argvtest.c @@ -1095,6 +1095,7 @@ mymain(void) driver.config->vxhsTLS =3D 0; VIR_FREE(driver.config->vxhsTLSx509certdir); DO_TEST("disk-no-boot", NONE); + DO_TEST_CAPS_LATEST("disk-nvme"); DO_TEST_PARSE_ERROR("disk-device-lun-type-invalid", QEMU_CAPS_VIRTIO_SCSI); DO_TEST_FAILURE("disk-usb-nosupport", NONE); --=20 2.21.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Sun May 19 20:29:53 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 ARC-Seal: i=1; a=rsa-sha256; t=1569514917; cv=none; d=zoho.com; s=zohoarc; b=TSn8lHO2iZhqdi5UQBGvUtaAJmXWsJS2UzEhpOkvBmGXdDS0kLBCpJv5+E86a1dNJxAcvRuWK8yO6uyYC5SiLs1Tg8FXaimHQD3hAAFn/qMzMpLGAaOL8SnI0Uc2OXMbjfc2/BGvCZhA1lIkojywm4Bd54n1oJhGEM0yYz957Lo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1569514917; h=Content-Type:Content-Transfer-Encoding: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:ARC-Authentication-Results; bh=thnqGDetWZFsLAAjtoboRLFA5oVZzEpBgQo+2Zyip9Y=; b=lATR/pxP5AyL6423IFk4L+jGQCnBC9VsroqyYOlK3BponAOMVApgFUXhyUre5oqtFz/aXg/9XgsrCc6AhY1+yJzhB00VdAK+zbAl6m3Zi3Nk0H34K80UNSGbKoWdnQTe320XVtKpnVr53isHsIJVlKLLA/ahUXJ9rXiLiKrwaUI= ARC-Authentication-Results: i=1; mx.zoho.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 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 1569514917939147.12812734607928; Thu, 26 Sep 2019 09:21:57 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 5E3B28E39B; Thu, 26 Sep 2019 16:21:56 +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 38F9D100EBD5; Thu, 26 Sep 2019 16:21:56 +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 EFBDB180BA9A; Thu, 26 Sep 2019 16:21:55 +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 x8QGEt9e003893 for ; Thu, 26 Sep 2019 12:14:55 -0400 Received: by smtp.corp.redhat.com (Postfix) id 72F995D9E2; Thu, 26 Sep 2019 16:14:55 +0000 (UTC) Received: from moe.brq.redhat.com (unknown [10.43.2.30]) by smtp.corp.redhat.com (Postfix) with ESMTP id F0E885D9D5 for ; Thu, 26 Sep 2019 16:14:52 +0000 (UTC) From: Michal Privoznik To: libvir-list@redhat.com Date: Thu, 26 Sep 2019 18:12:31 +0200 Message-Id: <3b56303b2b297685620901126346118410e26165.1569514291.git.mprivozn@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v2 35/39] qemu_monitor_text: Catch IOMMU/VFIO related errors in qemuMonitorTextAddDrive 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-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.22 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Thu, 26 Sep 2019 16:21:56 +0000 (UTC) Content-Type: text/plain; charset="utf-8" Because this is a HMP we're dealing with, there is nothing like class of reply message, so we have to do some string comparison to guess if the command fails. Well, with NVMe disks whole new class of errors comes to play because qemu needs to initialize IOMMU and VFIO for them. You can see all the messages it may produce in qemu_vfio_init_pci(). Signed-off-by: Michal Privoznik --- src/qemu/qemu_monitor_text.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/qemu/qemu_monitor_text.c b/src/qemu/qemu_monitor_text.c index b1abcacdd0..39445247a0 100644 --- a/src/qemu/qemu_monitor_text.c +++ b/src/qemu/qemu_monitor_text.c @@ -76,6 +76,13 @@ int qemuMonitorTextAddDrive(qemuMonitorPtr mon, goto cleanup; } =20 + if (strstr(reply, "IOMMU") || + strstr(reply, "VFIO")) { + virReportError(VIR_ERR_OPERATION_FAILED, "%s", + reply); + goto cleanup; + } + ret =3D 0; =20 cleanup: --=20 2.21.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Sun May 19 20:29:53 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 ARC-Seal: i=1; a=rsa-sha256; t=1569514931; cv=none; d=zoho.com; s=zohoarc; b=Zp60ntc1sxdlrQUg9ycWpzPZJFJI+XanjpclFheUxwE6RNkbSN2/G//krM/heCvKAgc9aVoszjBSySuUTYNJpyyA0/Vv73PZ+lwahabR2FwmV99qSRSwury7ZsCl9pCMCGqTTyW9JR8ndUOJ7uEy7oiBiLIeSXnzXWSZ+mA6R+A= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1569514931; h=Content-Type:Content-Transfer-Encoding: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:ARC-Authentication-Results; bh=MVSrQuAmaPmrWhoMlFUzvcncK+QpHql5g252ARipLp0=; b=ZyfixadhRUgytfp6pWlbOHMSBBMsQVWNtsL1UXFt5iaq1g1IdQDc/8/s5Obk1wFd+iTpdJcKiS+OBc7W6/2suhQY4tFnU+ccrYNglH8UI/Dr3QiS3QSH9QE8lBf88fZqXGBBSkLxkX+b94BKQ2dwfF9POeH/xeCfKU+Ziz/Yx+w= ARC-Authentication-Results: i=1; mx.zoho.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 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 1569514931152148.40717216689143; Thu, 26 Sep 2019 09:22:11 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id A8CE210DCCA6; Thu, 26 Sep 2019 16:22:08 +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 82F9E61F24; Thu, 26 Sep 2019 16:22:08 +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 434F9180B536; Thu, 26 Sep 2019 16:22:08 +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 x8QGEvaH003914 for ; Thu, 26 Sep 2019 12:14:57 -0400 Received: by smtp.corp.redhat.com (Postfix) id B8DE05D9E2; Thu, 26 Sep 2019 16:14:57 +0000 (UTC) Received: from moe.brq.redhat.com (unknown [10.43.2.30]) by smtp.corp.redhat.com (Postfix) with ESMTP id 42E085D9D5 for ; Thu, 26 Sep 2019 16:14:55 +0000 (UTC) From: Michal Privoznik To: libvir-list@redhat.com Date: Thu, 26 Sep 2019 18:12:32 +0200 Message-Id: <43b7e78912698121b15fb430663ea7d654eedcce.1569514291.git.mprivozn@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v2 36/39] qemu: Don't leak storage perms on failure in qemuDomainAttachDiskGeneric 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-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.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.6.2 (mx1.redhat.com [10.5.110.64]); Thu, 26 Sep 2019 16:22:10 +0000 (UTC) Content-Type: text/plain; charset="utf-8" At the very beginning of the attach function the qemuDomainStorageSourceChainAccessAllow() is called which modifies CGroups, locks and seclabels for new disk and its backing chain. This must be followed by a counterpart which reverts back all the changes if something goes wrong. This boils down to calling qemuDomainStorageSourceChainAccessRevoke() which is done under 'error' label. But not all failure branches jump there. They just jump onto 'cleanup' label where no revoke is done. Such mistake is easy to do because 'cleanup' label does exist. Therefore, dissolve 'error' block in 'cleanup' and have everything jump onto 'cleanup' label. Signed-off-by: Michal Privoznik --- src/qemu/qemu_hotplug.c | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/src/qemu/qemu_hotplug.c b/src/qemu/qemu_hotplug.c index 5f92c61aa9..75ffc099e1 100644 --- a/src/qemu/qemu_hotplug.c +++ b/src/qemu/qemu_hotplug.c @@ -682,13 +682,13 @@ qemuDomainAttachDiskGeneric(virQEMUDriverPtr driver, bool blockdev =3D virQEMUCapsGet(priv->qemuCaps, QEMU_CAPS_BLOCKDEV); =20 if (qemuDomainStorageSourceChainAccessAllow(driver, vm, disk->src) < 0) - goto cleanup; + return -1; =20 if (qemuAssignDeviceDiskAlias(vm->def, disk, priv->qemuCaps) < 0) - goto error; + goto cleanup; =20 if (qemuDomainPrepareDiskSource(disk, priv, cfg) < 0) - goto error; + goto cleanup; =20 if (blockdev) { if (disk->copy_on_read =3D=3D VIR_TRISTATE_SWITCH_ON && @@ -705,13 +705,13 @@ qemuDomainAttachDiskGeneric(virQEMUDriverPtr driver, } =20 if (!(devstr =3D qemuBuildDiskDeviceStr(vm->def, disk, 0, priv->qemuCa= ps))) - goto error; + goto cleanup; =20 if (VIR_REALLOC_N(vm->def->disks, vm->def->ndisks + 1) < 0) - goto error; + goto cleanup; =20 if (qemuHotplugAttachManagedPR(driver, vm, disk->src, QEMU_ASYNC_JOB_N= ONE) < 0) - goto error; + goto cleanup; =20 qemuDomainObjEnterMonitor(driver, vm); =20 @@ -747,7 +747,7 @@ qemuDomainAttachDiskGeneric(virQEMUDriverPtr driver, =20 if (qemuDomainObjExitMonitor(driver, vm) < 0) { ret =3D -2; - goto error; + goto cleanup; } =20 virDomainAuditDisk(vm, NULL, disk->src, "attach", true); @@ -756,6 +756,8 @@ qemuDomainAttachDiskGeneric(virQEMUDriverPtr driver, ret =3D 0; =20 cleanup: + if (ret < 0) + ignore_value(qemuDomainStorageSourceChainAccessRevoke(driver, vm, = disk->src)); qemuDomainSecretDiskDestroy(disk); return ret; =20 @@ -772,9 +774,6 @@ qemuDomainAttachDiskGeneric(virQEMUDriverPtr driver, ret =3D -2; =20 virDomainAuditDisk(vm, NULL, disk->src, "attach", false); - - error: - ignore_value(qemuDomainStorageSourceChainAccessRevoke(driver, vm, disk= ->src)); goto cleanup; } =20 --=20 2.21.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Sun May 19 20:29:53 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 ARC-Seal: i=1; a=rsa-sha256; t=1569514975; cv=none; d=zoho.com; s=zohoarc; b=PNwBqGRnPhUUittbAX1VPzRfait3Jt2fU1rzTSXKOqI0KFbiJXQ+fBraDw8bO1x+2Qm8l7U+R1d91K1iYAN6RFeCYadQAUJJujnODK0rEKis//PxVxnE8u6EUhtcPXqWwaQQwSKdYI+yLyIA3U1ze5ynCT7d59tN+mZncLybH74= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1569514975; h=Content-Type:Content-Transfer-Encoding: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:ARC-Authentication-Results; bh=uVdXQEebrIcfvm6zZoTOznx+kqNAJWLSxv1yzr/xMIo=; b=G+mlCpvpJgQisWtVi6Jtvv7qRXq9vRgELFFt9xoyVo/sVxzfi2Y4855OvulrpKf65j4ofgkikjXJQE3z0CQDJAhmptfhFCP/wbbIIDhBid/s4PyBOblMqgWW/9YlZVYdh/fExgPwwTz3wqXhDNXIA7YbbNUKkGa43RtZSU/o19o= ARC-Authentication-Results: i=1; mx.zoho.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 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 15695149750591015.3525408441596; Thu, 26 Sep 2019 09:22:55 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 8918518C4299; Thu, 26 Sep 2019 16:22:53 +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 61FB75D6B0; Thu, 26 Sep 2019 16:22:53 +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 2327F1803517; Thu, 26 Sep 2019 16:22:53 +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 x8QGF3vO003950 for ; Thu, 26 Sep 2019 12:15:03 -0400 Received: by smtp.corp.redhat.com (Postfix) id 81CFA5D9E2; Thu, 26 Sep 2019 16:15:03 +0000 (UTC) Received: from moe.brq.redhat.com (unknown [10.43.2.30]) by smtp.corp.redhat.com (Postfix) with ESMTP id 0A3645D9D5 for ; Thu, 26 Sep 2019 16:14:57 +0000 (UTC) From: Michal Privoznik To: libvir-list@redhat.com Date: Thu, 26 Sep 2019 18:12:33 +0200 Message-Id: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v2 37/39] qemu: Allow forcing VFIO when computing memlock limit 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-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.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.6.2 (mx1.redhat.com [10.5.110.62]); Thu, 26 Sep 2019 16:22:54 +0000 (UTC) Content-Type: text/plain; charset="utf-8" With NVMe disks, one can start a blockjob with a NVMe disk that is not visible in domain XML (at least right away). Usually, it's fairly easy to override this limitation of qemuDomainGetMemLockLimitBytes() - for instance for hostdevs we temporarily add the device to domain def, let the function calculate the limit and then remove the device. But it's not so easy with virStorageSourcePtr - in some cases they don't necessarily are attached to a disk. And even if they are it's done later in the process and frankly, I find it too complicated to be able to use the simple trick we use with hostdevs. Signed-off-by: Michal Privoznik --- src/qemu/qemu_command.c | 2 +- src/qemu/qemu_domain.c | 46 ++++++++++++++++++++++++++--------------- src/qemu/qemu_domain.h | 6 ++++-- src/qemu/qemu_hotplug.c | 12 +++++------ tests/qemumemlocktest.c | 2 +- 5 files changed, 41 insertions(+), 27 deletions(-) diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c index ad6c1e7e8a..fa2394378a 100644 --- a/src/qemu/qemu_command.c +++ b/src/qemu/qemu_command.c @@ -10511,7 +10511,7 @@ qemuBuildCommandLine(virQEMUDriverPtr driver, =20 /* In some situations, eg. VFIO passthrough, QEMU might need to lock a * significant amount of memory, so we need to set the limit according= ly */ - virCommandSetMaxMemLock(cmd, qemuDomainGetMemLockLimitBytes(def)); + virCommandSetMaxMemLock(cmd, qemuDomainGetMemLockLimitBytes(def, false= )); =20 if (virQEMUCapsGet(qemuCaps, QEMU_CAPS_MSG_TIMESTAMP) && cfg->logTimestamp) diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c index e4e9d4e361..3fe0004cab 100644 --- a/src/qemu/qemu_domain.c +++ b/src/qemu/qemu_domain.c @@ -11843,12 +11843,14 @@ ppc64VFIODeviceIsNV2Bridge(const char *device) /** * getPPC64MemLockLimitBytes: * @def: domain definition + * @forceVFIO: force VFIO usage * * A PPC64 helper that calculates the memory locking limit in order for * the guest to operate properly. */ static unsigned long long -getPPC64MemLockLimitBytes(virDomainDefPtr def) +getPPC64MemLockLimitBytes(virDomainDefPtr def, + bool forceVFIO) { unsigned long long memKB =3D 0; unsigned long long baseLimit =3D 0; @@ -11939,7 +11941,7 @@ getPPC64MemLockLimitBytes(virDomainDefPtr def) passthroughLimit =3D maxMemory + 128 * (1ULL<<30) / 512 * nPCIHostBridges + 8192; - } else if (usesVFIO) { + } else if (usesVFIO || forceVFIO) { /* For regular (non-NVLink2 present) VFIO passthrough, the value * of passthroughLimit is: * @@ -11977,16 +11979,20 @@ getPPC64MemLockLimitBytes(virDomainDefPtr def) /** * qemuDomainGetMemLockLimitBytes: * @def: domain definition + * @forceVFIO: force VFIO calculation * * Calculate the memory locking limit that needs to be set in order for * the guest to operate properly. The limit depends on a number of factors, * including certain configuration options and less immediately apparent o= nes * such as the guest architecture or the use of certain devices. + * The @forceVFIO argument can be used to tell this function will use VFIO= even + * though @def doesn't indicates so right now. * * Returns: the memory locking limit, or 0 if setting the limit is not nee= ded */ unsigned long long -qemuDomainGetMemLockLimitBytes(virDomainDefPtr def) +qemuDomainGetMemLockLimitBytes(virDomainDefPtr def, + bool forceVFIO) { unsigned long long memKB =3D 0; bool usesVFIO =3D false; @@ -12007,7 +12013,7 @@ qemuDomainGetMemLockLimitBytes(virDomainDefPtr def) return VIR_DOMAIN_MEMORY_PARAM_UNLIMITED; =20 if (ARCH_IS_PPC64(def->os.arch) && def->virtType =3D=3D VIR_DOMAIN_VIR= T_KVM) - return getPPC64MemLockLimitBytes(def); + return getPPC64MemLockLimitBytes(def, forceVFIO); =20 /* For device passthrough using VFIO the guest memory and MMIO memory * regions need to be locked persistent in order to allow DMA. @@ -12027,18 +12033,20 @@ qemuDomainGetMemLockLimitBytes(virDomainDefPtr de= f) * * Note that this may not be valid for all platforms. */ - for (i =3D 0; i < def->nhostdevs; i++) { - if (virHostdevIsVFIODevice(def->hostdevs[i]) || - virHostdevIsMdevDevice(def->hostdevs[i])) { - usesVFIO =3D true; - break; + if (!forceVFIO) { + for (i =3D 0; i < def->nhostdevs; i++) { + if (virHostdevIsVFIODevice(def->hostdevs[i]) || + virHostdevIsMdevDevice(def->hostdevs[i])) { + usesVFIO =3D true; + break; + } } + + if (virDomainDefHasNVMeDisk(def)) + usesVFIO =3D true; } =20 - if (virDomainDefHasNVMeDisk(def)) - usesVFIO =3D true; - - if (usesVFIO) + if (usesVFIO || forceVFIO) memKB =3D virDomainDefGetMemoryTotal(def) + 1024 * 1024; =20 done: @@ -12049,9 +12057,12 @@ qemuDomainGetMemLockLimitBytes(virDomainDefPtr def) /** * qemuDomainAdjustMaxMemLock: * @vm: domain + * @forceVFIO: apply VFIO requirements even if vm's def doesn't require it * * Adjust the memory locking limit for the QEMU process associated to @vm,= in - * order to comply with VFIO or architecture requirements. + * order to comply with VFIO or architecture requirements. If @forceVFIO is + * true then the limit is changed even if nothing in @vm's definition indi= cates + * so. * * The limit will not be changed unless doing so is needed; the first time * the limit is changed, the original (default) limit is stored in @vm and @@ -12061,12 +12072,13 @@ qemuDomainGetMemLockLimitBytes(virDomainDefPtr de= f) * Returns: 0 on success, <0 on failure */ int -qemuDomainAdjustMaxMemLock(virDomainObjPtr vm) +qemuDomainAdjustMaxMemLock(virDomainObjPtr vm, + bool forceVFIO) { unsigned long long bytes =3D 0; int ret =3D -1; =20 - bytes =3D qemuDomainGetMemLockLimitBytes(vm->def); + bytes =3D qemuDomainGetMemLockLimitBytes(vm->def, forceVFIO); =20 if (bytes) { /* If this is the first time adjusting the limit, save the current @@ -12115,7 +12127,7 @@ qemuDomainAdjustMaxMemLockHostdev(virDomainObjPtr v= m, int ret =3D 0; =20 vm->def->hostdevs[vm->def->nhostdevs++] =3D hostdev; - if (qemuDomainAdjustMaxMemLock(vm) < 0) + if (qemuDomainAdjustMaxMemLock(vm, false) < 0) ret =3D -1; =20 vm->def->hostdevs[--(vm->def->nhostdevs)] =3D NULL; diff --git a/src/qemu/qemu_domain.h b/src/qemu/qemu_domain.h index de6479f8e0..7802a8b98b 100644 --- a/src/qemu/qemu_domain.h +++ b/src/qemu/qemu_domain.h @@ -962,8 +962,10 @@ bool qemuDomainSupportsPCI(virDomainDefPtr def, =20 void qemuDomainUpdateCurrentMemorySize(virDomainObjPtr vm); =20 -unsigned long long qemuDomainGetMemLockLimitBytes(virDomainDefPtr def); -int qemuDomainAdjustMaxMemLock(virDomainObjPtr vm); +unsigned long long qemuDomainGetMemLockLimitBytes(virDomainDefPtr def, + bool forceVFIO); +int qemuDomainAdjustMaxMemLock(virDomainObjPtr vm, + bool forceVFIO); int qemuDomainAdjustMaxMemLockHostdev(virDomainObjPtr vm, virDomainHostdevDefPtr hostdev); =20 diff --git a/src/qemu/qemu_hotplug.c b/src/qemu/qemu_hotplug.c index 75ffc099e1..f5a672a195 100644 --- a/src/qemu/qemu_hotplug.c +++ b/src/qemu/qemu_hotplug.c @@ -1648,7 +1648,7 @@ qemuDomainAttachHostPCIDevice(virQEMUDriverPtr driver, if (teardowndevice && qemuDomainNamespaceTeardownHostdev(vm, hostdev) < 0) VIR_WARN("Unable to remove host device from /dev"); - if (teardownmemlock && qemuDomainAdjustMaxMemLock(vm) < 0) + if (teardownmemlock && qemuDomainAdjustMaxMemLock(vm, false) < 0) VIR_WARN("Unable to reset maximum locked memory on hotplug fail"); =20 if (releaseaddr) @@ -2387,7 +2387,7 @@ qemuDomainAttachMemory(virQEMUDriverPtr driver, if (virDomainMemoryInsert(vm->def, mem) < 0) goto cleanup; =20 - if (qemuDomainAdjustMaxMemLock(vm) < 0) + if (qemuDomainAdjustMaxMemLock(vm, false) < 0) goto removedef; =20 qemuDomainObjEnterMonitor(driver, vm); @@ -2458,7 +2458,7 @@ qemuDomainAttachMemory(virQEMUDriverPtr driver, =20 /* reset the mlock limit */ virErrorPreserveLast(&orig_err); - ignore_value(qemuDomainAdjustMaxMemLock(vm)); + ignore_value(qemuDomainAdjustMaxMemLock(vm, false)); virErrorRestore(&orig_err); =20 goto audit; @@ -2856,7 +2856,7 @@ qemuDomainAttachMediatedDevice(virQEMUDriverPtr drive= r, ret =3D 0; cleanup: if (ret < 0) { - if (teardownmemlock && qemuDomainAdjustMaxMemLock(vm) < 0) + if (teardownmemlock && qemuDomainAdjustMaxMemLock(vm, false) < 0) VIR_WARN("Unable to reset maximum locked memory on hotplug fai= l"); if (teardowncgroup && qemuTeardownHostdevCgroup(vm, hostdev) < 0) VIR_WARN("Unable to remove host device cgroup ACL on hotplug f= ail"); @@ -4378,7 +4378,7 @@ qemuDomainRemoveMemoryDevice(virQEMUDriverPtr driver, ignore_value(qemuProcessRefreshBalloonState(driver, vm, QEMU_ASYNC_JOB= _NONE)); =20 /* decrease the mlock limit after memory unplug if necessary */ - ignore_value(qemuDomainAdjustMaxMemLock(vm)); + ignore_value(qemuDomainAdjustMaxMemLock(vm, false)); =20 return 0; } @@ -4505,7 +4505,7 @@ qemuDomainRemoveHostDevice(virQEMUDriverPtr driver, qemuDomainRemovePCIHostDevice(driver, vm, hostdev); /* QEMU might no longer need to lock as much memory, eg. we just * detached the last VFIO device, so adjust the limit here */ - if (qemuDomainAdjustMaxMemLock(vm) < 0) + if (qemuDomainAdjustMaxMemLock(vm, false) < 0) VIR_WARN("Failed to adjust locked memory limit"); break; case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_USB: diff --git a/tests/qemumemlocktest.c b/tests/qemumemlocktest.c index c9484ac9cb..1d52498e25 100644 --- a/tests/qemumemlocktest.c +++ b/tests/qemumemlocktest.c @@ -43,7 +43,7 @@ testCompareMemLock(const void *data) goto cleanup; } =20 - ret =3D virTestCompareToULL(info->memlock, qemuDomainGetMemLockLimitBy= tes(def)); + ret =3D virTestCompareToULL(info->memlock, qemuDomainGetMemLockLimitBy= tes(def, false)); =20 cleanup: virDomainDefFree(def); --=20 2.21.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Sun May 19 20:29:53 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 ARC-Seal: i=1; a=rsa-sha256; t=1569514941; cv=none; d=zoho.com; s=zohoarc; b=XCJQxQtM2olngZlEdnpohjsHbG0Tt+B+G4cMh+tyBxnAE90rlz/02s7/ZtlE7emlolfoEzjWQNVM2CZOLrG7wiIvkEoNW8mhB9BxXJ+SIG4hA9yOkB54wjz3Lq+SEzv4m2azEnv2o9t6BhoyuouqRgsHqVcpG5cX06APp3hEOmw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1569514941; h=Content-Type:Content-Transfer-Encoding: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:ARC-Authentication-Results; bh=8xLsMZGc7wM+8vcqCjs3LQSGWppG+jimMx7I4F6PKlc=; b=PXVdB1luM3fe0BUclzei0eFfEsR/7V75YNYPN8/kohBQVOMXkX97UN8fm3wdagTfkKHImFq/KpApTUWhRIGHXvTzGMo6hPTc/w6q/E/JRxxITSJ1RCDaxseEnFjlW0WFRihL6dGHCvVKBu0ljiUk/t2Ag7nXNg7mcr8vEkLe3AE= ARC-Authentication-Results: i=1; mx.zoho.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 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 1569514941307436.13240415408313; Thu, 26 Sep 2019 09:22:21 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id C7F0910CC200; Thu, 26 Sep 2019 16:22:19 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 9F86560A9F; Thu, 26 Sep 2019 16:22:19 +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 666774EE68; Thu, 26 Sep 2019 16:22:19 +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 x8QGF8w6003971 for ; Thu, 26 Sep 2019 12:15:08 -0400 Received: by smtp.corp.redhat.com (Postfix) id BAC975D9E2; Thu, 26 Sep 2019 16:15:08 +0000 (UTC) Received: from moe.brq.redhat.com (unknown [10.43.2.30]) by smtp.corp.redhat.com (Postfix) with ESMTP id 422115D9D5 for ; Thu, 26 Sep 2019 16:15:03 +0000 (UTC) From: Michal Privoznik To: libvir-list@redhat.com Date: Thu, 26 Sep 2019 18:12:34 +0200 Message-Id: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v2 38/39] qemu_hotplug: Prepare NVMe disks on hotplug 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-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.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.6.2 (mx1.redhat.com [10.5.110.65]); Thu, 26 Sep 2019 16:22:20 +0000 (UTC) Content-Type: text/plain; charset="utf-8" Signed-off-by: Michal Privoznik --- src/qemu/qemu_domain.c | 58 +++++++++++++++++++++++++++++++++++++++++ src/qemu/qemu_hostdev.c | 22 ++++++++++++++++ src/qemu/qemu_hostdev.h | 6 +++++ 3 files changed, 86 insertions(+) diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c index 3fe0004cab..cb94840d5f 100644 --- a/src/qemu/qemu_domain.c +++ b/src/qemu/qemu_domain.c @@ -10537,6 +10537,54 @@ typedef enum { } qemuDomainStorageSourceAccessFlags; =20 =20 +static int +qemuDomainStorageSourceAccessModifyNVMe(virQEMUDriverPtr driver, + virDomainObjPtr vm, + virStorageSourcePtr src, + bool revoke) +{ + bool revoke_maxmemlock =3D false; + bool revoke_hostdev =3D false; + int ret =3D -1; + + if (!virStorageSourceChainHasNVMe(src)) + return 0; + + VIR_DEBUG("Modifying access for a NVMe disk src=3D%p revoke=3D%d", + src, revoke); + + if (revoke) { + revoke_maxmemlock =3D true; + revoke_hostdev =3D true; + ret =3D 0; + goto revoke; + } + + if (qemuDomainAdjustMaxMemLock(vm, true) < 0) + goto revoke; + + revoke_maxmemlock =3D true; + + if (qemuHostdevPrepareOneNVMeDisk(driver, vm->def->name, src) < 0) + goto revoke; + + revoke_hostdev =3D true; + + return 0; + + revoke: + if (revoke_maxmemlock) { + if (qemuDomainAdjustMaxMemLock(vm, false) < 0) + VIR_WARN("Unable to change max memlock limit"); + } + + if (revoke_hostdev) + qemuHostdevReAttachOneNVMeDisk(driver, vm->def->name, src); + + return ret; +} + + /** * qemuDomainStorageSourceAccessModify: * @driver: qemu driver struct @@ -10568,6 +10616,7 @@ qemuDomainStorageSourceAccessModify(virQEMUDriverPt= r driver, bool revoke_cgroup =3D false; bool revoke_label =3D false; bool revoke_namespace =3D false; + bool revoke_nvme =3D false; bool revoke_lockspace =3D false; =20 VIR_DEBUG("src=3D'%s' readonly=3D%d force_ro=3D%d force_rw=3D%d revoke= =3D%d chain=3D%d", @@ -10585,6 +10634,7 @@ qemuDomainStorageSourceAccessModify(virQEMUDriverPt= r driver, revoke_cgroup =3D true; revoke_label =3D true; revoke_namespace =3D true; + revoke_nvme =3D true; revoke_lockspace =3D true; ret =3D 0; goto revoke; @@ -10595,6 +10645,11 @@ qemuDomainStorageSourceAccessModify(virQEMUDriverP= tr driver, =20 revoke_lockspace =3D true; =20 + if (qemuDomainStorageSourceAccessModifyNVMe(driver, vm, src, false) < = 0) + goto revoke; + + revoke_nvme =3D true; + /* When modifying access of existing @src namespace does not need upda= te */ if (!(flags & QEMU_DOMAIN_STORAGE_SOURCE_ACCESS_MODIFY_ACCESS)) { if (qemuDomainNamespaceSetupDisk(vm, src) < 0) @@ -10645,6 +10700,9 @@ qemuDomainStorageSourceAccessModify(virQEMUDriverPt= r driver, VIR_WARN("Unable to remove /dev entry for %s", srcstr); } =20 + if (revoke_nvme) + qemuDomainStorageSourceAccessModifyNVMe(driver, vm, src, true); + if (revoke_lockspace) { if (virDomainLockImageDetach(driver->lockManager, vm, src) < 0) VIR_WARN("Unable to release lock on %s", srcstr); diff --git a/src/qemu/qemu_hostdev.c b/src/qemu/qemu_hostdev.c index 5ab0217858..6ab052724a 100644 --- a/src/qemu/qemu_hostdev.c +++ b/src/qemu/qemu_hostdev.c @@ -212,6 +212,17 @@ qemuHostdevPreparePCIDevicesCheckSupport(virDomainHost= devDefPtr *hostdevs, return true; } =20 +int +qemuHostdevPrepareOneNVMeDisk(virQEMUDriverPtr driver, + const char *name, + virStorageSourcePtr src) +{ + return virHostdevPrepareOneNVMeDevice(driver->hostdevMgr, + QEMU_DRIVER_NAME, + name, + src); +} + int qemuHostdevPrepareNVMeDisks(virQEMUDriverPtr driver, const char *name, @@ -369,6 +380,17 @@ qemuHostdevPrepareDomainDevices(virQEMUDriverPtr drive= r, return 0; } =20 +void +qemuHostdevReAttachOneNVMeDisk(virQEMUDriverPtr driver, + const char *name, + virStorageSourcePtr src) +{ + virHostdevReAttachOneNVMeDevice(driver->hostdevMgr, + QEMU_DRIVER_NAME, + name, + src); +} + void qemuHostdevReAttachNVMeDisks(virQEMUDriverPtr driver, const char *name, diff --git a/src/qemu/qemu_hostdev.h b/src/qemu/qemu_hostdev.h index 735414b6aa..23df925529 100644 --- a/src/qemu/qemu_hostdev.h +++ b/src/qemu/qemu_hostdev.h @@ -41,6 +41,9 @@ int qemuHostdevUpdateActiveSCSIDevices(virQEMUDriverPtr d= river, int qemuHostdevUpdateActiveDomainDevices(virQEMUDriverPtr driver, virDomainDefPtr def); =20 +int qemuHostdevPrepareOneNVMeDisk(virQEMUDriverPtr driver, + const char *name, + virStorageSourcePtr src); int qemuHostdevPrepareNVMeDisks(virQEMUDriverPtr driver, const char *name, virDomainDiskDefPtr *disks, @@ -74,6 +77,9 @@ int qemuHostdevPrepareDomainDevices(virQEMUDriverPtr driv= er, virQEMUCapsPtr qemuCaps, unsigned int flags); =20 +void qemuHostdevReAttachOneNVMeDisk(virQEMUDriverPtr driver, + const char *name, + virStorageSourcePtr src); void qemuHostdevReAttachNVMeDisks(virQEMUDriverPtr driver, const char *name, virDomainDiskDefPtr *disks, --=20 2.21.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Sun May 19 20:29:53 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 ARC-Seal: i=1; a=rsa-sha256; t=1569514991; cv=none; d=zoho.com; s=zohoarc; b=iBsveYxKWvCSu9BONusMDQM25UFwA6kFrSq10mta7MP8zLZZbhUDk4K3/jTzqjFKO9gKRlDDJUtBktBd/0AEI0hoZRMTTzJL2xuLjA+p1DG2hLb1D01rWef7hI9cs34AghJv5ZvhKZr+FFTwLP47MnfDIfu5CR4E4/eZGJmC5vQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1569514991; h=Content-Type:Content-Transfer-Encoding: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:ARC-Authentication-Results; bh=UXwjnHs2ZL70yFKz8I+Ma3ZkEWFlJCmVXMFXKiC80BE=; b=MFoAwZA4vVfwpcR7OBxOIwR0hd/nQn/4aLdfILt3+3q0MgZXpXhOfy+UJbcynq/2DuaxoanTAP680s6gk6cHXPWAzpDiKayWLtGIbUq/B9KzU8kmrdASnZfs9r5SyRH9Yp79N+wFARtc98GR8ye0HIaAsT5L07IOdDLgBQZAcvA= ARC-Authentication-Results: i=1; mx.zoho.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 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 156951499120650.94786555520329; Thu, 26 Sep 2019 09:23:11 -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 9C41918C4269; Thu, 26 Sep 2019 16:23:09 +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 77E6B1FD3C; Thu, 26 Sep 2019 16:23:09 +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 38F55180B76F; Thu, 26 Sep 2019 16:23:09 +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 x8QGFC3v003989 for ; Thu, 26 Sep 2019 12:15:12 -0400 Received: by smtp.corp.redhat.com (Postfix) id 031B05D9D5; Thu, 26 Sep 2019 16:15:12 +0000 (UTC) Received: from moe.brq.redhat.com (unknown [10.43.2.30]) by smtp.corp.redhat.com (Postfix) with ESMTP id 7F6A75D9E2 for ; Thu, 26 Sep 2019 16:15:08 +0000 (UTC) From: Michal Privoznik To: libvir-list@redhat.com Date: Thu, 26 Sep 2019 18:12:35 +0200 Message-Id: <4b0db282c4a6c45daacd778c3bba2af282166663.1569514291.git.mprivozn@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v2 39/39] virsh: Introduce nvme disk to domblklist 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-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.6.2 (mx1.redhat.com [10.5.110.62]); Thu, 26 Sep 2019 16:23:10 +0000 (UTC) Content-Type: text/plain; charset="utf-8" This is slightly more complicated because NVMe disk source is not a simple attribute to element. The format in which the PCI address and namespace ID are printed is the same as QEMU accepts them: nvme://XXXX:XX:XX.X/X Signed-off-by: Michal Privoznik --- tools/virsh-domain-monitor.c | 31 +++++++++++++++++++++++++------ 1 file changed, 25 insertions(+), 6 deletions(-) diff --git a/tools/virsh-domain-monitor.c b/tools/virsh-domain-monitor.c index 0e2c4191d7..f663a87f8f 100644 --- a/tools/virsh-domain-monitor.c +++ b/tools/virsh-domain-monitor.c @@ -627,8 +627,8 @@ cmdDomblklist(vshControl *ctl, const vshCmd *cmd) for (i =3D 0; i < ndisks; i++) { ctxt->node =3D disks[i]; =20 + type =3D virXPathString("string(./@type)", ctxt); if (details) { - type =3D virXPathString("string(./@type)", ctxt); device =3D virXPathString("string(./@device)", ctxt); if (!type || !device) { vshPrint(ctl, "unable to query block list details"); @@ -641,11 +641,30 @@ cmdDomblklist(vshControl *ctl, const vshCmd *cmd) vshError(ctl, "unable to query block list"); goto cleanup; } - source =3D virXPathString("string(./source/@file" - "|./source/@dev" - "|./source/@dir" - "|./source/@name" - "|./source/@volume)", ctxt); + + if (STREQ_NULLABLE(type, "nvme")) { + VIR_AUTOFREE(char *) namespace =3D NULL; + virPCIDeviceAddress addr =3D { 0 }; + xmlNodePtr addrNode =3D NULL; + + if (!(namespace =3D virXPathString("string(./source/@namespace= )", ctxt)) || + !(addrNode =3D virXPathNode("./source/address", ctxt)) || + virPCIDeviceAddressParseXML(addrNode, &addr) < 0) { + vshError(ctl, "Unable to query NVMe disk address"); + goto cleanup; + } + + if (virAsprintf(&source, "nvme://%04x:%02x:%02x.%d/%s", + addr.domain, addr.bus, addr.slot, addr.functio= n, namespace) < 0) + goto cleanup; + } else { + source =3D virXPathString("string(./source/@file" + "|./source/@dev" + "|./source/@dir" + "|./source/@name" + "|./source/@volume)", ctxt); + } + if (details) { if (vshTableRowAppend(table, type, device, target, NULLSTR_MINUS(source), NULL) < 0) --=20 2.21.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list