Re: [libvirt] [PATCH 08/12] virpci: Drop newid style of PCI device detach

2019-08-21 Thread Ján Tomko

On Tue, Aug 20, 2019 at 04:30:28PM +0200, Michal Privoznik wrote:

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 
---
src/util/virpci.c | 284 +-
1 file changed, 2 insertions(+), 282 deletions(-)



Reviewed-by: Ján Tomko 

Jano


signature.asc
Description: PGP signature
--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list

Re: [libvirt] [PATCH 08/12] virpci: Drop newid style of PCI device detach

2019-08-20 Thread Daniel Henrique Barboza




On 8/20/19 11:30 AM, Michal Privoznik wrote:

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 
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)
  }
  
  
-static char *

-virPCIDriverFile(const char *driver, const char *file)
-{
-char *buffer;
-
-ignore_value(virAsprintf(, PCI_SYSFS "drivers/%s/%s", driver, 
file));
-return buffer;
-}
-
-
  static char *
  virPCIFile(const char *device, const char *file)
  {
@@ -1145,104 +1135,6 @@ virPCIDeviceBindWithDriverOverride(virPCIDevicePtr dev,
  return 0;
  }
  
-static int

-virPCIDeviceUnbindFromStubWithNewid(virPCIDevicePtr dev)
-{
-int result = -1;
-VIR_AUTOFREE(char *) drvdir = NULL;
-VIR_AUTOFREE(char *) path = NULL;
-VIR_AUTOFREE(char *) driver = NULL;
-
-/* If the device is currently bound to one of the "well known"
- * stub drivers, then unbind it, otherwise ignore it.
- */
-if (virPCIDeviceGetDriverPathAndName(dev, , ) < 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) == 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 = 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 device */
-if (!(path = 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 = false;
-
- reprobe:
-if (!dev->reprobe) {
-VIR_DEBUG("Reprobe skipped for PCI device %s", dev->name);
-result = 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 = 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 device 
'%s'"),
- dev->name);
-goto cleanup;
-}
-}
-
-result = 0;
-
- cleanup:
-/* do not do it again */
-dev->unbind_from_stub = false;
-dev->remove_slot = false;
-dev->reprobe = false;
-
-return result;
-}
-
  static int
  virPCIDeviceUnbindFromStubWithOverride(virPCIDevicePtr dev)
  {
@@ -1257,167 +1149,7 @@ virPCIDeviceUnbindFromStubWithOverride(virPCIDevicePtr 
dev)
  static int
  virPCIDeviceUnbindFromStub(virPCIDevicePtr dev)
  {
-VIR_AUTOFREE(char *) path = NULL;
-
-/*
- * Prefer using the device's driver_override interface, falling back
- * to the unpleasant new_id interface.
- */
-if (!(path = virPCIFile(dev->name, "driver_override")))
-return -1;
-
-if (virFileExists(path))
-return virPCIDeviceUnbindFromStubWithOverride(dev);
-
-return virPCIDeviceUnbindFromStubWithNewid(dev);
-}
-
-static int
-virPCIDeviceBindToStubWithNewid(virPCIDevicePtr dev)
-{
-int result = -1;
-bool reprobe = false;
-VIR_AUTOFREE(char *) 

[libvirt] [PATCH 08/12] virpci: Drop newid style of PCI device detach

2019-08-20 Thread Michal Privoznik
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 
---
 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)
 }
 
 
-static char *
-virPCIDriverFile(const char *driver, const char *file)
-{
-char *buffer;
-
-ignore_value(virAsprintf(, PCI_SYSFS "drivers/%s/%s", driver, 
file));
-return buffer;
-}
-
-
 static char *
 virPCIFile(const char *device, const char *file)
 {
@@ -1145,104 +1135,6 @@ virPCIDeviceBindWithDriverOverride(virPCIDevicePtr dev,
 return 0;
 }
 
-static int
-virPCIDeviceUnbindFromStubWithNewid(virPCIDevicePtr dev)
-{
-int result = -1;
-VIR_AUTOFREE(char *) drvdir = NULL;
-VIR_AUTOFREE(char *) path = NULL;
-VIR_AUTOFREE(char *) driver = NULL;
-
-/* If the device is currently bound to one of the "well known"
- * stub drivers, then unbind it, otherwise ignore it.
- */
-if (virPCIDeviceGetDriverPathAndName(dev, , ) < 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) == 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 = 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 device */
-if (!(path = 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 = false;
-
- reprobe:
-if (!dev->reprobe) {
-VIR_DEBUG("Reprobe skipped for PCI device %s", dev->name);
-result = 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 = 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 
device '%s'"),
- dev->name);
-goto cleanup;
-}
-}
-
-result = 0;
-
- cleanup:
-/* do not do it again */
-dev->unbind_from_stub = false;
-dev->remove_slot = false;
-dev->reprobe = false;
-
-return result;
-}
-
 static int
 virPCIDeviceUnbindFromStubWithOverride(virPCIDevicePtr dev)
 {
@@ -1257,167 +1149,7 @@ virPCIDeviceUnbindFromStubWithOverride(virPCIDevicePtr 
dev)
 static int
 virPCIDeviceUnbindFromStub(virPCIDevicePtr dev)
 {
-VIR_AUTOFREE(char *) path = NULL;
-
-/*
- * Prefer using the device's driver_override interface, falling back
- * to the unpleasant new_id interface.
- */
-if (!(path = virPCIFile(dev->name, "driver_override")))
-return -1;
-
-if (virFileExists(path))
-return virPCIDeviceUnbindFromStubWithOverride(dev);
-
-return virPCIDeviceUnbindFromStubWithNewid(dev);
-}
-
-static int
-virPCIDeviceBindToStubWithNewid(virPCIDevicePtr dev)
-{
-int result = -1;
-bool reprobe = false;
-VIR_AUTOFREE(char *) stubDriverPath = NULL;
-VIR_AUTOFREE(char *) driverLink = NULL;
-VIR_AUTOFREE(char *) path = NULL; /* reused for different purposes */
-