From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from firstgate.proxmox.com (firstgate.proxmox.com [212.224.123.68]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by lists.proxmox.com (Postfix) with ESMTPS id 547557A187 for ; Thu, 6 May 2021 17:27:36 +0200 (CEST) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 4A15422D58 for ; Thu, 6 May 2021 17:27:06 +0200 (CEST) Received: from proxmox-new.maurer-it.com (proxmox-new.maurer-it.com [94.136.29.106]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by firstgate.proxmox.com (Proxmox) with ESMTPS id 139F222D1D for ; Thu, 6 May 2021 17:27:04 +0200 (CEST) Received: from proxmox-new.maurer-it.com (localhost.localdomain [127.0.0.1]) by proxmox-new.maurer-it.com (Proxmox) with ESMTP id D69F04651D for ; Thu, 6 May 2021 17:27:03 +0200 (CEST) From: Stefan Reiter To: pbs-devel@lists.proxmox.com Date: Thu, 6 May 2021 17:26:17 +0200 Message-Id: <20210506152624.12605-3-s.reiter@proxmox.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20210506152624.12605-1-s.reiter@proxmox.com> References: <20210506152624.12605-1-s.reiter@proxmox.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SPAM-LEVEL: Spam detection results: 0 AWL 0.015 Adjusted score from AWL reputation of From: address KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record Subject: [pbs-devel] [PATCH proxmox-backup 2/9] file-restore: try to kill VM when stale X-BeenThere: pbs-devel@lists.proxmox.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Proxmox Backup Server development discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 06 May 2021 15:27:36 -0000 Helps to clean up a VM that has crashed, is not responding to vsock API calls, but still has a running QEMU instance. We always check the process commandline to ensure we don't kill a random process that took over the PID. Signed-off-by: Stefan Reiter --- src/bin/proxmox_file_restore/block_driver_qemu.rs | 2 ++ src/bin/proxmox_file_restore/qemu_helper.rs | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/src/bin/proxmox_file_restore/block_driver_qemu.rs b/src/bin/proxmox_file_restore/block_driver_qemu.rs index c95bf80b..24f62796 100644 --- a/src/bin/proxmox_file_restore/block_driver_qemu.rs +++ b/src/bin/proxmox_file_restore/block_driver_qemu.rs @@ -98,6 +98,7 @@ async fn cleanup_map(map: &mut HashMap) -> bool { "VM '{}' (pid: {}, cid: {}) was not reachable, removing from map", name, state.pid, state.cid ); + let _ = super::qemu_helper::try_kill_vm(state.pid); } } @@ -131,6 +132,7 @@ async fn ensure_running(details: &SnapRestoreDetails) -> Result { eprintln!("stale VM detected, restarting ({})", err); // VM is dead, restart + let _ = super::qemu_helper::try_kill_vm(vm.pid); let vms = start_vm(vm.cid, details).await?; new_cid = vms.cid; state.map.insert(name, vms.clone()); diff --git a/src/bin/proxmox_file_restore/qemu_helper.rs b/src/bin/proxmox_file_restore/qemu_helper.rs index 20b4f344..a2b5b09d 100644 --- a/src/bin/proxmox_file_restore/qemu_helper.rs +++ b/src/bin/proxmox_file_restore/qemu_helper.rs @@ -60,7 +60,7 @@ fn validate_img_existance(debug: bool) -> Result<(), Error> { Ok(()) } -fn try_kill_vm(pid: i32) -> Result<(), Error> { +pub fn try_kill_vm(pid: i32) -> Result<(), Error> { let pid = Pid::from_raw(pid); if let Ok(()) = kill(pid, None) { // process is running (and we could kill it), check if it is actually ours -- 2.20.1