summaryrefslogtreecommitdiffstats
path: root/extras/hook-scripts/add-brick/pre/S28Quota-enable-root-xattr-heal.sh
blob: 0801386549abf2e92b1c88facede70898ab308a9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
#!/bin/sh

###############################################################################
## ----------------------------------------------------------------------------
## The scripts
## I.   add-brick/pre/S28Quota-root-xattr-heal.sh (itself)
## II.  add-brick/post/disabled-root-xattr-heal.sh AND
## collectively archieves the job of healing the 'limit-set' xattr upon
## add-brick to the gluster volume.
##
## This script is the 'controlling' script. Upon add-brick this script enables
## the corresponding script based on the status of the volume.
## If volume is started - enable add-brick/post script
## else                 - enable start/post script.
##
## The enabling and disabling of a script is based on the glusterd's logic,
## that it only runs the scripts which starts its name with 'S'. So,
## Enable - symlink the file to 'S'*.
## Disable- unlink symlink
## ----------------------------------------------------------------------------
###############################################################################

OPTSPEC="volname:,version:,gd-workdir:,volume-op:"
PROGNAME="Quota-xattr-heal-add-brick-pre"
VOL_NAME=
GLUSTERD_WORKING_DIR=
VOLUME_OP=
VERSION=
ENABLED_NAME="S28Quota-root-xattr-heal.sh"
DISABLED_NAME="disabled-quota-root-xattr-heal.sh"

enable ()
{
        ln -sf $DISABLED_STATE $1;
}

##------------------------------------------
## Parse the arguments
##------------------------------------------
ARGS=$(getopt -l $OPTSPEC  -name $PROGNAME $@)
eval set -- "$ARGS"

while true;
do
        case $1 in
        --volname)
                 shift
                 VOL_NAME=$1
                 ;;
        --gd-workdir)
                 shift
                 GLUSTERD_WORKING_DIR=$1
                 ;;
        --volume-op)
                 shift
                 VOLUME_OP=$1
                 ;;
        --version)
                 shift
                 VERSION=$1
                 ;;
        *)
                 shift
                 break
                 ;;
        esac
        shift
done
##----------------------------------------

DISABLED_STATE="$GLUSTERD_WORKING_DIR/hooks/$VERSION/add-brick/post/$DISABLED_NAME"
ENABLED_STATE_START="$GLUSTERD_WORKING_DIR/hooks/$VERSION/start/post/$ENABLED_NAME"
ENABLED_STATE_ADD_BRICK="$GLUSTERD_WORKING_DIR/hooks/$VERSION/add-brick/post/$ENABLED_NAME";

## Why to proceed if the required script itself is not present?
ls $DISABLED_STATE;
if [ 0 -ne $? ]
then
        exit $?;
fi

## Is quota enabled?
FLAG=`cat $GLUSTERD_WORKING_DIR/vols/$VOL_NAME/info | grep "^features.quota=" \
      | awk -F'=' '{print $NF}'`;
if [ "$FLAG" != "on" ]
then
        exit $EXIT_SUCCESS;
fi

## Is volume started?
FLAG=`cat $GLUSTERD_WORKING_DIR/vols/$VOL_NAME/info | grep "^status=" \
      | awk -F'=' '{print $NF}'`;
if [ "$FLAG" != "1" ]
then
        enable $ENABLED_STATE_START;
        exit $?
fi

enable $ENABLED_STATE_ADD_BRICK;
exit $?