e7a346
From d88cae2d02f0c106b4330128715921c459dd77fc Mon Sep 17 00:00:00 2001
e7a346
From: Amar Tumballi <amarts@redhat.com>
e7a346
Date: Fri, 3 Nov 2017 11:49:42 +0530
e7a346
Subject: [PATCH 174/180] hooks: add a script to stat the subdirs in add-brick
e7a346
e7a346
The subdirectories are expected to be present for a subdir
e7a346
mount to be successful. If not, the client_handshake()
e7a346
itself fails to succeed. When a volume is about to get
e7a346
mounted first time, this is easier to handle, as if the
e7a346
directory is not present in one brick, then its mostly
e7a346
not present in any other brick. In case of add-brick,
e7a346
the directory is not present in new brick, and there is
e7a346
no chance of healing it from the subdirectory mount, as
e7a346
in those clients, the subdir itself will be 'root' ('/')
e7a346
of the filesystem. Hence we need a volume mount to heal
e7a346
the directory before connections can succeed.
e7a346
e7a346
This patch does take care of that by healing the directories
e7a346
which are expected to be mounted as subdirectories from the
e7a346
volume level mount point.
e7a346
e7a346
>Change-Id: I2c2ac7b7567fe209aaa720006d09b68584d0dd14
e7a346
>BUG: 1549915
e7a346
>Signed-off-by: Amar Tumballi <amarts@redhat.com>
e7a346
upstream patch: https://review.gluster.org/#/c/18645/
e7a346
e7a346
BUG: 1508999
e7a346
Change-Id: I2c2ac7b7567fe209aaa720006d09b68584d0dd14
e7a346
Signed-off-by: Sunil Kumar Acharya <sheggodu@redhat.com>
e7a346
Reviewed-on: https://code.engineering.redhat.com/gerrit/131896
e7a346
Tested-by: RHGS Build Bot <nigelb@redhat.com>
e7a346
Reviewed-by: Atin Mukherjee <amukherj@redhat.com>
e7a346
---
e7a346
 extras/hook-scripts/add-brick/post/Makefile.am     |  4 +-
e7a346
 .../add-brick/post/S13create-subdir-mounts.sh      | 86 ++++++++++++++++++++++
e7a346
 glusterfs.spec.in                                  |  3 +-
e7a346
 tests/features/subdir-mount.t                      | 16 +---
e7a346
 4 files changed, 94 insertions(+), 15 deletions(-)
e7a346
 create mode 100755 extras/hook-scripts/add-brick/post/S13create-subdir-mounts.sh
e7a346
e7a346
diff --git a/extras/hook-scripts/add-brick/post/Makefile.am b/extras/hook-scripts/add-brick/post/Makefile.am
e7a346
index 5ca5a66..8eb82a1 100644
e7a346
--- a/extras/hook-scripts/add-brick/post/Makefile.am
e7a346
+++ b/extras/hook-scripts/add-brick/post/Makefile.am
e7a346
@@ -1,4 +1,4 @@
e7a346
-EXTRA_DIST = disabled-quota-root-xattr-heal.sh
e7a346
+EXTRA_DIST = disabled-quota-root-xattr-heal.sh S13create-subdir-mounts.sh
e7a346
 
e7a346
 hookdir = $(GLUSTERD_WORKDIR)/hooks/1/add-brick/post/
