[PATCH v2 2/3] nodedev: Mark device initialization complete even in case of an error

Michal Privoznik posted 3 patches 4 years, 10 months ago
[PATCH v2 2/3] nodedev: Mark device initialization complete even in case of an error
Posted by Michal Privoznik 4 years, 10 months ago
To speed up nodedev driver initialization, the device enumeration
is done in a separate thread. Once finished, the thread sets a
boolean variable that allows public APIs to be called (instead of
waiting for the thread to finish).

However, if there's an error in the device enumeration thread
then the control jumps over at the 'error' label and the boolean
is never set. This means, that any virNodeDev*() API is stuck
forever. Mark the initialization as complete (the thread is
quitting anyway) and let the APIs proceed.

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

diff --git a/src/node_device/node_device_udev.c b/src/node_device/node_device_udev.c
index 84785d9e1e..658170a767 100644
--- a/src/node_device/node_device_udev.c
+++ b/src/node_device/node_device_udev.c
@@ -1982,6 +1982,7 @@ nodeStateInitializeEnumerate(void *opaque)
     if (nodeDeviceUpdateMediatedDevices() != 0)
         goto error;
 
+ cleanup:
     nodeDeviceLock();
     driver->initialized = true;
     virCondBroadcast(&driver->initCond);
@@ -1996,6 +1997,8 @@ nodeStateInitializeEnumerate(void *opaque)
     priv->threadQuit = true;
     virCondSignal(&priv->threadCond);
     virObjectUnlock(priv);
+
+    goto cleanup;
 }
 
 
-- 
2.26.3

Re: [PATCH v2 2/3] nodedev: Mark device initialization complete even in case of an error
Posted by Erik Skultety 4 years, 10 months ago
On Tue, Apr 13, 2021 at 05:57:14PM +0200, Michal Privoznik wrote:
> To speed up nodedev driver initialization, the device enumeration
> is done in a separate thread. Once finished, the thread sets a
> boolean variable that allows public APIs to be called (instead of
> waiting for the thread to finish).
> 
> However, if there's an error in the device enumeration thread
> then the control jumps over at the 'error' label and the boolean
> is never set. This means, that any virNodeDev*() API is stuck
> forever. Mark the initialization as complete (the thread is
> quitting anyway) and let the APIs proceed.
> 
> Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
> ---
Reviewed-by: Erik Skultety <eskultet@redhat.com>