From nobody Fri May 15 10:51:54 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.libvirt.org designates 38.145.34.151 as permitted sender) client-ip=38.145.34.151; envelope-from=devel-bounces@lists.libvirt.org; helo=lists.libvirt.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.libvirt.org designates 38.145.34.151 as permitted sender) smtp.mailfrom=devel-bounces@lists.libvirt.org; dmarc=pass(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1776968314; cv=none; d=zohomail.com; s=zohoarc; b=cr0psF0kDelraov2pI7E+/4N/dIWFhzZZAGNakv3olABcO2sFf3HSPThAEDyM+pd7ZWLMUPO+uhXjg7k3nn0h4ziiQjvD2FV1dGPGZT0x+T/H9zjDoQrTiTi7jSUm9CFDWdgIN4W1jmpNoRONjMUCq/Ui/69DolcVylZXPxATa8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1776968314; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:List-Subscribe:List-Post:List-Owner:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Subject:Subject:To:To:Message-Id:Reply-To; bh=bcHMJcV4WveCeViTgLbSBiLbeC/FV3HcYdMa+Xf47Go=; b=Eovp9Qo2TIuV7a7vLXTuTmFtjl9HciSs+Knxwdy4R56Nu0fmzzcAYkYycVFm2JZTmqEAu1d7pu+H6eBnEu4DUW/ugz7NDAjhqugWRU1DsD18BoIIgnknfRyVc73AnTswiQjvqvOOxKAXt8Un1bP+zZGoTbQ7WGaT/mLq/6G5p1U= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.libvirt.org designates 38.145.34.151 as permitted sender) smtp.mailfrom=devel-bounces@lists.libvirt.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.libvirt.org (lists.libvirt.org [38.145.34.151]) by mx.zohomail.com with SMTPS id 1776968314492489.19700211096597; Thu, 23 Apr 2026 11:18:34 -0700 (PDT) Received: by lists.libvirt.org (Postfix, from userid 993) id B16FA41961; Thu, 23 Apr 2026 14:18:32 -0400 (EDT) Received: from [172.19.199.9] (unknown [10.16.107.18]) by lists.libvirt.org (Postfix) with ESMTP id 2F8C741ADC; Thu, 23 Apr 2026 14:17:34 -0400 (EDT) Received: by lists.libvirt.org (Postfix, from userid 993) id A026D41945; Thu, 23 Apr 2026 14:17:25 -0400 (EDT) Received: from mail-ed1-x52b.google.com (mail-ed1-x52b.google.com [IPv6:2a00:1450:4864:20::52b]) (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 D1E0F41942 for ; Thu, 23 Apr 2026 14:17:23 -0400 (EDT) Received: by mail-ed1-x52b.google.com with SMTP id 4fb4d7f45d1cf-671c5eb7fb0so8616463a12.3 for ; Thu, 23 Apr 2026 11:17:23 -0700 (PDT) Received: from tulp.my.domain (2001-1c02-1a15-3000-ee82-4536-a8f2-9e22.cable.dynamic.v6.ziggo.nl. [2001:1c02:1a15:3000:ee82:4536:a8f2:9e22]) by smtp.gmail.com with ESMTPSA id 4fb4d7f45d1cf-672c4d5d8f9sm4203427a12.25.2026.04.23.11.17.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 23 Apr 2026 11:17:20 -0700 (PDT) X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-26) on lists.libvirt.org X-Spam-Level: X-Spam-Status: No, score=-2.7 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE autolearn=unavailable autolearn_force=no version=4.0.1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1776968242; x=1777573042; darn=lists.libvirt.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=bcHMJcV4WveCeViTgLbSBiLbeC/FV3HcYdMa+Xf47Go=; b=VQZH6s7N9YogWgcQ9aLH0p+/hPOhxfLEao8HnICjkgDXtG2N/NwhXILHfX4gWyaZWA xs+ugXvmHU21JzLrT4DMZR0ZEoKPwEwZAQ49o5oJXdHIc3s11yk4ujEpt+tns+H+qnq6 IZy+1wR/PpCKz6hj0fLQARNMO8RmhSrurhsph83WMs1G0cVQDQDD9eG51JEes6o2uDdO 4SaBPgaY/ZAz2cNBWRsal62HjXIyrce7b5wR8qB9mZN2gyBDbkQ+Dtqm7p4QiSqcfpt6 dUgiyYi8UHl+6qkrurY4DFNcPeqggEeshhLhwOIVqEprw5/kmzt98fLuRNre9E+Dop7j Y2RQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1776968242; x=1777573042; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=bcHMJcV4WveCeViTgLbSBiLbeC/FV3HcYdMa+Xf47Go=; b=blj/mXd6vaIi9HlX16TS9aH8/xHJh2MpnSUMwjnUuXdN7QcAzx+yUo4O7uWVaXosEh FXpa0xUfH+GY+HcUHhP5Nz0lCbqe55u0sUDJjp0dS1UxlhEk/DFUScMEI+UnHg5EkxO6 pmTacMjg06Mq/pkGRejUOT2BPqIvzG/H6SUgxchIRtJx9YCisgjKQdRfASEsgarkkfa5 XpQEsJfD2xZnfYDfjQHu+oenPWeTUmn+SQq7lql+Z/EsI+Xjkd6DO0moxfUU59Bfbjr3 +TgiqoDTBReNgKl9HWVRpnzZVZ+z4TgI0bToEplWNPuFO3XLEYM789D4zaPox43GZP2c rIFA== X-Gm-Message-State: AOJu0YwX6k3UMO6LXgmlHi4nQtoKafEyXZA4KIiKfZ0XWJZ3+rp09zeP ZGd4Ram5/WrSjNc3100SSYedyqvf8yhADVIoZhe/aW69JsEaZ3d3MhH+0LTX9P8U X-Gm-Gg: AeBDieurMPda98vE7xBgFUd8Zgi1K4vOx9DmLrcweso1ML+2+q5skzCe7ijToxDsGEo ucMeDK5YT3C7yU+KKNHVq66oE7ooUlvBEhxzrkG6L52F57xE7OecMISs+F2s1yLcFONLtIF5Wrj 7hvWRkjZzV5IP89iSrDqCfZpHAC4otDUjKxqKBpfvaXdBGGwbYPi7JwXIW1R+JJ7wb3CFT8M5oX QhBkZxIBS7f0w8+ahfoiBLgKbDofkq6FifmtuoX8iKFMsmhaTXjn3W1Bq9GuOWRr/7sRL4pHqEm 8N4+6l9CoTVlknzJBbnS725wjhii+H3EBReWxtgHNonvjYNsNru89tLOQPGJmgPMRrq5we3idm6 KUz7qDWBEHnTzbR62fIH5cv4Ti/BRaODtNDL+gShmxQwip3Y17e61vDYczjx8f09JBoxkHYAF+P Xodzc7gL/uEETVI7CW0LYaxLMLZ248cWuiVNrtmwC5pnETvBC+mD/e9vSv1vU2ktY9GHFzhLikz XKFx1NNLzUM0yygufOPlfEWYtpkxGv5/ZDQUhL7StaW4DW6 X-Received: by 2002:a05:6402:5201:b0:675:278c:9d8 with SMTP id 4fb4d7f45d1cf-675278c0e3bmr9262712a12.17.1776968241444; Thu, 23 Apr 2026 11:17:21 -0700 (PDT) From: Roman Bogorodskiy To: devel@lists.libvirt.org Subject: [PATCH] bhyve: fix virBhyveProcessStop() Date: Thu, 23 Apr 2026 20:15:16 +0200 Message-ID: <20260423181516.1804-1-bogorodskiy@gmail.com> X-Mailer: git-send-email 2.52.0 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Message-ID-Hash: X7ZYMNWWCPSI64WRL4EY5ZBZJFZLIHMO X-Message-ID-Hash: X7ZYMNWWCPSI64WRL4EY5ZBZJFZLIHMO X-MailFrom: bogorodskiy@gmail.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 CC: Roman Bogorodskiy , Peter Krempa 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: X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1776968316647158500 Content-Type: text/plain; charset="utf-8" Currently, there are two (at least) issues in virBhyveProcessStop(). Before going into details, a quick overview of the bhyve shutdown process. It is a two stage process*: first, the main bhyve process gets destroyed (either via an external command or within the guest), then the resources need to be cleaned up using the bhyvectl(8) tool. The first issue is that if virCommandRun() for bhyvectl(8) fails, virBhyveProcessStop() jumps to the 'cleanup' label and misses cleaning of some resources. The second issue is more serious. Currently, monitor is closed only after running of the bhyvectl(8) command. That means that the monitor could catch the domain destroy event and try to run virBhyveProcessStop() on the same domain again, resulting in trying to release already released resources, such as the monitor itself. Address by: * Making virCommandRun() on bhyvectl(8) non-critical. Even if it fails, we try to clean up all resources. We consider the function failed (return value 1) though. * Close monitor before running bhyvectl(8) Additionally, do not verify that virBhyveProcessBuildDestroyCmd() returns non-NULL, there could be only allocation errors. Reported-by: Peter Krempa Signed-off-by: Roman Bogorodskiy Reviewed-by: Peter Krempa --- src/bhyve/bhyve_process.c | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/src/bhyve/bhyve_process.c b/src/bhyve/bhyve_process.c index 26320200c5..842ff0d6fc 100644 --- a/src/bhyve/bhyve_process.c +++ b/src/bhyve/bhyve_process.c @@ -515,7 +515,7 @@ virBhyveProcessStop(struct _bhyveConn *driver, virDomainObj *vm, virDomainShutoffReason reason) { - int ret =3D -1; + int ret =3D 0; g_autoptr(virCommand) cmd =3D NULL; bhyveDomainObjPrivate *priv =3D vm->privateData; =20 @@ -531,15 +531,19 @@ virBhyveProcessStop(struct _bhyveConn *driver, return -1; } =20 - if (!(cmd =3D virBhyveProcessBuildDestroyCmd(driver, vm->def))) - return -1; - - if (virCommandRun(cmd, NULL) < 0) - goto cleanup; - + /* Destroy monitor before running the actual destroy command to prevent + * it from detecting VM shutdown and entering this cleanup routine aga= in */ if ((priv !=3D NULL) && (priv->mon !=3D NULL)) bhyveMonitorClose(priv->mon); =20 + cmd =3D virBhyveProcessBuildDestroyCmd(driver, vm->def); + if (virCommandRun(cmd, NULL) < 0) { + /* Only failure of the actual destroy command warrants unsuccessfu= l return code, + * other failures are not considered critical */ + ret =3D -1; + VIR_WARN("Failed to run the domain destroy command"); + } + bhyveProcessStopHook(driver, vm, VIR_HOOK_BHYVE_OP_STOPPED); =20 /* Cleanup network interfaces */ @@ -554,8 +558,6 @@ virBhyveProcessStop(struct _bhyveConn *driver, } } =20 - ret =3D 0; - virCloseCallbacksDomainRemove(vm, NULL, bhyveProcessAutoDestroy); =20 virDomainObjSetState(vm, VIR_DOMAIN_SHUTOFF, reason); @@ -563,8 +565,6 @@ virBhyveProcessStop(struct _bhyveConn *driver, vm->def->id =3D -1; =20 bhyveProcessStopHook(driver, vm, VIR_HOOK_BHYVE_OP_RELEASE); - - cleanup: virPidFileDelete(BHYVE_STATE_DIR, vm->def->name); bhyveProcessRemoveDomainStatus(BHYVE_STATE_DIR, vm->def->name); =20 --=20 2.52.0