summaryrefslogtreecommitdiff
path: root/src/node_device
diff options
context:
space:
mode:
authorMichal Privoznik <mprivozn@redhat.com>2021-04-13 11:18:23 +0200
committerMichal Privoznik <mprivozn@redhat.com>2021-04-14 10:16:48 +0200
commit77a13eb9ac3ac054bde3dafb0bcbedb77f07a135 (patch)
treeae1342cf254d475b2ec678170747476db6fc2dc5 /src/node_device
parent5b56a288cab097896832dc9d4acb7f23dfca377c (diff)
downloadlibvirt-77a13eb9ac3ac054bde3dafb0bcbedb77f07a135.tar.gz
nodedev: Wait for device initialization in all public API callbacks
Although I have not experienced this in real life, there is a possible race condition when creating new device, getting its XML or parent or listing its capabilities. If the nodedev driver is still enumerating devices (in a separate thread) and one of virNodeDeviceGetXMLDesc(), virNodeDeviceGetParent(), virNodeDeviceNumOfCaps(), virNodeDeviceListCaps() or 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 any of the APIs. Signed-off-by: Michal Privoznik <mprivozn@redhat.com> Reviewed-by: Erik Skultety <eskultet@redhat.com>
Diffstat (limited to 'src/node_device')
-rw-r--r--src/node_device/node_device_driver.c15
1 files changed, 15 insertions, 0 deletions
diff --git a/src/node_device/node_device_driver.c b/src/node_device/node_device_driver.c
index 5f8995172d..7aee8201e8 100644
--- a/src/node_device/node_device_driver.c
+++ b/src/node_device/node_device_driver.c
@@ -340,6 +340,9 @@ nodeDeviceGetXMLDesc(virNodeDevicePtr device,
virCheckFlags(0, NULL);
+ if (nodeDeviceInitWait() < 0)
+ return NULL;
+
if (!(obj = nodeDeviceObjFindByName(device->name)))
return NULL;
def = virNodeDeviceObjGetDef(obj);
@@ -368,6 +371,9 @@ nodeDeviceGetParent(virNodeDevicePtr device)
virNodeDeviceDef *def;
char *ret = NULL;
+ if (nodeDeviceInitWait() < 0)
+ return NULL;
+
if (!(obj = nodeDeviceObjFindByName(device->name)))
return NULL;
def = virNodeDeviceObjGetDef(obj);
@@ -395,6 +401,9 @@ nodeDeviceNumOfCaps(virNodeDevicePtr device)
virNodeDeviceDef *def;
int ret = -1;
+ if (nodeDeviceInitWait() < 0)
+ return -1;
+
if (!(obj = nodeDeviceObjFindByName(device->name)))
return -1;
def = virNodeDeviceObjGetDef(obj);
@@ -423,6 +432,9 @@ nodeDeviceListCaps(virNodeDevicePtr device,
int ret = -1;
size_t i = 0;
+ if (nodeDeviceInitWait() < 0)
+ return -1;
+
if (!(obj = nodeDeviceObjFindByName(device->name)))
return -1;
def = virNodeDeviceObjGetDef(obj);
@@ -1399,6 +1411,9 @@ nodeDeviceCreate(virNodeDevice *device,
virCheckFlags(0, -1);
+ if (nodeDeviceInitWait() < 0)
+ return -1;
+
if (!(obj = nodeDeviceObjFindByName(device->name)))
return -1;