refs #2705: Improve dealing with blocked unmount by our own script

pull/110/head
Vadim vtroshchinskiy 2025-09-03 13:30:15 +02:00
parent 8290c31146
commit d4a6e09771
1 changed files with 13 additions and 6 deletions

View File

@ -89,6 +89,8 @@ class FilesystemLibrary:
if not pid_dir.isdigit():
continue # Not a pid directory
pid_num = int(pid_dir)
pid_dir_path = os.path.join(proc_path, pid_dir)
fd_path = os.path.join(pid_dir_path, "fd")
@ -100,11 +102,11 @@ class FilesystemLibrary:
if command_name.startswith(path):
self.logger.debug("PID %s (%s) is running from within %s: %s", pid_dir, command_name, path, command_name)
pids_using_path[pid_dir] = { "cmd" : command_name, "args" : cmdline}
self.logger.debug("PID %i (%s) is running from within %s: %s", pid_num, command_name, path, command_name)
pids_using_path[pid_num] = { "cmd" : command_name, "args" : cmdline}
elif working_dir.startswith(path):
self.logger.debug("PID %s (%s) is has a working directory within %s: %s", pid_dir, command_name, path, working_dir)
pids_using_path[pid_dir] = { "cmd" : command_name, "args" : cmdline}
self.logger.debug("PID %i (%s) is has a working directory within %s: %s", pid_num, command_name, path, working_dir)
pids_using_path[pid_num] = { "cmd" : command_name, "args" : cmdline}
else:
try:
for fd_file in os.listdir(fd_path):
@ -112,8 +114,8 @@ class FilesystemLibrary:
target = self._read_link(fd_file_full_path)
if target.startswith(path):
self.logger.debug("PID %s (%s) is has an open file within %s: %s", pid_dir, command_name, path, target)
pids_using_path[pid_dir] = { "cmd" : command_name, "args" : cmdline}
self.logger.debug("PID %i (%s) is has an open file within %s: %s", pid_num, command_name, path, target)
pids_using_path[pid_num] = { "cmd" : command_name, "args" : cmdline}
except IOError as ioerr:
self.logger.warning("Exception during listdir: %s", ioerr)
@ -140,6 +142,11 @@ class FilesystemLibrary:
lsof_data = self.lsof(path)
for pid, pid_data in lsof_data.items():
if pid == os.getpid():
self.logger.error("We're trying to terminate our own process!")
self.logger.error("This script is probably being run from within a mounted filesystem we need unmounted.")
self.logger.error("Our working directory is %s", os.getcwd())
self.logger.error("We need %s to be unmounted", path)
try:
if use_sigkill: