mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-08-28 11:31:16 +00:00
virthreadpool: Allow setting identity for workers
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>
This commit is contained in:
parent
775de86975
commit
0c8f1aeddf
@ -1333,6 +1333,7 @@ virNWFilterDHCPSnoopThread(void *req0)
|
|||||||
worker = virThreadPoolNewFull(1, 1, 0,
|
worker = virThreadPoolNewFull(1, 1, 0,
|
||||||
virNWFilterDHCPDecodeWorker,
|
virNWFilterDHCPDecodeWorker,
|
||||||
"dhcp-decode",
|
"dhcp-decode",
|
||||||
|
NULL,
|
||||||
req);
|
req);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -914,7 +914,9 @@ qemuStateInitialize(bool privileged,
|
|||||||
* running domains since there might occur some QEMU monitor
|
* running domains since there might occur some QEMU monitor
|
||||||
* events that will be dispatched to the worker pool */
|
* events that will be dispatched to the worker pool */
|
||||||
qemu_driver->workerPool = virThreadPoolNewFull(0, 1, 0, qemuProcessEventHandler,
|
qemu_driver->workerPool = virThreadPoolNewFull(0, 1, 0, qemuProcessEventHandler,
|
||||||
"qemu-event", qemu_driver);
|
"qemu-event",
|
||||||
|
NULL,
|
||||||
|
qemu_driver);
|
||||||
if (!qemu_driver->workerPool)
|
if (!qemu_driver->workerPool)
|
||||||
goto error;
|
goto error;
|
||||||
|
|
||||||
|
@ -378,6 +378,7 @@ virNetServer *virNetServerNew(const char *name,
|
|||||||
priority_workers,
|
priority_workers,
|
||||||
virNetServerHandleJob,
|
virNetServerHandleJob,
|
||||||
"rpc-worker",
|
"rpc-worker",
|
||||||
|
NULL,
|
||||||
srv)))
|
srv)))
|
||||||
goto error;
|
goto error;
|
||||||
|
|
||||||
|
@ -55,6 +55,8 @@ struct _virThreadPool {
|
|||||||
virThreadPoolJobList jobList;
|
virThreadPoolJobList jobList;
|
||||||
size_t jobQueueDepth;
|
size_t jobQueueDepth;
|
||||||
|
|
||||||
|
virIdentity *identity;
|
||||||
|
|
||||||
virMutex mutex;
|
virMutex mutex;
|
||||||
virCond cond;
|
virCond cond;
|
||||||
virCond quit_cond;
|
virCond quit_cond;
|
||||||
@ -99,6 +101,9 @@ static void virThreadPoolWorker(void *opaque)
|
|||||||
|
|
||||||
virMutexLock(&pool->mutex);
|
virMutexLock(&pool->mutex);
|
||||||
|
|
||||||
|
if (pool->identity)
|
||||||
|
virIdentitySetCurrent(pool->identity);
|
||||||
|
|
||||||
while (1) {
|
while (1) {
|
||||||
/* In order to support async worker termination, we need ensure that
|
/* In order to support async worker termination, we need ensure that
|
||||||
* both busy and free workers know if they need to terminated. Thus,
|
* both busy and free workers know if they need to terminated. Thus,
|
||||||
@ -219,6 +224,7 @@ virThreadPoolNewFull(size_t minWorkers,
|
|||||||
size_t prioWorkers,
|
size_t prioWorkers,
|
||||||
virThreadPoolJobFunc func,
|
virThreadPoolJobFunc func,
|
||||||
const char *name,
|
const char *name,
|
||||||
|
virIdentity *identity,
|
||||||
void *opaque)
|
void *opaque)
|
||||||
{
|
{
|
||||||
virThreadPool *pool;
|
virThreadPool *pool;
|
||||||
@ -234,6 +240,9 @@ virThreadPoolNewFull(size_t minWorkers,
|
|||||||
pool->jobName = name;
|
pool->jobName = name;
|
||||||
pool->jobOpaque = opaque;
|
pool->jobOpaque = opaque;
|
||||||
|
|
||||||
|
if (identity)
|
||||||
|
pool->identity = g_object_ref(identity);
|
||||||
|
|
||||||
if (virMutexInit(&pool->mutex) < 0)
|
if (virMutexInit(&pool->mutex) < 0)
|
||||||
goto error;
|
goto error;
|
||||||
if (virCondInit(&pool->cond) < 0)
|
if (virCondInit(&pool->cond) < 0)
|
||||||
@ -300,6 +309,9 @@ void virThreadPoolFree(virThreadPool *pool)
|
|||||||
virMutexLock(&pool->mutex);
|
virMutexLock(&pool->mutex);
|
||||||
virThreadPoolDrainLocked(pool);
|
virThreadPoolDrainLocked(pool);
|
||||||
|
|
||||||
|
if (pool->identity)
|
||||||
|
g_object_unref(pool->identity);
|
||||||
|
|
||||||
g_free(pool->workers);
|
g_free(pool->workers);
|
||||||
virMutexUnlock(&pool->mutex);
|
virMutexUnlock(&pool->mutex);
|
||||||
virMutexDestroy(&pool->mutex);
|
virMutexDestroy(&pool->mutex);
|
||||||
|
@ -22,17 +22,19 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "internal.h"
|
#include "internal.h"
|
||||||
|
#include "viridentity.h"
|
||||||
|
|
||||||
typedef struct _virThreadPool virThreadPool;
|
typedef struct _virThreadPool virThreadPool;
|
||||||
|
|
||||||
typedef void (*virThreadPoolJobFunc)(void *jobdata, void *opaque);
|
typedef void (*virThreadPoolJobFunc)(void *jobdata, void *opaque);
|
||||||
|
|
||||||
virThreadPool *virThreadPoolNewFull(size_t minWorkers,
|
virThreadPool *virThreadPoolNewFull(size_t minWorkers,
|
||||||
size_t maxWorkers,
|
size_t maxWorkers,
|
||||||
size_t prioWorkers,
|
size_t prioWorkers,
|
||||||
virThreadPoolJobFunc func,
|
virThreadPoolJobFunc func,
|
||||||
const char *name,
|
const char *name,
|
||||||
void *opaque) ATTRIBUTE_NONNULL(4);
|
virIdentity *identity,
|
||||||
|
void *opaque) ATTRIBUTE_NONNULL(4);
|
||||||
|
|
||||||
size_t virThreadPoolGetMinWorkers(virThreadPool *pool);
|
size_t virThreadPoolGetMinWorkers(virThreadPool *pool);
|
||||||
size_t virThreadPoolGetMaxWorkers(virThreadPool *pool);
|
size_t virThreadPoolGetMaxWorkers(virThreadPool *pool);
|
||||||
|
Loading…
Reference in New Issue
Block a user