summaryrefslogtreecommitdiffstats
path: root/extras/hook-scripts/add-brick/post/disabled-quota-root-xattr-heal.sh
blob: 5f14333435853daa37acc342e3bf3c9872a73b8c (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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
#!/bin/sh

##---------------------------------------------------------------------------
## This script updates the 'limit-set' xattr on the newly added node. Please
## refer hook-scripts/add-brick/pre/S28Quota-root-xattr-heal.sh for the complete
## description.
## Do the following only if limit configured on root.
## 1. Do an auxiliary mount.
## 2. Get 'limit-set' xattr on root
## 3. Set xattrs with the same value on the root.
## 4. Disable itself
##---------------------------------------------------------------------------

QUOTA_CONFIG_XATTR="trusted.glusterfs.quota.limit-set";
MOUNT_DIR=`mktemp -d -t ${0##*/}.XXXXXX`;
OPTSPEC="volname:,version:,gd-workdir:,volume-op:"
PROGNAME="Quota-xattr-heal-add-brick"
VOL_NAME=
VERSION=
VOLUME_OP=
GLUSTERD_WORKDIR=
ENABLED_NAME="S28Quota-root-xattr-heal.sh"

cleanup_mountpoint ()
{
        umount -f $MOUNT_DIR;
        if [ 0 -ne $? ]
        then
                return $?
        fi

        rmdir $MOUNT_DIR;
        if [ 0 -ne $? ]
        then
                return $?
        fi
}

disable_and_exit ()
{
        if [ -e "$ENABLED_STATE" ]
        then
                unlink $ENABLED_STATE;
                exit $?
        fi

        exit 0
}

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

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

ENABLED_STATE="$GLUSTERD_WORKDIR/hooks/$VERSION/$VOLUME_OP/post/$ENABLED_NAME"

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

## -----------------------------------
## Mount the volume in temp directory.
## -----------------------------------
glusterfs -s localhost --volfile-id=$VOL_NAME --client-pid=-42 $MOUNT_DIR;
if [ 0 -ne $? ]
then
        exit $?;
fi
## -----------------------------------

## ------------------
## Getfattr the value
## ------------------
VALUE=$(getfattr -n $QUOTA_CONFIG_XATTR -e hex --absolute-names $MOUNT_DIR 2>&1)
RET=$?
if [ 0 -ne $RET ]
then
        ## Clean up and exit
        cleanup_mountpoint;

        echo $VALUE | grep -iq "No such attribute"
        if [ 0 -eq $? ]; then
                disable_and_exit
        fi

        exit $RET;
fi

VALUE=$(echo $VALUE | grep $QUOTA_CONFIG_XATTR | awk -F'=' '{print $NF}')
## ------------------

## ---------
## Set xattr
## ---------
setfattr -n "$QUOTA_CONFIG_XATTR" -v $VALUE $MOUNT_DIR;
RET=$?
if [ 0 -ne $RET ]
then
        ## Clean up and exit
        cleanup_mountpoint;

        exit $RET;
fi
## ---------

cleanup_mountpoint;
disable_and_exit;