From nobody Sat Apr 20 06:15:26 2024 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 1530965480904108.07031793335273; Sat, 7 Jul 2018 05:11:20 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.25]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 58B87308212F; Sat, 7 Jul 2018 12:11:19 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 404BF2010CF4; Sat, 7 Jul 2018 12:11:18 +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 4729E4BB78; Sat, 7 Jul 2018 12:11:15 +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 w67CBCMj005857 for ; Sat, 7 Jul 2018 08:11:12 -0400 Received: by smtp.corp.redhat.com (Postfix) id 7FAF35C301; Sat, 7 Jul 2018 12:11:12 +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 3F0AA65F44 for ; Sat, 7 Jul 2018 12:11:12 +0000 (UTC) From: John Ferlan To: libvir-list@redhat.com Date: Sat, 7 Jul 2018 08:10:59 -0400 Message-Id: <20180707121107.7629-2-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 1/9] libvirtd: Alter refcnt processing for domain server objects 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.84 on 10.5.11.25 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.42]); Sat, 07 Jul 2018 12:11:19 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Once virNetDaemonAddServer returns, the @srv or @srvAdm have either been added to the @dmn list increasing the refcnt or there was an error. In either case, we can lower the refcnt from virNetServerNew, but not set to NULL. Thus "using" the hash table reference when adding programs later or allowing the immediate free of the object on error. The @dmn dispose function (virNetDaemonDispose) will handle the Unref of each object during the virHashFree when the object is removed from the hash table. Signed-off-by: John Ferlan Reviewed-by: Erik Skultety Reviewed-by: Marc Hartmayer --- src/remote/remote_daemon.c | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/src/remote/remote_daemon.c b/src/remote/remote_daemon.c index 9f3a5f38ad..f61d58f3e5 100644 --- a/src/remote/remote_daemon.c +++ b/src/remote/remote_daemon.c @@ -1036,6 +1036,7 @@ int main(int argc, char **argv) { char *remote_config_file =3D NULL; int statuswrite =3D -1; int ret =3D 1; + int rc; int pid_file_fd =3D -1; char *pid_file =3D NULL; char *sock_file =3D NULL; @@ -1290,7 +1291,11 @@ int main(int argc, char **argv) { goto cleanup; } =20 - if (virNetDaemonAddServer(dmn, srv) < 0) { + /* Add @srv to @dmn servers hash table and Unref to allow removal from + * hash table at @dmn disposal to decide when to free @srv */ + rc =3D virNetDaemonAddServer(dmn, srv); + virObjectUnref(srv); + if (rc < 0) { ret =3D VIR_DAEMON_ERR_INIT; goto cleanup; } @@ -1358,7 +1363,11 @@ int main(int argc, char **argv) { goto cleanup; } =20 - if (virNetDaemonAddServer(dmn, srvAdm) < 0) { + /* Add @srvAdm to @dmn servers hash table and Unref to allow removal f= rom + * hash table at @dmn disposal to decide when to free @srvAdm */ + rc =3D virNetDaemonAddServer(dmn, srvAdm); + virObjectUnref(srvAdm); + if (rc < 0) { ret =3D VIR_DAEMON_ERR_INIT; goto cleanup; } @@ -1479,11 +1488,9 @@ int main(int argc, char **argv) { } =20 virObjectUnref(adminProgram); - virObjectUnref(srvAdm); virObjectUnref(qemuProgram); virObjectUnref(lxcProgram); virObjectUnref(remoteProgram); - virObjectUnref(srv); virObjectUnref(dmn); =20 virNetlinkShutdown(); --=20 2.17.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Sat Apr 20 06:15:27 2024 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 1530965506983907.2267909109892; Sat, 7 Jul 2018 05:11:46 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id A9EE8308624B; Sat, 7 Jul 2018 12:11:45 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 636E065F4F; Sat, 7 Jul 2018 12:11:45 +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 0CF21410B2; Sat, 7 Jul 2018 12:11:45 +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 w67CBCG5005875 for ; Sat, 7 Jul 2018 08:11:12 -0400 Received: by smtp.corp.redhat.com (Postfix) id E9CC86515C; Sat, 7 Jul 2018 12:11:12 +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 A6C9F5C301 for ; Sat, 7 Jul 2018 12:11:12 +0000 (UTC) From: John Ferlan To: libvir-list@redhat.com Date: Sat, 7 Jul 2018 08:11:00 -0400 Message-Id: <20180707121107.7629-3-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 2/9] libvirtd: Alter refcnt processing for server program objects 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.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.49]); Sat, 07 Jul 2018 12:11:46 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Once virNetServerProgramNew returns, the program objects have either been added to the @srv or @srvAdm list increasing the refcnt or there was an error. In either case, we can lower the refcnt from virNetServerProgramNew and set the object to NULL since it won't be used any more. The @srv or @srvAdm dispose function (virNetServerDispose) will handle the Unref of each object during the virHashFree when the object is removed from the hash table. Signed-off-by: John Ferlan --- src/remote/remote_daemon.c | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/src/remote/remote_daemon.c b/src/remote/remote_daemon.c index f61d58f3e5..dee634d7e1 100644 --- a/src/remote/remote_daemon.c +++ b/src/remote/remote_daemon.c @@ -1317,7 +1317,10 @@ int main(int argc, char **argv) { ret =3D VIR_DAEMON_ERR_INIT; goto cleanup; } - if (virNetServerAddProgram(srv, remoteProgram) < 0) { + + rc =3D virNetServerAddProgram(srv, remoteProgram); + virObjectUnref(remoteProgram); + if (rc < 0) { ret =3D VIR_DAEMON_ERR_INIT; goto cleanup; } @@ -1329,7 +1332,10 @@ int main(int argc, char **argv) { ret =3D VIR_DAEMON_ERR_INIT; goto cleanup; } - if (virNetServerAddProgram(srv, lxcProgram) < 0) { + + rc =3D virNetServerAddProgram(srv, lxcProgram); + virObjectUnref(lxcProgram); + if (rc < 0) { ret =3D VIR_DAEMON_ERR_INIT; goto cleanup; } @@ -1341,7 +1347,10 @@ int main(int argc, char **argv) { ret =3D VIR_DAEMON_ERR_INIT; goto cleanup; } - if (virNetServerAddProgram(srv, qemuProgram) < 0) { + + rc =3D virNetServerAddProgram(srv, qemuProgram); + virObjectUnref(qemuProgram); + if (rc < 0) { ret =3D VIR_DAEMON_ERR_INIT; goto cleanup; } @@ -1379,7 +1388,10 @@ int main(int argc, char **argv) { ret =3D VIR_DAEMON_ERR_INIT; goto cleanup; } - if (virNetServerAddProgram(srvAdm, adminProgram) < 0) { + + rc =3D virNetServerAddProgram(srvAdm, adminProgram); + virObjectUnref(adminProgram); + if (rc < 0) { ret =3D VIR_DAEMON_ERR_INIT; goto cleanup; } @@ -1487,10 +1499,6 @@ int main(int argc, char **argv) { virStateCleanup(); } =20 - virObjectUnref(adminProgram); - virObjectUnref(qemuProgram); - virObjectUnref(lxcProgram); - virObjectUnref(remoteProgram); virObjectUnref(dmn); =20 virNetlinkShutdown(); --=20 2.17.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Sat Apr 20 06:15:27 2024 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 From nobody Sat Apr 20 06:15:27 2024 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 1530965480909299.9701746188309; Sat, 7 Jul 2018 05:11:20 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 1AE708EB3F; Sat, 7 Jul 2018 12:11:19 +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 633705C301; Sat, 7 Jul 2018 12:11:18 +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 337DF1841C4A; Sat, 7 Jul 2018 12:11:17 +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 w67CBDvk005904 for ; Sat, 7 Jul 2018 08:11:13 -0400 Received: by smtp.corp.redhat.com (Postfix) id C3C606515C; 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 831335C301 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:02 -0400 Message-Id: <20180707121107.7629-5-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 4/9] rpc: Introduce virNetServerQuitRequested 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.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Sat, 07 Jul 2018 12:11:19 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Create a helper API to disable new connections and request the worker threads to quit when a quit has been requested such as via a signal handler. Signed-off-by: John Ferlan --- src/libvirt_remote.syms | 1 + src/rpc/virnetdaemon.c | 13 +++++++++++++ src/rpc/virnetserver.c | 24 ++++++++++++++++++++++++ src/rpc/virnetserver.h | 2 ++ 4 files changed, 40 insertions(+) diff --git a/src/libvirt_remote.syms b/src/libvirt_remote.syms index 9a33626ec6..9ee983fdf2 100644 --- a/src/libvirt_remote.syms +++ b/src/libvirt_remote.syms @@ -129,6 +129,7 @@ virNetServerNewPostExecRestart; virNetServerNextClientID; virNetServerPreExecRestart; virNetServerProcessClients; +virNetServerQuitRequested; virNetServerSetClientAuthenticated; virNetServerSetClientLimits; virNetServerSetThreadPoolParameters; diff --git a/src/rpc/virnetdaemon.c b/src/rpc/virnetdaemon.c index 31b687de12..329f116a6c 100644 --- a/src/rpc/virnetdaemon.c +++ b/src/rpc/virnetdaemon.c @@ -862,6 +862,18 @@ virNetDaemonRun(virNetDaemonPtr dmn) } =20 =20 +static int +daemonServerQuitRequested(void *payload, + const void *key ATTRIBUTE_UNUSED, + void *opaque ATTRIBUTE_UNUSED) +{ + virNetServerPtr srv =3D payload; + + virNetServerQuitRequested(srv); + return 0; +} + + void virNetDaemonQuit(virNetDaemonPtr dmn) { @@ -869,6 +881,7 @@ virNetDaemonQuit(virNetDaemonPtr dmn) =20 VIR_DEBUG("Quit requested %p", dmn); dmn->quit =3D true; + virHashForEach(dmn->servers, daemonServerQuitRequested, NULL); =20 virObjectUnlock(dmn); } diff --git a/src/rpc/virnetserver.c b/src/rpc/virnetserver.c index 5c7f7dd08f..c426567d86 100644 --- a/src/rpc/virnetserver.c +++ b/src/rpc/virnetserver.c @@ -818,6 +818,30 @@ void virNetServerDispose(void *obj) virNetServerMDNSFree(srv->mdns); } =20 + +/* virNetServerQuitRequested: + * @srv: Netserver pointer + * + * Disable new connections and let the worker threads know that + * a quit has been requested. + */ +void +virNetServerQuitRequested(virNetServerPtr srv) +{ + size_t i; + + if (!srv) + return; + + VIR_DEBUG("Quit server requested '%s'", srv->name); + + for (i =3D 0; i < srv->nservices; i++) + virNetServerServiceToggle(srv->services[i], false); + + virThreadPoolQuitRequested(srv->workers); +} + + void virNetServerClose(virNetServerPtr srv) { size_t i; diff --git a/src/rpc/virnetserver.h b/src/rpc/virnetserver.h index 26cec43c22..fcaf48fe14 100644 --- a/src/rpc/virnetserver.h +++ b/src/rpc/virnetserver.h @@ -58,6 +58,8 @@ virNetServerPtr virNetServerNewPostExecRestart(virJSONVal= uePtr object, ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2) ATTRIBUTE_NONNULL(3) ATTRIBUTE_NONNULL(4) ATTRIBUTE_NONNULL(5) ATTRIBUTE_NONNULL(6); =20 +void virNetServerQuitRequested(virNetServerPtr srv); + void virNetServerClose(virNetServerPtr srv); =20 virJSONValuePtr virNetServerPreExecRestart(virNetServerPtr srv); --=20 2.17.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Sat Apr 20 06:15:27 2024 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 1530965506238752.1783280519971; Sat, 7 Jul 2018 05:11:46 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 9A0EB3082A34; Sat, 7 Jul 2018 12:11:44 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 57E385D6A5; Sat, 7 Jul 2018 12:11:44 +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 EC3F34A469; Sat, 7 Jul 2018 12:11:43 +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 w67CBEhA005927 for ; Sat, 7 Jul 2018 08:11:14 -0400 Received: by smtp.corp.redhat.com (Postfix) id 39D665C301; Sat, 7 Jul 2018 12:11:14 +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 E971965F44 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:03 -0400 Message-Id: <20180707121107.7629-6-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 5/9] rpc: Introduce virNetServerWorkerCount 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.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.45]); Sat, 07 Jul 2018 12:11:45 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Get a count of the number of workers for all servers that are still processing a job. Signed-off-by: John Ferlan --- src/libvirt_remote.syms | 1 + src/rpc/virnetserver.c | 26 ++++++++++++++++++++++++++ src/rpc/virnetserver.h | 2 ++ 3 files changed, 29 insertions(+) diff --git a/src/libvirt_remote.syms b/src/libvirt_remote.syms index 9ee983fdf2..a8f937f32e 100644 --- a/src/libvirt_remote.syms +++ b/src/libvirt_remote.syms @@ -136,6 +136,7 @@ virNetServerSetThreadPoolParameters; virNetServerSetTLSContext; virNetServerStart; virNetServerUpdateServices; +virNetServerWorkerCount; =20 =20 # rpc/virnetserverclient.h diff --git a/src/rpc/virnetserver.c b/src/rpc/virnetserver.c index c426567d86..053ef8a5ab 100644 --- a/src/rpc/virnetserver.c +++ b/src/rpc/virnetserver.c @@ -842,6 +842,32 @@ virNetServerQuitRequested(virNetServerPtr srv) } =20 =20 +/* virNetServerWorkerCount: + * @srv: Netserver pointer + * + * Return the number of workers still waiting to be processed. This + * allows the quit requested code to wait for all worker jobs to be + * completed before actually quitting. + */ +size_t +virNetServerWorkerCount(virNetServerPtr srv) +{ + size_t workerCount; + + virObjectLock(srv); + + workerCount =3D virThreadPoolGetCurrentWorkers(srv->workers) + + virThreadPoolGetPriorityWorkers(srv->workers); + + if (workerCount > 0) + VIR_DEBUG("server '%s' still has %zd workers", srv->name, workerCo= unt); + + virObjectUnlock(srv); + + return workerCount; +} + + void virNetServerClose(virNetServerPtr srv) { size_t i; diff --git a/src/rpc/virnetserver.h b/src/rpc/virnetserver.h index fcaf48fe14..3b2582e15b 100644 --- a/src/rpc/virnetserver.h +++ b/src/rpc/virnetserver.h @@ -60,6 +60,8 @@ virNetServerPtr virNetServerNewPostExecRestart(virJSONVal= uePtr object, =20 void virNetServerQuitRequested(virNetServerPtr srv); =20 +size_t virNetServerWorkerCount(virNetServerPtr srv); + void virNetServerClose(virNetServerPtr srv); =20 virJSONValuePtr virNetServerPreExecRestart(virNetServerPtr srv); --=20 2.17.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Sat Apr 20 06:15:27 2024 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 1530965506919336.0863311843309; Sat, 7 Jul 2018 05:11:46 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id C50678EB45; Sat, 7 Jul 2018 12:11:45 +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 791D771455; Sat, 7 Jul 2018 12:11:45 +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 109EF1841C4B; Sat, 7 Jul 2018 12:11:45 +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 w67CBEGS005949 for ; Sat, 7 Jul 2018 08:11:14 -0400 Received: by smtp.corp.redhat.com (Postfix) id A1E666515C; Sat, 7 Jul 2018 12:11:14 +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 60BF95C301 for ; Sat, 7 Jul 2018 12:11:14 +0000 (UTC) From: John Ferlan To: libvir-list@redhat.com Date: Sat, 7 Jul 2018 08:11:04 -0400 Message-Id: <20180707121107.7629-7-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 6/9] daemon: Add quit_timeout period 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.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Sat, 07 Jul 2018 12:11:46 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" In order to prepare for the possibility to allow long running thread(s) to complete their task(s) when a quit signal is received by the daemon, create a configurable quit_timeout period in seconds. Signed-off-by: John Ferlan --- src/remote/libvirtd.aug | 1 + src/remote/libvirtd.conf | 8 ++++++++ src/remote/remote_daemon_config.c | 5 +++++ src/remote/remote_daemon_config.h | 2 ++ src/remote/test_libvirtd.aug.in | 1 + 5 files changed, 17 insertions(+) diff --git a/src/remote/libvirtd.aug b/src/remote/libvirtd.aug index 13333448a4..2c282e53e5 100644 --- a/src/remote/libvirtd.aug +++ b/src/remote/libvirtd.aug @@ -62,6 +62,7 @@ module Libvirtd =3D | int_entry "max_anonymous_clients" | int_entry "max_client_requests" | int_entry "prio_workers" + | int_entry "quit_timeout" =20 let admin_processing_entry =3D int_entry "admin_min_workers" | int_entry "admin_max_workers" diff --git a/src/remote/libvirtd.conf b/src/remote/libvirtd.conf index 92562ab7ae..cc9647391d 100644 --- a/src/remote/libvirtd.conf +++ b/src/remote/libvirtd.conf @@ -321,6 +321,14 @@ # parameter. #max_client_requests =3D 5 =20 +# Approximate number of seconds to wait to allow worker threads to +# complete when a signal to quit (e.g. SIGINT, SIGQUIT, SIGTERM) is +# received by libvirtd. This is only for currently processing workers +# in order to allow them to potentially complete their long running +# task such as stats collection or migrations. The default is to +# not wait. +#quit_timeout =3D 0 + # Same processing controls, but this time for the admin interface. # For description of each option, be so kind to scroll few lines # upwards. diff --git a/src/remote/remote_daemon_config.c b/src/remote/remote_daemon_c= onfig.c index b1516befb4..d6b3575a9a 100644 --- a/src/remote/remote_daemon_config.c +++ b/src/remote/remote_daemon_config.c @@ -155,6 +155,8 @@ daemonConfigNew(bool privileged ATTRIBUTE_UNUSED) =20 data->max_client_requests =3D 5; =20 + data->quit_timeout =3D 0; + data->audit_level =3D 1; data->audit_logging =3D 0; =20 @@ -350,6 +352,9 @@ daemonConfigLoadOptions(struct daemonConfig *data, if (virConfGetValueUInt(conf, "max_client_requests", &data->max_client= _requests) < 0) goto error; =20 + if (virConfGetValueUInt(conf, "quit_timeout", &data->quit_timeout) < 0) + goto error; + if (virConfGetValueUInt(conf, "admin_min_workers", &data->admin_min_wo= rkers) < 0) goto error; if (virConfGetValueUInt(conf, "admin_max_workers", &data->admin_max_wo= rkers) < 0) diff --git a/src/remote/remote_daemon_config.h b/src/remote/remote_daemon_c= onfig.h index 49ea80104b..0f27bf44c8 100644 --- a/src/remote/remote_daemon_config.h +++ b/src/remote/remote_daemon_config.h @@ -73,6 +73,8 @@ struct daemonConfig { =20 unsigned int max_client_requests; =20 + unsigned int quit_timeout; + unsigned int log_level; char *log_filters; char *log_outputs; diff --git a/src/remote/test_libvirtd.aug.in b/src/remote/test_libvirtd.aug= .in index 527e3d7d0d..c559696f58 100644 --- a/src/remote/test_libvirtd.aug.in +++ b/src/remote/test_libvirtd.aug.in @@ -43,6 +43,7 @@ module Test_libvirtd =3D { "max_workers" =3D "20" } { "prio_workers" =3D "5" } { "max_client_requests" =3D "5" } + { "quit_timeout" =3D "0" } { "admin_min_workers" =3D "1" } { "admin_max_workers" =3D "5" } { "admin_max_clients" =3D "5" } --=20 2.17.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Sat Apr 20 06:15:27 2024 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 1530965519404996.6617678523892; Sat, 7 Jul 2018 05:11:59 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.24]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id D82883091986; Sat, 7 Jul 2018 12:11:57 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 93D2E308BDA3; Sat, 7 Jul 2018 12:11:57 +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 363593FC9D; Sat, 7 Jul 2018 12:11:57 +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 w67CBFV6005958 for ; Sat, 7 Jul 2018 08:11:15 -0400 Received: by smtp.corp.redhat.com (Postfix) id 188726515C; Sat, 7 Jul 2018 12:11:15 +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 C9F355C301 for ; Sat, 7 Jul 2018 12:11:14 +0000 (UTC) From: John Ferlan To: libvir-list@redhat.com Date: Sat, 7 Jul 2018 08:11:05 -0400 Message-Id: <20180707121107.7629-8-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 7/9] rpc: Alter virNetDaemonQuit processing 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.84 on 10.5.11.24 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.41]); Sat, 07 Jul 2018 12:11:58 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" 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 inform their workers that a quit was requested. Still because we cannot guarantee a quit will happen or it's possible there's no workers pending, use a virNetDaemonQuitTimer to not only break the event loop but keep track of how long we're waiting and we've waited too long, force an ungraceful exit so that we don't hang waiting forever or cause some sort of SEGV because something is still pending and we Unref things. Signed-off-by: John Ferlan --- src/libvirt_remote.syms | 1 + src/remote/remote_daemon.c | 1 + src/rpc/virnetdaemon.c | 68 +++++++++++++++++++++++++++++++++++++- src/rpc/virnetdaemon.h | 4 +++ 4 files changed, 73 insertions(+), 1 deletion(-) diff --git a/src/libvirt_remote.syms b/src/libvirt_remote.syms index a8f937f32e..e416cfec44 100644 --- a/src/libvirt_remote.syms +++ b/src/libvirt_remote.syms @@ -87,6 +87,7 @@ virNetDaemonPreExecRestart; virNetDaemonQuit; virNetDaemonRemoveShutdownInhibition; virNetDaemonRun; +virNetDaemonSetQuitTimeout; virNetDaemonUpdateServices; =20 =20 diff --git a/src/remote/remote_daemon.c b/src/remote/remote_daemon.c index dee634d7e1..d11adf422f 100644 --- a/src/remote/remote_daemon.c +++ b/src/remote/remote_daemon.c @@ -1273,6 +1273,7 @@ int main(int argc, char **argv) { ret =3D VIR_DAEMON_ERR_DRIVER; goto cleanup; } + virNetDaemonSetQuitTimeout(dmn, config->quit_timeout); =20 if (!(srv =3D virNetServerNew("libvirtd", 1, config->min_workers, diff --git a/src/rpc/virnetdaemon.c b/src/rpc/virnetdaemon.c index 329f116a6c..c6ed65c8c3 100644 --- a/src/rpc/virnetdaemon.c +++ b/src/rpc/virnetdaemon.c @@ -73,6 +73,8 @@ struct _virNetDaemon { virHashTablePtr servers; virJSONValuePtr srvObject; =20 + unsigned int quitTimeout; + bool quitRequested; bool quit; =20 unsigned int autoShutdownTimeout; @@ -153,6 +155,14 @@ virNetDaemonNew(void) } =20 =20 +void +virNetDaemonSetQuitTimeout(virNetDaemonPtr dmn, + unsigned int quitTimeout) +{ + dmn->quitTimeout =3D quitTimeout; +} + + int virNetDaemonAddServer(virNetDaemonPtr dmn, virNetServerPtr srv) @@ -791,11 +801,50 @@ daemonServerProcessClients(void *payload, return 0; } =20 + +static int +daemonServerWorkerCount(void *payload, + const void *key ATTRIBUTE_UNUSED, + void *opaque) +{ + size_t *workerCount =3D opaque; + virNetServerPtr srv =3D payload; + + *workerCount +=3D virNetServerWorkerCount(srv); + + return 0; +} + + +static bool +daemonServerWorkersDone(virNetDaemonPtr dmn) +{ + size_t workerCount =3D 0; + + virHashForEach(dmn->servers, daemonServerWorkerCount, &workerCount); + + return workerCount =3D=3D 0; +} + + +static void +virNetDaemonQuitTimer(int timer ATTRIBUTE_UNUSED, + void *opaque) +{ + int *quitCount =3D opaque; + + (*quitCount)++; + VIR_DEBUG("quitCount=3D%d", *quitCount); +} + + void virNetDaemonRun(virNetDaemonPtr dmn) { int timerid =3D -1; bool timerActive =3D false; + int quitTimer =3D -1; + int quitCount =3D 0; =20 virObjectLock(dmn); =20 @@ -855,10 +904,27 @@ virNetDaemonRun(virNetDaemonPtr dmn) virObjectLock(dmn); =20 virHashForEach(dmn->servers, daemonServerProcessClients, NULL); + + /* HACK: Add a dummy timeout to break event loop */ + if (dmn->quitRequested && quitTimer =3D=3D -1) + quitTimer =3D virEventAddTimeout(500, virNetDaemonQuitTimer, + &quitCount, NULL); + + if (dmn->quitRequested && daemonServerWorkersDone(dmn)) { + dmn->quit =3D true; + } else { + /* Firing every 1/2 second and quitTimeout in seconds, force + * an exit when there are still worker threads running and we + * have waited long enough */ + if (quitCount > dmn->quitTimeout * 2) + _exit(EXIT_FAILURE); + } } =20 cleanup: virObjectUnlock(dmn); + if (quitTimer !=3D -1) + virEventRemoveTimeout(quitTimer); } =20 =20 @@ -880,7 +946,7 @@ virNetDaemonQuit(virNetDaemonPtr dmn) virObjectLock(dmn); =20 VIR_DEBUG("Quit requested %p", dmn); - dmn->quit =3D true; + dmn->quitRequested =3D true; virHashForEach(dmn->servers, daemonServerQuitRequested, NULL); =20 virObjectUnlock(dmn); diff --git a/src/rpc/virnetdaemon.h b/src/rpc/virnetdaemon.h index 09ed5adf36..8433d6a09d 100644 --- a/src/rpc/virnetdaemon.h +++ b/src/rpc/virnetdaemon.h @@ -35,6 +35,10 @@ =20 virNetDaemonPtr virNetDaemonNew(void); =20 +void +virNetDaemonSetQuitTimeout(virNetDaemonPtr dmn, + unsigned int quitTimeout); + int virNetDaemonAddServer(virNetDaemonPtr dmn, virNetServerPtr srv); =20 --=20 2.17.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Sat Apr 20 06:15:27 2024 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 1530965512871116.09250749503963; Sat, 7 Jul 2018 05:11:52 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.26]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 9F1B730832EE; 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 5CF4D30012CB; 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 E5F0E1841C5C; 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 w67CBFvJ005964 for ; Sat, 7 Jul 2018 08:11:15 -0400 Received: by smtp.corp.redhat.com (Postfix) id 8135F5C301; Sat, 7 Jul 2018 12:11:15 +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 3FB5865F44 for ; Sat, 7 Jul 2018 12:11:15 +0000 (UTC) From: John Ferlan To: libvir-list@redhat.com Date: Sat, 7 Jul 2018 08:11:06 -0400 Message-Id: <20180707121107.7629-9-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 8/9] docs: Add news article for libvirtd issue 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.84 on 10.5.11.26 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.44]); Sat, 07 Jul 2018 12:11:52 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Signed-off-by: John Ferlan --- docs/news.xml | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/docs/news.xml b/docs/news.xml index 773c95b0da..6cacded58f 100644 --- a/docs/news.xml +++ b/docs/news.xml @@ -46,6 +46,18 @@
+ + + Fix issues with unexpected libvirtd termination + + + If there were outstanding worker threads when libvirtd + received a quit signal via SIGTERM, SIGINT, or SIGQUIT + then, libvirtd may have crashed or hung waiting for a + worker job to send a completion notification that cannot + be received because the event loop was stopped too soon. + +
--=20 2.17.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Sat Apr 20 06:15:27 2024 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 153096551915550.4320224607992; Sat, 7 Jul 2018 05:11:59 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 0E1938EB4B; Sat, 7 Jul 2018 12:11:58 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id BEC8733ECF; Sat, 7 Jul 2018 12:11:57 +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 595463FB1D; Sat, 7 Jul 2018 12:11:57 +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 w67CBGTr005970 for ; Sat, 7 Jul 2018 08:11:16 -0400 Received: by smtp.corp.redhat.com (Postfix) id F000E6515C; Sat, 7 Jul 2018 12:11:15 +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 A99435C301 for ; Sat, 7 Jul 2018 12:11:15 +0000 (UTC) From: John Ferlan To: libvir-list@redhat.com Date: Sat, 7 Jul 2018 08:11:07 -0400 Message-Id: <20180707121107.7629-10-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 9/9] APPLY ONLY FOR TESTING PURPOSES 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.84 on 10.5.11.23 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Sat, 07 Jul 2018 12:11:58 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Modify GetAllStats to generate a long enough pause in order to send a SIGTERM to libvirtd while a client connection is processing. In order to "set things up": 1. In one terminal window from a local branch built using these patches using a root account run libvirtd debug, e.g.: # ./run gdb src/libvirtd once running, type a 'c' (e.g. continue) and 2. Start a domain (or have one running with the current libvirtd) virsh start $domain 3. Prepare a domstats command for that domain (but don't yet hit in order run it): virsh domstats $domain 4. Prepare a kill command for the running libvirtd, e.g.: jferlan 4143 4107 0 09:51 pts/1 00:00:00 vim +1396 src/libvirtd.c root 30054 21195 6 11:17 pts/8 00:00:01 gdb /home/jferlan/git/libvi= rt.work/src/.libs/lt-libvirtd root 30087 30054 7 11:17 pts/8 00:00:01 /home/jferlan/git/libvirt.w= ork/src/.libs/lt-libvirtd root 30385 19861 0 11:17 pts/17 00:00:00 grep --color=3Dauto libvirtd but again don't hit yet. 5. Align your stars perfectly now... a. Hit on your domstats command b. Swap to the kill command window and hit This should cause the libvirtd debug window to stop, but since you already typed 'c' it'll continue at least briefly, for example: ... [Thread 0x7fffc3231700 (LWP 30374) exited] Detaching after fork from child process 30376. Detaching after fork from child process 30377. Detaching after fork from child process 30378. [Thread 0x7fffc4445700 (LWP 30106) exited] c 2018-01-10 16:18:12.962+0000: 30094: info : libvirt version: 4.0.0 2018-01-10 16:18:12.962+0000: 30094: info : hostname: unknown4ceb42c824f4.a= ttlocal.net 2018-01-10 16:18:12.962+0000: 30094: warning : qemuConnectGetAllDomainStats= :20265 : k =3D -5340232226128654848 Thread 1 "lt-libvirtd" received signal SIGTERM, Terminated. 0x00007ffff3ae6d2d in poll () from /lib64/libc.so.6 ... (gdb) c Continuing. [Thread 0x7fffc5c48700 (LWP 30103) exited] [Thread 0x7fffc5447700 (LWP 30104) exited] [Thread 0x7fffc4c46700 (LWP 30105) exited] [Thread 0x7fffc6449700 (LWP 30102) exited] [Thread 0x7fffc6c4a700 (LWP 30101) exited] [Thread 0x7fffe3b57700 (LWP 30097) exited] [Thread 0x7fffe4358700 (LWP 30096) exited] [Thread 0x7fffe2354700 (LWP 30100) exited] [Thread 0x7fffe3356700 (LWP 30098) exited] [Thread 0x7fffe2b55700 (LWP 30099) exited] [Thread 0x7fffe535a700 (LWP 30094) exited] [Thread 0x7fffe5b5b700 (LWP 30093) exited] [Thread 0x7fffe635c700 (LWP 30092) exited] [Thread 0x7fffe6b5d700 (LWP 30091) exited] 2018-01-10 16:18:25.451+0000: 30095: warning : qemuConnectGetAllDomainStats= :20265 : k =3D -5340232226128654848 [Thread 0x7fffe4b59700 (LWP 30095) exited] [Thread 0x7fffc3a32700 (LWP 30187) exited] [Inferior 1 (process 30087) exited normally] (gdb) c The program is not being run. (gdb) quit The virsh domstats window will "close" as follows: error: Disconnected from qemu:///system due to end of file error: End of file while reading data: Input/output error If something's wrong, then the libvirtd window may not exit those final two threads in which case you could interrupt it (^c) and check the threads (thread apply all bt) which will probably show some sort of hang... My testing shows that the hang no longer occurs with all the previous patches applied. The subsequent patch calling virHashRemoveAll from virNetDaemonClose does not seem to be necessary, although I suppose it cannot hurt as the same essential functionality occurs during the Dispose function Signed-off-by: John Ferlan --- src/qemu/qemu_driver.c | 5 +++++ src/rpc/virnetdaemon.c | 3 ++- src/rpc/virnetserver.c | 4 ++-- src/util/virthreadpool.c | 10 +++++++--- 4 files changed, 16 insertions(+), 6 deletions(-) diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index 9a35e04a85..fa725131a2 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -20454,6 +20454,7 @@ qemuConnectGetAllDomainStats(virConnectPtr conn, bool enforce =3D !!(flags & VIR_CONNECT_GET_ALL_DOMAINS_STATS_ENFORCE_= STATS); int nstats =3D 0; size_t i; + size_t j, k =3D 0; int ret =3D -1; unsigned int privflags =3D 0; unsigned int domflags =3D 0; @@ -20492,6 +20493,10 @@ qemuConnectGetAllDomainStats(virConnectPtr conn, if (qemuDomainGetStatsNeedMonitor(stats)) privflags |=3D QEMU_DOMAIN_STATS_HAVE_JOB; =20 + for (j =3D 0; j < 10000000000; j++) // Add one more zero for longer... + k =3D j + k; + VIR_WARN("k =3D %zd", k); + for (i =3D 0; i < nvms; i++) { virDomainStatsRecordPtr tmp =3D NULL; domflags =3D 0; diff --git a/src/rpc/virnetdaemon.c b/src/rpc/virnetdaemon.c index c6ed65c8c3..6cce4b7004 100644 --- a/src/rpc/virnetdaemon.c +++ b/src/rpc/virnetdaemon.c @@ -834,7 +834,7 @@ virNetDaemonQuitTimer(int timer ATTRIBUTE_UNUSED, int *quitCount =3D opaque; =20 (*quitCount)++; - VIR_DEBUG("quitCount=3D%d", *quitCount); + VIR_WARN("quitCount=3D%d", *quitCount); } =20 =20 @@ -912,6 +912,7 @@ virNetDaemonRun(virNetDaemonPtr dmn) =20 if (dmn->quitRequested && daemonServerWorkersDone(dmn)) { dmn->quit =3D true; + VIR_WARN ("quitRequested and no workers remain"); } else { /* Firing every 1/2 second and quitTimeout in seconds, force * an exit when there are still worker threads running and we diff --git a/src/rpc/virnetserver.c b/src/rpc/virnetserver.c index 053ef8a5ab..109f369bac 100644 --- a/src/rpc/virnetserver.c +++ b/src/rpc/virnetserver.c @@ -833,7 +833,7 @@ virNetServerQuitRequested(virNetServerPtr srv) if (!srv) return; =20 - VIR_DEBUG("Quit server requested '%s'", srv->name); + VIR_WARN ("Quit server requested '%s'", srv->name); =20 for (i =3D 0; i < srv->nservices; i++) virNetServerServiceToggle(srv->services[i], false); @@ -860,7 +860,7 @@ virNetServerWorkerCount(virNetServerPtr srv) virThreadPoolGetPriorityWorkers(srv->workers); =20 if (workerCount > 0) - VIR_DEBUG("server '%s' still has %zd workers", srv->name, workerCo= unt); + VIR_WARN ("server '%s' still has %zd workers", srv->name, workerCo= unt); =20 virObjectUnlock(srv); =20 diff --git a/src/util/virthreadpool.c b/src/util/virthreadpool.c index 137c5d1746..fc7bc64fb5 100644 --- a/src/util/virthreadpool.c +++ b/src/util/virthreadpool.c @@ -136,8 +136,10 @@ static void virThreadPoolWorker(void *opaque) goto out; } =20 - if (pool->quit) + if (pool->quit) { + VIR_WARN("Quit set"); break; + } =20 if (priority) { job =3D pool->jobList.firstPrio; @@ -330,7 +332,7 @@ virThreadPoolQuitRequested(virThreadPoolPtr pool) { virMutexLock(&pool->mutex); =20 - VIR_DEBUG("nWorkers=3D%zd, nPrioWorkers=3D%zd jobQueueDepth=3D%zd", + VIR_WARN ("nWorkers=3D%zd, nPrioWorkers=3D%zd jobQueueDepth=3D%zd", pool->nWorkers, pool->nPrioWorkers, pool->jobQueueDepth); =20 virThreadPoolSetQuit(pool); @@ -415,8 +417,10 @@ int virThreadPoolSendJob(virThreadPoolPtr pool, virThreadPoolJobPtr job; =20 virMutexLock(&pool->mutex); - if (pool->quit) + if (pool->quit) { + VIR_WARN("Quit set"); goto error; + } =20 if (pool->freeWorkers - pool->jobQueueDepth <=3D 0 && pool->nWorkers < pool->maxWorkers && --=20 2.17.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list