glusterfs

Форк
0
/
dht.rc 
197 строк · 4.6 Кб
1
#!/bin/bash
2

3
dhthashdebugxattr="dht.file.hashed-subvol."
4

5
function get_layout()
6
{
7
        getfattr -n trusted.glusterfs.dht -e hex $1 2>&1 | grep dht | cut -d = -f2
8
}
9

10
## populates $BRICK1 and $BRICK2 with hashed/cached subvolume. These will be
11
## used by get_cached_brick and get_hashed_brick
12

13
function file_has_linkfile()
14
{
15
        k=0
16
        l=0
17
        while [ $k -lt $BRICK_COUNT ]
18
        do
19
                stat=$(stat $B0/${V0}$k/$1 2>/dev/null)
20
                if [ $? -eq 0 ]
21
                then
22
                        let l++
23
                        let "BRICK${l}=$k"
24

25
                fi
26
                let k++
27
        done
28
        return $l
29
}
30

31
function get_cached_brick()
32
{
33
        i=1
34
        brick=$BRICK1
35
        while [ $i -lt 3 ]
36
        do
37
                test=$(getfattr -n trusted.glusterfs.dht.linkto -e text $B0/${V0}$brick/$1 2>&1)
38
                if [ $? -eq 1 ]
39
                then
40
                        cached=$brick
41
                        i=$(( $i+3 ))
42
                fi
43
                brick=$BRICK1
44
                let i++
45
        done
46

47
        return $cached
48
}
49

50
function get_hashed_brick()
51
{
52
        j=1
53
        brick=$BRICK1
54
        while [ $j -lt 3 ]
55
        do
56
                test=$(getfattr -n trusted.glusterfs.dht.linkto -e text $B0/${V0}$brick/$1 2>&1)
57
                if [ $? -eq 0 ]
58
                then
59
                        hashed=$brick
60
                        j=$(( $j+3 ))
61
                fi
62
                brick=$BRICK2
63
                let j++
64
        done
65

66
        return $hashed
67
}
68

69

70
function cluster_rebalance_completed()
71
{
72
       val=1
73

74
       # Rebalance status will be either "failed" or "completed"
75

76
       test=$($CLI_1 volume rebalance $V0 status | grep "in progress" 2>&1)
77
       if [ $? -ne 0 ]
78
       then
79
               val=0
80
       fi
81

82
       echo $val
83
       # Do not *return* the value here.  If it's non-zero, that will cause
84
       # EXPECT_WITHIN (e.g. in bug-884455.t) to return prematurely, leading to
85
       # a spurious test failure.  Nothing else checks the return value anyway
86
       # (they all check the output) so there's no need for it to be non-zero
87
       # just because grep didn't find what we want.
88
}
89

90
function rebalance_completed()
91
{
92
       val=1
93
       test=$($CLI volume rebalance $V0 status | grep localhost | grep "completed" 2>&1)
94
       if [ $? -eq 0 ]
95
       then
96
               val=0
97
       fi
98

99
       echo $val
100
       # Do not *return* the value here.  If it's non-zero, that will cause
101
       # EXPECT_WITHIN (e.g. in bug-884455.t) to return prematurely, leading to
102
       # a spurious test failure.  Nothing else checks the return value anyway
103
       # (they all check the output) so there's no need for it to be non-zero
104
       # just because grep didn't find what we want.
105
}
106

107
function remove_brick_completed()
108
{
109
       val=1
110
       test=$(gluster volume remove-brick $V0 $H0:$B0/${V0}2 status | grep localhost | grep "completed" 2>&1)
111
       if [ $? -eq 0 ]
112
       then
113
                val=0
114
       fi
115

116
       echo $val
117
}
118

119
function dht_get_linkto_target()
120
{
121
        local path=$1;
122
        echo $(getfattr -e text --only-values --absolute-names -n trusted.glusterfs.dht.linkto $path)
123
}
124

125
function is_dht_linkfile()
126
{
127
        local path=$1
128
        retval=0
129
        local output=$(stat -c %a $path)
130
        if [ $output -eq 1000 ]; then
131
                 retval=1
132
        fi
133

134
        echo $retval
135
        return $retval
136
}
137

138

139
# Given an existing directory on the volume, get the hashed subvol for a file
140
# in that directory
141
# Input: filename dirpath_on_mount
142

143
function dht_get_hash_subvol()
144
{
145
        local hashed_subvol
146
        hashed_subvol=$(getfattr --only-values -n "$dhthashdebugxattr$1" $2 2>/dev/null)
147
        echo $hashed_subvol
148
}
149

150

151
# Find the first filename that hashes to the same subvol
152
# as $1
153
# Input: subvol_name dirpath_on_mount file_pattern
154

155
function dht_first_filename_with_hashsubvol()
156
{
157
        local in_subvol=$1
158
        local in_path=$2
159
        local in_hash_subvol
160
        local file_pattern=$3
161
        local filename
162

163
        for i in {1..50}
164
        do
165
               filename="$file_pattern$i"
166
               in_hash_subvol=$(dht_get_hash_subvol "$filename" "$in_path")
167
        #       echo $in_hash_subvol
168
               if [ "$in_subvol" == "$in_hash_subvol" ]; then
169
                        fn_return_val=$filename
170
                        return 0
171
               fi
172
        done
173
        return 1
174
}
175

176
function has_sticky_attr()
177
{
178
    local file="$1"
179
    if [ -k "$file" ]
180
    then
181
        echo "Y"
182
    else
183
        echo "N"
184
    fi
185
}
186

187
function has_sgid_attr()
188
{
189
    local file="$1"
190
#-g checks SGID bit. -k checks for sticky bit
191
    if [ -g "$file" ]
192
    then
193
        echo "Y"
194
    else
195
        echo "N"
196
    fi
197
}
198

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.