summaryrefslogtreecommitdiffstats
path: root/tests/volume.rc
blob: 2a6ada3e6c8cac29dc540858f7ac7ec955fd6ab7 (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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
function volinfo_field()
{
    local vol=$1;
    local field=$2;

    $CLI volume info $vol | grep "^$field: " | sed 's/.*: //';
}


function brick_count()
{
    local vol=$1;

    $CLI volume info $vol | egrep "^Brick[0-9]+: " | wc -l;
}

function online_brick_count ()
{
    pidof glusterfsd | wc -w
}

function volume_option()
{
        local vol=$1
        local key=$2
        $CLI volume info $vol | egrep "^$key: " | cut -f2 -d' ';
}

function rebalance_status_field {
        $CLI volume rebalance $1 status | sed -n '$p' | cut -d' ' -f4
}

function remove_brick_status_completed_field {
        $CLI volume remove-brick $V0 $H0:$B0/r2d2_{4,5} status | awk '{print $6}' | sed -n 3p
}

function get_mount_process_pid {
        local vol=$1
        ps aux | grep glusterfs | grep -E "volfile-id[ =]/?$vol " | awk '{print $2}' | head -1
}

function generate_statedump {
        local fpath=""
        pid=$1
        #remove old stale statedumps
        rm -f "$statedumpdir/*$pid.dump.*"
        kill -USR1 $pid
        #Wait till the statedump is generated
        sleep 1
        fname=$(ls $statedumpdir | grep -E "*$pid.dump.*")
        echo $statedumpdir/$fname
}

function generate_mount_statedump {
        local vol=$1
        generate_statedump $(get_mount_process_pid $vol)
}

function _afr_child_up_status {
        local vol=$1
        #brick_id is (brick-num in volume info - 1)
        local brick_id=$2
        local gen_state_dump=$3
        local fpath=$($gen_state_dump $vol)
        up=$(grep -B1 trusted.afr.$vol-client-$brick_id $fpath | head -1 | cut -f2 -d'=')
        rm -f $fpath
        echo "$up"
}

function afr_child_up_status {
        local vol=$1
        #brick_id is (brick-num in volume info - 1)
        local brick_id=$2
        _afr_child_up_status $vol $brick_id generate_mount_statedump
}

function get_shd_process_pid {
        local vol=$1
        ps aux | grep glusterfs | grep -E "glustershd/run/glustershd.pid" | awk '{print $2}' | head -1
}

function generate_shd_statedump {
        local vol=$1
        generate_statedump $(get_shd_process_pid $vol)
}

function generate_brick_statedump {
        local vol=$1
        local host=$2
        local brick=$3
        generate_statedump $(get_brick_pid $vol $host $brick)
}

function afr_child_up_status_in_shd {
        local vol=$1
        #brick_id is (brick-num in volume info - 1)
        local brick_id=$2
        _afr_child_up_status $vol $brick_id generate_shd_statedump
}

function glustershd_up_status {
        gluster volume status | grep "Self-heal Daemon" | awk '{print $6}'
}

function get_brick_pid {
        local vol=$1
        local host=$2
        local brick=$3
        local brick_hiphenated=$(echo $brick | tr '/' '-')
        echo `cat /var/lib/glusterd/vols/$vol/run/${host}${brick_hiphenated}.pid`
}

function kill_brick {
        local vol=$1
        local host=$2
        local brick=$3
        kill -9 $(get_brick_pid $vol $host $brick)
}

function check_option_help_presence {
        local option=$1
        $CLI volume set help | grep "^Option:" | grep -w $option
}

function afr_get_changelog_xattr {
        local file=$1
        local xkey=$2
        getfattr -n $xkey -e hex $file 2>/dev/null | grep "client-" | cut -f2 -d'='
}

function afr_get_pending_heal_count {
        local vol=$1
        gluster volume heal $vol info | grep "Number of entries" | awk '{ sum+=$4} END {print sum}'
}

function afr_get_index_path {
        local brick_path=$1
        echo "$brick_path/.glusterfs/indices/xattrop"
}

function afr_get_num_indices_in_brick {
        local brick_path=$1
        echo $(ls $(afr_get_index_path $brick_path) | grep -v xattrop | wc -l)
}

function gf_get_gfid_xattr {
        file=$1
        getfattr -n trusted.gfid -e hex $file 2>/dev/null | grep "trusted.gfid" | cut -f2 -d'='
}

function gf_gfid_xattr_to_str {
        xval=$1
        echo "${xval:2:8}-${xval:10:4}-${xval:14:4}-${xval:18:4}-${xval:22:12}"
}

function gf_check_file_opened_in_brick {
        vol=$1
        host=$2
        brick=$3
        realpath=$4
        ls -l /proc/$(get_brick_pid $vol $host $brick)/fd | grep "${realpath}$" 2>&1 > /dev/null
        if [ $? -eq 0 ]; then
                echo "Y"
        else
                echo "N"
        fi
}

function gf_get_gfid_backend_file_path {
        brickpath=$1
        filepath_in_brick=$2
        gfid=$(gf_get_gfid_xattr "$brickpath/$filepath_in_brick")
        gfidstr=$(gf_gfid_xattr_to_str $gfid)
        echo "$brickpath/.glusterfs/${gfidstr:0:2}/${gfidstr:2:2}/$gfidstr"
}

function gf_rm_file_and_gfid_link {
        brickpath=$1
        filepath_in_brick=$2
        rm -f $(gf_get_gfid_backend_file_path $brickpath $filepath_in_brick)
        rm -f "$brickpath/$filepath_in_brick"
}


function gd_is_replace_brick_completed {
        local host=$1
        local vol=$2
        local src_brick=$3
        local dst_brick=$4
        $CLI volume replace-brick $vol $src_brick $dst_brick status | grep -i "Migration complete"
        if [ $? -eq 0 ]; then
                echo "Y"
        else
                echo "N"
        fi
}

function dht_get_layout {
	local my_xa=trusted.glusterfs.dht
	getfattr -d -e hex -n $my_xa $1 2> /dev/null | grep "$my_xa=" | cut -d= -f2
}