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 272B160458 for ; Wed, 7 Oct 2020 13:53:46 +0200 (CEST) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id E148A2E283 for ; Wed, 7 Oct 2020 13:53:15 +0200 (CEST) Received: from proxmox-new.maurer-it.com (proxmox-new.maurer-it.com [212.186.127.180]) (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 BF80E2E278 for ; Wed, 7 Oct 2020 13:53:14 +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 891DA45C18 for ; Wed, 7 Oct 2020 13:53:14 +0200 (CEST) From: Stefan Reiter To: pbs-devel@lists.proxmox.com Date: Wed, 7 Oct 2020 13:53:07 +0200 Message-Id: <20201007115308.6275-7-s.reiter@proxmox.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20201007115308.6275-1-s.reiter@proxmox.com> References: <20201007115308.6275-1-s.reiter@proxmox.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SPAM-LEVEL: Spam detection results: 0 AWL -0.042 Adjusted score from AWL reputation of From: address KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment RCVD_IN_DNSWL_MED -2.3 Sender listed at https://www.dnswl.org/, medium trust 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 6/7] fuse_loop: wait for instance to close after killing 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: Wed, 07 Oct 2020 11:53:46 -0000 On unmap, only report success if the instance we are killing actually terminates. This is especially important so that cleanup routines can be assured that /run files are actually cleaned up after calling cleanup_unused_run_files. Signed-off-by: Stefan Reiter --- src/tools/fuse_loop.rs | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/src/tools/fuse_loop.rs b/src/tools/fuse_loop.rs index da186b4c..05d92525 100644 --- a/src/tools/fuse_loop.rs +++ b/src/tools/fuse_loop.rs @@ -16,6 +16,7 @@ use futures::stream::{StreamExt, TryStreamExt}; use futures::channel::mpsc::{Sender, Receiver}; use proxmox::const_regex; +use proxmox::tools::time; use proxmox_fuse::{*, requests::FuseRequest}; use super::loopdev; use super::fs; @@ -288,8 +289,28 @@ fn unmap_from_backing(backing_file: &Path) -> Result<(), Error> { let pid = pid_str.parse::().map_err(|err| format_err!("malformed PID ({}) in pidfile - {}", pid_str, err))?; + let pid = Pid::from_raw(pid); + // send SIGINT to trigger cleanup and exit in target process - signal::kill(Pid::from_raw(pid), Signal::SIGINT)?; + signal::kill(pid, Signal::SIGINT)?; + + // block until unmap is complete or timeout + let start = time::epoch_i64(); + loop { + match signal::kill(pid, None) { + Ok(_) => { + // 10 second timeout, then assume failure + if (time::epoch_i64() - start) > 10 { + return Err(format_err!("timed out waiting for PID '{}' to exit", &pid)); + } + std::thread::sleep(std::time::Duration::from_millis(100)); + }, + Err(nix::Error::Sys(nix::errno::Errno::ESRCH)) => { + break; + }, + Err(e) => return Err(e.into()), + } + } Ok(()) } -- 2.20.1