e7a346
From 644bcd954000b77fc8f49e3a7941de23ca869427 Mon Sep 17 00:00:00 2001
e7a346
From: Anoop C S <anoopcs@redhat.com>
e7a346
Date: Wed, 21 Mar 2018 13:09:01 +0530
e7a346
Subject: [PATCH 481/493] extras/hooks: Do not blindly remove volume share from
e7a346
 smb.conf
e7a346
e7a346
When Gluster volumes are shared via Samba, any extra smb.conf parameter
e7a346
setting done by administrator to those shares are lost during restart
e7a346
of the volume. Instead of removing the whole share completely from
e7a346
smb.conf(via hook scripts during volume stop) it is better to make it
e7a346
temporarily unavailable to end-users till the volume is started again.
e7a346
Therefore we make use of a smb.conf parameter named 'available'[1] to
e7a346
achieve the above intend.
e7a346
e7a346
[1] https://www.samba.org/samba/docs/current/man-html/smb.conf.5.html
e7a346
e7a346
upstream ref: https://review.gluster.org/c/glusterfs/+/19750
e7a346
e7a346
Change-Id: I68a9055b50791f6ffd3b95a3c13d858a75fa6530
e7a346
BUG: 1164778
e7a346
Signed-off-by: Anoop C S <anoopcs@redhat.com>
e7a346
Reviewed-on: https://code.engineering.redhat.com/gerrit/158495
e7a346
Tested-by: RHGS Build Bot <nigelb@redhat.com>
e7a346
Reviewed-by: Sunil Kumar Heggodu Gopala Acharya <sheggodu@redhat.com>
e7a346
---
e7a346
 extras/hook-scripts/set/post/S30samba-set.sh     | 11 ++++++-----
e7a346
 extras/hook-scripts/start/post/S30samba-start.sh |  4 +++-
e7a346
 extras/hook-scripts/stop/pre/S30samba-stop.sh    |  6 +++---
e7a346
 3 files changed, 12 insertions(+), 9 deletions(-)
e7a346
e7a346
diff --git a/extras/hook-scripts/set/post/S30samba-set.sh b/extras/hook-scripts/set/post/S30samba-set.sh
e7a346
index b93415b..c596db0 100755
e7a346
--- a/extras/hook-scripts/set/post/S30samba-set.sh
e7a346
+++ b/extras/hook-scripts/set/post/S30samba-set.sh
e7a346
@@ -103,9 +103,9 @@ function sighup_samba () {
e7a346
         fi
e7a346
 }
e7a346
 
e7a346
-function del_samba_share () {
e7a346
+function deactivate_samba_share () {
e7a346
         volname=$1
e7a346
-        sed -i "/\[gluster-$volname\]/,/^$/d" ${CONFIGFILE}
e7a346
+        sed -i -e '/^\[gluster-'"$volname"'\]/{ :a' -e 'n; /available = no/H; /^$/!{$!ba;}; x; /./!{ s/^/available = no/; $!{G;x}; $H; }; s/.*//; x; };' ${CONFIGFILE}
e7a346
 }
e7a346
 
e7a346
 function is_volume_started () {
e7a346
@@ -140,12 +140,13 @@ if [ "$USERCIFS_SET" = "YES" ] || [ "$USERSMB_SET" = "YES" ]; then
e7a346
     find_config_info
e7a346
 
e7a346
     if [ "$(get_smb "$VOL")" = "disable" ]; then
e7a346
-        del_samba_share $VOL
e7a346
-        sighup_samba
e7a346
+        deactivate_samba_share $VOL
e7a346
     else
e7a346
         if ! grep --quiet "\[gluster-$VOL\]" ${CONFIGFILE} ; then
e7a346
             add_samba_share $VOL
e7a346
-            sighup_samba
e7a346
+        else
e7a346
+            sed -i '/\[gluster-'"$VOL"'\]/,/^$/!b;/available = no/d' ${CONFIGFILE}
e7a346
         fi
e7a346
     fi
e7a346
+    sighup_samba
e7a346
 fi
e7a346
diff --git a/extras/hook-scripts/start/post/S30samba-start.sh b/extras/hook-scripts/start/post/S30samba-start.sh
e7a346
index 92ddaf4..5d586ee 100755
e7a346
--- a/extras/hook-scripts/start/post/S30samba-start.sh
e7a346
+++ b/extras/hook-scripts/start/post/S30samba-start.sh
e7a346
@@ -127,5 +127,7 @@ find_config_info
e7a346
 
e7a346
 if ! grep --quiet "\[gluster-$VOL\]" ${CONFIGFILE} ; then
e7a346
         add_samba_share $VOL
e7a346
-        sighup_samba
e7a346
+else
e7a346
+        sed -i '/\[gluster-'"$VOL"'\]/,/^$/!b;/available = no/d' ${CONFIGFILE}
e7a346
 fi
e7a346
+sighup_samba
e7a346
diff --git a/extras/hook-scripts/stop/pre/S30samba-stop.sh b/extras/hook-scripts/stop/pre/S30samba-stop.sh
e7a346
index 5e87845..ea79938 100755
e7a346
--- a/extras/hook-scripts/stop/pre/S30samba-stop.sh
e7a346
+++ b/extras/hook-scripts/stop/pre/S30samba-stop.sh
e7a346
@@ -56,9 +56,9 @@ function find_config_info () {
e7a346
         PIDDIR=`smbd -b | grep PIDDIR | awk '{print $2}'`
e7a346
 }
e7a346
 
e7a346
-function del_samba_share () {
e7a346
+function deactivate_samba_share () {
e7a346
         volname=$1
e7a346
-        sed -i "/\[gluster-$volname\]/,/^$/d" ${CONFIGFILE}
e7a346
+        sed -i -e '/^\[gluster-'"$volname"'\]/{ :a' -e 'n; /available = no/H; /^$/!{$!ba;}; x; /./!{ s/^/available = no/; $!{G;x}; $H; }; s/.*//; x; };' ${CONFIGFILE}
e7a346
 }
e7a346
 
e7a346
 function sighup_samba () {
e7a346
@@ -73,5 +73,5 @@ function sighup_samba () {
e7a346
 
e7a346
 parse_args "$@"
e7a346
 find_config_info
e7a346
-del_samba_share $VOL
e7a346
+deactivate_samba_share $VOL
e7a346
 sighup_samba
e7a346
-- 
e7a346
1.8.3.1
e7a346