e7a346
-hook_SCRIPTS = disabled-quota-root-xattr-heal.sh
e7a346
+hook_SCRIPTS = disabled-quota-root-xattr-heal.sh S13create-subdir-mounts.sh
e7a346
diff --git a/extras/hook-scripts/add-brick/post/S13create-subdir-mounts.sh b/extras/hook-scripts/add-brick/post/S13create-subdir-mounts.sh
e7a346
new file mode 100755
e7a346
index 0000000..95e624e
e7a346
--- /dev/null
e7a346
+++ b/extras/hook-scripts/add-brick/post/S13create-subdir-mounts.sh
e7a346
@@ -0,0 +1,86 @@
e7a346
+#!/bin/bash
e7a346
+
e7a346
+##---------------------------------------------------------------------------
e7a346
+## This script runs the self-heal of the directories which are expected to
e7a346
+## be present as they are mounted as subdirectory mounts.
e7a346
+##---------------------------------------------------------------------------
e7a346
+
e7a346
+MOUNT_DIR=`mktemp -d -t ${0##*/}.XXXXXX`;
e7a346
+OPTSPEC="volname:,go-workdir"
e7a346
+PROGNAME="add-brick-create-subdir"
e7a346
+VOL_NAME=test
e7a346
+GLUSTERD_WORKDIR="/var/lib/glusterd"
e7a346
+
e7a346
+cleanup_mountpoint ()
e7a346
+{
e7a346
+        umount -f $MOUNT_DIR;
e7a346
+        if [ 0 -ne $? ]
e7a346
+        then
e7a346
+                return $?
e7a346
+        fi
e7a346
+
e7a346
+        rmdir $MOUNT_DIR;
e7a346
+        if [ 0 -ne $? ]
e7a346
+        then
e7a346
+                return $?
e7a346
+        fi
e7a346
+}
e7a346
+
e7a346
+##------------------------------------------
e7a346
+## Parse the arguments
e7a346
+##------------------------------------------
e7a346
+ARGS=$(getopt -l $OPTSPEC  -name $PROGNAME $@)
e7a346
+eval set -- "$ARGS"
e7a346
+
e7a346
+while true;
e7a346
+do
e7a346
+    case $1 in
e7a346
+        --volname)
e7a346
+            shift
e7a346
+            VOL_NAME=$1
e7a346
+            ;;
e7a346
+        --gd-workdir)
e7a346
+            shift
e7a346
+            GLUSTERD_WORKDIR=$1
e7a346
+            ;;
e7a346
+	--version)
e7a346
+	    shift
e7a346
+	    ;;
e7a346
+	--volume-op)
e7a346
+	    shift
e7a346
+	    ;;
e7a346
+	*)
e7a346
+	    shift
e7a346
+	    break
e7a346
+	    ;;
e7a346
+    esac
e7a346
+    shift
e7a346
+done
e7a346
+
e7a346
+## See if we have any subdirs to be healed before going further
e7a346
+subdirs=$(grep 'auth.allow' ${GLUSTERD_WORKDIR}/vols/${VOL_NAME}/info | cut -f2 -d'=' | tr ',' '\n' | cut -f1 -d'(');
e7a346
+
e7a346
+if [ -z ${subdirs} ]; then
e7a346
+    rmdir $MOUNT_DIR;
e7a346
+    exit 0;
e7a346
+fi
e7a346
+
e7a346
+##----------------------------------------
e7a346
+## Mount the volume in temp directory.
e7a346
+## -----------------------------------
e7a346
+glusterfs -s localhost --volfile-id=$VOL_NAME --client-pid=-50 $MOUNT_DIR;
e7a346
+if [ 0 -ne $? ]
e7a346
+then
e7a346
+    exit $?;
e7a346
+fi
e7a346
+
e7a346
+## -----------------------------------
e7a346
+# Do the 'stat' on all the directory for now. Ideal fix is to look at subdir
e7a346
+# list from 'auth.allow' option and only stat them.
e7a346
+for subdir in ${subdirs}
e7a346
+do
e7a346
+    stat ${MOUNT_DIR}/${subdir} > /dev/null;
e7a346
+done
e7a346
+
e7a346
+## Clean up and exit
e7a346
+cleanup_mountpoint;
e7a346
diff --git a/glusterfs.spec.in b/glusterfs.spec.in
e7a346
index ca36e65..34a3aba 100644
e7a346
--- a/glusterfs.spec.in
e7a346
+++ b/glusterfs.spec.in
e7a346
@@ -1519,8 +1519,9 @@ exit 0
e7a346
        %dir %attr(0755,-,-) %{_sharedstatedir}/glusterd/hooks/1/add-brick
e7a346
        %dir %attr(0755,-,-) %{_sharedstatedir}/glusterd/hooks/1/add-brick/post
e7a346
             %attr(0755,-,-) %{_sharedstatedir}/glusterd/hooks/1/add-brick/post/disabled-quota-root-xattr-heal.sh
e7a346
-            %attr(0755,-,-) %{_sharedstatedir}/glusterd/hooks/1/add-brick/pre/S28Quota-enable-root-xattr-heal.sh
e7a346
+            %attr(0755,-,-) %{_sharedstatedir}/glusterd/hooks/1/add-brick/post/S13create-subdir-mounts.sh
e7a346
        %dir %attr(0755,-,-) %{_sharedstatedir}/glusterd/hooks/1/add-brick/pre
e7a346
+            %attr(0755,-,-) %{_sharedstatedir}/glusterd/hooks/1/add-brick/pre/S28Quota-enable-root-xattr-heal.sh
e7a346
        %dir %attr(0755,-,-) %{_sharedstatedir}/glusterd/hooks/1/create
e7a346
        %dir %attr(0755,-,-) %{_sharedstatedir}/glusterd/hooks/1/create/post
e7a346
             %attr(0755,-,-) %{_sharedstatedir}/glusterd/hooks/1/create/post/S10selinux-label-brick.sh
e7a346
diff --git a/tests/features/subdir-mount.t b/tests/features/subdir-mount.t
e7a346
index 1742f86..8401946 100644
e7a346
--- a/tests/features/subdir-mount.t
e7a346
+++ b/tests/features/subdir-mount.t
e7a346
@@ -98,22 +98,14 @@ TEST test "$mount_inode" == "1"
e7a346
 
e7a346
 TEST umount $M2
e7a346
 
e7a346
-# because the subdir is not yet 'healed', below should fail.
e7a346
+# Now the exported subdirs should be automatically healed due to
e7a346
+# hook scripts. Check if the mount is successful.
e7a346
 TEST $GFS --subdir-mount /subdir2 -s $H0 --volfile-id $V0 $M2
e7a346
 mount_inode=$(stat --format "%i" "$M2")
e7a346
-TEST test "$mount_inode" != "1"
e7a346
-
e7a346
-# Allow the heal to complete
e7a346
-TEST stat $M0/subdir1/subdir1.1/subdir1.2/subdir1.2_file;
e7a346
-TEST stat $M0/subdir2/
e7a346
-
e7a346
-# Now the mount should succeed
e7a346
-TEST $GFS --subdir-mount /subdir2 -s $H0 --volfile-id $V0 $M1
e7a346
-TEST stat $M1
e7a346
+TEST test "$mount_inode" == "1"
e7a346
 
e7a346
-# umount $M1 / $M2
e7a346
 TEST umount $M0
e7a346
-TEST umount $M1
e7a346
+TEST umount $M2
e7a346
 
e7a346
 
e7a346
 TEST $CLI volume stop $V0;
e7a346
-- 
e7a346
1.8.3.1
e7a346