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

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