From nobody Mon Feb 9 18:01:40 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1530965514272933.7691903313946; Sat, 7 Jul 2018 05:11:54 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 949A9308FB95; Sat, 7 Jul 2018 12:11:51 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 25A1B608F6; Sat, 7 Jul 2018 12:11:51 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id B8A541841C49; Sat, 7 Jul 2018 12:11:50 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w67CBDNQ005889 for ; Sat, 7 Jul 2018 08:11:13 -0400 Received: by smtp.corp.redhat.com (Postfix) id 5E36E6515C; Sat, 7 Jul 2018 12:11:13 +0000 (UTC) Received: from unknown4CEB42C824F4.redhat.com (ovpn-116-46.phx2.redhat.com [10.3.116.46]) by smtp.corp.redhat.com (Postfix) with ESMTP id 1B2835C301 for ; Sat, 7 Jul 2018 12:11:13 +0000 (UTC) From: John Ferlan To: libvir-list@redhat.com Date: Sat, 7 Jul 2018 08:11:01 -0400 Message-Id: <20180707121107.7629-4-jferlan@redhat.com> In-Reply-To: <20180707121107.7629-1-jferlan@redhat.com> References: <20180707121107.7629-1-jferlan@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v2 3/9] util: Introduce virThreadPoolQuitRequested X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.43]); Sat, 07 Jul 2018 12:11:53 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Create a helper API to set the quit flag and wake up the worker threads when a quit has been requested such as via a signal handler. Signed-off-by: John Ferlan --- src/libvirt_private.syms | 1 + src/util/virthreadpool.c | 43 ++++++++++++++++++++++++++++++++++------ src/util/virthreadpool.h | 2 ++ 3 files changed, 40 insertions(+), 6 deletions(-) diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index 3e304907b9..af76c29928 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -3001,6 +3001,7 @@ virThreadPoolGetMaxWorkers; virThreadPoolGetMinWorkers; virThreadPoolGetPriorityWorkers; virThreadPoolNewFull; +virThreadPoolQuitRequested; virThreadPoolSendJob; virThreadPoolSetParameters; =20 diff --git a/src/util/virthreadpool.c b/src/util/virthreadpool.c index 10f2bd2c3a..137c5d1746 100644 --- a/src/util/virthreadpool.c +++ b/src/util/virthreadpool.c @@ -30,9 +30,12 @@ #include "viralloc.h" #include "virthread.h" #include "virerror.h" +#include "virlog.h" =20 #define VIR_FROM_THIS VIR_FROM_NONE =20 +VIR_LOG_INIT("util.threadpool"); + typedef struct _virThreadPoolJob virThreadPoolJob; typedef virThreadPoolJob *virThreadPoolJobPtr; =20 @@ -269,6 +272,18 @@ virThreadPoolNewFull(size_t minWorkers, =20 } =20 + +static void +virThreadPoolSetQuit(virThreadPoolPtr pool) +{ + pool->quit =3D true; + if (pool->nWorkers > 0) + virCondBroadcast(&pool->cond); + if (pool->nPrioWorkers > 0) + virCondBroadcast(&pool->prioCond); +} + + void virThreadPoolFree(virThreadPoolPtr pool) { virThreadPoolJobPtr job; @@ -278,13 +293,9 @@ void virThreadPoolFree(virThreadPoolPtr pool) return; =20 virMutexLock(&pool->mutex); - pool->quit =3D true; - if (pool->nWorkers > 0) - virCondBroadcast(&pool->cond); - if (pool->nPrioWorkers > 0) { + if (pool->nPrioWorkers > 0) priority =3D true; - virCondBroadcast(&pool->prioCond); - } + virThreadPoolSetQuit(pool); =20 while (pool->nWorkers > 0 || pool->nPrioWorkers > 0) ignore_value(virCondWait(&pool->quit_cond, &pool->mutex)); @@ -307,6 +318,26 @@ void virThreadPoolFree(virThreadPoolPtr pool) } =20 =20 +/* + * virThreadPoolQuitRequested: + * @pool: Pointer to thread pool + * + * When libvirtd quit is requested via the daemonShutdownHandler let's + * set the quit flag for current workers and wake them up. + */ +void +virThreadPoolQuitRequested(virThreadPoolPtr pool) +{ + virMutexLock(&pool->mutex); + + VIR_DEBUG("nWorkers=3D%zd, nPrioWorkers=3D%zd jobQueueDepth=3D%zd", + pool->nWorkers, pool->nPrioWorkers, pool->jobQueueDepth); + + virThreadPoolSetQuit(pool); + virMutexUnlock(&pool->mutex); +} + + size_t virThreadPoolGetMinWorkers(virThreadPoolPtr pool) { size_t ret; diff --git a/src/util/virthreadpool.h b/src/util/virthreadpool.h index e1f362f5bb..f2c8b2ae61 100644 --- a/src/util/virthreadpool.h +++ b/src/util/virthreadpool.h @@ -52,6 +52,8 @@ size_t virThreadPoolGetJobQueueDepth(virThreadPoolPtr poo= l); =20 void virThreadPoolFree(virThreadPoolPtr pool); =20 +void virThreadPoolQuitRequested(virThreadPoolPtr pool); + int virThreadPoolSendJob(virThreadPoolPtr pool, unsigned int priority, void *jobdata) ATTRIBUTE_NONNULL(1) --=20 2.17.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list