[libvirt] [PATCH 7/9] rpc: Alter virNetDaemonQuit processing

John Ferlan posted 9 patches 7 years, 3 months ago
There is a newer version of this series
[libvirt] [PATCH 7/9] rpc: Alter virNetDaemonQuit processing
Posted by John Ferlan 7 years, 3 months ago
When virNetDaemonQuit is called from libvirtd's shutdown
handler (daemonShutdownHandler) we need to perform the quit
in multiple steps. The first part is to "request" the quit
and notify the NetServer's of the impending quit which causes
the NetServers to Drain their pending queue and tell workers
to quit and the second is wait for any currently running
worker jobs to complete. Once the workers are complete, then
we can cause the quit to occur.

Signed-off-by: John Ferlan <jferlan@redhat.com>
---
 src/rpc/virnetdaemon.c | 32 +++++++++++++++++++++++++++++++-
 1 file changed, 31 insertions(+), 1 deletion(-)

diff --git a/src/rpc/virnetdaemon.c b/src/rpc/virnetdaemon.c
index e5b376ced..6aee712a5 100644
--- a/src/rpc/virnetdaemon.c
+++ b/src/rpc/virnetdaemon.c
@@ -73,6 +73,7 @@ struct _virNetDaemon {
     virHashTablePtr servers;
     virJSONValuePtr srvObject;
 
+    bool quitRequested;
     bool quit;
 
     unsigned int autoShutdownTimeout;
@@ -779,6 +780,32 @@ daemonServerProcessClients(void *payload,
     return 0;
 }
 
+
+static int
+daemonServerWorkerCount(void *payload,
+                        const void *key ATTRIBUTE_UNUSED,
+                        void *opaque)
+{
+    size_t *workerCount = opaque;
+    virNetServerPtr srv = payload;
+
+    *workerCount += virNetServerWorkerCount(srv);
+
+    return 0;
+}
+
+
+static bool
+daemonServerWorkersDone(virNetDaemonPtr dmn)
+{
+    size_t workerCount = 0;
+
+    virHashForEach(dmn->servers, daemonServerWorkerCount, &workerCount);
+
+    return workerCount == 0;
+}
+
+
 void
 virNetDaemonRun(virNetDaemonPtr dmn)
 {
@@ -843,6 +870,9 @@ virNetDaemonRun(virNetDaemonPtr dmn)
         virObjectLock(dmn);
 
         virHashForEach(dmn->servers, daemonServerProcessClients, NULL);
+
+        if (dmn->quitRequested && daemonServerWorkersDone(dmn))
+            dmn->quit = true;
     }
 
  cleanup:
@@ -868,7 +898,7 @@ virNetDaemonQuit(virNetDaemonPtr dmn)
     virObjectLock(dmn);
 
     VIR_DEBUG("Quit requested %p", dmn);
-    dmn->quit = true;
+    dmn->quitRequested = true;
     virHashForEach(dmn->servers, daemonServerQuitRequested, NULL);
 
     virObjectUnlock(dmn);
-- 
2.13.6

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] [PATCH 7/9] rpc: Alter virNetDaemonQuit processing
Posted by John Ferlan 7 years, 3 months ago

On 01/19/2018 12:23 PM, John Ferlan wrote:
> When virNetDaemonQuit is called from libvirtd's shutdown
> handler (daemonShutdownHandler) we need to perform the quit
> in multiple steps. The first part is to "request" the quit
> and notify the NetServer's of the impending quit which causes
> the NetServers to Drain their pending queue and tell workers
> to quit and the second is wait for any currently running
> worker jobs to complete. Once the workers are complete, then
> we can cause the quit to occur.
> 
> Signed-off-by: John Ferlan <jferlan@redhat.com>
> ---
>  src/rpc/virnetdaemon.c | 32 +++++++++++++++++++++++++++++++-
>  1 file changed, 31 insertions(+), 1 deletion(-)
> 

sigh - too quick with the send and neglected to run the so what happens
when I have nothing pending check/test...  Attached is a patch that
would be merged with this one.

John
> diff --git a/src/rpc/virnetdaemon.c b/src/rpc/virnetdaemon.c
> index e5b376ced..6aee712a5 100644
> --- a/src/rpc/virnetdaemon.c
> +++ b/src/rpc/virnetdaemon.c
> @@ -73,6 +73,7 @@ struct _virNetDaemon {
>      virHashTablePtr servers;
>      virJSONValuePtr srvObject;
>  
> +    bool quitRequested;
>      bool quit;
>  
>      unsigned int autoShutdownTimeout;
> @@ -779,6 +780,32 @@ daemonServerProcessClients(void *payload,
>      return 0;
>  }
>  
> +
> +static int
> +daemonServerWorkerCount(void *payload,
> +                        const void *key ATTRIBUTE_UNUSED,
> +                        void *opaque)
> +{
> +    size_t *workerCount = opaque;
> +    virNetServerPtr srv = payload;
> +
> +    *workerCount += virNetServerWorkerCount(srv);
> +
> +    return 0;
> +}
> +
> +
> +static bool
> +daemonServerWorkersDone(virNetDaemonPtr dmn)
> +{
> +    size_t workerCount = 0;
> +
> +    virHashForEach(dmn->servers, daemonServerWorkerCount, &workerCount);
> +
> +    return workerCount == 0;
> +}
> +
> +
>  void
>  virNetDaemonRun(virNetDaemonPtr dmn)
>  {
> @@ -843,6 +870,9 @@ virNetDaemonRun(virNetDaemonPtr dmn)
>          virObjectLock(dmn);
>  
>          virHashForEach(dmn->servers, daemonServerProcessClients, NULL);
> +
> +        if (dmn->quitRequested && daemonServerWorkersDone(dmn))
> +            dmn->quit = true;
>      }
>  
>   cleanup:
> @@ -868,7 +898,7 @@ virNetDaemonQuit(virNetDaemonPtr dmn)
>      virObjectLock(dmn);
>  
>      VIR_DEBUG("Quit requested %p", dmn);
> -    dmn->quit = true;
> +    dmn->quitRequested = true;
>      virHashForEach(dmn->servers, daemonServerQuitRequested, NULL);
>  
>      virObjectUnlock(dmn);
> 

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] [PATCH 7/9] rpc: Alter virNetDaemonQuit processing
Posted by Marc Hartmayer 6 years, 10 months ago
On Fri, Jan 19, 2018 at 06:23 PM +0100, John Ferlan <jferlan@redhat.com> wrote:
> When virNetDaemonQuit is called from libvirtd's shutdown
> handler (daemonShutdownHandler) we need to perform the quit
> in multiple steps. The first part is to "request" the quit
> and notify the NetServer's of the impending quit which causes
> the NetServers to Drain their pending queue and tell workers
> to quit and the second is wait for any currently running
> worker jobs to complete. Once the workers are complete, then
> we can cause the quit to occur.

Instead of “polling” for 'daemonServerWorkersDone' we could use a pipe
for signaling. This would also ensure that we do not remain in the
poll() call indefinitely and it avoids the timer hack.

[…snip]

--
Beste Grüße / Kind regards
   Marc Hartmayer

IBM Deutschland Research & Development GmbH
Vorsitzende des Aufsichtsrats: Martina Koederitz
Geschäftsführung: Dirk Wittkopp
Sitz der Gesellschaft: Böblingen
Registergericht: Amtsgericht Stuttgart, HRB 243294


--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list