From nobody Fri Apr 19 16:08:06 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=1562860472; cv=none; d=zoho.com; s=zohoarc; b=AYb2dz2LXe8c5DhL0AcFUmGmGskVrlthn0UsIGJlefmkdMpqYugR433pp+j5TP732iJihLGaKsfRrBmfdJ97GzU6vOmZbiTkhe0jkW9tpjraIErsIunEXH0M3MY5VXjeljGcoD11TI7vLLB6FCZPhuEtrCBmYe3sZFzqk4g7Tfg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1562860472; 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=9K4po4DlLixFvQ0fX16v7hMWhYDjBcvGk4JOqHTIqy8=; b=nglNx7da0s4ntOfvWIvy1niDij+Rc3Y3ZPf2v3u7VAx/aBQ4tBWns496FHsaSL45/RCSnEtm6iTZPCKhVRKrTNdbmDi6sqZGKOhS7D3fIZWrceoEYb0tOhUPgH7Oq5+VyF+CBF2D8G7ba9TCc36O4tNgcoc7EDcTrs+07aLBUjI= 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 1562860472586845.3569230921016; Thu, 11 Jul 2019 08:54:32 -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 BB0EA30C5847; Thu, 11 Jul 2019 15:54: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 A668660A97; Thu, 11 Jul 2019 15:54: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 CEC3018184AC; Thu, 11 Jul 2019 15:54:27 +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 x6BFsPPW014606 for ; Thu, 11 Jul 2019 11:54:25 -0400 Received: by smtp.corp.redhat.com (Postfix) id CD6465D9DC; Thu, 11 Jul 2019 15:54:25 +0000 (UTC) Received: from moe.brq.redhat.com (unknown [10.43.2.30]) by smtp.corp.redhat.com (Postfix) with ESMTP id 590D35D9CC for ; Thu, 11 Jul 2019 15:54:25 +0000 (UTC) From: Michal Privoznik To: libvir-list@redhat.com Date: Thu, 11 Jul 2019 17:53:48 +0200 Message-Id: <6f19a3aaf0ca65bf75f4b50a5f5d0a3cc71d8752.1562859733.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 v1 01/31] 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.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.46]); Thu, 11 Jul 2019 15:54:31 +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 --- src/util/virhostdev.c | 48 ++++++++++++++++++++++++++++--------------- 1 file changed, 32 insertions(+), 16 deletions(-) diff --git a/src/util/virhostdev.c b/src/util/virhostdev.c index a3647a6cf4..88b0828675 100644 --- a/src/util/virhostdev.c +++ b/src/util/virhostdev.c @@ -613,27 +613,22 @@ virHostdevRestoreNetConfig(virDomainHostdevDefPtr hos= tdev, } } =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 @@ -906,10 +901,31 @@ virHostdevPreparePCIDevices(virHostdevManagerPtr mgr, cleanup: virObjectUnlock(mgr->activePCIHostdevs); virObjectUnlock(mgr->inactivePCIHostdevs); - 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); +} + /* * Pre-condition: inactivePCIHostdevs & activePCIHostdevs * are locked --=20 2.21.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Fri Apr 19 16:08:06 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=1562860472; cv=none; d=zoho.com; s=zohoarc; b=KHcQozsyTDavaWZ/uNKlEB+KxPlcBs260MeR2wyFq0gXo0S1lKqDeA14KpvLO6jBnx4efAY/+T89/7ZkP4AVCit6xH6rQ29iA8xFmYWc6TBc6FEN+TfwtC3G9AZuThcTEp7qBDpqCdkOH4tGSmQHSpyfgyJgfQyNWsU1cPmBlWY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1562860472; 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=r/6jwVm6/Nc4HbjNgeJTE74r00+iIASaX1uzEJX/iHo=; b=KA0gcm4+/n8wjyyJKmMGdVwE9iHPn5bokzmUxwB5SLlsqzTZas38jDnCrurz0POGvRlxT0kL71XLnFUM8qHzLTIzHTY0XX/bqeWYQXRa4nFCz9TqMAvgXBEE3DOcH2csWMr6pSDcpj/vcVwSuc+F6xFpE3N+c1lUlQPvpdexYTc= 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 1562860472847163.24057345312553; Thu, 11 Jul 2019 08:54:32 -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 BA57187628; Thu, 11 Jul 2019 15:54:30 +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 A5A1019C69; Thu, 11 Jul 2019 15:54: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 115A43D3F3; Thu, 11 Jul 2019 15:54:27 +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 x6BFsQKU014614 for ; Thu, 11 Jul 2019 11:54:26 -0400 Received: by smtp.corp.redhat.com (Postfix) id 97D725D9DC; Thu, 11 Jul 2019 15:54:26 +0000 (UTC) Received: from moe.brq.redhat.com (unknown [10.43.2.30]) by smtp.corp.redhat.com (Postfix) with ESMTP id 23E565D9CC for ; Thu, 11 Jul 2019 15:54:25 +0000 (UTC) From: Michal Privoznik To: libvir-list@redhat.com Date: Thu, 11 Jul 2019 17:53:49 +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 v1 02/31] 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.23 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Thu, 11 Jul 2019 15:54:31 +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 --- 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 88b0828675..07397b9682 100644 --- a/src/util/virhostdev.c +++ b/src/util/virhostdev.c @@ -953,30 +953,18 @@ virHostdevReattachPCIDevice(virHostdevManagerPtr mgr, } } =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 @@ -1100,6 +1088,34 @@ virHostdevReAttachPCIDevices(virHostdevManagerPtr mg= r, virObjectUnref(pcidevs); } =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 Fri Apr 19 16:08:06 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=1562860486; cv=none; d=zoho.com; s=zohoarc; b=LeBYj5Yuu6H1/yPhtrbGdDQvuSJdITHZXV/SIIw8WMp0CySAN2FIi7vStXx5SdWf7ECcmWHofXS2ailkgV5mb8mOw8ySZQU4v9/6EnLBMxK0IeEB45N4DqBB4lrBMcrJMO6HOXXvMWxNNsX1pZ9WuMpXahomsBT6pPL6bkgNoak= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1562860486; 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=b3wqAyf70WZO+DQB1Pr5Vd6MBNzT52E7HPaQMI/PIfU=; b=ROuzyn/NMm8AQou8bqjX2kTamoCM9+Xy6KcXxkJ3DLcTgbXYDmsQihJSeTs8qxt+Q/E5aB090jqnyGwVzjFT1FthiXesuMy9936Jtk4JeFU0Hvon4Y3twW6fLjJF72H8RqDt9bgpKqyytF+VyXRoT+1wMOCeYY2PlDD+MZ+xGY0= 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 15628604864941015.1595370691829; Thu, 11 Jul 2019 08:54:46 -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 8BC8DC057F4B; Thu, 11 Jul 2019 15:54:44 +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 192BE5D9CC; Thu, 11 Jul 2019 15:54: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 D07EE1801215; Thu, 11 Jul 2019 15:54: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 x6BFsR4W014622 for ; Thu, 11 Jul 2019 11:54:27 -0400 Received: by smtp.corp.redhat.com (Postfix) id 62FB85D9DC; Thu, 11 Jul 2019 15:54:27 +0000 (UTC) Received: from moe.brq.redhat.com (unknown [10.43.2.30]) by smtp.corp.redhat.com (Postfix) with ESMTP id E2D135D9CC for ; Thu, 11 Jul 2019 15:54:26 +0000 (UTC) From: Michal Privoznik To: libvir-list@redhat.com Date: Thu, 11 Jul 2019 17:53:50 +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 v1 03/31] virpcimock: Move actions checking one level up 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, 11 Jul 2019 15:54:45 +0000 (UTC) Content-Type: text/plain; charset="utf-8" The pci_driver_bind() and pci_driver_unbind() functions are "internal implementation", meaning other parts of the code should be able to call them and get the job done. Checking for actions (PCI_ACTION_BIND and PCI_ACTION_UNBIND) should be done in handlers (pci_driver_handle_bind() and pci_driver_handle_unbind()). Surprisingly, the other two actions (PCI_ACTION_NEW_ID and PCI_ACTION_REMOVE_ID) are checked already at this level. Signed-off-by: Michal Privoznik --- tests/virpcimock.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/tests/virpcimock.c b/tests/virpcimock.c index beb5e1490d..6865f992dc 100644 --- a/tests/virpcimock.c +++ b/tests/virpcimock.c @@ -551,8 +551,8 @@ pci_driver_bind(struct pciDriver *driver, int ret =3D -1; char *devpath =3D NULL, *driverpath =3D NULL; =20 - if (dev->driver || PCI_ACTION_BIND & driver->fail) { - /* Device already bound or failing driver requested */ + if (dev->driver) { + /* Device already bound */ errno =3D ENODEV; return ret; } @@ -598,8 +598,8 @@ pci_driver_unbind(struct pciDriver *driver, int ret =3D -1; char *devpath =3D NULL, *driverpath =3D NULL; =20 - if (dev->driver !=3D driver || PCI_ACTION_UNBIND & driver->fail) { - /* Device not bound to the @driver or failing driver used */ + if (dev->driver !=3D driver) { + /* Device not bound to the @driver */ errno =3D ENODEV; return ret; } @@ -669,8 +669,8 @@ pci_driver_handle_bind(const char *path) struct pciDevice *dev =3D pci_device_find_by_content(path); struct pciDriver *driver =3D pci_driver_find_by_path(path); =20 - if (!driver || !dev) { - /* This should never happen (TM) */ + if (!driver || !dev || PCI_ACTION_BIND & driver->fail) { + /* No driver, no device or failing driver requested */ errno =3D ENODEV; goto cleanup; } @@ -686,8 +686,8 @@ pci_driver_handle_unbind(const char *path) int ret =3D -1; struct pciDevice *dev =3D pci_device_find_by_content(path); =20 - if (!dev || !dev->driver) { - /* This should never happen (TM) */ + if (!dev || !dev->driver || PCI_ACTION_UNBIND & dev->driver->fail) { + /* No device, device not binded or failing driver requested */ errno =3D ENODEV; goto cleanup; } --=20 2.21.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Fri Apr 19 16:08:06 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=1562860485; cv=none; d=zoho.com; s=zohoarc; b=BnflN+mkCCMnIdq/Rz4tOuiiBnCkL6pyKCQeshgxDf9gCehgVq4VuOi/E4boKf9MrzdInu+6IjKBJYFxDbOVuyjHPpXhvPK083wJAGUmENLJ6dicD7bEOiBC1qvWDzHm1T6JoG9b16EDq5Ui2V2iCk7S0rd0LnV6DAGzsk83OVQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1562860485; 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=DtGOODcpfoI8PKxiXpDce+pYcfiX6bTxG4IcEQzPJu0=; b=Q49frTLxyA989nXqKp2C+Rv6jn6nHftufnxueWLdKxfUem7IoWlEjyWBGbB1xtADaTF+GOgQGZV+tWM2Ej/zKpvojam1KBS95ACMS4GL40HyJ9SjcmZn4QigVS8ztsopLA6Mr0c+xKNpI0Bo7H3KX/bFkl83HjZYP1CRY0jUc3c= 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 1562860485230268.36953033604686; Thu, 11 Jul 2019 08:54:45 -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 87240307D861; Thu, 11 Jul 2019 15:54: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 59A3C6014E; Thu, 11 Jul 2019 15:54: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 1B61018184B7; Thu, 11 Jul 2019 15:54: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 x6BFsS9p014630 for ; Thu, 11 Jul 2019 11:54:28 -0400 Received: by smtp.corp.redhat.com (Postfix) id 2EB865D9DC; Thu, 11 Jul 2019 15:54:28 +0000 (UTC) Received: from moe.brq.redhat.com (unknown [10.43.2.30]) by smtp.corp.redhat.com (Postfix) with ESMTP id AF32E5D9CC for ; Thu, 11 Jul 2019 15:54:27 +0000 (UTC) From: Michal Privoznik To: libvir-list@redhat.com Date: Thu, 11 Jul 2019 17:53:51 +0200 Message-Id: <48cb8d5771288a152366718b749e230c1e983b9f.1562859733.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 v1 04/31] Revert "virpcitest: Test virPCIDeviceDetach failure" 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.48]); Thu, 11 Jul 2019 15:54:44 +0000 (UTC) Content-Type: text/plain; charset="utf-8" This reverts commit b70c093ffa00cd87c8d39d3652b798f033a81faf. In next commit the virpcimock is going to be extended and thus binding a PCI device to vfio-pci driver will finally succeed. Remove this test as it will no longer make sense. Signed-off-by: Michal Privoznik --- tests/virpcitest.c | 32 -------------------------------- 1 file changed, 32 deletions(-) diff --git a/tests/virpcitest.c b/tests/virpcitest.c index 961a7eff1a..9ecd1b7d27 100644 --- a/tests/virpcitest.c +++ b/tests/virpcitest.c @@ -256,36 +256,6 @@ testVirPCIDeviceDetachSingle(const void *opaque) return ret; } =20 -static int -testVirPCIDeviceDetachFail(const void *opaque) -{ - const struct testPCIDevData *data =3D opaque; - int ret =3D -1; - virPCIDevicePtr dev; - - dev =3D virPCIDeviceNew(data->domain, data->bus, data->slot, data->fun= ction); - if (!dev) - goto cleanup; - - virPCIDeviceSetStubDriver(dev, VIR_PCI_STUB_DRIVER_VFIO); - - if (virPCIDeviceDetach(dev, NULL, NULL) < 0) { - if (virTestGetVerbose() || virTestGetDebug()) - virDispatchError(NULL); - virResetLastError(); - ret =3D 0; - } else { - virReportError(VIR_ERR_INTERNAL_ERROR, - "Attaching device %s to %s should have failed", - virPCIDeviceGetName(dev), - virPCIStubDriverTypeToString(VIR_PCI_STUB_DRIVER_VF= IO)); - } - - cleanup: - virPCIDeviceFree(dev); - return ret; -} - static int testVirPCIDeviceReattachSingle(const void *opaque) { @@ -421,8 +391,6 @@ mymain(void) DO_TEST_PCI(testVirPCIDeviceIsAssignable, 5, 0x90, 1, 0); DO_TEST_PCI(testVirPCIDeviceIsAssignable, 1, 1, 0, 0); =20 - DO_TEST_PCI(testVirPCIDeviceDetachFail, 0, 0x0a, 1, 0); - /* Reattach a device already bound to non-stub a driver */ DO_TEST_PCI_DRIVER(0, 0x0a, 1, 0, "i915"); DO_TEST_PCI(testVirPCIDeviceReattachSingle, 0, 0x0a, 1, 0); --=20 2.21.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Fri Apr 19 16:08:06 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=1562860488; cv=none; d=zoho.com; s=zohoarc; b=czdpTbB6v7LSg+Rfj2sqP2k2tJiI0GlaCgQ9+fk7b6wBc0rp6FfK4ZTaM32JboS8wvKK8L0wpV6VRat4pxlXtAzEYJ94z2aRBZFwMb/Bl9kBpFuXdE8ftxLUDHY7eqyhheJM2tcplsUza4pCQq43KnSHTlJFYzTKUXw6uFz2NGc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1562860488; 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=5wCOG0HDL813EN7k7g+4xF7PERg9DziQhQYli83ioMs=; b=MImkSb4iYz/C2fAVKfWJ8b+bvLv4bLpmJNqsXzOKqyUEnJ2UusVa2U9AaFmGIGhfnp22JkokaY5KmB2aTNjjunq6z+BQ40aoyXuSd5WBv/JSzVySrd/WU0hl+LkIFbxAsQuKi2h2ObdCB+A1spl4ddA48DMjXN0koB4TRMvYKRA= 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 1562860488829972.1521533558903; Thu, 11 Jul 2019 08:54:48 -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 1677C309B143; Thu, 11 Jul 2019 15:54:47 +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 E5A2D60148; Thu, 11 Jul 2019 15:54:46 +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 A58D9206D4; Thu, 11 Jul 2019 15:54:46 +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 x6BFsSdi014642 for ; Thu, 11 Jul 2019 11:54:29 -0400 Received: by smtp.corp.redhat.com (Postfix) id EDE195D9CC; Thu, 11 Jul 2019 15:54:28 +0000 (UTC) Received: from moe.brq.redhat.com (unknown [10.43.2.30]) by smtp.corp.redhat.com (Postfix) with ESMTP id 7A1C95D9DC for ; Thu, 11 Jul 2019 15:54:28 +0000 (UTC) From: Michal Privoznik To: libvir-list@redhat.com Date: Thu, 11 Jul 2019 17:53:52 +0200 Message-Id: <883546a6872fb3afc83ea184d901bdb274b1000f.1562859733.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 v1 05/31] virpcimock: Create driver_override file in device dirs 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.49]); Thu, 11 Jul 2019 15:54:47 +0000 (UTC) Content-Type: text/plain; charset="utf-8" Newer kernels (v3.16-rc1~29^2~6^4) have 'driver_override' file which simplifies way of binding a PCI device to desired driver. Libvirt has support for this for some time too (v2.3.0-rc1~236), but not our virpcimock. So far we did not care because our code is designed to deal with this situation. Except for one. hypothetical case: binding a device to the vfio-pci driver can be successful only via driver_override. Any attempt to bind a PCI device to vfio-pci driver using old method (new_id + unbind + bind) will fail because of b803b29c1a5. While on vanilla kernel I'm able to use the old method successfully, it's failing on RHEL kernels (not sure why). Signed-off-by: Michal Privoznik --- tests/virpcimock.c | 57 +++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 51 insertions(+), 6 deletions(-) diff --git a/tests/virpcimock.c b/tests/virpcimock.c index 6865f992dc..18d06d11d4 100644 --- a/tests/virpcimock.c +++ b/tests/virpcimock.c @@ -87,6 +87,11 @@ char *fakesysfspcidir; * Probe for a driver that handles the specified device. * Data in format "DDDD:BB:DD.F" (Domain:Bus:Device.Function). * + * /sys/bus/pci/devices//driver_override + * Name of a driver that overrides preferred driver can be written + * here. The device will be attached to it on drivers_probe event. + * Writing an empty string (or "\n") clears the override. + * * As a little hack, we are not mocking write to these files, but close() * instead. The advantage is we don't need any self growing array to hold = the * partial writes and construct them back. We can let all the writes finis= h, @@ -147,6 +152,7 @@ static struct pciDevice *pci_device_find_by_content(con= st char *path); static void pci_driver_new(const char *name, int fail, ...); static struct pciDriver *pci_driver_find_by_dev(struct pciDevice *dev); static struct pciDriver *pci_driver_find_by_path(const char *path); +static struct pciDriver *pci_driver_find_by_driver_override(struct pciDevi= ce *dev); static int pci_driver_bind(struct pciDriver *driver, struct pciDevice *dev= ); static int pci_driver_unbind(struct pciDriver *driver, struct pciDevice *d= ev); static int pci_driver_handle_change(int fd, const char *path); @@ -202,7 +208,8 @@ make_symlink(const char *path, static int pci_read_file(const char *path, char *buf, - size_t buf_size) + size_t buf_size, + bool truncate) { int ret =3D -1; int fd =3D -1; @@ -224,7 +231,8 @@ pci_read_file(const char *path, goto cleanup; } =20 - if (ftruncate(fd, 0) < 0) + if (truncate && + ftruncate(fd, 0) < 0) goto cleanup; =20 ret =3D 0; @@ -398,6 +406,8 @@ pci_device_new_from_stub(const struct pciDevice *data) ABORT("@tmp overflow"); make_file(devpath, "class", tmp, -1); =20 + make_file(devpath, "driver_override", NULL, -1); + if (snprintf(tmp, sizeof(tmp), "%s/../../../kernel/iommu_groups/%d", devpath, dev->iommuGroup) < 0) { @@ -441,7 +451,7 @@ pci_device_find_by_content(const char *path) { char tmp[32]; =20 - if (pci_read_file(path, tmp, sizeof(tmp)) < 0) + if (pci_read_file(path, tmp, sizeof(tmp), true) < 0) return NULL; =20 return pci_device_find_by_id(tmp); @@ -450,7 +460,10 @@ pci_device_find_by_content(const char *path) static int pci_device_autobind(struct pciDevice *dev) { - struct pciDriver *driver =3D pci_driver_find_by_dev(dev); + struct pciDriver *driver =3D pci_driver_find_by_driver_override(dev); + + if (!driver) + driver =3D pci_driver_find_by_dev(dev); =20 if (!driver) { /* No driver found. Nothing to do */ @@ -544,6 +557,36 @@ pci_driver_find_by_path(const char *path) return NULL; } =20 +static struct pciDriver * +pci_driver_find_by_driver_override(struct pciDevice *dev) +{ + struct pciDriver *ret =3D NULL; + char *path =3D NULL; + char tmp[32]; + size_t i; + + if (virAsprintfQuiet(&path, + SYSFS_PCI_PREFIX "devices/%s/driver_override", + dev->id) < 0) + return NULL; + + if (pci_read_file(path, tmp, sizeof(tmp), false) < 0) + goto cleanup; + + for (i =3D 0; i < nPCIDrivers; i++) { + struct pciDriver *driver =3D pciDrivers[i]; + + if (STREQ(tmp, driver->name)) { + ret =3D driver; + break; + } + } + + cleanup: + VIR_FREE(path); + return ret; +} + static int pci_driver_bind(struct pciDriver *driver, struct pciDevice *dev) @@ -657,6 +700,8 @@ pci_driver_handle_change(int fd ATTRIBUTE_UNUSED, const= char *path) ret =3D pci_driver_handle_remove_id(path); else if (STREQ(file, "drivers_probe")) ret =3D pci_driver_handle_drivers_probe(path); + else if (STREQ(file, "driver_override")) + ret =3D 0; /* nada */ else ABORT("Not handled write to: %s", path); return ret; @@ -711,7 +756,7 @@ pci_driver_handle_new_id(const char *path) goto cleanup; } =20 - if (pci_read_file(path, buf, sizeof(buf)) < 0) + if (pci_read_file(path, buf, sizeof(buf), true) < 0) goto cleanup; =20 if (sscanf(buf, "%x %x", &vendor, &device) < 2) { @@ -766,7 +811,7 @@ pci_driver_handle_remove_id(const char *path) goto cleanup; } =20 - if (pci_read_file(path, buf, sizeof(buf)) < 0) + if (pci_read_file(path, buf, sizeof(buf), true) < 0) goto cleanup; =20 if (sscanf(buf, "%x %x", &vendor, &device) < 2) { --=20 2.21.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Fri Apr 19 16:08:06 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=1562860489; cv=none; d=zoho.com; s=zohoarc; b=NrByNcJOYYO/RX/8Wf1d+EeKmYQ8DGMRf9+buhtCM11ocuhJy83YL+By/WZbEjdR/0mVXvaidjp0C+WMCP6KZceWqvUMtnW6A0cf+DxKzAGvzp42skaefZwJuZe9UHsENGtLqV7KapZVnN3xOJqyT6GAbYOrvsIA7rTPX4d44nE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1562860489; 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=2LhmpGwIs2USrecHmAjTEwuiReVJynQE8LVucsvPL+M=; b=mBgxReQ1e0G3WiGpTmhwE1yg/pZO1Xale8vGRvJ9+Ehi5pF4Ynb67clUtpXH+ZE1/YKU1zXIJC5n+BvpiufORZP7/HMmFvQefEIoo2/wSR9GgornpFlSq/zfHKhjsInGyrk+S8PCb8D+qkro1hsj+V4BhffIdL27OGhcIAIJupA= 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 1562860489338186.1345946518917; Thu, 11 Jul 2019 08:54:49 -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 C5643C05B1CD; Thu, 11 Jul 2019 15:54:47 +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 99C4D60605; Thu, 11 Jul 2019 15:54:47 +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 567F01832FC6; Thu, 11 Jul 2019 15:54:47 +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 x6BFsTU9014647 for ; Thu, 11 Jul 2019 11:54:29 -0400 Received: by smtp.corp.redhat.com (Postfix) id B920B5D973; Thu, 11 Jul 2019 15:54:29 +0000 (UTC) Received: from moe.brq.redhat.com (unknown [10.43.2.30]) by smtp.corp.redhat.com (Postfix) with ESMTP id 452D15D9DC for ; Thu, 11 Jul 2019 15:54:29 +0000 (UTC) From: Michal Privoznik To: libvir-list@redhat.com Date: Thu, 11 Jul 2019 17:53:53 +0200 Message-Id: <6fdea280f33230ff485a7f2f91167d2ba21573f1.1562859733.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 v1 06/31] virPCIDeviceAddressEqual: Fix const correctness 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.32]); Thu, 11 Jul 2019 15:54:48 +0000 (UTC) Content-Type: text/plain; charset="utf-8" This function does not change any of the passed addresses. It just reads them. Signed-off-by: Michal Privoznik --- src/util/virpci.c | 4 ++-- src/util/virpci.h | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/util/virpci.c b/src/util/virpci.c index 75e8daadd5..5392d62406 100644 --- a/src/util/virpci.c +++ b/src/util/virpci.c @@ -1718,8 +1718,8 @@ virPCIDeviceAddressIsEmpty(const virPCIDeviceAddress = *addr) } =20 bool -virPCIDeviceAddressEqual(virPCIDeviceAddress *addr1, - virPCIDeviceAddress *addr2) +virPCIDeviceAddressEqual(const virPCIDeviceAddress *addr1, + const virPCIDeviceAddress *addr2) { if (addr1->domain =3D=3D addr2->domain && addr1->bus =3D=3D addr2->bus && diff --git a/src/util/virpci.h b/src/util/virpci.h index 457be3c929..a940608701 100644 --- a/src/util/virpci.h +++ b/src/util/virpci.h @@ -231,8 +231,8 @@ bool virPCIDeviceAddressIsValid(virPCIDeviceAddressPtr = addr, bool report); bool virPCIDeviceAddressIsEmpty(const virPCIDeviceAddress *addr); =20 -bool virPCIDeviceAddressEqual(virPCIDeviceAddress *addr1, - virPCIDeviceAddress *addr2); +bool virPCIDeviceAddressEqual(const virPCIDeviceAddress *addr1, + const virPCIDeviceAddress *addr2); =20 char *virPCIDeviceAddressAsString(virPCIDeviceAddressPtr 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 Fri Apr 19 16:08:06 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=1562860493; cv=none; d=zoho.com; s=zohoarc; b=IZLJlyXN38W1ipfu2O703cnDhudACLshOaatNPP4wkOxn9a6bEebBXgKNN5UCrx/at26lKRxjCTe02hJ4/bmuxe9m0k9paQvQx6nYwdesdDtH7UHN3DHEBU9xyL5X/c7Fvots0T3Mr0V6C78zfehXRkvNJySoV3mxMHuHdyiVYc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1562860493; 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=PmOUH3RBMI0UBAA06sDOK8u2kMq3uUvS6SEGIcLONOs=; b=V86GV9o5gkuakuq1UA63X1BAXgSBF+vnApfGskujIUolLC1/UuUk53SRHRjOuAoPpQNyJyiEUsLLQnxUWTqPlif0bE9hbb2xD6bdlr/uWBtI+Ah4STdwfqrrHwGxWUBs/N0utXJ2J3vqOdwRfDMVkgFVGhSrkxnNLf1fY3xgurQ= 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 1562860493442770.6034014274087; Thu, 11 Jul 2019 08:54:53 -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 56F14C04BD48; Thu, 11 Jul 2019 15:54:51 +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 2945E5D784; Thu, 11 Jul 2019 15:54: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 CBC4C1833007; Thu, 11 Jul 2019 15:54:50 +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 x6BFsUtE014660 for ; Thu, 11 Jul 2019 11:54:30 -0400 Received: by smtp.corp.redhat.com (Postfix) id 8522E5D973; Thu, 11 Jul 2019 15:54:30 +0000 (UTC) Received: from moe.brq.redhat.com (unknown [10.43.2.30]) by smtp.corp.redhat.com (Postfix) with ESMTP id 10C935D9DC for ; Thu, 11 Jul 2019 15:54:29 +0000 (UTC) From: Michal Privoznik To: libvir-list@redhat.com Date: Thu, 11 Jul 2019 17:53:54 +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 v1 07/31] virPCIDeviceAddressAsString: Fix const correctness 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.31]); Thu, 11 Jul 2019 15:54:52 +0000 (UTC) Content-Type: text/plain; charset="utf-8" This function does not change any of the passed addresses. It just reads them. Signed-off-by: Michal Privoznik --- src/util/virpci.c | 2 +- src/util/virpci.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/util/virpci.c b/src/util/virpci.c index 5392d62406..59f478dd41 100644 --- a/src/util/virpci.c +++ b/src/util/virpci.c @@ -1731,7 +1731,7 @@ virPCIDeviceAddressEqual(const virPCIDeviceAddress *a= ddr1, } =20 char * -virPCIDeviceAddressAsString(virPCIDeviceAddressPtr addr) +virPCIDeviceAddressAsString(const virPCIDeviceAddress *addr) { char *str; =20 diff --git a/src/util/virpci.h b/src/util/virpci.h index a940608701..1efd8b77ed 100644 --- a/src/util/virpci.h +++ b/src/util/virpci.h @@ -234,7 +234,7 @@ bool virPCIDeviceAddressIsEmpty(const virPCIDeviceAddre= ss *addr); bool virPCIDeviceAddressEqual(const virPCIDeviceAddress *addr1, const virPCIDeviceAddress *addr2); =20 -char *virPCIDeviceAddressAsString(virPCIDeviceAddressPtr addr) +char *virPCIDeviceAddressAsString(const virPCIDeviceAddress *addr) ATTRIBUTE_NONNULL(1); =20 int virPCIDeviceAddressParse(char *address, virPCIDeviceAddressPtr bdf); --=20 2.21.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Fri Apr 19 16:08:06 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=1562860492; cv=none; d=zoho.com; s=zohoarc; b=EOG8v5Yr7E0BHD0UQzvbFwlc3PH5Lzqcdd5WvxIiY5IbVG1TfA+LrsEyW/oZIzg/OPzgW+AMKDSNBva9I/sj57CdcEf1OmzsAYjZjZm0iJBjpU8dkC9sW6nDUAI2uBBPCkwqeNBO4M/E/9QQW2AmbPBA35yaKdwmAJeNPcivNZ8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1562860492; 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=E56242hW65uSRN1unhOj8NrEK0N4GN6IOuVSpzBeOLw=; b=FTZ9VvCdhy2dlTUm6xAX6Z9N0EYulfF73XUYHQ6w+FvAvVQrbqoeev8tT4VvuZyG5rwJuu+WrbZKmAauiGUuTnm8ZuKVwWNGqEvOfQ7s0fQ2jHdb/XVw3pMWv90mva3WheOGDeeJdAZQZskzImYu3+88q4TrWwJEaw21crHAB4Q= 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 1562860492308769.8400013958524; Thu, 11 Jul 2019 08:54:52 -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 82096309264D; Thu, 11 Jul 2019 15:54:50 +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 564F660A97; Thu, 11 Jul 2019 15:54:50 +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 0D8421833003; Thu, 11 Jul 2019 15:54:50 +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 x6BFsVFx014667 for ; Thu, 11 Jul 2019 11:54:31 -0400 Received: by smtp.corp.redhat.com (Postfix) id 514275D9DC; Thu, 11 Jul 2019 15:54:31 +0000 (UTC) Received: from moe.brq.redhat.com (unknown [10.43.2.30]) by smtp.corp.redhat.com (Postfix) with ESMTP id D05854F9B6 for ; Thu, 11 Jul 2019 15:54:30 +0000 (UTC) From: Michal Privoznik To: libvir-list@redhat.com Date: Thu, 11 Jul 2019 17:53:55 +0200 Message-Id: <3415f4aa393ba268d00b811f5f6fb95c307fc8bb.1562859733.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 v1 08/31] 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.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.43]); Thu, 11 Jul 2019 15:54:51 +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 --- src/libvirt_private.syms | 1 + src/util/virpci.c | 6 ++++++ src/util/virpci.h | 2 ++ 3 files changed, 9 insertions(+) diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index 02d5b7acce..6cef8d20fe 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -2612,6 +2612,7 @@ virObjectUnref; =20 # util/virpci.h virPCIDeviceAddressAsString; +virPCIDeviceAddressCopy; virPCIDeviceAddressEqual; virPCIDeviceAddressGetIOMMUGroupAddresses; virPCIDeviceAddressGetIOMMUGroupNum; diff --git a/src/util/virpci.c b/src/util/virpci.c index 59f478dd41..03ce651f40 100644 --- a/src/util/virpci.c +++ b/src/util/virpci.c @@ -1730,6 +1730,12 @@ virPCIDeviceAddressEqual(const virPCIDeviceAddress *= addr1, return false; } =20 +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 1efd8b77ed..72e90a1ef3 100644 --- a/src/util/virpci.h +++ b/src/util/virpci.h @@ -233,6 +233,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 Fri Apr 19 16:08:06 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=1562860495; cv=none; d=zoho.com; s=zohoarc; b=SSBsp7n3sm19lKLUMeZnb/z8/fxhJbdSgFVQYV91n2uUHB6sQhYDGBH9L8wYM1BpngjvDS+ww1RekHOCUoFrYqANfVKqCYq15yAxyIxAYk0snps7Pp3RChc0tcWfn0ccESmLcpr5KsLWBbFXaZMwccx34OYRXFAgAJKBBmm1/pY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1562860495; 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=/Wj7U27gP0o6642EvbVYN93X8vQjNcw88AN7KRbRMJk=; b=hm+N9v3QC0zUegD10kmMG2G8LD4mSGu95hKgYNCTdBsEUN4mk9jaPhaOtTDG0jR3yqa6+YEgNaM+tS4QrTOGHz+KsC0u+F1pI6A2epzW6CurSSHuwvxjsIZPL+IPkg/O1jQiHRBz2jsomtoMbnX6Bie1RbQS43oOgPdw/XAgNNs= 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 1562860495683171.64346558291697; Thu, 11 Jul 2019 08:54: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 006A959474; Thu, 11 Jul 2019 15:54: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 D0CCC5B683; Thu, 11 Jul 2019 15:54: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 98B94206DA; Thu, 11 Jul 2019 15:54: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 x6BFsWgC014675 for ; Thu, 11 Jul 2019 11:54:32 -0400 Received: by smtp.corp.redhat.com (Postfix) id 1D5295D9CC; Thu, 11 Jul 2019 15:54:32 +0000 (UTC) Received: from moe.brq.redhat.com (unknown [10.43.2.30]) by smtp.corp.redhat.com (Postfix) with ESMTP id 9D09B5D9DC for ; Thu, 11 Jul 2019 15:54:31 +0000 (UTC) From: Michal Privoznik To: libvir-list@redhat.com Date: Thu, 11 Jul 2019 17:53:56 +0200 Message-Id: <9cca51701e895305ebc68de3da90a158767bbae6.1562859733.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 v1 09/31] qemuDomainDeviceDefValidateDisk: Reorder some checks 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.39]); Thu, 11 Jul 2019 15:54:54 +0000 (UTC) Content-Type: text/plain; charset="utf-8" I find this function more readable if checks for passed storage source are done first and backing chain is done last. Mixing them together does not hurt, but is less readable. Signed-off-by: Michal Privoznik --- src/qemu/qemu_domain.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c index 0f1fda2384..f09abc8a73 100644 --- a/src/qemu/qemu_domain.c +++ b/src/qemu/qemu_domain.c @@ -5178,11 +5178,6 @@ qemuDomainDeviceDefValidateDisk(const virDomainDiskD= ef *disk, return -1; } =20 - for (n =3D disk->src; virStorageSourceIsBacking(n); n =3D n->backingSt= ore) { - if (qemuDomainValidateStorageSource(n, qemuCaps) < 0) - return -1; - } - if (disk->device =3D=3D VIR_DOMAIN_DISK_DEVICE_CDROM && disk->bus =3D=3D VIR_DOMAIN_DISK_BUS_VIRTIO) { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, @@ -5191,6 +5186,11 @@ qemuDomainDeviceDefValidateDisk(const virDomainDiskD= ef *disk, return -1; } =20 + for (n =3D disk->src; virStorageSourceIsBacking(n); n =3D n->backingSt= ore) { + if (qemuDomainValidateStorageSource(n, qemuCaps) < 0) + return -1; + } + return 0; } =20 --=20 2.21.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Fri Apr 19 16:08:06 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=1562860488; cv=none; d=zoho.com; s=zohoarc; b=CQtRN4YghMezW8m7+k27D27/gCNHrlQNG1t04Ly+C2ux320PHv5r40/bOZYmqmGch33qOC7DFBRRwwNjJ46Ilsbot5qozPxPgCXYvT8640Y/JU+SON8KlRaD8tsiCcNlBOefxqiwmh6fAuqBpOgQWDTiXb+inHKthb7YPL8I6+E= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1562860488; 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=n/qSGTif9/6TiHXTKYJFm0e+DacknCdDyguGfSNc5vw=; b=b7F5hCvNebRIo7vGBlypEsDmtG9n4m1X85IGhUGhQgLGQvllubzn51oP+YF12yjbBXjPtqRn8IrdQmvJki5CDvR0nNVLLsX4k3ZH5OMAgKGwkzD0WYOuh6T8B1VfTag0di6iv0Teddd8FzTstWckCmvRvYm7xzr+tascH+CxB1o= 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 1562860488320356.04480535189305; Thu, 11 Jul 2019 08:54:48 -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 98B16C024906; Thu, 11 Jul 2019 15:54:46 +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 7119460C47; Thu, 11 Jul 2019 15:54:46 +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 2F778206D1; Thu, 11 Jul 2019 15:54:46 +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 x6BFsZbv014698 for ; Thu, 11 Jul 2019 11:54:35 -0400 Received: by smtp.corp.redhat.com (Postfix) id 1A23C5D9DC; Thu, 11 Jul 2019 15:54:35 +0000 (UTC) Received: from moe.brq.redhat.com (unknown [10.43.2.30]) by smtp.corp.redhat.com (Postfix) with ESMTP id 99A415D973 for ; Thu, 11 Jul 2019 15:54:32 +0000 (UTC) From: Michal Privoznik To: libvir-list@redhat.com Date: Thu, 11 Jul 2019 17:53:57 +0200 Message-Id: <17aad25e7827405ec0d33a2fd030683c4249ef30.1562859733.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 v1 10/31] 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.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.32]); Thu, 11 Jul 2019 15:54:47 +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 | 45 +++++++++++++++++++++-- docs/schemas/domaincommon.rng | 32 ++++++++++++++++ tests/qemuxml2argvdata/disk-nvme.xml | 55 ++++++++++++++++++++++++++++ 3 files changed, 129 insertions(+), 3 deletions(-) create mode 100644 tests/qemuxml2argvdata/disk-nvme.xml diff --git a/docs/formatdomain.html.in b/docs/formatdomain.html.in index a7a6ec32a5..545578076d 100644 --- a/docs/formatdomain.html.in +++ b/docs/formatdomain.html.in @@ -2922,6 +2922,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 @@ -2935,7 +2942,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.5.0) and refer to the underlying source for the disk. Since 0.0.3 @@ -3118,6 +3126,31 @@ 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. +
+
+
With "file", "block", and "volume", one or more optional sub-elements seclabel, described @@ -3280,11 +3313,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.5.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", "volume" or "nvme" disk type which represents a cdro= m 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 31db599ab9..f367e8f6fd 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..0b3dbad4eb --- /dev/null +++ b/tests/qemuxml2argvdata/disk-nvme.xml @@ -0,0 +1,55 @@ + + 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 Fri Apr 19 16:08:06 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=1562860491; cv=none; d=zoho.com; s=zohoarc; b=bZ7JCyKPNiMSKS2DWJ5WMVnecJkf/+KW0DpbhGzj26bNhH8k6TwOiUL4e2jto+ibDhlQessNJeFBGB2SG6N8NUUhoGX7bYugKaO0JKRB0y0ny0Ensx0qrCVYvc4kVpgv9evALUEkZUHkr5lBHE/KQikU2FzWgqrKg+oKcdYxUic= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1562860491; 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=bLBfcbdt6aRNsYtZ48IpVCFOn6oanQgg9Kl0w/4GGJo=; b=c9uO336Iv4PtBqPD3bIcJMwYUIx3UmaLZfUkOtJLSHYDNiB/lO5W2LPo7g/dmGmiuptw+qQaGbE3Gb/s/bq3/QK7qmQrw3fZ51NO7mPEmHxcvlcp/v8Vv65Ucs7moyviYbAyUvCj9QO+/oQCNYl1Hzgco3vyDw+OmJPBDLtHKyk= 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 1562860491653584.0722785137572; Thu, 11 Jul 2019 08:54:51 -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 F1D184E90E; Thu, 11 Jul 2019 15:54:49 +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 C96B75D9CC; Thu, 11 Jul 2019 15:54:49 +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 801A1206D9; Thu, 11 Jul 2019 15:54:49 +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 x6BFsapr014707 for ; Thu, 11 Jul 2019 11:54:36 -0400 Received: by smtp.corp.redhat.com (Postfix) id 0A9035D973; Thu, 11 Jul 2019 15:54:36 +0000 (UTC) Received: from moe.brq.redhat.com (unknown [10.43.2.30]) by smtp.corp.redhat.com (Postfix) with ESMTP id 652915D9DC for ; Thu, 11 Jul 2019 15:54:35 +0000 (UTC) From: Michal Privoznik To: libvir-list@redhat.com Date: Thu, 11 Jul 2019 17:53:58 +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 v1 11/31] 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.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.38]); Thu, 11 Jul 2019 15:54:50 +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 | 129 +++++++++++++++++++++++++ src/libvirt_private.syms | 1 + src/qemu/qemu_block.c | 1 + src/qemu/qemu_command.c | 1 + src/qemu/qemu_driver.c | 4 + src/qemu/qemu_migration.c | 1 + src/util/virstoragefile.c | 59 +++++++++++ src/util/virstoragefile.h | 15 +++ src/xenconfig/xen_xl.c | 1 + tests/qemuxml2argvdata/disk-nvme.xml | 12 ++- tests/qemuxml2xmloutdata/disk-nvme.xml | 1 + tests/qemuxml2xmltest.c | 1 + 12 files changed, 224 insertions(+), 2 deletions(-) create mode 120000 tests/qemuxml2xmloutdata/disk-nvme.xml diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 3323c9a5b1..73f5e1fa0f 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -5088,6 +5088,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; @@ -5938,6 +5943,38 @@ virDomainDiskDefValidate(const virDomainDiskDef *dis= k) return -1; } =20 + if (disk->src->type =3D=3D VIR_STORAGE_TYPE_NVME) { + /* These might not be valid for all hypervisors, but be + * strict now and possibly refine in the future. */ + if (disk->device !=3D VIR_DOMAIN_DISK_DEVICE_DISK) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, + _("Unsupported disk type '%s' for NVMe disk"), + virDomainDiskDeviceTypeToString(disk->device)); + return -1; + } + + if (disk->bus !=3D VIR_DOMAIN_DISK_BUS_VIRTIO) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, + _("Unsupported bus '%s' for NVMe disk"), + virDomainDiskBusTypeToString(disk->bus)); + return -1; + } + + if (disk->startupPolicy !=3D VIR_DOMAIN_STARTUP_POLICY_DEFAULT && + disk->startupPolicy !=3D VIR_DOMAIN_STARTUP_POLICY_MANDATORY) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, + _("Unsupported startup policy '%s' for NVMe dis= k"), + virDomainStartupPolicyTypeToString(disk->startu= pPolicy)); + return -1; + } + + if (disk->src->shared) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", + _("Unsupported for NVMe disk")); + return -1; + } + } + return 0; } =20 @@ -9184,6 +9221,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_ul(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, @@ -9284,6 +9391,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, @@ -23922,6 +24033,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'%ld'", nvme->namespace); + virPCIDeviceAddressFormat(childBuf, nvme->pciAddr, false); +} + + static int virDomainDiskSourceFormatPrivateData(virBufferPtr buf, virStorageSourcePtr src, @@ -24008,6 +24132,11 @@ virDomainDiskSourceFormat(virBufferPtr buf, =20 break; =20 + case VIR_STORAGE_TYPE_NVME: + if (src->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 6cef8d20fe..350b638193 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -2994,6 +2994,7 @@ virStorageSourceNetworkAssignDefaultPorts; virStorageSourceNew; virStorageSourceNewFromBacking; virStorageSourceNewFromBackingAbsolute; +virStorageSourceNVMeDefFree; virStorageSourceParseRBDColonString; virStorageSourcePoolDefFree; virStorageSourcePoolModeTypeFromString; diff --git a/src/qemu/qemu_block.c b/src/qemu/qemu_block.c index 0a6522577d..5eeb3757f1 100644 --- a/src/qemu/qemu_block.c +++ b/src/qemu/qemu_block.c @@ -1050,6 +1050,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; diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c index 688dc324c6..927641cf46 100644 --- a/src/qemu/qemu_command.c +++ b/src/qemu/qemu_command.c @@ -1184,6 +1184,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 a52b54b9d8..9bf12ea20d 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -14637,6 +14637,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, @@ -14653,6 +14654,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, @@ -14715,6 +14717,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, @@ -14837,6 +14840,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 2436f5051b..87adccab3d 100644 --- a/src/qemu/qemu_migration.c +++ b/src/qemu/qemu_migration.c @@ -227,6 +227,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, diff --git a/src/util/virstoragefile.c b/src/util/virstoragefile.c index 269d0050fd..18aa33fe05 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, @@ -2114,6 +2115,48 @@ 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 =3D *src; + 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) @@ -2323,6 +2366,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 @@ -2376,6 +2423,10 @@ virStorageSourceIsSameLocation(virStorageSourcePtr a, } } =20 + if (a->type =3D=3D VIR_STORAGE_TYPE_NVME && + !virStorageSourceNVMeDefIsEqual(a->nvme, b->nvme)) + return false; + return true; } =20 @@ -2463,6 +2514,7 @@ virStorageSourceIsLocalStorage(const virStorageSource= *src) =20 case VIR_STORAGE_TYPE_NETWORK: case VIR_STORAGE_TYPE_VOLUME: + case VIR_STORAGE_TYPE_NVME: case VIR_STORAGE_TYPE_LAST: case VIR_STORAGE_TYPE_NONE: return false; @@ -2493,6 +2545,10 @@ virStorageSourceIsEmpty(virStorageSourcePtr src) src->protocol =3D=3D VIR_STORAGE_NET_PROTOCOL_NONE) return true; =20 + if (src->type =3D=3D VIR_STORAGE_TYPE_NVME && + !src->nvme) + return true; + return false; } =20 @@ -2548,6 +2604,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); @@ -3776,6 +3833,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: virReportError(VIR_ERR_INTERNAL_ERROR, @@ -4242,6 +4300,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 38ba901858..a1294ea608 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,14 @@ struct _virStorageSourceInitiatorDef { char *iqn; /* Initiator IQN */ }; =20 +typedef struct _virStorageSourceNVMeDef virStorageSourceNVMeDef; +typedef virStorageSourceNVMeDef *virStorageSourceNVMeDefPtr; +struct _virStorageSourceNVMeDef { + unsigned long namespace; + int managed; /* enum virTristateBool */ + virPCIDeviceAddress pciAddr; +}; + typedef struct _virStorageDriverData virStorageDriverData; typedef virStorageDriverData *virStorageDriverDataPtr; =20 @@ -262,6 +272,8 @@ struct _virStorageSource { bool encryptionInherited; virStoragePRDefPtr pr; =20 + virStorageSourceNVMeDefPtr nvme; /* type =3D=3D VIR_STORAGE_TYPE_NVME = */ + virStorageSourceInitiatorDef initiator; =20 virObjectPtr privateData; @@ -416,6 +428,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/src/xenconfig/xen_xl.c b/src/xenconfig/xen_xl.c index ca094d30c2..fa15e4e2a5 100644 --- a/src/xenconfig/xen_xl.c +++ b/src/xenconfig/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/tests/qemuxml2argvdata/disk-nvme.xml b/tests/qemuxml2argvdata/= disk-nvme.xml index 0b3dbad4eb..fe956d5ab6 100644 --- a/tests/qemuxml2argvdata/disk-nvme.xml +++ b/tests/qemuxml2argvdata/disk-nvme.xml @@ -20,6 +20,7 @@
+
@@ -27,6 +28,7 @@
+
@@ -34,6 +36,7 @@
+
@@ -44,10 +47,15 @@ +
- + +
+ - + +
+ 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 6d808e172f..c9f3a8dbfa 100644 --- a/tests/qemuxml2xmltest.c +++ b/tests/qemuxml2xmltest.c @@ -336,6 +336,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); 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 Fri Apr 19 16:08:06 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=1562860499; cv=none; d=zoho.com; s=zohoarc; b=NobnO95joDXwrqvbO9enm2l334pYY2M8n0zRxBgpFP16o2AgxU5wRVzEbFx0abKjcTviMDFsLVFclfTfJbi28yDS+bFpn8SNZm8bQmmLm0Y499Q9VAvK/ZWtxAkjJlh2KcNzAp6F9jd6t8L/jqpqiVqmVZ5c3ylm7E2PR7NEkws= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1562860499; 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=ELgSw6NoLzoPE9bRe+z5WhHT4+7bGzwKKqUyUenjMKI=; b=HhAWu7WptJOiJZxvskuDFH7CxVy7bJ3v5NQuHqScCeQVCa/e/oaKbskkDGJqQe11OjNqVl9rRW8XDvZvX9RGpElqTC60Kcaw8CZbn5iS+fKm1GKTGH2QiKCGiHhXtjFshE/nuw/98edn1yfbKayLNtmYMOmTLyCrCNUs2OlEnGA= 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 1562860499129872.6298667303746; Thu, 11 Jul 2019 08:54:59 -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 7BA0DB2DEC; Thu, 11 Jul 2019 15:54: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 526FA1001DD9; Thu, 11 Jul 2019 15:54: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 136FC1833011; Thu, 11 Jul 2019 15:54: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 x6BFsaEf014715 for ; Thu, 11 Jul 2019 11:54:36 -0400 Received: by smtp.corp.redhat.com (Postfix) id C9EA25D973; Thu, 11 Jul 2019 15:54:36 +0000 (UTC) Received: from moe.brq.redhat.com (unknown [10.43.2.30]) by smtp.corp.redhat.com (Postfix) with ESMTP id 559125D9DC for ; Thu, 11 Jul 2019 15:54:36 +0000 (UTC) From: Michal Privoznik To: libvir-list@redhat.com Date: Thu, 11 Jul 2019 17:53:59 +0200 Message-Id: <3c185732424075ada2124640fdaed154672aca6c.1562859733.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 v1 12/31] 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.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, 11 Jul 2019 15:54:58 +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 | 412 +++++++++++++++++++++++++++++++++++++++ src/util/virnvme.h | 89 +++++++++ 4 files changed, 521 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 350b638193..856b770e57 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -2585,6 +2585,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 a47f333a98..998bec741e 100644 --- a/src/util/Makefile.inc.am +++ b/src/util/Makefile.inc.am @@ -143,6 +143,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..53724b63f7 --- /dev/null +++ b/src/util/virnvme.c @@ -0,0 +1,412 @@ +/* + * 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.pci"); +#define VIR_FROM_THIS VIR_FROM_NONE + +struct _virNVMeDevice { + virPCIDeviceAddress address; /* PCI address of controller */ + unsigned long 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 %lu is already on the l= ist"), + 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 %lu 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; +} + + +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 virPCIDeviceNew(d->address.domain, + d->address.bus, + d->address.slot, + d->address.function))) + return NULL; + + /* NVMe devices must be bound to vfio */ + virPCIDeviceSetStubDriver(pci, VIR_PCI_STUB_DRIVER_VFIO); + virPCIDeviceSetManaged(pci, d->managed); + + if (virPCIDeviceListAdd(pciDevices, pci) < 0) + return NULL; + + /* avoid freeing the device */ + pci =3D NULL; + } + + VIR_RETURN_PTR(pciDevices); +} + + +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 %lu 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 virPCIDeviceNew(d->address.domain, + d->address.bus, + d->address.slot, + d->address.function))) + return NULL; + + /* NVMe devices must be bound to vfio */ + virPCIDeviceSetStubDriver(pci, VIR_PCI_STUB_DRIVER_VFIO); + virPCIDeviceSetManaged(pci, d->managed); + + 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..edf5fe58ab --- /dev/null +++ b/src/util/virnvme.h @@ -0,0 +1,89 @@ +/* + * 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; +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 Fri Apr 19 16:08:06 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=1562860497; cv=none; d=zoho.com; s=zohoarc; b=U3S0MT7OyTjsOngsfgEL7C+X9eI4EyPSF38J1cxMVilylPMU9oN6K1xuo/1GzUy70aPAF7q8c8l8UNqFPnuJnDp4nS3nbkhXwvv4xp5VuJZ7HaMVcJzjaT+y3l7jANkZD0wJ45QlG5KH1WuV9c+FUwKWx+wnY5i1A3F50/iunYE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1562860497; 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=KDpaSrAbK2L0vWhi1MUAr9jMHTBwzcDqvhcgmqMZcVo=; b=egTKg0ShSk7raQrgb0j6pEiiUDIKOYwsrAFayd6dPnkksM3TXlLWvsF1q3Hw7NvyrPnp9p6E/UV8lQGaEMGY530NzAnYZQxLGLYi9/Su54udaCg5U1YEvLE+5F0IvLzTTDL2KpAQvP54Gj/GYbKMpxhSnVYxBqahcg4kPaKgQTk= 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 1562860497176429.6741440858817; Thu, 11 Jul 2019 08:54: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 63657307D84D; Thu, 11 Jul 2019 15:54:55 +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 3EB181001B00; Thu, 11 Jul 2019 15:54:55 +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 015BA183300B; Thu, 11 Jul 2019 15:54: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 x6BFsb6w014723 for ; Thu, 11 Jul 2019 11:54:37 -0400 Received: by smtp.corp.redhat.com (Postfix) id 956655D973; Thu, 11 Jul 2019 15:54:37 +0000 (UTC) Received: from moe.brq.redhat.com (unknown [10.43.2.30]) by smtp.corp.redhat.com (Postfix) with ESMTP id 211305D9DC for ; Thu, 11 Jul 2019 15:54:36 +0000 (UTC) From: Michal Privoznik To: libvir-list@redhat.com Date: Thu, 11 Jul 2019 17:54:00 +0200 Message-Id: <3977dd674b7559c651f442a087b9e38e96a759c5.1562859733.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 v1 13/31] 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.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, 11 Jul 2019 15:54:55 +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 | 3 + src/util/virhostdev.c | 244 +++++++++++++++++++++++++++++++++++++++ src/util/virhostdev.h | 25 ++++ 3 files changed, 272 insertions(+) diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index 856b770e57..bc6583562a 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -2077,18 +2077,21 @@ virHostdevPCINodeDeviceReAttach; virHostdevPCINodeDeviceReset; virHostdevPrepareDomainDevices; virHostdevPrepareMediatedDevices; +virHostdevPrepareNVMeDevices; virHostdevPreparePCIDevices; virHostdevPrepareSCSIDevices; virHostdevPrepareSCSIVHostDevices; virHostdevPrepareUSBDevices; virHostdevReAttachDomainDevices; virHostdevReAttachMediatedDevices; +virHostdevReAttachNVMeDevices; virHostdevReAttachPCIDevices; virHostdevReAttachSCSIDevices; virHostdevReAttachSCSIVHostDevices; virHostdevReAttachUSBDevices; virHostdevUpdateActiveDomainDevices; virHostdevUpdateActiveMediatedDevices; +virHostdevUpdateActiveNVMeDevices; virHostdevUpdateActivePCIDevices; virHostdevUpdateActiveSCSIDevices; virHostdevUpdateActiveUSBDevices; diff --git a/src/util/virhostdev.c b/src/util/virhostdev.c index 07397b9682..90d94b0a92 100644 --- a/src/util/virhostdev.c +++ b/src/util/virhostdev.c @@ -137,6 +137,7 @@ virHostdevManagerDispose(void *obj) virObjectUnref(hostdevMgr->activeSCSIHostdevs); virObjectUnref(hostdevMgr->activeSCSIVHostHostdevs); virObjectUnref(hostdevMgr->activeMediatedHostdevs); + virObjectUnref(hostdevMgr->activeNVMeHostdevs); VIR_FREE(hostdevMgr->stateDir); } =20 @@ -167,6 +168,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; @@ -2229,3 +2233,243 @@ virHostdevUpdateActiveDomainDevices(virHostdevManag= erPtr mgr, =20 return 0; } + + +static virNVMeDeviceListPtr +virHostdevGetNVMeDeviceList(virDomainDiskDefPtr *disks, + size_t ndisks, + const char *drv_name, + const char *dom_name) +{ + VIR_AUTOUNREF(virNVMeDeviceListPtr) nvmeDevices =3D NULL; + size_t i; + + if (!(nvmeDevices =3D virNVMeDeviceListNew())) + return NULL; + + for (i =3D 0; i < ndisks; i++) { + virDomainDiskDefPtr disk =3D disks[i]; + virStorageSourcePtr n; + + for (n =3D disk->src; virStorageSourceIsBacking(n); n =3D n->backi= ngStore) { + 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 NULL; + + if (virNVMeDeviceUsedBySet(dev, drv_name, dom_name) < 0) + return NULL; + + if (virNVMeDeviceListAdd(nvmeDevices, dev) < 0) + return NULL; + } + } + + VIR_RETURN_PTR(nvmeDevices); +} + + +int +virHostdevPrepareNVMeDevices(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; + 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 virHostdevGetNVMeDeviceList(disks, ndisks, drv_n= ame, dom_name))) + 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; + + /* 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 +virHostdevReAttachNVMeDevices(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; + size_t i; + int ret =3D -1; + + if (!(nvmeDevices =3D virHostdevGetNVMeDeviceList(disks, ndisks, drv_n= ame, dom_name))) + 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 +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 virHostdevGetNVMeDeviceList(disks, ndisks, drv_n= ame, dom_name))) + 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); + + 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 88501e2743..98dc226631 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); @@ -201,3 +205,24 @@ int virHostdevPCINodeDeviceReAttach(virHostdevManagerP= tr mgr, int virHostdevPCINodeDeviceReset(virHostdevManagerPtr mgr, virPCIDevicePtr pci) ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2); + +int +virHostdevPrepareNVMeDevices(virHostdevManagerPtr hostdev_mgr, + const char *drv_name, + const char *dom_name, + virDomainDiskDefPtr *disks, + size_t ndisks); + +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 Fri Apr 19 16:08:06 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=1562860495; cv=none; d=zoho.com; s=zohoarc; b=llxOgGu0IZQWjmOW07YCoF7f4HdBu4CkkSwhM/0QjpRw/mFcp+F9/50ra67oEnu2XFmuC3gtCKCwT13DKugBNUa6vtn51EpeSoD/ms0H2g2RkxmYON29eAOpl0wRmnmnh3sf5Mdh6TmBMCGK2nuj6Swm6VvmgrGHE5CCSTFQVOs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1562860495; 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=dObg2rulgM3pDf5ef+isfoWcVo5i7pfnYBpSZVsDcvs=; b=bG9u9YjMnV6hQ+h7RNglZq8H/Rnti161XWW8/+gdIh+BRtpZUrgGqLEEvysB5tYU62UVU0Nd1tYvXnlFZRXC4sb5KPIxg0yK++rmodBCJ+9ycg3Um/yK0bAknae0bmqO/Crg2l85cpMdJGRQAJJOR+W0aYhYqMqEL/kYj7q+s6U= 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 1562860495600946.2072356764245; Thu, 11 Jul 2019 08:54:55 -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 ECEC6309265F; Thu, 11 Jul 2019 15:54: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 C91671001B0F; Thu, 11 Jul 2019 15:54: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 8B1E7183300A; Thu, 11 Jul 2019 15:54: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 x6BFseRV014738 for ; Thu, 11 Jul 2019 11:54:40 -0400 Received: by smtp.corp.redhat.com (Postfix) id 451635D9DC; Thu, 11 Jul 2019 15:54:40 +0000 (UTC) Received: from moe.brq.redhat.com (unknown [10.43.2.30]) by smtp.corp.redhat.com (Postfix) with ESMTP id C4D745D9CC for ; Thu, 11 Jul 2019 15:54:37 +0000 (UTC) From: Michal Privoznik To: libvir-list@redhat.com Date: Thu, 11 Jul 2019 17:54:01 +0200 Message-Id: <00b38194a82a03cadde010e96ba9e59bb8da4824.1562859733.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 v1 14/31] virhostdevtest: Don't proceed to test cases if init failed 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.43]); Thu, 11 Jul 2019 15:54:54 +0000 (UTC) Content-Type: text/plain; charset="utf-8" The myInit() function is called before any of the test cases because it prepares all internal structures for individual cases. Well, if it fails there's no point in proceeding with testing. Signed-off-by: Michal Privoznik --- tests/virhostdevtest.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/tests/virhostdevtest.c b/tests/virhostdevtest.c index 20eaca82e0..cf39c83c76 100644 --- a/tests/virhostdevtest.c +++ b/tests/virhostdevtest.c @@ -574,8 +574,11 @@ mymain(void) ret =3D -1; \ } while (0) =20 - if (myInit() < 0) + if (myInit() < 0) { fprintf(stderr, "Init data structures failed."); + virFileDeleteTree(fakerootdir); + return EXIT_FAILURE; + } =20 DO_TEST(testVirHostdevRoundtripNoGuest); DO_TEST(testVirHostdevRoundtripUnmanaged); --=20 2.21.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Fri Apr 19 16:08:06 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=1562860499; cv=none; d=zoho.com; s=zohoarc; b=lxL4S/n3q9fpXRZapPSl/Fy03WlNFT3EkoRQMuXYfwQQVIIyzqxsw4TRT2eVYlBSUvkltrPgeQQcAyCGmktO9VbtxYNvPRESZlvOLakrICnVNf+uU8OcqT7iDiQ7JLyJXvqMfJK/FtTZnXTf1p6SURWBfDHw1IntcFzIm9czCac= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1562860499; 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=UZMPvoJlkTlgJ7qJRgGrC9i8ZC9B+YtWQdtq+/kHkqc=; b=H7RTg08zF7576FiLk5WslqF4tRlpHccytxAdfTxGmAEAag5+EdjpDzHPMb8Sh4b7rj41mYYTVfaalXlhbLJ1xbkzCuQE8HPJKuLXRzxzxU/0cnQrfpBOwaTBY5yGoPwW7Z9WcUYQA1sjeuBKSWtvFzC7lYB5uFBUP8IaiclQkTQ= 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 1562860499903874.9405817987557; Thu, 11 Jul 2019 08:54:59 -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 A4D23356D2; Thu, 11 Jul 2019 15:54: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 6DAF461B67; Thu, 11 Jul 2019 15:54: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 1B0D7206DE; Thu, 11 Jul 2019 15:54: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 x6BFsicJ014753 for ; Thu, 11 Jul 2019 11:54:44 -0400 Received: by smtp.corp.redhat.com (Postfix) id D7E6E5DA65; Thu, 11 Jul 2019 15:54:44 +0000 (UTC) Received: from moe.brq.redhat.com (unknown [10.43.2.30]) by smtp.corp.redhat.com (Postfix) with ESMTP id 630A35DD8D for ; Thu, 11 Jul 2019 15:54:40 +0000 (UTC) From: Michal Privoznik To: libvir-list@redhat.com Date: Thu, 11 Jul 2019 17:54:02 +0200 Message-Id: <86240ff451cabe5de80311ad0449a84404c0045d.1562859733.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 v1 15/31] virhostdevtest: s/CHECK_LIST_COUNT/CHECK_PCI_LIST_COUNT/ 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, 11 Jul 2019 15:54:58 +0000 (UTC) Content-Type: text/plain; charset="utf-8" In near future we will need to check for number of members of two different types of lists: PCI and NVMe. Rename CHECK_LIST_COUNT to CHECK_PCI_LIST_COUNT to mark explicitly what type of list it is working with. Signed-off-by: Michal Privoznik --- tests/virhostdevtest.c | 83 ++++++++++++++++++++++-------------------- 1 file changed, 43 insertions(+), 40 deletions(-) diff --git a/tests/virhostdevtest.c b/tests/virhostdevtest.c index cf39c83c76..7d15a87797 100644 --- a/tests/virhostdevtest.c +++ b/tests/virhostdevtest.c @@ -34,10 +34,10 @@ =20 VIR_LOG_INIT("tests.hostdevtest"); =20 -# define CHECK_LIST_COUNT(list, cnt) \ +# define CHECK_LIST_COUNT(list, cnt, cb) \ do { \ size_t actualCount; \ - if ((actualCount =3D virPCIDeviceListCount(list)) !=3D cnt) { \ + if ((actualCount =3D cb(list)) !=3D cnt) { \ virReportError(VIR_ERR_INTERNAL_ERROR, \ "Unexpected count of items in " #list ": %zu, "= \ "expecting %zu", actualCount, (size_t) cnt); \ @@ -45,6 +45,9 @@ VIR_LOG_INIT("tests.hostdevtest"); } \ } while (0) =20 +# define CHECK_PCI_LIST_COUNT(list, cnt) \ + CHECK_LIST_COUNT(list, cnt, virPCIDeviceListCount) + # define TEST_STATE_DIR abs_builddir "/hostdevmgr" static const char *drv_name =3D "test_driver"; static const char *dom_name =3D "test_domain"; @@ -143,16 +146,16 @@ testVirHostdevPreparePCIHostdevs_unmanaged(void) if (virHostdevPreparePCIDevices(mgr, drv_name, dom_name, uuid, NULL, 0, 0) < 0) goto cleanup; - CHECK_LIST_COUNT(mgr->activePCIHostdevs, active_count); - CHECK_LIST_COUNT(mgr->inactivePCIHostdevs, inactive_count); + CHECK_PCI_LIST_COUNT(mgr->activePCIHostdevs, active_count); + CHECK_PCI_LIST_COUNT(mgr->inactivePCIHostdevs, inactive_count); =20 /* Test unmanaged hostdevs */ VIR_DEBUG("Test >=3D1 unmanaged hostdevs"); if (virHostdevPreparePCIDevices(mgr, drv_name, dom_name, uuid, hostdevs, nhostdevs, 0) < 0) goto cleanup; - CHECK_LIST_COUNT(mgr->activePCIHostdevs, active_count + nhostdevs); - CHECK_LIST_COUNT(mgr->inactivePCIHostdevs, inactive_count - nhostdevs); + CHECK_PCI_LIST_COUNT(mgr->activePCIHostdevs, active_count + nhostdevs); + CHECK_PCI_LIST_COUNT(mgr->inactivePCIHostdevs, inactive_count - nhostd= evs); =20 /* Test conflict */ active_count =3D virPCIDeviceListCount(mgr->activePCIHostdevs); @@ -161,22 +164,22 @@ testVirHostdevPreparePCIHostdevs_unmanaged(void) if (!virHostdevPreparePCIDevices(mgr, drv_name, dom_name, uuid, &hostdevs[0], 1, 0)) goto cleanup; - CHECK_LIST_COUNT(mgr->activePCIHostdevs, active_count); - CHECK_LIST_COUNT(mgr->inactivePCIHostdevs, inactive_count); + CHECK_PCI_LIST_COUNT(mgr->activePCIHostdevs, active_count); + CHECK_PCI_LIST_COUNT(mgr->inactivePCIHostdevs, inactive_count); =20 VIR_DEBUG("Test: prepare same hostdevs for same driver, diff domain ag= ain"); if (!virHostdevPreparePCIDevices(mgr, drv_name, "test_domain1", uuid, &hostdevs[1], 1, 0)) goto cleanup; - CHECK_LIST_COUNT(mgr->activePCIHostdevs, active_count); - CHECK_LIST_COUNT(mgr->inactivePCIHostdevs, inactive_count); + CHECK_PCI_LIST_COUNT(mgr->activePCIHostdevs, active_count); + CHECK_PCI_LIST_COUNT(mgr->inactivePCIHostdevs, inactive_count); =20 VIR_DEBUG("Test: prepare same hostdevs for diff driver/domain again"); if (!virHostdevPreparePCIDevices(mgr, "test_driver1", dom_name, uuid, &hostdevs[2], 1, 0)) goto cleanup; - CHECK_LIST_COUNT(mgr->activePCIHostdevs, active_count); - CHECK_LIST_COUNT(mgr->inactivePCIHostdevs, inactive_count); + CHECK_PCI_LIST_COUNT(mgr->activePCIHostdevs, active_count); + CHECK_PCI_LIST_COUNT(mgr->inactivePCIHostdevs, inactive_count); =20 ret =3D 0; =20 @@ -203,14 +206,14 @@ testVirHostdevReAttachPCIHostdevs_unmanaged(void) =20 VIR_DEBUG("Test 0 hostdevs"); virHostdevReAttachPCIDevices(mgr, drv_name, dom_name, NULL, 0, NULL); - CHECK_LIST_COUNT(mgr->activePCIHostdevs, active_count); - CHECK_LIST_COUNT(mgr->inactivePCIHostdevs, inactive_count); + CHECK_PCI_LIST_COUNT(mgr->activePCIHostdevs, active_count); + CHECK_PCI_LIST_COUNT(mgr->inactivePCIHostdevs, inactive_count); =20 VIR_DEBUG("Test >=3D1 unmanaged hostdevs"); virHostdevReAttachPCIDevices(mgr, drv_name, dom_name, hostdevs, nhostdevs, NULL); - CHECK_LIST_COUNT(mgr->activePCIHostdevs, active_count - nhostdevs); - CHECK_LIST_COUNT(mgr->inactivePCIHostdevs, inactive_count + nhostdevs); + CHECK_PCI_LIST_COUNT(mgr->activePCIHostdevs, active_count - nhostdevs); + CHECK_PCI_LIST_COUNT(mgr->inactivePCIHostdevs, inactive_count + nhostd= evs); =20 ret =3D 0; =20 @@ -236,14 +239,14 @@ testVirHostdevPreparePCIHostdevs_managed(bool mixed) if (virHostdevPreparePCIDevices(mgr, drv_name, dom_name, uuid, hostdevs, nhostdevs, 0) < 0) goto cleanup; - CHECK_LIST_COUNT(mgr->activePCIHostdevs, active_count + nhostdevs); + CHECK_PCI_LIST_COUNT(mgr->activePCIHostdevs, active_count + nhostdevs); /* If testing a mixed roundtrip, devices are already in the inactive l= ist * before we start and are removed from it as soon as we attach them to * the guest */ if (mixed) - CHECK_LIST_COUNT(mgr->inactivePCIHostdevs, inactive_count - nhostd= evs); + CHECK_PCI_LIST_COUNT(mgr->inactivePCIHostdevs, inactive_count - nh= ostdevs); else - CHECK_LIST_COUNT(mgr->inactivePCIHostdevs, inactive_count); + CHECK_PCI_LIST_COUNT(mgr->inactivePCIHostdevs, inactive_count); =20 /* Test conflict */ active_count =3D virPCIDeviceListCount(mgr->activePCIHostdevs); @@ -252,22 +255,22 @@ testVirHostdevPreparePCIHostdevs_managed(bool mixed) if (!virHostdevPreparePCIDevices(mgr, drv_name, dom_name, uuid, &hostdevs[0], 1, 0)) goto cleanup; - CHECK_LIST_COUNT(mgr->activePCIHostdevs, active_count); - CHECK_LIST_COUNT(mgr->inactivePCIHostdevs, inactive_count); + CHECK_PCI_LIST_COUNT(mgr->activePCIHostdevs, active_count); + CHECK_PCI_LIST_COUNT(mgr->inactivePCIHostdevs, inactive_count); =20 VIR_DEBUG("Test: prepare same hostdevs for same driver, diff domain ag= ain"); if (!virHostdevPreparePCIDevices(mgr, drv_name, "test_domain1", uuid, &hostdevs[1], 1, 0)) goto cleanup; - CHECK_LIST_COUNT(mgr->activePCIHostdevs, active_count); - CHECK_LIST_COUNT(mgr->inactivePCIHostdevs, inactive_count); + CHECK_PCI_LIST_COUNT(mgr->activePCIHostdevs, active_count); + CHECK_PCI_LIST_COUNT(mgr->inactivePCIHostdevs, inactive_count); =20 VIR_DEBUG("Test: prepare same hostdevs for diff driver/domain again"); if (!virHostdevPreparePCIDevices(mgr, "test_driver1", dom_name, uuid, &hostdevs[2], 1, 0)) goto cleanup; - CHECK_LIST_COUNT(mgr->activePCIHostdevs, active_count); - CHECK_LIST_COUNT(mgr->inactivePCIHostdevs, inactive_count); + CHECK_PCI_LIST_COUNT(mgr->activePCIHostdevs, active_count); + CHECK_PCI_LIST_COUNT(mgr->inactivePCIHostdevs, inactive_count); =20 ret =3D 0; =20 @@ -294,19 +297,19 @@ testVirHostdevReAttachPCIHostdevs_managed(bool mixed) =20 VIR_DEBUG("Test 0 hostdevs"); virHostdevReAttachPCIDevices(mgr, drv_name, dom_name, NULL, 0, NULL); - CHECK_LIST_COUNT(mgr->activePCIHostdevs, active_count); - CHECK_LIST_COUNT(mgr->inactivePCIHostdevs, inactive_count); + CHECK_PCI_LIST_COUNT(mgr->activePCIHostdevs, active_count); + CHECK_PCI_LIST_COUNT(mgr->inactivePCIHostdevs, inactive_count); =20 VIR_DEBUG("Test >=3D1 hostdevs"); virHostdevReAttachPCIDevices(mgr, drv_name, dom_name, hostdevs, nhostdevs, NULL); - CHECK_LIST_COUNT(mgr->activePCIHostdevs, active_count - nhostdevs); + CHECK_PCI_LIST_COUNT(mgr->activePCIHostdevs, active_count - nhostdevs); /* If testing a mixed roundtrip, devices are added back to the inactive * list as soon as we detach from the guest */ if (mixed) - CHECK_LIST_COUNT(mgr->inactivePCIHostdevs, inactive_count + nhostd= evs); + CHECK_PCI_LIST_COUNT(mgr->inactivePCIHostdevs, inactive_count + nh= ostdevs); else - CHECK_LIST_COUNT(mgr->inactivePCIHostdevs, inactive_count); + CHECK_PCI_LIST_COUNT(mgr->inactivePCIHostdevs, inactive_count); =20 ret =3D 0; =20 @@ -326,8 +329,8 @@ testVirHostdevDetachPCINodeDevice(void) inactive_count =3D virPCIDeviceListCount(mgr->inactivePCIHostdevs); if (virHostdevPCINodeDeviceDetach(mgr, dev[i]) < 0) goto cleanup; - CHECK_LIST_COUNT(mgr->activePCIHostdevs, active_count); - CHECK_LIST_COUNT(mgr->inactivePCIHostdevs, inactive_count + 1); + CHECK_PCI_LIST_COUNT(mgr->activePCIHostdevs, active_count); + CHECK_PCI_LIST_COUNT(mgr->inactivePCIHostdevs, inactive_count + 1); } =20 ret =3D 0; @@ -347,8 +350,8 @@ testVirHostdevResetPCINodeDevice(void) inactive_count =3D virPCIDeviceListCount(mgr->inactivePCIHostdevs); if (virHostdevPCINodeDeviceReset(mgr, dev[i]) < 0) goto cleanup; - CHECK_LIST_COUNT(mgr->activePCIHostdevs, active_count); - CHECK_LIST_COUNT(mgr->inactivePCIHostdevs, inactive_count); + CHECK_PCI_LIST_COUNT(mgr->activePCIHostdevs, active_count); + CHECK_PCI_LIST_COUNT(mgr->inactivePCIHostdevs, inactive_count); } =20 ret =3D 0; @@ -369,8 +372,8 @@ testVirHostdevReAttachPCINodeDevice(void) inactive_count =3D virPCIDeviceListCount(mgr->inactivePCIHostdevs); if (virHostdevPCINodeDeviceReAttach(mgr, dev[i]) < 0) goto cleanup; - CHECK_LIST_COUNT(mgr->activePCIHostdevs, active_count); - CHECK_LIST_COUNT(mgr->inactivePCIHostdevs, inactive_count - 1); + CHECK_PCI_LIST_COUNT(mgr->activePCIHostdevs, active_count); + CHECK_PCI_LIST_COUNT(mgr->inactivePCIHostdevs, inactive_count - 1); } =20 ret =3D 0; @@ -393,15 +396,15 @@ testVirHostdevUpdateActivePCIHostdevs(void) if (virHostdevUpdateActivePCIDevices(mgr, NULL, 0, drv_name, dom_name) < 0) goto cleanup; - CHECK_LIST_COUNT(mgr->activePCIHostdevs, active_count); - CHECK_LIST_COUNT(mgr->inactivePCIHostdevs, inactive_count); + CHECK_PCI_LIST_COUNT(mgr->activePCIHostdevs, active_count); + CHECK_PCI_LIST_COUNT(mgr->inactivePCIHostdevs, inactive_count); =20 VIR_DEBUG("Test >=3D1 hostdevs"); if (virHostdevUpdateActivePCIDevices(mgr, hostdevs, nhostdevs, drv_name, dom_name) < 0) goto cleanup; - CHECK_LIST_COUNT(mgr->activePCIHostdevs, active_count + nhostdevs); - CHECK_LIST_COUNT(mgr->inactivePCIHostdevs, inactive_count); + CHECK_PCI_LIST_COUNT(mgr->activePCIHostdevs, active_count + nhostdevs); + CHECK_PCI_LIST_COUNT(mgr->inactivePCIHostdevs, inactive_count); =20 ret =3D 0; =20 --=20 2.21.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Fri Apr 19 16:08:06 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=1562860502; cv=none; d=zoho.com; s=zohoarc; b=PLl9spAo+OGYJOWBXnzsF69aEFgIXLr5++Ci0zN/UbGQgNv6BWtUR3AdE1Wwnf6ma/yCicOu2JB0rO43+KVhRIWbqlH3h8orEWhCs4O4K0tNmcP9/rJdTeFBzsxEayFjfpHn+ZBuW8kzOFTKqLE5TD3H/ADsJUdIsmlGacAK9I4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1562860502; 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=pcGVbFcdCmy2bPjNuWbNARrrt4AN3txH6xmJUzmfjgQ=; b=GLUVDTexv6353r1jRvj/BbnLtvkUjDuNkPYkSP8dbiUYmRTzQU5mQbH0hWIxzuFV4GuDhBxjtG0qcn2QBfzGMOLL3dT6Sly4cI3WrtYT/8aiWrdbvRQG3FHeubNHuB6NwuMQ0lWGMN47a8RK9aLvVkYEQI77alsPblkEBHGTMKM= 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 1562860502390925.2397153877386; Thu, 11 Jul 2019 08:55:02 -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 BB4EE83F42; Thu, 11 Jul 2019 15:55:00 +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 974CC1A265; Thu, 11 Jul 2019 15:55:00 +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 5DF711833018; Thu, 11 Jul 2019 15:55:00 +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 x6BFsj57014758 for ; Thu, 11 Jul 2019 11:54:45 -0400 Received: by smtp.corp.redhat.com (Postfix) id A360B5DA65; Thu, 11 Jul 2019 15:54:45 +0000 (UTC) Received: from moe.brq.redhat.com (unknown [10.43.2.30]) by smtp.corp.redhat.com (Postfix) with ESMTP id 2EDF15D9CC for ; Thu, 11 Jul 2019 15:54:45 +0000 (UTC) From: Michal Privoznik To: libvir-list@redhat.com Date: Thu, 11 Jul 2019 17:54:03 +0200 Message-Id: <4075200ea09ac6ef45eec7924cddd64c35509f8c.1562859733.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 v1 16/31] 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.84 on 10.5.11.23 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.27]); Thu, 11 Jul 2019 15:55:01 +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 --- 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 18d06d11d4..a26b7c1b2e 100644 --- a/tests/virpcimock.c +++ b/tests/virpcimock.c @@ -880,6 +880,7 @@ init_env(void) MAKE_PCI_DRIVER("i915", 0x8086, 0x0046, 0x8086, 0x0047); MAKE_PCI_DRIVER("pci-stub", -1, -1); pci_driver_new("vfio-pci", PCI_ACTION_BIND, -1, -1); + MAKE_PCI_DRIVER("nvme", 0x1cc1, 0x8201); =20 # define MAKE_PCI_DEVICE(Id, Vendor, Device, ...) \ do { \ @@ -902,6 +903,8 @@ init_env(void) MAKE_PCI_DEVICE("0000:0a:01.0", 0x8086, 0x0047); MAKE_PCI_DEVICE("0000:0a:02.0", 0x8286, 0x0048); MAKE_PCI_DEVICE("0000:0a:03.0", 0x8386, 0x0048); + MAKE_PCI_DEVICE("0000:01:00.0", 0x1cc1, 0x8201, .iommuGroup =3D 8, .kl= ass =3D 0x010802); + MAKE_PCI_DEVICE("0000:02:00.0", 0x1cc1, 0x8201, .iommuGroup =3D 9, .kl= ass =3D 0x010802); } =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 Fri Apr 19 16:08:06 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=1562860506; cv=none; d=zoho.com; s=zohoarc; b=Pia6cA/bN6tke3SSkmZv5a10RAKWoz8/+t1dVQ4mJ/9K+4+AKnZ6dXz48mJwDYNt408e4F6u8H7s0uJ2VN+ckYUF6UDT3Ggm7UJyN88oMx6tGoUFPO9gRo3TUtGmVzDrc+DXeMKTeyi7LGPutDnaiFegz7JJJOUW8g6ZQzegBrc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1562860506; 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=9rAAQxUPGLIqgdMnPJS2WmnuCQCW5/yn8rxcWntHjxc=; b=NrNBYE1O7NZEmhL16iLHAKW+7lJHLRmffQ2q3/yWo2dpT0b7zP6xneU7jYLdIeptj3AVqShLIdkqZxKbeZZna2K7VrB5UUX8/fWTH9L7LQc0UtdExx4Kp7QBWbqt/XWIpusc6obf4Mw3Q+YsUUM9MoBVBJMvoTGgKZ3lJDRLE0U= 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 1562860506686391.612316266874; Thu, 11 Jul 2019 08:55:06 -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 20D1A30820C9; Thu, 11 Jul 2019 15:55: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 EF9C660191; Thu, 11 Jul 2019 15:55:04 +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 A56D1183301F; Thu, 11 Jul 2019 15:55:04 +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 x6BFskIx014764 for ; Thu, 11 Jul 2019 11:54:46 -0400 Received: by smtp.corp.redhat.com (Postfix) id 6F8495DC19; Thu, 11 Jul 2019 15:54:46 +0000 (UTC) Received: from moe.brq.redhat.com (unknown [10.43.2.30]) by smtp.corp.redhat.com (Postfix) with ESMTP id EEF535D9CC for ; Thu, 11 Jul 2019 15:54:45 +0000 (UTC) From: Michal Privoznik To: libvir-list@redhat.com Date: Thu, 11 Jul 2019 17:54:04 +0200 Message-Id: <546b4a6df6c532d77b744ca0ee73d391f73cf49c.1562859733.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 v1 17/31] 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.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.47]); Thu, 11 Jul 2019 15:55:05 +0000 (UTC) Content-Type: text/plain; charset="utf-8" Signed-off-by: Michal Privoznik --- tests/virhostdevtest.c | 97 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 97 insertions(+) diff --git a/tests/virhostdevtest.c b/tests/virhostdevtest.c index 7d15a87797..e34959c4f1 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_KVM); } =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) @@ -550,6 +594,58 @@ testVirHostdevOther(const void *opaque ATTRIBUTE_UNUSE= D) return ret; } =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 @@ -588,6 +684,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 Fri Apr 19 16:08:06 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=1562860500; cv=none; d=zoho.com; s=zohoarc; b=Hq2sL6sC4np9xgwdZaDkbZ5rtabyYU9xzG27W8HQ32cCQlXaSprOutZlq8uo7gc6zwyRF+ERHE645Ikd37V4ERu/kwemD3NYeVXoRAeUHrcVYiLoDxN9Q4zfQAmA0dXvKacTcFKRo0VOvohhSPF+psM46bIUPqMUJkibg2m245Y= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1562860500; 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=j9IkkJwq8EdstcKho0J0HsX+tubpuqtaNk64Fd1bcSE=; b=JK/zrfP8tc6IOgkH4GEwRFI4Q+qPLCkZkzZtVg6KgOupPgc3OkslBiGg/YE365P3yzCuvN0dUoMhc1/713YEULZVHJFl6WIV0q4ZamguaG4CC0B8z9CsEo6lKzirgXKKlfnKCvg2LiJupMLPkaxul5rkl/W94Oy+frfEZYEUE58= 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 1562860500534787.73935344404; Thu, 11 Jul 2019 08:55:00 -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 0059AC0669AF; Thu, 11 Jul 2019 15:54:59 +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 CE04C5C64A; Thu, 11 Jul 2019 15:54:58 +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 926EE1D576; Thu, 11 Jul 2019 15:54:58 +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 x6BFslUI014774 for ; Thu, 11 Jul 2019 11:54:47 -0400 Received: by smtp.corp.redhat.com (Postfix) id 3AD565DD8E; Thu, 11 Jul 2019 15:54:47 +0000 (UTC) Received: from moe.brq.redhat.com (unknown [10.43.2.30]) by smtp.corp.redhat.com (Postfix) with ESMTP id B9F175D9CC for ; Thu, 11 Jul 2019 15:54:46 +0000 (UTC) From: Michal Privoznik To: libvir-list@redhat.com Date: Thu, 11 Jul 2019 17:54:05 +0200 Message-Id: <6afab83f86f96bf7ae8e3a26bcf0e34ea7078497.1562859733.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 v1 18/31] 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.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.32]); Thu, 11 Jul 2019 15:54:59 +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 --- 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 92b037e1ed..efa4d62f1f 100644 --- a/src/qemu/qemu_hostdev.c +++ b/src/qemu/qemu_hostdev.c @@ -96,13 +96,28 @@ qemuHostdevUpdateActiveMediatedDevices(virQEMUDriverPtr= driver, } =20 =20 +int +qemuHostdevUpdateActiveNVMeDevices(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 (qemuHostdevUpdateActiveNVMeDevices(driver, def) < 0) + return -1; + if (qemuHostdevUpdateActivePCIDevices(driver, def) < 0) return -1; =20 @@ -226,6 +241,17 @@ qemuHostdevPreparePCIDevicesCheckSupport(virDomainHost= devDefPtr *hostdevs, return true; } =20 +int +qemuHostdevPrepareNVMeDevices(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, @@ -342,9 +368,12 @@ qemuHostdevPrepareDomainDevices(virQEMUDriverPtr drive= r, virQEMUCapsPtr qemuCaps, unsigned int flags) { - if (!def->nhostdevs) + if (!def->nhostdevs && !def->ndisks) return 0; =20 + if (qemuHostdevPrepareNVMeDevices(driver, def->name, def->disks, def->= ndisks) < 0) + return -1; + if (qemuHostdevPreparePCIDevices(driver, def->name, def->uuid, def->hostdevs, def->nhostdevs, qemuCaps, flags) < 0) @@ -369,6 +398,17 @@ qemuHostdevPrepareDomainDevices(virQEMUDriverPtr drive= r, return 0; } =20 +void +qemuHostdevReAttachNVMeDevices(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, @@ -448,9 +488,12 @@ void qemuHostdevReAttachDomainDevices(virQEMUDriverPtr driver, virDomainDefPtr def) { - if (!def->nhostdevs) + if (!def->nhostdevs && !def->ndisks) return; =20 + qemuHostdevReAttachNVMeDevices(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 f6d76c1c2a..4afb103354 100644 --- a/src/qemu/qemu_hostdev.h +++ b/src/qemu/qemu_hostdev.h @@ -27,6 +27,8 @@ bool qemuHostdevHostSupportsPassthroughLegacy(void); bool qemuHostdevHostSupportsPassthroughVFIO(void); =20 +int qemuHostdevUpdateActiveNVMeDevices(virQEMUDriverPtr driver, + virDomainDefPtr def); int qemuHostdevUpdateActiveMediatedDevices(virQEMUDriverPtr driver, virDomainDefPtr def); int qemuHostdevUpdateActivePCIDevices(virQEMUDriverPtr driver, @@ -38,6 +40,10 @@ int qemuHostdevUpdateActiveSCSIDevices(virQEMUDriverPtr = driver, int qemuHostdevUpdateActiveDomainDevices(virQEMUDriverPtr driver, virDomainDefPtr def); =20 +int qemuHostdevPrepareNVMeDevices(virQEMUDriverPtr driver, + const char *name, + virDomainDiskDefPtr *disks, + size_t ndisks); int qemuHostdevPreparePCIDevices(virQEMUDriverPtr driver, const char *name, const unsigned char *uuid, @@ -67,6 +73,10 @@ int qemuHostdevPrepareDomainDevices(virQEMUDriverPtr dri= ver, virQEMUCapsPtr qemuCaps, unsigned int flags); =20 +void qemuHostdevReAttachNVMeDevices(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 Fri Apr 19 16:08:06 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=1562860502; cv=none; d=zoho.com; s=zohoarc; b=N/Q4OK744lsIMmWMTuTeTQBe3+FBmgGRUdQ6/y0rnMGDS0kuIiA9lPQuiriWlphcwPB7oaRCYEV8JNkgAjSfx+Xm41TcW3lu1h0VJKm9vdS2uQBH7GFkAtEDTcSlRSKSYkfPqCPDM9s1fkZ9j8SWzOkPHzJBcblPGIEo3ffKSPU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1562860502; 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=IoBEBa+dSb2VnLMDbcrS6SkFD9Ssc37RZDGBChHu9V0=; b=lcpLTmW8uuHIL2jYZ28hS8MtgMzmXC4IK22XFlsTBVr7dN9W0Yqdac7FjmMsOSWr9V/cHfIdNLXoAJdMQQyfWyQKnek45PNmmwTr4G2nWcw2uVsGw4KmI6MDht4gMb9s/hLVyRSIcjXzgQqq39K74zaW/S2Iu+3UIefSz7NLU5I= 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 1562860502495695.5973507357896; Thu, 11 Jul 2019 08:55:02 -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 C1C8381DE1; Thu, 11 Jul 2019 15:55:00 +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 9DAF61001B00; Thu, 11 Jul 2019 15:55:00 +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 5B1AF1833017; Thu, 11 Jul 2019 15:55:00 +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 x6BFsm7L014782 for ; Thu, 11 Jul 2019 11:54:48 -0400 Received: by smtp.corp.redhat.com (Postfix) id 05A725D9DC; Thu, 11 Jul 2019 15:54:48 +0000 (UTC) Received: from moe.brq.redhat.com (unknown [10.43.2.30]) by smtp.corp.redhat.com (Postfix) with ESMTP id 855FC5DD8E for ; Thu, 11 Jul 2019 15:54:47 +0000 (UTC) From: Michal Privoznik To: libvir-list@redhat.com Date: Thu, 11 Jul 2019 17:54:06 +0200 Message-Id: <7254ac9220dfaa6eb63c378c535ed059cb09c525.1562859733.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 v1 19/31] 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.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, 11 Jul 2019 15:55:01 +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 --- src/qemu/qemu_domain.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c index f09abc8a73..09e5ee37f4 100644 --- a/src/qemu/qemu_domain.c +++ b/src/qemu/qemu_domain.c @@ -10950,6 +10950,21 @@ qemuDomainGetMemLockLimitBytes(virDomainDefPtr def) } } =20 + for (i =3D 0; i < def->ndisks; i++) { + virDomainDiskDefPtr disk =3D def->disks[i]; + virStorageSourcePtr n; + + if (!disk->src) + continue; + + for (n =3D disk->src; virStorageSourceIsBacking(n); n =3D n->backi= ngStore) { + if (n->type =3D=3D VIR_STORAGE_TYPE_NVME) { + memKB =3D virDomainDefGetMemoryTotal(def) + 1024 * 1024; + goto done; + } + } + } + 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 Fri Apr 19 16:08:06 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=1562860510; cv=none; d=zoho.com; s=zohoarc; b=hZphhvK5IxTC3bgDAZXNfyINfPhDRBfTzNYvY4rGEHxq0K8v/EJ9wJRazFupWT6sIygPo8sUIafbUWykn/+Z0CX0GMap0+B/BqxPc4BUe8jZ8DU7WlmwUGhRlTvo84br6+HpubI2MlsrDv+Ys6FUqbPS27+ersS7rQlrFuZGFjU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1562860510; 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=cynkRnnlxIuWFAzZUSi49YIVuf1DRsCD8Kvy+ipC2Qo=; b=Jo/cf3g2OX1BOVotF9X2KlPg8asuvBVJGGN9aJLUJ1+YPi9knoUXCjdjpXa3IQHXranU+cYz1ug33XpX4RticwOveOzehMpCiECIDUI6qpnAVzc57mbfwS+LaqbeUk8DTt7nlTXGjXadG8HO/zvGRi11rFUgcavndwYMwwJugMw= 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 1562860510655217.95795392349044; Thu, 11 Jul 2019 08:55:10 -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 E0408300B916; Thu, 11 Jul 2019 15:55:08 +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 B0C1060600; Thu, 11 Jul 2019 15:55: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 7078419729; Thu, 11 Jul 2019 15:55: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 x6BFsmmQ014792 for ; Thu, 11 Jul 2019 11:54:48 -0400 Received: by smtp.corp.redhat.com (Postfix) id C5ACC5D9DC; Thu, 11 Jul 2019 15:54:48 +0000 (UTC) Received: from moe.brq.redhat.com (unknown [10.43.2.30]) by smtp.corp.redhat.com (Postfix) with ESMTP id 513D05D9CC for ; Thu, 11 Jul 2019 15:54:48 +0000 (UTC) From: Michal Privoznik To: libvir-list@redhat.com Date: Thu, 11 Jul 2019 17:54:07 +0200 Message-Id: <2ea3e530dfc8d636008ee30ffcf2d32917a893c1.1562859733.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 v1 20/31] 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.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.49]); Thu, 11 Jul 2019 15:55:09 +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 --- 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 bc6583562a..5b7aa58dd8 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -2994,6 +2994,7 @@ virStoragePRDefIsManaged; virStoragePRDefParseXML; virStorageSourceBackingStoreClear; virStorageSourceChainHasManagedPR; +virStorageSourceChainHasNVMe; virStorageSourceClear; virStorageSourceCopy; virStorageSourceFindByNodeName; diff --git a/src/util/virstoragefile.c b/src/util/virstoragefile.c index 18aa33fe05..a9ceb697cf 100644 --- a/src/util/virstoragefile.c +++ b/src/util/virstoragefile.c @@ -2157,6 +2157,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 a1294ea608..8afd5d60cb 100644 --- a/src/util/virstoragefile.h +++ b/src/util/virstoragefile.h @@ -431,6 +431,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 Fri Apr 19 16:08:06 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=1562860514; cv=none; d=zoho.com; s=zohoarc; b=hLfCj+KccUGgBE9Yw53xZ6arwXcYcon4qUxJSnR9pzPtl74rS0xHpKzQi7nvzusKF0cioLSzX0ltCoYJQaHpwKlV9Vi+d1dxMEWV5vKBVg8EcNdOHTuvVlH4rMDYIDy37A9Z6i+sNJX9+Tz30w/QewTwGNmZVrQNfYtvm+/uI58= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1562860514; 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=F1nNspxFEoa0JDp2wZO45SGKhUjVzxXgXerIWxk4R4w=; b=Jho9O7KVSDj3rVFVYXHIxiw4uwQLSktG8hzuumfMKSHtKusTW1N+szH2gMcx6NwXMclcKC9tU1MwXH7sHFpt6ibmgqgcTD/Qn8+y+7LlWx7Wjm+LUflzG6KVTEBjCCXRsk3GnTIlg6kytgvJ5EvKdHBrv+HLSP3gKL5bLW0H2C8= 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 1562860514831679.729424073571; Thu, 11 Jul 2019 08:55:14 -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 2BCDE5D60F; Thu, 11 Jul 2019 15:55:13 +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 F33DF19729; Thu, 11 Jul 2019 15:55:12 +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 B01A01972F; Thu, 11 Jul 2019 15:55:12 +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 x6BFsnBu014799 for ; Thu, 11 Jul 2019 11:54:49 -0400 Received: by smtp.corp.redhat.com (Postfix) id 913735D973; Thu, 11 Jul 2019 15:54:49 +0000 (UTC) Received: from moe.brq.redhat.com (unknown [10.43.2.30]) by smtp.corp.redhat.com (Postfix) with ESMTP id 1D3C55D9CC for ; Thu, 11 Jul 2019 15:54:48 +0000 (UTC) From: Michal Privoznik To: libvir-list@redhat.com Date: Thu, 11 Jul 2019 17:54:08 +0200 Message-Id: <416237ee6addd425062919b8477594c7bf574cf2.1562859733.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 v1 21/31] 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.84 on 10.5.11.23 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.39]); Thu, 11 Jul 2019 15:55:13 +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 --- 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 73f5e1fa0f..1b6ee3bfa6 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -31431,6 +31431,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; +} + + /** * virDomainGraphicsDefHasOpenGL: * @def: domain definition diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h index c1b5fc1337..2a067633bd 100644 --- a/src/conf/domain_conf.h +++ b/src/conf/domain_conf.h @@ -3611,6 +3611,9 @@ virDomainDiskGetDetectZeroesMode(virDomainDiskDiscard= discard, bool virDomainDefHasManagedPR(const virDomainDef *def); =20 +bool +virDomainDefHasNVMeDisk(const virDomainDef *def); + bool virDomainGraphicsDefHasOpenGL(const virDomainDef *def); =20 diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index 5b7aa58dd8..15bfae115f 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -284,6 +284,7 @@ virDomainDefHasDeviceAddress; virDomainDefHasManagedPR; virDomainDefHasMemballoon; virDomainDefHasMemoryHotplug; +virDomainDefHasNVMeDisk; virDomainDefHasUSB; virDomainDefHasVcpusOffline; virDomainDefLifecycleActionAllowed; --=20 2.21.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Fri Apr 19 16:08:06 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=1562860519; cv=none; d=zoho.com; s=zohoarc; b=GaFlbC1lwOg6qIx6nvW142JZRsigB3uAfv4zPYONKeX+zscu4AGONDOrRTtb5agNlIAuc5JV+yzy/oIrj4GQ+D0iPc6YytDpfUtIRo7xClcSutTGUv5B9iZ124zl8H8WTcEdVGZpC+IwBNcdDqtEWfW+gbHGxNaJsEx2PUufw/s= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1562860519; 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=qoKXZ/b5GxKsvouRxHsN3DLwDornQ5WxLW8+HY+3AmQ=; b=j8j8DgYyhP1PmWtPKum2UR0NkIv4B9RuOAgTrLsT+887nfRfEXHCbowAShgCUZuY5G2ASjAen37cXMav94Gm7PrpRfxRZTO8ZwlPlTXQ+LD22ixWF3SY/4ShvlRMsSRlGCMXGNpxs3eiETqg9z5iB/iH5MPOde1pksx0jRVXcKA= 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 1562860519284341.0905163068903; Thu, 11 Jul 2019 08:55: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 1F8362ED2E2; Thu, 11 Jul 2019 15:55:17 +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 E0E456061B; Thu, 11 Jul 2019 15:55:16 +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 96C3F19733; Thu, 11 Jul 2019 15:55:16 +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 x6BFsodE014807 for ; Thu, 11 Jul 2019 11:54:50 -0400 Received: by smtp.corp.redhat.com (Postfix) id 5D5A918352; Thu, 11 Jul 2019 15:54:50 +0000 (UTC) Received: from moe.brq.redhat.com (unknown [10.43.2.30]) by smtp.corp.redhat.com (Postfix) with ESMTP id DCB6E5DC19 for ; Thu, 11 Jul 2019 15:54:49 +0000 (UTC) From: Michal Privoznik To: libvir-list@redhat.com Date: Thu, 11 Jul 2019 17:54:09 +0200 Message-Id: <4fe7e12d3e710a3c8622e9213096a07ce9084711.1562859733.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 v1 22/31] qemu_domain: Separate VFIO code 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, 11 Jul 2019 15:55:17 +0000 (UTC) Content-Type: text/plain; charset="utf-8" This piece of code will be re-used later. Signed-off-by: Michal Privoznik --- src/conf/domain_conf.c | 17 +++++++++++++++++ src/conf/domain_conf.h | 3 +++ src/libvirt_private.syms | 1 + src/qemu/qemu_domain.c | 13 ++----------- 4 files changed, 23 insertions(+), 11 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 1b6ee3bfa6..e71e484a6f 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -31445,6 +31445,23 @@ virDomainDefHasNVMeDisk(const virDomainDef *def) } =20 =20 +bool +virDomainDefHasVFIOHostdev(const virDomainDef *def) +{ + size_t i; + + 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) + return true; + } + + return false; +} + + /** * virDomainGraphicsDefHasOpenGL: * @def: domain definition diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h index 2a067633bd..5c6c5b7a33 100644 --- a/src/conf/domain_conf.h +++ b/src/conf/domain_conf.h @@ -3614,6 +3614,9 @@ virDomainDefHasManagedPR(const virDomainDef *def); bool virDomainDefHasNVMeDisk(const virDomainDef *def); =20 +bool +virDomainDefHasVFIOHostdev(const virDomainDef *def); + bool virDomainGraphicsDefHasOpenGL(const virDomainDef *def); =20 diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index 15bfae115f..4fda747fb3 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -287,6 +287,7 @@ virDomainDefHasMemoryHotplug; virDomainDefHasNVMeDisk; virDomainDefHasUSB; virDomainDefHasVcpusOffline; +virDomainDefHasVFIOHostdev; virDomainDefLifecycleActionAllowed; virDomainDefMaybeAddController; virDomainDefMaybeAddInput; diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c index 09e5ee37f4..2a7f09ce24 100644 --- a/src/qemu/qemu_domain.c +++ b/src/qemu/qemu_domain.c @@ -11764,7 +11764,7 @@ qemuDomainGetHostdevPath(virDomainDefPtr def, bool includeVFIO =3D false; char **tmpPaths =3D NULL; int *tmpPerms =3D NULL; - size_t i, tmpNpaths =3D 0; + size_t tmpNpaths =3D 0; int perm =3D 0; =20 *npaths =3D 0; @@ -11787,16 +11787,7 @@ qemuDomainGetHostdevPath(virDomainDefPtr def, =20 perm =3D VIR_CGROUP_DEVICE_RW; if (teardown) { - size_t nvfios =3D 0; - for (i =3D 0; i < def->nhostdevs; i++) { - virDomainHostdevDefPtr tmp =3D def->hostdevs[i]; - if (tmp->mode =3D=3D VIR_DOMAIN_HOSTDEV_MODE_SUBSY= S && - tmp->source.subsys.type =3D=3D VIR_DOMAIN_HOST= DEV_SUBSYS_TYPE_PCI && - tmp->source.subsys.u.pci.backend =3D=3D VIR_DO= MAIN_HOSTDEV_PCI_BACKEND_VFIO) - nvfios++; - } - - if (nvfios =3D=3D 0) + if (!virDomainDefHasVFIOHostdev(def)) includeVFIO =3D true; } else { includeVFIO =3D true; --=20 2.21.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Fri Apr 19 16:08:06 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=1562860507; cv=none; d=zoho.com; s=zohoarc; b=I4JaMepH359qcQWEdkOph1ltgHppAwcisiZaZGn8fNrXp6saR8fIaz8yp/83SDaO7D555XNQssDYjnjrBqjIXVSkEuYrqt7g89GnyJm/m5yY1l0/ebfxTnk+kGryVEgKui1lX6kzAlBAlYS+Ds0elJ0Z3a71PPtH5goMMAbOCss= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1562860507; 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=/DlLW2YXvYsa/6ZdRzBYwFiQcAj642zSBdh7QSLwd1U=; b=n+zVz2ewfBbQqB3+68ttStiOnfHUSBLEf0h+xWE1UWw67EF0Kj/aRGTLMBwhffDwAjZziQ114uO9C+/ZSDiPg1iAp137A1+hwBdhauFMfpVRJekVVd2pLETcC7v1kk4g1ryF4uw2oOb1UkSUtuZphbXm6MZikQij4G7tPMxjx3g= 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 1562860507626762.3349131634666; Thu, 11 Jul 2019 08:55:07 -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 3779D30860A8; Thu, 11 Jul 2019 15:55:05 +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 0B51D1001B0F; Thu, 11 Jul 2019 15:55: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 BB0EE19725; Thu, 11 Jul 2019 15:55:04 +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 x6BFspRt014820 for ; Thu, 11 Jul 2019 11:54:51 -0400 Received: by smtp.corp.redhat.com (Postfix) id 28B755D973; Thu, 11 Jul 2019 15:54:51 +0000 (UTC) Received: from moe.brq.redhat.com (unknown [10.43.2.30]) by smtp.corp.redhat.com (Postfix) with ESMTP id A806018352 for ; Thu, 11 Jul 2019 15:54:50 +0000 (UTC) From: Michal Privoznik To: libvir-list@redhat.com Date: Thu, 11 Jul 2019 17:54:10 +0200 Message-Id: <7e389b790d3d56ba988ebb785a692f23cc9ce538.1562859733.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 v1 23/31] qemu_domain: Introduce NVMe path getting helpers 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.44]); Thu, 11 Jul 2019 15:55:05 +0000 (UTC) Content-Type: text/plain; charset="utf-8" Couple of places in the QEMU driver will want to know what paths are associated with NVMe disks (for instance CGroup code or namespaces code). Introduce helpers which return desired paths (for instance /dev/vfio/vfio and /dev/vfio/N). Signed-off-by: Michal Privoznik --- src/qemu/qemu_domain.c | 44 ++++++++++++++++++++++++++++++++++++++++++ src/qemu/qemu_domain.h | 6 ++++++ 2 files changed, 50 insertions(+) diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c index 2a7f09ce24..949bbace88 100644 --- a/src/qemu/qemu_domain.c +++ b/src/qemu/qemu_domain.c @@ -11723,6 +11723,50 @@ qemuDomainSupportsVideoVga(virDomainVideoDefPtr vi= deo, } =20 =20 +char * +qemuDomainGetNVMeDiskPath(const virStorageSourceNVMeDef *nvme) +{ + VIR_AUTOPTR(virPCIDevice) pci =3D NULL; + + /* All NVMe devices are VFIO PCI devices */ + if (!(pci =3D virPCIDeviceNew(nvme->pciAddr.domain, + nvme->pciAddr.bus, + nvme->pciAddr.slot, + nvme->pciAddr.function))) + return NULL; + + return virPCIDeviceGetIOMMUGroupDev(pci); +} + + +char ** +qemuDomainGetDiskNVMePaths(const virDomainDef *def, + const virStorageSource *src, + bool teardown) +{ + VIR_AUTOFREE(char *) iommuGroup =3D NULL; + VIR_AUTOSTRINGLIST paths =3D NULL; + bool includeVFIO =3D !teardown; + + if (!(iommuGroup =3D qemuDomainGetNVMeDiskPath(src->nvme))) + return NULL; + + if (virStringListAdd(&paths, iommuGroup) < 0) + return NULL; + + if (teardown && def && + !virDomainDefHasNVMeDisk(def) && + !virDomainDefHasVFIOHostdev(def)) + includeVFIO =3D true; + + if (includeVFIO && + virStringListAdd(&paths, QEMU_DEV_VFIO) < 0) + return NULL; + + VIR_RETURN_PTR(paths); +} + + /** * qemuDomainGetHostdevPath: * @def: domain definition diff --git a/src/qemu/qemu_domain.h b/src/qemu/qemu_domain.h index 3eea8b0f96..82e225088d 100644 --- a/src/qemu/qemu_domain.h +++ b/src/qemu/qemu_domain.h @@ -1011,6 +1011,12 @@ int qemuDomainCheckMonitor(virQEMUDriverPtr driver, bool qemuDomainSupportsVideoVga(virDomainVideoDefPtr video, virQEMUCapsPtr qemuCaps); =20 +char * qemuDomainGetNVMeDiskPath(const virStorageSourceNVMeDef *nvme); + +char ** qemuDomainGetDiskNVMePaths(const virDomainDef *def, + const virStorageSource *src, + bool teardown); + 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 Fri Apr 19 16:08:06 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=1562860505; cv=none; d=zoho.com; s=zohoarc; b=R+Q2hbZz600YPsyGnELLbze0yYexqMj88eJnUDYOd9jyWrKKxPWnkKGirNB4lR8B3t3FNJore7d0b//KDvIVfNjD2tuP/U+FEfw6NjLsfsu4r3otFGWlXMmjrF9JSjRa5TAD0yS58aFJt0f7QLjVnAsYBjtm0E7Toxuyr+gyeJQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1562860505; 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=qhc5FKNcGgJCDgW8SnVaL4XAwVJlH4qGe/Oya9pdvNU=; b=lw/nIF3+Emdteu4KnL9HdYDpE4hImayg5Iy9yrnitPOyrIOmbCVlFMEGWNL38u36d5TOhKHzyMkPn6L8pTLFWDXYq3pzVzknICcIvVInMRSyH8HyzAijG3XD1Nlo9egwiEhtebYccmucpx3AAQXvqfH5bqUeOyQF6l6ELIvyIdw= 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 1562860505479370.7018616335346; Thu, 11 Jul 2019 08:55:05 -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 CA177308C21F; Thu, 11 Jul 2019 15:55:02 +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 9AB2D6014E; Thu, 11 Jul 2019 15:55:02 +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 43BDA183301B; Thu, 11 Jul 2019 15:55:02 +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 x6BFspjt014829 for ; Thu, 11 Jul 2019 11:54:51 -0400 Received: by smtp.corp.redhat.com (Postfix) id E9B705D973; Thu, 11 Jul 2019 15:54:51 +0000 (UTC) Received: from moe.brq.redhat.com (unknown [10.43.2.30]) by smtp.corp.redhat.com (Postfix) with ESMTP id 73C5C5D9CC for ; Thu, 11 Jul 2019 15:54:51 +0000 (UTC) From: Michal Privoznik To: libvir-list@redhat.com Date: Thu, 11 Jul 2019 17:54: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 v1 24/31] 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.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.48]); Thu, 11 Jul 2019 15:55:03 +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 | 35 ++++++++++++++++++++++++++++++++++- 1 file changed, 34 insertions(+), 1 deletion(-) diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c index 949bbace88..cd3205a588 100644 --- a/src/qemu/qemu_domain.c +++ b/src/qemu/qemu_domain.c @@ -11831,7 +11831,8 @@ qemuDomainGetHostdevPath(virDomainDefPtr def, =20 perm =3D VIR_CGROUP_DEVICE_RW; if (teardown) { - if (!virDomainDefHasVFIOHostdev(def)) + if (!virDomainDefHasVFIOHostdev(def) && + !virDomainDefHasNVMeDisk(def)) includeVFIO =3D true; } else { includeVFIO =3D true; @@ -12415,6 +12416,22 @@ qemuDomainSetupDisk(virQEMUDriverConfigPtr cfg ATT= RIBUTE_UNUSED, int ret =3D -1; =20 for (next =3D disk->src; virStorageSourceIsBacking(next); next =3D nex= t->backingStore) { + /* NVMe disks must be checked before virStorageSourceIsLocalStorag= e() + * is called. This is because while NVMe disks are local, they don= 't + * have next->path set. */ + if (next->type =3D=3D VIR_STORAGE_TYPE_NVME) { + VIR_AUTOSTRINGLIST nvmePaths =3D NULL; + size_t i; + + if (!(nvmePaths =3D qemuDomainGetDiskNVMePaths(NULL, next, fal= se))) + goto cleanup; + + for (i =3D 0; nvmePaths[i]; i++) { + if (qemuDomainCreateDevice(nvmePaths[i], data, false) < 0) + goto cleanup; + } + } + if (!next->path || !virStorageSourceIsLocalStorage(next)) { /* Not creating device. Just continue. */ continue; @@ -13462,12 +13479,28 @@ qemuDomainNamespaceSetupDisk(virDomainObjPtr vm, virStorageSourcePtr src) { virStorageSourcePtr next; + VIR_AUTOSTRINGLIST nvmePaths =3D NULL; const char **paths =3D NULL; size_t npaths =3D 0; char *dmPath =3D NULL; int ret =3D -1; =20 for (next =3D src; virStorageSourceIsBacking(next); next =3D next->bac= kingStore) { + /* NVMe disks must be checked before virStorageSourceIsLocalStorag= e() + * is called. This is because while NVMe disks are local, they don= 't + * have next->path set. */ + if (next->type =3D=3D VIR_STORAGE_TYPE_NVME) { + size_t i; + + if (!(nvmePaths =3D qemuDomainGetDiskNVMePaths(NULL, next, fal= se))) + goto cleanup; + + for (i =3D 0; nvmePaths[i]; i++) { + if (VIR_APPEND_ELEMENT_COPY(paths, npaths, nvmePaths[i]) <= 0) + goto cleanup; + } + } + if (virStorageSourceIsEmpty(next) || !virStorageSourceIsLocalStorage(next)) { /* Not creating device. Just continue. */ --=20 2.21.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Fri Apr 19 16:08:06 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=1562860522; cv=none; d=zoho.com; s=zohoarc; b=bjHPxdbPbxvrNY4y7YatGSZTpkuxqT9OcowhWX4tC0O0vZ2MjBePxiZC1CSINAiAWT9e88+Uctb09y1VN+ZG2ea9hxLbSbFFx21z/Rzt5Tt0YbI/2izLemSeEjW/yqz780hAdDud3JBdCO4iRbB/YbOb0CkzjHvOmgvShQWjFsU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1562860522; 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=393xYt0abjrLM1X2bL4DcwYRs9uLIYnnHCQVIfyjNPc=; b=ZwOVjpJ1i0Nr3FFVmuZESLVA1OLTp2sR0nbZVDmUV4mPVqZSLs59Lr2ehg0TzNPHt41hphO22oHmPvNA6YZmUlYDkK9dzGOCV72MhdJABJ9HMwAAQWjE2YXDyxfOErMyuez8YH3MWPzAuICFzXtgHXGQlny+otD4d9YTUMlNbzE= 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 1562860522457815.5091909024682; Thu, 11 Jul 2019 08:55:22 -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 B814A30054AB; Thu, 11 Jul 2019 15:55:20 +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 8B23F1001B19; Thu, 11 Jul 2019 15:55:20 +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 4071F1833027; Thu, 11 Jul 2019 15:55:20 +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 x6BFsqWK014835 for ; Thu, 11 Jul 2019 11:54:52 -0400 Received: by smtp.corp.redhat.com (Postfix) id B62605D973; Thu, 11 Jul 2019 15:54:52 +0000 (UTC) Received: from moe.brq.redhat.com (unknown [10.43.2.30]) by smtp.corp.redhat.com (Postfix) with ESMTP id 419855D9CC for ; Thu, 11 Jul 2019 15:54:52 +0000 (UTC) From: Michal Privoznik To: libvir-list@redhat.com Date: Thu, 11 Jul 2019 17:54:12 +0200 Message-Id: <80b485d19d7fbabc44abbd3a4d106111fabe60c7.1562859733.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 v1 25/31] 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.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, 11 Jul 2019 15:55:21 +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 | 59 +++++++++++++++++++++++++++++++++--------- 1 file changed, 47 insertions(+), 12 deletions(-) diff --git a/src/qemu/qemu_cgroup.c b/src/qemu/qemu_cgroup.c index 19ca60905a..2a7fc07ac7 100644 --- a/src/qemu/qemu_cgroup.c +++ b/src/qemu/qemu_cgroup.c @@ -118,10 +118,29 @@ 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 R/W. */ + readonly =3D false; + + if (!(path =3D qemuDomainGetNVMeDiskPath(src->nvme))) + 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) && @@ -129,7 +148,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 @@ -146,6 +165,7 @@ qemuTeardownImageCgroup(virDomainObjPtr vm, virStorageSourcePtr src) { qemuDomainObjPrivatePtr priv =3D vm->privateData; + VIR_AUTOFREE(char *path) =3D NULL; int perms =3D VIR_CGROUP_DEVICE_RWM; size_t i; int ret; @@ -154,10 +174,25 @@ 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; + if (src->type =3D=3D VIR_STORAGE_TYPE_NVME) { + if (!(path =3D qemuDomainGetNVMeDiskPath(src->nvme))) + return -1; + + ret =3D virCgroupDenyDevicePath(priv->cgroup, QEMU_DEV_VFIO, perms= , true); + virDomainAuditCgroupPath(vm, priv->cgroup, "deny", + QEMU_DEV_VFIO, + virCgroupGetDevicePermsString(perms), ret= ); + if (ret < 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 (virFileExists(QEMU_DEVICE_MAPPER_CONTROL_PATH)) { @@ -184,11 +219,11 @@ qemuTeardownImageCgroup(virDomainObjPtr vm, } } =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 Fri Apr 19 16:08:06 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=1562860510; cv=none; d=zoho.com; s=zohoarc; b=V43CfxDZvB+yGOFk8JZMTijVLtDVz/7gMxXeSF3S/4aIsf2tdecMLc9/042lC8jPFlw4J6QtQOctxyyQkFkzXi2KhkB5zUheL56P8OvPrjEHx8tM54A5MORX9SopbfQI7GswLbNNxGZgbAAhJzEYk8AvZExfqE/W1mQzMMfed8w= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1562860510; 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=8lQiYLO5iQ2rNqC1AYjN1B/iPSf3hoSIXVBc/r5TMcg=; b=jC8vCv6RKNWmR7Tnv8zZ0a6C56uq2rqexnwvraAf589JFwaUOPuxPMTttOGXpUE71PSaNnTOgKTJsdSWa4i0qR8WDRA5S306a4gR9/bKAmxd9wbcjhJCZv8CivwuyDffk/1gJ8WE1HL1qBJ6rUBNPcsfHBboZUczqtBPZBkcO0g= 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 1562860510533598.6958480597845; Thu, 11 Jul 2019 08:55:10 -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 EEF70308621F; Thu, 11 Jul 2019 15:55:08 +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 C6C7960603; Thu, 11 Jul 2019 15:55: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 8070B19728; Thu, 11 Jul 2019 15:55: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 x6BFsr26014847 for ; Thu, 11 Jul 2019 11:54:53 -0400 Received: by smtp.corp.redhat.com (Postfix) id 813DA5DD65; Thu, 11 Jul 2019 15:54:53 +0000 (UTC) Received: from moe.brq.redhat.com (unknown [10.43.2.30]) by smtp.corp.redhat.com (Postfix) with ESMTP id 0D1C15D973 for ; Thu, 11 Jul 2019 15:54:52 +0000 (UTC) From: Michal Privoznik To: libvir-list@redhat.com Date: Thu, 11 Jul 2019 17:54:13 +0200 Message-Id: <74d55aaf0fad4bd7dd0c50db70c0752649522a30.1562859733.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 v1 26/31] 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.42]); Thu, 11 Jul 2019 15:55:09 +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 --- src/security/security_selinux.c | 39 ++++++++++++++------------------- 1 file changed, 17 insertions(+), 22 deletions(-) diff --git a/src/security/security_selinux.c b/src/security/security_selinu= x.c index ea20373a90..99cef3f212 100644 --- a/src/security/security_selinux.c +++ b/src/security/security_selinux.c @@ -1820,7 +1820,10 @@ virSecuritySELinuxSetImageLabelInternal(virSecurityM= anagerPtr mgr, virSecurityDeviceLabelDefPtr disk_seclabel; virSecurityDeviceLabelDefPtr parent_seclabel =3D NULL; bool remember; - int ret; + const char *path =3D src->path; + const char *tcon =3D NULL; + bool optional =3D false; + int ret =3D -1; =20 if (!src->path || !virStorageSourceIsLocalStorage(src)) return 0; @@ -1853,40 +1856,32 @@ 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 virSecuritySELinuxSetFileconOptional(mgr, - src->path, - data->file_context, - remember); + tcon =3D data->file_context; + optional =3D true; } else if (src->readonly) { - ret =3D virSecuritySELinuxSetFileconOptional(mgr, - src->path, - data->content_conte= xt, - remember); + tcon =3D data->content_context; + optional =3D true; } else if (secdef->imagelabel) { - ret =3D virSecuritySELinuxSetFileconOptional(mgr, - src->path, - secdef->imagelabel, - remember); + tcon =3D secdef->imagelabel; + optional =3D true; } else { - ret =3D 0; + return 0; } } else { - ret =3D virSecuritySELinuxSetFileconOptional(mgr, - src->path, - data->content_context, - remember); + optional =3D true; + tcon =3D data->content_context; } =20 + ret =3D virSecuritySELinuxSetFileconHelper(mgr, path, tcon, optional, = 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 Fri Apr 19 16:08:06 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=1562860514; cv=none; d=zoho.com; s=zohoarc; b=XD4Pc1W5qZqT+Jc2xPKFQVANH3sedG5BHTMHkODXLulKPjSwtRSzpOQE0CxHQ6dodF4XcgPmVxcHUZ2ewEu4FpMhi6vNSg/IInWi7huXJtLOXR6dd6asr+lK27kB/qc7F9xRV1WEJd6qIwnxEjH4Pfg9QCf7Nmf6gEyqKO5OU+A= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1562860514; 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=tSOAfHRt1ItNCPc8oED7jUMQZtn/EibjFMKq0+m+pRY=; b=HeD4iiemAenoBPCZes/rkjVGapoilCu84LeFxpxYFJ8NLAJ+77fxvaURzMw3tbAfaeYQOUtCGqNnCkspg0sOE1vX89hRJpHxew/BzuQ+8TOhKZohcDctbjw/bxLSxpcshczZgq+GmTKWhJ/Ipn3UomHr2HcbSy0kQLNWO6ZEUcs= 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 1562860514347508.70871205874914; Thu, 11 Jul 2019 08:55:14 -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 A8295B2DC8; Thu, 11 Jul 2019 15:55:12 +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 81CCE5D9CC; Thu, 11 Jul 2019 15:55:12 +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 412BF1833022; Thu, 11 Jul 2019 15:55:12 +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 x6BFssQn014857 for ; Thu, 11 Jul 2019 11:54:54 -0400 Received: by smtp.corp.redhat.com (Postfix) id 4C90F5D973; Thu, 11 Jul 2019 15:54:54 +0000 (UTC) Received: from moe.brq.redhat.com (unknown [10.43.2.30]) by smtp.corp.redhat.com (Postfix) with ESMTP id CC9A45D9CC for ; Thu, 11 Jul 2019 15:54:53 +0000 (UTC) From: Michal Privoznik To: libvir-list@redhat.com Date: Thu, 11 Jul 2019 17:54:14 +0200 Message-Id: <1b06b5ac0fe51b19b201b0b7b4cb568cf12b5af5.1562859733.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 v1 27/31] 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.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Thu, 11 Jul 2019 15:55:13 +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_dac.c | 38 ++++++++++++++++++++++ src/security/security_selinux.c | 56 ++++++++++++++++++++++++++++----- 2 files changed, 87 insertions(+), 7 deletions(-) diff --git a/src/security/security_dac.c b/src/security/security_dac.c index 137daf5d28..d0b84c99b0 100644 --- a/src/security/security_dac.c +++ b/src/security/security_dac.c @@ -912,6 +912,23 @@ 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; + VIR_AUTOUNREF(virPCIDevicePtr) pci =3D virPCIDeviceNew(nvme->pciAd= dr.domain, + nvme->pciAddr= .bus, + nvme->pciAddr= .slot, + nvme->pciAddr= .function); + if (!pci || + !(vfioGroupDev =3D virPCIDeviceGetIOMMUGroupDev(pci))) + 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 @@ -1001,6 +1018,27 @@ 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; + VIR_AUTOUNREF(virPCIDevicePtr) pci =3D virPCIDeviceNew(nvme->pciAd= dr.domain, + nvme->pciAddr= .bus, + nvme->pciAddr= .slot, + nvme->pciAddr= .function); + if (!pci || + !(vfioGroupDev =3D virPCIDeviceGetIOMMUGroupDev(pci))) + 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 99cef3f212..a2e4dcb6da 100644 --- a/src/security/security_selinux.c +++ b/src/security/security_selinux.c @@ -1751,9 +1751,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) @@ -1785,9 +1784,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); @@ -1795,7 +1801,26 @@ 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; + VIR_AUTOUNREF(virPCIDevicePtr) pci =3D virPCIDeviceNew(nvme->pciAd= dr.domain, + nvme->pciAddr= .bus, + nvme->pciAddr= .slot, + nvme->pciAddr= .function); + if (!pci || + !(vfioGroupDev =3D virPCIDeviceGetIOMMUGroupDev(pci))) + 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 @@ -1820,6 +1845,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; bool optional =3D false; @@ -1880,6 +1906,22 @@ 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; + VIR_AUTOUNREF(virPCIDevicePtr) pci =3D virPCIDeviceNew(nvme->pciAd= dr.domain, + nvme->pciAddr= .bus, + nvme->pciAddr= .slot, + nvme->pciAddr= .function); + if (!pci || + !(vfioGroupDev =3D virPCIDeviceGetIOMMUGroupDev(pci))) + return -1; + + path =3D vfioGroupDev; + } + ret =3D virSecuritySELinuxSetFileconHelper(mgr, path, tcon, optional, = 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 Fri Apr 19 16:08:06 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=1562860518; cv=none; d=zoho.com; s=zohoarc; b=N76OrZ6Th1IFbgDKjAR5It6WXYmHQnnO0okibVTwxeQ15VSOu4tpa021CSHh2AmzC+B4AvuOv5A6LnREUoBtkYokBTYJRSUlu3t6Iq9cHE4kf/0WTFVGMQXL2caSF+k09F4K9gaQd6i1L41ZU+L6tHP/kn9GyGigfg8Ns1n9rNQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1562860518; 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=nPf7ka8EuaMVmYqYJbBZkHvz2k/miy+xMLoi9C9xGOQ=; b=Iz+duXi82NF5sIZ1o2d1JRjMS3kNXnHIL8T0lCDqWH6Uf8ArWHfpeXZI+79MDOd3IGB95Oc4isPoUZDck15zV0RJoOvIIcBRIAV4DwDal661K0sSG+ZYxAuuWBZJ8lvudMMhBaMotXI9QR63BbqMEb5pj19Cqq6LDLXhFwKtvEY= 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 1562860518200458.655813929519; Thu, 11 Jul 2019 08:55:18 -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 87DA030C31AB; Thu, 11 Jul 2019 15:55:16 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 5EBC660159; Thu, 11 Jul 2019 15:55:16 +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 084A51833026; Thu, 11 Jul 2019 15:55:16 +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 x6BFstbP014869 for ; Thu, 11 Jul 2019 11:54:55 -0400 Received: by smtp.corp.redhat.com (Postfix) id 181105D9CC; Thu, 11 Jul 2019 15:54:55 +0000 (UTC) Received: from moe.brq.redhat.com (unknown [10.43.2.30]) by smtp.corp.redhat.com (Postfix) with ESMTP id 982245D973 for ; Thu, 11 Jul 2019 15:54:54 +0000 (UTC) From: Michal Privoznik To: libvir-list@redhat.com Date: Thu, 11 Jul 2019 17:54:15 +0200 Message-Id: <46893874a43df02514e1edb197f890e81736cee2.1562859733.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 v1 28/31] 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.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.40]); Thu, 11 Jul 2019 15:55:17 +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 02e84edc15..87f506b09e 100644 --- a/src/qemu/qemu_capabilities.c +++ b/src/qemu/qemu_capabilities.c @@ -533,6 +533,9 @@ VIR_ENUM_IMPL(virQEMUCaps, "x86-max-cpu", "cpu-unavailable-features", "canonical-cpu-features", + + /* 335 */ + "drive-nvme", ); =20 =20 @@ -1274,6 +1277,7 @@ static struct virQEMUCapsStringFlags virQEMUCapsQMPSc= hemaQueries[] =3D { { "query-iothreads/ret-type/poll-max-ns", QEMU_CAPS_IOTHREAD_POLLING }, { "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/+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 915ba6cb2e..fc288b023c 100644 --- a/src/qemu/qemu_capabilities.h +++ b/src/qemu/qemu_capabilities.h @@ -515,6 +515,9 @@ typedef enum { /* virQEMUCapsFlags grouping marker for = syntax-check */ QEMU_CAPS_CPU_UNAVAILABLE_FEATURES, /* "unavailable-features" CPU prop= erty */ QEMU_CAPS_CANONICAL_CPU_FEATURES, /* avoid CPU feature aliases */ =20 + /* 335 */ + 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 140da91b86..3b72024216 100644 --- a/tests/qemucapabilitiesdata/caps_2.12.0.aarch64.xml +++ b/tests/qemucapabilitiesdata/caps_2.12.0.aarch64.xml @@ -153,6 +153,7 @@ + 2011090 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 40718981a8..d848e55fc1 100644 --- a/tests/qemucapabilitiesdata/caps_3.0.0.ppc64.xml +++ b/tests/qemucapabilitiesdata/caps_3.0.0.ppc64.xml @@ -151,6 +151,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 c6394db602..1c6fd4dd83 100644 --- a/tests/qemucapabilitiesdata/caps_3.0.0.x86_64.xml +++ b/tests/qemucapabilitiesdata/caps_3.0.0.x86_64.xml @@ -198,6 +198,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 ee6921ff92..dc340838a8 100644 --- a/tests/qemucapabilitiesdata/caps_3.1.0.ppc64.xml +++ b/tests/qemucapabilitiesdata/caps_3.1.0.ppc64.xml @@ -156,6 +156,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 a8cb061bf3..f1517fa365 100644 --- a/tests/qemucapabilitiesdata/caps_3.1.0.x86_64.xml +++ b/tests/qemucapabilitiesdata/caps_3.1.0.x86_64.xml @@ -201,6 +201,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 250b7edd52..d2966b6045 100644 --- a/tests/qemucapabilitiesdata/caps_4.0.0.aarch64.xml +++ b/tests/qemucapabilitiesdata/caps_4.0.0.aarch64.xml @@ -163,6 +163,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 24b55002a6..4afbc543cc 100644 --- a/tests/qemucapabilitiesdata/caps_4.0.0.ppc64.xml +++ b/tests/qemucapabilitiesdata/caps_4.0.0.ppc64.xml @@ -168,6 +168,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 230e1e7c99..1b8137612a 100644 --- a/tests/qemucapabilitiesdata/caps_4.0.0.riscv32.xml +++ b/tests/qemucapabilitiesdata/caps_4.0.0.riscv32.xml @@ -166,6 +166,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 4b2f4cf628..bd06a816d8 100644 --- a/tests/qemucapabilitiesdata/caps_4.0.0.riscv64.xml +++ b/tests/qemucapabilitiesdata/caps_4.0.0.riscv64.xml @@ -166,6 +166,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 a1ac2587a0..82326dec79 100644 --- a/tests/qemucapabilitiesdata/caps_4.0.0.s390x.xml +++ b/tests/qemucapabilitiesdata/caps_4.0.0.s390x.xml @@ -131,6 +131,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 716b756979..b8b46a7fa7 100644 --- a/tests/qemucapabilitiesdata/caps_4.0.0.x86_64.xml +++ b/tests/qemucapabilitiesdata/caps_4.0.0.x86_64.xml @@ -205,6 +205,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 9cbf65b405..6bbe0603d3 100644 --- a/tests/qemucapabilitiesdata/caps_4.1.0.x86_64.xml +++ b/tests/qemucapabilitiesdata/caps_4.1.0.x86_64.xml @@ -207,6 +207,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 Fri Apr 19 16:08:06 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=1562860526; cv=none; d=zoho.com; s=zohoarc; b=A8RuFiJfVfPc0/OdT752Sf3MkmqqsERXj+OlaeemB9w87vB2pR5QVweC3F5wxcBlvvUYwXTX/kLxUt+OjDhBCtCYeI9crEeIPcHFa6eC+0hsZZu/0ZpjfVueyHycxfT9xBu5lUy/DbB3CSnJevqiolcBO1VD96hjfo5sFc/Gg8E= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1562860526; 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=17SP+zh64DaoMY8mvvG7AB1eAYSmsdsM9VzEPfwRz9Y=; b=jjXBIMF2zoqN8oES53eoS3EbejZ9BsBM+sAa8WkzaAiDVfOEOR8u7cC8xfpdtXqyReiG4I9NDfflSqEHhZDFeyQ8Le+eLWWtIhiacEdlSQYj4FlYLFVO2G4AWtkRDV/x1venbZqdo9t/Q3XYB6zEl22nb/W/oLuAhvhCK40XzOU= 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 1562860526280641.8109042352451; Thu, 11 Jul 2019 08:55:26 -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 A679F3092677; Thu, 11 Jul 2019 15:55:24 +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 8236D60156; Thu, 11 Jul 2019 15:55:24 +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 3C201183302A; Thu, 11 Jul 2019 15:55:24 +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 x6BFstw8014877 for ; Thu, 11 Jul 2019 11:54:55 -0400 Received: by smtp.corp.redhat.com (Postfix) id D89F85D973; Thu, 11 Jul 2019 15:54:55 +0000 (UTC) Received: from moe.brq.redhat.com (unknown [10.43.2.30]) by smtp.corp.redhat.com (Postfix) with ESMTP id 63FE75D9CC for ; Thu, 11 Jul 2019 15:54:55 +0000 (UTC) From: Michal Privoznik To: libvir-list@redhat.com Date: Thu, 11 Jul 2019 17:54:16 +0200 Message-Id: <6cd7985a55b2b1cff5106968ae004329b876fbca.1562859733.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 v1 29/31] 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.5.16 (mx1.redhat.com [10.5.110.43]); Thu, 11 Jul 2019 15:55:25 +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 | 52 +++++++++++++++++++ tests/qemuxml2argvtest.c | 1 + 5 files changed, 87 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 5eeb3757f1..bf49b7bc7c 100644 --- a/src/qemu/qemu_block.c +++ b/src/qemu/qemu_block.c @@ -992,6 +992,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) @@ -1049,8 +1068,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 927641cf46..e42377927e 100644 --- a/src/qemu/qemu_command.c +++ b/src/qemu/qemu_command.c @@ -1594,6 +1594,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 aa09ef175a..ebe35e6363 100644 --- a/src/qemu/qemu_process.c +++ b/src/qemu/qemu_process.c @@ -5294,6 +5294,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..5ff41de7b9 --- /dev/null +++ b/tests/qemuxml2argvdata/disk-nvme.x86_64-latest.args @@ -0,0 +1,52 @@ +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,\ +key-secret=3Dvirtio-disk3-luks-secret0,format=3Dluks,if=3Dnone,id=3Ddrive-= virtio-disk3 \ +-device virtio-blk-pci,scsi=3Doff,bus=3Dpci.0,addr=3D0x7,drive=3Ddrive-vir= tio-disk3,\ +id=3Dvirtio-disk3 \ +-sandbox on,obsolete=3Ddeny,elevateprivileges=3Ddeny,spawn=3Ddeny,\ +resourcecontrol=3Ddeny \ +-msg timestamp=3Don diff --git a/tests/qemuxml2argvtest.c b/tests/qemuxml2argvtest.c index 0ac128be00..d4a16c35a6 100644 --- a/tests/qemuxml2argvtest.c +++ b/tests/qemuxml2argvtest.c @@ -1068,6 +1068,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 Fri Apr 19 16:08:06 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=1562860530; cv=none; d=zoho.com; s=zohoarc; b=gXg9b9q4thAP2fXoBejrR2xrDha5eEtis8G2uNPrnAcKskknabDs34eUag0ockjNDIg0qImYoAjdWU/XnwI0D3A21knbMQtSpVNeTP/qXOf2rUA2nVVQ9u86RzAYqJmflux3Jp9CnJg1NtsYTNHOoCAv4jykQOJsr8FWdQUvyCI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1562860530; 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=vu3fvBtEwUzv2kw+zHvLernry95goe/Fkse3alsOQNU=; b=fmkBRJqbTQ89PwnTVyFdLEnHgrNhNp20KFlxjm85pnRLJOMruJgJ2wudqUHtfGLGJMMUK6JnY/SRhTE6o53fKS0+TeHO5Iiaw+D03M7OMpj5iiyn7wZudERLchay6KngPN3d/pMlWIqtY9MJiLmpa9fa9vQDDQWBMPHI/qejT8g= 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 1562860530132853.6242298066278; Thu, 11 Jul 2019 08:55:30 -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 64AF4C05E14C; Thu, 11 Jul 2019 15:55:28 +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 3C8C75D720; Thu, 11 Jul 2019 15:55:28 +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 036691973A; Thu, 11 Jul 2019 15:55:28 +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 x6BFsugN014882 for ; Thu, 11 Jul 2019 11:54:56 -0400 Received: by smtp.corp.redhat.com (Postfix) id A432C5D973; Thu, 11 Jul 2019 15:54:56 +0000 (UTC) Received: from moe.brq.redhat.com (unknown [10.43.2.30]) by smtp.corp.redhat.com (Postfix) with ESMTP id 300945D9CC for ; Thu, 11 Jul 2019 15:54:56 +0000 (UTC) From: Michal Privoznik To: libvir-list@redhat.com Date: Thu, 11 Jul 2019 17:54:17 +0200 Message-Id: <0e9c14aed4c59512009473831f9c1eb01eaf59b0.1562859733.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 v1 30/31] 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.5.16 (mx1.redhat.com [10.5.110.32]); Thu, 11 Jul 2019 15:55:28 +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 7e9c1a1649..3c6c0da3a0 100644 --- a/src/qemu/qemu_hotplug.c +++ b/src/qemu/qemu_hotplug.c @@ -624,13 +624,13 @@ qemuDomainAttachDiskGeneric(virQEMUDriverPtr driver, VIR_AUTOFREE(char *) corAlias =3D NULL; =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 (virQEMUCapsGet(priv->qemuCaps, QEMU_CAPS_BLOCKDEV)) { if (disk->copy_on_read =3D=3D VIR_TRISTATE_SWITCH_ON && @@ -647,13 +647,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 @@ -674,7 +674,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); @@ -683,6 +683,8 @@ qemuDomainAttachDiskGeneric(virQEMUDriverPtr driver, ret =3D 0; =20 cleanup: + if (ret < 0) + ignore_value(qemuDomainStorageSourceChainAccessRevoke(driver, vm, = disk->src)); qemuDomainSecretDiskDestroy(disk); VIR_FREE(devstr); return ret; @@ -700,9 +702,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 Fri Apr 19 16:08:06 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=1562860522; cv=none; d=zoho.com; s=zohoarc; b=IUJocjohuVQyVYl3+TYnllf9uB83FnQiIv7Jh8PyQs1D0x7s1WAhFjojobj1Bl9zdrLHtJq3WhEnTreb96dQoXtO8hsJa2IiwG80WYrOh0DlvTnnqe4SsYu8JD09QUaWlbO+xMZZjLVkbgab41C21u2kNV86dt1CvtrMl4mJjp8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1562860522; 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=wXx+Ub/3HBLgbv12XbFmOlYfKQx20XCmothBu/p+4nw=; b=KWKcsaZlKiUXA09Y453qe0DUMgYjypfKG3o6xYcZyzISLnNkpYhfg1zPtn6wDUuyXICvL5sCfNpFk+1/ymTPb2H4tQVqTpSQtSjnlzmFsxJa4GogBOkEafXekkZKEQeHTl3+3OXyIR4PMpKKpS3l2PHcrZTppZBA/p//cIwWhx4= 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 1562860522595623.9392956590368; Thu, 11 Jul 2019 08:55:22 -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 DA7DEC059B9F; Thu, 11 Jul 2019 15:55: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 AE6E75C220; Thu, 11 Jul 2019 15:55:20 +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 6285119734; Thu, 11 Jul 2019 15:55:20 +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 x6BFsvIc014894 for ; Thu, 11 Jul 2019 11:54:57 -0400 Received: by smtp.corp.redhat.com (Postfix) id 704835D9CC; Thu, 11 Jul 2019 15:54:57 +0000 (UTC) Received: from moe.brq.redhat.com (unknown [10.43.2.30]) by smtp.corp.redhat.com (Postfix) with ESMTP id EFA545D973 for ; Thu, 11 Jul 2019 15:54:56 +0000 (UTC) From: Michal Privoznik To: libvir-list@redhat.com Date: Thu, 11 Jul 2019 17:54:18 +0200 Message-Id: <3e395452178a96c2a6bb1d8f5e411239c6242f4c.1562859733.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 v1 31/31] 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.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.32]); Thu, 11 Jul 2019 15:55:21 +0000 (UTC) Content-Type: text/plain; charset="utf-8" Signed-off-by: Michal Privoznik --- src/qemu/qemu_hotplug.c | 65 +++++++++++++++++++++++++++++++++++++---- 1 file changed, 60 insertions(+), 5 deletions(-) diff --git a/src/qemu/qemu_hotplug.c b/src/qemu/qemu_hotplug.c index 3c6c0da3a0..6dbff23aa0 100644 --- a/src/qemu/qemu_hotplug.c +++ b/src/qemu/qemu_hotplug.c @@ -605,6 +605,54 @@ qemuDomainChangeEjectableMedia(virQEMUDriverPtr driver, } =20 =20 +static int +qemuDomainStorageSourcePrepareDisk(virQEMUDriverPtr driver, + virDomainObjPtr vm, + virDomainDiskDefPtr disk, + bool teardown) +{ + int rc; + bool adjustMemlock =3D false; + bool reattach =3D false; + + if (!virDomainDefHasNVMeDisk(vm->def) && + !virStorageSourceChainHasNVMe(disk->src)) + return 0; + + if (teardown) { + adjustMemlock =3D true; + reattach =3D true; + goto rollback; + } + + /* Tentatively add disk to domain def so that memlock limit can be com= puted. */ + vm->def->disks[vm->def->ndisks++] =3D disk; + rc =3D qemuDomainAdjustMaxMemLock(vm); + vm->def->disks[--vm->def->ndisks] =3D NULL; + + if (rc < 0) + return -1; + + adjustMemlock =3D true; + + if (qemuHostdevPrepareNVMeDevices(driver, vm->def->name, &disk, 1) < 0) + return -1; + + reattach =3D true; + + return 0; + + rollback: + if (reattach) + qemuHostdevReAttachNVMeDevices(driver, vm->def->name, &disk, 1); + + if (adjustMemlock) + qemuDomainAdjustMaxMemLock(vm); + + return 0; +} + + /** * qemuDomainAttachDiskGeneric: * @@ -623,8 +671,14 @@ qemuDomainAttachDiskGeneric(virQEMUDriverPtr driver, VIR_AUTOPTR(virJSONValue) corProps =3D NULL; VIR_AUTOFREE(char *) corAlias =3D NULL; =20 + if (VIR_REALLOC_N(vm->def->disks, vm->def->ndisks + 1) < 0) + return -1; + + if (qemuDomainStorageSourcePrepareDisk(driver, vm, disk, false) < 0) + return -1; + if (qemuDomainStorageSourceChainAccessAllow(driver, vm, disk->src) < 0) - return -1; + goto cleanup; =20 if (qemuAssignDeviceDiskAlias(vm->def, disk, priv->qemuCaps) < 0) goto cleanup; @@ -649,9 +703,6 @@ qemuDomainAttachDiskGeneric(virQEMUDriverPtr driver, if (!(devstr =3D qemuBuildDiskDeviceStr(vm->def, disk, 0, priv->qemuCa= ps))) goto cleanup; =20 - if (VIR_REALLOC_N(vm->def->disks, vm->def->ndisks + 1) < 0) - goto cleanup; - if (qemuHotplugAttachManagedPR(driver, vm, disk->src, QEMU_ASYNC_JOB_N= ONE) < 0) goto cleanup; =20 @@ -683,8 +734,10 @@ qemuDomainAttachDiskGeneric(virQEMUDriverPtr driver, ret =3D 0; =20 cleanup: - if (ret < 0) + if (ret < 0) { ignore_value(qemuDomainStorageSourceChainAccessRevoke(driver, vm, = disk->src)); + qemuDomainStorageSourcePrepareDisk(driver, vm, disk, true); + } qemuDomainSecretDiskDestroy(disk); VIR_FREE(devstr); return ret; @@ -4267,6 +4320,8 @@ qemuDomainRemoveDiskDevice(virQEMUDriverPtr driver, dev.data.disk =3D disk; ignore_value(qemuRemoveSharedDevice(driver, &dev, vm->def->name)); =20 + qemuDomainStorageSourcePrepareDisk(driver, vm, disk, true); + if (virStorageSourceChainHasManagedPR(disk->src) && qemuHotplugRemoveManagedPR(driver, vm, QEMU_ASYNC_JOB_NONE) < 0) goto cleanup; --=20 2.21.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list