[PATCH 2/6] nodedev: Wait for device initialization in nodeDeviceCreate()

Michal Privoznik posted 6 patches 4 years, 10 months ago
There is a newer version of this series
[PATCH 2/6] nodedev: Wait for device initialization in nodeDeviceCreate()
Posted by Michal Privoznik 4 years, 10 months ago
Although I have not experienced this in real life, there is a
possible race condition when creating new device. If the nodedev
driver is still enumerating devices (in a separate thread) and
virNodeDeviceCreate() is called then it can lead to spurious
results because the device enumeration thread is removing devices
from or adding them to the internal list of devices (among with
their states).

Therefore, wait for things to settle down before proceeding with
nodeDeviceCreate().

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
---
 src/node_device/node_device_driver.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/src/node_device/node_device_driver.c b/src/node_device/node_device_driver.c
index 4678a0fc01..bc8a758c1c 100644
--- a/src/node_device/node_device_driver.c
+++ b/src/node_device/node_device_driver.c
@@ -1399,6 +1399,9 @@ nodeDeviceCreate(virNodeDevice *device,
 
     virCheckFlags(0, -1);
 
+    if (nodeDeviceInitWait() < 0)
+        return -1;
+
     if (!(obj = nodeDeviceObjFindByName(device->name)))
         return -1;
 
-- 
2.26.3

Re: [PATCH 2/6] nodedev: Wait for device initialization in nodeDeviceCreate()
Posted by Erik Skultety 4 years, 10 months ago
On Tue, Apr 13, 2021 at 12:01:53PM +0200, Michal Privoznik wrote:
> Although I have not experienced this in real life, there is a
> possible race condition when creating new device. If the nodedev
> driver is still enumerating devices (in a separate thread) and
> virNodeDeviceCreate() is called then it can lead to spurious
> results because the device enumeration thread is removing devices
> from or adding them to the internal list of devices (among with
> their states).
> 
> Therefore, wait for things to settle down before proceeding with
> nodeDeviceCreate().

Hmm, correct. Looking at the source - nodeDeviceGetXMLDesc,
nodeDeviceGetParent and nodeDeviceNumOfCaps are the only exceptions as far as
public API mappings go. Would you mind extending this patch?

Erik

Re: [PATCH 2/6] nodedev: Wait for device initialization in nodeDeviceCreate()
Posted by Michal Privoznik 4 years, 10 months ago
On 4/13/21 4:14 PM, Erik Skultety wrote:
> On Tue, Apr 13, 2021 at 12:01:53PM +0200, Michal Privoznik wrote:
>> Although I have not experienced this in real life, there is a
>> possible race condition when creating new device. If the nodedev
>> driver is still enumerating devices (in a separate thread) and
>> virNodeDeviceCreate() is called then it can lead to spurious
>> results because the device enumeration thread is removing devices
>> from or adding them to the internal list of devices (among with
>> their states).
>>
>> Therefore, wait for things to settle down before proceeding with
>> nodeDeviceCreate().
> 
> Hmm, correct. Looking at the source - nodeDeviceGetXMLDesc,
> nodeDeviceGetParent and nodeDeviceNumOfCaps are the only exceptions as far as
> public API mappings go. Would you mind extending this patch?

Good catch. In fact there's a fourth one - nodeDeviceListCaps.
Is it okay to fix locally or do you want me to send v2?

Michal