@@ -669,9 +669,26 @@ get_pids()
669669 $FUSER -Mm $dir 2> /dev/null
670670 fi
671671 elif [ " $FORCE_UNMOUNT " = " safe" ]; then
672- procs=$( find /proc/[0-9]* / -type l -lname " ${dir} /*" -or -lname " ${dir} " 2> /dev/null | awk -F/ ' {print $3}' )
673- mmap_procs=$( grep " ${dir} /" /proc/[0-9]* /maps | awk -F/ ' {print $3}' )
674- printf " ${procs} \n${mmap_procs} " | sort | uniq
672+ # Yes, in theory, ${dir} could contain "intersting" characters
673+ # and would need to be quoted for glob (find) and regex (grep).
674+ # Don't do that, then.
675+
676+ # Avoid /proc/[0-9]*, it may cause "Argument list too long".
677+ # There are several ways to filter for /proc/<pid>
678+ # -mindepth 1 -not -path "/proc/[0-9]*" -prune -o ...
679+ # -path "/proc/[!0-9]*" -prune -o ...
680+ # -path "/proc/[0-9]*" -a ...
681+ # the latter seemd to be significantly faster for this one in my naive test.
682+ procs=$( exec 2> /dev/null;
683+ find /proc -path " /proc/[0-9]*" -type l \( -lname " ${dir} /*" -o -lname " ${dir} " \) -print |
684+ awk -F/ ' {print $3}' | uniq)
685+
686+ # This finds both /proc/<pid>/maps and /proc/<pid>/task/<tid>/maps;
687+ # if you don't want the latter, add -maxdepth.
688+ mmap_procs=$( exec 2> /dev/null;
689+ find /proc -path " /proc/[0-9]*/maps" -print |
690+ xargs -r grep -l " ${dir} /" | awk -F/ ' {print $3}' | uniq)
691+ printf " ${procs} \n${mmap_procs} " | sort -u
675692 fi
676693}
677694
@@ -732,6 +749,11 @@ fs_stop() {
732749 local SUB=" $1 " timeout=$2 grace_time ret
733750 grace_time=$(( timeout/ 2 ))
734751
752+ # Just walking /proc may take "a long time", even if we don't find any users of this FS.
753+ # If dependencies are properly configured, umount should just work.
754+ # Only if that fails, try to find and kill processes that still use it.
755+ try_umount " " " $SUB " && return $OCF_SUCCESS
756+
735757 # try gracefully terminating processes for up to half of the configured timeout
736758 fs_stop_loop " " " $SUB " " $OCF_RESKEY_term_signals " &
737759 timeout_child $! $grace_time
0 commit comments