From nobody Sun May 5 19:55:54 2024 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 From nobody Sun May 5 19:55:54 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 63.128.21.124 as permitted sender) client-ip=63.128.21.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 63.128.21.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=1612314436; cv=none; d=zohomail.com; s=zohoarc; b=kyMpfAa1xfjjOTrwiAmthRiQx3PRpKdu48eD/8RKU8awf6RzQIms0lMyPA3o8gckU3bESGAfkxDDxRjf8arfNqn3lONe+s96mtPrSbSGNHqbZb1JC4b24lJbCdnZSZdVVujHSzGcTjn4j2pHtph+xBwXoDFFfuHuYHZlCxBwJbs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1612314436; 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=5YQQYkKhVM2X8ZlGnbF+axCYGT8WD0VnNMRd/NxzvPE=; b=YqrqGX/qzMZUpQF3Pl+ZipQMuTgmag6YsEfQkU9Mj5kPH7CXAxT8iI4dkChdV0gg4QJotWW6Xe0MlLvT+CXzQSuR4+34ZXUyD6RrmAzm1cRdE+frrbkWwLD38Nw7j1GQGtY/lyBKoLEqWnMnKWT20TPy7a6PxnL5TcYaFCpFpXg= ARC-Authentication-Results: i=1; mx.zohomail.com; spf=pass (zohomail.com: domain of redhat.com designates 63.128.21.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 [63.128.21.124]) by mx.zohomail.com with SMTPS id 1612314436050799.7133842186438; Tue, 2 Feb 2021 17:07:16 -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-442-25w43riSMYi1zXvNJ8aROw-1; Tue, 02 Feb 2021 20:07:13 -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 940B7189DF4E; Wed, 3 Feb 2021 01:07:07 +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 6FBB75D9E3; Wed, 3 Feb 2021 01:07:07 +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 385F35003F; Wed, 3 Feb 2021 01:07:07 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 11316lM9010328 for ; Tue, 2 Feb 2021 20:06:47 -0500 Received: by smtp.corp.redhat.com (Postfix) id 9D35F11422DA; Wed, 3 Feb 2021 01:06:47 +0000 (UTC) Received: from mimecast-mx02.redhat.com (mimecast02.extmail.prod.ext.rdu2.redhat.com [10.11.55.18]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 97F0D1004C64 for ; Wed, 3 Feb 2021 01:06:44 +0000 (UTC) Received: from us-smtp-1.mimecast.com (us-smtp-1.mimecast.com [205.139.110.61]) (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 373C682DFE0 for ; Wed, 3 Feb 2021 01:06:44 +0000 (UTC) Received: from mail-qk1-f171.google.com (mail-qk1-f171.google.com [209.85.222.171]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-274-IXY8OouuPy-7b2ynJIgm_w-1; Tue, 02 Feb 2021 20:06:40 -0500 Received: by mail-qk1-f171.google.com with SMTP id r77so21863614qka.12; Tue, 02 Feb 2021 17:06:40 -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.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 02 Feb 2021 17:06:39 -0800 (PST) X-MC-Unique: 25w43riSMYi1zXvNJ8aROw-1 X-MC-Unique: IXY8OouuPy-7b2ynJIgm_w-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=5YQQYkKhVM2X8ZlGnbF+axCYGT8WD0VnNMRd/NxzvPE=; b=JrXNtlm+gMz/FFuoSuCz0Jh5tLg3GAB7tGASswRycAC34b757nsjmfIDqqz9SJUBnA D4bACnp4cSZj7dTIo6TLpox0fDvo3wa8a8Nxjg2lNvBbupD9OLDFZofikZgcVlvETsYl Q9FVRMBwI8jO+qsCwDu2eqFb9DMApYT4s4/NySYY6ezTo6LpTG9+PooJ0F6mM08NkPYM JoRErV3NII8OKOc8eQGj8vBdEZ/mjnZwMD1+1YUw47MwLx9z/dp4ItC2CIguD/FIud/V FpccZM7iugoXOXMI1e5DE6hLmT4/p27Jssb0TYbu39arQMUJLi+zNaKlShyI42ZJNV2G 5h8g== X-Gm-Message-State: AOAM533mIgAZoHo2ALWh66pKvSmCuLJsy1X4b9dArY2OGSQY7k/LURg6 qaqyvTJ54cGujKK/vYL6DpRA3+fH3FU= X-Google-Smtp-Source: ABdhPJyoM9+hddxAOj7Wi+ayIAMV9SshLKWu++u6kZrOQGOssnsUL9zZxRUdVWPfNjmW0Pl/bYjuJg== X-Received: by 2002:a37:aa90:: with SMTP id t138mr457525qke.150.1612314399697; Tue, 02 Feb 2021 17:06:39 -0800 (PST) From: Daniel Henrique Barboza To: libvir-list@redhat.com Subject: [PATCH v2 02/10] datatypes.h: register AUTOPTR_CLEANUP_FUNC for virNodeDevicePtr Date: Tue, 2 Feb 2021 22:06:17 -0300 Message-Id: <20210203010625.2328911-3-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.3 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.14 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 Next patch will use g_autoptr() with virNodeDevicePtr for cleanups. Reviewed-by: J=C3=A1n Tomko Signed-off-by: Daniel Henrique Barboza --- src/datatypes.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/datatypes.h b/src/datatypes.h index ade3779e43..7a88aba0df 100644 --- a/src/datatypes.h +++ b/src/datatypes.h @@ -707,6 +707,8 @@ struct _virNodeDevice { char *parentName; /* parent device name */ }; =20 +G_DEFINE_AUTOPTR_CLEANUP_FUNC(virNodeDevice, virObjectUnref); + /** * _virSecret: * --=20 2.26.2 From nobody Sun May 5 19:55:54 2024 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=1612314440; cv=none; d=zohomail.com; s=zohoarc; b=Amnu1iT8pJ4JQEKxVWIzuGzLDXhZ4oZwMofW+u/HXtH5TC7ydikw1jNtXkXjFFd9Bl3gTvBJYQCq4CovWyQfCSKGHyH+LwRK2oo/FBmybM4zW8tW5chQRemjMcF+lhfRpikb6P/aPCqrtnC4YgZVtFsAJ/tdMOn5ZumxEjfy3VI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1612314440; 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=4bHsPNCafNjuLv+ar9kaZn4JLjonVYNzT+FWsYCDk+o=; b=hTo4CpubrOvAqUc/bUAFMJuNT6HoSk0kIQXR+sIpl4Szkyjetc92Eo1F/fP5AZ+6hkVNr8nVvGD4JFIRjU7pwrt2rpYIaGGVlA4rlEN/lWIHHHa3TeDSmqWIfTL21J7JI7If4+CikQmd21rm/4WgpD+Ubk1cTy5XhFEeh1w2IN4= 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 1612314440384643.1387606075468; Tue, 2 Feb 2021 17:07:20 -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-81-JTw55YpqNbKo6AzNfBmP5w-1; Tue, 02 Feb 2021 20:07:16 -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 0BA3881628; Wed, 3 Feb 2021 01:07:11 +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 DB4D55F9C0; Wed, 3 Feb 2021 01:07:10 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 9E7305003E; Wed, 3 Feb 2021 01:07:10 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 11316nOc010343 for ; Tue, 2 Feb 2021 20:06:49 -0500 Received: by smtp.corp.redhat.com (Postfix) id 2263FEE38A; Wed, 3 Feb 2021 01:06:49 +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 1C942EE388 for ; Wed, 3 Feb 2021 01:06:46 +0000 (UTC) Received: from us-smtp-1.mimecast.com (us-smtp-1.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 9E00A800157 for ; Wed, 3 Feb 2021 01:06:46 +0000 (UTC) Received: from mail-qt1-f176.google.com (mail-qt1-f176.google.com [209.85.160.176]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-569-ByaihuO_NSi6fuUIluTT1Q-1; Tue, 02 Feb 2021 20:06:42 -0500 Received: by mail-qt1-f176.google.com with SMTP id t14so16448911qto.8; Tue, 02 Feb 2021 17:06:42 -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.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 02 Feb 2021 17:06:41 -0800 (PST) X-MC-Unique: JTw55YpqNbKo6AzNfBmP5w-1 X-MC-Unique: ByaihuO_NSi6fuUIluTT1Q-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=4bHsPNCafNjuLv+ar9kaZn4JLjonVYNzT+FWsYCDk+o=; b=Xc/Or1q5OmZmdvmcJ4rXnNEiXExZOx4KziGSoYNMmw+1Ou4RjmeAowxqVT57/DitnP tBnw5mHlA9Jj0F/YE/vbKVrLDMUxWlXHUBgDLftsr7kOeERtoiMmO1RyV3UFu9uOx6KT 0wKv+N+VH3WVTzMK1gb/ML9oNe1DDo0DBSBTSQiF9Nx0lfHIV3KY0OKPodSw7eReMoOG yxacBGiu6aWaeezZntaGBx2Ka00gWgU7pR7fK49S7z3ZxIpnPhq8/9+adjaK9JRdUZ+8 lPfRzyUIU4D8nRggqWjOnoetp9mbJuGbjnJ6rmfiSV18HlxZstWSkuexxEStTAujrzKe OKCg== X-Gm-Message-State: AOAM531agR+ZBZ/L6jmv4w4XpkH6BbfpSsZQDwLad7D4Fo0gu6u98MM/ TXLuTqojsjR6jToIHktOPjUFjESQuLQ= X-Google-Smtp-Source: ABdhPJyRFElXDNViciUuN3QDWO+EhW7j9XT2lrOMObrxwYB741RZjbZGvNJDiB2j503ink/GRc3qZw== X-Received: by 2002:ac8:5854:: with SMTP id h20mr535235qth.301.1612314401586; Tue, 02 Feb 2021 17:06:41 -0800 (PST) From: Daniel Henrique Barboza To: libvir-list@redhat.com Subject: [PATCH v2 03/10] domain_driver.c: use g_auto* in virDomainDriverNodeDeviceReset() Date: Tue, 2 Feb 2021 22:06:18 -0300 Message-Id: <20210203010625.2328911-4-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.79 on 10.11.54.5 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.16 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 Reviewed-by: J=C3=A1n Tomko Signed-off-by: Daniel Henrique Barboza --- src/hypervisor/domain_driver.c | 33 ++++++++++++--------------------- 1 file changed, 12 insertions(+), 21 deletions(-) diff --git a/src/hypervisor/domain_driver.c b/src/hypervisor/domain_driver.c index 0c86fd714f..82e5587a50 100644 --- a/src/hypervisor/domain_driver.c +++ b/src/hypervisor/domain_driver.c @@ -375,51 +375,42 @@ int virDomainDriverNodeDeviceReset(virNodeDevicePtr dev, virHostdevManagerPtr hostdevMgr) { - virPCIDevicePtr pci; + g_autoptr(virPCIDevice) pci =3D NULL; virPCIDeviceAddress devAddr; - virNodeDeviceDefPtr def =3D NULL; + g_autoptr(virNodeDeviceDef) def =3D NULL; g_autofree char *xml =3D NULL; - virConnectPtr nodeconn =3D NULL; - virNodeDevicePtr nodedev =3D NULL; - int ret =3D -1; + g_autoptr(virConnect) nodeconn =3D NULL; + g_autoptr(virNodeDevice) nodedev =3D NULL; =20 if (!(nodeconn =3D virGetConnectNodeDev())) - goto cleanup; + return -1; =20 /* '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; + return -1; =20 xml =3D virNodeDeviceGetXMLDesc(nodedev, 0); if (!xml) - goto cleanup; + return -1; =20 def =3D virNodeDeviceDefParseString(xml, EXISTING_DEVICE, NULL); if (!def) - goto cleanup; + return -1; =20 /* ACL check must happen against original 'dev', * not the new 'nodedev' we acquired */ if (virNodeDeviceResetEnsureACL(dev->conn, def) < 0) - goto cleanup; + return -1; =20 if (virDomainDriverNodeDeviceGetPCIInfo(def, &devAddr) < 0) - goto cleanup; + return -1; =20 pci =3D virPCIDeviceNew(&devAddr); if (!pci) - goto cleanup; - - ret =3D virHostdevPCINodeDeviceReset(hostdevMgr, pci); - - virPCIDeviceFree(pci); - cleanup: - virNodeDeviceDefFree(def); - virObjectUnref(nodedev); - virObjectUnref(nodeconn); - return ret; + return -1; =20 + return virHostdevPCINodeDeviceReset(hostdevMgr, pci); } --=20 2.26.2 From nobody Sun May 5 19:55:54 2024 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=ClPyTnV/R5EjQ+SSQQWgWC63ZtFkMKgcrcEZMXEc6ktIBRCAAVruJjyqHYkKbvwuAlzCj6xdW2aOtAWdcWp8rW9UOVfQRz86gzCZpMEBr+e2sSSe4AdZeLAMe96+NCWp8KJXBa78IPNPXuMsZxFXxKmMkoXrskgrUISYscbwNIY= 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=R3S3MsyCrNw6Qx/O3QH7Ig2zdsGCWoEr0Prd3xZcSYU=; b=kMOiUpPt/JSbsymNbDSe8GcY4LVSA5UDzl57qzXAL9danRafHGs+riRP+yQmRLCQEUtgZtneEAyxHFlCnSlOIk674yU0d4ehOZ8yDnRDue/PGxthVBpq5BfYEC5W82LaYzoR7qzhpMU//XFBX7bn2Al8nuiGAnnoUSIfjh+mfM8= 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 1612314418791867.1448672075841; 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-219-qCpikqExMVK6PnNEduPAOQ-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 DB0EC189DF56; Wed, 3 Feb 2021 01:06:49 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id CDC8B5D763; Wed, 3 Feb 2021 01:06:48 +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 6523A5003B; Wed, 3 Feb 2021 01:06:47 +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 11316ksN010313 for ; Tue, 2 Feb 2021 20:06:46 -0500 Received: by smtp.corp.redhat.com (Postfix) id 1C7862166B2A; Wed, 3 Feb 2021 01:06:46 +0000 (UTC) Received: from mimecast-mx02.redhat.com (mimecast06.extmail.prod.ext.rdu2.redhat.com [10.11.55.22]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 170FD2166B27 for ; Wed, 3 Feb 2021 01:06:46 +0000 (UTC) Received: from us-smtp-1.mimecast.com (us-smtp-delivery-1.mimecast.com [205.139.110.120]) (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 03B42185A794 for ; Wed, 3 Feb 2021 01:06:46 +0000 (UTC) Received: from mail-qk1-f174.google.com (mail-qk1-f174.google.com [209.85.222.174]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-70-fBZYsMLAPxGJ105NsYwKQA-1; Tue, 02 Feb 2021 20:06:44 -0500 Received: by mail-qk1-f174.google.com with SMTP id d85so21882814qkg.5; Tue, 02 Feb 2021 17:06:44 -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.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 02 Feb 2021 17:06:42 -0800 (PST) X-MC-Unique: qCpikqExMVK6PnNEduPAOQ-1 X-MC-Unique: fBZYsMLAPxGJ105NsYwKQA-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=R3S3MsyCrNw6Qx/O3QH7Ig2zdsGCWoEr0Prd3xZcSYU=; b=bsYRycQqy7HBZ6Ag9ZnMzAf8TyIpugiiOO+qOpMoWfG4hiq7mxlNss5XqopDUnWv1q fDWzT/J8yGJvC5ZhX3Qv9FIKXJ5T5+q+LNDq7wBxxJQtAA2FiNChEb1qSnon4pNJ0sgT r+7uPVFlHxo4fT3t9SbKI52tKsfbszloi5e9WLFfjHMUUO4//wqbqQmZcBdmqZs7DyCy KnGyA4IIKvqf5xKCUMFoBT6p8vKt/cJPwG+hUMgdDCno8x9HEtpkKjdjfDrvlSTw2V80 /B6siqJC1VuDSlHjfn2haFO6aoJ5dbUboYqdLy8JZk7egQ67tCezV+imI+fdTXsP1erv ruvw== X-Gm-Message-State: AOAM5337+7u78hHplwxgabUaYsXzLVhCFutY+D0b2ZPiFn7KpfuKLFvG WiyL094NWUlueLlKgqhQQmidOTMulC8= X-Google-Smtp-Source: ABdhPJzgkznoOXhyT078jtY4Q1qB01pPfMUXMkB4htEPEtkpCy/0TAkVHq67MWzaWY7fd97ALRR+mw== X-Received: by 2002:a05:620a:248e:: with SMTP id i14mr438489qkn.245.1612314403435; Tue, 02 Feb 2021 17:06:43 -0800 (PST) From: Daniel Henrique Barboza To: libvir-list@redhat.com Subject: [PATCH v2 04/10] qemu, libxl, hypervisor: use virDomainDriverNodeDeviceReAttach() helper Date: Tue, 2 Feb 2021 22:06:19 -0300 Message-Id: <20210203010625.2328911-5-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 libxlNodeDeviceReAttach() and qemuNodeDeviceReAttach() are mostly equal, differing only how the virHostdevManager pointer is retrieved. Put the common code into virDomainDriverNodeDeviceReAttach() to reduce code duplication. Reviewed-by: J=C3=A1n Tomko Signed-off-by: Daniel Henrique Barboza --- src/hypervisor/domain_driver.c | 53 ++++++++++++++++++++++++++++++++++ src/hypervisor/domain_driver.h | 3 ++ src/libvirt_private.syms | 1 + src/libxl/libxl_driver.c | 53 ++-------------------------------- src/qemu/qemu_driver.c | 49 ++----------------------------- 5 files changed, 63 insertions(+), 96 deletions(-) diff --git a/src/hypervisor/domain_driver.c b/src/hypervisor/domain_driver.c index 82e5587a50..c559f94348 100644 --- a/src/hypervisor/domain_driver.c +++ b/src/hypervisor/domain_driver.c @@ -414,3 +414,56 @@ virDomainDriverNodeDeviceReset(virNodeDevicePtr dev, =20 return virHostdevPCINodeDeviceReset(hostdevMgr, pci); } + + +int +virDomainDriverNodeDeviceReAttach(virNodeDevicePtr dev, + virHostdevManagerPtr hostdevMgr) +{ + virPCIDevicePtr pci =3D NULL; + virPCIDeviceAddress devAddr; + int ret =3D -1; + virNodeDeviceDefPtr def =3D NULL; + g_autofree char *xml =3D NULL; + virConnectPtr nodeconn =3D NULL; + virNodeDevicePtr nodedev =3D NULL; + + 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 (virNodeDeviceReAttachEnsureACL(dev->conn, def) < 0) + goto cleanup; + + if (virDomainDriverNodeDeviceGetPCIInfo(def, &devAddr) < 0) + goto cleanup; + + pci =3D virPCIDeviceNew(&devAddr); + if (!pci) + goto cleanup; + + ret =3D virHostdevPCINodeDeviceReAttach(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 b690844fe5..71eed6d5a9 100644 --- a/src/hypervisor/domain_driver.h +++ b/src/hypervisor/domain_driver.h @@ -53,3 +53,6 @@ int virDomainDriverNodeDeviceGetPCIInfo(virNodeDeviceDefP= tr def, =20 int virDomainDriverNodeDeviceReset(virNodeDevicePtr dev, virHostdevManagerPtr hostdevMgr); + +int virDomainDriverNodeDeviceReAttach(virNodeDevicePtr dev, + virHostdevManagerPtr hostdevMgr); diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index 1f6048e3f7..ed01f79106 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -1504,6 +1504,7 @@ virDomainDriverGenerateMachineName; virDomainDriverGenerateRootHash; virDomainDriverMergeBlkioDevice; virDomainDriverNodeDeviceGetPCIInfo; +virDomainDriverNodeDeviceReAttach; virDomainDriverNodeDeviceReset; virDomainDriverParseBlkioDeviceStr; virDomainDriverSetupPersistentDefBlkioParams; diff --git a/src/libxl/libxl_driver.c b/src/libxl/libxl_driver.c index 814a6c282c..316a6c6bf5 100644 --- a/src/libxl/libxl_driver.c +++ b/src/libxl/libxl_driver.c @@ -5852,59 +5852,12 @@ libxlNodeDeviceDettach(virNodeDevicePtr dev) static int libxlNodeDeviceReAttach(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 (virNodeDeviceReAttachEnsureACL(dev->conn, def) < 0) - goto cleanup; - - if (virDomainDriverNodeDeviceGetPCIInfo(def, &devAddr) < 0) - goto cleanup; - - pci =3D virPCIDeviceNew(&devAddr); - if (!pci) - goto cleanup; =20 - if (virHostdevPCINodeDeviceReAttach(hostdev_mgr, pci) < 0) - goto cleanup; - - ret =3D 0; - - cleanup: - virPCIDeviceFree(pci); - virNodeDeviceDefFree(def); - virObjectUnref(nodedev); - virObjectUnref(nodeconn); - VIR_FREE(xml); - return ret; + /* virNodeDeviceReAttachEnsureACL() is being called by + * virDomainDriverNodeDeviceReAttach() */ + return virDomainDriverNodeDeviceReAttach(dev, hostdev_mgr); } =20 static int diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index 8270a26c0b..64ae8fafc0 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -12054,54 +12054,11 @@ static int qemuNodeDeviceReAttach(virNodeDevicePtr dev) { virQEMUDriverPtr driver =3D dev->conn->privateData; - virPCIDevicePtr pci =3D NULL; - 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; - - xml =3D virNodeDeviceGetXMLDesc(nodedev, 0); - if (!xml) - goto cleanup; - - def =3D virNodeDeviceDefParseString(xml, EXISTING_DEVICE, NULL); - 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; - - if (virDomainDriverNodeDeviceGetPCIInfo(def, &devAddr) < 0) - goto cleanup; - - pci =3D virPCIDeviceNew(&devAddr); - if (!pci) - goto cleanup; - - ret =3D virHostdevPCINodeDeviceReAttach(hostdev_mgr, pci); - - virPCIDeviceFree(pci); - cleanup: - virNodeDeviceDefFree(def); - virObjectUnref(nodedev); - virObjectUnref(nodeconn); - return ret; + /* virNodeDeviceReAttachEnsureACL() is being called by + * virDomainDriverNodeDeviceReAttach() */ + return virDomainDriverNodeDeviceReAttach(dev, hostdev_mgr); } =20 static int --=20 2.26.2 From nobody Sun May 5 19:55:54 2024 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=1612314437; cv=none; d=zohomail.com; s=zohoarc; b=lCNQ52eY4hraCeMSHPcbqgy3y+xJMCxIPaVnimydU9iNsOG7f68qXJuudkwnwtB9rIHxPOu1C37I0K7/WIm43G5KJxci1wFbFPB5ua3rCsgVLIRonioRn2x7BDiFG2ThpNq4hrhoJeGGVJmjW5JioWJa+/mqqci+1fDzqYKvyP0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1612314437; 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=XudLh34yzCIEWR2IbFoz0zX4B8OlxwBudOMykdp5Tao=; b=D58dRMaEN9cs+7N7BYtM6376kiu+WrKPbh0yafnNFCFfxBWj1Z+EVm1YtNokZGMckMvQbbSanG9WWKSZHYmXacMtFCB0VUgh/5qSEihlZU5gVSSGu7JOs39JSt1MFd6OBjsm9M3X/pEneSj7BmlhkKp9zCNVXCFEzq7wNz7liz8= 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 161231443708547.923301169444926; Tue, 2 Feb 2021 17:07: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-569--lx2ckpLMnSrFGMyxlnL0g-1; Tue, 02 Feb 2021 20:07:13 -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 7E356107ACE4; Wed, 3 Feb 2021 01:07:07 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 59C8B5FC1D; Wed, 3 Feb 2021 01:07:07 +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 24B7618095CE; Wed, 3 Feb 2021 01:07:07 +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 11316odK010350 for ; Tue, 2 Feb 2021 20:06:50 -0500 Received: by smtp.corp.redhat.com (Postfix) id 07A612166B27; Wed, 3 Feb 2021 01:06:50 +0000 (UTC) Received: from mimecast-mx02.redhat.com (mimecast02.extmail.prod.ext.rdu2.redhat.com [10.11.55.18]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 022D92166B2A for ; Wed, 3 Feb 2021 01:06:49 +0000 (UTC) Received: from us-smtp-1.mimecast.com (us-smtp-delivery-1.mimecast.com [205.139.110.120]) (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 E1F7882DFE0 for ; Wed, 3 Feb 2021 01:06:49 +0000 (UTC) Received: from mail-qk1-f179.google.com (mail-qk1-f179.google.com [209.85.222.179]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-604-Q00VZdTRMxyk3KTlAey88Q-1; Tue, 02 Feb 2021 20:06:46 -0500 Received: by mail-qk1-f179.google.com with SMTP id d85so21882869qkg.5; Tue, 02 Feb 2021 17:06:45 -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.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 02 Feb 2021 17:06:44 -0800 (PST) X-MC-Unique: -lx2ckpLMnSrFGMyxlnL0g-1 X-MC-Unique: Q00VZdTRMxyk3KTlAey88Q-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=XudLh34yzCIEWR2IbFoz0zX4B8OlxwBudOMykdp5Tao=; b=KC2HsKC7yroVC8qXHjmmRucgAHCKyKyIjw9m1CQG4QoS66EV4Au0xmfWEq6CrdNVzS nH2DFwMEQwv2WlVAo0S0909qdSz7JmKPvuWPjtmHGnoPeKUNGmHLt3xgxezsndrxgcKz J+cfkIwYiRNyQuYtfOJ00lyzixj+i75QX2B29lRPvIudpgZBiLRdIGkd/hBicni/oNgv bv0II45GA9olizaZX9ccZrh68YhFNOHNEXTbHTNUpJ8xRSUFBZqELWZ2ZIlQu/LHW5nP 0cDGtP04y+jCLetbAtutbWnadyVlK5e685GpeBYInm8rzz0MmSnqToKMjczft3eM/ox3 0Ryw== X-Gm-Message-State: AOAM530+qJuEykJqFSs03Zdk+JLUX2iuf5KUr6xDUjSxAq+QwBfuTX1j XPxSz3DoKGTZPEcXAuUWGZU+gOwDSeQ= X-Google-Smtp-Source: ABdhPJxb8vFUQCbaM3EoXkBo22+UVTRptBzmkp9j66AA6V2zQZyZOzYa9j5KZkPSKqpwQhs6eBuC7g== X-Received: by 2002:a37:4a82:: with SMTP id x124mr460996qka.458.1612314405385; Tue, 02 Feb 2021 17:06:45 -0800 (PST) From: Daniel Henrique Barboza To: libvir-list@redhat.com Subject: [PATCH v2 05/10] domain_driver.c: use g_auto* in virDomainDriverNodeDeviceReAttach() Date: Tue, 2 Feb 2021 22:06:20 -0300 Message-Id: <20210203010625.2328911-6-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.16 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 Reviewed-by: J=C3=A1n Tomko Signed-off-by: Daniel Henrique Barboza --- src/hypervisor/domain_driver.c | 32 ++++++++++++-------------------- 1 file changed, 12 insertions(+), 20 deletions(-) diff --git a/src/hypervisor/domain_driver.c b/src/hypervisor/domain_driver.c index c559f94348..ea4c3c9466 100644 --- a/src/hypervisor/domain_driver.c +++ b/src/hypervisor/domain_driver.c @@ -420,50 +420,42 @@ int virDomainDriverNodeDeviceReAttach(virNodeDevicePtr dev, virHostdevManagerPtr hostdevMgr) { - virPCIDevicePtr pci =3D NULL; + g_autoptr(virPCIDevice) pci =3D NULL; virPCIDeviceAddress devAddr; - int ret =3D -1; - virNodeDeviceDefPtr def =3D NULL; + g_autoptr(virNodeDeviceDef) def =3D NULL; g_autofree char *xml =3D NULL; - virConnectPtr nodeconn =3D NULL; - virNodeDevicePtr nodedev =3D NULL; + g_autoptr(virConnect) nodeconn =3D NULL; + g_autoptr(virNodeDevice) nodedev =3D NULL; =20 if (!(nodeconn =3D virGetConnectNodeDev())) - goto cleanup; + return -1; =20 /* '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; + return -1; =20 xml =3D virNodeDeviceGetXMLDesc(nodedev, 0); if (!xml) - goto cleanup; + return -1; =20 def =3D virNodeDeviceDefParseString(xml, EXISTING_DEVICE, NULL); if (!def) - goto cleanup; + return -1; =20 /* ACL check must happen against original 'dev', * not the new 'nodedev' we acquired */ if (virNodeDeviceReAttachEnsureACL(dev->conn, def) < 0) - goto cleanup; + return -1; =20 if (virDomainDriverNodeDeviceGetPCIInfo(def, &devAddr) < 0) - goto cleanup; + return -1; =20 pci =3D virPCIDeviceNew(&devAddr); if (!pci) - goto cleanup; - - ret =3D virHostdevPCINodeDeviceReAttach(hostdevMgr, pci); + return -1; =20 - virPCIDeviceFree(pci); - cleanup: - virNodeDeviceDefFree(def); - virObjectUnref(nodedev); - virObjectUnref(nodeconn); - return ret; + return virHostdevPCINodeDeviceReAttach(hostdevMgr, pci); } --=20 2.26.2 From nobody Sun May 5 19:55:54 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 63.128.21.124 as permitted sender) client-ip=63.128.21.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 63.128.21.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=1612314438; cv=none; d=zohomail.com; s=zohoarc; b=EtArf+h3sSAnyyiZiKeISlftTOsQTauK8c4i+v2STx1XDg5MG5ej5A5Pb8zgG6BSuewMcgPvqrFi6Q+ZxZHKiBcrAbMvsh2MfeJY4FqY+wFgyv1j3jhUwKS8wOGLGZSDbwdvBUYuVSsQjDNb6EzMeF9sO9lZBBiioEPUuyrga8Q= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1612314438; 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=zX47cbwDX+33BdPnEq4S8S+tVeRXIjnbZC52EJeSJFI=; b=UdAzP7QtoO1G564aA8R8J2iIO8KfegJWz96EgwYNpzVEBWNDLEG13rbEBtbwzOBfwaxIXRRfu8ytkE1Z1XilHd+Rrz0PqasAlEDLmQU685vQAt+UhIYx0GRYiG6SAL2LjIKkGwwy9IJGbc+zl2+7i5XY3bUQJFL1iu50IBce0bs= ARC-Authentication-Results: i=1; mx.zohomail.com; spf=pass (zohomail.com: domain of redhat.com designates 63.128.21.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 [63.128.21.124]) by mx.zohomail.com with SMTPS id 1612314438660986.189251734789; Tue, 2 Feb 2021 17:07: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-268-dhIhDNHPNKGH_cijLFAUPg-1; Tue, 02 Feb 2021 20:07:15 -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 539D2189DF57; Wed, 3 Feb 2021 01:07:10 +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 2BAB85D763; Wed, 3 Feb 2021 01:07:10 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id DE5231809C8F; Wed, 3 Feb 2021 01:07:09 +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 11316ou2010352 for ; Tue, 2 Feb 2021 20:06:50 -0500 Received: by smtp.corp.redhat.com (Postfix) id 247622166B2D; Wed, 3 Feb 2021 01:06:50 +0000 (UTC) Received: from mimecast-mx02.redhat.com (mimecast04.extmail.prod.ext.rdu2.redhat.com [10.11.55.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 1F4302166B2A for ; Wed, 3 Feb 2021 01:06:50 +0000 (UTC) Received: from us-smtp-1.mimecast.com (us-smtp-delivery-1.mimecast.com [205.139.110.120]) (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 0BFD2101042F for ; Wed, 3 Feb 2021 01:06:50 +0000 (UTC) Received: from mail-qt1-f171.google.com (mail-qt1-f171.google.com [209.85.160.171]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-50-SyjrKiO9NkS-jco_4VTRTg-1; Tue, 02 Feb 2021 20:06:47 -0500 Received: by mail-qt1-f171.google.com with SMTP id l23so16432544qtq.13; Tue, 02 Feb 2021 17:06:47 -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.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 02 Feb 2021 17:06:46 -0800 (PST) X-MC-Unique: dhIhDNHPNKGH_cijLFAUPg-1 X-MC-Unique: SyjrKiO9NkS-jco_4VTRTg-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=zX47cbwDX+33BdPnEq4S8S+tVeRXIjnbZC52EJeSJFI=; b=K7NyaNayK2aTmrMvDJKJcoYaFrvwR6kVwJm+E2AldQAGlK06mecqAJl5fwlklELyrK wF/5xKq4PDaChETFjYZKroTuU+IO2XR+TVxIklP2dFn0R0hKr0YikDOvFuLxzlU1rXl2 59UEFAAOx7bb+d6tCVF6tUuvv0TB2WmZWI+KXaQsbNQgWLRyUvNVuqqZCmLTDMZ+Sc96 Dur69bMRfaBOUdVY2JqP4G8ym985zOvlHV5VIFcPV3RUNyB3YzT9SiyKRAPv8R/2Y9XV HSFv7fdXNvfV7MUpFWomh5QWcT7SKGnP3Ot5U4S6weWMCKNe1S0tMPINvVP7WvEinr88 OX7g== X-Gm-Message-State: AOAM530QLl2b9p9KxehF/hWjn2pr+/EHuHW0xxDDJCZB6Ew7foSBwkjq zYGtZjyNdf+RptW6mHqpI1WrVOAH3TU= X-Google-Smtp-Source: ABdhPJyE0Ef+5RWHpZbBWrpCXr9yN4TfEe1xytDPMTJPSCrHzJ9tSbEfUpOGrfavowPMtbnv1WK82Q== X-Received: by 2002:ac8:66c9:: with SMTP id m9mr534257qtp.43.1612314407057; Tue, 02 Feb 2021 17:06:47 -0800 (PST) From: Daniel Henrique Barboza To: libvir-list@redhat.com Subject: [PATCH v2 06/10] libxl_driver.c: validate 'driverName' earlier in libxlNodeDeviceDetachFlags() Date: Tue, 2 Feb 2021 22:06:21 -0300 Message-Id: <20210203010625.2328911-7-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 The validation of 'driverName' does not depend on any other state and can be done right on the start of the function. We can fail earlier while avoiding a cleanup jump. Reviewed-by: J=C3=A1n Tomko Signed-off-by: Daniel Henrique Barboza --- src/libxl/libxl_driver.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/libxl/libxl_driver.c b/src/libxl/libxl_driver.c index 316a6c6bf5..eadacdfb76 100644 --- a/src/libxl/libxl_driver.c +++ b/src/libxl/libxl_driver.c @@ -5791,6 +5791,12 @@ libxlNodeDeviceDetachFlags(virNodeDevicePtr dev, =20 virCheckFlags(0, -1); =20 + if (driverName && STRNEQ(driverName, "xen")) { + virReportError(VIR_ERR_INVALID_ARG, + _("unsupported driver name '%s'"), driverName); + return -1; + } + if (!(nodeconn =3D virGetConnectNodeDev())) goto cleanup; =20 @@ -5822,13 +5828,7 @@ libxlNodeDeviceDetachFlags(virNodeDevicePtr dev, if (!pci) goto cleanup; =20 - if (!driverName || STREQ(driverName, "xen")) { - virPCIDeviceSetStubDriver(pci, VIR_PCI_STUB_DRIVER_XEN); - } else { - virReportError(VIR_ERR_INVALID_ARG, - _("unsupported driver name '%s'"), driverName); - goto cleanup; - } + virPCIDeviceSetStubDriver(pci, VIR_PCI_STUB_DRIVER_XEN); =20 if (virHostdevPCINodeDeviceDetach(hostdev_mgr, pci) < 0) goto cleanup; --=20 2.26.2 From nobody Sun May 5 19:55:54 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 63.128.21.124 as permitted sender) client-ip=63.128.21.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 63.128.21.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=1612314442; cv=none; d=zohomail.com; s=zohoarc; b=d1WK4mtu1i2Gna1cPQK33ijkShis7Ob2Qm8BrPOY8dZ1fl2FOeU420oDSdXMTyRtgtJi2UzTY/Lg8DVJ8ORsSQX7Yw34mHaxQZnNbUM28s2OEPAJDBaOAjUPmnWh6dXB0FH+8a2swYfS7rQtQvkbuke1IdO594zckt+n/53XLB4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1612314442; 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=av+6ZkhlK/1lwFoqqpgzKi/53vw2+JYbwUX4EriHfkw=; b=WOonkDF+ceruXIsM0+N1HC9HzG6l6/X/y5j4nVn5Zy1nJjIBlM99uuKeI4A1PUa4MZnoqsThwF5bY0TReRykOu+O9/HeE//uQ6dsmxnWjdg4jcQ5BT+E61TcEmgAPJhwXzngjzThhFf4wTDyICXNwi1spoiAzxX7sQhL6ahbo9k= ARC-Authentication-Results: i=1; mx.zohomail.com; spf=pass (zohomail.com: domain of redhat.com designates 63.128.21.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 [63.128.21.124]) by mx.zohomail.com with SMTPS id 1612314442379557.3164360603116; Tue, 2 Feb 2021 17:07: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-206-08Ew2dCZNRupkHUqcaGtqA-1; Tue, 02 Feb 2021 20:07:18 -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 511DC801AAF; Wed, 3 Feb 2021 01:07:11 +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 2E9017EA8B; Wed, 3 Feb 2021 01:07:11 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id E90AB50042; Wed, 3 Feb 2021 01:07:10 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 11316p2b010375 for ; Tue, 2 Feb 2021 20:06:51 -0500 Received: by smtp.corp.redhat.com (Postfix) id B21BF100416A; Wed, 3 Feb 2021 01:06:51 +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 AE2C9100332B for ; Wed, 3 Feb 2021 01:06:51 +0000 (UTC) Received: from us-smtp-1.mimecast.com (us-smtp-delivery-1.mimecast.com [207.211.31.120]) (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 9C4D080B92B for ; Wed, 3 Feb 2021 01:06:51 +0000 (UTC) Received: from mail-qk1-f176.google.com (mail-qk1-f176.google.com [209.85.222.176]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-421-8CBC5w7OOBWWZzOv83nfzg-1; Tue, 02 Feb 2021 20:06:49 -0500 Received: by mail-qk1-f176.google.com with SMTP id r77so21863917qka.12; Tue, 02 Feb 2021 17:06:49 -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.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 02 Feb 2021 17:06:48 -0800 (PST) X-MC-Unique: 08Ew2dCZNRupkHUqcaGtqA-1 X-MC-Unique: 8CBC5w7OOBWWZzOv83nfzg-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=av+6ZkhlK/1lwFoqqpgzKi/53vw2+JYbwUX4EriHfkw=; b=kkJmrvq0BkCqgP+oj1gMuZ9HttKxDpi89jEKPRFM2EmwEk1fdKvQ+fACwO6+EvIhEi +vrSyhgebHji3hXpe0rthp29AtUIXegkh58vb6lZ7rHoP1DaS+ElmF38aVLkfQD8rRYD MZF8Oy30MggWcXAsfnjm/qHvymoAXcbCksaFvNpre3F2O3cK161hXeL2sDyxzHk51gRX EMJEl9dkG9gdKSz7yfTphnGjfjtinAf3GTn6cYggO64UooI+1qhSysWyN+oovPCwxAd1 hjRfMpYQg0LzhNcZtFqxHTXVA5BJe2hg7hdcBRa6cD/U5mMYLnWPf1ZJcPevPkI5uduT lU5w== X-Gm-Message-State: AOAM531a+TsNWyy/eb/5UjuhQmEtejL6AobBuLKaoEjYxL0PcigYSynz 5FImi49lQJFVD8TMW5XjA1RuHUqI/eo= X-Google-Smtp-Source: ABdhPJxnLIIRqOR6MsmBiaD1lWB0mplWoe4MBMQN3vd9l0i0iT7TNHXkOgMDmQClgqvaOFrUy1RwSQ== X-Received: by 2002:a05:620a:a01:: with SMTP id i1mr496212qka.80.1612314408880; Tue, 02 Feb 2021 17:06:48 -0800 (PST) From: Daniel Henrique Barboza To: libvir-list@redhat.com Subject: [PATCH v2 07/10] qemu_driver.c: validate 'driverName' earlier in qemuNodeDeviceDetachFlags() Date: Tue, 2 Feb 2021 22:06:22 -0300 Message-Id: <20210203010625.2328911-8-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.3 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 The validation of 'driverName' does not depend on any other state and can be done right on the start of the function. We can fail earlier while avoiding a cleanup jump. Reviewed-by: J=C3=A1n Tomko Signed-off-by: Daniel Henrique Barboza --- src/qemu/qemu_driver.c | 41 ++++++++++++++++++++--------------------- 1 file changed, 20 insertions(+), 21 deletions(-) diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index 64ae8fafc0..c6ba33e4ad 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -11982,6 +11982,25 @@ qemuNodeDeviceDetachFlags(virNodeDevicePtr dev, =20 virCheckFlags(0, -1); =20 + if (!driverName) + driverName =3D "vfio"; + + if (STREQ(driverName, "vfio") && !vfio) { + virReportError(VIR_ERR_ARGUMENT_UNSUPPORTED, "%s", + _("VFIO device assignment is currently not " + "supported on this system")); + return -1; + } else if (STREQ(driverName, "kvm")) { + virReportError(VIR_ERR_ARGUMENT_UNSUPPORTED, "%s", + _("KVM device assignment is no longer " + "supported on this system")); + return -1; + } else { + virReportError(VIR_ERR_INVALID_ARG, + _("unknown driver name '%s'"), driverName); + return -1; + } + if (!(nodeconn =3D virGetConnectNodeDev())) goto cleanup; =20 @@ -12013,27 +12032,7 @@ qemuNodeDeviceDetachFlags(virNodeDevicePtr dev, if (!pci) goto cleanup; =20 - if (!driverName) - driverName =3D "vfio"; - - if (STREQ(driverName, "vfio")) { - if (!vfio) { - virReportError(VIR_ERR_ARGUMENT_UNSUPPORTED, "%s", - _("VFIO device assignment is currently not " - "supported on this system")); - goto cleanup; - } - virPCIDeviceSetStubDriver(pci, VIR_PCI_STUB_DRIVER_VFIO); - } else if (STREQ(driverName, "kvm")) { - virReportError(VIR_ERR_ARGUMENT_UNSUPPORTED, "%s", - _("KVM device assignment is no longer " - "supported on this system")); - goto cleanup; - } else { - virReportError(VIR_ERR_INVALID_ARG, - _("unknown driver name '%s'"), driverName); - goto cleanup; - } + virPCIDeviceSetStubDriver(pci, VIR_PCI_STUB_DRIVER_VFIO); =20 ret =3D virHostdevPCINodeDeviceDetach(hostdev_mgr, pci); cleanup: --=20 2.26.2 From nobody Sun May 5 19:55:54 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 63.128.21.124 as permitted sender) client-ip=63.128.21.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 63.128.21.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=1612314444; cv=none; d=zohomail.com; s=zohoarc; b=eGNuac++vi8fLJ6ZcV3XTC7dLu6W/q3+CkU6XDBDvBzP5M38uzbaJpBF5WZGo/xo5wV4Y8i4tdoGRP2IgHrNEPDOUB5RqcttpKE2EjCjL1Ih5QNqoRaIAnuWr9r8M8EkhwRhXQO44CDTFOBdcPL1nY6yj5lYfqro72Q/7cgfeHM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1612314444; 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=4c58XIVKa7QjvbQ+dbmisAtOTyyNUOsiJXeo+2vJkk8=; b=klRbuCl0GZ4BboCwGPraJE8UBL0Q5vzmAFCuwtLQwWALSQtGmCMD6mX/rTQi76P/gkbDwfYo/PoJMOA2qc79LdwPGbOj82GY1jsquB9AWIgNf8Q1alBOMkQcYBAAxn1EcSOnHChEL7krDxHUmlZTRlhOp2xZZLaiQ7ACAwc3TQ8= ARC-Authentication-Results: i=1; mx.zohomail.com; spf=pass (zohomail.com: domain of redhat.com designates 63.128.21.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 [63.128.21.124]) by mx.zohomail.com with SMTPS id 1612314444170362.5536025396601; Tue, 2 Feb 2021 17:07: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-312-ywhFszupNeSr3zup7E0rsw-1; Tue, 02 Feb 2021 20:07:21 -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 01310189DF75; Wed, 3 Feb 2021 01:07:14 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id C90A21F475; Wed, 3 Feb 2021 01:07: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 946E318089CC; Wed, 3 Feb 2021 01:07:13 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 11316u7r010402 for ; Tue, 2 Feb 2021 20:06:56 -0500 Received: by smtp.corp.redhat.com (Postfix) id 1FAA32026D49; Wed, 3 Feb 2021 01:06:56 +0000 (UTC) Received: from mimecast-mx02.redhat.com (mimecast06.extmail.prod.ext.rdu2.redhat.com [10.11.55.22]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 1AD7E2026D47 for ; Wed, 3 Feb 2021 01:06:56 +0000 (UTC) Received: from us-smtp-1.mimecast.com (us-smtp-1.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 01B08185A794 for ; Wed, 3 Feb 2021 01:06:56 +0000 (UTC) Received: from mail-qk1-f175.google.com (mail-qk1-f175.google.com [209.85.222.175]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-205-0p0z2rUTMHOUV9MVsrKcow-1; Tue, 02 Feb 2021 20:06:51 -0500 Received: by mail-qk1-f175.google.com with SMTP id t63so21907363qkc.1; Tue, 02 Feb 2021 17:06:51 -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.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 02 Feb 2021 17:06:50 -0800 (PST) X-MC-Unique: ywhFszupNeSr3zup7E0rsw-1 X-MC-Unique: 0p0z2rUTMHOUV9MVsrKcow-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=4c58XIVKa7QjvbQ+dbmisAtOTyyNUOsiJXeo+2vJkk8=; b=KVYbw9kpKVXsXGU8SJIRHgDP4B5PAWOUFjBYC3EY0K1gu5eW95679vtH8GYXH6QsEY avNmbHzeul1qpTbjncuypLC42i/B9O2hqKqqId4PpsjeWIW/hewNNbXXySGfr97cofMz pfyIrFIyaNY/5qEXrDS9orxJFb2PCFonT9HFyPNc4BswVroRamtmPZUV20VE2xH8LQrd TnhZeGwSMp32bMBHAdkOoLccePXOrBW6teU5zxSX/EFJlEzXxWiHKKGUgfH9JNaD9b85 aO8uIiHPCEciCGOxYp8NmoUIgNGNOxiLCpMaDxccBgkQg/SuwVin6SFlped7WJWEEtxE FjNA== X-Gm-Message-State: AOAM530ukBgMiAzmRsy8RKFn2u3cSC2D2+AjvjUAS25nsutFEbJcSvj9 e7nW95HZ7Rzgr6LbQRAMWI2SONuA7MU= X-Google-Smtp-Source: ABdhPJzTfU+gCe2DS6gYe1YRqTPjEIkXoA6wZUHHDVKCBjmqRGlDtwrF5X+9cuJWvDI/l+XMNjHqfQ== X-Received: by 2002:a05:620a:711:: with SMTP id 17mr404000qkc.501.1612314410698; Tue, 02 Feb 2021 17:06:50 -0800 (PST) From: Daniel Henrique Barboza To: libvir-list@redhat.com Subject: [PATCH v2 08/10] qemu, libxl, hypervisor: use virDomainDriverNodeDeviceDetachFlags() helper Date: Tue, 2 Feb 2021 22:06:23 -0300 Message-Id: <20210203010625.2328911-9-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.4 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.84 on 10.5.11.23 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 libxlNodeDeviceDetachFlags() and qemuNodeDeviceDetachFlags() are mostly equal, aside from how the virHostdevmanager pointer is retrieved and the PCI stub driver used. Now that the PCI stub driver verification is done early in both functions, we can use the virDomainDriverNodeDeviceDetachFlags() helper to reduce code duplication between them. 'driverName' is checked inside the helper to set the appropriate stub driver. The helper is named with the 'Flags' suffix, even when the helper itself isn't receiving the flags from the callers, to be compliant with the ACL function virNodeDeviceDetachFlagsEnsureACL() that is being called inside it and was called from the original functions. Renaming the helper would implicate in renaming REMOTE_PROC_NODE_DEVICE_DETACH_FLAGS, and all t= he related structs inside remote_protocol.x, to be compliant with the ACL rules. This is not being checked at this moment, but we'll fix check-aclrules.py to verify all the helpers that calls ACL functions in domain_driver.c shortly. Reviewed-by: J=C3=A1n Tomko Signed-off-by: Daniel Henrique Barboza --- src/hypervisor/domain_driver.c | 60 ++++++++++++++++++++++++++++++++++ src/hypervisor/domain_driver.h | 4 +++ src/libvirt_private.syms | 1 + src/libxl/libxl_driver.c | 54 ++---------------------------- src/qemu/qemu_driver.c | 49 ++------------------------- 5 files changed, 71 insertions(+), 97 deletions(-) diff --git a/src/hypervisor/domain_driver.c b/src/hypervisor/domain_driver.c index ea4c3c9466..6ee74d6dff 100644 --- a/src/hypervisor/domain_driver.c +++ b/src/hypervisor/domain_driver.c @@ -459,3 +459,63 @@ virDomainDriverNodeDeviceReAttach(virNodeDevicePtr dev, =20 return virHostdevPCINodeDeviceReAttach(hostdevMgr, pci); } + +int +virDomainDriverNodeDeviceDetachFlags(virNodeDevicePtr dev, + virHostdevManagerPtr hostdevMgr, + const char *driverName) +{ + virPCIDevicePtr pci =3D NULL; + virPCIDeviceAddress devAddr; + int ret =3D -1; + virNodeDeviceDefPtr def =3D NULL; + g_autofree char *xml =3D NULL; + virConnectPtr nodeconn =3D NULL; + virNodeDevicePtr nodedev =3D NULL; + + if (!driverName) + return -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 (virNodeDeviceDetachFlagsEnsureACL(dev->conn, def) < 0) + goto cleanup; + + if (virDomainDriverNodeDeviceGetPCIInfo(def, &devAddr) < 0) + goto cleanup; + + pci =3D virPCIDeviceNew(&devAddr); + if (!pci) + goto cleanup; + + if (STREQ(driverName, "vfio")) + virPCIDeviceSetStubDriver(pci, VIR_PCI_STUB_DRIVER_VFIO); + else if (STREQ(driverName, "xen")) + virPCIDeviceSetStubDriver(pci, VIR_PCI_STUB_DRIVER_XEN); + + ret =3D virHostdevPCINodeDeviceDetach(hostdevMgr, pci); + cleanup: + virPCIDeviceFree(pci); + virNodeDeviceDefFree(def); + virObjectUnref(nodedev); + virObjectUnref(nodeconn); + return ret; +} diff --git a/src/hypervisor/domain_driver.h b/src/hypervisor/domain_driver.h index 71eed6d5a9..a22a3ee76c 100644 --- a/src/hypervisor/domain_driver.h +++ b/src/hypervisor/domain_driver.h @@ -56,3 +56,7 @@ int virDomainDriverNodeDeviceReset(virNodeDevicePtr dev, =20 int virDomainDriverNodeDeviceReAttach(virNodeDevicePtr dev, virHostdevManagerPtr hostdevMgr); + +int virDomainDriverNodeDeviceDetachFlags(virNodeDevicePtr dev, + virHostdevManagerPtr hostdevMgr, + const char *driverName); diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index ed01f79106..57622dc9a7 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -1503,6 +1503,7 @@ virDomainCgroupSetupMemtune; virDomainDriverGenerateMachineName; virDomainDriverGenerateRootHash; virDomainDriverMergeBlkioDevice; +virDomainDriverNodeDeviceDetachFlags; virDomainDriverNodeDeviceGetPCIInfo; virDomainDriverNodeDeviceReAttach; virDomainDriverNodeDeviceReset; diff --git a/src/libxl/libxl_driver.c b/src/libxl/libxl_driver.c index eadacdfb76..a644593dd9 100644 --- a/src/libxl/libxl_driver.c +++ b/src/libxl/libxl_driver.c @@ -5779,15 +5779,8 @@ libxlNodeDeviceDetachFlags(virNodeDevicePtr dev, const char *driverName, unsigned int flags) { - 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; =20 virCheckFlags(0, -1); =20 @@ -5797,50 +5790,9 @@ libxlNodeDeviceDetachFlags(virNodeDevicePtr dev, return -1; } =20 - 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 (virNodeDeviceDetachFlagsEnsureACL(dev->conn, def) < 0) - goto cleanup; - - if (virDomainDriverNodeDeviceGetPCIInfo(def, &devAddr) < 0) - goto cleanup; - - pci =3D virPCIDeviceNew(&devAddr); - if (!pci) - goto cleanup; - - virPCIDeviceSetStubDriver(pci, VIR_PCI_STUB_DRIVER_XEN); - - if (virHostdevPCINodeDeviceDetach(hostdev_mgr, pci) < 0) - goto cleanup; - - ret =3D 0; - cleanup: - virPCIDeviceFree(pci); - virNodeDeviceDefFree(def); - virObjectUnref(nodedev); - virObjectUnref(nodeconn); - VIR_FREE(xml); - return ret; + /* virNodeDeviceDetachFlagsEnsureACL() is being called by + * virDomainDriverNodeDeviceDetachFlags() */ + return virDomainDriverNodeDeviceDetachFlags(dev, hostdev_mgr, driverNa= me); } =20 static int diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index c6ba33e4ad..21ce143764 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -11970,15 +11970,8 @@ qemuNodeDeviceDetachFlags(virNodeDevicePtr dev, unsigned int flags) { virQEMUDriverPtr driver =3D dev->conn->privateData; - virPCIDevicePtr pci =3D NULL; - virPCIDeviceAddress devAddr; - int ret =3D -1; - virNodeDeviceDefPtr def =3D NULL; - 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 @@ -12001,46 +11994,10 @@ qemuNodeDeviceDetachFlags(virNodeDevicePtr dev, return -1; } =20 - 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; =20 - /* ACL check must happen against original 'dev', - * not the new 'nodedev' we acquired */ - if (virNodeDeviceDetachFlagsEnsureACL(dev->conn, def) < 0) - goto cleanup; - - if (virDomainDriverNodeDeviceGetPCIInfo(def, &devAddr) < 0) - goto cleanup; - - pci =3D virPCIDeviceNew(&devAddr); - if (!pci) - goto cleanup; - - virPCIDeviceSetStubDriver(pci, VIR_PCI_STUB_DRIVER_VFIO); - - ret =3D virHostdevPCINodeDeviceDetach(hostdev_mgr, pci); - cleanup: - virPCIDeviceFree(pci); - virNodeDeviceDefFree(def); - virObjectUnref(nodedev); - virObjectUnref(nodeconn); - return ret; + /* virNodeDeviceDetachFlagsEnsureACL() is being called by + * virDomainDriverNodeDeviceDetachFlags() */ + return virDomainDriverNodeDeviceDetachFlags(dev, hostdev_mgr, driverNa= me); } =20 static int --=20 2.26.2 From nobody Sun May 5 19:55:54 2024 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=1612314446; cv=none; d=zohomail.com; s=zohoarc; b=fuKDLPQatqK8ym3I4wdvzWNLRNKaSDr+ORa9wjYr93mmCyShKltnWPV1gdwR7soUwAGTu0weW7awpBv/JehCy6/SPoqDrqWQ2MX1fs4NgpLLcy2w1Gxox0UIMK00fX26gRT8HdxGK3/eQXhUNTK/KJr6hZg+DFQ+zmV3AI0sSk0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1612314446; 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=y/qWRsMyow/m1RmFEmR0AiSsu+uD+R+UmjW0YN29WuE=; b=i107GsUVARZ4godFqsAX78SVr32nqmbw9PK+YLBwrCYFZU+HyRiKS1mGjqGnrC/6Sfu4ggw7IccEaSW0co3sHbM3+msqQhbvIU/KC+CJYMigR8D4qo3tcMOdhy6FdjKTixc6g9H8SCYB6BnzQq3nKAUWneldOlrrxNXEOIVLzsM= 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 1612314446109968.9772558923914; Tue, 2 Feb 2021 17:07:26 -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-593-FDjf1MKkMnCcbvBweojdMg-1; Tue, 02 Feb 2021 20:07:22 -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 84146801ABA; Wed, 3 Feb 2021 01:07:13 +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 5BCE05D9F1; Wed, 3 Feb 2021 01:07: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 231401809C92; Wed, 3 Feb 2021 01:07:13 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 11316wwp010420 for ; Tue, 2 Feb 2021 20:06:58 -0500 Received: by smtp.corp.redhat.com (Postfix) id 01358100416A; Wed, 3 Feb 2021 01:06:58 +0000 (UTC) Received: from mimecast-mx02.redhat.com (mimecast03.extmail.prod.ext.rdu2.redhat.com [10.11.55.19]) by smtp.corp.redhat.com (Postfix) with ESMTPS id EEE2911422D8 for ; Wed, 3 Feb 2021 01:06:57 +0000 (UTC) Received: from us-smtp-1.mimecast.com (us-smtp-1.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 41A06811E87 for ; Wed, 3 Feb 2021 01:06:57 +0000 (UTC) Received: from mail-qk1-f181.google.com (mail-qk1-f181.google.com [209.85.222.181]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-491-naF3OO4QMP27rhHJa_o_Rw-1; Tue, 02 Feb 2021 20:06:53 -0500 Received: by mail-qk1-f181.google.com with SMTP id d85so21883167qkg.5; Tue, 02 Feb 2021 17:06:53 -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.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 02 Feb 2021 17:06:52 -0800 (PST) X-MC-Unique: FDjf1MKkMnCcbvBweojdMg-1 X-MC-Unique: naF3OO4QMP27rhHJa_o_Rw-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=y/qWRsMyow/m1RmFEmR0AiSsu+uD+R+UmjW0YN29WuE=; b=GYIsxHTrFM6Iq3QJXjQJcyIk+ON2iHlq4/eDZo9opuN+TmPlI1WDZwSR29rK8/27Yb rO6c5phYCTtbf9x51nmHsppocrvG1lzTND+9ftDaAGy6c35xzAbvlmZwUr/ZGJuWHDZe kQQZ7b+IYShoYB4MPPFaaf4jNvMEBeWtOn0QsDhBhoqrOeAEEbersyEznPQHSSFmdGI0 DhGg4b+es6GRg5npVE8s0YshBsjXbIFNRKcPqbFfL+42mMqBvEhqqncYVB1hlUQqzK6d 2tlVlf/P54J9gPeeuTQejb6PzmqA0qqSmm2fF9N/zxeR6wbZW9NI55eBLCOIdzTiOWCD 4iew== X-Gm-Message-State: AOAM530XHyvQAQOnuThulLV0tuLxYq05sy8oXJV5l8Kvk2xjd7YCQlVc Of4n8ILUMRps05qMY8wlTQ4cZl2kCus= X-Google-Smtp-Source: ABdhPJzvakcCbt181klVn98MHF+yvKOYJvcUYAa0HhBxMMnjr2Q0ObjXSrS3reyTvIjTmn9qGphb6Q== X-Received: by 2002:a37:8485:: with SMTP id g127mr423773qkd.233.1612314412664; Tue, 02 Feb 2021 17:06:52 -0800 (PST) From: Daniel Henrique Barboza To: libvir-list@redhat.com Subject: [PATCH v2 09/10] domain_driver.c: use g_auto* in virDomainDriverNodeDeviceDetachFlags() Date: Tue, 2 Feb 2021 22:06:24 -0300 Message-Id: <20210203010625.2328911-10-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.3 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.14 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 Reviewed-by: J=C3=A1n Tomko Signed-off-by: Daniel Henrique Barboza --- src/hypervisor/domain_driver.c | 31 ++++++++++++------------------- 1 file changed, 12 insertions(+), 19 deletions(-) diff --git a/src/hypervisor/domain_driver.c b/src/hypervisor/domain_driver.c index 6ee74d6dff..c08b7d46c5 100644 --- a/src/hypervisor/domain_driver.c +++ b/src/hypervisor/domain_driver.c @@ -465,57 +465,50 @@ virDomainDriverNodeDeviceDetachFlags(virNodeDevicePtr= dev, virHostdevManagerPtr hostdevMgr, const char *driverName) { - virPCIDevicePtr pci =3D NULL; + g_autoptr(virPCIDevice) pci =3D NULL; virPCIDeviceAddress devAddr; - int ret =3D -1; - virNodeDeviceDefPtr def =3D NULL; + g_autoptr(virNodeDeviceDef) def =3D NULL; g_autofree char *xml =3D NULL; - virConnectPtr nodeconn =3D NULL; - virNodeDevicePtr nodedev =3D NULL; + g_autoptr(virConnect) nodeconn =3D NULL; + g_autoptr(virNodeDevice) nodedev =3D NULL; =20 if (!driverName) return -1; =20 if (!(nodeconn =3D virGetConnectNodeDev())) - goto cleanup; + return -1; =20 /* '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; + return -1; =20 xml =3D virNodeDeviceGetXMLDesc(nodedev, 0); if (!xml) - goto cleanup; + return -1; =20 def =3D virNodeDeviceDefParseString(xml, EXISTING_DEVICE, NULL); if (!def) - goto cleanup; + return -1; =20 /* ACL check must happen against original 'dev', * not the new 'nodedev' we acquired */ if (virNodeDeviceDetachFlagsEnsureACL(dev->conn, def) < 0) - goto cleanup; + return -1; =20 if (virDomainDriverNodeDeviceGetPCIInfo(def, &devAddr) < 0) - goto cleanup; + return -1; =20 pci =3D virPCIDeviceNew(&devAddr); if (!pci) - goto cleanup; + return -1; =20 if (STREQ(driverName, "vfio")) virPCIDeviceSetStubDriver(pci, VIR_PCI_STUB_DRIVER_VFIO); else if (STREQ(driverName, "xen")) virPCIDeviceSetStubDriver(pci, VIR_PCI_STUB_DRIVER_XEN); =20 - ret =3D virHostdevPCINodeDeviceDetach(hostdevMgr, pci); - cleanup: - virPCIDeviceFree(pci); - virNodeDeviceDefFree(def); - virObjectUnref(nodedev); - virObjectUnref(nodeconn); - return ret; + return virHostdevPCINodeDeviceDetach(hostdevMgr, pci); } --=20 2.26.2 From nobody Sun May 5 19:55:54 2024 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=1612314446; cv=none; d=zohomail.com; s=zohoarc; b=LJNKnDWQzuFK9ekhdgXRSUVlStTJDb9dHzM1u9m3zLv26koU4U2bdXQuxRpULn0VcWoIIB/c0Qktra9xw/w81TnQUViimU71clf726Gg2aJasY0Ov17DUzAn+ZwzfWsX9EOpIEop0SHzi2y7vlhv2TAyEYNoKt5ujr8S658EtG0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1612314446; 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=yJi1LFad/V6qAL52wBAHa5TWiGxgIcdAMXhrAZq8TKU=; b=j28ZUM0MI7fblCVCzzuFU7gzEoKniMMnOWi3k7c66CRlS2y8LBGFSfUJYN+zAfgCsNA7PmgVn+2pnCEtm9LSBCPV6i6eUtTVUf8CrmfYo3BTSTDotsx1xGEgssK7E9xmn62EH3nLJHECuFougB5sQwb/0LocRzR9h2/nTSZbvUM= 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 1612314446696444.12321141259883; Tue, 2 Feb 2021 17:07:26 -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-353-tvRK6VJFNOuwJ-Eil_f1Ig-1; Tue, 02 Feb 2021 20:07:22 -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 B94D8189DF57; Wed, 3 Feb 2021 01:07:16 +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 932D26E510; Wed, 3 Feb 2021 01:07:16 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 61FBA50045; Wed, 3 Feb 2021 01:07:16 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 11316ve3010407 for ; Tue, 2 Feb 2021 20:06:57 -0500 Received: by smtp.corp.redhat.com (Postfix) id F2B6FBE5D3; Wed, 3 Feb 2021 01:06:56 +0000 (UTC) Received: from mimecast-mx02.redhat.com (mimecast06.extmail.prod.ext.rdu2.redhat.com [10.11.55.22]) by smtp.corp.redhat.com (Postfix) with ESMTPS id EDA27F00D6 for ; Wed, 3 Feb 2021 01:06:56 +0000 (UTC) Received: from us-smtp-1.mimecast.com (us-smtp-delivery-1.mimecast.com [207.211.31.120]) (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 DA546185A794 for ; Wed, 3 Feb 2021 01:06:56 +0000 (UTC) Received: from mail-qv1-f54.google.com (mail-qv1-f54.google.com [209.85.219.54]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-509-cybb3tdXN3S5P_cEkB3fvg-1; Tue, 02 Feb 2021 20:06:55 -0500 Received: by mail-qv1-f54.google.com with SMTP id n14so10924292qvg.5 for ; Tue, 02 Feb 2021 17:06:54 -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.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 02 Feb 2021 17:06:53 -0800 (PST) X-MC-Unique: tvRK6VJFNOuwJ-Eil_f1Ig-1 X-MC-Unique: cybb3tdXN3S5P_cEkB3fvg-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=yJi1LFad/V6qAL52wBAHa5TWiGxgIcdAMXhrAZq8TKU=; b=WpiunRd9Eq1KKuRZt5dlkMVRuudI2TTot50HF+h/b+Xw4+WDFv/HOvZJsPLR1+3n8r IsRxMIUFUF9MNT93L86sLXK0WTAk5eO24Bq4j6ASOEImEui00ohhm+HzRCek8SJK+1Ao EN9a6id2vRR/Z7zVhj5N3TLL3UuVKWDiAVIysIHSqE+UndpMMyLVxE3BcALJ84YqiFfW ikcDsFWNRg1lzRGSuBdnu60wEBgcnO2lcnXRCQn97hab6HSUW4CYsXlC4SCZifr7fmpS JGbQDePP2qli95BSuGijsXhjSpiGDklAQjfExXJIO8OXQ22clDIngvFA4HdbXhrmRTkz 3rsw== X-Gm-Message-State: AOAM533CCdCdq+qtkf/L9AJ2UUGgzkYYP7o75Ml5DnobhnDKtto08vpJ jKEy9mqlGhHlP0/UwyGw78qQzbGU0fU= X-Google-Smtp-Source: ABdhPJykyFWh+GyZEQszpz+Owsou2UVEf9XZhL5EcoiKXYJQAv7QZ/0jcFCUjpxMkS8dA+f0uB7Ruw== X-Received: by 2002:ad4:49af:: with SMTP id u15mr852096qvx.20.1612314414361; Tue, 02 Feb 2021 17:06:54 -0800 (PST) From: Daniel Henrique Barboza To: libvir-list@redhat.com Subject: [PATCH v2 10/10] scripts/check-aclrules.py: check ACL for domain_driver.c ACL callers Date: Tue, 2 Feb 2021 22:06:25 -0300 Message-Id: <20210203010625.2328911-11-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.79 on 10.11.54.5 X-loop: libvir-list@redhat.com Cc: Daniel Henrique Barboza 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 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-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" This script works under two specific conditions. For each opened file, search for all functions that has ACL calls and store them, and see if there is a vir*DriverPtr struct declared in it. For each implementation found, check if there is an ACL verification inside it, and error out if none was found. The script also supports the concept of stub, where another function takes the responsibility for the ACL call instead of the original API. Unfortunately this is not enough to cover the new scenario we have now, with domain_driver.c containing helper functions that execute the ACL calls. The script does not store state between files because, until now, it wasn't needed to - APIs and stubs and vir*DriverPtr declarations were always in the same file. Also, the script will not check for ACL in functio= ns that does not belong to a vir*DriverPtr interface. What we have now in domain_driver.c breaks both assumptions: the functions are in a different file, and there is no vir*DriverPtr being implemented in the file that uses these functions. This patch changes check-aclrules.py to accomodate this scenario. The helpe= rs that have ACL checks are stored beforehand in aclFuncHelpers, allowing other files to use them to recognize a stub situation. In case the current file being analyzed is domain_driver.c itself, we'll do a manual check using aclFuncHelpers to verify that these functions indeed have ACL checks. Signed-off-by: Daniel Henrique Barboza --- scripts/check-aclrules.py | 25 ++++++++++++++++++++++++- src/hypervisor/meson.build | 2 ++ 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/scripts/check-aclrules.py b/scripts/check-aclrules.py index 2335e8cfdd..ed6805058b 100755 --- a/scripts/check-aclrules.py +++ b/scripts/check-aclrules.py @@ -62,6 +62,14 @@ implpermitted =3D { "vzDomainMigrateConfirm3Params": True, } =20 +aclFuncHelpers =3D { + "virDomainDriverNodeDeviceDetachFlags": True, + "virDomainDriverNodeDeviceReset": True, + "virDomainDriverNodeDeviceReAttach": True, +} + +aclFuncHelperFile =3D "domain_driver.c" + lastfile =3D None =20 =20 @@ -136,8 +144,14 @@ def process_file(filename): maybefunc =3D None intable =3D False table =3D None + aclHelperFileCheck =3D False + + acls =3D aclFuncHelpers + + if aclFuncHelperFile in filename: + acls =3D {} + aclHelperFileCheck =3D True =20 - acls =3D {} aclfilters =3D {} errs =3D False with open(filename, "r") as fh: @@ -262,6 +276,15 @@ def process_file(filename): if "}" in line: brace =3D brace - 1 =20 + if aclHelperFileCheck: + for helper in aclFuncHelpers: + if helper not in acls: + print(("%s:%d Missing ACL check in helper function '%s'") % + (filename, lineno, helper), + file=3Dsys.stderr) + + errs =3D True + return errs =20 =20 diff --git a/src/hypervisor/meson.build b/src/hypervisor/meson.build index 32d5ab365f..70801c0820 100644 --- a/src/hypervisor/meson.build +++ b/src/hypervisor/meson.build @@ -5,6 +5,8 @@ hypervisor_sources =3D [ 'virhostdev.c', ] =20 +stateful_driver_source_files +=3D files(hypervisor_sources) + hypervisor_lib =3D static_library( 'virt_hypervisor', [ --=20 2.26.2