From nobody Sun Feb 8 20:53:40 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 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=1566311460; cv=none; d=zoho.com; s=zohoarc; b=DnJEGOtcoxN9i/Lh3KO5cng0FFWSSRoSBuXDlsK8G3bHl7A0W73mG359IzSTXVKPYZLOk5sfghr0tPjQotDAfu+OLwyvdLznMksDhW6CLPjC+S5d+r0F4ChxCZjUdSL6BWzvuuI/IudK4dMAsYFb0cAtt9fiYEITfRminPBjC+w= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1566311460; h=Content-Type:Content-Transfer-Encoding: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:ARC-Authentication-Results; bh=xtuYmYas3EHuvO18Zebcc61/cgSrsaFEvTI9HPgQXaw=; b=F164jArv0DpXQKCrV2LCS30N/kQanwudDM99UIrz6MgAuqcDqxJ2O46H7vh6FZKge7AgkP7Nmw7FCQrOjFagjMJZhDxJCoQXSOtckbSY9jJUJjWzf3F0UhJPiunsba9ClHDiacGDrvPxhnh9FI8o9E1GfantxP852GyLODFbMMY= ARC-Authentication-Results: i=1; mx.zoho.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1566311460343287.2991935159781; Tue, 20 Aug 2019 07:31:00 -0700 (PDT) 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 mx1.redhat.com (Postfix) with ESMTPS id EBC04180158A; Tue, 20 Aug 2019 14:30:58 +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 C46905D9D5; Tue, 20 Aug 2019 14:30:58 +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 8774F24F36; Tue, 20 Aug 2019 14:30:58 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x7KEUtUC028851 for ; Tue, 20 Aug 2019 10:30:55 -0400 Received: by smtp.corp.redhat.com (Postfix) id 19ABB438B; Tue, 20 Aug 2019 14:30:55 +0000 (UTC) Received: from moe.brq.redhat.com (unknown [10.43.2.30]) by smtp.corp.redhat.com (Postfix) with ESMTP id 96A461F0 for ; Tue, 20 Aug 2019 14:30:50 +0000 (UTC) From: Michal Privoznik To: libvir-list@redhat.com Date: Tue, 20 Aug 2019 16:30:28 +0200 Message-Id: <518f29156cfb32d4044b116cfdd37d032ab8342c.1566311075.git.mprivozn@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 08/12] virpci: Drop newid style of PCI device detach 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: , Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.6.2 (mx1.redhat.com [10.5.110.63]); Tue, 20 Aug 2019 14:30:59 +0000 (UTC) Content-Type: text/plain; charset="utf-8" As stated in 84f9358b18346 all kernels that we are interested in have 'drivers_override'. Drop the other, older style of overriding PCI device driver - newid. Signed-off-by: Michal Privoznik Reviewed-by: Daniel Henrique Barboza Reviewed-by: J=C3=A1n Tomko Tested-by: Daniel Henrique Barboza --- src/util/virpci.c | 284 +--------------------------------------------- 1 file changed, 2 insertions(+), 282 deletions(-) diff --git a/src/util/virpci.c b/src/util/virpci.c index ea5be62033..6724a8ad9e 100644 --- a/src/util/virpci.c +++ b/src/util/virpci.c @@ -218,16 +218,6 @@ virPCIDriverDir(const char *driver) } =20 =20 -static char * -virPCIDriverFile(const char *driver, const char *file) -{ - char *buffer; - - ignore_value(virAsprintf(&buffer, PCI_SYSFS "drivers/%s/%s", driver, f= ile)); - return buffer; -} - - static char * virPCIFile(const char *device, const char *file) { @@ -1145,104 +1135,6 @@ virPCIDeviceBindWithDriverOverride(virPCIDevicePtr = dev, return 0; } =20 -static int -virPCIDeviceUnbindFromStubWithNewid(virPCIDevicePtr dev) -{ - int result =3D -1; - VIR_AUTOFREE(char *) drvdir =3D NULL; - VIR_AUTOFREE(char *) path =3D NULL; - VIR_AUTOFREE(char *) driver =3D NULL; - - /* If the device is currently bound to one of the "well known" - * stub drivers, then unbind it, otherwise ignore it. - */ - if (virPCIDeviceGetDriverPathAndName(dev, &drvdir, &driver) < 0) - goto cleanup; - - if (!driver) { - /* The device is not bound to any driver and we are almost done. */ - VIR_DEBUG("PCI device %s is not bound to any driver", dev->name); - goto reprobe; - } - - if (!dev->unbind_from_stub) { - VIR_DEBUG("Unbind from stub skipped for PCI device %s", dev->name); - goto remove_slot; - } - - /* If the device isn't bound to a known stub, skip the unbind. */ - if (virPCIStubDriverTypeFromString(driver) < 0 || - virPCIStubDriverTypeFromString(driver) =3D=3D VIR_PCI_STUB_DRIVER_= NONE) { - VIR_DEBUG("Unbind from stub skipped for PCI device %s because of " - "unknown stub driver", dev->name); - goto remove_slot; - } - - VIR_DEBUG("Unbinding PCI device %s from stub driver %s", - dev->name, driver); - - if (virPCIDeviceUnbind(dev) < 0) - goto cleanup; - dev->unbind_from_stub =3D false; - - remove_slot: - if (!dev->remove_slot) { - VIR_DEBUG("Slot removal skipped for PCI device %s", dev->name); - goto reprobe; - } - - VIR_DEBUG("Removing slot for PCI device %s", dev->name); - - /* Xen's pciback.ko wants you to use remove_slot on the specific devic= e */ - if (!(path =3D virPCIDriverFile(driver, "remove_slot"))) - goto cleanup; - - if (virFileExists(path) && virFileWriteStr(path, dev->name, 0) < 0) { - virReportSystemError(errno, - _("Failed to remove slot for PCI device '%s' = from %s"), - dev->name, driver); - goto cleanup; - } - dev->remove_slot =3D false; - - reprobe: - if (!dev->reprobe) { - VIR_DEBUG("Reprobe skipped for PCI device %s", dev->name); - result =3D 0; - goto cleanup; - } - - VIR_DEBUG("Reprobing for PCI device %s", dev->name); - - /* Trigger a re-probe of the device is not in the stub's dynamic - * ID table. If the stub is available, but 'remove_id' isn't - * available, then re-probing would just cause the device to be - * re-bound to the stub. - */ - VIR_FREE(path); - if (driver && !(path =3D virPCIDriverFile(driver, "remove_id"))) - goto cleanup; - - if (!driver || !virFileExists(drvdir) || virFileExists(path)) { - if (virFileWriteStr(PCI_SYSFS "drivers_probe", dev->name, 0) < 0) { - virReportSystemError(errno, - _("Failed to trigger a re-probe for PCI d= evice '%s'"), - dev->name); - goto cleanup; - } - } - - result =3D 0; - - cleanup: - /* do not do it again */ - dev->unbind_from_stub =3D false; - dev->remove_slot =3D false; - dev->reprobe =3D false; - - return result; -} - static int virPCIDeviceUnbindFromStubWithOverride(virPCIDevicePtr dev) { @@ -1257,167 +1149,7 @@ virPCIDeviceUnbindFromStubWithOverride(virPCIDevice= Ptr dev) static int virPCIDeviceUnbindFromStub(virPCIDevicePtr dev) { - VIR_AUTOFREE(char *) path =3D NULL; - - /* - * Prefer using the device's driver_override interface, falling back - * to the unpleasant new_id interface. - */ - if (!(path =3D virPCIFile(dev->name, "driver_override"))) - return -1; - - if (virFileExists(path)) - return virPCIDeviceUnbindFromStubWithOverride(dev); - - return virPCIDeviceUnbindFromStubWithNewid(dev); -} - -static int -virPCIDeviceBindToStubWithNewid(virPCIDevicePtr dev) -{ - int result =3D -1; - bool reprobe =3D false; - VIR_AUTOFREE(char *) stubDriverPath =3D NULL; - VIR_AUTOFREE(char *) driverLink =3D NULL; - VIR_AUTOFREE(char *) path =3D NULL; /* reused for different purposes */ - VIR_AUTOPTR(virError) err =3D NULL; - const char *stubDriverName =3D NULL; - - /* Check the device is configured to use one of the known stub drivers= */ - if (dev->stubDriver =3D=3D VIR_PCI_STUB_DRIVER_NONE) { - virReportError(VIR_ERR_INTERNAL_ERROR, - _("No stub driver configured for PCI device %s"), - dev->name); - return -1; - } else if (!(stubDriverName =3D virPCIStubDriverTypeToString(dev->stub= Driver))) { - virReportError(VIR_ERR_INTERNAL_ERROR, - _("Unknown stub driver configured for PCI device %s= "), - dev->name); - return -1; - } - - if (!(stubDriverPath =3D virPCIDriverDir(stubDriverName)) || - !(driverLink =3D virPCIFile(dev->name, "driver"))) - goto cleanup; - - if (virFileExists(driverLink)) { - if (virFileLinkPointsTo(driverLink, stubDriverPath)) { - /* The device is already bound to the correct driver */ - VIR_DEBUG("Device %s is already bound to %s", - dev->name, stubDriverName); - result =3D 0; - goto cleanup; - } - reprobe =3D true; - } - - /* Add the PCI device ID to the stub's dynamic ID table; - * this is needed to allow us to bind the device to the stub. - * Note: if the device is not currently bound to any driver, - * stub will immediately be bound to the device. Also, note - * that if a new device with this ID is hotplugged, or if a probe - * is triggered for such a device, it will also be immediately - * bound by the stub. - */ - if (!(path =3D virPCIDriverFile(stubDriverName, "new_id"))) - goto cleanup; - - if (virFileWriteStr(path, dev->id, 0) < 0) { - virReportSystemError(errno, - _("Failed to add PCI device ID '%s' to %s"), - dev->id, stubDriverName); - goto cleanup; - } - - /* check whether the device is bound to pci-stub when we write dev->id= to - * ${stubDriver}/new_id. - */ - if (virFileLinkPointsTo(driverLink, stubDriverPath)) { - dev->unbind_from_stub =3D true; - dev->remove_slot =3D true; - result =3D 0; - goto remove_id; - } - - if (virPCIDeviceUnbind(dev) < 0) - goto remove_id; - - /* If the device was bound to a driver we'll need to reprobe later */ - dev->reprobe =3D reprobe; - - /* If the device isn't already bound to pci-stub, try binding it now. - */ - if (!virFileLinkPointsTo(driverLink, stubDriverPath)) { - /* Xen's pciback.ko wants you to use new_slot first */ - VIR_FREE(path); - if (!(path =3D virPCIDriverFile(stubDriverName, "new_slot"))) - goto remove_id; - - if (virFileExists(path) && virFileWriteStr(path, dev->name, 0) < 0= ) { - virReportSystemError(errno, - _("Failed to add slot for " - "PCI device '%s' to %s"), - dev->name, stubDriverName); - goto remove_id; - } - dev->remove_slot =3D true; - - VIR_FREE(path); - if (!(path =3D virPCIDriverFile(stubDriverName, "bind"))) - goto remove_id; - - if (virFileWriteStr(path, dev->name, 0) < 0) { - virReportSystemError(errno, - _("Failed to bind PCI device '%s' to %s"), - dev->name, stubDriverName); - goto remove_id; - } - dev->unbind_from_stub =3D true; - } - - result =3D 0; - - remove_id: - err =3D virSaveLastError(); - - /* If 'remove_id' exists, remove the device id from pci-stub's dynamic - * ID table so that 'drivers_probe' works below. - */ - VIR_FREE(path); - if (!(path =3D virPCIDriverFile(stubDriverName, "remove_id"))) { - /* We do not remove PCI ID from pci-stub, and we cannot reprobe it= */ - if (dev->reprobe) { - VIR_WARN("Could not remove PCI ID '%s' from %s, and the device= " - "cannot be probed again.", dev->id, stubDriverName); - } - dev->reprobe =3D false; - result =3D -1; - goto cleanup; - } - - if (virFileExists(path) && virFileWriteStr(path, dev->id, 0) < 0) { - virReportSystemError(errno, - _("Failed to remove PCI ID '%s' from %s"), - dev->id, stubDriverName); - - /* remove PCI ID from pci-stub failed, and we cannot reprobe it */ - if (dev->reprobe) { - VIR_WARN("Failed to remove PCI ID '%s' from %s, and the device= " - "cannot be probed again.", dev->id, stubDriverName); - } - dev->reprobe =3D false; - result =3D -1; - goto cleanup; - } - - cleanup: - if (result < 0) - virPCIDeviceUnbindFromStub(dev); - - if (err) - virSetError(err); - - return result; + return virPCIDeviceUnbindFromStubWithOverride(dev); } =20 static int @@ -1463,19 +1195,7 @@ virPCIDeviceBindToStubWithOverride(virPCIDevicePtr d= ev) static int virPCIDeviceBindToStub(virPCIDevicePtr dev) { - VIR_AUTOFREE(char *) path =3D NULL; - - /* - * Prefer using the device's driver_override interface, falling back - * to the unpleasant new_id interface. - */ - if (!(path =3D virPCIFile(dev->name, "driver_override"))) - return -1; - - if (virFileExists(path)) - return virPCIDeviceBindToStubWithOverride(dev); - - return virPCIDeviceBindToStubWithNewid(dev); + return virPCIDeviceBindToStubWithOverride(dev); } =20 /* virPCIDeviceDetach: --=20 2.21.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list