From nobody Mon Apr 29 15:22:14 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=1612180039; cv=none; d=zohomail.com; s=zohoarc; b=C/f+rHwRQYIrEblhPWozJvIvE8Er5U/dZUNqLvfz4Ag+ekupVZupDssx6PisBs6wttf+VmwJikofA0ag1ReOTRE/4VpHqOjv65iaTzFDp79l4XTWmd3RqaxLWpTgyZy9IZqDxf+SNLXk0KZ5zpi1PsnrHBYpPkU7SB5zF7CfzRM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1612180039; 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=vue6nIh5LvIfd4UzB5QGJLgIsGZp7ld/xsU4r6V4BPQ=; b=bM/PZH37lU+lOn3h6ZOWk3CoyQxahJt63zp7TlJU7uFuO00aOn/Lk90TVNg7bbMwSBBtDH8Y1RMK7higr6kjWi+roh27BRUKZbfQ6cISKMP29BvLlsSfPLS+fLcR1OTYK6iuIg863vq0bVkHuMCxmsV4sjuUARqRsAD/b7wZpoo= 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 1612180039893305.4396513706547; Mon, 1 Feb 2021 03:47:19 -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-289--J8rPHQRN6OAszfjL4-5vw-1; Mon, 01 Feb 2021 06:47:16 -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 12D7F612AC; Mon, 1 Feb 2021 11:47: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 DCBA65DA2E; Mon, 1 Feb 2021 11:47: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 9DDAF5003C; Mon, 1 Feb 2021 11:47:10 +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 111BkwLk005706 for ; Mon, 1 Feb 2021 06:46:58 -0500 Received: by smtp.corp.redhat.com (Postfix) id 7D9902166B28; Mon, 1 Feb 2021 11:46:58 +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 781D72166B27 for ; Mon, 1 Feb 2021 11:46:54 +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 B8A7288CC4C for ; Mon, 1 Feb 2021 11:46:54 +0000 (UTC) Received: from mail-qt1-f181.google.com (mail-qt1-f181.google.com [209.85.160.181]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-549-TmEB_VVBMdiT9TRKPPEbJA-1; Mon, 01 Feb 2021 06:46:52 -0500 Received: by mail-qt1-f181.google.com with SMTP id r20so8377235qtm.3 for ; Mon, 01 Feb 2021 03:46:52 -0800 (PST) Received: from rekt.ibmuc.com ([2804:431:c7c6:6df1:6267:881f:cc79:a1f7]) by smtp.gmail.com with ESMTPSA id t6sm13671374qti.2.2021.02.01.03.46.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 01 Feb 2021 03:46:51 -0800 (PST) X-MC-Unique: -J8rPHQRN6OAszfjL4-5vw-1 X-MC-Unique: TmEB_VVBMdiT9TRKPPEbJA-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=vue6nIh5LvIfd4UzB5QGJLgIsGZp7ld/xsU4r6V4BPQ=; b=pnThBkspln2OsPIxcyHMBriEqCRXOgIRnVakmQ4JGNmeCVEmujsMSFXWL8VDR1DJPx lTZcRvSOXc6PvlyaqQ9oQGqeJ2gM5WgJN3Hypni9o6TF1amwyxzTW8ZoEFgd29fZ0Rmc h0oFWvR2XKNcsvdjbpMNs8Pui7Vkm3oR+wL8U6PlWerzz/udh4gEF/ejF4KE0C6Y8XDe bs6vgnvN5uJb8jMuyg5pK5Iyad/bhHNhGvG/Ic8Ffig9igdQEOVmypvtHFuvmgXHzud0 A52B3TpkTAF3G6zXi8I4pCUO0f5ZEdiJfSpjeQuK4aUjnQ3W2ZsELQqZm/WgcCoMCy5t Cf1g== X-Gm-Message-State: AOAM531VXsGyd3d096iVDuTYw+j89LoSips794YgGzMmTYdObMU5ny24 eFhyKtWtAyObobFdNNvKGkbUBRDL46I= X-Google-Smtp-Source: ABdhPJzhkzIp3pNTKQZXGPlPhRHkVvCBNKPbIryWMveyjNY4Q0cj7oGByoi8v9rUo3X8SpSRZZui4g== X-Received: by 2002:ac8:1283:: with SMTP id y3mr5303524qti.328.1612180012003; Mon, 01 Feb 2021 03:46:52 -0800 (PST) From: Daniel Henrique Barboza To: libvir-list@redhat.com Subject: [PATCH 1/9] qemu, libxl, hypervisor: use virDomainDriverNodeDeviceReset() helper Date: Mon, 1 Feb 2021 08:46:34 -0300 Message-Id: <20210201114642.1947595-2-danielhb413@gmail.com> In-Reply-To: <20210201114642.1947595-1-danielhb413@gmail.com> References: <20210201114642.1947595-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 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-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" libxlNodeDeviceReset() and qemuNodeDeviceReset() are mostly equal, differing only how the virHostdevManager pointer is retrieved. Put the common code into virDomainDriverNodeDeviceReset() to reduce code duplication. Signed-off-by: Daniel Henrique Barboza Reviewed-by: J=C3=A1n Tomko --- 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 3eaf106006..50baeb43b6 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 Mon Apr 29 15:22:14 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=1612180032; cv=none; d=zohomail.com; s=zohoarc; b=MfoUYvh4NoEF4/ONlRrkz5IPgNcPNXL02POhv8Pvrnn3QSFfI6/my9Al/S9WoT/jEcSAoVpyNWv4MD9yR+IPT4lmuookagjDEcFL8zdlYmbFrrovPFoFIukndo2SByHx86pDWbGLMO0HqW/eDpaP0KCk6cdRCe/ymJxLV2lv/iQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1612180032; 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=lF26DglqSWNM362vFvmYpPxa4FtAyY8HQO+p/Le+gn4=; b=M5F/BTKR/kyE3eZNXjT5/lKFNFUh4t8ymqBAcuuYRT6ZbJKHJ5QA8fLruh9waGiaFN+AWuLPcPtLaOhXeH2xQe0UdSnjaevp+RY9cVLoqjW+62LAXksuYTMPc3DbpjFtPKYCeoFA0EGrR3ujXSL2Li3J4zerbv8vr9o3LABSBX8= 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 1612180032229701.0444273308383; Mon, 1 Feb 2021 03:47:12 -0800 (PST) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-389-sITzWMP3PzKme247jkZDEQ-1; Mon, 01 Feb 2021 06:47:08 -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 CD250800D62; Mon, 1 Feb 2021 11:47:02 +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 7C7526A8E5; Mon, 1 Feb 2021 11:47:01 +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 D96BA4A7C6; Mon, 1 Feb 2021 11:46:59 +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 111Bkw0F005707 for ; Mon, 1 Feb 2021 06:46:58 -0500 Received: by smtp.corp.redhat.com (Postfix) id 869A1111144C; Mon, 1 Feb 2021 11:46:58 +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 8319410031E5 for ; Mon, 1 Feb 2021 11:46: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 0735C805B7A for ; Mon, 1 Feb 2021 11:46:56 +0000 (UTC) Received: from mail-qk1-f170.google.com (mail-qk1-f170.google.com [209.85.222.170]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-39-tUR_MwfEMwat6QkSF1tqwg-1; Mon, 01 Feb 2021 06:46:54 -0500 Received: by mail-qk1-f170.google.com with SMTP id k193so15831905qke.6 for ; Mon, 01 Feb 2021 03:46:53 -0800 (PST) Received: from rekt.ibmuc.com ([2804:431:c7c6:6df1:6267:881f:cc79:a1f7]) by smtp.gmail.com with ESMTPSA id t6sm13671374qti.2.2021.02.01.03.46.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 01 Feb 2021 03:46:52 -0800 (PST) X-MC-Unique: sITzWMP3PzKme247jkZDEQ-1 X-MC-Unique: tUR_MwfEMwat6QkSF1tqwg-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=lF26DglqSWNM362vFvmYpPxa4FtAyY8HQO+p/Le+gn4=; b=tr7qYUPI3j7i4bIaq/Z23brzZT1JBYiY2CcOyWY7CDMBm5to9GKaQRz1PZLRcNvdG6 89Tt2UAi+wqZdxw2i0huPYLx2SiRaWMpV5bnDN5aeZzo6OxS2yynOGrzhsE4wnJ5WGK+ pSqdyseQqqLyiTiWhZUCXRkFuW9tNvA65dc/G6d1GNYm4e+uQQ4q/2MZxpAjfqTcJkqp +0cekWQOh3T/QWwv98oAhh/fs6kuAHs19+d/cK5T3gktCGfE/EOuH20zcG68pUgEEvpX 9AzKcIwOO/Msbw3tGERjEelIGayrLZHWw3+bduqzDNSb3CV+3VqOv+y8CH57F8ENMcxV xRtw== X-Gm-Message-State: AOAM530RQHiuCj5i6r9MVdQDhJXbbW86EnIgy7yQba0NV8nHqkQNWwuM X5+mZWVUDy4UKj7G5hkRmEZP8GeAOT4= X-Google-Smtp-Source: ABdhPJwh3muG0NdExXTHpfY0A8mcaqNRt7gZjcLkkD4RVf4SithecCrJIZf9c4VpIvJjhlTYQjLG+A== X-Received: by 2002:a37:8dc7:: with SMTP id p190mr15357840qkd.308.1612180013330; Mon, 01 Feb 2021 03:46:53 -0800 (PST) From: Daniel Henrique Barboza To: libvir-list@redhat.com Subject: [PATCH 2/9] datatypes.h: register AUTOPTR_CLEANUP_FUNC for virNodeDevicePtr Date: Mon, 1 Feb 2021 08:46:35 -0300 Message-Id: <20210201114642.1947595-3-danielhb413@gmail.com> In-Reply-To: <20210201114642.1947595-1-danielhb413@gmail.com> References: <20210201114642.1947595-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 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-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Next patch will use g_autoptr() with virNodeDevicePtr for cleanups. Signed-off-by: Daniel Henrique Barboza Reviewed-by: J=C3=A1n Tomko --- 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 Mon Apr 29 15:22:14 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=1612180032; cv=none; d=zohomail.com; s=zohoarc; b=P2dZbSyT54mEyUE1KrsRH+Yb2YybNodZIuMpgvuMz/mVD+Jky1uoOBGidL5fXMU4h0oZc0Rz2YrWbOnX1QEGQ9ZFhr4sVXhRWNbO11PaHlJQy4fErEjtx7K55jcraf0bU5a3rYGs0ru9DYxREi+tz9SJbkp5xp3XzmC+oDrt4lw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1612180032; 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=wMmuGY/UpzWka7F4CXvYHp9Jd19zxpoBGsfaMXF3hYQ=; b=aRkqwazouNK4FJ9jM4rCDJHMHzUpC2G9W+9a8lMIoDKCNwlF19EX6cmLo62zAh9z7VH/O5iGTa95JP6/iw4F6BU6cZI4XFaDkOunkmv5t+nrKMrGjYKoHrunIMXb9cMYuNJGkYVY2B6s6jssxJ90NjmS2wozWXu63mT3JfB1OeU= 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 1612180032338348.1414540078964; Mon, 1 Feb 2021 03:47:12 -0800 (PST) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-441-aXwm9NQ1NoqeWNv1QgCu0w-1; Mon, 01 Feb 2021 06:47:09 -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 39AD85B361; Mon, 1 Feb 2021 11:47:03 +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 154AA60D06; Mon, 1 Feb 2021 11:47:03 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id C790D1809C9F; Mon, 1 Feb 2021 11:47:02 +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 111Bl0uR005719 for ; Mon, 1 Feb 2021 06:47:00 -0500 Received: by smtp.corp.redhat.com (Postfix) id 6CAE044076; Mon, 1 Feb 2021 11:47:00 +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 66BFD6379F for ; Mon, 1 Feb 2021 11:46:57 +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 8A731187504F for ; Mon, 1 Feb 2021 11:46:57 +0000 (UTC) Received: from mail-qk1-f180.google.com (mail-qk1-f180.google.com [209.85.222.180]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-239-nVH1RuG3Pfmeyw7a13p4UA-1; Mon, 01 Feb 2021 06:46:55 -0500 Received: by mail-qk1-f180.google.com with SMTP id a12so15818493qkh.10 for ; Mon, 01 Feb 2021 03:46:55 -0800 (PST) Received: from rekt.ibmuc.com ([2804:431:c7c6:6df1:6267:881f:cc79:a1f7]) by smtp.gmail.com with ESMTPSA id t6sm13671374qti.2.2021.02.01.03.46.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 01 Feb 2021 03:46:54 -0800 (PST) X-MC-Unique: aXwm9NQ1NoqeWNv1QgCu0w-1 X-MC-Unique: nVH1RuG3Pfmeyw7a13p4UA-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=wMmuGY/UpzWka7F4CXvYHp9Jd19zxpoBGsfaMXF3hYQ=; b=kBK7GDyZsd2oM5RQ9K18s9/MAK7qyudmb+D6ygAcAYDWisK4SOYX3kLnlU6y5wMZfh L8iOH/TX3D3Hx6byKhXhFbx3zVroC0RcbXO0zNZe0XH2S/HoxsgrzrAZJvYBb5kw0R0U PlFWTXw9NYB/ZXxMAi21FOa8eBLa7Y5UENavvtiG2ezaavsnWP3EIV/fml3a3fRsvD/q emhY1DjXRZtot5Ew/PncgLZFiRRA4YIezg5XweE7I7P1+kX0s6VQ9y+PvXkZpUiVv8Fx 0KgN6i0y9QZt7uM2cwJ7Lm5RWgblBM7VQ87HcFv+95HtAY5d5eVF4tOiY1QW99h1shAr hmcg== X-Gm-Message-State: AOAM533hIb/TJraSk7qFfV+zdqEHbdH7IiH61J89Kec6H2EyQrfBdZcr 171XR5LGrl1dKHXrahTewTZQzg3UV7w= X-Google-Smtp-Source: ABdhPJxI9cSmZcpZkOrbT8FLekOzEmqHbD2ZADnfYcFmB1wNYEtHU5UcGq2Pki1ypg5SK0YQ/gW8Zg== X-Received: by 2002:a37:ad4:: with SMTP id 203mr15360970qkk.125.1612180014725; Mon, 01 Feb 2021 03:46:54 -0800 (PST) From: Daniel Henrique Barboza To: libvir-list@redhat.com Subject: [PATCH 3/9] domain_driver.c: use g_auto* in virDomainDriverNodeDeviceReset() Date: Mon, 1 Feb 2021 08:46:36 -0300 Message-Id: <20210201114642.1947595-4-danielhb413@gmail.com> In-Reply-To: <20210201114642.1947595-1-danielhb413@gmail.com> References: <20210201114642.1947595-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" Signed-off-by: Daniel Henrique Barboza Reviewed-by: J=C3=A1n Tomko --- 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 Mon Apr 29 15:22:14 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=1612180044; cv=none; d=zohomail.com; s=zohoarc; b=CFrTOiVuzEwLiZWDfKV1GN4eBZG/ckRc/N/LHH6zoXGOWE1TeHulPQ4UB2wUGLWe6MZzqrFzzeRiedRNZfGfzARHOwxIu5cy3R4sryiJMQIQFD36DJVkra/8jCzq6fjRTlByzOwUZt/DVo4uFlqF+O5D3DzxmzVkOP69hGwyGgI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1612180044; 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=hrVVUQ6belKGLbAa+ragqCx7VxMBEbBhTC8sdvAmI1A=; b=YNUmhbiJdeIhkxVozB/t4wse207KKRjE/l3VkLHHMg7VfHg+q1nUi50sJ6Vw5qqOZc28IvI1dxX7pV/3OYIZ17tDVdRZD9bx5qQTerfkd9XKhQoyA4taFM6DDCbGPNVlFKG55LkppGbNaw81gh1RElnHZ/f6F2oKRZ8oEFAA0jk= 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 1612180044148668.8877057577088; Mon, 1 Feb 2021 03:47: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-473-GMtYHRb6MRKRj8o6fh837w-1; Mon, 01 Feb 2021 06:47:21 -0500 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id E7E871005D59; Mon, 1 Feb 2021 11:47:11 +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 C1D461346F; Mon, 1 Feb 2021 11:47: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 887B41809CA2; Mon, 1 Feb 2021 11:47:11 +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 111Bl3SN005753 for ; Mon, 1 Feb 2021 06:47:03 -0500 Received: by smtp.corp.redhat.com (Postfix) id 1A4232166B29; Mon, 1 Feb 2021 11:47:03 +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 11D8A2166B2A for ; Mon, 1 Feb 2021 11:46:58 +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 BAC45803523 for ; Mon, 1 Feb 2021 11:46:58 +0000 (UTC) Received: from mail-qv1-f50.google.com (mail-qv1-f50.google.com [209.85.219.50]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-560-yyzjpDyUOSuO7lmXnFPRyw-1; Mon, 01 Feb 2021 06:46:56 -0500 Received: by mail-qv1-f50.google.com with SMTP id w11so7912900qvz.12 for ; Mon, 01 Feb 2021 03:46:56 -0800 (PST) Received: from rekt.ibmuc.com ([2804:431:c7c6:6df1:6267:881f:cc79:a1f7]) by smtp.gmail.com with ESMTPSA id t6sm13671374qti.2.2021.02.01.03.46.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 01 Feb 2021 03:46:55 -0800 (PST) X-MC-Unique: GMtYHRb6MRKRj8o6fh837w-1 X-MC-Unique: yyzjpDyUOSuO7lmXnFPRyw-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=hrVVUQ6belKGLbAa+ragqCx7VxMBEbBhTC8sdvAmI1A=; b=cAjZKiQ4iNr3Z+lIEoZeX3PuCx1dVH7He+yZ48T6atYzw/tyHhlceaBU8EQIXnttf7 TFx1ASqdde252giyYIhATowgz+UoRDzNvdWgfYhKY/6mlH561Qk0g1mAv4Pf3OmRRUzl FWunOPQTj6NDhSXRB+nChtHoZlUV5IXyDJBB6t+E+I5mLmOzBaeRRNBr7acLrEClzMBf 3XPaOyDeD0rWdYI9h7cQFjwX2+Y0yg2ooQjC2aIgWQ9pvpc2M+6hpiehQVVT0whu2eRo 5+vMMTswuuVru7Miag9WI9CZhfVNNke7xjg/1Z3TSlXDyQ23s/PjMAm58yvPC9jm6tz0 hOyg== X-Gm-Message-State: AOAM5326NcibNxUr4MLWcDvPEVUA95WI2bcDmhyUHGc/Z13pFvMv0YqZ fL1nm23U1nOM8xFzzxUt/nF6E6q4/+A= X-Google-Smtp-Source: ABdhPJxjw5K5gAj83+TDkEqi9urlRZNyQxNEXAuWPyKIenYeu3iyxBHLXI/nQ4GwvXS5yEsugbpTxg== X-Received: by 2002:a0c:d403:: with SMTP id t3mr14938906qvh.4.1612180016104; Mon, 01 Feb 2021 03:46:56 -0800 (PST) From: Daniel Henrique Barboza To: libvir-list@redhat.com Subject: [PATCH 4/9] qemu, libxl, hypervisor: use virDomainDriverNodeDeviceReAttach() helper Date: Mon, 1 Feb 2021 08:46:37 -0300 Message-Id: <20210201114642.1947595-5-danielhb413@gmail.com> In-Reply-To: <20210201114642.1947595-1-danielhb413@gmail.com> References: <20210201114642.1947595-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 X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 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" libxlNodeDeviceReAttach() and qemuNodeDeviceReAttach() are mostly equal, differing only how the virHostdevManager pointer is retrieved. Put the common code into virDomainDriverNodeDeviceReAttach() to reduce code duplication. Signed-off-by: Daniel Henrique Barboza Reviewed-by: J=C3=A1n Tomko --- 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 50baeb43b6..718717f14b 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 Mon Apr 29 15:22:14 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=1612180031; cv=none; d=zohomail.com; s=zohoarc; b=QWGf2bXRsMSCrhS1RP4lYoQl6vIsdCP0+ckHBpfejFDm8t4OO0tiqhNjVuRq2wq+RLfeeetfWkUclQasxsjwE/5eK/4cSw/N7JsLwRO3PI8ZmAUVPtQmAoGpP7KUB3Syx9PO8jL5ISL2QVuxXsRAQFZoHTyn2t0KiQjD4NlzHQM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1612180031; 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=kmf9ffjEmevf+SI/RVNdGY8X9XLrZDiLZwUkeWjP5Ew=; b=eny8Pirh5yADz4A//jEyaSbot49zC7bp4RcBRXz4T/tzUSFH8Qdj/w727YosihJeu2LjvkPLFSOOtF9+6X7EXUsd4ORE///q1CByLjbsqsDn6zwssRBYpCC3MLRcA1uumgO364oPDjI8XhKbaNkQ43OMiQNFUktzApvLv+pYSc4= 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 1612180031637685.7941106977789; Mon, 1 Feb 2021 03:47:11 -0800 (PST) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-30-L4MvoC8GOne2BBjAooF8pA-1; Mon, 01 Feb 2021 06:47:08 -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 17E5C10054FF; Mon, 1 Feb 2021 11:47:03 +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 DE52B3AE1; Mon, 1 Feb 2021 11:47:02 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 8279B180954D; Mon, 1 Feb 2021 11:47:02 +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 111Bl04f005717 for ; Mon, 1 Feb 2021 06:47:00 -0500 Received: by smtp.corp.redhat.com (Postfix) id 334BF111144D; Mon, 1 Feb 2021 11:47:00 +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 2E405111144C for ; Mon, 1 Feb 2021 11:47:00 +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 1C51A811E78 for ; Mon, 1 Feb 2021 11:47:00 +0000 (UTC) Received: from mail-qv1-f42.google.com (mail-qv1-f42.google.com [209.85.219.42]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-424-dxNESqTiMB2uzFB4yn_KuA-1; Mon, 01 Feb 2021 06:46:58 -0500 Received: by mail-qv1-f42.google.com with SMTP id n14so7937023qvg.5 for ; Mon, 01 Feb 2021 03:46:58 -0800 (PST) Received: from rekt.ibmuc.com ([2804:431:c7c6:6df1:6267:881f:cc79:a1f7]) by smtp.gmail.com with ESMTPSA id t6sm13671374qti.2.2021.02.01.03.46.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 01 Feb 2021 03:46:57 -0800 (PST) X-MC-Unique: L4MvoC8GOne2BBjAooF8pA-1 X-MC-Unique: dxNESqTiMB2uzFB4yn_KuA-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=kmf9ffjEmevf+SI/RVNdGY8X9XLrZDiLZwUkeWjP5Ew=; b=tfXFTLNOW7xX3z2lRsoit/EZf7j9lNiYQJqzyJ1gUnZxAtc26NSgjFpm0vgM2p5n+m LLky1WSTuhL4neLlZ9GBXPbD/6e8s2ehOA43WOI4smdUhzGhMUTh8ZGt8iAC2pYBfsQM qjnqq0Q13P/IKv9GeIIZ95Sj7ttrSANt3RMZ0gOXbx++ZQF6aQa9n6huRMEzoshpLyod w+sPdkSXXUDzUCNmy2yggN8nx6j6X10zZQZTCrhm3YdAwiknFQNnqwJ9FloYOFVX5FMZ R5Dpd3LvK4UgiaNybIQL+uBd6oulw8L7kHocTxyjUGHwL5QAKP2LvQLbLBZ5fA1aLRs6 TNsA== X-Gm-Message-State: AOAM530UjoAKsCodjKsQU657R4khNQDOXysKwFKI6PaGwBSgOqb+VWAz fA1wSLR6rE0gccdixmpW5TWfBColt4k= X-Google-Smtp-Source: ABdhPJyzOIDKrHR+GPROqp31+2QikFO1926nNlrQJCcefy4Xk80wnlhOWZRFS60Di/tR6/SEFAFqEA== X-Received: by 2002:ad4:576a:: with SMTP id r10mr14695972qvx.29.1612180017546; Mon, 01 Feb 2021 03:46:57 -0800 (PST) From: Daniel Henrique Barboza To: libvir-list@redhat.com Subject: [PATCH 5/9] domain_driver.c: use g_auto* in virDomainDriverNodeDeviceReAttach() Date: Mon, 1 Feb 2021 08:46:38 -0300 Message-Id: <20210201114642.1947595-6-danielhb413@gmail.com> In-Reply-To: <20210201114642.1947595-1-danielhb413@gmail.com> References: <20210201114642.1947595-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 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-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Signed-off-by: Daniel Henrique Barboza Reviewed-by: J=C3=A1n Tomko --- 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 Mon Apr 29 15:22:14 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=1612180039; cv=none; d=zohomail.com; s=zohoarc; b=KiabhvgHB0S4zxNmdS1SIQYW87G8CZcdrQ+URvDC9sKB7cKPStq9IVpOVEJi5+bz8DNvOsyXu++ezcGCZ1Isw1BJtIa5bmHPWMDO8v+HPjIwdc2cuAMF0GtwuEKSGefJZjufLZBs+tLXhUO0RReyWEPI9GwF9YQHYnd8IRw1aKY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1612180039; 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=UCLgMXkE3bt//UFrhFBE47eIS570dkQzFB1uTgUr7qg=; b=bBIyKu59vRvFRyeZuDXSWLSfwrxOe9SH/8aw/nJ+gsI9z11Vzia7OGwfwf6EE+vMxMdV6AWUdR9rgiTPrDk6Qdhi9dmTgZqRhPg5D9Ysekswkeih372s4OhfxELT3Dg02iLn4Q154QnmfGJGPJ9q8uH87MjNDJ7WaHEJ5CL6UaQ= 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 1612180039265588.5693231262644; Mon, 1 Feb 2021 03:47:19 -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-498-sDbBwqyJNRemzoNdYjfhSQ-1; Mon, 01 Feb 2021 06:47:16 -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 8B75C612A9; Mon, 1 Feb 2021 11:47:10 +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 648862CC9A; Mon, 1 Feb 2021 11:47: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 2638D50038; Mon, 1 Feb 2021 11:47: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 111Bl14o005744 for ; Mon, 1 Feb 2021 06:47:01 -0500 Received: by smtp.corp.redhat.com (Postfix) id BED8763AFA; Mon, 1 Feb 2021 11:47:01 +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 B98EF44076 for ; Mon, 1 Feb 2021 11:47:01 +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 A5E1E88CC48 for ; Mon, 1 Feb 2021 11:47:01 +0000 (UTC) Received: from mail-qk1-f172.google.com (mail-qk1-f172.google.com [209.85.222.172]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-539-q0u--dCdOseaH9hc2J4cHQ-1; Mon, 01 Feb 2021 06:46:59 -0500 Received: by mail-qk1-f172.google.com with SMTP id 19so15852517qkh.3 for ; Mon, 01 Feb 2021 03:46:59 -0800 (PST) Received: from rekt.ibmuc.com ([2804:431:c7c6:6df1:6267:881f:cc79:a1f7]) by smtp.gmail.com with ESMTPSA id t6sm13671374qti.2.2021.02.01.03.46.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 01 Feb 2021 03:46:58 -0800 (PST) X-MC-Unique: sDbBwqyJNRemzoNdYjfhSQ-1 X-MC-Unique: q0u--dCdOseaH9hc2J4cHQ-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=UCLgMXkE3bt//UFrhFBE47eIS570dkQzFB1uTgUr7qg=; b=KIZSjTeLEoCKt/3FWUG3/2ScYxgMTlqqRuSSrePLSeJKMadUUjgLKbV5gvkXpLe/Fd vS8RauI8z+1xGLX2ygSYsems8VUUGF7EWiCfTt9qbEh4tHV0nrJW9IGM4wS7sw/aldpb qQK1D9zgr4ern8elPHi8AXBxocl20f0QGAnUAqwp8hmJo9AgTLka3voWUjwqwaVRg3O/ pEFdd7ygiYLk3wJHUbusVfUZWyIWNxtKfdjAhbmhqQdPr9EfXwJKG22PL6beVvfN1SoD 0O4ky4q37XDkCHBitN9wrK2bUJ0dXm+PKXW7ByOfp31qZqLr0l5jFmHhW1S7YWr3k9+G eINA== X-Gm-Message-State: AOAM532zaK00xv84HQaIFnAkvGBAbBJWy9lkaTUey1m/RWEwD8N02tsF mYYLfy7h5/ELmFKEb5Hd1faJY0ZRhcY= X-Google-Smtp-Source: ABdhPJygZc/S/LPbHjw03rLCguLIro9+WEaNBn94omGq0x8zSlSATJaCSPevFGbg32SRkIJaUs2aRQ== X-Received: by 2002:a37:9ec8:: with SMTP id h191mr15192080qke.174.1612180018919; Mon, 01 Feb 2021 03:46:58 -0800 (PST) From: Daniel Henrique Barboza To: libvir-list@redhat.com Subject: [PATCH 6/9] libxl_driver.c: validate 'driverName' earlier in libxlNodeDeviceDetachFlags() Date: Mon, 1 Feb 2021 08:46:39 -0300 Message-Id: <20210201114642.1947595-7-danielhb413@gmail.com> In-Reply-To: <20210201114642.1947595-1-danielhb413@gmail.com> References: <20210201114642.1947595-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.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-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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. Signed-off-by: Daniel Henrique Barboza Reviewed-by: J=C3=A1n Tomko --- 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 718717f14b..7c7eeb3ad0 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 Mon Apr 29 15:22:14 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=1612180043; cv=none; d=zohomail.com; s=zohoarc; b=LhGg3IkyTOZRdtCdLSnBv1hxhkT9U55/VWYqxgP0LOL/kKgSt65IT3gj+2DMcnTC4vVFolvanqi0Iv3k1fhpfWVTLKbwA2D7mFTzpYoU7AuGEnq2pF3O8SECSqDbzeJD1uUSDh0S/3mj/Qhq7oVjYkOFWUrh3cvTt7Non/mj5u8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1612180043; 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=Iy9ULqnIm3gnWkB6tP0q7WW+Z4qltrn1rzXVMVHJZns=; b=RJeL33FehbAc6Qy1JZE4dmfShbSYQ/gONjkDYMJm1kxIU/VedpH2NFoKJQO9RFSd0NhhVFiebZgn3O48+UtKgT6YqwQOf34GjlG8dYa3DqU8Hyrf/t/IWyekMKm5K9B2wCXxNYbvt2mh5Bymhgv9tcHbiISjHRoSE3or97h7rhw= 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 1612180043460384.2819727087042; Mon, 1 Feb 2021 03:47:23 -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-494-MWNW_9itM6-QhP47-rfYMA-1; Mon, 01 Feb 2021 06:47:20 -0500 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 2ACBE107ACE4; Mon, 1 Feb 2021 11:47:15 +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 079391346F; Mon, 1 Feb 2021 11:47:15 +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 C495950040; Mon, 1 Feb 2021 11:47:14 +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 111Bl8Ef005798 for ; Mon, 1 Feb 2021 06:47:08 -0500 Received: by smtp.corp.redhat.com (Postfix) id E49422166B2A; Mon, 1 Feb 2021 11:47:07 +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 DF0962166B27 for ; Mon, 1 Feb 2021 11:47:03 +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 72711101A562 for ; Mon, 1 Feb 2021 11:47:03 +0000 (UTC) Received: from mail-qv1-f45.google.com (mail-qv1-f45.google.com [209.85.219.45]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-561-vHBx22jgOVmUQxz_PIx3Bw-1; Mon, 01 Feb 2021 06:47:01 -0500 Received: by mail-qv1-f45.google.com with SMTP id u16so7931160qvo.9 for ; Mon, 01 Feb 2021 03:47:00 -0800 (PST) Received: from rekt.ibmuc.com ([2804:431:c7c6:6df1:6267:881f:cc79:a1f7]) by smtp.gmail.com with ESMTPSA id t6sm13671374qti.2.2021.02.01.03.46.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 01 Feb 2021 03:46:59 -0800 (PST) X-MC-Unique: MWNW_9itM6-QhP47-rfYMA-1 X-MC-Unique: vHBx22jgOVmUQxz_PIx3Bw-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=Iy9ULqnIm3gnWkB6tP0q7WW+Z4qltrn1rzXVMVHJZns=; b=JfNGmh7ZWQ5jObFrYQ8K8cEUSXwL0iT/6cqjQlRqFVaRtPbiSQn7rtTiljj4A3limH u3bPSz58doygzqGyPRmYqETP772ROf9VcVjGODVItf0SVR5jAmtV+R5YcTR8cIGjObQE LYq7ET2jClOXqA+qkf2f8nm6I0k7PFqwk1vNG/xVnCEYCGeQhRREMEezr0VWHWpnLsj4 fgIsbPVr4J+aojlp1bsezbIzah1LFgcy01nmptiKkIocnwimeSgLpIPmfRxggShh2v/i iWl4aa+jt9kmJiH8UfRPh9bSzI5TlnBg6/PYJJlSgMOm/UTUA72e5VFb+v7Vi/fJVGI+ EVFA== X-Gm-Message-State: AOAM530M1qaKtgf0zike25f3mZApt8bPrS5KxCYfBuAe8GBTJB7lsE1i 1XqN+t6+SweJvjvY2x9aWgbRuMVGGy8= X-Google-Smtp-Source: ABdhPJx5xCOkZCitd3VAcykaFy3iYR+h2lIxRJTLB10RnUZeiIncWit88uA+l/AnIPXhgjHMnix9tw== X-Received: by 2002:a0c:f986:: with SMTP id t6mr14910502qvn.15.1612180020290; Mon, 01 Feb 2021 03:47:00 -0800 (PST) From: Daniel Henrique Barboza To: libvir-list@redhat.com Subject: [PATCH 7/9] qemu_driver.c: validate 'driverName' earlier in qemuNodeDeviceDetachFlags() Date: Mon, 1 Feb 2021 08:46:40 -0300 Message-Id: <20210201114642.1947595-8-danielhb413@gmail.com> In-Reply-To: <20210201114642.1947595-1-danielhb413@gmail.com> References: <20210201114642.1947595-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 X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 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" 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. Signed-off-by: Daniel Henrique Barboza Reviewed-by: J=C3=A1n Tomko --- 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 Mon Apr 29 15:22:14 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=1612180045; cv=none; d=zohomail.com; s=zohoarc; b=AmH/7H3YasSdfYSZ9KLeE+WSS3kX0Yc8glUw9W5ppCGbNxvOJGNgYeWqTzSh+bYVNIlPKBGw9eYc6uSvuQbs/nA/Q1LRuIP1aYSsA+/grlbNhnZ09mab3HO9lJcDMQ3hCZxhTHFL7xkSZKiYddvI4na3nsv6pG/nLhry2Gj1/QE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1612180045; 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=fZbupjH7Sw/hDmJLs4zQFPNn7Wyg13kjHIAaPk1nk9k=; b=F+Rv3eP+8LHeRh4JUogeqo7oBF+ZwUKQz2ausyhap/inXFmujQqRKxbn6e8gY57JiQnMfsBmZhwAm9I1addDOVDLTj5yYcAFxXe7HAN9p+WK2p6lNeHvgjYh0mjCBhxlnG7idNz/tVK5pJhkzn/cTX28WxNpaLu4807dw6PDB4s= 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 1612180045860451.4591647336839; Mon, 1 Feb 2021 03:47:25 -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-470-RxneKe4xPSWd4aCQHqRSVA-1; Mon, 01 Feb 2021 06:47: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 BA6DC10054FF; Mon, 1 Feb 2021 11:47:14 +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 97E855DA2E; Mon, 1 Feb 2021 11:47:14 +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 58E1F5003E; Mon, 1 Feb 2021 11:47:14 +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 111Bl4vV005770 for ; Mon, 1 Feb 2021 06:47:05 -0500 Received: by smtp.corp.redhat.com (Postfix) id C7B972166B28; Mon, 1 Feb 2021 11:47:04 +0000 (UTC) Received: from mimecast-mx02.redhat.com (mimecast01.extmail.prod.ext.rdu2.redhat.com [10.11.55.17]) by smtp.corp.redhat.com (Postfix) with ESMTPS id C1FCE2166B27 for ; Mon, 1 Feb 2021 11:47:04 +0000 (UTC) Received: from us-smtp-1.mimecast.com (us-smtp-2.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 A4706858281 for ; Mon, 1 Feb 2021 11:47:04 +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-352-VhY1LR-TPLCeUJA_Ft1VZA-1; Mon, 01 Feb 2021 06:47:02 -0500 Received: by mail-qt1-f176.google.com with SMTP id z22so11943534qto.7 for ; Mon, 01 Feb 2021 03:47:02 -0800 (PST) Received: from rekt.ibmuc.com ([2804:431:c7c6:6df1:6267:881f:cc79:a1f7]) by smtp.gmail.com with ESMTPSA id t6sm13671374qti.2.2021.02.01.03.47.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 01 Feb 2021 03:47:01 -0800 (PST) X-MC-Unique: RxneKe4xPSWd4aCQHqRSVA-1 X-MC-Unique: VhY1LR-TPLCeUJA_Ft1VZA-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=fZbupjH7Sw/hDmJLs4zQFPNn7Wyg13kjHIAaPk1nk9k=; b=nZvL1F8Bo35Ul8INxRlHjXbggmQWa2Nspk2a+/tETnGWQSX0mH20wqCgEypdah1qu/ wkdWsgt3M/T6kWV9MOd59hfG7+9gULivi0PDcLrELr3ywsXMbsknSBQxdt83bt8rN+jw oLPiqddQDS07XB6nufuZPK3lBVQ2Q4Wt9OghBiPPP9yyID7fkUaHyFO5eGHt84o1T8+o l+fScXepYR+FzztYb3trZG6c//ViWxjREMy6OFlwfowz8bRde5XoBBgfYnZi0RVmJcIv EBD9WocHM0am0qTcTKktiseTzu43zJsFhce7QeIGeQOMrbfAx+3siEwz7bEfJCB2AF9S jOTQ== X-Gm-Message-State: AOAM530xuvdP1i7k0kgHnp0hrfgIZ8UWR6SLQKuofif1fFgrdKBL/Ymy 4tkeyQ3Va2gx7LHh7sDuD+TEb1Yi4Ac= X-Google-Smtp-Source: ABdhPJwW1Edg6DQQ2y2gCeZNspulyVoW0F53QUw44zNSyix5D/yDEi0xRNC9Wn6NaWkV9Ym5djYlXQ== X-Received: by 2002:a05:622a:44b:: with SMTP id o11mr14409361qtx.229.1612180021817; Mon, 01 Feb 2021 03:47:01 -0800 (PST) From: Daniel Henrique Barboza To: libvir-list@redhat.com Subject: [PATCH 8/9] qemu, libxl, hypervisor: use virDomainDriverNodeDeviceDetachFlags() helper Date: Mon, 1 Feb 2021 08:46:41 -0300 Message-Id: <20210201114642.1947595-9-danielhb413@gmail.com> In-Reply-To: <20210201114642.1947595-1-danielhb413@gmail.com> References: <20210201114642.1947595-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 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-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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. Signed-off-by: Daniel Henrique Barboza Reviewed-by: J=C3=A1n Tomko --- 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 7c7eeb3ad0..4fc59b2a7e 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 Mon Apr 29 15:22:14 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=1612180046; cv=none; d=zohomail.com; s=zohoarc; b=lWvHTeSIi2sItDvVDhdcizjnDxvJzQ3q3KI06uTqJ9d3a4IiPd9+8pANwbPvbcFmf3ASOXN2lg2U3WsAivgBRn+ZOdLEceuGHqPmm3mz54/fOqovOx64VOvDqJzPrqn5No9LaRIua2oY2zrV2v1LMEnCw5vIY6GYkN/aj9mAj1E= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1612180046; 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=RT5phc49dtO/flDiUw96YDi7iQYVcWmQLPwnTaOasBc=; b=l6kfoaZJJOXuJC0SxLmPSs2xdtksBWNynLn8tm4ux8qD+EOUme9aAYiMmNONadPY+YkD+c/kUcEJsadrq86tW9y6DUWdFP7GxONzJoZG53UzbqoEYYGR+cgvUq6r7qUqpqg1jthK0C6BMJAJSJy+V6KEKp7ly8+W2kz6vZpk1FA= 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 1612180046838685.3725403686709; Mon, 1 Feb 2021 03:47: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-556-V2w7AHxgP2q8i3Tx1G2E7A-1; Mon, 01 Feb 2021 06:47:24 -0500 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 9BA04801ABD; Mon, 1 Feb 2021 11:47:18 +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 739B260C67; Mon, 1 Feb 2021 11:47:18 +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 3BFE750043; Mon, 1 Feb 2021 11:47:18 +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 111Bl6xs005781 for ; Mon, 1 Feb 2021 06:47:06 -0500 Received: by smtp.corp.redhat.com (Postfix) id E1149111144E; Mon, 1 Feb 2021 11:47:05 +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 DD44B111144C for ; Mon, 1 Feb 2021 11:47:05 +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 CB29A101A56B for ; Mon, 1 Feb 2021 11:47:05 +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-584-9AmdmWp0NsaqsMcqTd_zPQ-1; Mon, 01 Feb 2021 06:47:03 -0500 Received: by mail-qt1-f176.google.com with SMTP id r20so8377576qtm.3 for ; Mon, 01 Feb 2021 03:47:03 -0800 (PST) Received: from rekt.ibmuc.com ([2804:431:c7c6:6df1:6267:881f:cc79:a1f7]) by smtp.gmail.com with ESMTPSA id t6sm13671374qti.2.2021.02.01.03.47.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 01 Feb 2021 03:47:02 -0800 (PST) X-MC-Unique: V2w7AHxgP2q8i3Tx1G2E7A-1 X-MC-Unique: 9AmdmWp0NsaqsMcqTd_zPQ-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=RT5phc49dtO/flDiUw96YDi7iQYVcWmQLPwnTaOasBc=; b=gnrTuPFaqn0GILU32LvhkV8yzDvxwQqQg8OIV2FRIB6nHPq+PxazSfTkgT/cxUFpyu 9HWfefpWvJmsEwgytvwZmgeIbH5OAAsSoMT17IQskEWz/+Keg9rR1q34mUBSYHxbUVvy wuEdXntfvj2rKt2rvXAAFP7zNleNnx9k/S1a2esZuch6Ure0RuSkx7S3RJw4CLsqwW0M 7vQHhYiYTQsqaw9GZW/GLvZh5JOHYualwXDOm5sxoiOM/52tWPMykiwOLcZhCWNMx5zO v/ToJ2HKIrdFB9sKMDTan8NuTO2aVyh4/1Ki/T/nicD1SzokntmVWKh6abh2mnt1IjJD xChw== X-Gm-Message-State: AOAM533aYW05YXO4xPHKBsnysSymhrfh+Fq1EuNCTuZRFvOAVYQg5YWv u8Bzplj35cumf5hxiBZOd+CyWUGZQa0= X-Google-Smtp-Source: ABdhPJyevvK2D9bBrRV/26OKuD6V2wW9s+XCHzBAxkHCBdaeDO8bvR6YXpcnSz8F/8IyMSKFR8a6vA== X-Received: by 2002:ac8:110e:: with SMTP id c14mr14086610qtj.293.1612180023200; Mon, 01 Feb 2021 03:47:03 -0800 (PST) From: Daniel Henrique Barboza To: libvir-list@redhat.com Subject: [PATCH 9/9] domain_driver.c: use g_auto* in virDomainDriverNodeDeviceDetachFlags() Date: Mon, 1 Feb 2021 08:46:42 -0300 Message-Id: <20210201114642.1947595-10-danielhb413@gmail.com> In-Reply-To: <20210201114642.1947595-1-danielhb413@gmail.com> References: <20210201114642.1947595-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 X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 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" Signed-off-by: Daniel Henrique Barboza Reviewed-by: J=C3=A1n Tomko --- 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