From nobody Mon Feb 9 17:05:00 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) client-ip=170.10.133.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1692646468; cv=none; d=zohomail.com; s=zohoarc; b=g1c+RITArXZyxjmDlrVl+W/s+VpBOM0wDc6n2LORDq81bxb8D2DyL18M800zg8D5BNwXK6YFKM3Ia+v4MIAWnn6QuX7AePxupFti1jVxEV/ixlhwibgjXlLybTyNQinfIlz1WNE6mCAizAE0hCClysurZSczHfAzg+ABVIp0xvM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1692646468; 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=pEQpna+mTq5rfAiowEPiM5gD7tO5bFWvCiCAcCLIN9o=; b=efNocSqiVOWCB05jwfA9Ng77h3XtsKxZuwrsHCAxA10lFCjfFYDM7KR0mI8RoHWmXMPcYDQMMYKSUB5GKDuEYQGBwo1he/zJgymfMeTV717PZmIpHi28fRc9piKmIzAVj+C+UpMBtMAS/DFqgaY+mx+cvJ9IbmptMbgcfHjR7kQ= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by mx.zohomail.com with SMTPS id 1692646468664297.5225783446185; Mon, 21 Aug 2023 12:34:28 -0700 (PDT) Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-550-l0a40JEwO7mXlWsR7Rfx3A-1; Mon, 21 Aug 2023 15:33:38 -0400 Received: from smtp.corp.redhat.com (int-mx10.intmail.prod.int.rdu2.redhat.com [10.11.54.10]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 15CE88D40B6; Mon, 21 Aug 2023 19:33:36 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com [10.30.29.100]) by smtp.corp.redhat.com (Postfix) with ESMTP id 007B6492C13; Mon, 21 Aug 2023 19:33:36 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (localhost [IPv6:::1]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id 0D3D91946A7B; Mon, 21 Aug 2023 19:33:08 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx10.intmail.prod.int.rdu2.redhat.com [10.11.54.10]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id 789091946A4B for ; Mon, 21 Aug 2023 19:33:05 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id 63EC04021B9; Mon, 21 Aug 2023 19:33:00 +0000 (UTC) Received: from vhost3.router.laine.org (unknown [10.22.9.186]) by smtp.corp.redhat.com (Postfix) with ESMTP id 2D29C40282C; Mon, 21 Aug 2023 19:33:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1692646467; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=pEQpna+mTq5rfAiowEPiM5gD7tO5bFWvCiCAcCLIN9o=; b=DrcZ3rCOJZg25VuHtGajGP0/+W0TRet2GT5+fEyBH8+0WEL5Pfd7tsF7nRGhbhAaR70uez RD81eNizV/RLBs4DyLxY4AFbQUrorNaCQ+DVJkjWWz5//GV//xzxJzttH4FOKSfQDBovRN RXzPmxPPe7WPxB5wui261WnEFFKoxTI= X-MC-Unique: l0a40JEwO7mXlWsR7Rfx3A-1 X-Original-To: libvir-list@listman.corp.redhat.com From: Laine Stump To: libvir-list@redhat.com Subject: [libvirt PATCH v3 5/8] util: probe stub driver from within function that binds to stub driver Date: Mon, 21 Aug 2023 15:32:55 -0400 Message-ID: <20230821193258.520859-6-laine@redhat.com> In-Reply-To: <20230821193258.520859-1-laine@redhat.com> References: <20230821193258.520859-1-laine@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.10 X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: "Cc : Joao Martins" , "Cc : Cedric Le Goater" , "Cc : Jason Gunthorpe" Errors-To: libvir-list-bounces@redhat.com Sender: "libvir-list" X-Scanned-By: MIMEDefang 3.1 on 10.11.54.10 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1692646471093100001 Content-Type: text/plain; charset="utf-8"; x-default="true" virPCIProbeStubDriver() and virPCIDeviceBindToStub() both have very similar code that locally sets a driver name (based on stubDriverType). These two functions are each also called in just one place (virPCIDeviceDetach()), with just a small bit of validation code in between. To eliminate the "duplicated" code (which is going to be expanded slightly in upcoming patches to support manually or automatically picking a VFIO variant driver), this patch modifies virPCIProbeStubDriver() to take the driver name as an argument (rather than the virPCIDevice object), and calls it from within virPCIDeviceBindToStub() (rather than from that function's caller), using the driverName it has just figured out with the now-not-duplicated code. (NB: Since it could be used to probe *any* driver module, the name is changed to virPCIProbeDriver()). Signed-off-by: Laine Stump --- src/util/virpci.c | 33 ++++++++++++--------------------- 1 file changed, 12 insertions(+), 21 deletions(-) diff --git a/src/util/virpci.c b/src/util/virpci.c index e165725cd9..ac91480e0b 100644 --- a/src/util/virpci.c +++ b/src/util/virpci.c @@ -1154,28 +1154,19 @@ virPCIDeviceReset(virPCIDevice *dev, =20 =20 static int -virPCIProbeStubDriver(virPCIStubDriver driver) +virPCIProbeDriver(const char *driverName) { - const char *drvname =3D NULL; g_autofree char *drvpath =3D NULL; g_autofree char *errbuf =3D NULL; =20 - if (driver =3D=3D VIR_PCI_STUB_DRIVER_NONE || - !(drvname =3D virPCIStubDriverTypeToString(driver))) { - virReportError(VIR_ERR_INTERNAL_ERROR, - "%s", - _("Attempting to use unknown stub driver")); - return -1; - } - - drvpath =3D virPCIDriverDir(drvname); + drvpath =3D virPCIDriverDir(driverName); =20 /* driver previously loaded, return */ if (virFileExists(drvpath)) return 0; =20 - if ((errbuf =3D virKModLoad(drvname))) { - VIR_WARN("failed to load driver %s: %s", drvname, errbuf); + if ((errbuf =3D virKModLoad(driverName))) { + VIR_WARN("failed to load driver %s: %s", driverName, errbuf); goto cleanup; } =20 @@ -1187,14 +1178,14 @@ virPCIProbeStubDriver(virPCIStubDriver driver) /* If we know failure was because of admin config, let's report that; * otherwise, report a more generic failure message */ - if (virKModIsProhibited(drvname)) { + if (virKModIsProhibited(driverName)) { virReportError(VIR_ERR_INTERNAL_ERROR, - _("Failed to load PCI stub module %1$s: administrat= ively prohibited"), - drvname); + _("Failed to load PCI driver module %1$s: administr= atively prohibited"), + driverName); } else { virReportError(VIR_ERR_INTERNAL_ERROR, - _("Failed to load PCI stub module %1$s"), - drvname); + _("Failed to load PCI driver module %1$s"), + driverName); } =20 return -1; @@ -1316,6 +1307,9 @@ virPCIDeviceBindToStub(virPCIDevice *dev) return -1; } =20 + if (virPCIProbeDriver(stubDriverName) < 0) + return -1; + stubDriverPath =3D virPCIDriverDir(stubDriverName); driverLink =3D virPCIFile(dev->name, "driver"); =20 @@ -1358,9 +1352,6 @@ virPCIDeviceDetach(virPCIDevice *dev, virPCIDeviceList *activeDevs, virPCIDeviceList *inactiveDevs) { - if (virPCIProbeStubDriver(dev->stubDriverType) < 0) - return -1; - if (activeDevs && virPCIDeviceListFind(activeDevs, &dev->address)) { virReportError(VIR_ERR_INTERNAL_ERROR, _("Not detaching active device %1$s"), dev->name); --=20 2.41.0