From nobody Sun Oct 5 01:49:24 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=1757424885; cv=none; d=zohomail.com; s=zohoarc; b=gEK275BQGFciDmPWJlN64jPMuglvi6mSxP+7G1o35TGAzwurBrQRPgikdJT6v82en/U9oX9Ad2GVsMoSx0junpTR9kS8nxtmREhM4LXkIcfReTc4xw+V1I+MGsG7jT3RIMuCqu7h0PDQ92nf3/+GSI8D+wq35tW7bcTbEzyjoIg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1757424885; h=Content-Type:Content-Transfer-Encoding:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Owner:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:Reply-To:References:Subject:Subject:To:To:Message-Id:Cc; bh=/obb5hxuD9SuVS7jzHuwQawDxEDSoS6UyqhO2g7HQy8=; b=QR8yYkYnmFV9T2jqPOrSx/WB3BA0uivt1Ifyj69qVVQhsNCOAiBFh7/yEk5IRUNqeyYbWPpWYQECI/JEr3e+YveKNrqkS3UnmxO1rX8LsZp6L2O88tmP/qZUqeaqdOsFTQMQIMfmNlCw0hGbjeSlKiY3w30AFqRmZYMgDf/Bdmw= 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 1757424885686315.6472813932911; Tue, 9 Sep 2025 06:34:45 -0700 (PDT) Received: by lists.libvirt.org (Postfix, from userid 993) id 8BA0A41A10; Tue, 9 Sep 2025 09:34:42 -0400 (EDT) Received: from [172.19.199.3] (lists.libvirt.org [8.43.85.245]) by lists.libvirt.org (Postfix) with ESMTP id 4390241BA9; Tue, 9 Sep 2025 09:32:42 -0400 (EDT) Received: by lists.libvirt.org (Postfix, from userid 993) id 6103741932; Tue, 9 Sep 2025 09:32:14 -0400 (EDT) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (3072 bits) server-digest SHA256) (No client certificate requested) by lists.libvirt.org (Postfix) with ESMTPS id A591941B0D for ; Tue, 9 Sep 2025 09:32:13 -0400 (EDT) Received: from mx-prod-mc-08.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-468-C49-n9STNPaMTca29iWftA-1; Tue, 09 Sep 2025 09:32:12 -0400 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-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 58BEF180034D for ; Tue, 9 Sep 2025 13:32:11 +0000 (UTC) Received: from localhost.localdomain (unknown [10.43.3.236]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id AB453300018D for ; Tue, 9 Sep 2025 13:32:10 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-26) on lists.libvirt.org X-Spam-Level: X-Spam-Status: No, score=-1.5 required=5.0 tests=DKIM_INVALID,DKIM_SIGNED, MAILING_LIST_MULTI,RCVD_IN_DNSWL_LOW, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED,RCVD_IN_VALIDITY_RPBL_BLOCKED, RCVD_IN_VALIDITY_SAFE_BLOCKED,SPF_PASS autolearn=unavailable autolearn_force=no version=4.0.1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1757424733; h=from:from: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; bh=/obb5hxuD9SuVS7jzHuwQawDxEDSoS6UyqhO2g7HQy8=; b=VcZJm1+lP+kNva4qXyxkyU5tt7oJbdbe0reeMOE0ErjDh011hRTAxKeKPlzFIQWs2bydHk i+Ia5oJrxqCvHLKVKxs72Tke4i8cEpgeRC7vb+Mb6sqlaC0s36wPztMTG/iQ0YBGdmZW1B Jmu8uaKVYj02KkYDS1T+HjTfgGDfZ2Y= X-MC-Unique: C49-n9STNPaMTca29iWftA-1 X-Mimecast-MFC-AGG-ID: C49-n9STNPaMTca29iWftA_1757424731 To: devel@lists.libvirt.org Subject: [PATCH 3/4] ch: Introduce flags to virCHProcessStop() Date: Tue, 9 Sep 2025 15:32:01 +0200 Message-ID: <5027793a2c84b2b1f9e5a7d83e2db8c7c82956b3.1757424690.git.mprivozn@redhat.com> In-Reply-To: References: 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: ZpqIF6ut1ZG09To0Fw9BOd5fMAGEpYmk0bJqzgfu6K0_1757424731 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Message-ID-Hash: NYFMGPKNXPA7V6Y72QIBHCIJPZAZVP63 X-Message-ID-Hash: NYFMGPKNXPA7V6Y72QIBHCIJPZAZVP63 X-MailFrom: mprivozn@redhat.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; loop; banned-address; header-match-devel.lists.libvirt.org-0; emergency; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header X-Mailman-Version: 3.3.10 Precedence: list List-Id: Development discussions about the libvirt library & tools Archived-At: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: From: Michal Privoznik via Devel Reply-To: Michal Privoznik X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1757424887469116601 Content-Type: text/plain; charset="utf-8"; x-default="true" From: Michal Privoznik A caller (e.g. chDomainDestroyFlags()) might want to chose whether to kill emulator process forcefully or gracefully (the @force argument of virProcessKillPainfully()). Invent a flag to virCHProcessStop() for this. And to keep consistent behaviour, pass the flag everywhere for now. Signed-off-by: Michal Privoznik --- src/ch/ch_driver.c | 8 ++++++-- src/ch/ch_events.c | 2 +- src/ch/ch_process.c | 22 ++++++++++++++++------ src/ch/ch_process.h | 8 +++++++- 4 files changed, 30 insertions(+), 10 deletions(-) diff --git a/src/ch/ch_driver.c b/src/ch/ch_driver.c index 760fccba82..019994b202 100644 --- a/src/ch/ch_driver.c +++ b/src/ch/ch_driver.c @@ -686,8 +686,11 @@ chDomainDestroyFlags(virDomainPtr dom, unsigned int fl= ags) if (virDomainObjCheckActive(vm) < 0) goto endjob; =20 - if (virCHProcessStop(driver, vm, VIR_DOMAIN_SHUTOFF_DESTROYED) < 0) + if (virCHProcessStop(driver, vm, + VIR_DOMAIN_SHUTOFF_DESTROYED, + VIR_CH_PROCESS_STOP_FORCE) < 0) { goto endjob; + } =20 event =3D virDomainEventLifecycleNewFromObj(vm, VIR_DOMAIN_EVENT_STOPPED, @@ -818,7 +821,8 @@ chDoDomainSave(virCHDriver *driver, goto end; } =20 - if (virCHProcessStop(driver, vm, VIR_DOMAIN_SHUTOFF_SAVED) < 0) { + if (virCHProcessStop(driver, vm, + VIR_DOMAIN_SHUTOFF_SAVED, VIR_CH_PROCESS_STOP_FOR= CE) < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("Failed to shutoff after domain save")); goto end; diff --git a/src/ch/ch_events.c b/src/ch/ch_events.c index 3d4e3c41e1..be572dfde3 100644 --- a/src/ch/ch_events.c +++ b/src/ch/ch_events.c @@ -59,7 +59,7 @@ virCHEventStopProcess(virDomainObj *vm, virObjectLock(vm); if (virDomainObjBeginJob(vm, VIR_JOB_DESTROY)) return -1; - virCHProcessStop(driver, vm, reason); + virCHProcessStop(driver, vm, reason, VIR_CH_PROCESS_STOP_FORCE); virDomainObjEndJob(vm); virObjectUnlock(vm); =20 diff --git a/src/ch/ch_process.c b/src/ch/ch_process.c index 6b779285e1..54b21b0baf 100644 --- a/src/ch/ch_process.c +++ b/src/ch/ch_process.c @@ -1003,7 +1003,9 @@ virCHProcessStart(virCHDriver *driver, =20 cleanup: if (ret) - virCHProcessStop(driver, vm, VIR_DOMAIN_SHUTOFF_FAILED); + virCHProcessStop(driver, vm, + VIR_DOMAIN_SHUTOFF_FAILED, + VIR_CH_PROCESS_STOP_FORCE); =20 return ret; } @@ -1011,7 +1013,8 @@ virCHProcessStart(virCHDriver *driver, int virCHProcessStop(virCHDriver *driver, virDomainObj *vm, - virDomainShutoffReason reason) + virDomainShutoffReason reason, + unsigned int flags) { g_autoptr(virCHDriverConfig) cfg =3D virCHDriverGetConfig(driver); int ret; @@ -1022,13 +1025,18 @@ virCHProcessStop(virCHDriver *driver, virErrorPtr orig_err =3D NULL; size_t i; =20 - VIR_DEBUG("Stopping VM name=3D%s pid=3D%d reason=3D%d", - vm->def->name, (int)vm->pid, (int)reason); + VIR_DEBUG("Stopping VM name=3D%s pid=3D%d reason=3D%d flags=3D0x%x", + vm->def->name, (int)vm->pid, (int)reason, flags); =20 virErrorPreserveLast(&orig_err); =20 if (priv->monitor) { - virProcessKillPainfully(vm->pid, true); + bool force =3D false; + + if (flags & VIR_CH_PROCESS_STOP_FORCE) + force =3D true; + + virProcessKillPainfully(vm->pid, force); g_clear_pointer(&priv->monitor, virCHMonitorClose); } =20 @@ -1180,6 +1188,8 @@ virCHProcessStartRestore(virCHDriver *driver, virDoma= inObj *vm, const char *from if (tapfds) chCloseFDs(tapfds, ntapfds); if (ret) - virCHProcessStop(driver, vm, VIR_DOMAIN_SHUTOFF_FAILED); + virCHProcessStop(driver, vm, + VIR_DOMAIN_SHUTOFF_FAILED, + VIR_CH_PROCESS_STOP_FORCE); return ret; } diff --git a/src/ch/ch_process.h b/src/ch/ch_process.h index 70ae8f700d..a22790bb5c 100644 --- a/src/ch/ch_process.h +++ b/src/ch/ch_process.h @@ -26,9 +26,15 @@ int virCHProcessStart(virCHDriver *driver, virDomainObj *vm, virDomainRunningReason reason); + +typedef enum { + VIR_CH_PROCESS_STOP_FORCE =3D 1 << 0, +} virCHProcessStopFlags; + int virCHProcessStop(virCHDriver *driver, virDomainObj *vm, - virDomainShutoffReason reason); + virDomainShutoffReason reason, + unsigned int flags); =20 int virCHProcessStartRestore(virCHDriver *driver, virDomainObj *vm, --=20 2.49.1