From nobody Mon Feb 9 10:25:52 2026 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=1583864024; cv=none; d=zohomail.com; s=zohoarc; b=BgtO9ZlY/l+UPrFknTmUGFE2baxDpqM1PuAIzYRHpndWg5OhcFZMtZayeup0hGnFr6LjsLw6qIvBe23rC7+Wpfeysoi5orkgEHMKCGGMqUtXo2auq9ORtQkzm4CcpHstlKCRay4qg0GjL2YsQ8iee6T1DQx+TcsFLURjE4YTvpI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1583864024; 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=wah911ldKRZ3M0pUyM2hTz8zIcr9KVlOlHOncV/FvjQ=; b=f4cb3bP6aG/bS59Mztwvf6j7VxbLgrj1ZKaHm6DO/dTaycJkGJR3drfCX+6UorHKc1y2DB7HezXVxuyHBEbaEApCHAZncfIpHVko7TJ3krKQyxWcTuN2zJDSzq8+CGbD6bp3ni/jxqrSwY80frGOCMKwcnAROFxRzYEJcAg/ESE= 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 1583864024962461.437967715381; Tue, 10 Mar 2020 11:13:44 -0700 (PDT) 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-282-NK5daSOXNBe7Q4E8NF1WMA-1; Tue, 10 Mar 2020 14:13:40 -0400 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 DA4A6DB2E; Tue, 10 Mar 2020 18:13:34 +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 A84C68F354; Tue, 10 Mar 2020 18:13:34 +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 5011B18089CD; Tue, 10 Mar 2020 18:13:34 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 02AIDOjL010510 for ; Tue, 10 Mar 2020 14:13:24 -0400 Received: by smtp.corp.redhat.com (Postfix) id 4718E7388D; Tue, 10 Mar 2020 18:13:24 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-112-62.ams2.redhat.com [10.36.112.62]) by smtp.corp.redhat.com (Postfix) with ESMTP id 73E6B5C13D; Tue, 10 Mar 2020 18:13:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1583864022; 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=wah911ldKRZ3M0pUyM2hTz8zIcr9KVlOlHOncV/FvjQ=; b=LdycVnumNhVG7xh+vrVAY0WOGvHfioe+yTrTrF6b1Ga53mitAi8KCGsbaeBeSOIwRNWN9f 1P5+sE+1KgZBBRO36BDLrEz1/GO2SbNbxnCk++elYIbnwQoPLlZRiTR8oo09yzVd/r0BJ/ KHBHX8JQ6RczJkJ/qGrOqWW7WxGi5Uc= X-MC-Unique: NK5daSOXNBe7Q4E8NF1WMA-1 From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: libvir-list@redhat.com Subject: [libvirt PATCH 3/3] qemu: lookup node device against nodedev driver before getting XML Date: Tue, 10 Mar 2020 18:13:14 +0000 Message-Id: <20200310181314.3613846-4-berrange@redhat.com> In-Reply-To: <20200310181314.3613846-1-berrange@redhat.com> References: <20200310181314.3613846-1-berrange@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-loop: libvir-list@redhat.com 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-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" Some of the node device APIs are a little odd because they accept a virNodeDevicePtr object but are still implemented by the virt drivers. The first thing the virt drivers need to do is get the XML config associated with the node device, and that means talking to the node device driver. This worked previously because with monolithic libvirtd, both the virt driver and node device driver were in the same daemon and thus a single virConnectPtr can talk to both drivers. With the split daemon world though, the virNodeDevicePtr passed into the APIs is associated with the QEMU driver virConnectPtr, which has no ability to invoke APIs against the node device driver. We must thus get a duplicate virNodeDevicePtr object which is associated with a virConnectPtr for the node device driver. Signed-off-by: Daniel P. Berrang=C3=A9 --- src/libxl/libxl_driver.c | 63 ++++++++++++++++++++++++++++++++++++++-- src/qemu/qemu_driver.c | 63 ++++++++++++++++++++++++++++++++++++++-- 2 files changed, 120 insertions(+), 6 deletions(-) diff --git a/src/libxl/libxl_driver.c b/src/libxl/libxl_driver.c index f2387e2a20..eca45da097 100644 --- a/src/libxl/libxl_driver.c +++ b/src/libxl/libxl_driver.c @@ -5787,10 +5787,23 @@ libxlNodeDeviceDetachFlags(virNodeDevicePtr dev, char *xml =3D NULL; libxlDriverPrivatePtr driver =3D dev->conn->privateData; virHostdevManagerPtr hostdev_mgr =3D driver->hostdevMgr; + virConnectPtr nodeconn =3D NULL; + virNodeDevicePtr nodedev =3D NULL; =20 virCheckFlags(0, -1); =20 - xml =3D virNodeDeviceGetXMLDesc(dev, 0); + if (!(nodeconn =3D virGetConnectNodeDev())) + goto cleanup; + + /* 'dev' is associated with the QEMU virConnectPtr, + * so for split daemons, we need to get a copy that + * is associated with the virnodedevd daemon. + */ + if (!(nodedev =3D virNodeDeviceLookupByName( + nodeconn, virNodeDeviceGetName(dev)))) + goto cleanup; + + xml =3D virNodeDeviceGetXMLDesc(nodedev, 0); if (!xml) goto cleanup; =20 @@ -5798,6 +5811,8 @@ libxlNodeDeviceDetachFlags(virNodeDevicePtr dev, if (!def) goto cleanup; =20 + /* ACL check must happen against original 'dev', + * not the new 'nodedev' we acquired */ if (virNodeDeviceDetachFlagsEnsureACL(dev->conn, def) < 0) goto cleanup; =20 @@ -5823,6 +5838,10 @@ libxlNodeDeviceDetachFlags(virNodeDevicePtr dev, cleanup: virPCIDeviceFree(pci); virNodeDeviceDefFree(def); + if (nodedev) + virNodeDeviceFree(nodedev); + if (nodeconn) + virConnectClose(nodeconn); VIR_FREE(xml); return ret; } @@ -5843,8 +5862,21 @@ libxlNodeDeviceReAttach(virNodeDevicePtr dev) char *xml =3D NULL; libxlDriverPrivatePtr driver =3D dev->conn->privateData; virHostdevManagerPtr hostdev_mgr =3D driver->hostdevMgr; + virConnectPtr nodeconn =3D NULL; + virNodeDevicePtr nodedev =3D NULL; + + if (!(nodeconn =3D virGetConnectNodeDev())) + goto cleanup; =20 - xml =3D virNodeDeviceGetXMLDesc(dev, 0); + /* 'dev' is associated with the QEMU virConnectPtr, + * so for split daemons, we need to get a copy that + * is associated with the virnodedevd daemon. + */ + if (!(nodedev =3D virNodeDeviceLookupByName( + nodeconn, virNodeDeviceGetName(dev)))) + goto cleanup; + + xml =3D virNodeDeviceGetXMLDesc(nodedev, 0); if (!xml) goto cleanup; =20 @@ -5852,6 +5884,8 @@ libxlNodeDeviceReAttach(virNodeDevicePtr dev) if (!def) goto cleanup; =20 + /* ACL check must happen against original 'dev', + * not the new 'nodedev' we acquired */ if (virNodeDeviceReAttachEnsureACL(dev->conn, def) < 0) goto cleanup; =20 @@ -5870,6 +5904,10 @@ libxlNodeDeviceReAttach(virNodeDevicePtr dev) cleanup: virPCIDeviceFree(pci); virNodeDeviceDefFree(def); + if (nodedev) + virNodeDeviceFree(nodedev); + if (nodeconn) + virConnectClose(nodeconn); VIR_FREE(xml); return ret; } @@ -5884,8 +5922,21 @@ libxlNodeDeviceReset(virNodeDevicePtr dev) char *xml =3D NULL; libxlDriverPrivatePtr driver =3D dev->conn->privateData; virHostdevManagerPtr hostdev_mgr =3D driver->hostdevMgr; + virConnectPtr nodeconn =3D NULL; + virNodeDevicePtr nodedev =3D NULL; + + if (!(nodeconn =3D virGetConnectNodeDev())) + goto cleanup; + + /* 'dev' is associated with the QEMU virConnectPtr, + * so for split daemons, we need to get a copy that + * is associated with the virnodedevd daemon. + */ + if (!(nodedev =3D virNodeDeviceLookupByName( + nodeconn, virNodeDeviceGetName(dev)))) + goto cleanup; =20 - xml =3D virNodeDeviceGetXMLDesc(dev, 0); + xml =3D virNodeDeviceGetXMLDesc(nodedev, 0); if (!xml) goto cleanup; =20 @@ -5893,6 +5944,8 @@ libxlNodeDeviceReset(virNodeDevicePtr dev) if (!def) goto cleanup; =20 + /* ACL check must happen against original 'dev', + * not the new 'nodedev' we acquired */ if (virNodeDeviceResetEnsureACL(dev->conn, def) < 0) goto cleanup; =20 @@ -5911,6 +5964,10 @@ libxlNodeDeviceReset(virNodeDevicePtr dev) cleanup: virPCIDeviceFree(pci); virNodeDeviceDefFree(def); + if (nodedev) + virNodeDeviceFree(nodedev); + if (nodeconn) + virConnectClose(nodeconn); VIR_FREE(xml); return ret; } diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index cd761f87b5..d8f264ba7f 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -12965,10 +12965,23 @@ qemuNodeDeviceDetachFlags(virNodeDevicePtr dev, g_autofree char *xml =3D NULL; bool vfio =3D qemuHostdevHostSupportsPassthroughVFIO(); virHostdevManagerPtr hostdev_mgr =3D driver->hostdevMgr; + virConnectPtr nodeconn =3D NULL; + virNodeDevicePtr nodedev =3D NULL; =20 virCheckFlags(0, -1); =20 - xml =3D virNodeDeviceGetXMLDesc(dev, 0); + if (!(nodeconn =3D virGetConnectNodeDev())) + goto cleanup; + + /* 'dev' is associated with the QEMU virConnectPtr, + * so for split daemons, we need to get a copy that + * is associated with the virnodedevd daemon. + */ + if (!(nodedev =3D virNodeDeviceLookupByName( + nodeconn, virNodeDeviceGetName(dev)))) + goto cleanup; + + xml =3D virNodeDeviceGetXMLDesc(nodedev, 0); if (!xml) goto cleanup; =20 @@ -12976,6 +12989,8 @@ qemuNodeDeviceDetachFlags(virNodeDevicePtr dev, if (!def) goto cleanup; =20 + /* ACL check must happen against original 'dev', + * not the new 'nodedev' we acquired */ if (virNodeDeviceDetachFlagsEnsureACL(dev->conn, def) < 0) goto cleanup; =20 @@ -13012,6 +13027,10 @@ qemuNodeDeviceDetachFlags(virNodeDevicePtr dev, cleanup: virPCIDeviceFree(pci); virNodeDeviceDefFree(def); + if (nodedev) + virNodeDeviceFree(nodedev); + if (nodeconn) + virConnectClose(nodeconn); return ret; } =20 @@ -13031,8 +13050,21 @@ qemuNodeDeviceReAttach(virNodeDevicePtr dev) virNodeDeviceDefPtr def =3D NULL; g_autofree char *xml =3D NULL; virHostdevManagerPtr hostdev_mgr =3D driver->hostdevMgr; + virConnectPtr nodeconn =3D NULL; + virNodeDevicePtr nodedev =3D NULL; + + if (!(nodeconn =3D virGetConnectNodeDev())) + goto cleanup; =20 - xml =3D virNodeDeviceGetXMLDesc(dev, 0); + /* 'dev' is associated with the QEMU virConnectPtr, + * so for split daemons, we need to get a copy that + * is associated with the virnodedevd daemon. + */ + if (!(nodedev =3D virNodeDeviceLookupByName( + nodeconn, virNodeDeviceGetName(dev)))) + goto cleanup; + + xml =3D virNodeDeviceGetXMLDesc(nodedev, 0); if (!xml) goto cleanup; =20 @@ -13040,6 +13072,8 @@ qemuNodeDeviceReAttach(virNodeDevicePtr dev) if (!def) goto cleanup; =20 + /* ACL check must happen against original 'dev', + * not the new 'nodedev' we acquired */ if (virNodeDeviceReAttachEnsureACL(dev->conn, def) < 0) goto cleanup; =20 @@ -13055,6 +13089,10 @@ qemuNodeDeviceReAttach(virNodeDevicePtr dev) virPCIDeviceFree(pci); cleanup: virNodeDeviceDefFree(def); + if (nodedev) + virNodeDeviceFree(nodedev); + if (nodeconn) + virConnectClose(nodeconn); return ret; } =20 @@ -13068,8 +13106,21 @@ qemuNodeDeviceReset(virNodeDevicePtr dev) virNodeDeviceDefPtr def =3D NULL; g_autofree char *xml =3D NULL; virHostdevManagerPtr hostdev_mgr =3D driver->hostdevMgr; + virConnectPtr nodeconn =3D NULL; + virNodeDevicePtr nodedev =3D NULL; + + if (!(nodeconn =3D virGetConnectNodeDev())) + goto cleanup; + + /* 'dev' is associated with the QEMU virConnectPtr, + * so for split daemons, we need to get a copy that + * is associated with the virnodedevd daemon. + */ + if (!(nodedev =3D virNodeDeviceLookupByName( + nodeconn, virNodeDeviceGetName(dev)))) + goto cleanup; =20 - xml =3D virNodeDeviceGetXMLDesc(dev, 0); + xml =3D virNodeDeviceGetXMLDesc(nodedev, 0); if (!xml) goto cleanup; =20 @@ -13077,6 +13128,8 @@ qemuNodeDeviceReset(virNodeDevicePtr dev) if (!def) goto cleanup; =20 + /* ACL check must happen against original 'dev', + * not the new 'nodedev' we acquired */ if (virNodeDeviceResetEnsureACL(dev->conn, def) < 0) goto cleanup; =20 @@ -13092,6 +13145,10 @@ qemuNodeDeviceReset(virNodeDevicePtr dev) virPCIDeviceFree(pci); cleanup: virNodeDeviceDefFree(def); + if (nodedev) + virNodeDeviceFree(nodedev); + if (nodeconn) + virConnectClose(nodeconn); return ret; } =20 --=20 2.24.1