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

Michal Privoznik mprivozn at redhat.com
Tue Apr 13 10:01:53 UTC 2021


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 at 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




More information about the libvir-list mailing list