Fix some bugs when testing opensds ansible
[stor4nfv.git] / src / ceph / qa / workunits / fs / quota / quota.sh
1 #!/bin/bash
2
3 set -e
4 set -x
5
6 function expect_false()
7 {
8         set -x
9         if "$@"; then return 1; else return 0; fi
10 }
11
12 function write_file()
13 {
14         set +x
15         for ((i=1;i<=$2;i++))
16         do
17                 dd if=/dev/zero of=$1 bs=1M count=1 conv=notrunc oflag=append 2>/dev/null >/dev/null
18                 if [ $? != 0 ]; then
19                         echo Try to write $(($i * 1048576))
20                         set -x
21                         return 1
22                 fi
23                 sleep 0.05
24         done
25         set -x
26         return 0
27 }
28
29 mkdir quota-test
30 cd quota-test
31
32 # bytes
33 setfattr . -n ceph.quota.max_bytes -v 100000000  # 100m
34 expect_false write_file big 1000     # 1g
35 expect_false write_file second 10
36 setfattr . -n ceph.quota.max_bytes -v 0
37 dd if=/dev/zero of=third bs=1M count=10
38 dd if=/dev/zero of=big2 bs=1M count=100
39
40
41 rm -rf *
42
43 # files
44 setfattr . -n ceph.quota.max_files -v 5
45 mkdir ok
46 touch ok/1
47 touch ok/2
48 touch 3
49 expect_false touch shouldbefail     #  5 files will include the "."
50 expect_false touch ok/shouldbefail  #  5 files will include the "."
51 setfattr . -n ceph.quota.max_files -v 0
52 touch shouldbecreated
53 touch shouldbecreated2
54
55
56 rm -rf *
57
58 # mix
59 mkdir bytes bytes/files
60
61 setfattr bytes -n ceph.quota.max_bytes -v 10000000   #10m
62 setfattr bytes/files -n ceph.quota.max_files -v 5
63 dd if=/dev/zero of=bytes/files/1 bs=1M count=4
64 dd if=/dev/zero of=bytes/files/2 bs=1M count=4
65 expect_false write_file bytes/files/3 1000
66 expect_false write_file bytes/files/4 1000
67 expect_false write_file bytes/files/5 1000
68 stat --printf="%n %s\n" bytes/files/1 #4M
69 stat --printf="%n %s\n" bytes/files/2 #4M
70 stat --printf="%n %s\n" bytes/files/3 #bigger than 2M
71 stat --printf="%n %s\n" bytes/files/4 #should be zero
72 expect_false stat bytes/files/5       #shouldn't be exist
73
74
75
76
77 rm -rf *
78
79 #mv
80 mkdir files limit
81 truncate files/file -s 10G
82 setfattr limit -n ceph.quota.max_bytes -v 1000000 #1m
83 expect_false mv files limit/
84
85
86
87 rm -rf *
88
89 #limit by ancestor
90
91 mkdir -p ancestor/p1/p2/parent/p3
92 setfattr ancestor -n ceph.quota.max_bytes -v 1000000
93 setfattr ancestor/p1/p2/parent -n ceph.quota.max_bytes -v 1000000000 #1g
94 expect_false write_file ancestor/p1/p2/parent/p3/file1 900 #900m
95 stat --printf="%n %s\n" ancestor/p1/p2/parent/p3/file1
96
97
98 #get/set attribute
99
100 setfattr -n ceph.quota.max_bytes -v 0 .
101 setfattr -n ceph.quota.max_bytes -v 1 .
102 setfattr -n ceph.quota.max_bytes -v 9223372036854775807 .
103 expect_false setfattr -n ceph.quota.max_bytes -v 9223372036854775808 .
104 expect_false setfattr -n ceph.quota.max_bytes -v -1 .
105 expect_false setfattr -n ceph.quota.max_bytes -v -9223372036854775808 .
106 expect_false setfattr -n ceph.quota.max_bytes -v -9223372036854775809 .
107
108 setfattr -n ceph.quota.max_files -v 0 .
109 setfattr -n ceph.quota.max_files -v 1 .
110 setfattr -n ceph.quota.max_files -v 9223372036854775807 .
111 expect_false setfattr -n ceph.quota.max_files -v 9223372036854775808 .
112 expect_false setfattr -n ceph.quota.max_files -v -1 .
113 expect_false setfattr -n ceph.quota.max_files -v -9223372036854775808 .
114 expect_false setfattr -n ceph.quota.max_files -v -9223372036854775809 .
115
116 setfattr -n ceph.quota -v "max_bytes=0 max_files=0" .
117 setfattr -n ceph.quota -v "max_bytes=1 max_files=0" .
118 setfattr -n ceph.quota -v "max_bytes=0 max_files=1" .
119 setfattr -n ceph.quota -v "max_bytes=1 max_files=1" .
120 expect_false setfattr -n ceph.quota -v "max_bytes=-1 max_files=0" .
121 expect_false setfattr -n ceph.quota -v "max_bytes=0 max_files=-1" .
122 expect_false setfattr -n ceph.quota -v "max_bytes=-1 max_files=-1" .
123
124 #addme
125
126 cd ..
127 rm -rf quota-test
128
129 echo OK