Skip to content

Filesystem: try umount first during stop-action, and avoid potential "Argument list too long" for force_unmount=safe #1977

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Sep 19, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 25 additions & 3 deletions heartbeat/Filesystem
Original file line number Diff line number Diff line change
Expand Up @@ -669,9 +669,26 @@ get_pids()
$FUSER -Mm $dir 2>/dev/null
fi
elif [ "$FORCE_UNMOUNT" = "safe" ]; then
procs=$(find /proc/[0-9]*/ -type l -lname "${dir}/*" -or -lname "${dir}" 2>/dev/null | awk -F/ '{print $3}')
mmap_procs=$(grep " ${dir}/" /proc/[0-9]*/maps | awk -F/ '{print $3}')
printf "${procs}\n${mmap_procs}" | sort | uniq
# Yes, in theory, ${dir} could contain "intersting" characters
# and would need to be quoted for glob (find) and regex (grep).
# Don't do that, then.

# Avoid /proc/[0-9]*, it may cause "Argument list too long".
# There are several ways to filter for /proc/<pid>
# -mindepth 1 -not -path "/proc/[0-9]*" -prune -o ...
# -path "/proc/[!0-9]*" -prune -o ...
# -path "/proc/[0-9]*" -a ...
# the latter seemd to be significantly faster for this one in my naive test.
procs=$(exec 2>/dev/null;
find /proc -path "/proc/[0-9]*" -type l \( -lname "${dir}/*" -o -lname "${dir}" \) -print |
awk -F/ '{print $3}' | uniq)

# This finds both /proc/<pid>/maps and /proc/<pid>/task/<tid>/maps;
# if you don't want the latter, add -maxdepth.
mmap_procs=$(exec 2>/dev/null;
find /proc -path "/proc/[0-9]*/maps" -print |
xargs -r grep -l " ${dir}/" | awk -F/ '{print $3}' | uniq)
printf "${procs}\n${mmap_procs}" | sort -u
fi
}

Expand Down Expand Up @@ -732,6 +749,11 @@ fs_stop() {
local SUB="$1" timeout=$2 grace_time ret
grace_time=$((timeout/2))

# Just walking /proc may take "a long time", even if we don't find any users of this FS.
# If dependencies are properly configured, umount should just work.
# Only if that fails, try to find and kill processes that still use it.
try_umount "" "$SUB" && return $OCF_SUCCESS

# try gracefully terminating processes for up to half of the configured timeout
fs_stop_loop "" "$SUB" "$OCF_RESKEY_term_signals" &
timeout_child $! $grace_time
Expand Down