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
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
|
function volinfo_field()
{
local vol=$1;
local field=$2;
$CLI volume info $vol | grep "^$field: " | sed 's/.*: //';
}
function volume_get_field()
{
local vol=$1
local field=$2
$CLI volume get $vol $field | tail -1 | awk '{print $2}'
}
function brick_count()
{
local vol=$1;
$CLI volume info $vol | egrep "^Brick[0-9]+: " | wc -l;
}
function online_brick_count ()
{
pgrep glusterfsd | wc -l
}
function brick_up_status {
local vol=$1
local host=$2
local brick=$3
$CLI volume status $vol $host:$brick --xml | sed -ne 's/.*<status>\([01]\)<\/status>/\1/p'
}
function volume_option()
{
local vol=$1
local key=$2
$CLI volume info $vol | egrep "^$key: " | cut -f2 -d' ';
}
function rebalance_status_field {
#The rebalance status can be upto 3 words, (ex:'fix-layout in progress'), hence the awk-print $7 thru $9.
#But if the status is less than 3 words, it also prints the next field i.e the run_time_in_secs.(ex:'completed 3.00').
#So we trim the numbers out with `tr`. Finally remove the trailing white spaces with sed. What we get is one of the
#strings in the 'cli_vol_task_status_str' char array of cli-rpc-ops.c
$CLI volume rebalance $1 status | awk '{print $7,$8,$9}' |sed -n 3p |tr -d '[^0-9+\.]'|sed 's/ *$//g'
}
function detach_tier_status_field {
$CLI volume tier $1 detach status | awk '{print $7,$8,$9}' |sed -n 3p |tr -d '[^0-9+\.]'|sed 's/ *$//g'
}
function remove_brick_status_completed_field {
local vol=$1
local brick_list=$2
$CLI volume remove-brick $vol $brick_list status | awk '{print $7}' | sed -n 3p
}
function get_mount_process_pid {
local vol=$1
ps auxww | grep glusterfs | grep -E "volfile-id[ =]/?$vol " | awk '{print $2}' | head -1
}
function get_nfs_pid ()
{
ps auxww | grep "volfile-id\ gluster\/nfs" | awk '{print $2}' | head -1
}
function read_nfs_pidfile ()
{
echo `cat $GLUSTERD_WORKDIR/nfs/run/nfs.pid`
}
function cleanup_statedump {
pid=$1
rm -f $statedumpdir/*$pid.dump.*
#.vimrc friendly comment */
}
function generate_statedump {
local fpath=""
pid=$1
#remove old stale statedumps
cleanup_statedump $pid
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 cleanup_mount_statedump {
local vol=$1
cleanup_statedump $(get_mount_process_pid $vol)
}
function snap_client_connected_status {
local vol=$1
local fpath=$(generate_mount_statedump $vol)
up=$(grep -a -A2 xlator.protocol.client.$vol-snapd-client.priv $fpath | tail -1 | cut -f 2 -d'=')
rm -f $fpath
echo "$up"
}
function _jbrc_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 -a -B1 child_$brick_id=$vol-client-$brick_id $fpath | head -1 | cut -f2 -d'=')
rm -f $fpath
echo "$up"
}
function jbrc_child_up_status {
local vol=$1
#brick_id is (brick-num in volume info - 1)
local brick_id=$2
_jbrc_child_up_status $vol $brick_id generate_mount_statedump
}
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 -a -B1 trusted.afr.$vol-client-$brick_id $fpath | head -1 | cut -f2 -d'=')
rm -f $fpath
echo "$up"
}
function afr_child_up_status_meta {
local mnt=$1
local repl=$2
local child=$3
grep "child_up\[$child\]" $mnt/.meta/graphs/active/$repl/private | awk '{print $3}'
}
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 ec_get_info {
local vol=$1
local dist_id=$2
local key=$3
local fpath=$4
local value=$(sed -n "/^\[cluster\/disperse\.$vol-disperse-$dist_id\]/,/^\[/{s/^$key=\(.*\)/\1/p;}" $fpath | head -1)
rm -f $fpath
echo "$value"
}
function ec_child_up_status {
local vol=$1
local dist_id=$2
local brick_id=$(($3 + 1))
local mask=$(ec_get_info $vol $dist_id "childs_up_mask" $(generate_mount_statedump $vol))
echo "${mask: -$brick_id:1}"
}
function ec_child_up_count {
local vol=$1
local dist_id=$2
ec_get_info $vol $dist_id "childs_up" $(generate_mount_statedump $vol)
}
function ec_child_up_status_shd {
local vol=$1
local dist_id=$2
local brick_id=$(($3 + 1))
local mask=$(ec_get_info $vol $dist_id "childs_up_mask" $(generate_shd_statedump $vol))
echo "${mask: -$brick_id:1}"
}
function ec_child_up_count_shd {
local vol=$1
local dist_id=$2
ec_get_info $vol $dist_id "childs_up" $(generate_shd_statedump $vol)
}
function get_shd_process_pid {
ps auxww | grep glusterfs | grep -E "glustershd/run/glustershd.pid" | awk '{print $2}' | head -1
}
function generate_shd_statedump {
generate_statedump $(get_shd_process_pid)
}
function generate_nfs_statedump {
generate_statedump $(get_nfs_pid)
}
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 afr_child_up_status_in_nfs {
local vol=$1
#brick_id is (brick-num in volume info - 1)
local brick_id=$2
_afr_child_up_status $vol $brick_id generate_nfs_statedump
}
function nfs_up_status {
gluster volume status | grep "NFS Server" | awk '{print $7}'
}
function glustershd_up_status {
gluster volume status | grep "Self-heal Daemon" | awk '{print $7}'
}
function quotad_up_status {
gluster volume status | grep "Quota Daemon" | awk '{print $7}'
}
function get_brick_pid {
local vol=$1
local host=$2
local brick=$3
local brick_hiphenated=$(echo $brick | tr '/' '-')
echo `cat $GLUSTERD_WORKDIR/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
local xval=$(getfattr -n $xkey -e hex $file 2>/dev/null | grep "$xkey" | cut -f2 -d'=')
if [ -z $xval ]; then
xval="0x000000000000000000000000"
fi
echo $xval
}
function 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_split_brain_count {
local vol=$1
gluster volume heal $vol info split-brain | grep "Number of entries in split-brain" | awk '{ sum+=$6} 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 get_text_xattr {
local key=$1
local path=$2
getfattr -d -m. -e text $path 2>/dev/null | grep -a $key | cut -f2 -d'='
}
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
}
function afr_get_specific_changelog_xattr ()
{
local path=$1
local key=$2
local type=$3
local specific_changelog=""
changelog_xattr=$(afr_get_changelog_xattr "$path" "$key")
if [ "$type" == "data" ]; then
specific_changelog=${changelog_xattr:2:8}
elif [ "$type" == "metadata" ]; then
specific_changelog=${changelog_xattr:10:8}
elif [ "$type" == "entry" ]; then
specific_changelog=${changelog_xattr:18:8}
else
specific_changlog="error"
fi
echo $specific_changelog
}
##
# query pathinfo xattr and extract POSIX pathname(s)
##
function get_backend_paths {
local path=$1
getfattr -m . -n trusted.glusterfs.pathinfo $path | tr ' ' '\n' | sed -n 's/<POSIX.*:.*:\(.*\)>.*/\1/p'
}
#Gets the xattr value in hex, also removed 0x in front of the value
function get_hex_xattr {
local key=$1
local path=$2
getfattr -d -m. -e hex $2 2>/dev/null | grep $1 | cut -f2 -d'=' | cut -f2 -d'x'
}
function cumulative_stat_count {
echo "$1" | grep "Cumulative Stats:" | wc -l
}
function incremental_stat_count {
echo "$1" | grep "Interval$2Stats:" | wc -l
}
function cleared_stat_count {
echo "$1" | grep "Cleared stats." | wc -l
}
function data_read_count {
echo "$1" | grep "Data Read:$2bytes" | wc -l
}
function data_written_count {
echo "$1" | grep "Data Written:$2bytes" | wc -l
}
function has_holes {
if [ $((`stat -c '%b*%B-%s' $1`)) -lt 0 ];
then
echo "1"
else
echo "0"
fi
}
function do_volume_operations() {
local operation=$1
local count=$2
local force=$3
local pids=()
local cli
local v
for i in `seq 1 $count`; do
cli="CLI_$i"
v="V`expr $i - 1`"
${!cli} volume $operation ${!v} $force &
pids[$i]=$!
done
for i in `seq 1 $count`; do
wait ${pids[$i]}
done
}
function start_volumes() {
do_volume_operations start $1
}
function stop_volumes() {
do_volume_operations stop $1
}
function start_force_volumes() {
do_volume_operations start $1 force
}
function stop_force_volumes() {
do_volume_operations stop $1 force
}
function delete_volumes() {
do_volume_operations delete $1
}
function volume_exists() {
$CLI volume info $1 > /dev/null 2>&1
if [ $? -eq 0 ]; then
echo "Y"
else
echo "N"
fi
}
function killall_gluster() {
pkill gluster
sleep 1
}
function afr_get_index_count {
local brick=$1
ls $1/.glusterfs/indices/xattrop | grep -v xattrop | wc -l
}
function landfill_entry_count {
local brick=$1
ls $brick/.glusterfs/landfill | wc -l
}
function path_exists {
stat $1
if [ $? -eq 0 ]; then echo "Y"; else echo "N"; fi
}
function force_umount {
${UMOUNT_F} $*
if [ $? -eq 0 ]; then echo "Y"; else echo "N"; fi
}
function assign_gfid {
local gfid=$1
local file=$2
setfattr -n trusted.gfid -v $1 $2
}
function get_random_gfid {
echo "0x"$(uuidgen | awk -F '-' 'BEGIN {OFS=""} {print $1,$2,$3,$4,$5}')
}
function volgen_volume_exists {
local volfile="$1"
local xl_vol="$2"
local xl_type="$3"
local xl_feature="$4"
xl=$(sed -e "/./{H;\$!d;}" -e "x;/volume $xl_vol/!d;/type $xl_type\/$xl_feature/!d" $volfile)
if [ -z "$xl" ];
then
echo "N"
else
echo "Y"
fi
}
function volgen_volume_option {
local volfile="$1"
local xl_vol="$2"
local xl_type="$3"
local xl_feature="$4"
local xl_option="$5"
sed -e "/./{H;\$!d;}" -e "x;/volume $xl_vol/!d;/type $xl_type\/$xl_feature/!d;/option $xl_option/!d" $volfile | grep " $xl_option " | awk '{print $3}'
}
function mount_get_option_value {
local m=$1
local subvol=$2
local key=$3
grep -w "$3" $m/.meta/graphs/active/$subvol/private | awk '{print $3}'
}
function get_volume_mark {
getfattr -n trusted.glusterfs.volume-mark -ehex $1 | sed -n 's/^trusted.glusterfs.volume-mark=0x//p' | cut -b5-36 | sed 's/\([a-f0-9]\{8\}\)\([a-f0-9]\{4\}\)\([a-f0-9]\{4\}\)\([a-f0-9]\{4\}\)/\1-\2-\3-\4-/'
}
# setup geo-rep in a single a node.
function setup_georep {
$CLI volume create $GMV0 replica 2 $H0:$B0/${GMV0}{1,2,3,4};
$CLI volume start $GMV0
$CLI volume create $GSV0 replica 2 $H0:$B0/${GSV0}{1,2,3,4};
$CLI volume start $GSV0
$CLI system:: execute gsec_create
$CLI volume geo-rep $GMV0 $H0::$GSV0 create push-pem
$CLI volume geo-rep $GMV0 $H0::$GSV0 start
sleep 80 # after start geo-rep takes a minute to get stable
}
# stop and delete geo-rep session
function cleanup_georep {
$CLI volume geo-rep $GMV0 $H0::$GSV0 stop
$CLI volume geo-rep $GMV0 $H0::$GSV0 delete
}
function num_graphs
{
local mountpoint=$1
echo `ls $mountpoint/.meta/graphs/ | grep -v active | wc -l`
}
function get_aux()
{
##Check if a auxiliary mount is there
df -h 2>&1 | sed 's#/build/install##' | grep -e "[[:space:]]/run/gluster/${V0}$" -e "[[:space:]]/var/run/gluster/${V0}$" -
if [ $? -eq 0 ]
then
echo "0"
else
echo "1"
fi
}
function get_bitd_count {
ps auxww | grep glusterfs | grep bitd.pid | grep -v grep | wc -l
}
function get_scrubd_count {
ps auxww | grep glusterfs | grep scrub.pid | grep -v grep | wc -l
}
function get_quotad_count {
ps auxww | grep glusterfs | grep quotad.pid | grep -v grep | wc -l
}
function get_nfs_count {
ps auxww | grep glusterfs | grep nfs.pid | grep -v grep | wc -l
}
function get_snapd_count {
ps auxww | grep glusterfs | grep snapd.pid | grep -v grep | wc -l
}
function drop_cache() {
case $OSTYPE in
Linux)
echo 3 > /proc/sys/vm/drop_caches
;;
*)
# fail but flush caches
( cd $1 && umount $1 2>/dev/null )
;;
esac
}
function quota_list_field () {
local QUOTA_PATH=$1
local FIELD=$2
local awk_arg="{print \$$FIELD}"
$CLI volume quota $V0 list $QUOTA_PATH | grep $QUOTA_PATH | awk "$awk_arg"
}
function quota_object_list_field () {
local QUOTA_PATH=$1
local FIELD=$2
local awk_arg="{print \$$FIELD}"
$CLI volume quota $V0 list-objects $QUOTA_PATH | grep $QUOTA_PATH | awk "$awk_arg"
}
function quotausage()
{
quota_list_field $1 4
}
function quota_hard_limit()
{
quota_list_field $1 2
}
function quota_soft_limit()
{
quota_list_field $1 3
}
function quota_sl_exceeded()
{
quota_list_field $1 6
}
function quota_hl_exceeded()
{
quota_list_field $1 7
}
function scrub_status()
{
local vol=$1;
local field=$2;
$CLI volume bitrot $vol scrub status | grep "^$field: " | sed 's/.*: //';
}
function get_gfid_string {
local path=$1;
getfattr -n glusterfs.gfid.string $1 2>/dev/null \
| grep glusterfs.gfid.string | cut -d '"' -f 2
}
function file_all_zeroes {
< $1 tr -d '\0' | read -n 1 || echo 1
}
|