]> git.proxmox.com Git - ceph.git/blob - ceph/qa/workunits/rbd/journal.sh
update sources to ceph Nautilus 14.2.1
[ceph.git] / ceph / qa / workunits / rbd / journal.sh
1 #!/usr/bin/env bash
2 set -e
3
4 . $(dirname $0)/../../standalone/ceph-helpers.sh
5
6 function list_tests()
7 {
8 echo "AVAILABLE TESTS"
9 for i in $TESTS; do
10 echo " $i"
11 done
12 }
13
14 function usage()
15 {
16 echo "usage: $0 [-h|-l|-t <testname> [-t <testname>...] [--no-cleanup]]"
17 }
18
19 function expect_false()
20 {
21 set -x
22 if "$@"; then return 1; else return 0; fi
23 }
24
25 function save_commit_position()
26 {
27 local journal=$1
28
29 rados -p rbd getomapval journal.${journal} client_ \
30 $TMPDIR/${journal}.client_.omap
31 }
32
33 function restore_commit_position()
34 {
35 local journal=$1
36
37 rados -p rbd setomapval journal.${journal} client_ \
38 < $TMPDIR/${journal}.client_.omap
39 }
40
41 test_rbd_journal()
42 {
43 local image=testrbdjournal$$
44
45 rbd create --image-feature exclusive-lock --image-feature journaling \
46 --size 128 ${image}
47 local journal=$(rbd info ${image} --format=xml 2>/dev/null |
48 $XMLSTARLET sel -t -v "//image/journal")
49 test -n "${journal}"
50 rbd journal info ${journal}
51 rbd journal info --journal ${journal}
52 rbd journal info --image ${image}
53
54 rbd feature disable ${image} journaling
55
56 rbd info ${image} --format=xml 2>/dev/null |
57 expect_false $XMLSTARLET sel -t -v "//image/journal"
58 expect_false rbd journal info ${journal}
59 expect_false rbd journal info --image ${image}
60
61 rbd feature enable ${image} journaling
62
63 local journal1=$(rbd info ${image} --format=xml 2>/dev/null |
64 $XMLSTARLET sel -t -v "//image/journal")
65 test "${journal}" = "${journal1}"
66
67 rbd journal info ${journal}
68
69 rbd journal status ${journal}
70
71 local count=10
72 save_commit_position ${journal}
73 rbd bench --io-type write ${image} --io-size 4096 --io-threads 1 \
74 --io-total $((4096 * count)) --io-pattern seq
75 rbd journal status --image ${image} | fgrep "tid=$((count - 1))"
76 restore_commit_position ${journal}
77 rbd journal status --image ${image} | fgrep "positions=[]"
78 local count1=$(rbd journal inspect --verbose ${journal} |
79 grep -c 'event_type.*AioWrite')
80 test "${count}" -eq "${count1}"
81
82 rbd journal export ${journal} $TMPDIR/journal.export
83 local size=$(stat -c "%s" $TMPDIR/journal.export)
84 test "${size}" -gt 0
85
86 rbd export ${image} $TMPDIR/${image}.export
87
88 local image1=${image}1
89 rbd create --image-feature exclusive-lock --image-feature journaling \
90 --size 128 ${image1}
91 journal1=$(rbd info ${image1} --format=xml 2>/dev/null |
92 $XMLSTARLET sel -t -v "//image/journal")
93
94 save_commit_position ${journal1}
95 rbd journal import --dest ${image1} $TMPDIR/journal.export
96 rbd snap create ${image1}@test
97 restore_commit_position ${journal1}
98 # check that commit position is properly updated: the journal should contain
99 # 14 entries (2 AioFlush + 10 AioWrite + 1 SnapCreate + 1 OpFinish) and
100 # commit position set to tid=14
101 rbd journal inspect --image ${image1} --verbose | awk '
102 /AioFlush/ {a++} # match: "event_type": "AioFlush",
103 /AioWrite/ {w++} # match: "event_type": "AioWrite",
104 /SnapCreate/ {s++} # match: "event_type": "SnapCreate",
105 /OpFinish/ {f++} # match: "event_type": "OpFinish",
106 /entries inspected/ {t=$1; e=$4} # match: 14 entries inspected, 0 errors
107 {print} # for diagnostic
108 END {
109 if (a != 2 || w != 10 || s != 1 || f != 1 || t != 14 || e != 0) exit(1)
110 }
111 '
112
113 rbd export ${image1}@test $TMPDIR/${image1}.export
114 cmp $TMPDIR/${image}.export $TMPDIR/${image1}.export
115
116 rbd journal reset ${journal}
117
118 rbd journal inspect --verbose ${journal} | expect_false grep 'event_type'
119
120 rbd snap purge ${image1}
121 rbd remove ${image1}
122 rbd remove ${image}
123 }
124
125
126 rbd_assert_eq() {
127 local image=$1
128 local cmd=$2
129 local param=$3
130 local expected_val=$4
131
132 local val=$(rbd --format xml ${cmd} --image ${image} |
133 $XMLSTARLET sel -t -v "${param}")
134 test "${val}" = "${expected_val}"
135 }
136
137 test_rbd_create()
138 {
139 local image=testrbdcreate$$
140
141 rbd create --image-feature exclusive-lock --image-feature journaling \
142 --journal-pool rbd \
143 --journal-object-size 20M \
144 --journal-splay-width 6 \
145 --size 256 ${image}
146
147 rbd_assert_eq ${image} 'journal info' '//journal/order' 25
148 rbd_assert_eq ${image} 'journal info' '//journal/splay_width' 6
149 rbd_assert_eq ${image} 'journal info' '//journal/object_pool' rbd
150
151 rbd remove ${image}
152 }
153
154 test_rbd_copy()
155 {
156 local src=testrbdcopys$$
157 rbd create --size 256 ${src}
158
159 local image=testrbdcopy$$
160 rbd copy --image-feature exclusive-lock --image-feature journaling \
161 --journal-pool rbd \
162 --journal-object-size 20M \
163 --journal-splay-width 6 \
164 ${src} ${image}
165
166 rbd remove ${src}
167
168 rbd_assert_eq ${image} 'journal info' '//journal/order' 25
169 rbd_assert_eq ${image} 'journal info' '//journal/splay_width' 6
170 rbd_assert_eq ${image} 'journal info' '//journal/object_pool' rbd
171
172 rbd remove ${image}
173 }
174
175 test_rbd_deep_copy()
176 {
177 local src=testrbdcopys$$
178 rbd create --size 256 ${src}
179 rbd snap create ${src}@snap1
180
181 local dest=testrbdcopy$$
182 rbd deep copy --image-feature exclusive-lock --image-feature journaling \
183 --journal-pool rbd \
184 --journal-object-size 20M \
185 --journal-splay-width 6 \
186 ${src} ${dest}
187
188 rbd snap purge ${src}
189 rbd remove ${src}
190
191 rbd_assert_eq ${dest} 'journal info' '//journal/order' 25
192 rbd_assert_eq ${dest} 'journal info' '//journal/splay_width' 6
193 rbd_assert_eq ${dest} 'journal info' '//journal/object_pool' rbd
194
195 rbd snap purge ${dest}
196 rbd remove ${dest}
197 }
198
199 test_rbd_clone()
200 {
201 local parent=testrbdclonep$$
202 rbd create --image-feature layering --size 256 ${parent}
203 rbd snap create ${parent}@snap
204 rbd snap protect ${parent}@snap
205
206 local image=testrbdclone$$
207 rbd clone --image-feature layering --image-feature exclusive-lock --image-feature journaling \
208 --journal-pool rbd \
209 --journal-object-size 20M \
210 --journal-splay-width 6 \
211 ${parent}@snap ${image}
212
213 rbd_assert_eq ${image} 'journal info' '//journal/order' 25
214 rbd_assert_eq ${image} 'journal info' '//journal/splay_width' 6
215 rbd_assert_eq ${image} 'journal info' '//journal/object_pool' rbd
216
217 rbd remove ${image}
218 rbd snap unprotect ${parent}@snap
219 rbd snap purge ${parent}
220 rbd remove ${parent}
221 }
222
223 test_rbd_import()
224 {
225 local src=testrbdimports$$
226 rbd create --size 256 ${src}
227
228 rbd export ${src} $TMPDIR/${src}.export
229 rbd remove ${src}
230
231 local image=testrbdimport$$
232 rbd import --image-feature exclusive-lock --image-feature journaling \
233 --journal-pool rbd \
234 --journal-object-size 20M \
235 --journal-splay-width 6 \
236 $TMPDIR/${src}.export ${image}
237
238 rbd_assert_eq ${image} 'journal info' '//journal/order' 25
239 rbd_assert_eq ${image} 'journal info' '//journal/splay_width' 6
240 rbd_assert_eq ${image} 'journal info' '//journal/object_pool' rbd
241
242 rbd remove ${image}
243 }
244
245 test_rbd_feature()
246 {
247 local image=testrbdfeature$$
248
249 rbd create --image-feature exclusive-lock --size 256 ${image}
250
251 rbd feature enable ${image} journaling \
252 --journal-pool rbd \
253 --journal-object-size 20M \
254 --journal-splay-width 6
255
256 rbd_assert_eq ${image} 'journal info' '//journal/order' 25
257 rbd_assert_eq ${image} 'journal info' '//journal/splay_width' 6
258 rbd_assert_eq ${image} 'journal info' '//journal/object_pool' rbd
259
260 rbd remove ${image}
261 }
262
263 TESTS+=" rbd_journal"
264 TESTS+=" rbd_create"
265 TESTS+=" rbd_copy"
266 TESTS+=" rbd_clone"
267 TESTS+=" rbd_import"
268 TESTS+=" rbd_feature"
269
270 #
271 # "main" follows
272 #
273
274 tests_to_run=()
275
276 cleanup=true
277
278 while [[ $# -gt 0 ]]; do
279 opt=$1
280
281 case "$opt" in
282 "-l" )
283 do_list=1
284 ;;
285 "--no-cleanup" )
286 cleanup=false
287 ;;
288 "-t" )
289 shift
290 if [[ -z "$1" ]]; then
291 echo "missing argument to '-t'"
292 usage ;
293 exit 1
294 fi
295 tests_to_run+=" $1"
296 ;;
297 "-h" )
298 usage ;
299 exit 0
300 ;;
301 esac
302 shift
303 done
304
305 if [[ $do_list -eq 1 ]]; then
306 list_tests ;
307 exit 0
308 fi
309
310 TMPDIR=/tmp/rbd_journal$$
311 mkdir $TMPDIR
312 if $cleanup; then
313 trap "rm -fr $TMPDIR" 0
314 fi
315
316 if test -z "$tests_to_run" ; then
317 tests_to_run="$TESTS"
318 fi
319
320 for i in $tests_to_run; do
321 set -x
322 test_${i}
323 set +x
324 done
325
326 echo OK