Re: [PATCH 01/10] libvirt: add stateShutdown/stateShutdownWait to drivers

2020-07-21 Thread Daniel P . Berrangé
On Tue, Jul 14, 2020 at 12:32:52PM +0300, Nikolay Shirokovskiy wrote:
> stateShutdown is supposed to inform driver that it will be closed soon so that
> the driver can prepare and finish all background threads quickly on
> stateShutdownWait call.
> 
> Signed-off-by: Nikolay Shirokovskiy 
> ---
>  scripts/check-drivername.py |  2 ++
>  src/driver-state.h  |  8 
>  src/libvirt.c   | 42 ++
>  src/libvirt_internal.h  |  2 ++
>  4 files changed, 54 insertions(+)
> 
> diff --git a/scripts/check-drivername.py b/scripts/check-drivername.py
> index 39eff83..19d1cd1 100644
> --- a/scripts/check-drivername.py
> +++ b/scripts/check-drivername.py
> @@ -50,6 +50,8 @@ for drvfile in drvfiles:
>  "virDrvStateCleanup",
>  "virDrvStateReload",
>  "virDrvStateStop",
> +"virDrvStateShutdown",
> +"virDrvStateShutdownWait",
>  "virDrvConnectSupportsFeature",
>  "virDrvConnectURIProbe",
>  "virDrvDomainMigratePrepare",
> diff --git a/src/driver-state.h b/src/driver-state.h
> index 6b3f501..1f664f3 100644
> --- a/src/driver-state.h
> +++ b/src/driver-state.h
> @@ -45,6 +45,12 @@ typedef int
>  typedef int
>  (*virDrvStateStop)(void);
>  
> +typedef int
> +(*virDrvStateShutdown)(void);
> +
> +typedef int
> +(*virDrvStateShutdownWait)(void);

This is a bit of a bikeshedding comment, but I would have called
them   "StateShutdownPrepare" and "StateShutdownComplete" (or Wait)
just to make it slightly clearer that the first method is just
intended to kick off a shutdown asynchronously.

The design overall looks fine though, so regardless of the name

Reviewed-by: Daniel P. Berrangé 


Regards,
Daniel
-- 
|: https://berrange.com  -o-https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org -o-https://fstop138.berrange.com :|
|: https://entangle-photo.org-o-https://www.instagram.com/dberrange :|



[PATCH 01/10] libvirt: add stateShutdown/stateShutdownWait to drivers

2020-07-14 Thread Nikolay Shirokovskiy
stateShutdown is supposed to inform driver that it will be closed soon so that
the driver can prepare and finish all background threads quickly on
stateShutdownWait call.

Signed-off-by: Nikolay Shirokovskiy 
---
 scripts/check-drivername.py |  2 ++
 src/driver-state.h  |  8 
 src/libvirt.c   | 42 ++
 src/libvirt_internal.h  |  2 ++
 4 files changed, 54 insertions(+)

diff --git a/scripts/check-drivername.py b/scripts/check-drivername.py
index 39eff83..19d1cd1 100644
--- a/scripts/check-drivername.py
+++ b/scripts/check-drivername.py
@@ -50,6 +50,8 @@ for drvfile in drvfiles:
 "virDrvStateCleanup",
 "virDrvStateReload",
 "virDrvStateStop",
+"virDrvStateShutdown",
+"virDrvStateShutdownWait",
 "virDrvConnectSupportsFeature",
 "virDrvConnectURIProbe",
 "virDrvDomainMigratePrepare",
diff --git a/src/driver-state.h b/src/driver-state.h
index 6b3f501..1f664f3 100644
--- a/src/driver-state.h
+++ b/src/driver-state.h
@@ -45,6 +45,12 @@ typedef int
 typedef int
 (*virDrvStateStop)(void);
 
+typedef int
+(*virDrvStateShutdown)(void);
+
+typedef int
+(*virDrvStateShutdownWait)(void);
+
 typedef struct _virStateDriver virStateDriver;
 typedef virStateDriver *virStateDriverPtr;
 
@@ -55,4 +61,6 @@ struct _virStateDriver {
 virDrvStateCleanup stateCleanup;
 virDrvStateReload stateReload;
 virDrvStateStop stateStop;
+virDrvStateShutdown stateShutdown;
+virDrvStateShutdownWait stateShutdownWait;
 };
diff --git a/src/libvirt.c b/src/libvirt.c
index b2d0ba3..28f9332 100644
--- a/src/libvirt.c
+++ b/src/libvirt.c
@@ -673,6 +673,48 @@ virStateInitialize(bool privileged,
 
 
 /**
+ * virStateShutdown:
+ *
+ * Run each virtualization driver's shutdown method.
+ *
+ * Returns 0 if all succeed, -1 upon any failure.
+ */
+int
+virStateShutdown(void)
+{
+size_t i;
+
+for (i = 0; i < virStateDriverTabCount; i++) {
+if (virStateDriverTab[i]->stateShutdown &&
+virStateDriverTab[i]->stateShutdown() < 0)
+return -1;
+}
+return 0;
+}
+
+
+/**
+ * virStateShutdownWait:
+ *
+ * Run each virtualization driver's shutdown wait method.
+ *
+ * Returns 0 if all succeed, -1 upon any failure.
+ */
+int
+virStateShutdownWait(void)
+{
+size_t i;
+
+for (i = 0; i < virStateDriverTabCount; i++) {
+if (virStateDriverTab[i]->stateShutdownWait &&
+virStateDriverTab[i]->stateShutdownWait() < 0)
+return -1;
+}
+return 0;
+}
+
+
+/**
  * virStateCleanup:
  *
  * Run each virtualization driver's cleanup method.
diff --git a/src/libvirt_internal.h b/src/libvirt_internal.h
index 72c6127..5b6035f 100644
--- a/src/libvirt_internal.h
+++ b/src/libvirt_internal.h
@@ -34,6 +34,8 @@ int virStateInitialize(bool privileged,
const char *root,
virStateInhibitCallback inhibit,
void *opaque);
+int virStateShutdown(void);
+int virStateShutdownWait(void);
 int virStateCleanup(void);
 int virStateReload(void);
 int virStateStop(void);
-- 
1.8.3.1