From nobody Mon Feb 9 02:55:36 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) client-ip=170.10.133.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1655128614; cv=none; d=zohomail.com; s=zohoarc; b=DeeCYFOw18rJk4oOjW8hg0W9jA9hVSawYiAE1AC6lyDoetlwJsBIa4vANQG9M0O6LT5k//VYapZhVJSTL/Fhb22mzGUFveBjuSMu8573zjyUe7XpaM/QSahHPJibbZYPwtG+/gIsJjy8B3QjFuQctdcLQQ5rhI3y2Z99p4qovms= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1655128614; h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=cBcdpTBhKXnrfoBSuhkxffugH/zjFhvtTtThcw6vMKw=; b=EnVGdYQfntHzOP1I0sx1aU0huSu3jtfV2/C9wqomMgHbNR+PxvGd2/Gb3H5rTVbwh3TUs9sXYdL63sn+AF6z5lHy0UT/gIRlOE1o5S5xB/7tiN4PH1+tiayd6M1lkq9IPs/4Y3nLQzveJvh/31FuvXtGAjo/BhpcoEK22swhKVM= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by mx.zohomail.com with SMTPS id 1655128614549341.94083394626534; Mon, 13 Jun 2022 06:56:54 -0700 (PDT) Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-672-VOA4aCV9N_uyy_6E8LQ4eg-1; Mon, 13 Jun 2022 09:56:50 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.rdu2.redhat.com [10.11.54.1]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 1854B811E90; Mon, 13 Jun 2022 13:56:47 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com [10.30.29.100]) by smtp.corp.redhat.com (Postfix) with ESMTP id 0598940CFD0B; Mon, 13 Jun 2022 13:56:47 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (localhost [IPv6:::1]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id C88AA1947062; Mon, 13 Jun 2022 13:56:46 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx09.intmail.prod.int.rdu2.redhat.com [10.11.54.9]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id 3F20D1947062 for ; Mon, 13 Jun 2022 13:56:45 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id 20970492CA4; Mon, 13 Jun 2022 13:56:45 +0000 (UTC) Received: from speedmetal.redhat.com (unknown [10.40.208.34]) by smtp.corp.redhat.com (Postfix) with ESMTP id 9F1C1492CA2 for ; Mon, 13 Jun 2022 13:56:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1655128613; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=cBcdpTBhKXnrfoBSuhkxffugH/zjFhvtTtThcw6vMKw=; b=Y1Wdaij9758VxebF1wYOzDGStMhrjEPGUD7KIx06VK1WYGbCebZZ3HxssuVAwwJ9OUgWDh Wrd8TP4z9uoPzGwPZ3Fh7HfR0cfF09v8lM4J/OuzOuZQk+DwuPFD6fir1bbDBP8cA6luqA oc4F9iCtCjb17UkGo6IOewluxG7lCHI= X-MC-Unique: VOA4aCV9N_uyy_6E8LQ4eg-1 X-Original-To: libvir-list@listman.corp.redhat.com From: Peter Krempa To: libvir-list@redhat.com Subject: [PATCH 1/6] virnetdaemon: Extract autoShutdownTimer operations from virNetDaemonRun Date: Mon, 13 Jun 2022 15:56:28 +0200 Message-Id: <8b993870b6cadebe341618f86ee69a79e9266034.1655128518.git.pkrempa@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.85 on 10.11.54.9 X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libvir-list-bounces@redhat.com Sender: "libvir-list" X-Scanned-By: MIMEDefang 2.84 on 10.11.54.1 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1655128616311100003 Content-Type: text/plain; charset="utf-8" Introduce 'virNetDaemonShutdownTimerRegister' and 'virNetDaemonShutdownTimerUpdate' to aggregate the code to deal with the auto-shutdown timer. The code is also placed so that it can be called from 'virNetDaemonAutoShutdown' which involved the move of 'virNetDaemonAutoShutdownTimer'. Signed-off-by: Peter Krempa --- src/rpc/virnetdaemon.c | 108 +++++++++++++++++++++++++---------------- 1 file changed, 66 insertions(+), 42 deletions(-) diff --git a/src/rpc/virnetdaemon.c b/src/rpc/virnetdaemon.c index 1f32bae35f..7bf27eed9d 100644 --- a/src/rpc/virnetdaemon.c +++ b/src/rpc/virnetdaemon.c @@ -77,6 +77,8 @@ struct _virNetDaemon { bool execRestart; unsigned int autoShutdownTimeout; + int autoShutdownTimerID; + bool autoShutdownTimerActive; size_t autoShutdownInhibitions; int autoShutdownInhibitFd; }; @@ -153,6 +155,8 @@ virNetDaemonNew(void) if (virEventRegisterDefaultImpl() < 0) goto error; + dmn->autoShutdownTimerID =3D -1; + #ifndef WIN32 memset(&sig_action, 0, sizeof(sig_action)); sig_action.sa_handler =3D SIG_IGN; @@ -403,6 +407,65 @@ virNetDaemonIsPrivileged(virNetDaemon *dmn) } +static void +virNetDaemonAutoShutdownTimer(int timerid G_GNUC_UNUSED, + void *opaque) +{ + virNetDaemon *dmn =3D opaque; + VIR_LOCK_GUARD lock =3D virObjectLockGuard(dmn); + + if (!dmn->autoShutdownInhibitions) { + VIR_DEBUG("Automatic shutdown triggered"); + dmn->quit =3D true; + } +} + + +static int +virNetDaemonShutdownTimerRegister(virNetDaemon *dmn) +{ + if (dmn->autoShutdownTimeout =3D=3D 0) + return 0; + + if ((dmn->autoShutdownTimerID =3D virEventAddTimeout(-1, + virNetDaemonAutoShu= tdownTimer, + dmn, NULL)) < 0) { + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", + _("Failed to register shutdown timeout")); + return -1; + } + + return 0; +} + + +static void +virNetDaemonShutdownTimerUpdate(virNetDaemon *dmn) +{ + if (dmn->autoShutdownTimeout =3D=3D 0) + return; + + /* A shutdown timeout is specified, so check + * if any drivers have active state, if not + * shutdown after timeout seconds + */ + if (dmn->autoShutdownTimerActive) { + if (virNetDaemonHasClients(dmn)) { + VIR_DEBUG("Deactivating shutdown timer %d", dmn->autoShutdownT= imerID); + virEventUpdateTimeout(dmn->autoShutdownTimerID, -1); + dmn->autoShutdownTimerActive =3D false; + } + } else { + if (!virNetDaemonHasClients(dmn)) { + VIR_DEBUG("Activating shutdown timer %d", dmn->autoShutdownTim= erID); + virEventUpdateTimeout(dmn->autoShutdownTimerID, + dmn->autoShutdownTimeout * 1000); + dmn->autoShutdownTimerActive =3D true; + } + } +} + + void virNetDaemonAutoShutdown(virNetDaemon *dmn, unsigned int timeout) @@ -657,19 +720,6 @@ virNetDaemonAddSignalHandler(virNetDaemon *dmn G_GNUC_= UNUSED, #endif /* WIN32 */ -static void -virNetDaemonAutoShutdownTimer(int timerid G_GNUC_UNUSED, - void *opaque) -{ - virNetDaemon *dmn =3D opaque; - VIR_LOCK_GUARD lock =3D virObjectLockGuard(dmn); - - if (!dmn->autoShutdownInhibitions) { - VIR_DEBUG("Automatic shutdown triggered"); - dmn->quit =3D true; - } -} - static int daemonServerUpdateServices(void *payload, const char *key G_GNUC_UNUSED, @@ -743,11 +793,10 @@ virNetDaemonFinishTimer(int timerid G_GNUC_UNUSED, dmn->finished =3D true; } + void virNetDaemonRun(virNetDaemon *dmn) { - int timerid =3D -1; - bool timerActive =3D false; virThread shutdownThread; virObjectLock(dmn); @@ -763,14 +812,8 @@ virNetDaemonRun(virNetDaemon *dmn) dmn->finished =3D false; dmn->graceful =3D false; - if (dmn->autoShutdownTimeout && - (timerid =3D virEventAddTimeout(-1, - virNetDaemonAutoShutdownTimer, - dmn, NULL)) < 0) { - virReportError(VIR_ERR_INTERNAL_ERROR, "%s", - _("Failed to register shutdown timeout")); + if (virNetDaemonShutdownTimerRegister(dmn) < 0) goto cleanup; - } /* We are accepting connections now. Notify systemd * so it can start dependent services. */ @@ -778,26 +821,7 @@ virNetDaemonRun(virNetDaemon *dmn) VIR_DEBUG("dmn=3D%p quit=3D%d", dmn, dmn->quit); while (!dmn->finished) { - /* A shutdown timeout is specified, so check - * if any drivers have active state, if not - * shutdown after timeout seconds - */ - if (dmn->autoShutdownTimeout) { - if (timerActive) { - if (virNetDaemonHasClients(dmn)) { - VIR_DEBUG("Deactivating shutdown timer %d", timerid); - virEventUpdateTimeout(timerid, -1); - timerActive =3D false; - } - } else { - if (!virNetDaemonHasClients(dmn)) { - VIR_DEBUG("Activating shutdown timer %d", timerid); - virEventUpdateTimeout(timerid, - dmn->autoShutdownTimeout * 1000); - timerActive =3D true; - } - } - } + virNetDaemonShutdownTimerUpdate(dmn); virObjectUnlock(dmn); if (virEventRunDefaultImpl() < 0) { --=20 2.36.1