Re: [libvirt] [PATCH 08/19] util: new function virPCIDeviceRebind()

2017-03-17 Thread Laine Stump
On 03/17/2017 09:32 AM, Michal Privoznik wrote:
> On 03/10/2017 09:35 PM, Laine Stump wrote:
>> This function unbinds a device from its driver, then immediately
>> rebinds it to its driver again.
>> ---
>>  src/libvirt_private.syms |  1 +
>>  src/util/virpci.c| 25 +
>>  src/util/virpci.h|  1 +
>>  3 files changed, 27 insertions(+)
>>
>> diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
>> index b44a6ee..ef027cc 100644
>> --- a/src/libvirt_private.syms
>> +++ b/src/libvirt_private.syms
>> @@ -2217,6 +2217,7 @@ virPCIDeviceListSteal;
>>  virPCIDeviceListStealIndex;
>>  virPCIDeviceNew;
>>  virPCIDeviceReattach;
>> +virPCIDeviceRebind;
>>  virPCIDeviceReset;
>>  virPCIDeviceSetManaged;
>>  virPCIDeviceSetRemoveSlot;
>> diff --git a/src/util/virpci.c b/src/util/virpci.c
>> index 9878398..a007eea 100644
>> --- a/src/util/virpci.c
>> +++ b/src/util/virpci.c
>> @@ -1101,6 +1101,31 @@ virPCIDeviceUnbind(virPCIDevicePtr dev)
>>  return ret;
>>  }
>>
>> +
>> +/**
>> + * virPCIDeviceRebind:
>> + *  @dev: virPCIDevice object describing the device to rebind
>> + *
>> + * unbind a device from its driver, then immediately rebind it.
>> + *
>> + * Returns 0 on success, -1 on failure
>> + */
>> +int virPCIDeviceRebind(virPCIDevicePtr dev)
>> +{
>> +if (virPCIDeviceUnbind(dev) < 0)
>> +return -1;
>> +
>> +if (virFileWriteStr(PCI_SYSFS "drivers_probe", dev->name, 0) < 0) {
>> +virReportSystemError(errno,
>> + _("Failed to trigger a probe for PCI
>> device '%s'"),
>> + dev->name);
>> +return -1;
>> +}
>> +
>> +return 0;
>> +}
>> +
> 
> This is the same code as in virPCIDeviceBindWithDriverOverride(). ACK if
> you replace it with call to this function.

Ah, okay. It took me a second to parse your request - at first I was
thinking "No, it's not the same as virPCIDeviceBindWithDriverOverride()
- there's extra stuff in that function!". Then I realized you meant I
should replace those lines in WithDriverOverride() with a call to
this new function. Sure, that makes sense.

> 
> Michal
> 

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


Re: [libvirt] [PATCH 08/19] util: new function virPCIDeviceRebind()

2017-03-17 Thread Michal Privoznik

On 03/10/2017 09:35 PM, Laine Stump wrote:

This function unbinds a device from its driver, then immediately
rebinds it to its driver again.
---
 src/libvirt_private.syms |  1 +
 src/util/virpci.c| 25 +
 src/util/virpci.h|  1 +
 3 files changed, 27 insertions(+)

diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
index b44a6ee..ef027cc 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -2217,6 +2217,7 @@ virPCIDeviceListSteal;
 virPCIDeviceListStealIndex;
 virPCIDeviceNew;
 virPCIDeviceReattach;
+virPCIDeviceRebind;
 virPCIDeviceReset;
 virPCIDeviceSetManaged;
 virPCIDeviceSetRemoveSlot;
diff --git a/src/util/virpci.c b/src/util/virpci.c
index 9878398..a007eea 100644
--- a/src/util/virpci.c
+++ b/src/util/virpci.c
@@ -1101,6 +1101,31 @@ virPCIDeviceUnbind(virPCIDevicePtr dev)
 return ret;
 }

+
+/**
+ * virPCIDeviceRebind:
+ *  @dev: virPCIDevice object describing the device to rebind
+ *
+ * unbind a device from its driver, then immediately rebind it.
+ *
+ * Returns 0 on success, -1 on failure
+ */
+int virPCIDeviceRebind(virPCIDevicePtr dev)
+{
+if (virPCIDeviceUnbind(dev) < 0)
+return -1;
+
+if (virFileWriteStr(PCI_SYSFS "drivers_probe", dev->name, 0) < 0) {
+virReportSystemError(errno,
+ _("Failed to trigger a probe for PCI device 
'%s'"),
+ dev->name);
+return -1;
+}
+
+return 0;
+}
+


This is the same code as in virPCIDeviceBindWithDriverOverride(). ACK if 
you replace it with call to this function.


Michal

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


[libvirt] [PATCH 08/19] util: new function virPCIDeviceRebind()

2017-03-10 Thread Laine Stump
This function unbinds a device from its driver, then immediately
rebinds it to its driver again.
---
 src/libvirt_private.syms |  1 +
 src/util/virpci.c| 25 +
 src/util/virpci.h|  1 +
 3 files changed, 27 insertions(+)

diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
index b44a6ee..ef027cc 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -2217,6 +2217,7 @@ virPCIDeviceListSteal;
 virPCIDeviceListStealIndex;
 virPCIDeviceNew;
 virPCIDeviceReattach;
+virPCIDeviceRebind;
 virPCIDeviceReset;
 virPCIDeviceSetManaged;
 virPCIDeviceSetRemoveSlot;
diff --git a/src/util/virpci.c b/src/util/virpci.c
index 9878398..a007eea 100644
--- a/src/util/virpci.c
+++ b/src/util/virpci.c
@@ -1101,6 +1101,31 @@ virPCIDeviceUnbind(virPCIDevicePtr dev)
 return ret;
 }
 
+
+/**
+ * virPCIDeviceRebind:
+ *  @dev: virPCIDevice object describing the device to rebind
+ *
+ * unbind a device from its driver, then immediately rebind it.
+ *
+ * Returns 0 on success, -1 on failure
+ */
+int virPCIDeviceRebind(virPCIDevicePtr dev)
+{
+if (virPCIDeviceUnbind(dev) < 0)
+return -1;
+
+if (virFileWriteStr(PCI_SYSFS "drivers_probe", dev->name, 0) < 0) {
+virReportSystemError(errno,
+ _("Failed to trigger a probe for PCI device 
'%s'"),
+ dev->name);
+return -1;
+}
+
+return 0;
+}
+
+
 /*
  * Bind a PCI device to a driver using driver_override sysfs interface.
  * E.g.
diff --git a/src/util/virpci.h b/src/util/virpci.h
index 4be9cc0..8637c2c 100644
--- a/src/util/virpci.h
+++ b/src/util/virpci.h
@@ -225,6 +225,7 @@ int virPCIGetVirtualFunctionInfo(const char 
*vf_sysfs_device_path,
  char **pfname, int *vf_index);
 
 int virPCIDeviceUnbind(virPCIDevicePtr dev);
+int virPCIDeviceRebind(virPCIDevicePtr dev);
 int virPCIDeviceGetDriverPathAndName(virPCIDevicePtr dev,
  char **path,
  char **name);
-- 
2.9.3

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list