]> git.proxmox.com Git - ceph.git/blob - ceph/qa/workunits/fs/misc/rstats.sh
update sources to 12.2.7
[ceph.git] / ceph / qa / workunits / fs / misc / rstats.sh
1 #!/usr/bin/env bash
2
3 set -x
4
5 timeout=30
6 old_value=""
7 new_value=""
8
9 wait_until_changed() {
10 name=$1
11 wait=0
12 while [ $wait -lt $timeout ]; do
13 new_value=`getfattr --only-value -n ceph.dir.$name .`
14 [ $new_value == $old_value ] || return 0
15 sleep 1
16 wait=$(($wait + 1))
17 done
18 return 1
19 }
20
21 check_rctime() {
22 old_sec=$(echo $old_value | cut -d. -f1)
23 old_nsec=$(echo $old_value | cut -d. -f2)
24 new_sec=$(echo $new_value | cut -d. -f1)
25 new_nsec=$(echo $new_value | cut -d. -f2)
26 [ "$old_sec" -lt "$new_sec" ] && return 0
27 [ "$old_sec" -gt "$new_sec" ] && return 1
28 [ "$old_nsec" -lt "$new_nsec" ] && return 0
29 return 1
30 }
31
32 # sync(3) does not make ceph-fuse flush dirty caps, because fuse kernel module
33 # does not notify ceph-fuse about it. Use fsync(3) instead.
34 fsync_path() {
35 cmd="import os; fd=os.open(\"$1\", os.O_RDONLY); os.fsync(fd); os.close(fd)"
36 python -c "$cmd"
37 }
38
39 set -e
40
41 mkdir -p rstats_testdir/d1/d2
42 cd rstats_testdir
43
44 # rfiles
45 old_value=`getfattr --only-value -n ceph.dir.rfiles .`
46 [ $old_value == 0 ] || false
47 touch d1/d2/f1
48 wait_until_changed rfiles
49 [ $new_value == $(($old_value + 1)) ] || false
50
51 # rsubdirs
52 old_value=`getfattr --only-value -n ceph.dir.rsubdirs .`
53 [ $old_value == 3 ] || false
54 mkdir d1/d2/d3
55 wait_until_changed rsubdirs
56 [ $new_value == $(($old_value + 1)) ] || false
57
58 # rbytes
59 old_value=`getfattr --only-value -n ceph.dir.rbytes .`
60 [ $old_value == 0 ] || false
61 echo hello > d1/d2/f2
62 fsync_path d1/d2/f2
63 wait_until_changed rbytes
64 [ $new_value == $(($old_value + 6)) ] || false
65
66 #rctime
67 old_value=`getfattr --only-value -n ceph.dir.rctime .`
68 touch d1/d2/d3 # touch existing file
69 fsync_path d1/d2/d3
70 wait_until_changed rctime
71 check_rctime
72
73 old_value=`getfattr --only-value -n ceph.dir.rctime .`
74 touch d1/d2/f3 # create new file
75 wait_until_changed rctime
76 check_rctime
77
78 cd ..
79 rm -rf rstats_testdir
80 echo OK