From: Stefan Reiter <s.reiter@proxmox.com>
To: pbs-devel@lists.proxmox.com
Subject: [pbs-devel] [PATCH proxmox-backup 6/7] fuse_loop: wait for instance to close after killing
Date: Wed, 7 Oct 2020 13:53:07 +0200 [thread overview]
Message-ID: <20201007115308.6275-7-s.reiter@proxmox.com> (raw)
In-Reply-To: <20201007115308.6275-1-s.reiter@proxmox.com>
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 <s.reiter@proxmox.com>
---
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::<i32>().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
next prev parent reply other threads:[~2020-10-07 11:53 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-10-07 11:53 [pbs-devel] [PATCH 0/7] fuse_loop cleanups and named mappings Stefan Reiter
2020-10-07 11:53 ` [pbs-devel] [PATCH proxmox-backup 1/7] format: fix typo in function name Stefan Reiter
2020-10-07 11:53 ` [pbs-devel] [PATCH proxmox-backup 2/7] fuse_loop: add documentation Stefan Reiter
2020-10-07 11:53 ` [pbs-devel] [PATCH proxmox-backup 3/7] loopdev: add module doc Stefan Reiter
2020-10-07 11:53 ` [pbs-devel] [PATCH proxmox-backup 4/7] mount/map: use names for map/unmap for easier use Stefan Reiter
2020-10-07 11:53 ` [pbs-devel] [PATCH proxmox-backup 5/7] fuse_loop: add automatic cleanup of run files and dangling instances Stefan Reiter
2020-10-07 11:53 ` Stefan Reiter [this message]
2020-10-07 11:53 ` [pbs-devel] [PATCH proxmox-backup 7/7] fuse_loop: handle unmap on crashed instance Stefan Reiter
2020-10-08 6:45 ` [pbs-devel] applied: [PATCH 0/7] fuse_loop cleanups and named mappings Dietmar Maurer
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20201007115308.6275-7-s.reiter@proxmox.com \
--to=s.reiter@proxmox.com \
--cc=pbs-devel@lists.proxmox.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox