ac8f41417625aad6cbd921d82550de2134e19caa
[pti/rtp.git] / meta-starlingx / meta-stx-integ / recipes-support / drbd / drbd-utils / 0009-Check-for-mounted-device-before-demoting-Primary-DRB.patch
1 From 017157d21a56410811384a43d0b0cbba6444baeb Mon Sep 17 00:00:00 2001
2 From: Don Penney <don.penney@windriver.com>
3 Date: Wed, 6 Feb 2019 01:19:59 -0500
4 Subject: [PATCH] Check for mounted device before demoting Primary DRBD
5  resource
6
7 Update the OCF script to check for a mounted device when demoting
8 a resource that's in the Primary state. The state change will fail
9 if it is still in use, otherwise.
10
11 Signed-off-by: Don Penney <don.penney@windriver.com>
12 ---
13  scripts/drbd.ocf | 16 +++++++++++++++-
14  1 file changed, 15 insertions(+), 1 deletion(-)
15
16 diff --git a/scripts/drbd.ocf b/scripts/drbd.ocf
17 index e03bf6d..95da11a 100644
18 --- a/scripts/drbd.ocf
19 +++ b/scripts/drbd.ocf
20 @@ -720,7 +720,21 @@ drbd_stop() {
21                         ;;
22                 $OCF_RUNNING_MASTER)
23                         ocf_log warn "$DRBD_RESOURCE still Primary, demoting."
24 -                       do_drbdadm secondary  $DRBD_RESOURCE
25 +                       found=no
26 +                       for dev in ${DRBD_DEVICES[@]} ""; do
27 +                               cat /proc/mounts | grep -q "^${dev} "
28 +                               if [ $? -eq 0 ]; then
29 +                                       ocf_log warn "${DRBD_RESOURCE} is still mounted via $dev"
30 +                                       found=yes
31 +                                       break
32 +                               fi
33 +                       done
34 +                       if [ "${found}" = "yes" ]; then
35 +                               ocf_log warn "Waiting to drop $DRBD_RESOURCE"
36 +                       else
37 +                               ocf_log warn "Dropping $DRBD_RESOURCE to Secondary"
38 +                               do_drbdadm secondary  $DRBD_RESOURCE
39 +                       fi
40                 esac
41                 $first_try || sleep 1
42                 first_try=false
43 -- 
44 1.8.3.1
45