From nobody Fri Dec 19 08:04:07 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=pass(p=reject dis=none) header.from=lists.libvirt.org ARC-Seal: i=1; a=rsa-sha256; t=1742913374; cv=none; d=zohomail.com; s=zohoarc; b=TN0Mmkg605bf9P6C8spIGRqkxB9a/EutIsj5w8U37aaIp2T0mCyi9vjCM4RYkO0crClmmfdYjI8DF8+ga8idGELwx+q4eGgttI6may/8w/wxy5kuihRNXRR8AKMGv3Dci0c9k3UJ03VETvq5GjE6AUP5jx6qG3KZAHWCD4yMjHw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1742913374; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:Reply-To:References:Subject:Subject:To:To:Message-Id; bh=++v/Zl6N4N7MEkU2zKoh2hK5UwW29Gw0F6EcJyEdXSw=; b=lmrPw/67XR0mXjPxcYkb3ycifM4XG08IR+XZw1LprN8F5X4376kPydRvvSHt+GG8taHch803HZSgRinbRaMC9pNu9bQK4UGet0ta4KI1v2O51gbPAEUkXIu/JPhku82IefgHkNAql5ucb/qLjGOMnhellYhDVSBBh/VXz5+gTfc= ARC-Authentication-Results: i=1; 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=pass header.from= (p=reject dis=none) Return-Path: Received: from lists.libvirt.org (lists.libvirt.org [8.43.85.245]) by mx.zohomail.com with SMTPS id 1742913374010991.5681404811177; Tue, 25 Mar 2025 07:36:14 -0700 (PDT) Received: by lists.libvirt.org (Postfix, from userid 996) id 49C6314F9; Tue, 25 Mar 2025 10:36:13 -0400 (EDT) Received: from lists.libvirt.org (localhost [IPv6:::1]) by lists.libvirt.org (Postfix) with ESMTP id 9BDA51662; Tue, 25 Mar 2025 10:35:35 -0400 (EDT) Received: by lists.libvirt.org (Postfix, from userid 996) id 4FC511574; Tue, 25 Mar 2025 10:35:30 -0400 (EDT) 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 4AFEF1574 for ; Tue, 25 Mar 2025 10:35:24 -0400 (EDT) Received: from mx-prod-mc-01.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-489-T0Nf2wsxN0Wg8J9jS7F-wQ-1; Tue, 25 Mar 2025 10:35:22 -0400 Received: from mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.111]) (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-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 028F8196D2D8 for ; Tue, 25 Mar 2025 14:35:22 +0000 (UTC) Received: from kshcheti-thinkpadp1gen4i.tpbc.com (unknown [10.43.2.246]) by mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 178E21801756; Tue, 25 Mar 2025 14:35:20 +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, 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=1742913323; 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=hFvP3D1hZP/ZACkv1g7frLRWT7/Wr92nBZTCBVcO8TQ=; b=MtEq3WnFI48IbLZ8X59hxDQya5RkCRljVujip/StUY0gbCZA99Fm5VXR0wECrvcbEGGHO1 CIMUm2+HwECmDRfzw3ZWsyAIhsJs21XZj/ImJBNZ4Mck//B6ry7M+12WIyS4Cb3f0O7qUJ 0ggVkLD6hom/PnhYDH0wytAraFN6nCM= X-MC-Unique: T0Nf2wsxN0Wg8J9jS7F-wQ-1 X-Mimecast-MFC-AGG-ID: T0Nf2wsxN0Wg8J9jS7F-wQ_1742913322 To: devel@lists.libvirt.org Subject: [PATCH 1/3] ch: virCHMonitorNew() run new CH monitor daemonized Date: Tue, 25 Mar 2025 15:11:57 +0100 Message-ID: <20250325143501.728342-2-kshcheti@redhat.com> In-Reply-To: <20250325143501.728342-1-kshcheti@redhat.com> References: <20250325143501.728342-1-kshcheti@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.111 X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: YNCUSyjbsFh7IRzkgBHQLTegbcNrSchCtKphKs9voUs_1742913322 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Message-ID-Hash: DMO5XTR6TYK2JXZIPEVOXVSCD3I3AT6U X-Message-ID-Hash: DMO5XTR6TYK2JXZIPEVOXVSCD3I3AT6U X-MailFrom: kshcheti@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 CC: Kirill Shchetiniuk 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: From: Kirill Shchetiniuk via Devel Reply-To: Kirill Shchetiniuk X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1742913376105019000 Content-Type: text/plain; charset="utf-8"; x-default="true" When the new CH monitor was started, it ran as a non-daemonized process and was a child of the CH driver process. This led to a situation where if the CH driver died, the monitor process were killed too, terminating the running VM under the monitor. This led to termination of all VM started under the libvirt. Make new monitor running daemonized to avoid VMs shutdown when driver dies. Also added a pidfile its preparetion to be able to aquire daemon's PID. Signed-off-by: Kirill Shchetiniuk --- src/ch/ch_domain.c | 1 + src/ch/ch_domain.h | 1 + src/ch/ch_monitor.c | 24 ++++++++++++++++++++++-- src/ch/ch_process.c | 16 ++++++++++++++++ 4 files changed, 40 insertions(+), 2 deletions(-) diff --git a/src/ch/ch_domain.c b/src/ch/ch_domain.c index a08b18c5b9..c0c9acd85b 100644 --- a/src/ch/ch_domain.c +++ b/src/ch/ch_domain.c @@ -68,6 +68,7 @@ virCHDomainObjPrivateFree(void *data) virBitmapFree(priv->autoCpuset); virBitmapFree(priv->autoNodeset); virCgroupFree(priv->cgroup); + g_free(priv->pidfile); g_free(priv); } =20 diff --git a/src/ch/ch_domain.h b/src/ch/ch_domain.h index 8dea2b2123..69a657f6af 100644 --- a/src/ch/ch_domain.h +++ b/src/ch/ch_domain.h @@ -36,6 +36,7 @@ struct _virCHDomainObjPrivate { virBitmap *autoCpuset; virBitmap *autoNodeset; virCgroup *cgroup; + char *pidfile; }; =20 #define CH_DOMAIN_PRIVATE(vm) \ diff --git a/src/ch/ch_monitor.c b/src/ch/ch_monitor.c index 0ba927a194..1dc085a755 100644 --- a/src/ch/ch_monitor.c +++ b/src/ch/ch_monitor.c @@ -27,6 +27,7 @@ =20 #include "datatypes.h" #include "ch_conf.h" +#include "ch_domain.h" #include "ch_events.h" #include "ch_interface.h" #include "ch_monitor.h" @@ -37,6 +38,7 @@ #include "virfile.h" #include "virjson.h" #include "virlog.h" +#include "virpidfile.h" #include "virstring.h" =20 #define VIR_FROM_THIS VIR_FROM_CH @@ -584,6 +586,8 @@ virCHMonitorNew(virDomainObj *vm, virCHDriverConfig *cf= g, int logfile) { g_autoptr(virCHMonitor) mon =3D NULL; g_autoptr(virCommand) cmd =3D NULL; + virCHDomainObjPrivate *priv =3D vm->privateData; + int rv; int socket_fd =3D 0; int event_monitor_fd; =20 @@ -644,6 +648,7 @@ virCHMonitorNew(virDomainObj *vm, virCHDriverConfig *cf= g, int logfile) virCommandSetErrorFD(cmd, &logfile); virCommandNonblockingFDs(cmd); virCommandSetUmask(cmd, 0x002); + socket_fd =3D chMonitorCreateSocket(mon->socketpath); if (socket_fd < 0) { virReportSystemError(errno, @@ -655,13 +660,28 @@ virCHMonitorNew(virDomainObj *vm, virCHDriverConfig *= cfg, int logfile) virCommandAddArg(cmd, "--api-socket"); virCommandAddArgFormat(cmd, "fd=3D%d", socket_fd); virCommandPassFD(cmd, socket_fd, VIR_COMMAND_PASS_FD_CLOSE_PARENT); - virCommandAddArg(cmd, "--event-monitor"); virCommandAddArgFormat(cmd, "path=3D%s", mon->eventmonitorpath); + virCommandSetPidFile(cmd, priv->pidfile); + virCommandDaemonize(cmd); =20 /* launch Cloud-Hypervisor socket */ - if (virCommandRunAsync(cmd, &mon->pid) < 0) + rv =3D virCommandRun(cmd, NULL); + + if (rv =3D=3D 0) { + if ((rv =3D virPidFileReadPath(priv->pidfile, &mon->pid)) < 0) { + virReportSystemError(-rv, + _("Domain %1$s didn't show up"), + vm->def->name); + return NULL; + } + VIR_DEBUG("CH vm=3D%p name=3D%s running with pid=3D%lld", + vm, vm->def->name, (long long)vm->pid); + } else { + VIR_DEBUG("CH vm=3D%p name=3D%s failed to spawn", + vm, vm->def->name); return NULL; + } =20 /* open the reader end of fifo before start Event Handler */ while ((event_monitor_fd =3D open(mon->eventmonitorpath, O_RDONLY)) < = 0) { diff --git a/src/ch/ch_process.c b/src/ch/ch_process.c index b3eddd61e8..0954de6180 100644 --- a/src/ch/ch_process.c +++ b/src/ch/ch_process.c @@ -36,6 +36,7 @@ #include "virjson.h" #include "virlog.h" #include "virnuma.h" +#include "virpidfile.h" #include "virstring.h" #include "ch_interface.h" #include "ch_hostdev.h" @@ -850,6 +851,21 @@ virCHProcessPrepareHost(virCHDriver *driver, virDomain= Obj *vm) if (virCHHostdevPrepareDomainDevices(driver, vm->def, hostdev_flags) <= 0) return -1; =20 + VIR_FREE(priv->pidfile); + if (!(priv->pidfile =3D virPidFileBuildPath(cfg->stateDir, vm->def->na= me))) { + virReportSystemError(errno, + "%s", _("Failed to build pidfile path.")); + return -1; + } + + if (unlink(priv->pidfile) < 0 && + errno !=3D ENOENT) { + virReportSystemError(errno, + _("Cannot remove stale PID file %1$s"), + priv->pidfile); + return -1; + } + /* Ensure no historical cgroup for this VM is lying around */ VIR_DEBUG("Ensuring no historical cgroup is lying around"); virDomainCgroupRemoveCgroup(vm, priv->cgroup, priv->machineName); --=20 2.48.1