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

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