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