[PATCH 4/6] nodedev: Introduce nodeDeviceInitComplete()

Michal Privoznik posted 6 patches 4 years, 10 months ago
There is a newer version of this series
[PATCH 4/6] nodedev: Introduce nodeDeviceInitComplete()
Posted by Michal Privoznik 4 years, 10 months ago
When the device enumeration thread finishes it sets the
driver->initialized boolean and signals condition to wake up
other threads that are waiting for the initialization to
complete. Move this code into a separate function so that it can
be re-used from other places too.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
---
 src/node_device/node_device_driver.c | 10 ++++++++++
 src/node_device/node_device_driver.h |  2 ++
 src/node_device/node_device_udev.c   |  5 +----
 3 files changed, 13 insertions(+), 4 deletions(-)

diff --git a/src/node_device/node_device_driver.c b/src/node_device/node_device_driver.c
index bc8a758c1c..2bb83c19f2 100644
--- a/src/node_device/node_device_driver.c
+++ b/src/node_device/node_device_driver.c
@@ -157,6 +157,16 @@ nodeDeviceUnlock(void)
 }
 
 
+void
+nodeDeviceInitComplete(void)
+{
+    nodeDeviceLock();
+    driver->initialized = true;
+    virCondBroadcast(&driver->initCond);
+    nodeDeviceUnlock();
+}
+
+
 static int
 nodeDeviceInitWait(void)
 {
diff --git a/src/node_device/node_device_driver.h b/src/node_device/node_device_driver.h
index 8a935ffed6..7160f551db 100644
--- a/src/node_device/node_device_driver.h
+++ b/src/node_device/node_device_driver.h
@@ -39,6 +39,8 @@ nodeDeviceLock(void);
 void
 nodeDeviceUnlock(void);
 
+void nodeDeviceInitComplete(void);
+
 extern virNodeDeviceDriverStatePtr driver;
 
 int
diff --git a/src/node_device/node_device_udev.c b/src/node_device/node_device_udev.c
index 20a13211a0..68547c6986 100644
--- a/src/node_device/node_device_udev.c
+++ b/src/node_device/node_device_udev.c
@@ -1984,10 +1984,7 @@ nodeStateInitializeEnumerate(void *opaque)
     if (nodeDeviceUpdateMediatedDevices() != 0)
         goto error;
 
-    nodeDeviceLock();
-    driver->initialized = true;
-    virCondBroadcast(&driver->initCond);
-    nodeDeviceUnlock();
+    nodeDeviceInitComplete();
 
     return;
 
-- 
2.26.3

Re: [PATCH 4/6] nodedev: Introduce nodeDeviceInitComplete()
Posted by Erik Skultety 4 years, 10 months ago
On Tue, Apr 13, 2021 at 12:01:55PM +0200, Michal Privoznik wrote:
> When the device enumeration thread finishes it sets the
> driver->initialized boolean and signals condition to wake up
> other threads that are waiting for the initialization to
> complete. Move this code into a separate function so that it can
> be re-used from other places too.
> 
> Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
> ---
....

> diff --git a/src/node_device/node_device_udev.c b/src/node_device/node_device_udev.c
> index 20a13211a0..68547c6986 100644
> --- a/src/node_device/node_device_udev.c
> +++ b/src/node_device/node_device_udev.c
> @@ -1984,10 +1984,7 @@ nodeStateInitializeEnumerate(void *opaque)
>      if (nodeDeviceUpdateMediatedDevices() != 0)
>          goto error;
>  
> -    nodeDeviceLock();
> -    driver->initialized = true;
> -    virCondBroadcast(&driver->initCond);
> -    nodeDeviceUnlock();
> +    nodeDeviceInitComplete();

well, it will be re-used in the same function after patch 5. I suggest going
with the old style - introducing a fallthrough cleanup label and adding a 'goto
cleanup' to the 'error' section. Patch 5 will not be needed in that case.

Erik

Re: [PATCH 4/6] nodedev: Introduce nodeDeviceInitComplete()
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:55PM +0200, Michal Privoznik wrote:
>> When the device enumeration thread finishes it sets the
>> driver->initialized boolean and signals condition to wake up
>> other threads that are waiting for the initialization to
>> complete. Move this code into a separate function so that it can
>> be re-used from other places too.
>>
>> Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
>> ---
> ....
> 
>> diff --git a/src/node_device/node_device_udev.c b/src/node_device/node_device_udev.c
>> index 20a13211a0..68547c6986 100644
>> --- a/src/node_device/node_device_udev.c
>> +++ b/src/node_device/node_device_udev.c
>> @@ -1984,10 +1984,7 @@ nodeStateInitializeEnumerate(void *opaque)
>>       if (nodeDeviceUpdateMediatedDevices() != 0)
>>           goto error;
>>   
>> -    nodeDeviceLock();
>> -    driver->initialized = true;
>> -    virCondBroadcast(&driver->initCond);
>> -    nodeDeviceUnlock();
>> +    nodeDeviceInitComplete();
> 
> well, it will be re-used in the same function after patch 5. I suggest going
> with the old style - introducing a fallthrough cleanup label and adding a 'goto
> cleanup' to the 'error' section. Patch 5 will not be needed in that case.

Fair enough.

Michal