From nobody Sun Feb 8 12:37:51 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) client-ip=216.205.24.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=fail(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1612314418; cv=none; d=zohomail.com; s=zohoarc; b=L/aRuXTh/RyHFrU82v8E50O69ejHeIWRpsPqL3rYNvP+Nc2FYdaGwV1IxwtLy0xrzFyh5LcBYNVfxbSG8elHSC4DjKznP1yiMB7yIu2lKtmAD+scfS8DnqW1tygNJsrdEV8laWAbg10nVz4CBWtuHEhZhbs9zsqIvsA7fqM7lRo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1612314418; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=bNmNanOwTQVyhBhSkWLs83A6Zolndm4ggCWWX+yJtLo=; b=ddXi1vf6n3OYTEv1eDEiOro4K2nUjD1C5mYwenMXU/+Dv4Ip7cxUbKNI0yJ/3J4lJiE8hR6MfHkE3BMn54tVfabg5MQW48foqRJfJG4lYbGpsPsUYHXDFJ4bc3jLVzxhjO4GeB23bXw5KlVsN5FP7VOv76QtCGBfwSR5wtchbl0= ARC-Authentication-Results: i=1; mx.zohomail.com; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by mx.zohomail.com with SMTPS id 1612314418902288.9697140061737; Tue, 2 Feb 2021 17:06:58 -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-191-tWdURez8P3eWbPayw-MNaQ-1; Tue, 02 Feb 2021 20:06:55 -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 C395A8030B6; Wed, 3 Feb 2021 01:06:49 +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 7E47D7EA95; Wed, 3 Feb 2021 01:06:49 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 771B318095CB; Wed, 3 Feb 2021 01:06:46 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 11316jhM010300 for ; Tue, 2 Feb 2021 20:06:45 -0500 Received: by smtp.corp.redhat.com (Postfix) id 105C92166B2A; Wed, 3 Feb 2021 01:06:45 +0000 (UTC) Received: from mimecast-mx02.redhat.com (mimecast05.extmail.prod.ext.rdu2.redhat.com [10.11.55.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 0A40E2166B27 for ; Wed, 3 Feb 2021 01:06:43 +0000 (UTC) Received: from us-smtp-1.mimecast.com (us-smtp-2.mimecast.com [207.211.31.81]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id DFD87800969 for ; Wed, 3 Feb 2021 01:06:42 +0000 (UTC) Received: from mail-qt1-f179.google.com (mail-qt1-f179.google.com [209.85.160.179]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-337-TtH0Rj6EMFujotWSIcx4EA-1; Tue, 02 Feb 2021 20:06:38 -0500 Received: by mail-qt1-f179.google.com with SMTP id v3so16490398qtw.4; Tue, 02 Feb 2021 17:06:38 -0800 (PST) Received: from rekt.ibmuc.com ([2804:431:c7c6:6df1:6267:881f:cc79:a1f7]) by smtp.gmail.com with ESMTPSA id g6sm328813qtr.87.2021.02.02.17.06.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 02 Feb 2021 17:06:37 -0800 (PST) X-MC-Unique: tWdURez8P3eWbPayw-MNaQ-1 X-MC-Unique: TtH0Rj6EMFujotWSIcx4EA-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=bNmNanOwTQVyhBhSkWLs83A6Zolndm4ggCWWX+yJtLo=; b=RsSZDMdUieVDTxmDZpLvkfog/9kGfH9KEzxCHYTFDOTJ9Ci8MiQ24wskXO0W3NqXZd ny+S6kLNpdB9jfxAHbXoHhAIQSJt36Ow64rTDLRAnFvm2MzXzWOQGkB86EFTQRhh50mc ZP6asBdqs9e7LMXpJMzRkOZ+vUvxz8IgLhKsNbAnjpOsWh+NwXA5K9cGmjIscwYQXd4t z+4MuPb2X0v+Xxe05ptCwQWLYuDxWRUyk+eUsZy/2s2U2QhiskqU9FkX4rJhTXsp+9tp am/mXhsxIvzfzi3iNMAtRUG5MSWZz08FwYBsNlUWXjSVi4L5ViwZEmbXe1Zc8uPHHqsk mYQA== X-Gm-Message-State: AOAM53195kZ4QVRDewlWoHyNr7/RraUMyf1t+sl0UBv58FpztZF3nrlL 62RR1jeaLlcP3l+pjsKf/rlGOOphm7k= X-Google-Smtp-Source: ABdhPJx+BMDHErQrmu4ww+yUYuVcANrK8pcIVKctaE6H+MMCBEgGdgY9fZ/9mEqKUpIvMC7fqCuD0g== X-Received: by 2002:ac8:6f07:: with SMTP id g7mr581709qtv.54.1612314397993; Tue, 02 Feb 2021 17:06:37 -0800 (PST) From: Daniel Henrique Barboza To: libvir-list@redhat.com Subject: [PATCH v2 01/10] qemu, libxl, hypervisor: use virDomainDriverNodeDeviceReset() helper Date: Tue, 2 Feb 2021 22:06:16 -0300 Message-Id: <20210203010625.2328911-2-danielhb413@gmail.com> In-Reply-To: <20210203010625.2328911-1-danielhb413@gmail.com> References: <20210203010625.2328911-1-danielhb413@gmail.com> MIME-Version: 1.0 X-Mimecast-Impersonation-Protect: Policy=CLT - Impersonation Protection Definition; Similar Internal Domain=false; Similar Monitored External Domain=false; Custom External Domain=false; Mimecast External Domain=false; Newly Observed Domain=false; Internal User Name=false; Custom Display Name List=false; Reply-to Address Mismatch=false; Targeted Threat Dictionary=false; Mimecast Threat Dictionary=false; Custom Threat Dictionary=false X-Scanned-By: MIMEDefang 2.78 on 10.11.54.6 X-loop: libvir-list@redhat.com Cc: Daniel Henrique Barboza , =?UTF-8?q?J=C3=A1n=20Tomko?= 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 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable libxlNodeDeviceReset() and qemuNodeDeviceReset() are mostly equal, differing only how the virHostdevManager pointer is retrieved. Put the common code into virDomainDriverNodeDeviceReset() to reduce code duplication. Reviewed-by: J=C3=A1n Tomko Signed-off-by: Daniel Henrique Barboza --- src/hypervisor/domain_driver.c | 58 ++++++++++++++++++++++++++++++++++ src/hypervisor/domain_driver.h | 4 +++ src/hypervisor/meson.build | 1 + src/libvirt_private.syms | 1 + src/libxl/libxl_driver.c | 53 ++----------------------------- src/qemu/qemu_driver.c | 49 ++-------------------------- 6 files changed, 70 insertions(+), 96 deletions(-) diff --git a/src/hypervisor/domain_driver.c b/src/hypervisor/domain_driver.c index 5b03f79833..0c86fd714f 100644 --- a/src/hypervisor/domain_driver.c +++ b/src/hypervisor/domain_driver.c @@ -25,6 +25,10 @@ #include "virstring.h" #include "vircrypto.h" #include "virutil.h" +#include "virhostdev.h" +#include "viraccessapicheck.h" +#include "datatypes.h" +#include "driver.h" =20 #define VIR_FROM_THIS VIR_FROM_DOMAIN =20 @@ -365,3 +369,57 @@ virDomainDriverNodeDeviceGetPCIInfo(virNodeDeviceDefPt= r def, =20 return 0; } + + +int +virDomainDriverNodeDeviceReset(virNodeDevicePtr dev, + virHostdevManagerPtr hostdevMgr) +{ + virPCIDevicePtr pci; + virPCIDeviceAddress devAddr; + virNodeDeviceDefPtr def =3D NULL; + g_autofree char *xml =3D NULL; + virConnectPtr nodeconn =3D NULL; + virNodeDevicePtr nodedev =3D NULL; + int ret =3D -1; + + if (!(nodeconn =3D virGetConnectNodeDev())) + goto cleanup; + + /* 'dev' is associated with 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; + + def =3D virNodeDeviceDefParseString(xml, EXISTING_DEVICE, NULL); + if (!def) + goto cleanup; + + /* ACL check must happen against original 'dev', + * not the new 'nodedev' we acquired */ + if (virNodeDeviceResetEnsureACL(dev->conn, def) < 0) + goto cleanup; + + if (virDomainDriverNodeDeviceGetPCIInfo(def, &devAddr) < 0) + goto cleanup; + + pci =3D virPCIDeviceNew(&devAddr); + if (!pci) + goto cleanup; + + ret =3D virHostdevPCINodeDeviceReset(hostdevMgr, pci); + + virPCIDeviceFree(pci); + cleanup: + virNodeDeviceDefFree(def); + virObjectUnref(nodedev); + virObjectUnref(nodeconn); + return ret; + +} diff --git a/src/hypervisor/domain_driver.h b/src/hypervisor/domain_driver.h index 86b92d0284..b690844fe5 100644 --- a/src/hypervisor/domain_driver.h +++ b/src/hypervisor/domain_driver.h @@ -22,6 +22,7 @@ =20 #include "domain_conf.h" #include "node_device_conf.h" +#include "virhostdev.h" =20 char * virDomainDriverGenerateRootHash(const char *drivername, @@ -49,3 +50,6 @@ int virDomainDriverSetupPersistentDefBlkioParams(virDomai= nDefPtr persistentDef, =20 int virDomainDriverNodeDeviceGetPCIInfo(virNodeDeviceDefPtr def, virPCIDeviceAddressPtr devAddr); + +int virDomainDriverNodeDeviceReset(virNodeDevicePtr dev, + virHostdevManagerPtr hostdevMgr); diff --git a/src/hypervisor/meson.build b/src/hypervisor/meson.build index 85149c683e..32d5ab365f 100644 --- a/src/hypervisor/meson.build +++ b/src/hypervisor/meson.build @@ -11,6 +11,7 @@ hypervisor_lib =3D static_library( hypervisor_sources, ], dependencies: [ + access_dep, src_dep, ], include_directories: [ diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index 8138780237..1f6048e3f7 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -1504,6 +1504,7 @@ virDomainDriverGenerateMachineName; virDomainDriverGenerateRootHash; virDomainDriverMergeBlkioDevice; virDomainDriverNodeDeviceGetPCIInfo; +virDomainDriverNodeDeviceReset; virDomainDriverParseBlkioDeviceStr; virDomainDriverSetupPersistentDefBlkioParams; =20 diff --git a/src/libxl/libxl_driver.c b/src/libxl/libxl_driver.c index f480f8067e..814a6c282c 100644 --- a/src/libxl/libxl_driver.c +++ b/src/libxl/libxl_driver.c @@ -5910,59 +5910,12 @@ libxlNodeDeviceReAttach(virNodeDevicePtr dev) static int libxlNodeDeviceReset(virNodeDevicePtr dev) { - virPCIDevicePtr pci =3D NULL; - virPCIDeviceAddress devAddr; - int ret =3D -1; - virNodeDeviceDefPtr def =3D NULL; - 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; - - xml =3D virNodeDeviceGetXMLDesc(nodedev, 0); - if (!xml) - goto cleanup; - - def =3D virNodeDeviceDefParseString(xml, EXISTING_DEVICE, NULL); - if (!def) - goto cleanup; - - /* ACL check must happen against original 'dev', - * not the new 'nodedev' we acquired */ - if (virNodeDeviceResetEnsureACL(dev->conn, def) < 0) - goto cleanup; - - if (virDomainDriverNodeDeviceGetPCIInfo(def, &devAddr) < 0) - goto cleanup; - - pci =3D virPCIDeviceNew(&devAddr); - if (!pci) - goto cleanup; - - if (virHostdevPCINodeDeviceReset(hostdev_mgr, pci) < 0) - goto cleanup; =20 - ret =3D 0; - - cleanup: - virPCIDeviceFree(pci); - virNodeDeviceDefFree(def); - virObjectUnref(nodedev); - virObjectUnref(nodeconn); - VIR_FREE(xml); - return ret; + /* virNodeDeviceResetEnsureACL() is being called by + * virDomainDriverNodeDeviceReset() */ + return virDomainDriverNodeDeviceReset(dev, hostdev_mgr); } =20 static char * diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index ed840a5c8d..8270a26c0b 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -12108,54 +12108,11 @@ static int qemuNodeDeviceReset(virNodeDevicePtr dev) { virQEMUDriverPtr driver =3D dev->conn->privateData; - virPCIDevicePtr pci; - virPCIDeviceAddress devAddr; - int ret =3D -1; - 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(nodedev, 0); - if (!xml) - goto cleanup; - - def =3D virNodeDeviceDefParseString(xml, EXISTING_DEVICE, NULL); - if (!def) - goto cleanup; - - /* ACL check must happen against original 'dev', - * not the new 'nodedev' we acquired */ - if (virNodeDeviceResetEnsureACL(dev->conn, def) < 0) - goto cleanup; - - if (virDomainDriverNodeDeviceGetPCIInfo(def, &devAddr) < 0) - goto cleanup; - - pci =3D virPCIDeviceNew(&devAddr); - if (!pci) - goto cleanup; - - ret =3D virHostdevPCINodeDeviceReset(hostdev_mgr, pci); - - virPCIDeviceFree(pci); - cleanup: - virNodeDeviceDefFree(def); - virObjectUnref(nodedev); - virObjectUnref(nodeconn); - return ret; + /* virNodeDeviceResetEnsureACL() is being called by + * virDomainDriverNodeDeviceReset() */ + return virDomainDriverNodeDeviceReset(dev, hostdev_mgr); } =20 static int --=20 2.26.2