Blame SOURCES/bz1744145-Filesystem-2-prevent-killing-bind-mount.patch

5c52dd
From bfbc99003ebd96d79bbf8ad50be0b5e714a92fd7 Mon Sep 17 00:00:00 2001
5c52dd
From: ytakeshita <y.takeshita0311@gmail.com>
5c52dd
Date: Fri, 7 Jun 2019 15:20:52 +0900
5c52dd
Subject: [PATCH] Medium: Filesystem: Prevents to all root user processes are
5c52dd
 killed when bind mounting a directory on rootfs.
5c52dd
5c52dd
if a directory is bound mounting on rootfs and "force_umount" is not set "safe", change "force_umount" to "safe".
5c52dd
---
5c52dd
 heartbeat/Filesystem | 23 +++++++++++++++++++++++
5c52dd
 1 file changed, 23 insertions(+)
5c52dd
5c52dd
diff --git a/heartbeat/Filesystem b/heartbeat/Filesystem
5c52dd
index c46ec3cca..1b29a08b3 100755
5c52dd
--- a/heartbeat/Filesystem
5c52dd
+++ b/heartbeat/Filesystem
5c52dd
@@ -314,6 +314,24 @@ bind_kernel_check() {
5c52dd
 	[ $? -ne 0 ] &&
5c52dd
 		ocf_log warn "kernel `uname -r` cannot handle read only bind mounts"
5c52dd
 }
5c52dd
+
5c52dd
+bind_rootfs_check() {
5c52dd
+        local SOURCE
5c52dd
+        local TARGET
5c52dd
+        local ROOTFS
5c52dd
+
5c52dd
+        SOURCE=$1
5c52dd
+        TARGET=$(df --output=target $SOURCE | tail -n 1)
5c52dd
+
5c52dd
+        ROOTFS=$(list_mounts | grep -w rootfs | cut -d' ' -f 2)
5c52dd
+
5c52dd
+        if [ "${TARGET}" = "${ROOTFS}" ]; then
5c52dd
+                return 1
5c52dd
+        else
5c52dd
+                return 0
5c52dd
+        fi
5c52dd
+}
5c52dd
+
5c52dd
 bind_mount() {
5c52dd
 	if is_bind_mount && [ "$options" != "-o bind" ]
5c52dd
 	then
5c52dd
@@ -476,6 +494,11 @@ get_pids()
5c52dd
 	local procs
5c52dd
 	local mmap_procs
5c52dd
 
5c52dd
+        if is_bind_mount && ocf_is_true "$FORCE_UNMOUNT" && ! bind_rootfs_check "$DEVICE"; then
5c52dd
+                ocf_log debug "Change force_umount from '$FORCE_UNMOUNT' to 'safe'"
5c52dd
+                FORCE_UNMOUNT=safe
5c52dd
+        fi
5c52dd
+
5c52dd
 	if ocf_is_true  "$FORCE_UNMOUNT"; then
5c52dd
 		if [ "X${HOSTOS}" = "XOpenBSD" ];then
5c52dd
 			fstat | grep $dir | awk '{print $3}'