From nobody Sun Feb 8 14:52:05 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) client-ip=216.205.24.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=fail(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1612314418; cv=none; d=zohomail.com; s=zohoarc; b=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