From nobody Tue Jan 21 07:23:45 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.libvirt.org designates 8.43.85.245 as permitted sender) client-ip=8.43.85.245; envelope-from=devel-bounces@lists.libvirt.org; helo=lists.libvirt.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of lists.libvirt.org designates 8.43.85.245 as permitted sender) smtp.mailfrom=devel-bounces@lists.libvirt.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.libvirt.org (lists.libvirt.org [8.43.85.245]) by mx.zohomail.com with SMTPS id 1736365484305516.3819342636419; Wed, 8 Jan 2025 11:44:44 -0800 (PST) Received: by lists.libvirt.org (Postfix, from userid 996) id 428601485; Wed, 8 Jan 2025 14:44:43 -0500 (EST) Received: from lists.libvirt.org (localhost [IPv6:::1]) by lists.libvirt.org (Postfix) with ESMTP id AF946138F; Wed, 8 Jan 2025 14:43:14 -0500 (EST) Received: by lists.libvirt.org (Postfix, from userid 996) id 99E4912BA; Wed, 8 Jan 2025 14:43:07 -0500 (EST) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by lists.libvirt.org (Postfix) with ESMTPS id 1C90112A6 for ; Wed, 8 Jan 2025 14:43:07 -0500 (EST) Received: from mx-prod-mc-02.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-690-X5ySxZzgP2ypBDzY2jPmTQ-1; Wed, 08 Jan 2025 14:43:03 -0500 Received: from mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.4]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-02.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id A193219560B3 for ; Wed, 8 Jan 2025 19:43:02 +0000 (UTC) Received: from toolbx.redhat.com (unknown [10.42.28.103]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id C7BD4300018D; Wed, 8 Jan 2025 19:43:01 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on lists.libvirt.org X-Spam-Level: X-Spam-Status: No, score=-0.5 required=5.0 tests=DKIM_INVALID,DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2,RCVD_IN_VALIDITY_RPBL_BLOCKED, RCVD_IN_VALIDITY_SAFE_BLOCKED,SPF_HELO_NONE autolearn=unavailable autolearn_force=no version=3.4.4 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1736365386; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=EmQRX7Zl6FQWPQGPXTo2EZEXPAOJRYei2sHVU5WUyIk=; b=Y/twoTlRlZNVDCloD/oCJ3MCRwadzXYuy1LMSlP3INBxLVKDQIU6qygN04TAqVM9d/3lD3 4YOVBq41FhUWlQIXWjojKRHBGAmpBv3JEsqzMtteRI/q+T+XI3sEcMA0riwmjw8jor1pUM W51eC8HZfdevLxk5WlP3cWv08wdeNZI= X-MC-Unique: X5ySxZzgP2ypBDzY2jPmTQ-1 X-Mimecast-MFC-AGG-ID: X5ySxZzgP2ypBDzY2jPmTQ From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: devel@lists.libvirt.org Cc: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= Subject: [PATCH 01/26] util: add APIs for more systemd notifications Date: Wed, 8 Jan 2025 19:42:34 +0000 Message-ID: <20250108194259.1171990-2-berrange@redhat.com> In-Reply-To: <20250108194259.1171990-1-berrange@redhat.com> References: <20250108194259.1171990-1-berrange@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.4 X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: 311s1b5nJ2SQDR9VYcqFpRynChRM50bIdjmUGK5nZ3I_1736365382 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Message-ID-Hash: LW5BE5NEJDNAT6S2WR55CIPS7DMZXY64 X-Message-ID-Hash: LW5BE5NEJDNAT6S2WR55CIPS7DMZXY64 X-MailFrom: berrange@redhat.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; header-match-config-1; header-match-config-2; header-match-config-3; header-match-devel.lists.libvirt.org-0; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; suspicious-header X-Mailman-Version: 3.2.2 Precedence: list List-Id: Development discussions about the libvirt library & tools Archived-At: List-Archive: List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1736365486555116600 Content-Type: text/plain; charset="utf-8" We have a way to notify systemd when we're done starting the daemon. Systemd supports many more notifications, however, and many of them are quite relevant to our needs: https://www.freedesktop.org/software/systemd/man/latest/sd_notify.html This renames the existing notification API to better reflect its semantics, and adds new APIs for reporting * Initiation of config file reload * Initiation of daemon shutdown process * Adhoc progress status messages * Request to extend service shutdown timeout Signed-off-by: Daniel P. Berrang=C3=A9 --- src/libvirt_private.syms | 6 +++++- src/rpc/virnetdaemon.c | 2 +- src/util/virsystemd.c | 41 +++++++++++++++++++++++++++++++++++++--- src/util/virsystemd.h | 6 +++++- 4 files changed, 49 insertions(+), 6 deletions(-) diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index 33b93cbd3e..d0c116b78c 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -3524,7 +3524,11 @@ virSystemdHasResolved; virSystemdHasResolvedResetCachedValue; virSystemdMakeScopeName; virSystemdMakeSliceName; -virSystemdNotifyStartup; +virSystemdNotifyExtendTimeout; +virSystemdNotifyReady; +virSystemdNotifyReload; +virSystemdNotifyStatus; +virSystemdNotifyStopping; virSystemdResolvedRegisterNameServer; virSystemdTerminateMachine; =20 diff --git a/src/rpc/virnetdaemon.c b/src/rpc/virnetdaemon.c index e4c6261536..bb7d2ff9a0 100644 --- a/src/rpc/virnetdaemon.c +++ b/src/rpc/virnetdaemon.c @@ -749,7 +749,7 @@ virNetDaemonRun(virNetDaemon *dmn) =20 /* We are accepting connections now. Notify systemd * so it can start dependent services. */ - virSystemdNotifyStartup(); + virSystemdNotifyReady(); =20 VIR_DEBUG("dmn=3D%p quit=3D%d", dmn, dmn->quit); while (!dmn->finished) { diff --git a/src/util/virsystemd.c b/src/util/virsystemd.c index 5b772e29dd..2c09b9ab2b 100644 --- a/src/util/virsystemd.c +++ b/src/util/virsystemd.c @@ -624,12 +624,11 @@ int virSystemdTerminateMachine(const char *name) return 0; } =20 -void -virSystemdNotifyStartup(void) +static void +virSystemdNotify(const char *msg) { #ifndef WIN32 const char *path; - const char *msg =3D "READY=3D1"; int fd; struct sockaddr_un un =3D { .sun_family =3D AF_UNIX, @@ -644,6 +643,8 @@ virSystemdNotifyStartup(void) .msg_iovlen =3D 1, }; =20 + VIR_DEBUG("Notify '%s'", msg); + if (!(path =3D getenv("NOTIFY_SOCKET"))) { VIR_DEBUG("Skipping systemd notify, not requested"); return; @@ -674,6 +675,40 @@ virSystemdNotifyStartup(void) #endif /* !WIN32 */ } =20 +void virSystemdNotifyReady(void) +{ + virSystemdNotify("READY=3D1"); +} + +void virSystemdNotifyReload(void) +{ + virSystemdNotify("RELOAD=3D1"); +} + +void virSystemdNotifyStopping(void) +{ + virSystemdNotify("STOPPING=3D1"); +} + +void virSystemdNotifyExtendTimeout(int secs) +{ + g_autofree char *msg =3D g_strdup_printf("EXTEND_TIMEOUT_USEC=3D%llu", + secs * 1000ull * 1000ul); + virSystemdNotify(msg); +} + +void virSystemdNotifyStatus(const char *fmt, ...) +{ + g_autofree char *msg1 =3D NULL; + g_autofree char *msg2 =3D NULL; + va_list ap; + va_start(ap, fmt); + msg1 =3D g_strdup_vprintf(fmt, ap); + va_end(ap); + msg2 =3D g_strdup_printf("STATUS=3D%s", msg1); + virSystemdNotify(msg2); +} + static int virSystemdPMSupportTarget(const char *methodName, bool *result) { diff --git a/src/util/virsystemd.h b/src/util/virsystemd.h index b7fdaf67df..98460dbc3a 100644 --- a/src/util/virsystemd.h +++ b/src/util/virsystemd.h @@ -44,7 +44,11 @@ int virSystemdCreateMachine(const char *name, =20 int virSystemdTerminateMachine(const char *name); =20 -void virSystemdNotifyStartup(void); +void virSystemdNotifyReady(void); +void virSystemdNotifyReload(void); +void virSystemdNotifyStopping(void); +void virSystemdNotifyExtendTimeout(int secs); +void virSystemdNotifyStatus(const char *fmt, ...) G_GNUC_PRINTF(1, 2); =20 int virSystemdHasMachined(void); =20 --=20 2.47.1