From nobody Thu Dec 18 01:17:57 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 1739375311013258.3113965435366; Wed, 12 Feb 2025 07:48:31 -0800 (PST) Received: by lists.libvirt.org (Postfix, from userid 996) id 7067D1A20; Wed, 12 Feb 2025 10:48:30 -0500 (EST) Received: from lists.libvirt.org (localhost [IPv6:::1]) by lists.libvirt.org (Postfix) with ESMTP id 68AEF1AC8; Wed, 12 Feb 2025 10:47:11 -0500 (EST) Received: by lists.libvirt.org (Postfix, from userid 996) id D6ED018CF; Wed, 12 Feb 2025 10:47:06 -0500 (EST) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.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 4201218FE for ; Wed, 12 Feb 2025 10:46:57 -0500 (EST) Received: from mx-prod-mc-06.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-463-6xddiyZiOqap1kV9CFAP6Q-1; Wed, 12 Feb 2025 10:46:55 -0500 Received: from mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.15]) (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-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id BFF5A1800360 for ; Wed, 12 Feb 2025 15:46:54 +0000 (UTC) Received: from toolbx.redhat.com (unknown [10.45.224.110]) by mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 850381955F1B; Wed, 12 Feb 2025 15:46:53 +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.8 required=5.0 tests=DKIM_INVALID,DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H5,RCVD_IN_MSPIKE_WL,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=1739375216; 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=zkQ1weQIB8Jf7/CnFcg9Edgsy/SBG3j9bkXrXD/yWhk=; b=UBW+aLQG/Y6udPGRCS1dOageB866Gb8ouuhXLFWPMc0QB3pz5TEVuFq9VLmBH4CZvOviZH Yht6ru3vap1akKfxF2bp235mf8Z5lucVYi3U8XD5hE24ROpm51bIaszCpNjOwLengbxj7V B6tMiRDcFBnX4JW+sMQ9V4xjI16jfQg= X-MC-Unique: 6xddiyZiOqap1kV9CFAP6Q-1 X-Mimecast-MFC-AGG-ID: 6xddiyZiOqap1kV9CFAP6Q 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 v2 3/8] util: add APIs for more systemd notifications Date: Wed, 12 Feb 2025 15:46:41 +0000 Message-ID: <20250212154646.913282-4-berrange@redhat.com> In-Reply-To: <20250212154646.913282-1-berrange@redhat.com> References: <20250212154646.913282-1-berrange@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.15 X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: 7UK741SUChUVctTXm6qaFmlHYfSLW8wvuQn8l9UcRKE_1739375214 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Message-ID-Hash: VPEFU7IQKEB473EXQK6MOVUEMXXEPJV2 X-Message-ID-Hash: VPEFU7IQKEB473EXQK6MOVUEMXXEPJV2 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: 1739375312296019000 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 Reviewed-by: Peter Krempa --- src/libvirt_private.syms | 6 +++++- src/rpc/virnetdaemon.c | 2 +- src/util/virsystemd.c | 44 +++++++++++++++++++++++++++++++++++++--- src/util/virsystemd.h | 6 +++++- 4 files changed, 52 insertions(+), 6 deletions(-) diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index 6888f6b599..4eca252b2a 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -3531,7 +3531,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 f647cf60ba..e6bdfe0f88 100644 --- a/src/rpc/virnetdaemon.c +++ b/src/rpc/virnetdaemon.c @@ -753,7 +753,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 d46e5f74fc..bbcf77a41f 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,43 @@ virSystemdNotifyStartup(void) #endif /* !WIN32 */ } =20 +void virSystemdNotifyReady(void) +{ + virSystemdNotify("READY=3D1"); +} + +void virSystemdNotifyReload(void) +{ + gint64 now =3D g_get_monotonic_time(); + g_autofree char *msg =3D g_strdup_printf( + "RELOADING=3D1\nMONOTONIC_USEC=3D%lld", (long long int)now); + virSystemdNotify(msg); +} + +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