]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
virthreadpool: Allow setting identity for workers
authorMichal Privoznik <mprivozn@redhat.com>
Tue, 26 Oct 2021 09:04:24 +0000 (11:04 +0200)
committerMichal Privoznik <mprivozn@redhat.com>
Wed, 27 Oct 2021 15:11:29 +0000 (17:11 +0200)
In some cases the worker func running inside the pool may rely on
virIdentity. While worker func could check for identity and set
one it is not optimal - it may not have access to the identity of
the thread creating the pool and thus would have to call
virIdentityGetSystem(). Allow passing identity when creating the
pool.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
src/nwfilter/nwfilter_dhcpsnoop.c
src/qemu/qemu_driver.c
src/rpc/virnetserver.c
src/util/virthreadpool.c
src/util/virthreadpool.h

index 4b62a7b661584cab3b5312b58ed5054e9e88c01d..b0297f0741ebceaf91f5ae2da7b428f81a50c5e9 100644 (file)
@@ -1333,6 +1333,7 @@ virNWFilterDHCPSnoopThread(void *req0)
         worker = virThreadPoolNewFull(1, 1, 0,
                                       virNWFilterDHCPDecodeWorker,
                                       "dhcp-decode",
+                                      NULL,
                                       req);
     }
 
index 6997dc7deaf19e2a7db3b63569f10d73cb31c000..a8bf0ecc6fe55cda54b3653d685e53ad05ffac79 100644 (file)
@@ -914,7 +914,9 @@ qemuStateInitialize(bool privileged,
      * running domains since there might occur some QEMU monitor
      * events that will be dispatched to the worker pool */
     qemu_driver->workerPool = virThreadPoolNewFull(0, 1, 0, qemuProcessEventHandler,
-                                                   "qemu-event", qemu_driver);
+                                                   "qemu-event",
+                                                   NULL,
+                                                   qemu_driver);
     if (!qemu_driver->workerPool)
         goto error;
 
index dc8f32b095d707d730f8b354b5e80ad4d0876800..c7b4939398b76a8f4a9821fb7b17a2c71c40c2b3 100644 (file)
@@ -378,6 +378,7 @@ virNetServer *virNetServerNew(const char *name,
                                               priority_workers,
                                               virNetServerHandleJob,
                                               "rpc-worker",
+                                              NULL,
                                               srv)))
         goto error;
 
index 92b7cac286b587076b87a304125e39cb557fb477..7bf433388537b53f994450d1721a511439759d1d 100644 (file)
@@ -55,6 +55,8 @@ struct _virThreadPool {
     virThreadPoolJobList jobList;
     size_t jobQueueDepth;
 
+    virIdentity *identity;
+
     virMutex mutex;
     virCond cond;
     virCond quit_cond;
@@ -99,6 +101,9 @@ static void virThreadPoolWorker(void *opaque)
 
     virMutexLock(&pool->mutex);
 
+    if (pool->identity)
+        virIdentitySetCurrent(pool->identity);
+
     while (1) {
         /* In order to support async worker termination, we need ensure that
          * both busy and free workers know if they need to terminated. Thus,
@@ -219,6 +224,7 @@ virThreadPoolNewFull(size_t minWorkers,
                      size_t prioWorkers,
                      virThreadPoolJobFunc func,
                      const char *name,
+                     virIdentity *identity,
                      void *opaque)
 {
     virThreadPool *pool;
@@ -234,6 +240,9 @@ virThreadPoolNewFull(size_t minWorkers,
     pool->jobName = name;
     pool->jobOpaque = opaque;
 
+    if (identity)
+        pool->identity = g_object_ref(identity);
+
     if (virMutexInit(&pool->mutex) < 0)
         goto error;
     if (virCondInit(&pool->cond) < 0)
@@ -300,6 +309,9 @@ void virThreadPoolFree(virThreadPool *pool)
     virMutexLock(&pool->mutex);
     virThreadPoolDrainLocked(pool);
 
+    if (pool->identity)
+        g_object_unref(pool->identity);
+
     g_free(pool->workers);
     virMutexUnlock(&pool->mutex);
     virMutexDestroy(&pool->mutex);
index 619d128e9a492e37b8e942f98195b9f3c3259fa2..c6b9f3191654a776b7f9263bc283eed1e736cff4 100644 (file)
 #pragma once
 
 #include "internal.h"
+#include "viridentity.h"
 
 typedef struct _virThreadPool virThreadPool;
 
 typedef void (*virThreadPoolJobFunc)(void *jobdata, void *opaque);
 
 virThreadPool *virThreadPoolNewFull(size_t minWorkers,
-                                      size_t maxWorkers,
-                                      size_t prioWorkers,
-                                      virThreadPoolJobFunc func,
-                                      const char *name,
-                                      void *opaque) ATTRIBUTE_NONNULL(4);
+                                    size_t maxWorkers,
+                                    size_t prioWorkers,
+                                    virThreadPoolJobFunc func,
+                                    const char *name,
+                                    virIdentity *identity,
+                                    void *opaque) ATTRIBUTE_NONNULL(4);
 
 size_t virThreadPoolGetMinWorkers(virThreadPool *pool);
 size_t virThreadPoolGetMaxWorkers(virThreadPool *pool);