From nobody Fri Apr 26 22:05:19 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 207.211.31.81 as permitted sender) client-ip=207.211.31.81; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-1.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 207.211.31.81 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=1575296832; cv=none; d=zohomail.com; s=zohoarc; b=Rk3gHZtEDAHpAV70mok0Iu4KNeOew6QCYSX/decEQh/RcOxtxylLXaWHbpuKspxtqxnVj/YyTdoeFMNhNm4TFF/PVZ2zpDlxieWvESg1kO/010uLdMsuNazIcwcLph+vsGoRShmWzJDa7jpcK8e/BGRpXWLYxIPVWz75zG6DizY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1575296832; 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; bh=4GBMJcjAoIoCtIjkdsMW49zFc3S6Z+IjcwRKM7AzrZE=; b=SyDem1Dz/BMzGL/zbxFffbWPv3DNOzkqn/ItR9YZSHnd45Z1LZpig/n4VLs4j7gA9NyFNqQiNAnY/wZaV8ZQlWNHtAhV6u6gLFULWnvWb7tV5ysJkMmQb4+hi0uJZQmbGZcninlTy/rKDNgL4F74RPlu9/Yz5trYH/t8JvN65dk= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 207.211.31.81 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from us-smtp-delivery-1.mimecast.com (us-smtp-2.mimecast.com [207.211.31.81]) by mx.zohomail.com with SMTPS id 1575296832684885.4158437064136; Mon, 2 Dec 2019 06:27:12 -0800 (PST) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-403-rteU7GqIOFqkFJseBUeZVg-1; Mon, 02 Dec 2019 09:27:10 -0500 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 mimecast-mx01.redhat.com (Postfix) with ESMTPS id 6C82A802CAE; Mon, 2 Dec 2019 14:27:04 +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 89BC35D6BE; Mon, 2 Dec 2019 14:27:03 +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 67B7518089CD; Mon, 2 Dec 2019 14:27:00 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id xB2EQxdg027245 for ; Mon, 2 Dec 2019 09:26:59 -0500 Received: by smtp.corp.redhat.com (Postfix) id 54FBF67662; Mon, 2 Dec 2019 14:26:59 +0000 (UTC) Received: from moe.redhat.com (unknown [10.43.2.30]) by smtp.corp.redhat.com (Postfix) with ESMTP id D236A6764D for ; Mon, 2 Dec 2019 14:26:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1575296831; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=4GBMJcjAoIoCtIjkdsMW49zFc3S6Z+IjcwRKM7AzrZE=; b=A7YMg13kl9n/j/a5GIlY99Go8c7ve/5sQyfA0U916dvCbMTHXqQLoFwOXxVCJk8idYE1O8 hSR5lGV3VohX04/zJ778KcZorztZh8MuSF9nJRuAxBxgClEtVn7v1E2olOy7miBYXyIG3m CtczYLcwpJs1VbQaPFq/yA5JtXzJa/k= From: Michal Privoznik To: libvir-list@redhat.com Date: Mon, 2 Dec 2019 15:26:24 +0100 Message-Id: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v3 01/30] qemu: Explicitly add/remove /dev/vfio/vfio to/from NS/CGroups X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , 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-MC-Unique: rteU7GqIOFqkFJseBUeZVg-1 X-Mimecast-Spam-Score: 0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" In near future, the decision what to do with /dev/vfio/vfio with respect to domain namespace and CGroup is going to be moved out of qemuDomainGetHostdevPath() because there will be some other types of devices than hostdevs that need access to VFIO. All functions that I'm changing (except qemuSetupHostdevCgroup()) assume that hostdev we are adding/removing to VM is not in the definition yet (because of how qemuDomainNeedsVFIO() is written). Fortunately, this assumption is true. For qemuSetupHostdevCgroup(), the worst thing that may happen is that we allow /dev/vfio/vfio which was already allowed. Signed-off-by: Michal Privoznik Reviewed-by: Cole Robinson --- src/qemu/qemu_cgroup.c | 47 +++++++++++++++++++++++++++++++++++++++++- src/qemu/qemu_domain.c | 36 ++++++++++++++++++++++++++++++++ 2 files changed, 82 insertions(+), 1 deletion(-) diff --git a/src/qemu/qemu_cgroup.c b/src/qemu/qemu_cgroup.c index 31cf71146b..65b148cd83 100644 --- a/src/qemu/qemu_cgroup.c +++ b/src/qemu/qemu_cgroup.c @@ -25,6 +25,7 @@ #include "qemu_domain.h" #include "qemu_process.h" #include "qemu_extdevice.h" +#include "qemu_hostdev.h" #include "virlog.h" #include "viralloc.h" #include "virerror.h" @@ -359,6 +360,17 @@ qemuTeardownInputCgroup(virDomainObjPtr vm, } =20 =20 +/** + * qemuSetupHostdevCgroup: + * vm: domain object + * @dev: device to allow + * + * For given host device @dev allow access to in Cgroups. + * Note, @dev must not be in @vm's definition. + * + * Returns: 0 on success, + * -1 otherwise. + */ int qemuSetupHostdevCgroup(virDomainObjPtr vm, virDomainHostdevDefPtr dev) @@ -385,6 +397,16 @@ qemuSetupHostdevCgroup(virDomainObjPtr vm, goto cleanup; } =20 + if (qemuHostdevNeedsVFIO(dev)) { + VIR_DEBUG("Cgroup allow %s perms=3D%d", QEMU_DEV_VFIO, VIR_CGROUP_= DEVICE_RW); + rv =3D virCgroupAllowDevicePath(priv->cgroup, QEMU_DEV_VFIO, + VIR_CGROUP_DEVICE_RW, false); + virDomainAuditCgroupPath(vm, priv->cgroup, "allow", + QEMU_DEV_VFIO, "rw", rv); + if (rv < 0) + goto cleanup; + } + ret =3D 0; =20 cleanup: @@ -395,9 +417,21 @@ qemuSetupHostdevCgroup(virDomainObjPtr vm, return ret; } =20 + +/** + * qemuTeardownHostdevCgroup: + * @vm: doamin object + * @dev: device to tear down + * + * For given host device @dev deny access to it in CGroups. + * Note, @dev must not be in @vm's definition. + * + * Returns: 0 on success, + * -1 otherwise. + */ int qemuTeardownHostdevCgroup(virDomainObjPtr vm, - virDomainHostdevDefPtr dev) + virDomainHostdevDefPtr dev) { qemuDomainObjPrivatePtr priv =3D vm->privateData; char **path =3D NULL; @@ -421,6 +455,17 @@ qemuTeardownHostdevCgroup(virDomainObjPtr vm, goto cleanup; } =20 + if (qemuHostdevNeedsVFIO(dev) && + !qemuDomainNeedsVFIO(vm->def)) { + VIR_DEBUG("Cgroup deny " QEMU_DEV_VFIO); + rv =3D virCgroupDenyDevicePath(priv->cgroup, QEMU_DEV_VFIO, + VIR_CGROUP_DEVICE_RWM, false); + virDomainAuditCgroupPath(vm, priv->cgroup, "deny", + QEMU_DEV_VFIO, "rwm", rv); + if (rv < 0) + goto cleanup; + } + ret =3D 0; cleanup: for (i =3D 0; i < npaths; i++) diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c index d1596a28ca..550ae848df 100644 --- a/src/qemu/qemu_domain.c +++ b/src/qemu/qemu_domain.c @@ -13542,6 +13542,10 @@ qemuDomainSetupHostdev(virQEMUDriverConfigPtr cfg = G_GNUC_UNUSED, goto cleanup; } =20 + if (qemuHostdevNeedsVFIO(dev) && + qemuDomainCreateDevice(QEMU_DEV_VFIO, data, false) < 0) + goto cleanup; + ret =3D 0; cleanup: for (i =3D 0; i < npaths; i++) @@ -14565,6 +14569,17 @@ qemuDomainNamespaceTeardownDisk(virDomainObjPtr vm= G_GNUC_UNUSED, } =20 =20 +/** + * qemuDomainNamespaceSetupHostdev: + * @vm: domain object + * @hostdev: hostdev to create in @vm's namespace + * + * For given @hostdev, create its devfs representation (if it has one) in + * domain namespace. Note, @hostdev must not be in @vm's definition. + * + * Returns: 0 on success, + * -1 otherwise. + */ int qemuDomainNamespaceSetupHostdev(virDomainObjPtr vm, virDomainHostdevDefPtr hostdev) @@ -14579,6 +14594,11 @@ qemuDomainNamespaceSetupHostdev(virDomainObjPtr vm, if (qemuDomainNamespaceMknodPaths(vm, (const char **)paths, npaths) < = 0) goto cleanup; =20 + if (qemuHostdevNeedsVFIO(hostdev) && + !qemuDomainNeedsVFIO(vm->def) && + qemuDomainNamespaceMknodPath(vm, QEMU_DEV_VFIO) < 0) + goto cleanup; + ret =3D 0; cleanup: for (i =3D 0; i < npaths; i++) @@ -14588,6 +14608,17 @@ qemuDomainNamespaceSetupHostdev(virDomainObjPtr vm, } =20 =20 +/** + * qemuDomainNamespaceTeardownHostdev: + * @vm: domain object + * @hostdev: hostdev to remove in @vm's namespace + * + * For given @hostdev, remove its devfs representation (if it has one) in + * domain namespace. Note, @hostdev must not be in @vm's definition. + * + * Returns: 0 on success, + * -1 otherwise. + */ int qemuDomainNamespaceTeardownHostdev(virDomainObjPtr vm, virDomainHostdevDefPtr hostdev) @@ -14603,6 +14634,11 @@ qemuDomainNamespaceTeardownHostdev(virDomainObjPtr= vm, if (qemuDomainNamespaceUnlinkPaths(vm, (const char **)paths, npaths) <= 0) goto cleanup; =20 + if (qemuHostdevNeedsVFIO(hostdev) && + !qemuDomainNeedsVFIO(vm->def) && + qemuDomainNamespaceUnlinkPath(vm, QEMU_DEV_VFIO) < 0) + goto cleanup; + ret =3D 0; cleanup: for (i =3D 0; i < npaths; i++) --=20 2.23.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Fri Apr 26 22:05:19 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 207.211.31.120 as permitted sender) client-ip=207.211.31.120; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-1.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 207.211.31.120 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=1575296849; cv=none; d=zohomail.com; s=zohoarc; b=Sdhyl32r0ZDtrJEX0FjR6/W0M6O/ssjB+p2qJFcD3onYV/x1DasEFBYUulDCWJqBhfAbvYIisKCMyqgmlOkvO3FF4RbrQ8cBpCfsTu1GXW2T8ju2okH4PHjXrTajXFxJr/z8+2sp4lEXkyXlsAF1y/AlmHk02i4WKsNdAcnOFYQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1575296849; 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; bh=Y67dFitmR98jNbVr8NYs9/j+PAWdx7Q3mlJtrs5yHOY=; b=doYw64kstDAXeEAMKkLfsJ3bI0E2UJgpQD05YzgiP31R6ovJ14dlG7dLRjN1hv9MFkaVt6MvQ8HmG2Vr4m9q/Ewpnq6NPPz3bUQW28VwbTwn7e4Z9HmC+deulABm5e/gH/2PR53HJdiYe7fwuWxB6/0TdvAV3xrDjdaZMAXryC8= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 207.211.31.120 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from us-smtp-1.mimecast.com (us-smtp-delivery-1.mimecast.com [207.211.31.120]) by mx.zohomail.com with SMTPS id 1575296849687479.19444680819095; Mon, 2 Dec 2019 06:27:29 -0800 (PST) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-291-xb470t2HPy2GZAd0jrjS5A-1; Mon, 02 Dec 2019 09:27:27 -0500 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 mimecast-mx01.redhat.com (Postfix) with ESMTPS id 35A9B1014996; Mon, 2 Dec 2019 14:27:21 +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 EFE4E5C578; Mon, 2 Dec 2019 14:27: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 8D8A918089D0; Mon, 2 Dec 2019 14:27:20 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id xB2ER0hf027255 for ; Mon, 2 Dec 2019 09:27:00 -0500 Received: by smtp.corp.redhat.com (Postfix) id 25D8067662; Mon, 2 Dec 2019 14:27:00 +0000 (UTC) Received: from moe.redhat.com (unknown [10.43.2.30]) by smtp.corp.redhat.com (Postfix) with ESMTP id A2AFD6764D for ; Mon, 2 Dec 2019 14:26:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1575296848; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=Y67dFitmR98jNbVr8NYs9/j+PAWdx7Q3mlJtrs5yHOY=; b=SgXbscjxAUysrmkISe/aAo3qCjLJGgMaoki5izKoc60fpm5BbGdXRgsRO8wC8TSCs5e/sT d2vdyPJNufC3M+2dGIQ17aek2Xf09HiGBSNG0M8VtXDnhUZ1j3DHVdClzIgnPni7JYZ6DB lcuazhwnDudmsqrFqyf/82z3k045Z0U= From: Michal Privoznik To: libvir-list@redhat.com Date: Mon, 2 Dec 2019 15:26:25 +0100 Message-Id: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v3 02/30] qemuDomainGetHostdevPath: Use more g_autoptr()/g_autofree 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: , 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-MC-Unique: xb470t2HPy2GZAd0jrjS5A-1 X-Mimecast-Spam-Score: 0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" There are several variables which could be automatically freed upon return from the function. I'm not changing @tmpPaths (which is a string list) because it is going to be removed in next commit. Signed-off-by: Michal Privoznik Reviewed-by: Cole Robinson --- src/qemu/qemu_domain.c | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c index 550ae848df..6daae24c3d 100644 --- a/src/qemu/qemu_domain.c +++ b/src/qemu/qemu_domain.c @@ -12891,14 +12891,14 @@ qemuDomainGetHostdevPath(virDomainDefPtr def, virDomainHostdevSubsysSCSIPtr scsisrc =3D &dev->source.subsys.u.scsi; virDomainHostdevSubsysSCSIVHostPtr hostsrc =3D &dev->source.subsys.u.s= csi_host; virDomainHostdevSubsysMediatedDevPtr mdevsrc =3D &dev->source.subsys.u= .mdev; - virPCIDevicePtr pci =3D NULL; - virUSBDevicePtr usb =3D NULL; - virSCSIDevicePtr scsi =3D NULL; - virSCSIVHostDevicePtr host =3D NULL; - char *tmpPath =3D NULL; + g_autoptr(virPCIDevice) pci =3D NULL; + g_autoptr(virUSBDevice) usb =3D NULL; + g_autoptr(virSCSIDevice) scsi =3D NULL; + g_autoptr(virSCSIVHostDevice) host =3D NULL; + g_autofree char *tmpPath =3D NULL; bool includeVFIO =3D false; char **tmpPaths =3D NULL; - int *tmpPerms =3D NULL; + g_autofree int *tmpPerms =3D NULL; size_t tmpNpaths =3D 0; int perm =3D 0; =20 @@ -13025,12 +13025,6 @@ qemuDomainGetHostdevPath(virDomainDefPtr def, ret =3D 0; cleanup: virStringListFreeCount(tmpPaths, tmpNpaths); - VIR_FREE(tmpPerms); - virPCIDeviceFree(pci); - virUSBDeviceFree(usb); - virSCSIDeviceFree(scsi); - virSCSIVHostDeviceFree(host); - VIR_FREE(tmpPath); return ret; } =20 --=20 2.23.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Fri Apr 26 22:05:19 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 205.139.110.61 as permitted sender) client-ip=205.139.110.61; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-1.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 205.139.110.61 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=1575297005; cv=none; d=zohomail.com; s=zohoarc; b=eTYW6XU0nfr+Sic1pl+DJzzJaPrOJGKxkQubgEHtKe5v0M1bT4VR4Ke94GctR0gxXgx+0f+qf/PwLnhQLq9MNyt3IPgGfpEamoUQVkHS6bxIi3Pewg+mCgLScBkmrHZ1APtowlOtLYwgzU5Q89+6EFicjy05aDTDGqLkkN5rFiI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1575297005; 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; bh=ytAWQ1HJi1+MrZw17vSP6xeUfNdPxJryTWqvubmbnUQ=; b=Ei4517Xc3nrLUoSZqjV8PNGWaCReNJujYuaGmWFaHdRHrPN5n4i9RkH552S8EmxWObVFzRCdv6EWJ2R4M3b59r34G92dgiKX7KohV+/T7eiJx3/Yzu2cZ7GVJTpJjTYuXgTLKlJbFvWZTG/Hm7vVL+L63bCFvorqurhKvFPCLpM= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 205.139.110.61 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from us-smtp-delivery-1.mimecast.com (us-smtp-2.mimecast.com [205.139.110.61]) by mx.zohomail.com with SMTPS id 1575297005789631.9759972159239; Mon, 2 Dec 2019 06:30:05 -0800 (PST) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-409-liMu7AvZM-KI0o_JnKrm6A-1; Mon, 02 Dec 2019 09:27:34 -0500 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 mimecast-mx01.redhat.com (Postfix) with ESMTPS id A14628BEA4A; Mon, 2 Dec 2019 14:27:25 +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 68C9C5D9E5; Mon, 2 Dec 2019 14:27:25 +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 1041018089D7; Mon, 2 Dec 2019 14:27:25 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id xB2ER0dq027268 for ; Mon, 2 Dec 2019 09:27:00 -0500 Received: by smtp.corp.redhat.com (Postfix) id ECB0667662; Mon, 2 Dec 2019 14:27:00 +0000 (UTC) Received: from moe.redhat.com (unknown [10.43.2.30]) by smtp.corp.redhat.com (Postfix) with ESMTP id 751CD6764D for ; Mon, 2 Dec 2019 14:27:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1575297002; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=ytAWQ1HJi1+MrZw17vSP6xeUfNdPxJryTWqvubmbnUQ=; b=AluUjDnnuy+Fslg1Mrz1DIaYgr/CfzmxjdVzYt4jwfoaeGsbIegwQDZG0/nCG1IGr0fv2R KEFXRiGjL3r86BQLoDR3rjw7p1V0x2kcSX1wwIXfKJjpLXODBK54bzCRQri4wbKE8+bGgn lXfA9vMYpX8+LjbAclMsgbMEulIwnvo= From: Michal Privoznik To: libvir-list@redhat.com Date: Mon, 2 Dec 2019 15:26:26 +0100 Message-Id: <1eb009bf00167e1fe4aa9967d0fceff35826e626.1575296392.git.mprivozn@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v3 03/30] qemuDomainGetHostdevPath: Don't include /dev/vfio/vfio in returned paths X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , 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-MC-Unique: liMu7AvZM-KI0o_JnKrm6A-1 X-Mimecast-Spam-Score: 0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" Now that all callers of qemuDomainGetHostdevPath() handle /dev/vfio/vfio on their own, we can safely drop handling in this function. In near future the decision whether domain needs VFIO file is going to include more device types than just virDomainHostdev. Signed-off-by: Michal Privoznik Reviewed-by: Cole Robinson --- src/qemu/qemu_cgroup.c | 52 ++++++++-------------- src/qemu/qemu_domain.c | 98 +++++++++--------------------------------- src/qemu/qemu_domain.h | 9 ++-- 3 files changed, 42 insertions(+), 117 deletions(-) diff --git a/src/qemu/qemu_cgroup.c b/src/qemu/qemu_cgroup.c index 65b148cd83..d54d01d4c0 100644 --- a/src/qemu/qemu_cgroup.c +++ b/src/qemu/qemu_cgroup.c @@ -376,26 +376,23 @@ qemuSetupHostdevCgroup(virDomainObjPtr vm, virDomainHostdevDefPtr dev) { qemuDomainObjPrivatePtr priv =3D vm->privateData; - char **path =3D NULL; - int *perms =3D NULL; - size_t i, npaths =3D 0; + g_autofree char *path =3D NULL; + int perms; int rv, ret =3D -1; =20 if (!virCgroupHasController(priv->cgroup, VIR_CGROUP_CONTROLLER_DEVICE= S)) return 0; =20 - if (qemuDomainGetHostdevPath(NULL, dev, false, &npaths, &path, &perms)= < 0) + if (qemuDomainGetHostdevPath(dev, &path, &perms) < 0) goto cleanup; =20 - for (i =3D 0; i < npaths; i++) { - VIR_DEBUG("Cgroup allow %s perms=3D%d", path[i], perms[i]); - rv =3D virCgroupAllowDevicePath(priv->cgroup, path[i], perms[i], f= alse); - virDomainAuditCgroupPath(vm, priv->cgroup, "allow", path[i], - virCgroupGetDevicePermsString(perms[i]), - rv); - if (rv < 0) - goto cleanup; - } + VIR_DEBUG("Cgroup allow %s perms=3D%d", path, perms); + rv =3D virCgroupAllowDevicePath(priv->cgroup, path, perms, false); + virDomainAuditCgroupPath(vm, priv->cgroup, "allow", path, + virCgroupGetDevicePermsString(perms), + rv); + if (rv < 0) + goto cleanup; =20 if (qemuHostdevNeedsVFIO(dev)) { VIR_DEBUG("Cgroup allow %s perms=3D%d", QEMU_DEV_VFIO, VIR_CGROUP_= DEVICE_RW); @@ -410,10 +407,6 @@ qemuSetupHostdevCgroup(virDomainObjPtr vm, ret =3D 0; =20 cleanup: - for (i =3D 0; i < npaths; i++) - VIR_FREE(path[i]); - VIR_FREE(path); - VIR_FREE(perms); return ret; } =20 @@ -434,26 +427,22 @@ qemuTeardownHostdevCgroup(virDomainObjPtr vm, virDomainHostdevDefPtr dev) { qemuDomainObjPrivatePtr priv =3D vm->privateData; - char **path =3D NULL; - size_t i, npaths =3D 0; + g_autofree char *path =3D NULL; int rv, ret =3D -1; =20 if (!virCgroupHasController(priv->cgroup, VIR_CGROUP_CONTROLLER_DEVICE= S)) return 0; =20 - if (qemuDomainGetHostdevPath(vm->def, dev, true, - &npaths, &path, NULL) < 0) + if (qemuDomainGetHostdevPath(dev, &path, NULL) < 0) goto cleanup; =20 - for (i =3D 0; i < npaths; i++) { - VIR_DEBUG("Cgroup deny %s", path[i]); - rv =3D virCgroupDenyDevicePath(priv->cgroup, path[i], - VIR_CGROUP_DEVICE_RWM, false); - virDomainAuditCgroupPath(vm, priv->cgroup, - "deny", path[i], "rwm", rv); - if (rv < 0) - goto cleanup; - } + VIR_DEBUG("Cgroup deny %s", path); + rv =3D virCgroupDenyDevicePath(priv->cgroup, path, + VIR_CGROUP_DEVICE_RWM, false); + virDomainAuditCgroupPath(vm, priv->cgroup, + "deny", path, "rwm", rv); + if (rv < 0) + goto cleanup; =20 if (qemuHostdevNeedsVFIO(dev) && !qemuDomainNeedsVFIO(vm->def)) { @@ -468,9 +457,6 @@ qemuTeardownHostdevCgroup(virDomainObjPtr vm, =20 ret =3D 0; cleanup: - for (i =3D 0; i < npaths; i++) - VIR_FREE(path[i]); - VIR_FREE(path); return ret; } =20 diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c index 6daae24c3d..be769cb3ff 100644 --- a/src/qemu/qemu_domain.c +++ b/src/qemu/qemu_domain.c @@ -12861,29 +12861,23 @@ qemuDomainNeedsVFIO(const virDomainDef *def) =20 /** * qemuDomainGetHostdevPath: - * @def: domain definition * @dev: host device definition - * @teardown: true if device will be removed - * @npaths: number of items in @path and @perms arrays * @path: resulting path to @dev * @perms: Optional pointer to VIR_CGROUP_DEVICE_* perms * * For given device @dev fetch its host path and store it at - * @path. If a device requires other paths to be present/allowed - * they are stored in the @path array after the actual path. - * Optionally, caller can get @perms on the path (e.g. rw/ro). + * @path. Optionally, caller can get @perms on the path (e.g. + * rw/ro). * - * The caller is responsible for freeing the memory. + * The caller is responsible for freeing the @path when no longer + * needed. * * Returns 0 on success, -1 otherwise. */ int -qemuDomainGetHostdevPath(virDomainDefPtr def, - virDomainHostdevDefPtr dev, - bool teardown, - size_t *npaths, - char ***path, - int **perms) +qemuDomainGetHostdevPath(virDomainHostdevDefPtr dev, + char **path, + int *perms) { int ret =3D -1; virDomainHostdevSubsysUSBPtr usbsrc =3D &dev->source.subsys.u.usb; @@ -12896,14 +12890,9 @@ qemuDomainGetHostdevPath(virDomainDefPtr def, g_autoptr(virSCSIDevice) scsi =3D NULL; g_autoptr(virSCSIVHostDevice) host =3D NULL; g_autofree char *tmpPath =3D NULL; - bool includeVFIO =3D false; - char **tmpPaths =3D NULL; g_autofree int *tmpPerms =3D NULL; - size_t tmpNpaths =3D 0; int perm =3D 0; =20 - *npaths =3D 0; - switch ((virDomainHostdevMode) dev->mode) { case VIR_DOMAIN_HOSTDEV_MODE_SUBSYS: switch ((virDomainHostdevSubsysType)dev->source.subsys.type) { @@ -12920,12 +12909,6 @@ qemuDomainGetHostdevPath(virDomainDefPtr def, goto cleanup; =20 perm =3D VIR_CGROUP_DEVICE_RW; - if (teardown) { - if (!virDomainDefHasVFIOHostdev(def)) - includeVFIO =3D true; - } else { - includeVFIO =3D true; - } } break; =20 @@ -12981,7 +12964,6 @@ qemuDomainGetHostdevPath(virDomainDefPtr def, if (!(tmpPath =3D virMediatedDeviceGetIOMMUGroupDev(mdevsrc->u= uidstr))) goto cleanup; =20 - includeVFIO =3D true; perm =3D VIR_CGROUP_DEVICE_RW; break; case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_LAST: @@ -12995,36 +12977,11 @@ qemuDomainGetHostdevPath(virDomainDefPtr def, break; } =20 - if (tmpPath) { - size_t toAlloc =3D 1; - - if (includeVFIO) - toAlloc =3D 2; - - if (VIR_ALLOC_N(tmpPaths, toAlloc) < 0 || - VIR_ALLOC_N(tmpPerms, toAlloc) < 0) - goto cleanup; - tmpPaths[0] =3D g_strdup(tmpPath); - tmpNpaths =3D toAlloc; - tmpPerms[0] =3D perm; - - if (includeVFIO) { - tmpPaths[1] =3D g_strdup(QEMU_DEV_VFIO); - tmpPerms[1] =3D VIR_CGROUP_DEVICE_RW; - } - } - - *npaths =3D tmpNpaths; - tmpNpaths =3D 0; - *path =3D tmpPaths; - tmpPaths =3D NULL; - if (perms) { - *perms =3D tmpPerms; - tmpPerms =3D NULL; - } + *path =3D g_steal_pointer(&tmpPath); + if (perms) + *perms =3D perm; ret =3D 0; cleanup: - virStringListFreeCount(tmpPaths, tmpNpaths); return ret; } =20 @@ -13525,16 +13482,13 @@ qemuDomainSetupHostdev(virQEMUDriverConfigPtr cfg= G_GNUC_UNUSED, const struct qemuDomainCreateDeviceData *data) { int ret =3D -1; - char **path =3D NULL; - size_t i, npaths =3D 0; + g_autofree char *path =3D NULL; =20 - if (qemuDomainGetHostdevPath(NULL, dev, false, &npaths, &path, NULL) <= 0) + if (qemuDomainGetHostdevPath(dev, &path, NULL) < 0) goto cleanup; =20 - for (i =3D 0; i < npaths; i++) { - if (qemuDomainCreateDevice(path[i], data, false) < 0) - goto cleanup; - } + if (qemuDomainCreateDevice(path, data, false) < 0) + goto cleanup; =20 if (qemuHostdevNeedsVFIO(dev) && qemuDomainCreateDevice(QEMU_DEV_VFIO, data, false) < 0) @@ -13542,9 +13496,6 @@ qemuDomainSetupHostdev(virQEMUDriverConfigPtr cfg G= _GNUC_UNUSED, =20 ret =3D 0; cleanup: - for (i =3D 0; i < npaths; i++) - VIR_FREE(path[i]); - VIR_FREE(path); return ret; } =20 @@ -14579,13 +14530,12 @@ qemuDomainNamespaceSetupHostdev(virDomainObjPtr v= m, virDomainHostdevDefPtr hostdev) { int ret =3D -1; - char **paths =3D NULL; - size_t i, npaths =3D 0; + g_autofree char *path =3D NULL; =20 - if (qemuDomainGetHostdevPath(NULL, hostdev, false, &npaths, &paths, NU= LL) < 0) + if (qemuDomainGetHostdevPath(hostdev, &path, NULL) < 0) goto cleanup; =20 - if (qemuDomainNamespaceMknodPaths(vm, (const char **)paths, npaths) < = 0) + if (qemuDomainNamespaceMknodPath(vm, path) < 0) goto cleanup; =20 if (qemuHostdevNeedsVFIO(hostdev) && @@ -14595,9 +14545,6 @@ qemuDomainNamespaceSetupHostdev(virDomainObjPtr vm, =20 ret =3D 0; cleanup: - for (i =3D 0; i < npaths; i++) - VIR_FREE(paths[i]); - VIR_FREE(paths); return ret; } =20 @@ -14618,14 +14565,12 @@ qemuDomainNamespaceTeardownHostdev(virDomainObjPt= r vm, virDomainHostdevDefPtr hostdev) { int ret =3D -1; - char **paths =3D NULL; - size_t i, npaths =3D 0; + g_autofree char *path =3D NULL; =20 - if (qemuDomainGetHostdevPath(vm->def, hostdev, true, - &npaths, &paths, NULL) < 0) + if (qemuDomainGetHostdevPath(hostdev, &path, NULL) < 0) goto cleanup; =20 - if (qemuDomainNamespaceUnlinkPaths(vm, (const char **)paths, npaths) <= 0) + if (qemuDomainNamespaceUnlinkPath(vm, path) < 0) goto cleanup; =20 if (qemuHostdevNeedsVFIO(hostdev) && @@ -14635,9 +14580,6 @@ qemuDomainNamespaceTeardownHostdev(virDomainObjPtr = vm, =20 ret =3D 0; cleanup: - for (i =3D 0; i < npaths; i++) - VIR_FREE(paths[i]); - VIR_FREE(paths); return ret; } =20 diff --git a/src/qemu/qemu_domain.h b/src/qemu/qemu_domain.h index db45a932dc..65bd83aece 100644 --- a/src/qemu/qemu_domain.h +++ b/src/qemu/qemu_domain.h @@ -1079,12 +1079,9 @@ bool qemuDomainSupportsVideoVga(virDomainVideoDefPtr= video, =20 bool qemuDomainNeedsVFIO(const virDomainDef *def); =20 -int qemuDomainGetHostdevPath(virDomainDefPtr def, - virDomainHostdevDefPtr dev, - bool teardown, - size_t *npaths, - char ***path, - int **perms); +int qemuDomainGetHostdevPath(virDomainHostdevDefPtr dev, + char **path, + int *perms); =20 int qemuDomainBuildNamespace(virQEMUDriverConfigPtr cfg, virSecurityManagerPtr mgr, --=20 2.23.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Fri Apr 26 22:05:19 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 207.211.31.120 as permitted sender) client-ip=207.211.31.120; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-1.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 207.211.31.120 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=1575296834; cv=none; d=zohomail.com; s=zohoarc; b=Lp2JfzOJorpTjViawmsrPYzXwNX6vs6wYLIFLOMb0p3VB9JqKZc3lISwv2yU97Dw5mD1cZVoyDKCrnOh3ED/OJ2ef6ew5/ZbO0/tLD1QsWHXJ1+Wprl0XugynZXmMZ0aj4uNxdANCKDAjA1otcMEjpbVG4ZxvOdrTNfOMkLaTGw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1575296834; 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; bh=Uq5BbtFLI/1wgjtjMVO0y8QL+0F+0E6q3786cwkMxEc=; b=TtC2f29phOG+84rRTkmwcOfwCNtfumQNF4CMmmqzUpPfTQh6+qivQhIEBQwO3BVtlhuGel1mMF1Mx2c+CdY3c32CuVoui6c1L6d22v8o0Ciz6IoDixfnAamBH5QsRGHU8P3igRUXkoX82PUKASz10aETNMn7Anr89Yy+7FPfX3M= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 207.211.31.120 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from us-smtp-1.mimecast.com (us-smtp-delivery-1.mimecast.com [207.211.31.120]) by mx.zohomail.com with SMTPS id 1575296834240375.181005028689; Mon, 2 Dec 2019 06:27:14 -0800 (PST) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-29-3vGUqxWqOuq5FCGFi9wzEQ-1; Mon, 02 Dec 2019 09:27:11 -0500 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 mimecast-mx01.redhat.com (Postfix) with ESMTPS id C00F710513CD; Mon, 2 Dec 2019 14:27: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 D480D67662; Mon, 2 Dec 2019 14:27:03 +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 80E3C4EDAF; Mon, 2 Dec 2019 14:27:03 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id xB2ER1WM027273 for ; Mon, 2 Dec 2019 09:27:01 -0500 Received: by smtp.corp.redhat.com (Postfix) id BD21667E56; Mon, 2 Dec 2019 14:27:01 +0000 (UTC) Received: from moe.redhat.com (unknown [10.43.2.30]) by smtp.corp.redhat.com (Postfix) with ESMTP id 4644C67E52 for ; Mon, 2 Dec 2019 14:27:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1575296833; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=Uq5BbtFLI/1wgjtjMVO0y8QL+0F+0E6q3786cwkMxEc=; b=KL9Lu1vWReVf0MtNFI/Ou2YAblULGtrOXvwLuagd1kk8CwG93h44C2Pjf/4rg+MkaAhW0q f24Xc320WZ0bC8yaRmKcspzAbsTYInKs0LFNEWHHcKH4ZYdCAhzMlUlk0k8b8FxPboclRy Bq2OYGqc2GMPpn2BuBgKkLIJeh/t55M= From: Michal Privoznik To: libvir-list@redhat.com Date: Mon, 2 Dec 2019 15:26:27 +0100 Message-Id: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v3 04/30] qemu: Drop some 'cleanup' labels X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , 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-MC-Unique: 3vGUqxWqOuq5FCGFi9wzEQ-1 X-Mimecast-Spam-Score: 0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" Previous patches rendered some of 'cleanup' labels needless. Drop them. Signed-off-by: Michal Privoznik Reviewed-by: Cole Robinson --- src/qemu/qemu_cgroup.c | 25 +++++++++------------ src/qemu/qemu_domain.c | 50 ++++++++++++++++-------------------------- 2 files changed, 29 insertions(+), 46 deletions(-) diff --git a/src/qemu/qemu_cgroup.c b/src/qemu/qemu_cgroup.c index d54d01d4c0..d23318db8c 100644 --- a/src/qemu/qemu_cgroup.c +++ b/src/qemu/qemu_cgroup.c @@ -378,13 +378,13 @@ qemuSetupHostdevCgroup(virDomainObjPtr vm, qemuDomainObjPrivatePtr priv =3D vm->privateData; g_autofree char *path =3D NULL; int perms; - int rv, ret =3D -1; + int rv; =20 if (!virCgroupHasController(priv->cgroup, VIR_CGROUP_CONTROLLER_DEVICE= S)) return 0; =20 if (qemuDomainGetHostdevPath(dev, &path, &perms) < 0) - goto cleanup; + return -1; =20 VIR_DEBUG("Cgroup allow %s perms=3D%d", path, perms); rv =3D virCgroupAllowDevicePath(priv->cgroup, path, perms, false); @@ -392,7 +392,7 @@ qemuSetupHostdevCgroup(virDomainObjPtr vm, virCgroupGetDevicePermsString(perms), rv); if (rv < 0) - goto cleanup; + return -1; =20 if (qemuHostdevNeedsVFIO(dev)) { VIR_DEBUG("Cgroup allow %s perms=3D%d", QEMU_DEV_VFIO, VIR_CGROUP_= DEVICE_RW); @@ -401,13 +401,10 @@ qemuSetupHostdevCgroup(virDomainObjPtr vm, virDomainAuditCgroupPath(vm, priv->cgroup, "allow", QEMU_DEV_VFIO, "rw", rv); if (rv < 0) - goto cleanup; + return -1; } =20 - ret =3D 0; - - cleanup: - return ret; + return 0; } =20 =20 @@ -428,13 +425,13 @@ qemuTeardownHostdevCgroup(virDomainObjPtr vm, { qemuDomainObjPrivatePtr priv =3D vm->privateData; g_autofree char *path =3D NULL; - int rv, ret =3D -1; + int rv; =20 if (!virCgroupHasController(priv->cgroup, VIR_CGROUP_CONTROLLER_DEVICE= S)) return 0; =20 if (qemuDomainGetHostdevPath(dev, &path, NULL) < 0) - goto cleanup; + return -1; =20 VIR_DEBUG("Cgroup deny %s", path); rv =3D virCgroupDenyDevicePath(priv->cgroup, path, @@ -442,7 +439,7 @@ qemuTeardownHostdevCgroup(virDomainObjPtr vm, virDomainAuditCgroupPath(vm, priv->cgroup, "deny", path, "rwm", rv); if (rv < 0) - goto cleanup; + return -1; =20 if (qemuHostdevNeedsVFIO(dev) && !qemuDomainNeedsVFIO(vm->def)) { @@ -452,12 +449,10 @@ qemuTeardownHostdevCgroup(virDomainObjPtr vm, virDomainAuditCgroupPath(vm, priv->cgroup, "deny", QEMU_DEV_VFIO, "rwm", rv); if (rv < 0) - goto cleanup; + return -1; } =20 - ret =3D 0; - cleanup: - return ret; + return 0; } =20 =20 diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c index be769cb3ff..21a4dad37d 100644 --- a/src/qemu/qemu_domain.c +++ b/src/qemu/qemu_domain.c @@ -12879,7 +12879,6 @@ qemuDomainGetHostdevPath(virDomainHostdevDefPtr dev, char **path, int *perms) { - int ret =3D -1; virDomainHostdevSubsysUSBPtr usbsrc =3D &dev->source.subsys.u.usb; virDomainHostdevSubsysPCIPtr pcisrc =3D &dev->source.subsys.u.pci; virDomainHostdevSubsysSCSIPtr scsisrc =3D &dev->source.subsys.u.scsi; @@ -12903,10 +12902,10 @@ qemuDomainGetHostdevPath(virDomainHostdevDefPtr d= ev, pcisrc->addr.slot, pcisrc->addr.function); if (!pci) - goto cleanup; + return -1; =20 if (!(tmpPath =3D virPCIDeviceGetIOMMUGroupDev(pci))) - goto cleanup; + return -1; =20 perm =3D VIR_CGROUP_DEVICE_RW; } @@ -12919,7 +12918,7 @@ qemuDomainGetHostdevPath(virDomainHostdevDefPtr dev, usbsrc->device, NULL); if (!usb) - goto cleanup; + return -1; =20 tmpPath =3D g_strdup(virUSBDeviceGetPath(usb)); perm =3D VIR_CGROUP_DEVICE_RW; @@ -12940,7 +12939,7 @@ qemuDomainGetHostdevPath(virDomainHostdevDefPtr dev, dev->shareable); =20 if (!scsi) - goto cleanup; + return -1; =20 tmpPath =3D g_strdup(virSCSIDeviceGetPath(scsi)); perm =3D virSCSIDeviceGetReadonly(scsi) ? @@ -12952,7 +12951,7 @@ qemuDomainGetHostdevPath(virDomainHostdevDefPtr dev, if (hostsrc->protocol =3D=3D VIR_DOMAIN_HOSTDEV_SUBSYS_SCSI_HOST_PROTOCOL_TYPE_VHOST) { if (!(host =3D virSCSIVHostDeviceNew(hostsrc->wwpn))) - goto cleanup; + return -1; =20 tmpPath =3D g_strdup(virSCSIVHostDeviceGetPath(host)); perm =3D VIR_CGROUP_DEVICE_RW; @@ -12962,7 +12961,7 @@ qemuDomainGetHostdevPath(virDomainHostdevDefPtr dev, =20 case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_MDEV: if (!(tmpPath =3D virMediatedDeviceGetIOMMUGroupDev(mdevsrc->u= uidstr))) - goto cleanup; + return -1; =20 perm =3D VIR_CGROUP_DEVICE_RW; break; @@ -12980,9 +12979,7 @@ qemuDomainGetHostdevPath(virDomainHostdevDefPtr dev, *path =3D g_steal_pointer(&tmpPath); if (perms) *perms =3D perm; - ret =3D 0; - cleanup: - return ret; + return 0; } =20 =20 @@ -13481,22 +13478,19 @@ qemuDomainSetupHostdev(virQEMUDriverConfigPtr cfg= G_GNUC_UNUSED, virDomainHostdevDefPtr dev, const struct qemuDomainCreateDeviceData *data) { - int ret =3D -1; g_autofree char *path =3D NULL; =20 if (qemuDomainGetHostdevPath(dev, &path, NULL) < 0) - goto cleanup; + return -1; =20 if (qemuDomainCreateDevice(path, data, false) < 0) - goto cleanup; + return -1; =20 if (qemuHostdevNeedsVFIO(dev) && qemuDomainCreateDevice(QEMU_DEV_VFIO, data, false) < 0) - goto cleanup; + return -1; =20 - ret =3D 0; - cleanup: - return ret; + return 0; } =20 =20 @@ -14529,23 +14523,20 @@ int qemuDomainNamespaceSetupHostdev(virDomainObjPtr vm, virDomainHostdevDefPtr hostdev) { - int ret =3D -1; g_autofree char *path =3D NULL; =20 if (qemuDomainGetHostdevPath(hostdev, &path, NULL) < 0) - goto cleanup; + return -1; =20 if (qemuDomainNamespaceMknodPath(vm, path) < 0) - goto cleanup; + return -1; =20 if (qemuHostdevNeedsVFIO(hostdev) && !qemuDomainNeedsVFIO(vm->def) && qemuDomainNamespaceMknodPath(vm, QEMU_DEV_VFIO) < 0) - goto cleanup; + return -1; =20 - ret =3D 0; - cleanup: - return ret; + return 0; } =20 =20 @@ -14564,23 +14555,20 @@ int qemuDomainNamespaceTeardownHostdev(virDomainObjPtr vm, virDomainHostdevDefPtr hostdev) { - int ret =3D -1; g_autofree char *path =3D NULL; =20 if (qemuDomainGetHostdevPath(hostdev, &path, NULL) < 0) - goto cleanup; + return -1; =20 if (qemuDomainNamespaceUnlinkPath(vm, path) < 0) - goto cleanup; + return -1; =20 if (qemuHostdevNeedsVFIO(hostdev) && !qemuDomainNeedsVFIO(vm->def) && qemuDomainNamespaceUnlinkPath(vm, QEMU_DEV_VFIO) < 0) - goto cleanup; + return -1; =20 - ret =3D 0; - cleanup: - return ret; + return 0; } =20 =20 --=20 2.23.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Fri Apr 26 22:05:19 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 207.211.31.81 as permitted sender) client-ip=207.211.31.81; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-1.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 207.211.31.81 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=1575296860; cv=none; d=zohomail.com; s=zohoarc; b=QEl5GUehxc3JlOwh601Sj2SkGsfb6tdglc2s6YB27kLoZBzjFqyoOZmo3+y357jHNwnFqzbTC6WM3pCFDuWhZuCW165WpFfCGG7yKKID2Ku9vH9KU348KJF/lSdiGqRef8Tcp+/blGlaviC/2vpAWXrCjdsBjS+t4/wSHDmVqwI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1575296860; 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; bh=Ru1djAH7eKE4GJgIrc8T1LoM5mp2yryMdjxkRt+b4Fk=; b=HWmekyaSLRZY5WLh2W9itx5PHmkI50t+jeeZiohEUnzHudVwpp/m99szy157tqhwyKjZhR762AFxiRMixHs0v34w1KIq+asS0xlOPIF9DqofVA/OfcbR95ROz1LE5+/Sjc9d8G9uOKiIPTeRPI82lLtIHPaWKi8jxf2Osv0L4kQ= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 207.211.31.81 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from us-smtp-delivery-1.mimecast.com (us-smtp-1.mimecast.com [207.211.31.81]) by mx.zohomail.com with SMTPS id 1575296860356299.67207901013194; Mon, 2 Dec 2019 06:27:40 -0800 (PST) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-211-6cS3T1_lPqe0PPI-lDTwAQ-1; Mon, 02 Dec 2019 09:27:37 -0500 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 mimecast-mx01.redhat.com (Postfix) with ESMTPS id 7B87E9B8C7; Mon, 2 Dec 2019 14:27:29 +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 524D05D6A7; Mon, 2 Dec 2019 14:27: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 04C4F180880D; Mon, 2 Dec 2019 14:27:29 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id xB2ER2ss027288 for ; Mon, 2 Dec 2019 09:27:02 -0500 Received: by smtp.corp.redhat.com (Postfix) id 932A667E56; Mon, 2 Dec 2019 14:27:02 +0000 (UTC) Received: from moe.redhat.com (unknown [10.43.2.30]) by smtp.corp.redhat.com (Postfix) with ESMTP id 1AF6D67E52 for ; Mon, 2 Dec 2019 14:27:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1575296859; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=Ru1djAH7eKE4GJgIrc8T1LoM5mp2yryMdjxkRt+b4Fk=; b=Aar/Vp0DAxk/YDoW/XPZmZ7P17G7vJymhuG/GOjtb5wdEbCeCD374m6mPzeoYzXQGP+/9P Zi2Sv0fN2CXZ1NOTBI5GlozepBKyEUR9/6LedegTqewer8OH/dPnHz2BAIJVT9OkLbkwf9 gnLylJxsFnAIHSJBkJoNNLhDHUkXwWA= From: Michal Privoznik To: libvir-list@redhat.com Date: Mon, 2 Dec 2019 15:26:28 +0100 Message-Id: <667ad03b9edd9b986a7939cc316b4ab64615b27b.1575296392.git.mprivozn@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v3 05/30] virpci: Introduce and use virPCIDeviceAddressGetIOMMUGroupDev X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , 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-MC-Unique: 6cS3T1_lPqe0PPI-lDTwAQ-1 X-Mimecast-Spam-Score: 0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" Sometimes, we have a PCI address and not fully allocated virPCIDevice and yet we still want to know its /dev/vfio/N path. Introduce virPCIDeviceAddressGetIOMMUGroupDev() function exactly for that. Signed-off-by: Michal Privoznik Reviewed-by: Cole Robinson --- src/libvirt_private.syms | 1 + src/qemu/qemu_domain.c | 11 +---------- src/util/virpci.c | 15 +++++++++++++++ src/util/virpci.h | 1 + 4 files changed, 18 insertions(+), 10 deletions(-) diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index 8fe0bf9365..0988f36c20 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -2692,6 +2692,7 @@ virPCIDeviceAddressAsString; virPCIDeviceAddressEqual; virPCIDeviceAddressFree; virPCIDeviceAddressGetIOMMUGroupAddresses; +virPCIDeviceAddressGetIOMMUGroupDev; virPCIDeviceAddressGetIOMMUGroupNum; virPCIDeviceAddressGetSysfsFile; virPCIDeviceAddressIOMMUGroupIterate; diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c index 21a4dad37d..59e98de2d2 100644 --- a/src/qemu/qemu_domain.c +++ b/src/qemu/qemu_domain.c @@ -12884,12 +12884,10 @@ qemuDomainGetHostdevPath(virDomainHostdevDefPtr d= ev, virDomainHostdevSubsysSCSIPtr scsisrc =3D &dev->source.subsys.u.scsi; virDomainHostdevSubsysSCSIVHostPtr hostsrc =3D &dev->source.subsys.u.s= csi_host; virDomainHostdevSubsysMediatedDevPtr mdevsrc =3D &dev->source.subsys.u= .mdev; - g_autoptr(virPCIDevice) pci =3D NULL; g_autoptr(virUSBDevice) usb =3D NULL; g_autoptr(virSCSIDevice) scsi =3D NULL; g_autoptr(virSCSIVHostDevice) host =3D NULL; g_autofree char *tmpPath =3D NULL; - g_autofree int *tmpPerms =3D NULL; int perm =3D 0; =20 switch ((virDomainHostdevMode) dev->mode) { @@ -12897,14 +12895,7 @@ qemuDomainGetHostdevPath(virDomainHostdevDefPtr de= v, switch ((virDomainHostdevSubsysType)dev->source.subsys.type) { case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_PCI: if (pcisrc->backend =3D=3D VIR_DOMAIN_HOSTDEV_PCI_BACKEND_VFIO= ) { - pci =3D virPCIDeviceNew(pcisrc->addr.domain, - pcisrc->addr.bus, - pcisrc->addr.slot, - pcisrc->addr.function); - if (!pci) - return -1; - - if (!(tmpPath =3D virPCIDeviceGetIOMMUGroupDev(pci))) + if (!(tmpPath =3D virPCIDeviceAddressGetIOMMUGroupDev(&pci= src->addr))) return -1; =20 perm =3D VIR_CGROUP_DEVICE_RW; diff --git a/src/util/virpci.c b/src/util/virpci.c index 9bea5a20d0..b0a4107551 100644 --- a/src/util/virpci.c +++ b/src/util/virpci.c @@ -1942,6 +1942,21 @@ virPCIDeviceAddressGetIOMMUGroupNum(virPCIDeviceAddr= essPtr addr) } =20 =20 +char * +virPCIDeviceAddressGetIOMMUGroupDev(const virPCIDeviceAddress *devAddr) +{ + g_autoptr(virPCIDevice) pci =3D NULL; + + if (!(pci =3D virPCIDeviceNew(devAddr->domain, + devAddr->bus, + devAddr->slot, + devAddr->function))) + return NULL; + + return virPCIDeviceGetIOMMUGroupDev(pci); +} + + /* virPCIDeviceGetIOMMUGroupDev - return the name of the device used * to control this PCI device's group (e.g. "/dev/vfio/15") */ diff --git a/src/util/virpci.h b/src/util/virpci.h index cfb4581edf..1c94dc307c 100644 --- a/src/util/virpci.h +++ b/src/util/virpci.h @@ -195,6 +195,7 @@ int virPCIDeviceAddressGetIOMMUGroupAddresses(virPCIDev= iceAddressPtr devAddr, virPCIDeviceAddressPtr **iom= muGroupDevices, size_t *nIommuGroupDevices); int virPCIDeviceAddressGetIOMMUGroupNum(virPCIDeviceAddressPtr addr); +char *virPCIDeviceAddressGetIOMMUGroupDev(const virPCIDeviceAddress *devAd= dr); char *virPCIDeviceGetIOMMUGroupDev(virPCIDevicePtr dev); =20 int virPCIDeviceIsAssignable(virPCIDevicePtr dev, --=20 2.23.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Fri Apr 26 22:05:19 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 207.211.31.81 as permitted sender) client-ip=207.211.31.81; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-1.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 207.211.31.81 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=1575296850; cv=none; d=zohomail.com; s=zohoarc; b=SPvXWK7iFzpEzvmCwZPeSTRfYOtDJDxdkIIxCKCJDSchfsFbrprVL4L8FbdcathQoxTux+xGPDs/AV5hgssHjBJCJTG2kINHzEk79ud5lAG9Phmm9NCaPd3hJyQi97rGszordmsxbkrKS2oUYg5qAuje9wn7tdbld3iTJLQ0IHQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1575296850; 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; bh=HD69gL4TGE7lsADEV5OJry+rJtcwn4eE/kkdFjdCXoM=; b=X75PJOFw9P76uBGfRvqqC9t4tjWNIJzzgfioznwmkuzgpkEk5ALVrgr4DxGnYDa5g7aQNDxX1zfx0Q2R8/3H9ozGbdJ85O0Y9/PiPwoO0sBu9ETVqPHf7XTClmYimCNq1yVUkuWq/QVRSsBFVtFSKdME5eTZEKG3EXJA1FLT6iw= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 207.211.31.81 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from us-smtp-delivery-1.mimecast.com (us-smtp-1.mimecast.com [207.211.31.81]) by mx.zohomail.com with SMTPS id 1575296850763741.6160975485046; Mon, 2 Dec 2019 06:27:30 -0800 (PST) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-375-b52O5NfON6W5mYotvCdxUg-1; Mon, 02 Dec 2019 09:27:27 -0500 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 mimecast-mx01.redhat.com (Postfix) with ESMTPS id 416171083EA0; Mon, 2 Dec 2019 14:27:21 +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 06D675C240; Mon, 2 Dec 2019 14:27:21 +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 9551F4EDAE; Mon, 2 Dec 2019 14:27:20 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id xB2ER3Uh027293 for ; Mon, 2 Dec 2019 09:27:03 -0500 Received: by smtp.corp.redhat.com (Postfix) id 633C267E57; Mon, 2 Dec 2019 14:27:03 +0000 (UTC) Received: from moe.redhat.com (unknown [10.43.2.30]) by smtp.corp.redhat.com (Postfix) with ESMTP id E037067E52 for ; Mon, 2 Dec 2019 14:27:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1575296849; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=HD69gL4TGE7lsADEV5OJry+rJtcwn4eE/kkdFjdCXoM=; b=Uu7KCY6JTYXYbr9tgpW52R8LjeiVFKI5zFAX4MQpzMIWVtUzfMAju9ZCor7eIho0Q8XbOC E5tdyrPZlXO2IcIEyR6LD6Ahf332HTvvx7Vao//qx8VTGoFlszJEUIWtyHiSpHSC+sIpXc gmd2Iuy1RVtCoMXEfWYQodqxtHiBs38= From: Michal Privoznik To: libvir-list@redhat.com Date: Mon, 2 Dec 2019 15:26:29 +0100 Message-Id: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v3 06/30] 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: , 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-MC-Unique: b52O5NfON6W5mYotvCdxUg-1 X-Mimecast-Spam-Score: 0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" In near future we will have a list of PCI devices we want to detach (held in virPCIDeviceListPtr) but we don't have virDomainHostdevDefPtr. That's okay because virHostdevPreparePCIDevices() works with virPCIDeviceListPtr mostly anyway. And in very few places where it needs virDomainHostdevDefPtr are not interesting for our case. Signed-off-by: Michal Privoznik ACKed-by: Peter Krempa Reviewed-by: Cole Robinson --- src/util/virhostdev.c | 48 +++++++++++++++++++++++++++++-------------- 1 file changed, 33 insertions(+), 15 deletions(-) diff --git a/src/util/virhostdev.c b/src/util/virhostdev.c index 39e6b8f49f..b8e6e2bc36 100644 --- a/src/util/virhostdev.c +++ b/src/util/virhostdev.c @@ -714,27 +714,22 @@ virHostdevReattachAllPCIDevices(virHostdevManagerPtr = mgr, } } =20 -int -virHostdevPreparePCIDevices(virHostdevManagerPtr mgr, - const char *drv_name, - const char *dom_name, - const unsigned char *uuid, - virDomainHostdevDefPtr *hostdevs, - int nhostdevs, - unsigned int flags) + +static int +virHostdevPreparePCIDevicesImpl(virHostdevManagerPtr mgr, + const char *drv_name, + const char *dom_name, + const unsigned char *uuid, + virPCIDeviceListPtr pcidevs, + virDomainHostdevDefPtr *hostdevs, + int nhostdevs, + unsigned int flags) { - g_autoptr(virPCIDeviceList) 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 @@ -984,6 +979,29 @@ virHostdevPreparePCIDevices(virHostdevManagerPtr mgr, return ret; } =20 + +int +virHostdevPreparePCIDevices(virHostdevManagerPtr mgr, + const char *drv_name, + const char *dom_name, + const unsigned char *uuid, + virDomainHostdevDefPtr *hostdevs, + int nhostdevs, + unsigned int flags) +{ + g_autoptr(virPCIDeviceList) pcidevs =3D NULL; + + if (!nhostdevs) + return 0; + + if (!(pcidevs =3D virHostdevGetPCIHostDeviceList(hostdevs, nhostdevs))) + return -1; + + return virHostdevPreparePCIDevicesImpl(mgr, drv_name, dom_name, uuid, + pcidevs, hostdevs, nhostdevs, f= lags); +} + + /* @oldStateDir: * For upgrade purpose: see virHostdevRestoreNetConfig */ --=20 2.23.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Fri Apr 26 22:05:19 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 205.139.110.120 as permitted sender) client-ip=205.139.110.120; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-1.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 205.139.110.120 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=1575296856; cv=none; d=zohomail.com; s=zohoarc; b=f5/Xp+aED2CbYqomH7bGfg/8Mh74Y3bpF8Odo3m33xUpOC9jRzueIyQS8e/2lf8yydAPu9sqVWSi1rLM6VUgYA3aMEFl7Wq8ZtWDf3U/Mm4XhW24VL7gPuLOdeKfewMI8ottiK+GbdsAPbyEQ7gsWih1ub2QF4AsinNwJssGELQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1575296856; 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; bh=IX7qrP/vxbLNH02bT7ksgiYDb6KZ84ywsPamAoz/gvw=; b=S4Lcs4s9FcYVsG+yLgM46Pq8DdVBS72dypTbizj49jrDPdvKPx6KdBvfrv+iXo+AKXwZHrHxCM6tvh3zQH57uaAnDD/QduKXFUyZsxTryF0cu9s4+evplq9kYGT/hTJHgMp7euuzPQQKbsgY2F0u6YjbrTGlHD0WL5Y5gN7h3ZM= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 205.139.110.120 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from us-smtp-1.mimecast.com (us-smtp-delivery-1.mimecast.com [205.139.110.120]) by mx.zohomail.com with SMTPS id 1575296856619741.6420963912824; Mon, 2 Dec 2019 06:27:36 -0800 (PST) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-246-p6D8qNDAOwKw0wE6YU9ufQ-1; Mon, 02 Dec 2019 09:27:33 -0500 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 mimecast-mx01.redhat.com (Postfix) with ESMTPS id A61668048E9; Mon, 2 Dec 2019 14:27:25 +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 737C35D6A7; Mon, 2 Dec 2019 14:27:25 +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 1A12A4EDB1; Mon, 2 Dec 2019 14:27:25 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id xB2ER6ni027317 for ; Mon, 2 Dec 2019 09:27:06 -0500 Received: by smtp.corp.redhat.com (Postfix) id 8255B6764D; Mon, 2 Dec 2019 14:27:06 +0000 (UTC) Received: from moe.redhat.com (unknown [10.43.2.30]) by smtp.corp.redhat.com (Postfix) with ESMTP id 0BCE767662 for ; Mon, 2 Dec 2019 14:27:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1575296855; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=IX7qrP/vxbLNH02bT7ksgiYDb6KZ84ywsPamAoz/gvw=; b=aTbsiLX/Qhx2NbeI6oarCGsjoQktBXjQpvDzZLt9IJ9YsLGR+uCQBiwmbrmJVSVGIGwzvf NnGEz1YNC1mkXgdDzOhnEfx8cMY3AsVe3fOuEiOcgUX5O+mKbiRy4qne4ZifrP8MB6DDZC epQg2FtcZOzUtdEeykkpJyhtDri0Pl8= From: Michal Privoznik To: libvir-list@redhat.com Date: Mon, 2 Dec 2019 15:26:30 +0100 Message-Id: <3c143522acd9224ce40de2588fb40d6fb23479d1.1575296392.git.mprivozn@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v3 07/30] 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: , 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-MC-Unique: p6D8qNDAOwKw0wE6YU9ufQ-1 X-Mimecast-Spam-Score: 0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" In near future we will have a list of PCI devices we want to re-attach to the host (held in virPCIDeviceListPtr) but we don't have virDomainHostdevDefPtr. That's okay because virHostdevReAttachPCIDevices() works with virPCIDeviceListPtr mostly anyway. And in very few places where it needs virDomainHostdevDefPtr are not interesting for our case. Signed-off-by: Michal Privoznik ACKed-by: Peter Krempa Reviewed-by: Cole Robinson --- 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 b8e6e2bc36..94a0185597 100644 --- a/src/util/virhostdev.c +++ b/src/util/virhostdev.c @@ -1002,30 +1002,17 @@ virHostdevPreparePCIDevices(virHostdevManagerPtr mg= r, } =20 =20 -/* @oldStateDir: - * For upgrade purpose: see virHostdevRestoreNetConfig - */ -void -virHostdevReAttachPCIDevices(virHostdevManagerPtr mgr, - const char *drv_name, - const char *dom_name, - virDomainHostdevDefPtr *hostdevs, - int nhostdevs, - const char *oldStateDir) +static void +virHostdevReAttachPCIDevicesImpl(virHostdevManagerPtr mgr, + const char *drv_name, + const char *dom_name, + virPCIDeviceListPtr pcidevs, + virDomainHostdevDefPtr *hostdevs, + int nhostdevs, + const char *oldStateDir) { - g_autoptr(virPCIDeviceList) 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 @@ -1121,6 +1108,35 @@ virHostdevReAttachPCIDevices(virHostdevManagerPtr mg= r, virObjectUnlock(mgr->inactivePCIHostdevs); } =20 + +/* @oldStateDir: + * For upgrade purpose: see virHostdevRestoreNetConfig + */ +void +virHostdevReAttachPCIDevices(virHostdevManagerPtr mgr, + const char *drv_name, + const char *dom_name, + virDomainHostdevDefPtr *hostdevs, + int nhostdevs, + const char *oldStateDir) +{ + g_autoptr(virPCIDeviceList) 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.23.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Fri Apr 26 22:05:19 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 205.139.110.61 as permitted sender) client-ip=205.139.110.61; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-1.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 205.139.110.61 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=1575296853; cv=none; d=zohomail.com; s=zohoarc; b=KEikN6t34EHLdxOCP1pMefsmpcBsmiYLB85uqnwXk7xrDrFrDidQ0FaebdDrg1PghAWwchYNHUR2r1enrCrOdn4gseq49OIl8MBApwexaJKGDtsaCPHAqbHC85EoD+e8HCtzjm8CNpmjfkeqrTwDVgG1ivkssoYXXdNHNLz4vRM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1575296853; 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; bh=NMt8v39Vc/6STzLRkqUXHVx4wDUEiiWH6jTpgh4hdNo=; b=K45XPDjRVYuyQ6aTyAU7+hJXsepFgh3//elDtYHbn52AvFt3/bvKtL40Whw6sNaCcPdC38aYLaemA9Uw1ErJskxVhHFBczZ6AzCW8yGvHs1/87YPaS5139bZ01Mhnu56l3kDnarisJNxYMzF4RCcSqSFIOBHWlnOMsJpMT8ak3w= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 205.139.110.61 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from us-smtp-1.mimecast.com (us-smtp-1.mimecast.com [205.139.110.61]) by mx.zohomail.com with SMTPS id 15752968535581016.0458434409496; Mon, 2 Dec 2019 06:27:33 -0800 (PST) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-6-fM_ZG7gBPlmT_2g1KKGJDw-1; Mon, 02 Dec 2019 09:27:29 -0500 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 mimecast-mx01.redhat.com (Postfix) with ESMTPS id 0B54E9B49B; Mon, 2 Dec 2019 14:27:23 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id D9F64600CA; Mon, 2 Dec 2019 14:27:22 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 8F61218089D5; Mon, 2 Dec 2019 14:27:22 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id xB2ER7ap027322 for ; Mon, 2 Dec 2019 09:27:07 -0500 Received: by smtp.corp.redhat.com (Postfix) id 5227967662; Mon, 2 Dec 2019 14:27:07 +0000 (UTC) Received: from moe.redhat.com (unknown [10.43.2.30]) by smtp.corp.redhat.com (Postfix) with ESMTP id CFC4F6764D for ; Mon, 2 Dec 2019 14:27:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1575296852; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=NMt8v39Vc/6STzLRkqUXHVx4wDUEiiWH6jTpgh4hdNo=; b=ctHjxoKw1P5xaSF7logIA++wPp4PM5YmkDQoK5luyzu5D3oYsvkz0l1G1qjloP+hVY0rzB kExuO0QUDAB/DKG03wbMFoSAHUBsVtcYF0dxGL8/vgCHYgR4Iq0nvxg0VSmdtE2mQZvmAi ainUoNyxVLGsGi6+UdPcT1bescjAQYE= From: Michal Privoznik To: libvir-list@redhat.com Date: Mon, 2 Dec 2019 15:26:31 +0100 Message-Id: <2c14885ad7f394f1be788fb7784a4facf71a61e3.1575296392.git.mprivozn@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v3 08/30] 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: , 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-MC-Unique: fM_ZG7gBPlmT_2g1KKGJDw-1 X-Mimecast-Spam-Score: 0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" This helper is cleaner than plain memcpy() because one doesn't have to look into virPCIDeviceAddress struct to see if it contains any strings / pointers. Signed-off-by: Michal Privoznik ACKed-by: Peter Krempa Reviewed-by: Cole Robinson --- src/libvirt_private.syms | 1 + src/util/virpci.c | 14 ++++++++++++++ src/util/virpci.h | 4 ++++ 3 files changed, 19 insertions(+) diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index 0988f36c20..6e4ef0413b 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -2689,6 +2689,7 @@ virObjectUnref; =20 # util/virpci.h virPCIDeviceAddressAsString; +virPCIDeviceAddressCopy; virPCIDeviceAddressEqual; virPCIDeviceAddressFree; virPCIDeviceAddressGetIOMMUGroupAddresses; diff --git a/src/util/virpci.c b/src/util/virpci.c index b0a4107551..99a8002743 100644 --- a/src/util/virpci.c +++ b/src/util/virpci.c @@ -1340,6 +1340,20 @@ virPCIDeviceAddressEqual(const virPCIDeviceAddress *= addr1, return false; } =20 +/** + * virPCIDeviceAddressCopy: + * @dst: where to store address + * @src: source address to copy + * + * Creates a deep copy of given @src address and stores it into + * @dst which has to be pre-allocated by caller. + */ +void virPCIDeviceAddressCopy(virPCIDeviceAddressPtr dst, + const virPCIDeviceAddress *src) +{ + memcpy(dst, src, sizeof(*src)); +} + char * virPCIDeviceAddressAsString(const virPCIDeviceAddress *addr) { diff --git a/src/util/virpci.h b/src/util/virpci.h index 1c94dc307c..f6796fc422 100644 --- a/src/util/virpci.h +++ b/src/util/virpci.h @@ -44,6 +44,7 @@ typedef virZPCIDeviceAddress *virZPCIDeviceAddressPtr; struct _virZPCIDeviceAddress { unsigned int uid; /* exempt from syntax-check */ unsigned int fid; + /* Don't forget to update virPCIDeviceAddressCopy if needed. */ }; =20 #define VIR_PCI_DEVICE_ADDRESS_FMT "%04x:%02x:%02x.%d" @@ -56,6 +57,7 @@ struct _virPCIDeviceAddress { int multi; /* virTristateSwitch */ int extFlags; /* enum virPCIDeviceAddressExtensionFlags */ virZPCIDeviceAddress zpci; + /* Don't forget to update virPCIDeviceAddressCopy if needed. */ }; =20 typedef enum { @@ -236,6 +238,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.23.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Fri Apr 26 22:05:19 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 207.211.31.120 as permitted sender) client-ip=207.211.31.120; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-1.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 207.211.31.120 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=1575296951; cv=none; d=zohomail.com; s=zohoarc; b=Xz+N3/ECnBEsl2+go/KBQAIjfztsvbiMk+pmQhThSL0V4EI6l65V/cjmbSucggiPIScL5epbUIos2epqsQhRu7e4Rojv3q/c6rEAsyR2in2ojehPfKa/KHQE/I0sf7DgxFfrwKKx616m97ah+H4c3sOr8X8hw35887AUOCPm2EQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1575296951; 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; bh=R069iecDYQIBD9AwHG0q94kz+FGqY/PrQ7Id+q/Vuqw=; b=bn5QgnrYF+YLg2iO+HajaPMdC7NsSGrJz2fpYd8sfROqfKz73WoJps5dcy1EPI4Uorbz3qSuVf8ufBsTsBL+84+1b9KWuAwKURKrxd6qy0rReMsvVSeC7/P+vm3lrL7mC/ckx1KtfPhTf1edFnM3QJPKFUwNs96JBx2yCQbVPpo= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 207.211.31.120 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from us-smtp-1.mimecast.com (us-smtp-delivery-1.mimecast.com [207.211.31.120]) by mx.zohomail.com with SMTPS id 15752969515951.040916666630551; Mon, 2 Dec 2019 06:29:11 -0800 (PST) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-220-eS0g4Vq2PxKKeoG1ijOZuw-1; Mon, 02 Dec 2019 09:27:42 -0500 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 mimecast-mx01.redhat.com (Postfix) with ESMTPS id D5AD48048F6; Mon, 2 Dec 2019 14:27:33 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id AABD3100194E; Mon, 2 Dec 2019 14:27:33 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 4A3A6180CB3B; Mon, 2 Dec 2019 14:27:33 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id xB2ER84h027328 for ; Mon, 2 Dec 2019 09:27:08 -0500 Received: by smtp.corp.redhat.com (Postfix) id 2301967648; Mon, 2 Dec 2019 14:27:08 +0000 (UTC) Received: from moe.redhat.com (unknown [10.43.2.30]) by smtp.corp.redhat.com (Postfix) with ESMTP id A032D6764D for ; Mon, 2 Dec 2019 14:27:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1575296950; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=R069iecDYQIBD9AwHG0q94kz+FGqY/PrQ7Id+q/Vuqw=; b=CbkPmV8eGkAWyKbIdLRXPPnWk5Imd6XCNCNs18If9NWL/sQd0Ymcn8391DT4WVFDWHhc0a XH0SOU8LEEGDslpezz6IsJ0n7MQk8N99cC7xUw+hIDNmBD52pUPxA8FXdXdKci0APf3FE+ gQ4M/BlpzuKvXIe8S+Llay8CdJtEEYo= From: Michal Privoznik To: libvir-list@redhat.com Date: Mon, 2 Dec 2019 15:26:32 +0100 Message-Id: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v3 09/30] qemuMigrationSrcIsSafe: Rework slightly X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , 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-MC-Unique: eS0g4Vq2PxKKeoG1ijOZuw-1 X-Mimecast-Spam-Score: 0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" There are going to be more disk types that are considered unsafe with respect to migration. Therefore, move the error reporting call outside of if() body and rework if-else combo to switch(). Signed-off-by: Michal Privoznik Reviewed-by: Cole Robinson --- src/qemu/qemu_migration.c | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/src/qemu/qemu_migration.c b/src/qemu/qemu_migration.c index c38bf342d7..e4760c6ad3 100644 --- a/src/qemu/qemu_migration.c +++ b/src/qemu/qemu_migration.c @@ -1228,6 +1228,8 @@ qemuMigrationSrcIsSafe(virDomainDefPtr def, for (i =3D 0; i < def->ndisks; i++) { virDomainDiskDefPtr disk =3D def->disks[i]; const char *src =3D virDomainDiskGetSource(disk); + int actualType =3D virStorageSourceGetActualType(disk->src); + bool unsafe =3D false; =20 /* Disks without any source (i.e. floppies and CD-ROMs) * OR readonly are safe. */ @@ -1241,21 +1243,34 @@ qemuMigrationSrcIsSafe(virDomainDefPtr def, continue; =20 /* However, disks on local FS (e.g. ext4) are not safe. */ - if (virStorageSourceGetActualType(disk->src) =3D=3D VIR_STORAGE_TY= PE_FILE) { + switch ((virStorageType) actualType) { + case VIR_STORAGE_TYPE_FILE: if ((rc =3D virFileIsSharedFS(src)) < 0) { return false; } else if (rc =3D=3D 0) { - virReportError(VIR_ERR_MIGRATE_UNSAFE, "%s", - _("Migration without shared storage is unsa= fe")); - return false; + unsafe =3D true; } if ((rc =3D virStorageFileIsClusterFS(src)) < 0) return false; else if (rc =3D=3D 1) continue; - } else if (virStorageSourceGetActualType(disk->src) =3D=3D VIR_STO= RAGE_TYPE_NETWORK) { + break; + case VIR_STORAGE_TYPE_NETWORK: /* But network disks are safe again. */ continue; + + case VIR_STORAGE_TYPE_NONE: + case VIR_STORAGE_TYPE_BLOCK: + case VIR_STORAGE_TYPE_DIR: + case VIR_STORAGE_TYPE_VOLUME: + case VIR_STORAGE_TYPE_LAST: + break; + } + + if (unsafe) { + virReportError(VIR_ERR_MIGRATE_UNSAFE, "%s", + _("Migration without shared storage is unsafe")= ); + return false; } =20 /* Our code elsewhere guarantees shared disks are either readonly = (in --=20 2.23.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Fri Apr 26 22:05:19 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 205.139.110.120 as permitted sender) client-ip=205.139.110.120; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-1.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 205.139.110.120 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=1575297018; cv=none; d=zohomail.com; s=zohoarc; b=QZ9kDHnlzwuIuv/2jXYm4mKWrz1Zc+L2m3BaBY4t8gn29cmgkFqArgreXYbVReFIrWD8bwxnrGo9McoFnTeHktkTuGMdU0Tf0glIc6KQDPzCdO6wuwXjKq8d38DESNbnfVxSx4yZzGX3sWdB3GpcWUEJY6YbghhG5foWrrUgL3A= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1575297018; 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; bh=Rn2vA4qtqU+OxxO4WEjpFW2W8ZI83HyUlLrwbRWPNXE=; b=EFWhpI1nFn6P50dyDayC5Er8XGzEMy5v22hpHZykrlSBZ1abGdJ7AeydD8q0eGnMc0+n7JPrFxpCdRkIvO2CBBqd3R+O45CBgdNXLyB71DSvZj5QnH8PaDzGLJj1eEiAfSIrLEi7uQK76Jgayc5uJttTT9aaPvdO9YddKgOCBvo= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 205.139.110.120 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from us-smtp-1.mimecast.com (us-smtp-delivery-1.mimecast.com [205.139.110.120]) by mx.zohomail.com with SMTPS id 1575297018740765.6896260022497; Mon, 2 Dec 2019 06:30:18 -0800 (PST) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-295-2PZejrJ9MK68jQuqkGmlqA-1; Mon, 02 Dec 2019 09:27:42 -0500 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 mimecast-mx01.redhat.com (Postfix) with ESMTPS id 962578C20F3; Mon, 2 Dec 2019 14:27:29 +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 6D0DD5D9E5; Mon, 2 Dec 2019 14:27: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 228C44EDB3; Mon, 2 Dec 2019 14:27:29 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id xB2ER9xx027343 for ; Mon, 2 Dec 2019 09:27:09 -0500 Received: by smtp.corp.redhat.com (Postfix) id ED6B867662; Mon, 2 Dec 2019 14:27:08 +0000 (UTC) Received: from moe.redhat.com (unknown [10.43.2.30]) by smtp.corp.redhat.com (Postfix) with ESMTP id 733F367648 for ; Mon, 2 Dec 2019 14:27:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1575297017; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=Rn2vA4qtqU+OxxO4WEjpFW2W8ZI83HyUlLrwbRWPNXE=; b=W2UC78+WE7RYWDuHVGVi73+lYzrdra03v9obrXCBqc/bYUE7V1cDJuDk0GeqEAf7D0ELyc xa0kBr548f0ZvL+hIUkslR1CaXFcmhlEu+UeSROQvS2g8UwL9jJqTt42J14raPHeI2TA5u eApDqEzj2YHA9D04P12+cvdiIXSRMmE= From: Michal Privoznik To: libvir-list@redhat.com Date: Mon, 2 Dec 2019 15:26:33 +0100 Message-Id: <479c0671df3f76fe3353d06c39002c1ec6878ce5.1575296392.git.mprivozn@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v3 10/30] 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: , 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-MC-Unique: 2PZejrJ9MK68jQuqkGmlqA-1 X-Mimecast-Spam-Score: 0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) 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 Reviewed-by: Cole Robinson --- docs/formatdomain.html.in | 57 +++++++++++++++++++++++-- docs/schemas/domaincommon.rng | 32 ++++++++++++++ tests/qemuxml2argvdata/disk-nvme.xml | 63 ++++++++++++++++++++++++++++ 3 files changed, 149 insertions(+), 3 deletions(-) create mode 100644 tests/qemuxml2argvdata/disk-nvme.xml diff --git a/docs/formatdomain.html.in b/docs/formatdomain.html.in index 6df4a8b26e..fe871d933f 100644 --- a/docs/formatdomain.html.in +++ b/docs/formatdomain.html.in @@ -2944,6 +2944,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 @@ -2957,7 +2964,8 @@ Valid values are "file", "block", "dir" (since 0.7.5), "network" (since 0.8.7), or - "volume" (since 1.0.5) + "volume" (since 1.0.5), or + "nvme" (since 5.6.0) and refer to the underlying source for the disk. Since 0.0.3 @@ -3140,6 +3148,43 @@ Since 1.0.5

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

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

+ + +
+ + + + +
+ + +
+ + + + +
+ + +
+ + + + +
+ + + + + +
+ + +
+ + + +
+ + + + + + --=20 2.23.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Fri Apr 26 22:05:19 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 207.211.31.81 as permitted sender) client-ip=207.211.31.81; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-1.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 207.211.31.81 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=1575296866; cv=none; d=zohomail.com; s=zohoarc; b=IUi4vRUOqGpCx1TVJDM6HdB0f3pmpnLnCRJJkXVEDLu1aNtajw5IPTH4lCyTUhpRlhFg7xLOVkLsdTARO3whCIbLGWn8N6V9K5SZRqka8bJB4pyOeLYDhv1DW/scBTm+mCSHOgmSe/Bbuv+RfoggQXOtP2OrU0ZerALoTipElNI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1575296866; 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; bh=MPC7kDRYqQy1lIrtMc23grj7A5ApKG4A+6YUW7VaUy8=; b=WUJsYD+1A3joqn6s1ycUknZd5xeJ4bizZUmBrzSdFa9A6yYY+Qa1wE+39eRnFVzR7R/6Pfeh8H7/InABTyqbJ72IyuR8a/w5SpAljk3YIYbZ4AZpRRB+Q2xfFHatMTI9o7/TB9MrZGo3se+A9ZNWdQsbdHK0RokKFjZQKWRhSbU= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 207.211.31.81 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from us-smtp-delivery-1.mimecast.com (us-smtp-1.mimecast.com [207.211.31.81]) by mx.zohomail.com with SMTPS id 1575296866836280.86576570989155; Mon, 2 Dec 2019 06:27:46 -0800 (PST) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-213-u8Mhra4RMHON7VHsAF6BQQ-1; Mon, 02 Dec 2019 09:27:43 -0500 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 mimecast-mx01.redhat.com (Postfix) with ESMTPS id 03AD8100E4E3; Mon, 2 Dec 2019 14:27:38 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id D08E4600CC; Mon, 2 Dec 2019 14:27:37 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 8422F5BBFE; Mon, 2 Dec 2019 14:27:37 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id xB2ER9sJ027351 for ; Mon, 2 Dec 2019 09:27:09 -0500 Received: by smtp.corp.redhat.com (Postfix) id E1FDEA4B86; Mon, 2 Dec 2019 14:27:09 +0000 (UTC) Received: from moe.redhat.com (unknown [10.43.2.30]) by smtp.corp.redhat.com (Postfix) with ESMTP id 4451E67E52 for ; Mon, 2 Dec 2019 14:27:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1575296865; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=MPC7kDRYqQy1lIrtMc23grj7A5ApKG4A+6YUW7VaUy8=; b=bEbu3HxmSU2fvxplacf8yhhSM5cpL8IME3ND+VBN1KrUnWCEBNceTq71/xZwmnj6fAdyAQ 7+AJAfHFvgEDrkv5UCKtTTKBbO0pSr05TYNd9NqWNlmdg0WqCqvz83iwlXD0w6TalGyjs7 pPSZ0A3jPNYowbUHx7y5C3pvJqt+qRc= From: Michal Privoznik To: libvir-list@redhat.com Date: Mon, 2 Dec 2019 15:26:34 +0100 Message-Id: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v3 11/30] 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: , 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-MC-Unique: u8Mhra4RMHON7VHsAF6BQQ-1 X-Mimecast-Spam-Score: 0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) 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 Reviewed-by: Cole Robinson --- src/conf/domain_conf.c | 95 ++++++++++++++++++++++++++ src/libvirt_private.syms | 1 + src/libxl/xen_xl.c | 1 + src/qemu/qemu_block.c | 2 + src/qemu/qemu_command.c | 1 + src/qemu/qemu_driver.c | 4 ++ src/qemu/qemu_migration.c | 5 ++ src/util/virstoragefile.c | 57 ++++++++++++++++ src/util/virstoragefile.h | 17 +++++ tests/qemuxml2xmloutdata/disk-nvme.xml | 1 + tests/qemuxml2xmltest.c | 1 + 11 files changed, 185 insertions(+) create mode 120000 tests/qemuxml2xmloutdata/disk-nvme.xml diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 9580884747..58879a66ba 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -5135,6 +5135,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; @@ -9271,6 +9276,75 @@ virDomainDiskSourceNetworkParse(xmlNodePtr node, } =20 =20 +static int +virDomainDiskSourceNVMeParse(xmlNodePtr node, + xmlXPathContextPtr ctxt, + virStorageSourcePtr src) +{ + g_autoptr(virStorageSourceNVMeDef) nvme =3D NULL; + g_autofree char *type =3D NULL; + g_autofree char *namespace =3D NULL; + g_autofree char *managed =3D NULL; + xmlNodePtr address; + + nvme =3D g_new0(virStorageSourceNVMeDef, 1); + + if (!(type =3D virXMLPropString(node, "type"))) { + virReportError(VIR_ERR_XML_ERROR, "%s", + _("missing 'type' attribute to disk source")); + return -1; + } + + if (STRNEQ(type, "pci")) { + virReportError(VIR_ERR_XML_ERROR, + _("unsupported source type '%s'"), + type); + return -1; + } + + if (!(namespace =3D virXMLPropString(node, "namespace"))) { + virReportError(VIR_ERR_XML_ERROR, "%s", + _("missing 'namespace' attribute to disk source")); + return -1; + } + + if (virStrToLong_ull(namespace, NULL, 10, &nvme->namespace) < 0) { + virReportError(VIR_ERR_XML_ERROR, + _("malformed namespace '%s'"), + namespace); + return -1; + } + + /* NVMe namespaces start from 1 */ + if (nvme->namespace =3D=3D 0) { + virReportError(VIR_ERR_XML_ERROR, "%s", + _("NVMe namespace can't be zero")); + return -1; + } + + if ((managed =3D virXMLPropString(node, "managed"))) { + if ((nvme->managed =3D virTristateBoolTypeFromString(managed)) <= =3D 0) { + virReportError(VIR_ERR_XML_ERROR, + _("malformed managed value '%s'"), + managed); + return -1; + } + } + + if (!(address =3D virXPathNode("./address", ctxt))) { + virReportError(VIR_ERR_XML_ERROR, "%s", + _("NVMe disk source is missing address")); + return -1; + } + + if (virPCIDeviceAddressParseXML(address, &nvme->pciAddr) < 0) + return -1; + + src->nvme =3D g_steal_pointer(&nvme); + return 0; +} + + static int virDomainDiskSourcePRParse(xmlNodePtr node, xmlXPathContextPtr ctxt, @@ -9369,6 +9443,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, @@ -24102,6 +24180,19 @@ virDomainDiskSourceFormatNetwork(virBufferPtr attr= Buf, } =20 =20 +static void +virDomainDiskSourceNVMeFormat(virBufferPtr attrBuf, + virBufferPtr childBuf, + const virStorageSourceNVMeDef *nvme) +{ + virBufferAddLit(attrBuf, " type=3D'pci'"); + virBufferAsprintf(attrBuf, " managed=3D'%s'", + virTristateBoolTypeToString(nvme->managed)); + virBufferAsprintf(attrBuf, " namespace=3D'%llu'", nvme->namespace); + virPCIDeviceAddressFormat(childBuf, nvme->pciAddr, false); +} + + static int virDomainDiskSourceFormatPrivateData(virBufferPtr buf, virStorageSourcePtr src, @@ -24178,6 +24269,10 @@ virDomainDiskSourceFormat(virBufferPtr buf, =20 break; =20 + case VIR_STORAGE_TYPE_NVME: + virDomainDiskSourceNVMeFormat(&attrBuf, &childBuf, src->nvme); + break; + case VIR_STORAGE_TYPE_NONE: case VIR_STORAGE_TYPE_LAST: virReportError(VIR_ERR_INTERNAL_ERROR, diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index 6e4ef0413b..d37d3867a6 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -3078,6 +3078,7 @@ virStorageSourceNetworkAssignDefaultPorts; virStorageSourceNew; virStorageSourceNewFromBacking; virStorageSourceNewFromBackingAbsolute; +virStorageSourceNVMeDefFree; virStorageSourceParseRBDColonString; virStorageSourcePoolDefFree; virStorageSourcePoolModeTypeFromString; diff --git a/src/libxl/xen_xl.c b/src/libxl/xen_xl.c index 396adf6dac..8e9770c367 100644 --- a/src/libxl/xen_xl.c +++ b/src/libxl/xen_xl.c @@ -1649,6 +1649,7 @@ xenFormatXLDiskSrc(virStorageSourcePtr src, char **sr= cstr) break; =20 case VIR_STORAGE_TYPE_VOLUME: + case VIR_STORAGE_TYPE_NVME: case VIR_STORAGE_TYPE_NONE: case VIR_STORAGE_TYPE_LAST: break; diff --git a/src/qemu/qemu_block.c b/src/qemu/qemu_block.c index ada2c52947..8eeb9c3c57 100644 --- a/src/qemu/qemu_block.c +++ b/src/qemu/qemu_block.c @@ -1060,6 +1060,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; @@ -2331,6 +2332,7 @@ qemuBlockStorageSourceCreateGetStorageProps(virStorag= eSourcePtr src, case VIR_STORAGE_TYPE_BLOCK: case VIR_STORAGE_TYPE_DIR: case VIR_STORAGE_TYPE_VOLUME: + case VIR_STORAGE_TYPE_NVME: return 0; =20 case VIR_STORAGE_TYPE_NONE: diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c index 3465d28b84..c61e38492a 100644 --- a/src/qemu/qemu_command.c +++ b/src/qemu/qemu_command.c @@ -1129,6 +1129,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 b5300241a8..72ee89db1f 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -14776,6 +14776,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, @@ -14792,6 +14793,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, @@ -14859,6 +14861,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, @@ -14986,6 +14989,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 e4760c6ad3..3705b263a6 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, @@ -1259,6 +1260,10 @@ qemuMigrationSrcIsSafe(virDomainDefPtr def, /* But network disks are safe again. */ continue; =20 + case VIR_STORAGE_TYPE_NVME: + unsafe =3D true; + break; + case VIR_STORAGE_TYPE_NONE: case VIR_STORAGE_TYPE_BLOCK: case VIR_STORAGE_TYPE_DIR: diff --git a/src/util/virstoragefile.c b/src/util/virstoragefile.c index 77f885ef1d..b4ec9624be 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, @@ -2094,6 +2095,49 @@ virStoragePRDefCopy(virStoragePRDefPtr src) } =20 =20 +static virStorageSourceNVMeDefPtr +virStorageSourceNVMeDefCopy(const virStorageSourceNVMeDef *src) +{ + virStorageSourceNVMeDefPtr ret =3D NULL; + + ret =3D g_new0(virStorageSourceNVMeDef, 1); + + ret->namespace =3D src->namespace; + ret->managed =3D src->managed; + virPCIDeviceAddressCopy(&ret->pciAddr, &src->pciAddr); + return 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) @@ -2292,6 +2336,9 @@ virStorageSourceCopy(const virStorageSource *src, !(def->pr =3D virStoragePRDefCopy(src->pr))) return NULL; =20 + if (src->nvme) + def->nvme =3D virStorageSourceNVMeDefCopy(src->nvme); + if (virStorageSourceInitiatorCopy(&def->initiator, &src->initiator) < = 0) return NULL; =20 @@ -2350,6 +2397,10 @@ virStorageSourceIsSameLocation(virStorageSourcePtr a, } } =20 + if (a->type =3D=3D VIR_STORAGE_TYPE_NVME && + !virStorageSourceNVMeDefIsEqual(a->nvme, b->nvme)) + return false; + return true; } =20 @@ -2432,6 +2483,9 @@ virStorageSourceIsLocalStorage(const virStorageSource= *src) =20 case VIR_STORAGE_TYPE_NETWORK: case VIR_STORAGE_TYPE_VOLUME: + /* While NVMe disks are local, they are not accessible via src->pa= th. + * Therefore, we have to return false here. */ + case VIR_STORAGE_TYPE_NVME: case VIR_STORAGE_TYPE_LAST: case VIR_STORAGE_TYPE_NONE: return false; @@ -2517,6 +2571,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); @@ -3773,6 +3828,7 @@ virStorageSourceUpdatePhysicalSize(virStorageSourcePt= r src, =20 /* We shouldn't get VOLUME, but the switch requires all cases */ case VIR_STORAGE_TYPE_VOLUME: + case VIR_STORAGE_TYPE_NVME: case VIR_STORAGE_TYPE_NONE: case VIR_STORAGE_TYPE_LAST: return -1; @@ -4229,6 +4285,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 c357803e50..42ca49bc64 100644 --- a/src/util/virstoragefile.h +++ b/src/util/virstoragefile.h @@ -30,6 +30,7 @@ #include "virutil.h" #include "virsecret.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. @@ -51,6 +52,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; @@ -230,6 +232,16 @@ struct _virStorageSourceInitiatorDef { char *iqn; /* Initiator IQN */ }; =20 +typedef struct _virStorageSourceNVMeDef virStorageSourceNVMeDef; +typedef virStorageSourceNVMeDef *virStorageSourceNVMeDefPtr; +struct _virStorageSourceNVMeDef { + unsigned long long namespace; + int managed; /* enum virTristateBool */ + virPCIDeviceAddress pciAddr; + + /* Don't forget to update virStorageSourceNVMeDefCopy */ +}; + typedef struct _virStorageDriverData virStorageDriverData; typedef virStorageDriverData *virStorageDriverDataPtr; =20 @@ -261,6 +273,8 @@ struct _virStorageSource { bool encryptionInherited; virStoragePRDefPtr pr; =20 + virStorageSourceNVMeDefPtr nvme; /* type =3D=3D VIR_STORAGE_TYPE_NVME = */ + virStorageSourceInitiatorDef initiator; =20 virObjectPtr privateData; @@ -416,6 +430,9 @@ bool virStoragePRDefIsManaged(virStoragePRDefPtr prd); bool virStorageSourceChainHasManagedPR(virStorageSourcePtr src); =20 +void virStorageSourceNVMeDefFree(virStorageSourceNVMeDefPtr def); +G_DEFINE_AUTOPTR_CLEANUP_FUNC(virStorageSourceNVMeDef, virStorageSourceNVM= eDefFree); + virSecurityDeviceLabelDefPtr virStorageSourceGetSecurityLabelDef(virStorageSourcePtr src, const char *model); diff --git a/tests/qemuxml2xmloutdata/disk-nvme.xml b/tests/qemuxml2xmloutd= ata/disk-nvme.xml new file mode 120000 index 0000000000..ea9eb267ac --- /dev/null +++ b/tests/qemuxml2xmloutdata/disk-nvme.xml @@ -0,0 +1 @@ +../qemuxml2argvdata/disk-nvme.xml \ No newline at end of file diff --git a/tests/qemuxml2xmltest.c b/tests/qemuxml2xmltest.c index 8b43f35f06..b11f086016 100644 --- a/tests/qemuxml2xmltest.c +++ b/tests/qemuxml2xmltest.c @@ -329,6 +329,7 @@ mymain(void) DO_TEST("disk-network-sheepdog", NONE); DO_TEST("disk-network-vxhs", NONE); DO_TEST("disk-network-tlsx509", NONE); + DO_TEST("disk-nvme", QEMU_CAPS_VIRTIO_SCSI, QEMU_CAPS_QCOW2_LUKS); DO_TEST("disk-scsi", QEMU_CAPS_SCSI_LSI, QEMU_CAPS_SCSI_MEGASAS, QEMU_CAPS_SCSI_MPTSAS1068, QEMU_CAPS_SCSI_DISK_WWN); DO_TEST("disk-virtio-scsi-reservations", --=20 2.23.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Fri Apr 26 22:05:19 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 205.139.110.120 as permitted sender) client-ip=205.139.110.120; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-1.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 205.139.110.120 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=1575296857; cv=none; d=zohomail.com; s=zohoarc; b=lzVk+NCQ68RXzeWwDD7L/HGkP/4t9hdA65piBSRg99ZnvO5W2DUR5pObBDAIoCJJRZAmIWBGH6EeFMmOXQUl5HFUugyGe/q2Q+p/JmGJfoEFOKDE1ckcRwu/2+nwIySU0FBS1qWx5K03JZzrPsFCuvXcD6bHrNboUOvNT0OZAf8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1575296857; 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; bh=ThreaABCB/77sdGmhYZhsd9MVeZDx7P3GC5laD+G4Bs=; b=fjqFv+yf3FGCgzCJOrdq7po2mnt3jE0TvvqzPpV0XQbINbdR2DR5R7Maozm55IzFgmWiqBfEMhFbGjEx8AMuyVOsTOOmgsPFuaVAVH7Ls+qsA+2W4ogHSjQqc9Ne9euCDe7olJwnuV4pvgDZsxFVCF6Zw6Lb16Xrr5MSre+7h5M= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 205.139.110.120 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from us-smtp-1.mimecast.com (us-smtp-delivery-1.mimecast.com [205.139.110.120]) by mx.zohomail.com with SMTPS id 1575296857789269.29871585951673; Mon, 2 Dec 2019 06:27:37 -0800 (PST) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-332-y3JFUwR6PJK682Pw_u9LQA-1; Mon, 02 Dec 2019 09:27:34 -0500 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 mimecast-mx01.redhat.com (Postfix) with ESMTPS id 378288048E8; Mon, 2 Dec 2019 14:27:27 +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 0C52B19756; Mon, 2 Dec 2019 14:27:27 +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 B4D8F1808855; Mon, 2 Dec 2019 14:27:26 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id xB2ERAcd027364 for ; Mon, 2 Dec 2019 09:27:10 -0500 Received: by smtp.corp.redhat.com (Postfix) id B508CA4B86; Mon, 2 Dec 2019 14:27:10 +0000 (UTC) Received: from moe.redhat.com (unknown [10.43.2.30]) by smtp.corp.redhat.com (Postfix) with ESMTP id 3B5BB6764D for ; Mon, 2 Dec 2019 14:27:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1575296856; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=ThreaABCB/77sdGmhYZhsd9MVeZDx7P3GC5laD+G4Bs=; b=YJyeECTFHni0YFu5tbaS4cd8A9E1poSZsOzuqhnE2xpDtLqPIwW7rUyTRhd0Simy1ESImZ BaU4C8gjVwya7AqSF6wJqyC9iUQCCp6mSqbT0icKi3xg47iCX8+0rdwsODXV4y9Nz9UzSU PkJ5pjAf+ktm6emZXPmQXCJA/Ogr654= From: Michal Privoznik To: libvir-list@redhat.com Date: Mon, 2 Dec 2019 15:26:35 +0100 Message-Id: <8a1e0debc0d6019c0c57b55ad0db0131e40a95b6.1575296392.git.mprivozn@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v3 12/30] 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: , 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-MC-Unique: y3JFUwR6PJK682Pw_u9LQA-1 X-Mimecast-Spam-Score: 0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" This function will return true if there's a storage source of type VIR_STORAGE_TYPE_NVME, or false otherwise. Signed-off-by: Michal Privoznik ACKed-by: Peter Krempa Reviewed-by: Cole Robinson --- 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 d37d3867a6..a7f94feb0a 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -3057,6 +3057,7 @@ virStoragePRDefIsManaged; virStoragePRDefParseXML; virStorageSourceBackingStoreClear; virStorageSourceChainHasManagedPR; +virStorageSourceChainHasNVMe; virStorageSourceClear; virStorageSourceCopy; virStorageSourceFindByNodeName; diff --git a/src/util/virstoragefile.c b/src/util/virstoragefile.c index b4ec9624be..5a5a16aef7 100644 --- a/src/util/virstoragefile.c +++ b/src/util/virstoragefile.c @@ -2138,6 +2138,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 42ca49bc64..39e50a989d 100644 --- a/src/util/virstoragefile.h +++ b/src/util/virstoragefile.h @@ -433,6 +433,8 @@ virStorageSourceChainHasManagedPR(virStorageSourcePtr s= rc); void virStorageSourceNVMeDefFree(virStorageSourceNVMeDefPtr def); G_DEFINE_AUTOPTR_CLEANUP_FUNC(virStorageSourceNVMeDef, virStorageSourceNVM= eDefFree); =20 +bool virStorageSourceChainHasNVMe(const virStorageSource *src); + virSecurityDeviceLabelDefPtr virStorageSourceGetSecurityLabelDef(virStorageSourcePtr src, const char *model); --=20 2.23.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Fri Apr 26 22:05:19 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 205.139.110.120 as permitted sender) client-ip=205.139.110.120; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-1.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 205.139.110.120 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=1575296860; cv=none; d=zohomail.com; s=zohoarc; b=lyoF3a/CuFoCiYzYaCT5fG1XNdIQ9JgQvON9txPFfEVikIGTefBtVgHekLf5sgH6ToBkR3qWTHtP9GGZxL5ADGYceseBm1pOEUBLkLB3CdKREfeHOwDWHHHX2j3yHJTfmCEKFlg4cR8BnFfJHq4GSU9e7EGNG62Dz8kS+nEbls8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1575296860; 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; bh=DjKvVPa5NOIIvJzXmolBt2gDPiYzoJhRJjD84AA4YkA=; b=XEoswwejfpDg6zOjUqRFzUMe2n8I4881fYTR0F86o1OhTrCSee2rnTroqoKbQX18LmfZ/aaTSiiqE0bw6O2Z5DR7D3wAccCEL30NTyCuLFy4MZVldsL/R6JnjxhEMDLCzq6QbyQse0E92CytV9eUDvxieXUmfrf/wy47d6nocKE= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 205.139.110.120 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from us-smtp-1.mimecast.com (us-smtp-delivery-1.mimecast.com [205.139.110.120]) by mx.zohomail.com with SMTPS id 1575296860712281.9402392768304; Mon, 2 Dec 2019 06:27:40 -0800 (PST) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-416-_IesVM_lPJ6EzOyW4CVZMA-1; Mon, 02 Dec 2019 09:27:38 -0500 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 mimecast-mx01.redhat.com (Postfix) with ESMTPS id 370C9100E4D0; Mon, 2 Dec 2019 14:27:31 +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 0196B1001B00; Mon, 2 Dec 2019 14:27:31 +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 895EB4EDBD; Mon, 2 Dec 2019 14:27:30 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id xB2ERBTt027376 for ; Mon, 2 Dec 2019 09:27:11 -0500 Received: by smtp.corp.redhat.com (Postfix) id 839C567648; Mon, 2 Dec 2019 14:27:11 +0000 (UTC) Received: from moe.redhat.com (unknown [10.43.2.30]) by smtp.corp.redhat.com (Postfix) with ESMTP id 0CB9FA4B86 for ; Mon, 2 Dec 2019 14:27:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1575296859; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=DjKvVPa5NOIIvJzXmolBt2gDPiYzoJhRJjD84AA4YkA=; b=bDLVWbBpxL16O0bu0EUUyBx5LLhPJNVkgDznszIcFHlDfchSDyl0vfLAgXo26e2EobCMyY 0WfVFfcDBOF4jYyn1h8Awwd+V2vqSK9Vto+9/pgXG0Lu4bARzKc4h/FwPAIhnoW/cd5Xam pmOJK2Y0AYpoASYISDemM/JP+8DWVTk= From: Michal Privoznik To: libvir-list@redhat.com Date: Mon, 2 Dec 2019 15:26:36 +0100 Message-Id: <43d036e7df9354e2ff0da056faefaf789623a5a7.1575296392.git.mprivozn@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v3 13/30] 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: , 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-MC-Unique: _IesVM_lPJ6EzOyW4CVZMA-1 X-Mimecast-Spam-Score: 0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" This function will return true if any of disks (or their backing chain) for given domain contains an NVMe disk. Signed-off-by: Michal Privoznik ACKed-by: Peter Krempa Reviewed-by: Cole Robinson --- src/conf/domain_conf.c | 14 ++++++++++++++ src/conf/domain_conf.h | 3 +++ src/libvirt_private.syms | 1 + 3 files changed, 18 insertions(+) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 58879a66ba..b6e04db0f7 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -31467,6 +31467,20 @@ virDomainDefHasManagedPR(const virDomainDef *def) } =20 =20 +bool +virDomainDefHasNVMeDisk(const virDomainDef *def) +{ + size_t i; + + for (i =3D 0; i < def->ndisks; i++) { + if (virStorageSourceChainHasNVMe(def->disks[i]->src)) + return true; + } + + return false; +} + + bool virDomainDefHasVFIOHostdev(const virDomainDef *def) { diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h index 49cb6970e6..520d2da0d2 100644 --- a/src/conf/domain_conf.h +++ b/src/conf/domain_conf.h @@ -3674,6 +3674,9 @@ virDomainDiskGetDetectZeroesMode(virDomainDiskDiscard= discard, bool virDomainDefHasManagedPR(const virDomainDef *def); =20 +bool +virDomainDefHasNVMeDisk(const virDomainDef *def); + bool virDomainDefHasVFIOHostdev(const virDomainDef *def); =20 diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index a7f94feb0a..86ee9cbc53 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -297,6 +297,7 @@ virDomainDefHasManagedPR; virDomainDefHasMdevHostdev; virDomainDefHasMemballoon; virDomainDefHasMemoryHotplug; +virDomainDefHasNVMeDisk; virDomainDefHasUSB; virDomainDefHasVcpusOffline; virDomainDefHasVFIOHostdev; --=20 2.23.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Fri Apr 26 22:05:19 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 205.139.110.120 as permitted sender) client-ip=205.139.110.120; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-1.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 205.139.110.120 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=1575296865; cv=none; d=zohomail.com; s=zohoarc; b=fivIeZcYXOUFeNwZ9UZ4U7L20jrycE8WzRd1xEN5dUnU/OpQILrQ5sUD4e+07zaAQOhnjITjn2bn6NNv6b3Sp3/ovuk0zQjnJXx9Ggl1UfCrQXXRUSDJlPVPUTptE5OIQ8tXXgdVE9UY0imv/HVVxdDN5t7aOg4KxOX4txazktM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1575296865; 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; bh=UIEMJO5kOzZjf4A7Ock0mv/V+v464Xpz7tQ3xjfSGWM=; b=ORNK5kI/x+h2/ioi5eLdQKUmggfRZ9aN9mUfbRoJKrdvqMLpYPLQxOJz4fD4oWHT4IqPZJzC8j/h0w/KvPPxs/XmsbH3Q0QBCzTIZe5dJFLXrJkSkqWlefMgiz66X44bATo0hhIKJ1I0p0HCzVmbu2QxI2qxsQEhlPuPsL6N36I= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 205.139.110.120 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from us-smtp-1.mimecast.com (us-smtp-delivery-1.mimecast.com [205.139.110.120]) by mx.zohomail.com with SMTPS id 1575296865953717.5963612018621; Mon, 2 Dec 2019 06:27:45 -0800 (PST) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-190-ZFuPn4O_M3a36vpCOIZ8Ww-1; Mon, 02 Dec 2019 09:27:41 -0500 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 mimecast-mx01.redhat.com (Postfix) with ESMTPS id 9DC75802566; Mon, 2 Dec 2019 14:27:35 +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 752821001B00; Mon, 2 Dec 2019 14:27:35 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 158414EA4D; Mon, 2 Dec 2019 14:27:35 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id xB2ERCt4027385 for ; Mon, 2 Dec 2019 09:27:12 -0500 Received: by smtp.corp.redhat.com (Postfix) id 53C5867648; Mon, 2 Dec 2019 14:27:12 +0000 (UTC) Received: from moe.redhat.com (unknown [10.43.2.30]) by smtp.corp.redhat.com (Postfix) with ESMTP id D1231A4B86 for ; Mon, 2 Dec 2019 14:27:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1575296864; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=UIEMJO5kOzZjf4A7Ock0mv/V+v464Xpz7tQ3xjfSGWM=; b=Mwn0HoCc+hqTO5x5MAcClRQ8EEduuy5lyAWEOMDSP7va0iaSu5+GTJhb0TBbu+t2aaf/Dn zrCIS4yUCIyLxAnXBZ7oVlxF0qNbn5vss2HHvHWNZ82tisZ2UivifW8+lpeDHABYK0ZUsb 6kf2XJ3aFX+iCjujDC3N/EL2a1oMegY= From: Michal Privoznik To: libvir-list@redhat.com Date: Mon, 2 Dec 2019 15:26:37 +0100 Message-Id: <6c1b84a1760f3277daac37c2916b794dc7a143c3.1575296392.git.mprivozn@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v3 14/30] 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: , 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-MC-Unique: ZFuPn4O_M3a36vpCOIZ8Ww-1 X-Mimecast-Spam-Score: 0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) 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 Reviewed-by: Cole Robinson --- po/POTFILES.in | 1 + src/libvirt_private.syms | 18 ++ src/util/Makefile.inc.am | 2 + src/util/virnvme.c | 447 +++++++++++++++++++++++++++++++++++++++ src/util/virnvme.h | 95 +++++++++ 5 files changed, 563 insertions(+) create mode 100644 src/util/virnvme.c create mode 100644 src/util/virnvme.h diff --git a/po/POTFILES.in b/po/POTFILES.in index debb51cd70..3d075201c4 100644 --- a/po/POTFILES.in +++ b/po/POTFILES.in @@ -277,6 +277,7 @@ @SRCDIR@/src/util/virnetlink.c @SRCDIR@/src/util/virnodesuspend.c @SRCDIR@/src/util/virnuma.c +@SRCDIR@/src/util/virnvme.c @SRCDIR@/src/util/virobject.c @SRCDIR@/src/util/virpci.c @SRCDIR@/src/util/virperf.c diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index 86ee9cbc53..aab2b49bdf 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -2664,6 +2664,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 0855f152fd..838e9479a9 100644 --- a/src/util/Makefile.inc.am +++ b/src/util/Makefile.inc.am @@ -150,6 +150,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..b8179aa431 --- /dev/null +++ b/src/util/virnvme.c @@ -0,0 +1,447 @@ +/* + * virnvme.c: helper APIs for managing NVMe devices + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library. If not, see + * . + */ + +#include + +#include "virnvme.h" +#include "virobject.h" +#include "virpci.h" +#include "viralloc.h" +#include "virlog.h" +#include "virstring.h" + +VIR_LOG_INIT("util.nvme"); +#define VIR_FROM_THIS VIR_FROM_NONE + +struct _virNVMeDevice { + virPCIDeviceAddress address; /* PCI address of controller */ + unsigned int namespace; /* Namespace ID */ + bool managed; + + char *drvname; + char *domname; +}; + + +struct _virNVMeDeviceList { + virObjectLockable parent; + + size_t count; + virNVMeDevicePtr *devs; +}; + + +static virClassPtr virNVMeDeviceListClass; + +static void virNVMeDeviceListDispose(void *obj); + +static int +virNVMeOnceInit(void) +{ + if (!VIR_CLASS_NEW(virNVMeDeviceList, virClassForObjectLockable())) + return -1; + + return 0; +} + +VIR_ONCE_GLOBAL_INIT(virNVMe); + + +virNVMeDevicePtr +virNVMeDeviceNew(const virPCIDeviceAddress *address, + unsigned long namespace, + bool managed) +{ + virNVMeDevicePtr dev =3D NULL; + + dev =3D g_new0(virNVMeDevice, 1); + + virPCIDeviceAddressCopy(&dev->address, address); + dev->namespace =3D namespace; + dev->managed =3D managed; + + return dev; +} + + +void +virNVMeDeviceFree(virNVMeDevicePtr dev) +{ + if (!dev) + return; + + virNVMeDeviceUsedByClear(dev); + VIR_FREE(dev); +} + + +virNVMeDevicePtr +virNVMeDeviceCopy(const virNVMeDevice *dev) +{ + virNVMeDevicePtr copy =3D NULL; + + copy =3D g_new0(virNVMeDevice, 1); + copy->drvname =3D g_strdup(dev->drvname); + copy->domname =3D g_strdup(dev->domname); + + virPCIDeviceAddressCopy(©->address, &dev->address); + copy->namespace =3D dev->namespace; + copy->managed =3D dev->managed; + + return 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; +} + + +void +virNVMeDeviceUsedBySet(virNVMeDevicePtr dev, + const char *drv, + const char *dom) +{ + dev->drvname =3D g_strdup(drv); + dev->domname =3D g_strdup(dom); +} + + +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))) { + g_autofree char *addrStr =3D virPCIDeviceAddressAsString(&tmp->add= ress); + virReportError(VIR_ERR_INTERNAL_ERROR, + _("NVMe device %s namespace %u is already on the li= st"), + NULLSTR(addrStr), tmp->namespace); + return -1; + } + + if (!(tmp =3D virNVMeDeviceCopy(dev)) || + VIR_APPEND_ELEMENT(list->devs, list->count, tmp) < 0) { + virNVMeDeviceFree(tmp); + return -1; + } + + return 0; +} + + +int +virNVMeDeviceListDel(virNVMeDeviceListPtr list, + const virNVMeDevice *dev) +{ + ssize_t idx; + virNVMeDevicePtr tmp =3D NULL; + + if ((idx =3D virNVMeDeviceListLookupIndex(list, dev)) < 0) { + g_autofree char *addrStr =3D virPCIDeviceAddressAsString(&dev->add= ress); + virReportError(VIR_ERR_INTERNAL_ERROR, + _("NVMe device %s namespace %u not found"), + NULLSTR(addrStr), dev->namespace); + return -1; + } + + tmp =3D list->devs[idx]; + VIR_DELETE_ELEMENT(list->devs, idx, list->count); + virNVMeDeviceFree(tmp); + return 0; +} + + +virNVMeDevicePtr +virNVMeDeviceListGet(virNVMeDeviceListPtr list, + size_t i) +{ + return i < list->count ? list->devs[i] : NULL; +} + + +virNVMeDevicePtr +virNVMeDeviceListLookup(virNVMeDeviceListPtr list, + const virNVMeDevice *dev) +{ + ssize_t idx; + + if ((idx =3D virNVMeDeviceListLookupIndex(list, dev)) < 0) + return NULL; + + return list->devs[idx]; +} + + +ssize_t +virNVMeDeviceListLookupIndex(virNVMeDeviceListPtr list, + const virNVMeDevice *dev) +{ + size_t i; + + if (!list) + return -1; + + for (i =3D 0; i < list->count; i++) { + virNVMeDevicePtr other =3D list->devs[i]; + + if (virPCIDeviceAddressEqual(&dev->address, &other->address) && + dev->namespace =3D=3D other->namespace) + return i; + } + + return -1; +} + + +static virNVMeDevicePtr +virNVMeDeviceListLookupByPCIAddress(virNVMeDeviceListPtr list, + const virPCIDeviceAddress *address) +{ + size_t i; + + if (!list) + return NULL; + + for (i =3D 0; i < list->count; i++) { + virNVMeDevicePtr other =3D list->devs[i]; + + if (virPCIDeviceAddressEqual(address, &other->address)) + return other; + } + + return NULL; +} + + +static virPCIDevicePtr +virNVMeDeviceCreatePCIDevice(const virNVMeDevice *nvme) +{ + g_autoptr(virPCIDevice) pci =3D NULL; + + if (!(pci =3D virPCIDeviceNew(nvme->address.domain, + nvme->address.bus, + nvme->address.slot, + nvme->address.function))) + return NULL; + + /* NVMe devices must be bound to vfio */ + virPCIDeviceSetStubDriver(pci, VIR_PCI_STUB_DRIVER_VFIO); + virPCIDeviceSetManaged(pci, nvme->managed); + + return g_steal_pointer(&pci); +} + + +/** + * virNVMeDeviceListCreateDetachList: + * @activeList: list of active NVMe devices + * @toDetachList: list of NVMe devices to detach from the host + * + * This function creates a list of PCI devices which can then be + * reused by PCI device detach functions (e.g. + * virHostdevPreparePCIDevicesImpl()) as each PCI device from the + * returned list is initialized properly for detach. + * + * Basically, this just blindly collects unique PCI addresses + * from @toDetachList that don't appear on @activeList. + * + * Returns: a list on success, + * NULL otherwise. + */ +virPCIDeviceListPtr +virNVMeDeviceListCreateDetachList(virNVMeDeviceListPtr activeList, + virNVMeDeviceListPtr toDetachList) +{ + g_autoptr(virPCIDeviceList) 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]; + g_autoptr(virPCIDevice) pci =3D NULL; + + /* If there is a NVMe device with the same PCI address on + * the activeList, the device is already detached. */ + if (virNVMeDeviceListLookupByPCIAddress(activeList, &d->address)) + continue; + + /* It may happen that we want to detach two namespaces + * from the same NVMe device. This will be represented as + * two different instances of virNVMeDevice, but + * obviously we want to put the PCI device on the detach + * list only once. */ + if (virPCIDeviceListFindByIDs(pciDevices, + d->address.domain, + d->address.bus, + d->address.slot, + d->address.function)) + continue; + + if (!(pci =3D virNVMeDeviceCreatePCIDevice(d))) + return NULL; + + if (virPCIDeviceListAdd(pciDevices, pci) < 0) + return NULL; + + /* avoid freeing the device */ + pci =3D NULL; + } + + return g_steal_pointer(&pciDevices); +} + + +/** + * virNVMeDeviceListCreateReAttachList: + * @activeList: list of active NVMe devices + * @toReAttachList: list of devices to reattach to the host + * + * This is a counterpart to virNVMeDeviceListCreateDetachList. + * + * This function creates a list of PCI devices which can then be + * reused by PCI device reattach functions (e.g. + * virHostdevReAttachPCIDevicesImpl()) as each PCI device from + * the returned list is initialized properly for reattach. + * + * Basically, this just collects unique PCI addresses + * of devices that appear on @toReAttachList and are used + * exactly once (i.e. no other namespaces are used from the same + * NVMe device). For that purpose, this function needs to know + * list of active NVMe devices (@activeList). + * + * Returns: a list on success, + * NULL otherwise. + */ +virPCIDeviceListPtr +virNVMeDeviceListCreateReAttachList(virNVMeDeviceListPtr activeList, + virNVMeDeviceListPtr toReAttachList) +{ + g_autoptr(virPCIDeviceList) 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]; + g_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) */ + g_autofree char *addrStr =3D virPCIDeviceAddressAsString(&d->a= ddress); + virReportError(VIR_ERR_INTERNAL_ERROR, + _("NVMe device %s namespace %u not found"), + NULLSTR(addrStr), d->namespace); + return NULL; + } else if (nused > 1) { + /* NVMe device is still in use */ + continue; + } + + /* nused =3D=3D 1 -> detach the device */ + if (!(pci =3D virNVMeDeviceCreatePCIDevice(d))) + return NULL; + + if (virPCIDeviceListAdd(pciDevices, pci) < 0) + return NULL; + + /* avoid freeing the device */ + pci =3D NULL; + } + + return g_steal_pointer(&pciDevices); +} diff --git a/src/util/virnvme.h b/src/util/virnvme.h new file mode 100644 index 0000000000..911a9d29f3 --- /dev/null +++ b/src/util/virnvme.h @@ -0,0 +1,95 @@ +/* + * virnvme.h: helper APIs for managing NVMe devices + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library. If not, see + * . + */ + +#pragma once + +#include "virpci.h" + +typedef struct _virNVMeDevice virNVMeDevice; +typedef virNVMeDevice *virNVMeDevicePtr; + +/* Note that this list is lockable, and in fact, it is caller's + * responsibility to acquire the lock and release it. The reason + * is that in a lot of cases the list must be locked between two + * API calls and therefore only caller knows when it is safe to + * finally release the lock. */ +typedef struct _virNVMeDeviceList virNVMeDeviceList; +typedef virNVMeDeviceList *virNVMeDeviceListPtr; + +virNVMeDevicePtr +virNVMeDeviceNew(const virPCIDeviceAddress *address, + unsigned long namespace, + bool managed); + +void +virNVMeDeviceFree(virNVMeDevicePtr dev); + +G_DEFINE_AUTOPTR_CLEANUP_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); + +void +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.23.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Fri Apr 26 22:05:19 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 207.211.31.120 as permitted sender) client-ip=207.211.31.120; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-1.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 207.211.31.120 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=1575296883; cv=none; d=zohomail.com; s=zohoarc; b=LcCj6Cnv1IyqqVeGD2Sc2fnwzfxqv+uwrnXz655KpcbB340VTmMdX6B0vbGF1TLu8VsgFmYE10WZoHxfB8AloSFGjwnKMXq16BZxob//NKsFc0KM7EzM4dmsiNtygugvE3KOgqXv6BhYo9kMVtToa8S8xs1nzi4TzzVMUXO0oNc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1575296883; 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; bh=Z7ag8b0pCvrKNOyPbz3b6pIAo1XqBgQl1zLzkOQB6Fg=; b=Y2P7IvghFRYxpilatBfIhSdxUWpXDVpTvblAqP+9ujrkPGcHsheF6ztPiwZVAhwIVWbWmrMzhyZe5MCQFQAWImPQo8K18ODrLNYDiHMS4nCrPmGzV2sqTtDO/oinOBP/hu9PAxzZQF3TN/35ilGBnAD1kLYxizZmZOUrMVRb7W8= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 207.211.31.120 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from us-smtp-1.mimecast.com (us-smtp-delivery-1.mimecast.com [207.211.31.120]) by mx.zohomail.com with SMTPS id 1575296883210933.9249668959131; Mon, 2 Dec 2019 06:28:03 -0800 (PST) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-190-QgzLIcjKOx-vco4mnZyEPg-1; Mon, 02 Dec 2019 09:27:41 -0500 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 mimecast-mx01.redhat.com (Postfix) with ESMTPS id 9E9D5802561; Mon, 2 Dec 2019 14:27:35 +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 767E21001B03; Mon, 2 Dec 2019 14:27:35 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 146F44EA4B; Mon, 2 Dec 2019 14:27:35 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id xB2ERDBr027390 for ; Mon, 2 Dec 2019 09:27:13 -0500 Received: by smtp.corp.redhat.com (Postfix) id 253D667648; Mon, 2 Dec 2019 14:27:13 +0000 (UTC) Received: from moe.redhat.com (unknown [10.43.2.30]) by smtp.corp.redhat.com (Postfix) with ESMTP id A2018A4B86 for ; Mon, 2 Dec 2019 14:27:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1575296881; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=Z7ag8b0pCvrKNOyPbz3b6pIAo1XqBgQl1zLzkOQB6Fg=; b=N6T9Upskpd8Xpf2GsIS4SHMW5StqHz2HrAwJ/gOI4Gyw88EMV6A1uUzkMzVxrJpu9UX+70 MUfw/bdXM9YbWz0jH52DpGRiCMtiYg607pBXixNaCWjx1CM4kCrTOvOwYlvru+1S6omaUF ML2o+7N/Ahze0nvJzUUM2bLClA8Z7uI= From: Michal Privoznik To: libvir-list@redhat.com Date: Mon, 2 Dec 2019 15:26:38 +0100 Message-Id: <24e25b213d1c1bd47e1d700cadb65969dbd5af27.1575296392.git.mprivozn@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v3 15/30] 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: , 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-MC-Unique: QgzLIcjKOx-vco4mnZyEPg-1 X-Mimecast-Spam-Score: 0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) 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 Reviewed-by: Cole Robinson --- src/libvirt_private.syms | 5 + src/util/virhostdev.c | 331 +++++++++++++++++++++++++++++++++++++++ src/util/virhostdev.h | 37 +++++ src/util/virnvme.h | 2 + 4 files changed, 375 insertions(+) diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index aab2b49bdf..398f8c21ac 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -2146,18 +2146,23 @@ virHostdevPCINodeDeviceReAttach; virHostdevPCINodeDeviceReset; virHostdevPrepareDomainDevices; virHostdevPrepareMediatedDevices; +virHostdevPrepareNVMeDevices; +virHostdevPrepareOneNVMeDevice; virHostdevPreparePCIDevices; virHostdevPrepareSCSIDevices; virHostdevPrepareSCSIVHostDevices; virHostdevPrepareUSBDevices; virHostdevReAttachDomainDevices; virHostdevReAttachMediatedDevices; +virHostdevReAttachNVMeDevices; +virHostdevReAttachOneNVMeDevice; virHostdevReAttachPCIDevices; virHostdevReAttachSCSIDevices; virHostdevReAttachSCSIVHostDevices; virHostdevReAttachUSBDevices; virHostdevUpdateActiveDomainDevices; virHostdevUpdateActiveMediatedDevices; +virHostdevUpdateActiveNVMeDevices; virHostdevUpdateActivePCIDevices; virHostdevUpdateActiveSCSIDevices; virHostdevUpdateActiveUSBDevices; diff --git a/src/util/virhostdev.c b/src/util/virhostdev.c index 94a0185597..78e409732a 100644 --- a/src/util/virhostdev.c +++ b/src/util/virhostdev.c @@ -135,6 +135,7 @@ virHostdevManagerDispose(void *obj) virObjectUnref(hostdevMgr->activeSCSIHostdevs); virObjectUnref(hostdevMgr->activeSCSIVHostHostdevs); virObjectUnref(hostdevMgr->activeMediatedHostdevs); + virObjectUnref(hostdevMgr->activeNVMeHostdevs); VIR_FREE(hostdevMgr->stateDir); } =20 @@ -165,6 +166,9 @@ virHostdevManagerNew(void) if (!(hostdevMgr->activeMediatedHostdevs =3D virMediatedDeviceListNew(= ))) return NULL; =20 + if (!(hostdevMgr->activeNVMeHostdevs =3D virNVMeDeviceListNew())) + return NULL; + if (privileged) { hostdevMgr->stateDir =3D g_strdup(HOSTDEV_STATE_DIR); =20 @@ -2235,3 +2239,330 @@ virHostdevUpdateActiveDomainDevices(virHostdevManag= erPtr mgr, =20 return 0; } + + +static int +virHostdevGetNVMeDeviceList(virNVMeDeviceListPtr nvmeDevices, + virStorageSourcePtr src, + const char *drv_name, + const char *dom_name) +{ + virStorageSourcePtr n; + + for (n =3D src; virStorageSourceIsBacking(n); n =3D n->backingStore) { + g_autoptr(virNVMeDevice) dev =3D NULL; + const virStorageSourceNVMeDef *srcNVMe =3D n->nvme; + + if (n->type !=3D VIR_STORAGE_TYPE_NVME) + continue; + + if (!(dev =3D virNVMeDeviceNew(&srcNVMe->pciAddr, + srcNVMe->namespace, + srcNVMe->managed))) + return -1; + + virNVMeDeviceUsedBySet(dev, drv_name, dom_name); + + if (virNVMeDeviceListAdd(nvmeDevices, dev) < 0) + return -1; + } + + return 0; +} + + +int +virHostdevPrepareOneNVMeDevice(virHostdevManagerPtr hostdev_mgr, + const char *drv_name, + const char *dom_name, + virStorageSourcePtr src) +{ + g_autoptr(virNVMeDeviceList) nvmeDevices =3D NULL; + g_autoptr(virPCIDeviceList) pciDevices =3D NULL; + const unsigned int pciFlags =3D 0; + virNVMeDevicePtr temp =3D NULL; + size_t i; + ssize_t lastGoodNVMeIdx =3D -1; + int ret =3D -1; + + if (!(nvmeDevices =3D virNVMeDeviceListNew())) + return -1; + + if (virHostdevGetNVMeDeviceList(nvmeDevices, src, drv_name, dom_name) = < 0) + return -1; + + if (virNVMeDeviceListCount(nvmeDevices) =3D=3D 0) + return 0; + + virObjectLock(hostdev_mgr->activeNVMeHostdevs); + + /* Firstly, let's check if all devices are free */ + for (i =3D 0; i < virNVMeDeviceListCount(nvmeDevices); i++) { + const virNVMeDevice *dev =3D virNVMeDeviceListGet(nvmeDevices, i); + const virPCIDeviceAddress *addr =3D NULL; + g_autofree char *addrStr =3D NULL; + const char *actual_drvname =3D NULL; + const char *actual_domname =3D NULL; + + temp =3D virNVMeDeviceListLookup(hostdev_mgr->activeNVMeHostdevs, = dev); + + /* Not on the list means not used */ + if (!temp) + continue; + + virNVMeDeviceUsedByGet(temp, &actual_drvname, &actual_domname); + addr =3D virNVMeDeviceAddressGet(dev); + addrStr =3D virPCIDeviceAddressAsString(addr); + + virReportError(VIR_ERR_OPERATION_INVALID, + _("NVMe device %s already in use by driver %s domai= n %s"), + NULLSTR(addrStr), actual_drvname, actual_domname); + goto cleanup; + } + + if (!(pciDevices =3D virNVMeDeviceListCreateDetachList(hostdev_mgr->ac= tiveNVMeHostdevs, + nvmeDevices))) + goto cleanup; + + /* Let's check if all PCI devices are NVMe disks. */ + for (i =3D 0; i < virPCIDeviceListCount(pciDevices); i++) { + virPCIDevicePtr pci =3D virPCIDeviceListGet(pciDevices, i); + g_autofree char *drvPath =3D NULL; + g_autofree char *drvName =3D NULL; + int stub =3D VIR_PCI_STUB_DRIVER_NONE; + + if (virPCIDeviceGetDriverPathAndName(pci, &drvPath, &drvName) < 0) + goto cleanup; + + if (drvName) + stub =3D virPCIStubDriverTypeFromString(drvName); + + if (stub =3D=3D VIR_PCI_STUB_DRIVER_VFIO || + STREQ_NULLABLE(drvName, "nvme")) + continue; + + VIR_WARN("Suspicious NVMe disk assignment. PCI device " + "%s is not an NVMe disk, it has %s driver", + virPCIDeviceGetName(pci), NULLSTR(drvName)); + } + + /* This looks like a good opportunity to merge inactive NVMe devices o= nto + * the active list. This, however, means that if something goes wrong = we + * have to perform a rollback before returning. */ + for (i =3D 0; i < virNVMeDeviceListCount(nvmeDevices); i++) { + temp =3D virNVMeDeviceListGet(nvmeDevices, i); + + if (virNVMeDeviceListAdd(hostdev_mgr->activeNVMeHostdevs, temp) < = 0) + goto rollback; + + lastGoodNVMeIdx =3D i; + } + + if (virHostdevPreparePCIDevicesImpl(hostdev_mgr, + drv_name, dom_name, NULL, + pciDevices, NULL, 0, pciFlags) < 0) + goto rollback; + + ret =3D 0; + cleanup: + virObjectUnlock(hostdev_mgr->activeNVMeHostdevs); + return ret; + + rollback: + while (lastGoodNVMeIdx >=3D 0) { + temp =3D virNVMeDeviceListGet(nvmeDevices, lastGoodNVMeIdx); + + virNVMeDeviceListDel(hostdev_mgr->activeNVMeHostdevs, temp); + + lastGoodNVMeIdx--; + } + goto cleanup; +} + + +int +virHostdevPrepareNVMeDevices(virHostdevManagerPtr hostdev_mgr, + const char *drv_name, + const char *dom_name, + virDomainDiskDefPtr *disks, + size_t ndisks) +{ + size_t i; + ssize_t lastGoodDiskIdx =3D -1; + + for (i =3D 0; i < ndisks; i++) { + if (virHostdevPrepareOneNVMeDevice(hostdev_mgr, drv_name, + dom_name, disks[i]->src) < 0) + goto rollback; + + lastGoodDiskIdx =3D i; + } + + return 0; + + rollback: + while (lastGoodDiskIdx >=3D 0) { + if (virHostdevReAttachOneNVMeDevice(hostdev_mgr, drv_name, dom_nam= e, + disks[lastGoodDiskIdx]->src) <= 0) { + VIR_ERROR(_("Failed to reattach NVMe for disk target: %s"), + disks[lastGoodDiskIdx]->dst); + } + + lastGoodDiskIdx--; + } + + return -1; +} + + +int +virHostdevReAttachOneNVMeDevice(virHostdevManagerPtr hostdev_mgr, + const char *drv_name, + const char *dom_name, + virStorageSourcePtr src) +{ + g_autoptr(virNVMeDeviceList) nvmeDevices =3D NULL; + g_autoptr(virPCIDeviceList) pciDevices =3D NULL; + size_t i; + int ret =3D -1; + + if (!(nvmeDevices =3D virNVMeDeviceListNew())) + return -1; + + if (virHostdevGetNVMeDeviceList(nvmeDevices, src, drv_name, dom_name) = < 0) + return -1; + + if (virNVMeDeviceListCount(nvmeDevices) =3D=3D 0) + return 0; + + virObjectLock(hostdev_mgr->activeNVMeHostdevs); + + if (!(pciDevices =3D virNVMeDeviceListCreateReAttachList(hostdev_mgr->= activeNVMeHostdevs, + nvmeDevices))) + goto cleanup; + + virHostdevReAttachPCIDevicesImpl(hostdev_mgr, + drv_name, dom_name, pciDevices, + NULL, 0, NULL); + + for (i =3D 0; i < virNVMeDeviceListCount(nvmeDevices); i++) { + virNVMeDevicePtr temp =3D virNVMeDeviceListGet(nvmeDevices, i); + + if (virNVMeDeviceListDel(hostdev_mgr->activeNVMeHostdevs, temp) < = 0) + goto cleanup; + } + + ret =3D 0; + cleanup: + virObjectUnlock(hostdev_mgr->activeNVMeHostdevs); + return ret; +} + + +int +virHostdevReAttachNVMeDevices(virHostdevManagerPtr hostdev_mgr, + const char *drv_name, + const char *dom_name, + virDomainDiskDefPtr *disks, + size_t ndisks) +{ + size_t i; + int ret =3D 0; + + /* Contrary to virHostdevPrepareNVMeDevices, this is a best + * effort approach. Just iterate over all disks and try to + * reattach them. Don't stop at the first failure. */ + for (i =3D 0; i < ndisks; i++) { + if (virHostdevReAttachOneNVMeDevice(hostdev_mgr, drv_name, + dom_name, disks[i]->src) < 0) { + VIR_ERROR(_("Failed to reattach NVMe for disk target: %s"), + disks[i]->dst); + ret =3D -1; + } + } + + return ret; +} + + +int +virHostdevUpdateActiveNVMeDevices(virHostdevManagerPtr hostdev_mgr, + const char *drv_name, + const char *dom_name, + virDomainDiskDefPtr *disks, + size_t ndisks) +{ + g_autoptr(virNVMeDeviceList) nvmeDevices =3D NULL; + g_autoptr(virPCIDeviceList) pciDevices =3D NULL; + virNVMeDevicePtr temp =3D NULL; + size_t i; + ssize_t lastGoodNVMeIdx =3D -1; + ssize_t lastGoodPCIIdx =3D -1; + int ret =3D -1; + + if (!(nvmeDevices =3D virNVMeDeviceListNew())) + return -1; + + for (i =3D 0; i < ndisks; i++) { + if (virHostdevGetNVMeDeviceList(nvmeDevices, disks[i]->src, drv_na= me, dom_name) < 0) + return -1; + } + + if (virNVMeDeviceListCount(nvmeDevices) =3D=3D 0) + return 0; + + virObjectLock(hostdev_mgr->activeNVMeHostdevs); + virObjectLock(hostdev_mgr->activePCIHostdevs); + virObjectLock(hostdev_mgr->inactivePCIHostdevs); + + if (!(pciDevices =3D virNVMeDeviceListCreateDetachList(hostdev_mgr->ac= tiveNVMeHostdevs, + nvmeDevices))) + goto cleanup; + + for (i =3D 0; i < virNVMeDeviceListCount(nvmeDevices); i++) { + temp =3D virNVMeDeviceListGet(nvmeDevices, i); + + if (virNVMeDeviceListAdd(hostdev_mgr->activeNVMeHostdevs, temp) < = 0) + goto rollback; + + lastGoodNVMeIdx =3D i; + } + + for (i =3D 0; i < virPCIDeviceListCount(pciDevices); i++) { + virPCIDevicePtr actual =3D virPCIDeviceListGet(pciDevices, i); + + /* We must restore some attributes that were lost on daemon restar= t. */ + virPCIDeviceSetUnbindFromStub(actual, true); + if (virPCIDeviceSetUsedBy(actual, drv_name, dom_name) < 0) + goto rollback; + + if (virPCIDeviceListAddCopy(hostdev_mgr->activePCIHostdevs, actual= ) < 0) + goto rollback; + + lastGoodPCIIdx =3D i; + } + + ret =3D 0; + cleanup: + virObjectUnlock(hostdev_mgr->inactivePCIHostdevs); + virObjectUnlock(hostdev_mgr->activePCIHostdevs); + virObjectUnlock(hostdev_mgr->activeNVMeHostdevs); + return ret; + + rollback: + while (lastGoodNVMeIdx >=3D 0) { + temp =3D virNVMeDeviceListGet(nvmeDevices, lastGoodNVMeIdx); + + virNVMeDeviceListDel(hostdev_mgr->activeNVMeHostdevs, temp); + + lastGoodNVMeIdx--; + } + while (lastGoodPCIIdx >=3D 0) { + virPCIDevicePtr actual =3D virPCIDeviceListGet(pciDevices, i); + + virPCIDeviceListDel(hostdev_mgr->activePCIHostdevs, actual); + + lastGoodPCIIdx--; + } + goto cleanup; +} diff --git a/src/util/virhostdev.h b/src/util/virhostdev.h index 2d61c21e9d..ae84ed3d20 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 G_DEFINE_AUTOPTR_CLEANUP_FUNC(virHostdevManager, virObjectUnref); @@ -207,3 +211,36 @@ int virHostdevPCINodeDeviceReAttach(virHostdevManagerP= tr mgr, int virHostdevPCINodeDeviceReset(virHostdevManagerPtr mgr, virPCIDevicePtr pci) ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2); + +int +virHostdevPrepareOneNVMeDevice(virHostdevManagerPtr hostdev_mgr, + const char *drv_name, + const char *dom_name, + virStorageSourcePtr src); + +int +virHostdevPrepareNVMeDevices(virHostdevManagerPtr hostdev_mgr, + const char *drv_name, + const char *dom_name, + virDomainDiskDefPtr *disks, + size_t ndisks); + +int +virHostdevReAttachOneNVMeDevice(virHostdevManagerPtr hostdev_mgr, + const char *drv_name, + const char *dom_name, + virStorageSourcePtr src); + +int +virHostdevReAttachNVMeDevices(virHostdevManagerPtr hostdev_mgr, + const char *drv_name, + const char *dom_name, + virDomainDiskDefPtr *disks, + size_t ndisks); + +int +virHostdevUpdateActiveNVMeDevices(virHostdevManagerPtr hostdev_mgr, + const char *drv_name, + const char *dom_name, + virDomainDiskDefPtr *disks, + size_t ndisks); diff --git a/src/util/virnvme.h b/src/util/virnvme.h index 911a9d29f3..db4d72ab9a 100644 --- a/src/util/virnvme.h +++ b/src/util/virnvme.h @@ -31,6 +31,8 @@ typedef virNVMeDevice *virNVMeDevicePtr; typedef struct _virNVMeDeviceList virNVMeDeviceList; typedef virNVMeDeviceList *virNVMeDeviceListPtr; =20 +G_DEFINE_AUTOPTR_CLEANUP_FUNC(virNVMeDeviceList, virObjectUnref); + virNVMeDevicePtr virNVMeDeviceNew(const virPCIDeviceAddress *address, unsigned long namespace, --=20 2.23.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Fri Apr 26 22:05:19 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 205.139.110.120 as permitted sender) client-ip=205.139.110.120; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-1.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 205.139.110.120 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=1575296953; cv=none; d=zohomail.com; s=zohoarc; b=UMehq2ospuAAvUAzFLWyyEB5cEhzfkVAvOVbz2zuaLt/dutujNS/8hckmO33EeP3cpSb+y4gQZHgO+fEHEGo3+ciZNwuKf1z7rYcSfAi1i5rs8M84icXeHST6AzbGj1S1vXdV8sSJCuqyI8vPdhpR+URhGs9MF0FH4ioFJiGi1A= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1575296953; 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; bh=StfThPYkNME/hDNPn/Si70i9zC5d3ziIOKMGhtnBATk=; b=AvyIum9npMqo89KxhzAbLnR6QzohbxGpCuWJqd9bIm9ayHi+XygQ9uMpvNrm5tO3aEIN/RxfxvjZq7BV58Isq8n356O/p4TJbcH656N3jnGWHrIb/9KAq01CRyjYbCm5+yApcdKPLbd++/0gqMmJFt3MvHXtbGlzsSgrTuDBvqg= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 205.139.110.120 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from us-smtp-1.mimecast.com (us-smtp-delivery-1.mimecast.com [205.139.110.120]) by mx.zohomail.com with SMTPS id 1575296953131252.68270558106292; Mon, 2 Dec 2019 06:29:13 -0800 (PST) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-251-hrP_R5DnMAa21TELiHrqcg-1; Mon, 02 Dec 2019 09:27:46 -0500 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 mimecast-mx01.redhat.com (Postfix) with ESMTPS id 90C98107ACFC; Mon, 2 Dec 2019 14:27:39 +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 61A8660C63; Mon, 2 Dec 2019 14:27:39 +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 16C091803C42; Mon, 2 Dec 2019 14:27:39 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id xB2ERDRN027405 for ; Mon, 2 Dec 2019 09:27:13 -0500 Received: by smtp.corp.redhat.com (Postfix) id E9D03A4B86; Mon, 2 Dec 2019 14:27:13 +0000 (UTC) Received: from moe.redhat.com (unknown [10.43.2.30]) by smtp.corp.redhat.com (Postfix) with ESMTP id 72D9B67648 for ; Mon, 2 Dec 2019 14:27:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1575296951; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=StfThPYkNME/hDNPn/Si70i9zC5d3ziIOKMGhtnBATk=; b=e5I5elPlPTdq5OrdfJS27wvQNjwI9XiJbytpwLEdyMdk3/QfaPgkVAfXIWvEHGlN+qZfOY Rf+wIvSmx/FQUiZKS9tblbTwcZDrBn1Qxsbuvrib9GtC8faba5YK2ielg0FFfst983Mppz RJNKxYLrWiG9elULulYi6t50ipDIwHM= From: Michal Privoznik To: libvir-list@redhat.com Date: Mon, 2 Dec 2019 15:26:39 +0100 Message-Id: <17da5e967c7c7290f3d1c54ffafeda2c6abb52f7.1575296392.git.mprivozn@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v3 16/30] 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: , 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-MC-Unique: hrP_R5DnMAa21TELiHrqcg-1 X-Mimecast-Spam-Score: 0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" The device configs (which are actually the same one config) come from a NVMe disk of mine. Signed-off-by: Michal Privoznik ACKed-by: Peter Krempa Reviewed-by: Cole Robinson --- 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 cd6ae1cff6..6048118d5c 100644 --- a/tests/virpcimock.c +++ b/tests/virpcimock.c @@ -980,6 +980,7 @@ init_env(void) MAKE_PCI_DRIVER("iwlwifi", 0x8086, 0x0044); MAKE_PCI_DRIVER("i915", 0x8086, 0x0046, 0x8086, 0x0047); MAKE_PCI_DRIVER("vfio-pci", -1, -1); + MAKE_PCI_DRIVER("nvme", 0x1cc1, 0x8201); =20 # define MAKE_PCI_DEVICE(Id, Vendor, Device, IommuGroup, ...) \ do { \ @@ -1015,6 +1016,8 @@ init_env(void) MAKE_PCI_DEVICE("0021:de:1f.1", 0x8086, 0x0047, 13, .physfn =3D "0021:de:1f.0"); /* Virtual Function */ =20 + MAKE_PCI_DEVICE("0000:01:00.0", 0x1cc1, 0x8201, 14, .klass =3D 0x01080= 2); + MAKE_PCI_DEVICE("0000:02:00.0", 0x1cc1, 0x8201, 15, .klass =3D 0x01080= 2); } =20 =20 diff --git a/tests/virpcitestdata/0000-01-00.0.config b/tests/virpcitestdat= a/0000-01-00.0.config new file mode 100644 index 0000000000000000000000000000000000000000..f92455e2ac5701ce60a51ae1982= 8658b80744399 GIT binary patch literal 4096 zcmeHIF;Buk6#lMP3WC_80!0h0vM?|ZHYb~)#L>jXKcF*Mr%9L>;{S2-*!p%x w=3Db5pKIZ+ec2|JnLT|5EZ*;+MDr9bc*RexLU6J#~1fK)&#@Fxm<1DBgMR{#J2 literal 0 HcmV?d00001 diff --git a/tests/virpcitestdata/0000-02-00.0.config b/tests/virpcitestdat= a/0000-02-00.0.config new file mode 100644 index 0000000000000000000000000000000000000000..ebb44d8f69c91809b82e8d26690= 26dfff42c3100 GIT binary patch literal 4096 zcmeHIJ5Iwu5Pj>-$HXLdfc(IT4QW!Oh|*DEDG*U2(QpB%)6hF9Xc0G{-~cHpZ9zfJ z322bGLCP>|J5DSjlp;bw+F5C5_RZVz>a9KYO*YD;3~)tdAWH!g;g^|DT!A}LQllO0 zfKOBAGo6v%Nj66qpz7dAnM2{>Nx zI9e@W7?nb%gO1$~!w=3Dvwj8>jg7)EtS6WUe7uo7>+ML1#rsDf3w!Hov7tz0X}jA<@| znO4!A1^^YZtw!BE*soP9<Vm(Pe#2&br`1}!)cEm@WPoIaHr{&J59pe0RNAZ%Qm+& w+Ruz#E{GcIPT1)j@8SvQ&et-M3anQFH~E3rsQUYQpCGGA1*8H}fj?2;8=3Dmzw{{R30 literal 0 HcmV?d00001 --=20 2.23.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Fri Apr 26 22:05:19 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 207.211.31.81 as permitted sender) client-ip=207.211.31.81; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-1.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 207.211.31.81 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=1575296874; cv=none; d=zohomail.com; s=zohoarc; b=ezZRL+A3kNC2xzUbIKHxbM5zhPlDk77kPZxtqlAWlo4NXj+alNIHEpOrvKZZTyQiaNE6oDY7P1xsinTGVfh+Zt94ISD1XJTT1BUAuS/iJpP8q65XBMD1OEdxv/wPpF4iRr/+Z+65Xb9e+kmb4lzme64tP354LNZKCuOASDErTbY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1575296874; 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; bh=0b9P38fsxNcnJ66caIFbicKI6B1mwy5CZMzoSIJ4kUk=; b=PDuPMMa9z2y/K+H3PhPQIT75zq88/55e/ZGOasRBlvYQmjJ9loGViZSqt0ny8jQnd+IROIn5h3Z2f4GPpVgqySwHcC3UGNlbiksjsSowWOuXv2leqz0v93BgXB0B6c4VzqfifYRwETAibjhJ436sGe7pwdifoFCWrOkmfdYnnO4= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 207.211.31.81 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from us-smtp-delivery-1.mimecast.com (us-smtp-2.mimecast.com [207.211.31.81]) by mx.zohomail.com with SMTPS id 1575296874855776.3329993681098; Mon, 2 Dec 2019 06:27:54 -0800 (PST) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-241-nHllxZZHPtGkNgItaLwW3A-1; Mon, 02 Dec 2019 09:27:52 -0500 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 mimecast-mx01.redhat.com (Postfix) with ESMTPS id C65DE8024FB; Mon, 2 Dec 2019 14:27:43 +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 923D760BFB; Mon, 2 Dec 2019 14:27: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 486F45BC06; Mon, 2 Dec 2019 14:27:43 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id xB2ERHZs027434 for ; Mon, 2 Dec 2019 09:27:17 -0500 Received: by smtp.corp.redhat.com (Postfix) id 169A1A4B86; Mon, 2 Dec 2019 14:27:17 +0000 (UTC) Received: from moe.redhat.com (unknown [10.43.2.30]) by smtp.corp.redhat.com (Postfix) with ESMTP id 9420A6764D for ; Mon, 2 Dec 2019 14:27:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1575296873; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=0b9P38fsxNcnJ66caIFbicKI6B1mwy5CZMzoSIJ4kUk=; b=JQiAxckWqNEj39/RliU2+XvBKWWTTZkb7I3r+KeAJU/5qNMUZgO5ZfVTyxqEcGnikstGQm xA83087sufdh5UYTHKKcJEnBXsyHWYFkO6oKfcsu/WKl/co/C5/ulxBrnJNCa/Ch/lXZ6i suV/2dqm1lk5EpKY+c4utSU1YJn/yV8= From: Michal Privoznik To: libvir-list@redhat.com Date: Mon, 2 Dec 2019 15:26:40 +0100 Message-Id: <7215404d5f1d3070f623decaa6573e1f26b3bac9.1575296392.git.mprivozn@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v3 17/30] 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: , 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-MC-Unique: nHllxZZHPtGkNgItaLwW3A-1 X-Mimecast-Spam-Score: 0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" Signed-off-by: Michal Privoznik ACKed-by: Peter Krempa Reviewed-by: Cole Robinson --- tests/virhostdevtest.c | 97 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 97 insertions(+) diff --git a/tests/virhostdevtest.c b/tests/virhostdevtest.c index ed8e7e8fc1..39216edc67 100644 --- a/tests/virhostdevtest.c +++ b/tests/virhostdevtest.c @@ -48,6 +48,9 @@ VIR_LOG_INIT("tests.hostdevtest"); # define CHECK_PCI_LIST_COUNT(list, cnt) \ CHECK_LIST_COUNT(list, cnt, virPCIDeviceListCount) =20 +# define CHECK_NVME_LIST_COUNT(list, cnt) \ + CHECK_LIST_COUNT(list, cnt, virNVMeDeviceListCount) + # define TEST_STATE_DIR abs_builddir "/hostdevmgr" static const char *drv_name =3D "test_driver"; static const char *dom_name =3D "test_domain"; @@ -57,6 +60,36 @@ static int nhostdevs =3D 3; static virDomainHostdevDefPtr hostdevs[] =3D {NULL, NULL, NULL}; static virPCIDevicePtr dev[] =3D {NULL, NULL, NULL}; static virHostdevManagerPtr mgr; +static const size_t ndisks =3D 3; +static virDomainDiskDefPtr disks[] =3D {NULL, NULL, NULL}; +static const char *diskXML[] =3D { + "" + " " + " " + "
" + " " + " " + "
" + "", + + "" + " " + " " + "
" + " " + " " + "
" + "", + + "" + " " + " " + "
" + " " + " " + "
" + "" +}; =20 static void myCleanup(void) @@ -67,6 +100,9 @@ myCleanup(void) virDomainHostdevDefFree(hostdevs[i]); } =20 + for (i =3D 0; i < ndisks; i++) + virDomainDiskDefFree(disks[i]); + if (mgr) { if (!getenv("LIBVIRT_SKIP_CLEANUP")) virFileDeleteTree(mgr->stateDir); @@ -75,6 +111,7 @@ myCleanup(void) virObjectUnref(mgr->activeUSBHostdevs); virObjectUnref(mgr->inactivePCIHostdevs); virObjectUnref(mgr->activeSCSIHostdevs); + virObjectUnref(mgr->activeNVMeHostdevs); VIR_FREE(mgr->stateDir); VIR_FREE(mgr); } @@ -107,6 +144,11 @@ myInit(void) virPCIDeviceSetStubDriver(dev[i], VIR_PCI_STUB_DRIVER_VFIO); } =20 + for (i =3D 0; i < ndisks; i++) { + if (!(disks[i] =3D virDomainDiskDefParse(diskXML[i], NULL, NULL, 0= ))) + goto cleanup; + } + if (VIR_ALLOC(mgr) < 0) goto cleanup; if ((mgr->activePCIHostdevs =3D virPCIDeviceListNew()) =3D=3D NULL) @@ -117,6 +159,8 @@ myInit(void) goto cleanup; if ((mgr->activeSCSIHostdevs =3D virSCSIDeviceListNew()) =3D=3D NULL) goto cleanup; + if ((mgr->activeNVMeHostdevs =3D virNVMeDeviceListNew()) =3D=3D NULL) + goto cleanup; mgr->stateDir =3D g_strdup(TEST_STATE_DIR); if (virFileMakePath(mgr->stateDir) < 0) goto cleanup; @@ -492,6 +536,58 @@ testVirHostdevOther(const void *opaque G_GNUC_UNUSED) return 0; } =20 +static int +testNVMeDiskRoundtrip(const void *opaque G_GNUC_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 @@ -526,6 +622,7 @@ mymain(void) DO_TEST(testVirHostdevRoundtripManaged); DO_TEST(testVirHostdevRoundtripMixed); DO_TEST(testVirHostdevOther); + DO_TEST(testNVMeDiskRoundtrip); =20 myCleanup(); =20 --=20 2.23.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Fri Apr 26 22:05:19 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 205.139.110.120 as permitted sender) client-ip=205.139.110.120; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-1.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 205.139.110.120 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=1575296872; cv=none; d=zohomail.com; s=zohoarc; b=iVfK9kzN66ALIs5zo7ZEyFbZErcCJeFt4UrzTE1WBHw96spQWMMIk2he8pEAzfmP+5cvcgiPGXnIXGWVWB7d3XEwmB7x31pFRIYMl8jdI8g5kchNTSjromRkKXXVDl/9LyIt6WfQVZK0jjn6f2QcSmtzCSzpLsjEyt05yqa4Jh0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1575296872; 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; bh=az4bcvtAJcIow+48DxoD8P7zjCudvgQlgooqdBhB4pA=; b=NTWV4TxeHaJighm2HSGQNBH1ByPt+iuY5GGtJnG1u0RPynfTerZ6vcUUJvgS5yH2XZqnTvZ1in4PU4Pjvl0TxwRLDhNVpPajKvjgyW4o44fjYO1+3YGAdK0RHW1cD5+uP1gymIpR7/nvimyxj8ncUWKlbFltAFRFjJilPUcKtB8= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 205.139.110.120 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from us-smtp-1.mimecast.com (us-smtp-delivery-1.mimecast.com [205.139.110.120]) by mx.zohomail.com with SMTPS id 1575296872730409.9878158971786; Mon, 2 Dec 2019 06:27:52 -0800 (PST) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-120-YkEZK4xJO5K4a-IdLqzzsA-1; Mon, 02 Dec 2019 09:27:48 -0500 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 mimecast-mx01.redhat.com (Postfix) with ESMTPS id 44A2C107ACE3; Mon, 2 Dec 2019 14:27:43 +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 2051967675; Mon, 2 Dec 2019 14:27: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 CC6BF5BC00; Mon, 2 Dec 2019 14:27:42 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id xB2ERHN7027439 for ; Mon, 2 Dec 2019 09:27:17 -0500 Received: by smtp.corp.redhat.com (Postfix) id DA4EA6764D; Mon, 2 Dec 2019 14:27:17 +0000 (UTC) Received: from moe.redhat.com (unknown [10.43.2.30]) by smtp.corp.redhat.com (Postfix) with ESMTP id 63499A4B86 for ; Mon, 2 Dec 2019 14:27:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1575296871; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=az4bcvtAJcIow+48DxoD8P7zjCudvgQlgooqdBhB4pA=; b=USzdd09uH3KogN1MdtFGthRJHuCPyBJY3+Ls/mbbKCdfFpp3lMkyyd0F26IYsnKGoQEY0O mpBXZCbfeYBqHiBBsSr2CKuHx7B9D94VDKeN7fMmSczGhAj7rl+UJReV37L8S84GoIKW8y FCsPc/M33ekVCR2MKvui4ITt6n69OWM= From: Michal Privoznik To: libvir-list@redhat.com Date: Mon, 2 Dec 2019 15:26:41 +0100 Message-Id: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v3 18/30] 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: , 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-MC-Unique: YkEZK4xJO5K4a-IdLqzzsA-1 X-Mimecast-Spam-Score: 0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" The qemu driver has its own wrappers around virHostdev module (so that some arguments are filled in automatically). Extend these to include NVMe devices too. Signed-off-by: Michal Privoznik ACKed-by: Peter Krempa Reviewed-by: Cole Robinson --- src/qemu/qemu_hostdev.c | 49 ++++++++++++++++++++++++++++++++++++++--- src/qemu/qemu_hostdev.h | 10 +++++++++ 2 files changed, 56 insertions(+), 3 deletions(-) diff --git a/src/qemu/qemu_hostdev.c b/src/qemu/qemu_hostdev.c index ebbca817b8..5ab0217858 100644 --- a/src/qemu/qemu_hostdev.c +++ b/src/qemu/qemu_hostdev.c @@ -96,13 +96,28 @@ qemuHostdevUpdateActiveMediatedDevices(virQEMUDriverPtr= driver, } =20 =20 +int +qemuHostdevUpdateActiveNVMeDisks(virQEMUDriverPtr driver, + virDomainDefPtr def) +{ + return virHostdevUpdateActiveNVMeDevices(driver->hostdevMgr, + QEMU_DRIVER_NAME, + def->name, + def->disks, + def->ndisks); +} + + int qemuHostdevUpdateActiveDomainDevices(virQEMUDriverPtr driver, virDomainDefPtr def) { - if (!def->nhostdevs) + if (!def->nhostdevs && !def->ndisks) return 0; =20 + if (qemuHostdevUpdateActiveNVMeDisks(driver, def) < 0) + return -1; + if (qemuHostdevUpdateActivePCIDevices(driver, def) < 0) return -1; =20 @@ -197,6 +212,17 @@ qemuHostdevPreparePCIDevicesCheckSupport(virDomainHost= devDefPtr *hostdevs, return true; } =20 +int +qemuHostdevPrepareNVMeDisks(virQEMUDriverPtr driver, + const char *name, + virDomainDiskDefPtr *disks, + size_t ndisks) +{ + return virHostdevPrepareNVMeDevices(driver->hostdevMgr, + QEMU_DRIVER_NAME, + name, disks, ndisks); +} + int qemuHostdevPreparePCIDevices(virQEMUDriverPtr driver, const char *name, @@ -313,9 +339,12 @@ qemuHostdevPrepareDomainDevices(virQEMUDriverPtr drive= r, virQEMUCapsPtr qemuCaps, unsigned int flags) { - if (!def->nhostdevs) + if (!def->nhostdevs && !def->ndisks) return 0; =20 + if (qemuHostdevPrepareNVMeDisks(driver, def->name, def->disks, def->nd= isks) < 0) + return -1; + if (qemuHostdevPreparePCIDevices(driver, def->name, def->uuid, def->hostdevs, def->nhostdevs, qemuCaps, flags) < 0) @@ -340,6 +369,17 @@ qemuHostdevPrepareDomainDevices(virQEMUDriverPtr drive= r, return 0; } =20 +void +qemuHostdevReAttachNVMeDisks(virQEMUDriverPtr driver, + const char *name, + virDomainDiskDefPtr *disks, + size_t ndisks) +{ + virHostdevReAttachNVMeDevices(driver->hostdevMgr, + QEMU_DRIVER_NAME, + name, disks, ndisks); +} + void qemuHostdevReAttachPCIDevices(virQEMUDriverPtr driver, const char *name, @@ -419,9 +459,12 @@ void qemuHostdevReAttachDomainDevices(virQEMUDriverPtr driver, virDomainDefPtr def) { - if (!def->nhostdevs) + if (!def->nhostdevs && !def->ndisks) return; =20 + qemuHostdevReAttachNVMeDisks(driver, def->name, def->disks, + def->ndisks); + qemuHostdevReAttachPCIDevices(driver, def->name, def->hostdevs, def->nhostdevs); =20 diff --git a/src/qemu/qemu_hostdev.h b/src/qemu/qemu_hostdev.h index 536069fe8a..735414b6aa 100644 --- a/src/qemu/qemu_hostdev.h +++ b/src/qemu/qemu_hostdev.h @@ -28,6 +28,8 @@ bool qemuHostdevNeedsVFIO(const virDomainHostdevDef *host= dev); =20 bool qemuHostdevHostSupportsPassthroughVFIO(void); =20 +int qemuHostdevUpdateActiveNVMeDisks(virQEMUDriverPtr driver, + virDomainDefPtr def); int qemuHostdevUpdateActiveMediatedDevices(virQEMUDriverPtr driver, virDomainDefPtr def); int qemuHostdevUpdateActivePCIDevices(virQEMUDriverPtr driver, @@ -39,6 +41,10 @@ int qemuHostdevUpdateActiveSCSIDevices(virQEMUDriverPtr = driver, int qemuHostdevUpdateActiveDomainDevices(virQEMUDriverPtr driver, virDomainDefPtr def); =20 +int qemuHostdevPrepareNVMeDisks(virQEMUDriverPtr driver, + const char *name, + virDomainDiskDefPtr *disks, + size_t ndisks); int qemuHostdevPreparePCIDevices(virQEMUDriverPtr driver, const char *name, const unsigned char *uuid, @@ -68,6 +74,10 @@ int qemuHostdevPrepareDomainDevices(virQEMUDriverPtr dri= ver, virQEMUCapsPtr qemuCaps, unsigned int flags); =20 +void qemuHostdevReAttachNVMeDisks(virQEMUDriverPtr driver, + const char *name, + virDomainDiskDefPtr *disks, + size_t ndisks); void qemuHostdevReAttachPCIDevices(virQEMUDriverPtr driver, const char *name, virDomainHostdevDefPtr *hostdevs, --=20 2.23.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Fri Apr 26 22:05:19 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 205.139.110.120 as permitted sender) client-ip=205.139.110.120; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-1.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 205.139.110.120 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=1575296964; cv=none; d=zohomail.com; s=zohoarc; b=Ub31lr+SQsnIOq9F9xTuhenRqRL494TjHICd1gX2i0oY/tYed517nnPZ5HUnOHlfis5KiT15gehMGjP0azHT5Ku5vVtzyb/CVBnU80WAHS3hxxM10w+Tc7Z91J3R2aiWcSbc46OKaPH0IceBOeW7n3EJxR19/sqKUuecEGV+Chc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1575296964; 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; bh=hotPif3UoLIkLJdcmED4BVNVjqn2LI9nHU4jKvleAgg=; b=jvL9ixo7OEeeQJdFgsa7ez8gLdmTziDkoV86jveJs4RKa1QGwvX28bIQQBV/Lkwy8Re/V9tKdsQbEPcZWWgbC2MRhbguYYYCdNgSxTCAY9mvJ1/H4R/P5L6Q9xtPFNSMCcIDaGLjVmbHmGOikWA7DrmBHIzyqy56eGk0zgc6A2I= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 205.139.110.120 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from us-smtp-1.mimecast.com (us-smtp-delivery-1.mimecast.com [205.139.110.120]) by mx.zohomail.com with SMTPS id 157529696418785.48965023785672; Mon, 2 Dec 2019 06:29:24 -0800 (PST) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-352-mZPVkTGPNgOyf-QkdqpOFQ-1; Mon, 02 Dec 2019 09:27:54 -0500 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 mimecast-mx01.redhat.com (Postfix) with ESMTPS id 08249804913; Mon, 2 Dec 2019 14:27:48 +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 D32BC19C68; Mon, 2 Dec 2019 14:27: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 8201018034EE; Mon, 2 Dec 2019 14:27:47 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id xB2ERIxd027449 for ; Mon, 2 Dec 2019 09:27:18 -0500 Received: by smtp.corp.redhat.com (Postfix) id A9EC16764D; Mon, 2 Dec 2019 14:27:18 +0000 (UTC) Received: from moe.redhat.com (unknown [10.43.2.30]) by smtp.corp.redhat.com (Postfix) with ESMTP id 331E7A4B86 for ; Mon, 2 Dec 2019 14:27:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1575296963; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=hotPif3UoLIkLJdcmED4BVNVjqn2LI9nHU4jKvleAgg=; b=WFFMd6BR20D1nZORjD5Y/0QlLZq0eq1P1JBq89trJXmjfqD+gNKXEFsLXIMZhkQwPkj9jt KZc4ZUXUi4RgZYiMG/VxQsOTbqpYm0wkflqUzFJn0aiCQvBa1hAdbyr+jtOn7ODeJD71/R ihgVc7ITx8DsW1DmlnwSLK5ssXNG4+k= From: Michal Privoznik To: libvir-list@redhat.com Date: Mon, 2 Dec 2019 15:26:42 +0100 Message-Id: <70725001ae8b8c80efaa4ea476801f77c4055bfc.1575296392.git.mprivozn@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v3 19/30] 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: , 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-MC-Unique: mZPVkTGPNgOyf-QkdqpOFQ-1 X-Mimecast-Spam-Score: 0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" We have this beautiful function that does crystal ball divination. The function is named qemuDomainGetMemLockLimitBytes() and it calculates the upper limit of how much locked memory is given guest going to need. The function bases its guess on devices defined for a domain. For instance, if there is a VFIO hostdev defined then it adds 1GiB to the guessed maximum. Since NVMe disks are pretty much VFIO hostdevs (but not quite), we have to do the same sorcery. Signed-off-by: Michal Privoznik ACKed-by: Peter Krempa Reviewed-by: Cole Robinson --- src/qemu/qemu_domain.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c index 59e98de2d2..7b515b9520 100644 --- a/src/qemu/qemu_domain.c +++ b/src/qemu/qemu_domain.c @@ -11920,6 +11920,9 @@ getPPC64MemLockLimitBytes(virDomainDefPtr def) } } =20 + if (virDomainDefHasNVMeDisk(def)) + usesVFIO =3D true; + memory =3D virDomainDefGetMemoryTotal(def); =20 if (def->mem.max_memory) @@ -12018,6 +12021,7 @@ unsigned long long qemuDomainGetMemLockLimitBytes(virDomainDefPtr def) { unsigned long long memKB =3D 0; + bool usesVFIO =3D false; size_t i; =20 /* prefer the hard limit */ @@ -12058,11 +12062,17 @@ qemuDomainGetMemLockLimitBytes(virDomainDefPtr de= f) for (i =3D 0; i < def->nhostdevs; i++) { if (virHostdevIsVFIODevice(def->hostdevs[i]) || virHostdevIsMdevDevice(def->hostdevs[i])) { - memKB =3D virDomainDefGetMemoryTotal(def) + 1024 * 1024; - goto done; + usesVFIO =3D true; + break; } } =20 + if (virDomainDefHasNVMeDisk(def)) + usesVFIO =3D true; + + if (usesVFIO) + memKB =3D virDomainDefGetMemoryTotal(def) + 1024 * 1024; + done: return memKB << 10; } --=20 2.23.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Fri Apr 26 22:05:19 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 205.139.110.61 as permitted sender) client-ip=205.139.110.61; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-1.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 205.139.110.61 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=1575296949; cv=none; d=zohomail.com; s=zohoarc; b=l9Fm8yx/DMXVynbcP7SvWbFyB8pA9WZqhqo5+G1Ki0PlOjI1QZhSr2ph10OBXjqi8Ek9O/nmDPGDA0JfYi+FZS+1wvbOHd3xZ74jEzTCWkfEQIutJCLn7wuH0euphyV6uXNGD+NCTr57l+t0ygxBki+fFxRVmQyUjgwM7ydsGe8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1575296949; 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; bh=fSnS/DYdExV8B7hEh91lOaXMOcu+O/QFhmwyklMU970=; b=fw7CWR2aN1zp3659zznw9v8vbFXZjaxCN/K7EaE+zvXZDvDYG+DgEoZqmRY0zHuTu7HYkcta7r3zGCbilo7nLO80diH7briD/TpgbiIKAxJH68wiKd4XdAbPxcGPNiH/rw7HSm2aL7fD1IJfMnfnLcoOnAAiwbRyOeLeVQ2qQIA= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 205.139.110.61 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from us-smtp-delivery-1.mimecast.com (us-smtp-2.mimecast.com [205.139.110.61]) by mx.zohomail.com with SMTPS id 1575296949071664.3879124310473; Mon, 2 Dec 2019 06:29:09 -0800 (PST) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-131-FwdcNsOLNG-XG_XpjuHiRw-1; Mon, 02 Dec 2019 09:27:56 -0500 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 mimecast-mx01.redhat.com (Postfix) with ESMTPS id 2535A107ACFC; Mon, 2 Dec 2019 14:27: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 E8A3219C68; Mon, 2 Dec 2019 14:27: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 A7DB218034EC; Mon, 2 Dec 2019 14:27:46 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id xB2ERJPJ027462 for ; Mon, 2 Dec 2019 09:27:19 -0500 Received: by smtp.corp.redhat.com (Postfix) id 79FD5A4B86; Mon, 2 Dec 2019 14:27:19 +0000 (UTC) Received: from moe.redhat.com (unknown [10.43.2.30]) by smtp.corp.redhat.com (Postfix) with ESMTP id 03C4F6764D for ; Mon, 2 Dec 2019 14:27:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1575296947; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=fSnS/DYdExV8B7hEh91lOaXMOcu+O/QFhmwyklMU970=; b=UJAGoXZWVn7dPcRBEGU/OO1Pb52bAXzQFIQ0ejT4/vdg7LpluJ4KRDHukd5cyw3+YkRyk1 6kZWEF/PYexf3xVQpD0OkTe5mhPzqjD/g5NwixOaaxmboN2YPA+nWIqt7uvX8l/bDgodfh S63dHdVrGDxWLg225mt31RysHUL/rSo= From: Michal Privoznik To: libvir-list@redhat.com Date: Mon, 2 Dec 2019 15:26:43 +0100 Message-Id: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v3 20/30] 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: , 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-MC-Unique: FwdcNsOLNG-XG_XpjuHiRw-1 X-Mimecast-Spam-Score: 0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) 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 Reviewed-by: Cole Robinson --- src/qemu/qemu_domain.c | 67 ++++++++++++++++++++++++++++++++---------- 1 file changed, 51 insertions(+), 16 deletions(-) diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c index 7b515b9520..70c4ee8e65 100644 --- a/src/qemu/qemu_domain.c +++ b/src/qemu/qemu_domain.c @@ -13430,16 +13430,29 @@ qemuDomainSetupDisk(virQEMUDriverConfigPtr cfg G_= GNUC_UNUSED, { virStorageSourcePtr next; char *dst =3D NULL; + bool hasNVMe =3D false; int ret =3D -1; =20 for (next =3D disk->src; virStorageSourceIsBacking(next); next =3D nex= t->backingStore) { - if (!next->path || !virStorageSourceIsLocalStorage(next)) { - /* Not creating device. Just continue. */ - continue; - } + if (next->type =3D=3D VIR_STORAGE_TYPE_NVME) { + g_autofree char *nvmePath =3D NULL; =20 - if (qemuDomainCreateDevice(next->path, data, false) < 0) - goto cleanup; + hasNVMe =3D true; + + if (!(nvmePath =3D virPCIDeviceAddressGetIOMMUGroupDev(&next->= nvme->pciAddr))) + goto cleanup; + + if (qemuDomainCreateDevice(nvmePath, data, false) < 0) + goto cleanup; + } else { + if (!next->path || !virStorageSourceIsLocalStorage(next)) { + /* Not creating device. Just continue. */ + continue; + } + + if (qemuDomainCreateDevice(next->path, data, false) < 0) + goto cleanup; + } } =20 /* qemu-pr-helper might require access to /dev/mapper/control. */ @@ -13447,6 +13460,10 @@ qemuDomainSetupDisk(virQEMUDriverConfigPtr cfg G_G= NUC_UNUSED, qemuDomainCreateDevice(QEMU_DEVICE_MAPPER_CONTROL_PATH, data, true= ) < 0) goto cleanup; =20 + if (hasNVMe && + qemuDomainCreateDevice(QEMU_DEV_VFIO, data, false) < 0) + goto cleanup; + ret =3D 0; cleanup: VIR_FREE(dst); @@ -14461,19 +14478,32 @@ qemuDomainNamespaceSetupDisk(virDomainObjPtr vm, virStorageSourcePtr src) { virStorageSourcePtr next; - const char **paths =3D NULL; + char **paths =3D NULL; size_t npaths =3D 0; - char *dmPath =3D NULL; + bool hasNVMe =3D false; + g_autofree char *dmPath =3D NULL; + g_autofree char *vfioPath =3D NULL; int ret =3D -1; =20 for (next =3D src; virStorageSourceIsBacking(next); next =3D next->bac= kingStore) { - if (virStorageSourceIsEmpty(next) || - !virStorageSourceIsLocalStorage(next)) { - /* Not creating device. Just continue. */ - continue; + g_autofree char *tmpPath =3D NULL; + + if (next->type =3D=3D VIR_STORAGE_TYPE_NVME) { + hasNVMe =3D true; + + if (!(tmpPath =3D virPCIDeviceAddressGetIOMMUGroupDev(&next->n= vme->pciAddr))) + goto cleanup; + } else { + if (virStorageSourceIsEmpty(next) || + !virStorageSourceIsLocalStorage(next)) { + /* Not creating device. Just continue. */ + continue; + } + + tmpPath =3D g_strdup(next->path); } =20 - if (VIR_APPEND_ELEMENT_COPY(paths, npaths, next->path) < 0) + if (VIR_APPEND_ELEMENT(paths, npaths, tmpPath) < 0) goto cleanup; } =20 @@ -14484,13 +14514,18 @@ qemuDomainNamespaceSetupDisk(virDomainObjPtr vm, goto cleanup; } =20 - if (qemuDomainNamespaceMknodPaths(vm, paths, npaths) < 0) + if (hasNVMe) { + vfioPath =3D g_strdup(QEMU_DEV_VFIO); + if (VIR_APPEND_ELEMENT(paths, npaths, vfioPath) < 0) + goto cleanup; + } + + if (qemuDomainNamespaceMknodPaths(vm, (const char **) paths, npaths) <= 0) goto cleanup; =20 ret =3D 0; cleanup: - VIR_FREE(dmPath); - VIR_FREE(paths); + virStringListFreeCount(paths, npaths); return ret; } =20 --=20 2.23.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Fri Apr 26 22:05:19 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 207.211.31.120 as permitted sender) client-ip=207.211.31.120; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-1.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 207.211.31.120 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=1575296934; cv=none; d=zohomail.com; s=zohoarc; b=LlGER0J58bJuNfy6W+k9mcTo8Mn7bdByp1WuNUJxLFYD8EW0xCc8qf13iEisx8/SqH7GQoDmXpCmrUk7BKKNvrpDOeskeQkH03ECLAfvo7ndFerRKc6yR2k36ZVMzlMTeloG+8gosn94V0PgpR7cef+VxcW/2pdUUz/VPqqFUIg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1575296934; 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; bh=EvP02gvqxudAWQOq9FI8VJ/eEKKq1dZYfeFjxZPvTqQ=; b=l1gI9rCHKk9m24Wzx0bUZTy4duU2pdKWUwyO5txpHT44aqA3LKM1JQZNKObP6ht0eBG8QFTZUlzwLoe45n3rwmNx5JFJGUji5iDByTIPALoUxgvYp72L9aJYRZrEKO9OofdI1SACimn35aL+6U9OgbuocBn6LvdJqupxP/qOTjo= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 207.211.31.120 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from us-smtp-1.mimecast.com (us-smtp-delivery-1.mimecast.com [207.211.31.120]) by mx.zohomail.com with SMTPS id 1575296934009921.9121427059118; Mon, 2 Dec 2019 06:28:54 -0800 (PST) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-237-6zDE7gQsNketuvRCPgm2bA-1; Mon, 02 Dec 2019 09:27:58 -0500 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 mimecast-mx01.redhat.com (Postfix) with ESMTPS id C7041100A159; Mon, 2 Dec 2019 14:27:51 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id A098D600C9; Mon, 2 Dec 2019 14:27: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 4549B5BC0B; Mon, 2 Dec 2019 14:27:51 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id xB2ERKv8027467 for ; Mon, 2 Dec 2019 09:27:20 -0500 Received: by smtp.corp.redhat.com (Postfix) id 49C8B6764D; Mon, 2 Dec 2019 14:27:20 +0000 (UTC) Received: from moe.redhat.com (unknown [10.43.2.30]) by smtp.corp.redhat.com (Postfix) with ESMTP id C6FFBA4B86 for ; Mon, 2 Dec 2019 14:27:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1575296932; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=EvP02gvqxudAWQOq9FI8VJ/eEKKq1dZYfeFjxZPvTqQ=; b=VaiFY8gUqMaXKiVljppXirR5YFwVKXrNTQ0ofCpVhKHV9XtDfy0lACTcbd52Kgqbum3ntu JY49x03Z5VRTm83v+u4GIIQwscTcyigF6zlShiMUYQKetceCwXzZcWTWRAW9N+lNrtbJgh KVKVL97ctL64h73uqg59oEdE20WXUY8= From: Michal Privoznik To: libvir-list@redhat.com Date: Mon, 2 Dec 2019 15:26:44 +0100 Message-Id: <7c7a49ccc881e99bd3d3e1376d02fe1809bd5264.1575296392.git.mprivozn@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v3 21/30] qemu: Mark NVMe disks as 'need VFIO' X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , 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-MC-Unique: 6zDE7gQsNketuvRCPgm2bA-1 X-Mimecast-Spam-Score: 0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" There are couple of places where a domain with a VFIO device gets special treatment: in CGroups when enabling/disabling access to /dev/vfio/vfio, and when creating/removing nodes in domain mount namespace. Well, a NVMe disk is a VFIO device too. Fortunately, we have this qemuDomainNeedsVFIO() function which is the only place that needs adjustment. Signed-off-by: Michal Privoznik Reviewed-by: Cole Robinson --- src/qemu/qemu_domain.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c index 70c4ee8e65..e81d986e9e 100644 --- a/src/qemu/qemu_domain.c +++ b/src/qemu/qemu_domain.c @@ -12865,7 +12865,8 @@ bool qemuDomainNeedsVFIO(const virDomainDef *def) { return virDomainDefHasVFIOHostdev(def) || - virDomainDefHasMdevHostdev(def); + virDomainDefHasMdevHostdev(def) || + virDomainDefHasNVMeDisk(def); } =20 =20 --=20 2.23.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Fri Apr 26 22:05:19 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 207.211.31.120 as permitted sender) client-ip=207.211.31.120; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-1.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 207.211.31.120 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=1575296885; cv=none; d=zohomail.com; s=zohoarc; b=JccX6LbBnGSXORFxEFg/2hTedTVaKTDH/OSywDh6T9qZlw7pn5xFgE3i6s/HRDhABCyKMb3xDqz0+t/UgOXme6F/pbN1cRqSnIV6Oqz8Vq5AwN8wq7kZ5qu6Ozpi/rNHr5Ujzesbc2BGHhREol1NmCFagwXP4b2OnJ/rEFXStzE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1575296885; 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; bh=nc3wEBmYz6xbH/ZMFof5vjK0/GARvtXPkHcBn8KBZzw=; b=MVbWSRNmj9/wBDfnCOOUCk1KP4zYFFUJsRGSz9MwmAN4nw1CJxjJUjhLlDoEF8XRl1nK3FSEDFuQtqyKBqu6yIhi+asiUp2OETt7krxKO8TumUf+OJZqmYGi7nnaFNlSdEQkyWFHPG66uFv7B7RRLwcW24v499cYFJJoVjF6Wnc= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 207.211.31.120 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from us-smtp-1.mimecast.com (us-smtp-delivery-1.mimecast.com [207.211.31.120]) by mx.zohomail.com with SMTPS id 1575296885928937.6344856969982; Mon, 2 Dec 2019 06:28:05 -0800 (PST) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-365-3ryXPZbnOomuZasDUhoz1w-1; Mon, 02 Dec 2019 09:27:58 -0500 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 mimecast-mx01.redhat.com (Postfix) with ESMTPS id 364EE80B736; Mon, 2 Dec 2019 14:27:52 +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 095A319C6A; Mon, 2 Dec 2019 14:27:52 +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 B52145BC0D; Mon, 2 Dec 2019 14:27:51 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id xB2ERLFl027485 for ; Mon, 2 Dec 2019 09:27:21 -0500 Received: by smtp.corp.redhat.com (Postfix) id 1A4B06764D; Mon, 2 Dec 2019 14:27:21 +0000 (UTC) Received: from moe.redhat.com (unknown [10.43.2.30]) by smtp.corp.redhat.com (Postfix) with ESMTP id 96C9467E56 for ; Mon, 2 Dec 2019 14:27:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1575296883; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=nc3wEBmYz6xbH/ZMFof5vjK0/GARvtXPkHcBn8KBZzw=; b=I46Qcq2nyFqA+hXG0hx3OialuJTfVKhhJ98l46+TvDZH5526BrpRFxrrHraXB5JLdoo6Q2 Vlj/iFTJYzXNh5Zus/o0MgxHfu27aADvJNAfsjXcKpTSjdAakRw5nOHFcwihFXozvWDdai rYmF657CQLSpP1WZjSzrAJIJW99dzdE= From: Michal Privoznik To: libvir-list@redhat.com Date: Mon, 2 Dec 2019 15:26:45 +0100 Message-Id: <46b9fe9333b3ca0d8aaf0e5abec1095b7433416d.1575296392.git.mprivozn@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v3 22/30] 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: , 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-MC-Unique: 3ryXPZbnOomuZasDUhoz1w-1 X-Mimecast-Spam-Score: 0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) 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 Reviewed-by: Cole Robinson --- src/qemu/qemu_cgroup.c | 97 ++++++++++++++++++++++++++++++------------ 1 file changed, 69 insertions(+), 28 deletions(-) diff --git a/src/qemu/qemu_cgroup.c b/src/qemu/qemu_cgroup.c index d23318db8c..1d3994ecc9 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; + g_autofree char *path =3D NULL; + bool readonly =3D src->readonly || forceReadonly; + + if (src->type =3D=3D VIR_STORAGE_TYPE_NVME) { + /* Even though disk is R/O we can't make it so in + * CGroups. QEMU will try to do some ioctl()-s over the + * device and such operations are considered R/W by the + * kernel */ + readonly =3D false; + + if (!(path =3D virPCIDeviceAddressGetIOMMUGroupDev(&src->nvme->pci= Addr))) + return -1; + + if (qemuSetupImagePathCgroup(vm, QEMU_DEV_VFIO, false) < 0) + return -1; + } else { + if (!src->path || !virStorageSourceIsLocalStorage(src)) { + VIR_DEBUG("Not updating cgroups for disk path '%s', type: %s", + NULLSTR(src->path), virStorageTypeToString(src->type= )); + return 0; + } + + path =3D g_strdup(src->path); } =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,7 +165,10 @@ qemuTeardownImageCgroup(virDomainObjPtr vm, virStorageSourcePtr src) { qemuDomainObjPrivatePtr priv =3D vm->privateData; + g_autofree char *path =3D NULL; int perms =3D VIR_CGROUP_DEVICE_RWM; + bool hasPR =3D false; + bool hasNVMe =3D false; size_t i; int ret; =20 @@ -154,41 +176,60 @@ qemuTeardownImageCgroup(virDomainObjPtr vm, VIR_CGROUP_CONTROLLER_DEVICES)) return 0; =20 - if (!src->path || !virStorageSourceIsLocalStorage(src)) { - VIR_DEBUG("Not updating cgroups for disk path '%s', type: %s", - NULLSTR(src->path), virStorageTypeToString(src->type)); - return 0; - } + for (i =3D 0; i < vm->def->ndisks; i++) { + virStorageSourcePtr diskSrc =3D vm->def->disks[i]->src; =20 - if (virFileExists(QEMU_DEVICE_MAPPER_CONTROL_PATH)) { - for (i =3D 0; i < vm->def->ndisks; i++) { - virStorageSourcePtr diskSrc =3D vm->def->disks[i]->src; + if (src =3D=3D diskSrc) + continue; =20 - if (src =3D=3D diskSrc) - continue; + if (virStoragePRDefIsManaged(diskSrc->pr)) + hasPR =3D true; =20 - if (virStoragePRDefIsManaged(diskSrc->pr)) - break; - } + if (virStorageSourceChainHasNVMe(diskSrc)) + hasNVMe =3D true; + } =20 - if (i =3D=3D vm->def->ndisks) { - VIR_DEBUG("Disabling device mapper control"); - ret =3D virCgroupDenyDevicePath(priv->cgroup, - QEMU_DEVICE_MAPPER_CONTROL_PATH, - perms, true); + if (src->type =3D=3D VIR_STORAGE_TYPE_NVME) { + if (!(path =3D virPCIDeviceAddressGetIOMMUGroupDev(&src->nvme->pci= Addr))) + return -1; + + if (!hasNVMe && + !qemuDomainNeedsVFIO(vm->def)) { + ret =3D virCgroupDenyDevicePath(priv->cgroup, QEMU_DEV_VFIO, p= erms, true); virDomainAuditCgroupPath(vm, priv->cgroup, "deny", - QEMU_DEVICE_MAPPER_CONTROL_PATH, + QEMU_DEV_VFIO, virCgroupGetDevicePermsString(perms),= ret); if (ret < 0) - return ret; + return -1; } + } else { + if (!src->path || !virStorageSourceIsLocalStorage(src)) { + VIR_DEBUG("Not updating cgroups for disk path '%s', type: %s", + NULLSTR(src->path), virStorageTypeToString(src->type= )); + return 0; + } + + path =3D g_strdup(src->path); + } + + if (!hasPR && + virFileExists(QEMU_DEVICE_MAPPER_CONTROL_PATH)) { + VIR_DEBUG("Disabling device mapper control"); + ret =3D virCgroupDenyDevicePath(priv->cgroup, + QEMU_DEVICE_MAPPER_CONTROL_PATH, + perms, true); + virDomainAuditCgroupPath(vm, priv->cgroup, "deny", + QEMU_DEVICE_MAPPER_CONTROL_PATH, + virCgroupGetDevicePermsString(perms), ret= ); + if (ret < 0) + return ret; } =20 - VIR_DEBUG("Deny path %s", src->path); + VIR_DEBUG("Deny path %s", path); =20 - ret =3D virCgroupDenyDevicePath(priv->cgroup, src->path, perms, true); + ret =3D virCgroupDenyDevicePath(priv->cgroup, path, perms, true); =20 - virDomainAuditCgroupPath(vm, priv->cgroup, "deny", src->path, + virDomainAuditCgroupPath(vm, priv->cgroup, "deny", path, virCgroupGetDevicePermsString(perms), ret); =20 /* If you're looking for a counter part to --=20 2.23.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Fri Apr 26 22:05:19 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 207.211.31.120 as permitted sender) client-ip=207.211.31.120; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-1.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 207.211.31.120 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=1575296952; cv=none; d=zohomail.com; s=zohoarc; b=ZRtV/5mpxwUZsqUp4/+Svm+CM8qu6slkkFvzTvoUEZCBz5zkjfcCVHN/A48fwojNFIDbUZo7aXmhVrrU8jruK3gXNdVVb8s01FuqGV/QpxPvgLgn6ynO+co17E/4L7uz0LItT2DVbpxcW+CwhRLN0xAgEF1LBrSm5KJR4LCBZUg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1575296952; 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; bh=0CMtNN+GhfSc7xUHcYA/UO8cuUQafM+zzvnnotAPO4E=; b=KT5J9LseRvwWeZFA2Z1brMKNKxQr0fF7HEAT7Hvb409Ra7Z3hnKiHXaYONF3BzCJsFUaja8hPfHBQnF8NuhGMtAhyx69xwOgeEDvn4C693PgH73LzDFSTcqbvxkUZfy96KGW+uMORUywd4pYXIYC3HYvQ/1Qco1McIAKr4J4iHk= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 207.211.31.120 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from us-smtp-1.mimecast.com (us-smtp-delivery-1.mimecast.com [207.211.31.120]) by mx.zohomail.com with SMTPS id 1575296952166482.65764873904277; Mon, 2 Dec 2019 06:29:12 -0800 (PST) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-19-dzvbIyPSOxuMoLhOLTLBFQ-1; Mon, 02 Dec 2019 09:28:02 -0500 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 mimecast-mx01.redhat.com (Postfix) with ESMTPS id F24BC100A15F; Mon, 2 Dec 2019 14:27:55 +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 C66525DA70; Mon, 2 Dec 2019 14:27: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 7B2C05BC11; Mon, 2 Dec 2019 14:27:55 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id xB2ERL6h027495 for ; Mon, 2 Dec 2019 09:27:21 -0500 Received: by smtp.corp.redhat.com (Postfix) id DF6A16764D; Mon, 2 Dec 2019 14:27:21 +0000 (UTC) Received: from moe.redhat.com (unknown [10.43.2.30]) by smtp.corp.redhat.com (Postfix) with ESMTP id 68A8EA4B86 for ; Mon, 2 Dec 2019 14:27:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1575296951; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=0CMtNN+GhfSc7xUHcYA/UO8cuUQafM+zzvnnotAPO4E=; b=dkLo/GxcCaqhc74Q7rb6X6EWDtl8KzdL6FPthdBVZjjv+nXKlGrXQ0ix7WcNtpea2B3oVi xX8Gif7TAtw6hKykFh5DPUkbLWvqIQ0RAodWdTiPiCY4WSViRe5kJJb8/L1bm0d1Zp/CbU gzPB4BwBpsMf0nXKzVEmiI8m4wEWo9Y= From: Michal Privoznik To: libvir-list@redhat.com Date: Mon, 2 Dec 2019 15:26:46 +0100 Message-Id: <327d8c4ff536de52e156f62eaca68982d380bd37.1575296392.git.mprivozn@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v3 23/30] 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: , 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-MC-Unique: dzvbIyPSOxuMoLhOLTLBFQ-1 X-Mimecast-Spam-Score: 0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) 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 Reviewed-by: Cole Robinson --- src/security/security_apparmor.c | 25 ++++++++++++---- src/security/security_dac.c | 30 +++++++++++++++++++ src/security/security_selinux.c | 51 +++++++++++++++++++++++++++----- 3 files changed, 92 insertions(+), 14 deletions(-) diff --git a/src/security/security_apparmor.c b/src/security/security_appar= mor.c index 21560b2330..7cea788931 100644 --- a/src/security/security_apparmor.c +++ b/src/security/security_apparmor.c @@ -779,9 +779,8 @@ AppArmorSetSecurityImageLabel(virSecurityManagerPtr mgr, virSecurityDomainImageLabelFlags flags G_GNU= C_UNUSED) { virSecurityLabelDefPtr secdef; - - if (!src->path || !virStorageSourceIsLocalStorage(src)) - return 0; + g_autofree char *vfioGroupDev =3D NULL; + const char *path; =20 secdef =3D virDomainDefGetSecurityLabelDef(def, SECURITY_APPARMOR_NAME= ); if (!secdef || !secdef->relabel) @@ -790,15 +789,29 @@ AppArmorSetSecurityImageLabel(virSecurityManagerPtr m= gr, if (!secdef->imagelabel) return 0; =20 + if (src->type =3D=3D VIR_STORAGE_TYPE_NVME) { + const virStorageSourceNVMeDef *nvme =3D src->nvme; + + if (!(vfioGroupDev =3D virPCIDeviceAddressGetIOMMUGroupDev(&nvme->= pciAddr))) + return -1; + + path =3D vfioGroupDev; + } else { + if (!src->path || !virStorageSourceIsLocalStorage(src)) + return 0; + + path =3D src->path; + } + /* if the device doesn't exist, error out */ - if (!virFileExists(src->path)) { + if (!virFileExists(path)) { virReportError(VIR_ERR_INTERNAL_ERROR, _("\'%s\' does not exist"), - src->path); + path); return -1; } =20 - return reload_profile(mgr, def, src->path, true); + return reload_profile(mgr, def, path, true); } =20 static int diff --git a/src/security/security_dac.c b/src/security/security_dac.c index a9a1fad5d7..411aa1b159 100644 --- a/src/security/security_dac.c +++ b/src/security/security_dac.c @@ -911,6 +911,19 @@ virSecurityDACSetImageLabelInternal(virSecurityManager= Ptr mgr, return -1; } =20 + /* This is not very clean. But so far we don't have NVMe + * storage pool backend so that its chownCallback would be + * called. And this place looks least offensive. */ + if (src->type =3D=3D VIR_STORAGE_TYPE_NVME) { + const virStorageSourceNVMeDef *nvme =3D src->nvme; + g_autofree char *vfioGroupDev =3D NULL; + + if (!(vfioGroupDev =3D virPCIDeviceAddressGetIOMMUGroupDev(&nvme->= pciAddr))) + return -1; + + return virSecurityDACSetOwnership(mgr, NULL, vfioGroupDev, user, g= roup, false); + } + /* We can't do restore on shared resources safely. Not even * with refcounting implemented in XATTRs because if there * was a domain running with the feature turned off the @@ -1017,6 +1030,23 @@ virSecurityDACRestoreImageLabelSingle(virSecurityMan= agerPtr 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; + g_autofree char *vfioGroupDev =3D NULL; + + if (!(vfioGroupDev =3D virPCIDeviceAddressGetIOMMUGroupDev(&nvme->= pciAddr))) + return -1; + + /* Ideally, we would check if there is not another PCI + * device within domain def that is in the same IOMMU + * group. But we're not doing that for hostdevs yet. */ + + return virSecurityDACRestoreFileLabelInternal(mgr, NULL, vfioGroup= Dev, false); + } + return virSecurityDACRestoreFileLabelInternal(mgr, src, NULL, true); } =20 diff --git a/src/security/security_selinux.c b/src/security/security_selinu= x.c index e05ef7593e..26bbe55ce7 100644 --- a/src/security/security_selinux.c +++ b/src/security/security_selinux.c @@ -1729,9 +1729,8 @@ virSecuritySELinuxRestoreImageLabelSingle(virSecurity= ManagerPtr mgr, { virSecurityLabelDefPtr seclabel; virSecurityDeviceLabelDefPtr disk_seclabel; - - if (!src->path || !virStorageSourceIsLocalStorage(src)) - return 0; + g_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) @@ -1763,9 +1762,16 @@ virSecuritySELinuxRestoreImageLabelSingle(virSecurit= yManagerPtr 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); @@ -1773,7 +1779,22 @@ virSecuritySELinuxRestoreImageLabelSingle(virSecurit= yManagerPtr mgr, } } =20 - return virSecuritySELinuxRestoreFileLabel(mgr, src->path, true); + /* This is not very clean. But so far we don't have NVMe + * storage pool backend so that its chownCallback would be + * called. And this place looks least offensive. */ + if (src->type =3D=3D VIR_STORAGE_TYPE_NVME) { + const virStorageSourceNVMeDef *nvme =3D src->nvme; + + if (!(vfioGroupDev =3D virPCIDeviceAddressGetIOMMUGroupDev(&nvme->= pciAddr))) + return -1; + + /* Ideally, we would check if there is not another PCI + * device within domain def that is in the same IOMMU + * group. But we're not doing that for hostdevs yet. */ + path =3D vfioGroupDev; + } + + return virSecuritySELinuxRestoreFileLabel(mgr, path, true); } =20 =20 @@ -1820,6 +1841,8 @@ virSecuritySELinuxSetImageLabelInternal(virSecurityMa= nagerPtr mgr, char *use_label =3D NULL; bool remember; bool is_toplevel =3D parent =3D=3D src || parent->externalDataStore = =3D=3D src; + g_autofree char *vfioGroupDev =3D NULL; + const char *path =3D src->path; int ret; =20 if (!src->path || !virStorageSourceIsLocalStorage(src)) @@ -1872,7 +1895,19 @@ virSecuritySELinuxSetImageLabelInternal(virSecurityM= anagerPtr mgr, use_label =3D data->content_context; } =20 - ret =3D virSecuritySELinuxSetFilecon(mgr, src->path, use_label, rememb= er); + /* This is not very clean. But so far we don't have NVMe + * storage pool backend so that its chownCallback would be + * called. And this place looks least offensive. */ + if (src->type =3D=3D VIR_STORAGE_TYPE_NVME) { + const virStorageSourceNVMeDef *nvme =3D src->nvme; + + if (!(vfioGroupDev =3D virPCIDeviceAddressGetIOMMUGroupDev(&nvme->= pciAddr))) + return -1; + + path =3D vfioGroupDev; + } + + ret =3D virSecuritySELinuxSetFilecon(mgr, path, use_label, remember); =20 if (ret =3D=3D 1 && !disk_seclabel) { /* If we failed to set a label, but virt_use_nfs let us --=20 2.23.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Fri Apr 26 22:05:19 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 205.139.110.120 as permitted sender) client-ip=205.139.110.120; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-1.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 205.139.110.120 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=1575296887; cv=none; d=zohomail.com; s=zohoarc; b=mj+PezHmvURijVCyoASTrIyU1IKTvINeeXDCpZoD3q6d1A6xgZI40kyMIn6MBgKgDq1SBSxBhyERP+fFVa16cLuQ0l4Ayd/94PQlLxy3yTFmSF0okyCWsiVPx9JPp6nqsoB0X3uLrQJ8N0J4Qz/l9zxo9W+5pjYU+wnjuJ51Z4c= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1575296887; 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; bh=JRM+lt5msezNOdqpzBqAg4YCmHU/uBC+QUyrA/ofYvk=; b=HR+bVg6cZdAblQMW3nttooqDm9cgMm/34beik6+VvRZ6Ve54k69nTwDelsz4jHJs+LxukzWktunAGh3d31Y/zU08MW5k3hWOqeph09z8fw8ji6nCNtsnlVqNM7K2ZpWEOtUm4ZlrpUFl7bLcNQovHo0OySDRd+RwYWvn9s0H0IA= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 205.139.110.120 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from us-smtp-1.mimecast.com (us-smtp-delivery-1.mimecast.com [205.139.110.120]) by mx.zohomail.com with SMTPS id 1575296887701526.1735610937596; Mon, 2 Dec 2019 06:28:07 -0800 (PST) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-440-g4UexvjHO6uU8ctnHXOEPA-1; Mon, 02 Dec 2019 09:28:01 -0500 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 mimecast-mx01.redhat.com (Postfix) with ESMTPS id 2ACED18AAFBC; Mon, 2 Dec 2019 14:27:56 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id EBB535DA32; Mon, 2 Dec 2019 14:27: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 A823818034F9; Mon, 2 Dec 2019 14:27:55 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id xB2ERMJp027505 for ; Mon, 2 Dec 2019 09:27:22 -0500 Received: by smtp.corp.redhat.com (Postfix) id B0D296764D; Mon, 2 Dec 2019 14:27:22 +0000 (UTC) Received: from moe.redhat.com (unknown [10.43.2.30]) by smtp.corp.redhat.com (Postfix) with ESMTP id 3A0BCA4B86 for ; Mon, 2 Dec 2019 14:27:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1575296883; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=JRM+lt5msezNOdqpzBqAg4YCmHU/uBC+QUyrA/ofYvk=; b=f2CiDouyBIVH3CjpA31TYKg4qWtGS2QQOR67p7wjYVP73+lFJPcJuOMFIAyBG/IwK0YPk9 IIdLKeN/rI/JoZFNy7cI1cQDvVzso8KUhuURfxDqF8lBil/wsAeZFr7AJAfbVdzejR4jB2 F30QQg5PehwJXMOMLTMDxVWw2Z4KA9o= From: Michal Privoznik To: libvir-list@redhat.com Date: Mon, 2 Dec 2019 15:26:47 +0100 Message-Id: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v3 24/30] 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: , 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-MC-Unique: g4UexvjHO6uU8ctnHXOEPA-1 X-Mimecast-Spam-Score: 0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) 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 Reviewed-by: Cole Robinson --- src/qemu/qemu_capabilities.c | 2 ++ src/qemu/qemu_capabilities.h | 1 + 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 + tests/qemucapabilitiesdata/caps_4.2.0.aarch64.xml | 1 + tests/qemucapabilitiesdata/caps_4.2.0.ppc64.xml | 1 + tests/qemucapabilitiesdata/caps_4.2.0.s390x.xml | 1 + tests/qemucapabilitiesdata/caps_4.2.0.x86_64.xml | 1 + 24 files changed, 25 insertions(+) diff --git a/src/qemu/qemu_capabilities.c b/src/qemu/qemu_capabilities.c index f65af5c228..4b3b4f2eff 100644 --- a/src/qemu/qemu_capabilities.c +++ b/src/qemu/qemu_capabilities.c @@ -552,6 +552,7 @@ VIR_ENUM_IMPL(virQEMUCaps, "arm-max-cpu", "blockdev-file-dynamic-auto-read-only", "savevm-monitor-nodes", + "drive-nvme", ); =20 =20 @@ -1399,6 +1400,7 @@ static struct virQEMUCapsStringFlags virQEMUCapsQMPSc= hemaQueries[] =3D { { "blockdev-add/arg-type/+file/drop-cache", QEMU_CAPS_MIGRATION_FILE_D= ROP_CACHE }, { "blockdev-add/arg-type/+file/$dynamic-auto-read-only", QEMU_CAPS_BLO= CK_FILE_AUTO_READONLY_DYNAMIC }, { "human-monitor-command/$savevm-monitor-nodes", QEMU_CAPS_SAVEVM_MONI= TOR_NODES }, + { "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 3fd8bebe79..3a9b70c1cf 100644 --- a/src/qemu/qemu_capabilities.h +++ b/src/qemu/qemu_capabilities.h @@ -533,6 +533,7 @@ typedef enum { /* virQEMUCapsFlags grouping marker for = syntax-check */ QEMU_CAPS_ARM_MAX_CPU, /* max-arm-cpu type exists */ QEMU_CAPS_BLOCK_FILE_AUTO_READONLY_DYNAMIC, /* the auto-read-only prop= erty of block backends for files is dynamic */ QEMU_CAPS_SAVEVM_MONITOR_NODES, /* 'savevm' handles monitor-owned node= s properly */ + QEMU_CAPS_DRIVE_NVME, /* -drive file.driver=3Dnvme */ =20 QEMU_CAPS_LAST /* this must always be the last item */ } virQEMUCapsFlags; diff --git a/tests/qemucapabilitiesdata/caps_2.12.0.aarch64.xml b/tests/qem= ucapabilitiesdata/caps_2.12.0.aarch64.xml index 5d1bfb798f..72c63533a3 100644 --- a/tests/qemucapabilitiesdata/caps_2.12.0.aarch64.xml +++ b/tests/qemucapabilitiesdata/caps_2.12.0.aarch64.xml @@ -154,6 +154,7 @@ + 2012000 0 61700289 diff --git a/tests/qemucapabilitiesdata/caps_2.12.0.ppc64.xml b/tests/qemuc= apabilitiesdata/caps_2.12.0.ppc64.xml index 84179e8ef6..147c017fe3 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 42900289 diff --git a/tests/qemucapabilitiesdata/caps_2.12.0.s390x.xml b/tests/qemuc= apabilitiesdata/caps_2.12.0.s390x.xml index 4be4018d44..8ff0633724 100644 --- a/tests/qemucapabilitiesdata/caps_2.12.0.s390x.xml +++ b/tests/qemucapabilitiesdata/caps_2.12.0.s390x.xml @@ -123,6 +123,7 @@ + 2012000 0 39100289 diff --git a/tests/qemucapabilitiesdata/caps_2.12.0.x86_64.xml b/tests/qemu= capabilitiesdata/caps_2.12.0.x86_64.xml index 81903cd493..85954d352e 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 43100289 diff --git a/tests/qemucapabilitiesdata/caps_3.0.0.ppc64.xml b/tests/qemuca= pabilitiesdata/caps_3.0.0.ppc64.xml index 8714c3c1f4..baea300753 100644 --- a/tests/qemucapabilitiesdata/caps_3.0.0.ppc64.xml +++ b/tests/qemucapabilitiesdata/caps_3.0.0.ppc64.xml @@ -153,6 +153,7 @@ + 2012050 0 42900239 diff --git a/tests/qemucapabilitiesdata/caps_3.0.0.riscv32.xml b/tests/qemu= capabilitiesdata/caps_3.0.0.riscv32.xml index a31fc2a250..3b81ea11c3 100644 --- a/tests/qemucapabilitiesdata/caps_3.0.0.riscv32.xml +++ b/tests/qemucapabilitiesdata/caps_3.0.0.riscv32.xml @@ -93,6 +93,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 6bf0e68725..615667d9b2 100644 --- a/tests/qemucapabilitiesdata/caps_3.0.0.riscv64.xml +++ b/tests/qemucapabilitiesdata/caps_3.0.0.riscv64.xml @@ -93,6 +93,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 941369003b..34a4999294 100644 --- a/tests/qemucapabilitiesdata/caps_3.0.0.s390x.xml +++ b/tests/qemucapabilitiesdata/caps_3.0.0.s390x.xml @@ -126,6 +126,7 @@ + 3000000 0 39100239 diff --git a/tests/qemucapabilitiesdata/caps_3.0.0.x86_64.xml b/tests/qemuc= apabilitiesdata/caps_3.0.0.x86_64.xml index 92abf01e4e..3d5535f404 100644 --- a/tests/qemucapabilitiesdata/caps_3.0.0.x86_64.xml +++ b/tests/qemucapabilitiesdata/caps_3.0.0.x86_64.xml @@ -200,6 +200,7 @@ + 3000000 0 43100239 diff --git a/tests/qemucapabilitiesdata/caps_3.1.0.ppc64.xml b/tests/qemuca= pabilitiesdata/caps_3.1.0.ppc64.xml index 5667860b44..0f64cfb2ba 100644 --- a/tests/qemucapabilitiesdata/caps_3.1.0.ppc64.xml +++ b/tests/qemucapabilitiesdata/caps_3.1.0.ppc64.xml @@ -157,6 +157,7 @@ + 3000091 0 42900240 diff --git a/tests/qemucapabilitiesdata/caps_3.1.0.x86_64.xml b/tests/qemuc= apabilitiesdata/caps_3.1.0.x86_64.xml index 5cdba54a11..c468ad0153 100644 --- a/tests/qemucapabilitiesdata/caps_3.1.0.x86_64.xml +++ b/tests/qemucapabilitiesdata/caps_3.1.0.x86_64.xml @@ -203,6 +203,7 @@ + 3000092 0 43100240 diff --git a/tests/qemucapabilitiesdata/caps_4.0.0.aarch64.xml b/tests/qemu= capabilitiesdata/caps_4.0.0.aarch64.xml index dacbadd208..9fc3c7e6f5 100644 --- a/tests/qemucapabilitiesdata/caps_4.0.0.aarch64.xml +++ b/tests/qemucapabilitiesdata/caps_4.0.0.aarch64.xml @@ -167,6 +167,7 @@ + 4000000 0 61700240 diff --git a/tests/qemucapabilitiesdata/caps_4.0.0.ppc64.xml b/tests/qemuca= pabilitiesdata/caps_4.0.0.ppc64.xml index cd860daa9f..e84dd557a4 100644 --- a/tests/qemucapabilitiesdata/caps_4.0.0.ppc64.xml +++ b/tests/qemucapabilitiesdata/caps_4.0.0.ppc64.xml @@ -171,6 +171,7 @@ + 4000000 0 42900240 diff --git a/tests/qemucapabilitiesdata/caps_4.0.0.riscv32.xml b/tests/qemu= capabilitiesdata/caps_4.0.0.riscv32.xml index a1a1a26ece..bc675fc727 100644 --- a/tests/qemucapabilitiesdata/caps_4.0.0.riscv32.xml +++ b/tests/qemucapabilitiesdata/caps_4.0.0.riscv32.xml @@ -168,6 +168,7 @@ + 4000000 0 0 diff --git a/tests/qemucapabilitiesdata/caps_4.0.0.riscv64.xml b/tests/qemu= capabilitiesdata/caps_4.0.0.riscv64.xml index 5bdc1e9451..1eeda32b7c 100644 --- a/tests/qemucapabilitiesdata/caps_4.0.0.riscv64.xml +++ b/tests/qemucapabilitiesdata/caps_4.0.0.riscv64.xml @@ -168,6 +168,7 @@ + 4000000 0 0 diff --git a/tests/qemucapabilitiesdata/caps_4.0.0.s390x.xml b/tests/qemuca= pabilitiesdata/caps_4.0.0.s390x.xml index 54f7aba2dc..8b8acd5a33 100644 --- a/tests/qemucapabilitiesdata/caps_4.0.0.s390x.xml +++ b/tests/qemucapabilitiesdata/caps_4.0.0.s390x.xml @@ -134,6 +134,7 @@ + 4000000 0 39100240 diff --git a/tests/qemucapabilitiesdata/caps_4.0.0.x86_64.xml b/tests/qemuc= apabilitiesdata/caps_4.0.0.x86_64.xml index 90f8452710..c29be71658 100644 --- a/tests/qemucapabilitiesdata/caps_4.0.0.x86_64.xml +++ b/tests/qemucapabilitiesdata/caps_4.0.0.x86_64.xml @@ -208,6 +208,7 @@ + 4000000 0 43100240 diff --git a/tests/qemucapabilitiesdata/caps_4.1.0.x86_64.xml b/tests/qemuc= apabilitiesdata/caps_4.1.0.x86_64.xml index 9f1675aa55..2bc9672063 100644 --- a/tests/qemucapabilitiesdata/caps_4.1.0.x86_64.xml +++ b/tests/qemucapabilitiesdata/caps_4.1.0.x86_64.xml @@ -213,6 +213,7 @@ + 4001000 0 43100241 diff --git a/tests/qemucapabilitiesdata/caps_4.2.0.aarch64.xml b/tests/qemu= capabilitiesdata/caps_4.2.0.aarch64.xml index 6ed4829be6..588e682064 100644 --- a/tests/qemucapabilitiesdata/caps_4.2.0.aarch64.xml +++ b/tests/qemucapabilitiesdata/caps_4.2.0.aarch64.xml @@ -173,6 +173,7 @@ + 4001050 0 61700242 diff --git a/tests/qemucapabilitiesdata/caps_4.2.0.ppc64.xml b/tests/qemuca= pabilitiesdata/caps_4.2.0.ppc64.xml index bc7042e7e1..9a480c4eb3 100644 --- a/tests/qemucapabilitiesdata/caps_4.2.0.ppc64.xml +++ b/tests/qemucapabilitiesdata/caps_4.2.0.ppc64.xml @@ -174,6 +174,7 @@ + 4001050 0 42900242 diff --git a/tests/qemucapabilitiesdata/caps_4.2.0.s390x.xml b/tests/qemuca= pabilitiesdata/caps_4.2.0.s390x.xml index 714634dcc3..505b3adcb6 100644 --- a/tests/qemucapabilitiesdata/caps_4.2.0.s390x.xml +++ b/tests/qemucapabilitiesdata/caps_4.2.0.s390x.xml @@ -133,6 +133,7 @@ + 4001050 0 39100242 diff --git a/tests/qemucapabilitiesdata/caps_4.2.0.x86_64.xml b/tests/qemuc= apabilitiesdata/caps_4.2.0.x86_64.xml index c7bac03f44..31302c9a7b 100644 --- a/tests/qemucapabilitiesdata/caps_4.2.0.x86_64.xml +++ b/tests/qemucapabilitiesdata/caps_4.2.0.x86_64.xml @@ -216,6 +216,7 @@ + 4001092 0 43100242 --=20 2.23.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Fri Apr 26 22:05:19 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 205.139.110.61 as permitted sender) client-ip=205.139.110.61; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-1.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 205.139.110.61 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=1575297173; cv=none; d=zohomail.com; s=zohoarc; b=da7KuuuAcXcIoWoTskJR7u73goJcFhUinG6KJGQcGF0jyNsmTjscWrA3HnsEYBtozSz8tdIkhs3257I1ZN4qIslGZ0DwJGDdlVxo6FxBIiQHKUwc4/p8/x6YNAlY2qLXZ5T/Dvfw0md+JiEec6qQ2zhg1clFKNcL2X+757H6zl0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1575297173; 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; bh=zWutnleXWkjLIh/KFrVpMD9CTgBRVnjRjUUD0G7qi18=; b=TL4/GxxovTqVPAOq+pTT8Amjt2trw3oJ1OG8ysI6yXBu+ygfSLoGJr3rhCQ4FoJ3Vsr83Yky/oFSbRl92onhrmO+E7rotnTq0uVNPa48Ok5rQBs6YYzkUKRSErLiAa0x8q3A6xlndcb7895NoqLd0A6gTa537OP7/lVUMHtPzX8= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 205.139.110.61 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from us-smtp-delivery-1.mimecast.com (us-smtp-2.mimecast.com [205.139.110.61]) by mx.zohomail.com with SMTPS id 1575297173753732.0509293167347; Mon, 2 Dec 2019 06:32:53 -0800 (PST) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-166-f_x1NkDZPVyXQVJOP2fSmw-1; Mon, 02 Dec 2019 09:28:08 -0500 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 mimecast-mx01.redhat.com (Postfix) with ESMTPS id BE77780256B; Mon, 2 Dec 2019 14:27:59 +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 92CF160C84; Mon, 2 Dec 2019 14:27:59 +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 4903B1803500; Mon, 2 Dec 2019 14:27:59 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id xB2ERNQY027516 for ; Mon, 2 Dec 2019 09:27:23 -0500 Received: by smtp.corp.redhat.com (Postfix) id 82385A4B86; Mon, 2 Dec 2019 14:27:23 +0000 (UTC) Received: from moe.redhat.com (unknown [10.43.2.30]) by smtp.corp.redhat.com (Postfix) with ESMTP id 09FE26764D for ; Mon, 2 Dec 2019 14:27:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1575297172; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=zWutnleXWkjLIh/KFrVpMD9CTgBRVnjRjUUD0G7qi18=; b=EnHzZVPWdTac5yYDtc3/hmxXrPVg7Dp3oAHzJqlcYaj77NOocV0c9DGA77csFScsG3ksnM e7BIQtAyuFxYbNQaxvrIyRwtabCqVa5neJRvvGqGOQmz2Ru0kOzMWE8LG3uijcm+LQejFN 1V9WaUBRhgp0WWSxdXRTXcJ2qMzWnq8= From: Michal Privoznik To: libvir-list@redhat.com Date: Mon, 2 Dec 2019 15:26:48 +0100 Message-Id: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v3 25/30] 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: , 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-MC-Unique: f_x1NkDZPVyXQVJOP2fSmw-1 X-Mimecast-Spam-Score: 0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) 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 Reviewed-by: Cole Robinson --- src/qemu/qemu_block.c | 25 +++++++- src/qemu/qemu_command.c | 3 + src/qemu/qemu_process.c | 7 +++ .../disk-nvme.x86_64-latest.args | 63 +++++++++++++++++++ tests/qemuxml2argvtest.c | 1 + 5 files changed, 98 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 8eeb9c3c57..1ff5a7f226 100644 --- a/src/qemu/qemu_block.c +++ b/src/qemu/qemu_block.c @@ -977,6 +977,25 @@ qemuBlockStorageSourceGetVvfatProps(virStorageSourcePt= r src, } =20 =20 +static virJSONValuePtr +qemuBlockStorageSourceGetNVMeProps(virStorageSourcePtr src) +{ + const virStorageSourceNVMeDef *nvme =3D src->nvme; + g_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) @@ -1059,8 +1078,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 c61e38492a..97d11c1d5f 100644 --- a/src/qemu/qemu_command.c +++ b/src/qemu/qemu_command.c @@ -1527,6 +1527,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 a588ee25f8..fa507691ff 100644 --- a/src/qemu/qemu_process.c +++ b/src/qemu/qemu_process.c @@ -5284,6 +5284,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..b4486086fa --- /dev/null +++ b/tests/qemuxml2argvdata/disk-nvme.x86_64-latest.args @@ -0,0 +1,63 @@ +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 \ +-blockdev '{"driver":"nvme","device":"0000:01:00.0","namespace":1,\ +"node-name":"libvirt-4-storage","auto-read-only":true,"discard":"unmap"}' \ +-blockdev '{"node-name":"libvirt-4-format","read-only":false,"driver":"raw= ",\ +"file":"libvirt-4-storage"}' \ +-device virtio-blk-pci,scsi=3Doff,bus=3Dpci.0,addr=3D0x4,drive=3Dlibvirt-4= -format,\ +id=3Dvirtio-disk0,bootindex=3D1 \ +-blockdev '{"driver":"nvme","device":"0000:01:00.0","namespace":2,\ +"node-name":"libvirt-3-storage","auto-read-only":true,"discard":"unmap"}' \ +-blockdev '{"node-name":"libvirt-3-format","read-only":false,"driver":"raw= ",\ +"file":"libvirt-3-storage"}' \ +-device virtio-blk-pci,scsi=3Doff,bus=3Dpci.0,addr=3D0x5,drive=3Dlibvirt-3= -format,\ +id=3Dvirtio-disk1 \ +-blockdev '{"driver":"nvme","device":"0000:02:00.0","namespace":1,\ +"node-name":"libvirt-2-storage","auto-read-only":true,"discard":"unmap"}' \ +-blockdev '{"node-name":"libvirt-2-format","read-only":false,"driver":"raw= ",\ +"file":"libvirt-2-storage"}' \ +-device virtio-blk-pci,scsi=3Doff,bus=3Dpci.0,addr=3D0x6,drive=3Dlibvirt-2= -format,\ +id=3Dvirtio-disk2 \ +-object secret,id=3Dlibvirt-1-format-luks-secret0,\ +data=3D9eao5F8qtkGt+seB1HYivWIxbtwUu6MQtg1zpj/oDtUsPr1q8wBYM91uEHCn6j/1,\ +keyid=3DmasterKey0,iv=3DAAECAwQFBgcICQoLDA0ODw=3D=3D,format=3Dbase64 \ +-blockdev '{"driver":"nvme","device":"0001:02:00.0","namespace":2,\ +"node-name":"libvirt-1-storage","cache":{"direct":true,"no-flush":false},\ +"auto-read-only":true,"discard":"unmap"}' \ +-blockdev '{"node-name":"libvirt-1-format","read-only":false,\ +"cache":{"direct":true,"no-flush":false},"driver":"qcow2",\ +"encrypt":{"format":"luks","key-secret":"libvirt-1-format-luks-secret0"},\ +"file":"libvirt-1-storage"}' \ +-device virtio-blk-pci,scsi=3Doff,bus=3Dpci.0,addr=3D0x7,drive=3Dlibvirt-1= -format,\ +id=3Dvirtio-disk3,write-cache=3Don \ +-sandbox on,obsolete=3Ddeny,elevateprivileges=3Ddeny,spawn=3Ddeny,\ +resourcecontrol=3Ddeny \ +-msg timestamp=3Don diff --git a/tests/qemuxml2argvtest.c b/tests/qemuxml2argvtest.c index 86b8899921..440f47309f 100644 --- a/tests/qemuxml2argvtest.c +++ b/tests/qemuxml2argvtest.c @@ -1078,6 +1078,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_CAPS_LATEST_PARSE_ERROR("disk-attaching-partition-nosupport"); --=20 2.23.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Fri Apr 26 22:05:19 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 205.139.110.120 as permitted sender) client-ip=205.139.110.120; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-1.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 205.139.110.120 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=1575296893; cv=none; d=zohomail.com; s=zohoarc; b=j5Joj+v1qzEMpSIChW6P2Q0iNAO8Vw23LbB0zhBtl2tu/h2zK01Bat2xyFIAu8YFqh61i07JfBqAipCcMu4DynAV0LcBQRcEMcB0EEWiXjitBMMPXd2t7ZsceXltXPaqLBf5GGJCiOofthlT/f5gj4PLyqxG0nznsuxDToCE4vM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1575296893; 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; bh=qCD3BIE7PusFc5DaKwfC/63BVs0yKW0uKHwqC1xeOZk=; b=BjlWcR4Bw8sWgHGrU2pH+5xzHAns+aFL6w0M8jMiXekBYK9hStRVQWmeCfAZbef6yJX3bUNWaKLTIfiiQQezJmrqIbxSavLpvjfeUz8F/gUb8H+C4Kd0B4HvRpx5Z49j6p/WvH+HuJqfS5RfK1lSVmYpOkFiIih9l00m/LdjTb0= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 205.139.110.120 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from us-smtp-1.mimecast.com (us-smtp-delivery-1.mimecast.com [205.139.110.120]) by mx.zohomail.com with SMTPS id 157529689312578.62662459579485; Mon, 2 Dec 2019 06:28:13 -0800 (PST) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-174-cq_KQfHBMIus-u4H0GXFHA-1; Mon, 02 Dec 2019 09:28:10 -0500 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 mimecast-mx01.redhat.com (Postfix) with ESMTPS id EF27310830E7; Mon, 2 Dec 2019 14:28:04 +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 BF09519486; Mon, 2 Dec 2019 14:28: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 73A715BBFE; Mon, 2 Dec 2019 14:28:04 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id xB2EROxX027529 for ; Mon, 2 Dec 2019 09:27:24 -0500 Received: by smtp.corp.redhat.com (Postfix) id 4FF62A4B86; Mon, 2 Dec 2019 14:27:24 +0000 (UTC) Received: from moe.redhat.com (unknown [10.43.2.30]) by smtp.corp.redhat.com (Postfix) with ESMTP id CDDA36764D for ; Mon, 2 Dec 2019 14:27:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1575296891; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=qCD3BIE7PusFc5DaKwfC/63BVs0yKW0uKHwqC1xeOZk=; b=bbe/Ximj6tLTl0300CX0RAUmtLc1SRTco9IteLH/DXYUTc7p2YAH/J++3k/M5GPZPUVxZv B65jFxGGNlV4ebHm34fy51e6YOGQ8q8YzcUtfq26Rn645MH1sj1iYV7Jp6z0icSVedLlum cx+HH5GcfLo4xwE6JRAha9NIb5cCCvk= From: Michal Privoznik To: libvir-list@redhat.com Date: Mon, 2 Dec 2019 15:26:49 +0100 Message-Id: <24170644cce9c6cdb7dac62d844b497e0bbf546e.1575296392.git.mprivozn@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v3 26/30] qemu_monitor_text: Catch IOMMU/VFIO related errors in qemuMonitorTextAddDrive X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , 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-MC-Unique: cq_KQfHBMIus-u4H0GXFHA-1 X-Mimecast-Spam-Score: 0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" Because this is a HMP we're dealing with, there is nothing like class of reply message, so we have to do some string comparison to guess if the command fails. Well, with NVMe disks whole new class of errors comes to play because qemu needs to initialize IOMMU and VFIO for them. You can see all the messages it may produce in qemu_vfio_init_pci(). Signed-off-by: Michal Privoznik Reviewed-by: Cole Robinson --- src/qemu/qemu_monitor_text.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/qemu/qemu_monitor_text.c b/src/qemu/qemu_monitor_text.c index 9054682d60..6948a5bf90 100644 --- a/src/qemu/qemu_monitor_text.c +++ b/src/qemu/qemu_monitor_text.c @@ -75,6 +75,13 @@ int qemuMonitorTextAddDrive(qemuMonitorPtr mon, goto cleanup; } =20 + if (strstr(reply, "IOMMU") || + strstr(reply, "VFIO")) { + virReportError(VIR_ERR_OPERATION_FAILED, "%s", + reply); + goto cleanup; + } + ret =3D 0; =20 cleanup: --=20 2.23.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Fri Apr 26 22:05:19 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 207.211.31.81 as permitted sender) client-ip=207.211.31.81; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-1.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 207.211.31.81 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=1575296869; cv=none; d=zohomail.com; s=zohoarc; b=ZoYkVv+mx4+JnwP6W/F3WtDKopXwWLtnkA28UtYI1DaperVipC3YEBg2hotgkCXWatFlfbuVLhUAFmPoT6I2xnpE6EtBzVHr9TodFu8tUfIxPUYILgjHRv6Ds53Kk4FnQmEGNLCdfQQqWILvpgcPbnPWFj5fAsSQPTovdrQHiSk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1575296869; 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; bh=7kFCc2LarpbKHpkJOIfVrQd4FdYb5ANeJqNCDXMKjrE=; b=DHrjpTWyjN2hmC6reX2zwKZnU91L05xW1AUy+jN66lF27rBcuNEbu8hGcOJQFjHmd4x7gan20WLyV+hFjL/ud86rKvBVakL/ljaERtnLgwHRBdphs4uHqWD0+3qVEDSWS5r15np/i15o4FsTo3DBEw/FdCIIooC5uTN2Tu4M6dM= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 207.211.31.81 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from us-smtp-delivery-1.mimecast.com (us-smtp-2.mimecast.com [207.211.31.81]) by mx.zohomail.com with SMTPS id 1575296869509857.5786262594646; Mon, 2 Dec 2019 06:27:49 -0800 (PST) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-137-Ph7_DtMwPtyd0DX9tkFrkQ-1; Mon, 02 Dec 2019 09:27:45 -0500 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 mimecast-mx01.redhat.com (Postfix) with ESMTPS id 9415F100E4E8; Mon, 2 Dec 2019 14:27:39 +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 68EFB1001B00; Mon, 2 Dec 2019 14:27:39 +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 1F0631803C40; Mon, 2 Dec 2019 14:27:39 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id xB2ERPu8027543 for ; Mon, 2 Dec 2019 09:27:25 -0500 Received: by smtp.corp.redhat.com (Postfix) id 2146C6764D; Mon, 2 Dec 2019 14:27:25 +0000 (UTC) Received: from moe.redhat.com (unknown [10.43.2.30]) by smtp.corp.redhat.com (Postfix) with ESMTP id 9DE92A4B86 for ; Mon, 2 Dec 2019 14:27:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1575296868; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=7kFCc2LarpbKHpkJOIfVrQd4FdYb5ANeJqNCDXMKjrE=; b=Y2qiM3TrzPvKXPfXS5gX3Ph1L53vdWsTFqyOnqgq7MX2Ac9xlf+P7Exw9BzLQ/b/B3m+o8 H1ShayToX/tDWVdmcNMTlonVVQ9iH7V0BwVaI+uOAoMlpwGFO8TleZRM8U6cpPtkQy/eKo omSND1JQJY7LXVye4Jst8u6maufoVC4= From: Michal Privoznik To: libvir-list@redhat.com Date: Mon, 2 Dec 2019 15:26:50 +0100 Message-Id: <896370ef4bdb4cc2a27f3462c62cbbbb1db69c33.1575296392.git.mprivozn@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v3 27/30] 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: , 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-MC-Unique: Ph7_DtMwPtyd0DX9tkFrkQ-1 X-Mimecast-Spam-Score: 0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) 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 Reviewed-by: Cole Robinson --- 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 d4eacaf099..053523f8c5 100644 --- a/src/qemu/qemu_hotplug.c +++ b/src/qemu/qemu_hotplug.c @@ -683,13 +683,13 @@ qemuDomainAttachDiskGeneric(virQEMUDriverPtr driver, bool blockdev =3D virQEMUCapsGet(priv->qemuCaps, QEMU_CAPS_BLOCKDEV); =20 if (qemuDomainStorageSourceChainAccessAllow(driver, vm, disk->src) < 0) - goto cleanup; + return -1; =20 if (qemuAssignDeviceDiskAlias(vm->def, disk, priv->qemuCaps) < 0) - goto error; + goto cleanup; =20 if (qemuDomainPrepareDiskSource(disk, priv, cfg) < 0) - goto error; + goto cleanup; =20 if (blockdev) { if (disk->copy_on_read =3D=3D VIR_TRISTATE_SWITCH_ON && @@ -706,13 +706,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 @@ -748,7 +748,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); @@ -757,6 +757,8 @@ qemuDomainAttachDiskGeneric(virQEMUDriverPtr driver, ret =3D 0; =20 cleanup: + if (ret < 0) + ignore_value(qemuDomainStorageSourceChainAccessRevoke(driver, vm, = disk->src)); qemuDomainSecretDiskDestroy(disk); return ret; =20 @@ -773,9 +775,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.23.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Fri Apr 26 22:05:19 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 207.211.31.120 as permitted sender) client-ip=207.211.31.120; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-1.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 207.211.31.120 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=1575296897; cv=none; d=zohomail.com; s=zohoarc; b=WnGyTW+bI8BXJ5f1r2Ewh85McUVE9yYPw5Ae4w4MDL8/WdbhBCWSunHWjK/rGBiJ+VwawnXH9yBdS0e6ZnnOLe6dL17k0wvnZylBqBbo+VJHU1HHIVQxFtMUkRujc0G8XoO8/ONoOod5zIGpHzwjwLjj1PHVgHc59FWGso/04/E= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1575296897; 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; bh=fHBo2pLi7d0X8VWrwhFRsYi17jWsmzjF4ePSuj3FRNA=; b=RL67Yt12xjDZEUPB0r35gBBF9UhAzcDtZYTdgAYKO5S9CA6fY6UUQwQmq4lSD3cZbF7lzzoK0eYaftLwoeT0hAEuGbW7IJGBkXxW9CReGKlMVRt2Ip0uB8IWvOKp18d6Ht8E7cBdiiB+zanfeC3fLe0SGJUzYELZWS4QOErDVYg= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 207.211.31.120 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from us-smtp-1.mimecast.com (us-smtp-delivery-1.mimecast.com [207.211.31.120]) by mx.zohomail.com with SMTPS id 157529689764870.68335254017711; Mon, 2 Dec 2019 06:28:17 -0800 (PST) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-207-sPUgnjJMOfKs_HL1MD_GHA-1; Mon, 02 Dec 2019 09:28:14 -0500 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 mimecast-mx01.redhat.com (Postfix) with ESMTPS id 1877E881D2F; Mon, 2 Dec 2019 14:28:09 +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 CABCC1036C7B; Mon, 2 Dec 2019 14:28: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 78A875BC19; Mon, 2 Dec 2019 14:28:08 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id xB2ERPdQ027555 for ; Mon, 2 Dec 2019 09:27:25 -0500 Received: by smtp.corp.redhat.com (Postfix) id E55BFA4B86; Mon, 2 Dec 2019 14:27:25 +0000 (UTC) Received: from moe.redhat.com (unknown [10.43.2.30]) by smtp.corp.redhat.com (Postfix) with ESMTP id 6DF9D6764D for ; Mon, 2 Dec 2019 14:27:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1575296896; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=fHBo2pLi7d0X8VWrwhFRsYi17jWsmzjF4ePSuj3FRNA=; b=hLJcGSM1jG5XttK7+1Ahghg9mSdUSdFgB7sFgx/wDUgu1J/JUbrB15Pip+DFoKwnvpVyON pBEM6baH69CmVjoBg5udZQ/l6xav4evnl4LykMLT0JqxoM1HWrYuLHxtmTmNcTeNiWOEDG j8Q3RTw2VY8pF2j2v/wnUqdQ5XDC3co= From: Michal Privoznik To: libvir-list@redhat.com Date: Mon, 2 Dec 2019 15:26:51 +0100 Message-Id: <1cb397c28c07fd5efd41403d6adbffc3d0b2feec.1575296392.git.mprivozn@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v3 28/30] qemu: Allow forcing VFIO when computing memlock limit X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , 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-MC-Unique: sPUgnjJMOfKs_HL1MD_GHA-1 X-Mimecast-Spam-Score: 0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" With NVMe disks, one can start a blockjob with a NVMe disk that is not visible in domain XML (at least right away). Usually, it's fairly easy to override this limitation of qemuDomainGetMemLockLimitBytes() - for instance for hostdevs we temporarily add the device to domain def, let the function calculate the limit and then remove the device. But it's not so easy with virStorageSourcePtr - in some cases they don't necessarily are attached to a disk. And even if they are it's done later in the process and frankly, I find it too complicated to be able to use the simple trick we use with hostdevs. Signed-off-by: Michal Privoznik Reviewed-by: Cole Robinson --- src/qemu/qemu_command.c | 2 +- src/qemu/qemu_domain.c | 46 ++++++++++++++++++++++++++--------------- src/qemu/qemu_domain.h | 6 ++++-- src/qemu/qemu_hotplug.c | 12 +++++------ tests/qemumemlocktest.c | 2 +- 5 files changed, 41 insertions(+), 27 deletions(-) diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c index 97d11c1d5f..7cc6a55c75 100644 --- a/src/qemu/qemu_command.c +++ b/src/qemu/qemu_command.c @@ -10463,7 +10463,7 @@ qemuBuildCommandLine(virQEMUDriverPtr driver, =20 /* In some situations, eg. VFIO passthrough, QEMU might need to lock a * significant amount of memory, so we need to set the limit according= ly */ - virCommandSetMaxMemLock(cmd, qemuDomainGetMemLockLimitBytes(def)); + virCommandSetMaxMemLock(cmd, qemuDomainGetMemLockLimitBytes(def, false= )); =20 if (virQEMUCapsGet(qemuCaps, QEMU_CAPS_MSG_TIMESTAMP) && cfg->logTimestamp) diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c index e81d986e9e..be4aef049d 100644 --- a/src/qemu/qemu_domain.c +++ b/src/qemu/qemu_domain.c @@ -11875,12 +11875,14 @@ ppc64VFIODeviceIsNV2Bridge(const char *device) /** * getPPC64MemLockLimitBytes: * @def: domain definition + * @forceVFIO: force VFIO usage * * A PPC64 helper that calculates the memory locking limit in order for * the guest to operate properly. */ static unsigned long long -getPPC64MemLockLimitBytes(virDomainDefPtr def) +getPPC64MemLockLimitBytes(virDomainDefPtr def, + bool forceVFIO) { unsigned long long memKB =3D 0; unsigned long long baseLimit =3D 0; @@ -11971,7 +11973,7 @@ getPPC64MemLockLimitBytes(virDomainDefPtr def) passthroughLimit =3D maxMemory + 128 * (1ULL<<30) / 512 * nPCIHostBridges + 8192; - } else if (usesVFIO) { + } else if (usesVFIO || forceVFIO) { /* For regular (non-NVLink2 present) VFIO passthrough, the value * of passthroughLimit is: * @@ -12009,16 +12011,20 @@ getPPC64MemLockLimitBytes(virDomainDefPtr def) /** * qemuDomainGetMemLockLimitBytes: * @def: domain definition + * @forceVFIO: force VFIO calculation * * Calculate the memory locking limit that needs to be set in order for * the guest to operate properly. The limit depends on a number of factors, * including certain configuration options and less immediately apparent o= nes * such as the guest architecture or the use of certain devices. + * The @forceVFIO argument can be used to tell this function will use VFIO= even + * though @def doesn't indicates so right now. * * Returns: the memory locking limit, or 0 if setting the limit is not nee= ded */ unsigned long long -qemuDomainGetMemLockLimitBytes(virDomainDefPtr def) +qemuDomainGetMemLockLimitBytes(virDomainDefPtr def, + bool forceVFIO) { unsigned long long memKB =3D 0; bool usesVFIO =3D false; @@ -12039,7 +12045,7 @@ qemuDomainGetMemLockLimitBytes(virDomainDefPtr def) return VIR_DOMAIN_MEMORY_PARAM_UNLIMITED; =20 if (ARCH_IS_PPC64(def->os.arch) && def->virtType =3D=3D VIR_DOMAIN_VIR= T_KVM) - return getPPC64MemLockLimitBytes(def); + return getPPC64MemLockLimitBytes(def, forceVFIO); =20 /* For device passthrough using VFIO the guest memory and MMIO memory * regions need to be locked persistent in order to allow DMA. @@ -12059,18 +12065,20 @@ qemuDomainGetMemLockLimitBytes(virDomainDefPtr de= f) * * Note that this may not be valid for all platforms. */ - for (i =3D 0; i < def->nhostdevs; i++) { - if (virHostdevIsVFIODevice(def->hostdevs[i]) || - virHostdevIsMdevDevice(def->hostdevs[i])) { - usesVFIO =3D true; - break; + if (!forceVFIO) { + for (i =3D 0; i < def->nhostdevs; i++) { + if (virHostdevIsVFIODevice(def->hostdevs[i]) || + virHostdevIsMdevDevice(def->hostdevs[i])) { + usesVFIO =3D true; + break; + } } - } =20 - if (virDomainDefHasNVMeDisk(def)) - usesVFIO =3D true; + if (virDomainDefHasNVMeDisk(def)) + usesVFIO =3D true; + } =20 - if (usesVFIO) + if (usesVFIO || forceVFIO) memKB =3D virDomainDefGetMemoryTotal(def) + 1024 * 1024; =20 done: @@ -12081,9 +12089,12 @@ qemuDomainGetMemLockLimitBytes(virDomainDefPtr def) /** * qemuDomainAdjustMaxMemLock: * @vm: domain + * @forceVFIO: apply VFIO requirements even if vm's def doesn't require it * * Adjust the memory locking limit for the QEMU process associated to @vm,= in - * order to comply with VFIO or architecture requirements. + * order to comply with VFIO or architecture requirements. If @forceVFIO is + * true then the limit is changed even if nothing in @vm's definition indi= cates + * so. * * The limit will not be changed unless doing so is needed; the first time * the limit is changed, the original (default) limit is stored in @vm and @@ -12093,12 +12104,13 @@ qemuDomainGetMemLockLimitBytes(virDomainDefPtr de= f) * Returns: 0 on success, <0 on failure */ int -qemuDomainAdjustMaxMemLock(virDomainObjPtr vm) +qemuDomainAdjustMaxMemLock(virDomainObjPtr vm, + bool forceVFIO) { unsigned long long bytes =3D 0; int ret =3D -1; =20 - bytes =3D qemuDomainGetMemLockLimitBytes(vm->def); + bytes =3D qemuDomainGetMemLockLimitBytes(vm->def, forceVFIO); =20 if (bytes) { /* If this is the first time adjusting the limit, save the current @@ -12147,7 +12159,7 @@ qemuDomainAdjustMaxMemLockHostdev(virDomainObjPtr v= m, int ret =3D 0; =20 vm->def->hostdevs[vm->def->nhostdevs++] =3D hostdev; - if (qemuDomainAdjustMaxMemLock(vm) < 0) + if (qemuDomainAdjustMaxMemLock(vm, false) < 0) ret =3D -1; =20 vm->def->hostdevs[--(vm->def->nhostdevs)] =3D NULL; diff --git a/src/qemu/qemu_domain.h b/src/qemu/qemu_domain.h index 65bd83aece..65d137462d 100644 --- a/src/qemu/qemu_domain.h +++ b/src/qemu/qemu_domain.h @@ -955,8 +955,10 @@ bool qemuDomainSupportsPCI(virDomainDefPtr def, =20 void qemuDomainUpdateCurrentMemorySize(virDomainObjPtr vm); =20 -unsigned long long qemuDomainGetMemLockLimitBytes(virDomainDefPtr def); -int qemuDomainAdjustMaxMemLock(virDomainObjPtr vm); +unsigned long long qemuDomainGetMemLockLimitBytes(virDomainDefPtr def, + bool forceVFIO); +int qemuDomainAdjustMaxMemLock(virDomainObjPtr vm, + bool forceVFIO); int qemuDomainAdjustMaxMemLockHostdev(virDomainObjPtr vm, virDomainHostdevDefPtr hostdev); =20 diff --git a/src/qemu/qemu_hotplug.c b/src/qemu/qemu_hotplug.c index 053523f8c5..61deaffdd9 100644 --- a/src/qemu/qemu_hotplug.c +++ b/src/qemu/qemu_hotplug.c @@ -1646,7 +1646,7 @@ qemuDomainAttachHostPCIDevice(virQEMUDriverPtr driver, if (teardowndevice && qemuDomainNamespaceTeardownHostdev(vm, hostdev) < 0) VIR_WARN("Unable to remove host device from /dev"); - if (teardownmemlock && qemuDomainAdjustMaxMemLock(vm) < 0) + if (teardownmemlock && qemuDomainAdjustMaxMemLock(vm, false) < 0) VIR_WARN("Unable to reset maximum locked memory on hotplug fail"); =20 if (releaseaddr) @@ -2383,7 +2383,7 @@ qemuDomainAttachMemory(virQEMUDriverPtr driver, if (virDomainMemoryInsert(vm->def, mem) < 0) goto cleanup; =20 - if (qemuDomainAdjustMaxMemLock(vm) < 0) + if (qemuDomainAdjustMaxMemLock(vm, false) < 0) goto removedef; =20 qemuDomainObjEnterMonitor(driver, vm); @@ -2454,7 +2454,7 @@ qemuDomainAttachMemory(virQEMUDriverPtr driver, =20 /* reset the mlock limit */ virErrorPreserveLast(&orig_err); - ignore_value(qemuDomainAdjustMaxMemLock(vm)); + ignore_value(qemuDomainAdjustMaxMemLock(vm, false)); virErrorRestore(&orig_err); =20 goto audit; @@ -2857,7 +2857,7 @@ qemuDomainAttachMediatedDevice(virQEMUDriverPtr drive= r, ret =3D 0; cleanup: if (ret < 0) { - if (teardownmemlock && qemuDomainAdjustMaxMemLock(vm) < 0) + if (teardownmemlock && qemuDomainAdjustMaxMemLock(vm, false) < 0) VIR_WARN("Unable to reset maximum locked memory on hotplug fai= l"); if (teardowncgroup && qemuTeardownHostdevCgroup(vm, hostdev) < 0) VIR_WARN("Unable to remove host device cgroup ACL on hotplug f= ail"); @@ -4356,7 +4356,7 @@ qemuDomainRemoveMemoryDevice(virQEMUDriverPtr driver, ignore_value(qemuProcessRefreshBalloonState(driver, vm, QEMU_ASYNC_JOB= _NONE)); =20 /* decrease the mlock limit after memory unplug if necessary */ - ignore_value(qemuDomainAdjustMaxMemLock(vm)); + ignore_value(qemuDomainAdjustMaxMemLock(vm, false)); =20 return 0; } @@ -4483,7 +4483,7 @@ qemuDomainRemoveHostDevice(virQEMUDriverPtr driver, qemuDomainRemovePCIHostDevice(driver, vm, hostdev); /* QEMU might no longer need to lock as much memory, eg. we just * detached the last VFIO device, so adjust the limit here */ - if (qemuDomainAdjustMaxMemLock(vm) < 0) + if (qemuDomainAdjustMaxMemLock(vm, false) < 0) VIR_WARN("Failed to adjust locked memory limit"); break; case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_USB: diff --git a/tests/qemumemlocktest.c b/tests/qemumemlocktest.c index ef3bfa0345..23a144a8ce 100644 --- a/tests/qemumemlocktest.c +++ b/tests/qemumemlocktest.c @@ -42,7 +42,7 @@ testCompareMemLock(const void *data) goto cleanup; } =20 - ret =3D virTestCompareToULL(info->memlock, qemuDomainGetMemLockLimitBy= tes(def)); + ret =3D virTestCompareToULL(info->memlock, qemuDomainGetMemLockLimitBy= tes(def, false)); =20 cleanup: virDomainDefFree(def); --=20 2.23.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Fri Apr 26 22:05:19 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 205.139.110.61 as permitted sender) client-ip=205.139.110.61; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-1.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 205.139.110.61 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=1575296958; cv=none; d=zohomail.com; s=zohoarc; b=JueOIBvx87eq/SttCeHSiZNXdWEv62obRkRb7L2UL8TPS9ow04zzgpdmDJPCqPIpA2x6B0SMve8jeK17tqruwt1It8aE10ylJDMAomcXwrHRPtRBURD/dDGbm0BFGLnkObCaqGddO4q0DMDNZBgasFfNnao090TIhgAgQPw9XOI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1575296958; 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; bh=3hgwyM5Q7ELWFdbQxzCaS/fThVHW/IXu4suMYsVjC/k=; b=aR96jKjOz9mTNb1JieMA90/M66g7mWfcLSauECWTxNwGwE2vQUkGfeCKPTdT4acQJjiaLAmIZDJr+d6mZehnsBUknheESP+K4HAfE3pBJrNhy68OaqPee947grdOeLq4zUqR3C5CfoePVrHhMpeOxT19csxn57MJ+KVK9hKsjYM= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 205.139.110.61 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from us-smtp-delivery-1.mimecast.com (us-smtp-2.mimecast.com [205.139.110.61]) by mx.zohomail.com with SMTPS id 157529695897980.08476240117352; Mon, 2 Dec 2019 06:29:18 -0800 (PST) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-415--Q1E2nI1NDGE6zPeje_RDg-1; Mon, 02 Dec 2019 09:27:49 -0500 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 mimecast-mx01.redhat.com (Postfix) with ESMTPS id AEEC785EE98; Mon, 2 Dec 2019 14:27:43 +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 827095D6BB; Mon, 2 Dec 2019 14:27: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 3DF655BC05; Mon, 2 Dec 2019 14:27:43 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id xB2ERSSU027577 for ; Mon, 2 Dec 2019 09:27:28 -0500 Received: by smtp.corp.redhat.com (Postfix) id 8CFA567662; Mon, 2 Dec 2019 14:27:28 +0000 (UTC) Received: from moe.redhat.com (unknown [10.43.2.30]) by smtp.corp.redhat.com (Postfix) with ESMTP id 1644BA4B86 for ; Mon, 2 Dec 2019 14:27:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1575296957; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=3hgwyM5Q7ELWFdbQxzCaS/fThVHW/IXu4suMYsVjC/k=; b=AhJKUID76CQg32YFkupOEhltTcDEfxx+gXekcqNarUflibznNXSCyMvJdk4gEVBA59enl0 xJaDqOXz9ET+UZQkKZ5aAt+Vb01se60hVvrQ9AOcpBBbl5WQpf/zVpPTGRc3Pez/GvgQJF 6Sx0BHolrTNAkzbbn6ZW1j8J8jJYzVA= From: Michal Privoznik To: libvir-list@redhat.com Date: Mon, 2 Dec 2019 15:26:52 +0100 Message-Id: <048c228494c47e8b64bcbb4e7ba11c6db6d7603d.1575296392.git.mprivozn@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v3 29/30] 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: , 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-MC-Unique: -Q1E2nI1NDGE6zPeje_RDg-1 X-Mimecast-Spam-Score: 0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" Signed-off-by: Michal Privoznik Reviewed-by: Cole Robinson --- src/qemu/qemu_domain.c | 58 +++++++++++++++++++++++++++++++++++++++++ src/qemu/qemu_hostdev.c | 22 ++++++++++++++++ src/qemu/qemu_hostdev.h | 6 +++++ 3 files changed, 86 insertions(+) diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c index be4aef049d..7d3a5d07d7 100644 --- a/src/qemu/qemu_domain.c +++ b/src/qemu/qemu_domain.c @@ -10570,6 +10570,54 @@ typedef enum { } qemuDomainStorageSourceAccessFlags; =20 =20 +static int +qemuDomainStorageSourceAccessModifyNVMe(virQEMUDriverPtr driver, + virDomainObjPtr vm, + virStorageSourcePtr src, + bool revoke) +{ + bool revoke_maxmemlock =3D false; + bool revoke_hostdev =3D false; + int ret =3D -1; + + if (!virStorageSourceChainHasNVMe(src)) + return 0; + + VIR_DEBUG("Modifying access for a NVMe disk src=3D%p revoke=3D%d", + src, revoke); + + if (revoke) { + revoke_maxmemlock =3D true; + revoke_hostdev =3D true; + ret =3D 0; + goto revoke; + } + + if (qemuDomainAdjustMaxMemLock(vm, true) < 0) + goto revoke; + + revoke_maxmemlock =3D true; + + if (qemuHostdevPrepareOneNVMeDisk(driver, vm->def->name, src) < 0) + goto revoke; + + revoke_hostdev =3D true; + + return 0; + + revoke: + if (revoke_maxmemlock) { + if (qemuDomainAdjustMaxMemLock(vm, false) < 0) + VIR_WARN("Unable to change max memlock limit"); + } + + if (revoke_hostdev) + qemuHostdevReAttachOneNVMeDisk(driver, vm->def->name, src); + + return ret; +} + + /** * qemuDomainStorageSourceAccessModify: * @driver: qemu driver struct @@ -10601,6 +10649,7 @@ qemuDomainStorageSourceAccessModify(virQEMUDriverPt= r driver, bool revoke_cgroup =3D false; bool revoke_label =3D false; bool revoke_namespace =3D false; + bool revoke_nvme =3D false; bool revoke_lockspace =3D false; =20 VIR_DEBUG("src=3D'%s' readonly=3D%d force_ro=3D%d force_rw=3D%d revoke= =3D%d chain=3D%d", @@ -10618,6 +10667,7 @@ qemuDomainStorageSourceAccessModify(virQEMUDriverPt= r driver, revoke_cgroup =3D true; revoke_label =3D true; revoke_namespace =3D true; + revoke_nvme =3D true; revoke_lockspace =3D true; ret =3D 0; goto revoke; @@ -10628,6 +10678,11 @@ qemuDomainStorageSourceAccessModify(virQEMUDriverP= tr driver, =20 revoke_lockspace =3D true; =20 + if (qemuDomainStorageSourceAccessModifyNVMe(driver, vm, src, false) < = 0) + goto revoke; + + revoke_nvme =3D true; + /* When modifying access of existing @src namespace does not need upda= te */ if (!(flags & QEMU_DOMAIN_STORAGE_SOURCE_ACCESS_MODIFY_ACCESS)) { if (qemuDomainNamespaceSetupDisk(vm, src) < 0) @@ -10678,6 +10733,9 @@ qemuDomainStorageSourceAccessModify(virQEMUDriverPt= r driver, VIR_WARN("Unable to remove /dev entry for %s", srcstr); } =20 + if (revoke_nvme) + qemuDomainStorageSourceAccessModifyNVMe(driver, vm, src, true); + if (revoke_lockspace) { if (virDomainLockImageDetach(driver->lockManager, vm, src) < 0) VIR_WARN("Unable to release lock on %s", srcstr); diff --git a/src/qemu/qemu_hostdev.c b/src/qemu/qemu_hostdev.c index 5ab0217858..6ab052724a 100644 --- a/src/qemu/qemu_hostdev.c +++ b/src/qemu/qemu_hostdev.c @@ -212,6 +212,17 @@ qemuHostdevPreparePCIDevicesCheckSupport(virDomainHost= devDefPtr *hostdevs, return true; } =20 +int +qemuHostdevPrepareOneNVMeDisk(virQEMUDriverPtr driver, + const char *name, + virStorageSourcePtr src) +{ + return virHostdevPrepareOneNVMeDevice(driver->hostdevMgr, + QEMU_DRIVER_NAME, + name, + src); +} + int qemuHostdevPrepareNVMeDisks(virQEMUDriverPtr driver, const char *name, @@ -369,6 +380,17 @@ qemuHostdevPrepareDomainDevices(virQEMUDriverPtr drive= r, return 0; } =20 +void +qemuHostdevReAttachOneNVMeDisk(virQEMUDriverPtr driver, + const char *name, + virStorageSourcePtr src) +{ + virHostdevReAttachOneNVMeDevice(driver->hostdevMgr, + QEMU_DRIVER_NAME, + name, + src); +} + void qemuHostdevReAttachNVMeDisks(virQEMUDriverPtr driver, const char *name, diff --git a/src/qemu/qemu_hostdev.h b/src/qemu/qemu_hostdev.h index 735414b6aa..23df925529 100644 --- a/src/qemu/qemu_hostdev.h +++ b/src/qemu/qemu_hostdev.h @@ -41,6 +41,9 @@ int qemuHostdevUpdateActiveSCSIDevices(virQEMUDriverPtr d= river, int qemuHostdevUpdateActiveDomainDevices(virQEMUDriverPtr driver, virDomainDefPtr def); =20 +int qemuHostdevPrepareOneNVMeDisk(virQEMUDriverPtr driver, + const char *name, + virStorageSourcePtr src); int qemuHostdevPrepareNVMeDisks(virQEMUDriverPtr driver, const char *name, virDomainDiskDefPtr *disks, @@ -74,6 +77,9 @@ int qemuHostdevPrepareDomainDevices(virQEMUDriverPtr driv= er, virQEMUCapsPtr qemuCaps, unsigned int flags); =20 +void qemuHostdevReAttachOneNVMeDisk(virQEMUDriverPtr driver, + const char *name, + virStorageSourcePtr src); void qemuHostdevReAttachNVMeDisks(virQEMUDriverPtr driver, const char *name, virDomainDiskDefPtr *disks, --=20 2.23.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Fri Apr 26 22:05:19 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 205.139.110.61 as permitted sender) client-ip=205.139.110.61; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-1.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 205.139.110.61 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=1575296902; cv=none; d=zohomail.com; s=zohoarc; b=nRMtHFJWwj5cf92+gFugAwmoNYkSLQqYkhdFqdOtbi32PXKHKha4GuBYq8Px+HdvVcOhliLF/jSK/SoBlfTDMt4X61i7AOG/Z2cgkQtJk6lrvOk0t/p2tsmpM6WZq9XISZX+W/jeOFplXFyVFh78RlVBwQGwgxluGxgWNDZ0sPk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1575296902; 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; bh=XQwRotm/ojY4mrsiwTLMv2zedt6LcVrQk2dza0anc9M=; b=bUtvfol01N5Huo5PZ703v2kWQsfS0gUkqrMKA/Lrkh78xo2f0S5SnsZ55kScO1K9QC/N1Nxg2kEwwuSyzzT3ge9m3wPlxLHRHTKRix4J1KcLLzeAJkP226a4py9ttgGMCxr2rVhVx4/QBjScf4GIeqsnn2pFlJEUKEnsA3gv1lY= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 205.139.110.61 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from us-smtp-delivery-1.mimecast.com (us-smtp-2.mimecast.com [205.139.110.61]) by mx.zohomail.com with SMTPS id 1575296902935654.2759881666526; Mon, 2 Dec 2019 06:28:22 -0800 (PST) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-158-HyZWI7GbMlaYYt0Z6s0zvQ-1; Mon, 02 Dec 2019 09:28:20 -0500 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 mimecast-mx01.redhat.com (Postfix) with ESMTPS id D667218B5FB3; Mon, 2 Dec 2019 14:28: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 A4C165DA75; Mon, 2 Dec 2019 14:28:13 +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 4D7885EC65; Mon, 2 Dec 2019 14:28:13 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id xB2ERUEp027595 for ; Mon, 2 Dec 2019 09:27:30 -0500 Received: by smtp.corp.redhat.com (Postfix) id DEF5FA4B86; Mon, 2 Dec 2019 14:27:30 +0000 (UTC) Received: from moe.redhat.com (unknown [10.43.2.30]) by smtp.corp.redhat.com (Postfix) with ESMTP id 680A06764D for ; Mon, 2 Dec 2019 14:27:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1575296901; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=XQwRotm/ojY4mrsiwTLMv2zedt6LcVrQk2dza0anc9M=; b=QdKMYHnbyIOwFa6oWO2kQ487kMY9jAvzo71HeRY8BwiJj5ME/sOwz8G6PBy3BrzXvlv95f lC+naKXb1qaHxDaCc6P/9I37atFnawpCbHNaESPHseJOkMmZvBUHp3U4O3EQe8m/NcwPdw jq/pf4cR9hB75FEfgfYJW+9Pw4UTXWA= From: Michal Privoznik To: libvir-list@redhat.com Date: Mon, 2 Dec 2019 15:26:53 +0100 Message-Id: <599a469c686945e4f0c8e390c761319009659c43.1575296392.git.mprivozn@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v3 30/30] virsh: Introduce nvme disk to domblklist X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , 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-MC-Unique: HyZWI7GbMlaYYt0Z6s0zvQ-1 X-Mimecast-Spam-Score: 0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" This is slightly more complicated because NVMe disk source is not a simple attribute to element. The format in which the PCI address and namespace ID are printed is the same as QEMU accepts them: nvme://XXXX:XX:XX.X/X Signed-off-by: Michal Privoznik Reviewed-by: Cole Robinson --- tools/virsh-domain-monitor.c | 31 +++++++++++++++++++++++++------ 1 file changed, 25 insertions(+), 6 deletions(-) diff --git a/tools/virsh-domain-monitor.c b/tools/virsh-domain-monitor.c index c2f157ad6b..30b186ffd1 100644 --- a/tools/virsh-domain-monitor.c +++ b/tools/virsh-domain-monitor.c @@ -631,8 +631,8 @@ cmdDomblklist(vshControl *ctl, const vshCmd *cmd) for (i =3D 0; i < ndisks; i++) { ctxt->node =3D disks[i]; =20 + type =3D virXPathString("string(./@type)", ctxt); if (details) { - type =3D virXPathString("string(./@type)", ctxt); device =3D virXPathString("string(./@device)", ctxt); if (!type || !device) { vshPrint(ctl, "unable to query block list details"); @@ -645,11 +645,30 @@ cmdDomblklist(vshControl *ctl, const vshCmd *cmd) vshError(ctl, "unable to query block list"); goto cleanup; } - source =3D virXPathString("string(./source/@file" - "|./source/@dev" - "|./source/@dir" - "|./source/@name" - "|./source/@volume)", ctxt); + + if (STREQ_NULLABLE(type, "nvme")) { + g_autofree char *namespace =3D NULL; + virPCIDeviceAddress addr =3D { 0 }; + xmlNodePtr addrNode =3D NULL; + + if (!(namespace =3D virXPathString("string(./source/@namespace= )", ctxt)) || + !(addrNode =3D virXPathNode("./source/address", ctxt)) || + virPCIDeviceAddressParseXML(addrNode, &addr) < 0) { + vshError(ctl, "Unable to query NVMe disk address"); + goto cleanup; + } + + source =3D g_strdup_printf("nvme://%04x:%02x:%02x.%d/%s", + addr.domain, addr.bus, addr.slot, + addr.function, namespace); + } else { + source =3D virXPathString("string(./source/@file" + "|./source/@dev" + "|./source/@dir" + "|./source/@name" + "|./source/@volume)", ctxt); + } + if (details) { if (vshTableRowAppend(table, type, device, target, NULLSTR_MINUS(source), NULL) < 0) --=20 2.23.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list