3 . $(dirname $0)/../../standalone/ceph-helpers.sh
15 echo "usage: $0 [-h|-l|-t <testname> [-t <testname>...] [--no-sanity-check] [--no-cleanup]]"
18 function expect_false()
21 if "$@"; then return 1; else return 0; fi
24 function save_commit_position()
28 rados -p rbd getomapval journal.${journal} client_ \
29 $TMPDIR/${journal}.client_.omap
32 function restore_commit_position()
36 rados -p rbd setomapval journal.${journal} client_ \
37 < $TMPDIR/${journal}.client_.omap
42 local image=testrbdjournal$$
44 rbd create --image-feature exclusive-lock --image-feature journaling \
46 local journal=$(rbd info ${image} --format=xml 2>/dev/null |
47 $XMLSTARLET sel -t -v "//image/journal")
49 rbd journal info ${journal}
50 rbd journal info --journal ${journal}
51 rbd journal info --image ${image}
53 rbd feature disable ${image} journaling
55 rbd info ${image} --format=xml 2>/dev/null |
56 expect_false $XMLSTARLET sel -t -v "//image/journal"
57 expect_false rbd journal info ${journal}
58 expect_false rbd journal info --image ${image}
60 rbd feature enable ${image} journaling
62 local journal1=$(rbd info ${image} --format=xml 2>/dev/null |
63 $XMLSTARLET sel -t -v "//image/journal")
64 test "${journal}" = "${journal1}"
66 rbd journal info ${journal}
68 rbd journal status ${journal}
71 save_commit_position ${journal}
72 rbd bench-write ${image} --io-size 4096 --io-threads 1 \
73 --io-total $((4096 * count)) --io-pattern seq
74 rbd journal status --image ${image} | fgrep "tid=$((count - 1))"
75 restore_commit_position ${journal}
76 rbd journal status --image ${image} | fgrep "positions=[]"
77 local count1=$(rbd journal inspect --verbose ${journal} |
78 grep -c 'event_type.*AioWrite')
79 test "${count}" -eq "${count1}"
81 rbd journal export ${journal} $TMPDIR/journal.export
82 local size=$(stat -c "%s" $TMPDIR/journal.export)
85 rbd export ${image} $TMPDIR/${image}.export
87 local image1=${image}1
88 rbd create --image-feature exclusive-lock --image-feature journaling \
90 journal1=$(rbd info ${image1} --format=xml 2>/dev/null |
91 $XMLSTARLET sel -t -v "//image/journal")
93 save_commit_position ${journal1}
94 rbd journal import --dest ${image1} $TMPDIR/journal.export
95 rbd snap create ${image1}@test
96 restore_commit_position ${journal1}
97 # check that commit position is properly updated: the journal should contain
98 # 12 entries (10 AioWrite + 1 SnapCreate + 1 OpFinish) and commit
99 # position set to tid=11
100 rbd journal inspect --image ${image1} --verbose | awk '
101 /AioWrite/ {w++} # match: "event_type": "AioWrite",
102 /SnapCreate/ {s++} # match: "event_type": "SnapCreate",
103 /OpFinish/ {f++} # match: "event_type": "OpFinish",
104 /entries inspected/ {t=$1; e=$4} # match: 12 entries inspected, 0 errors
105 {print} # for diagnostic
107 if (w != 10 || s != 1 || f != 1 || t != 12 || e != 0) exit(1)
111 rbd export ${image1}@test $TMPDIR/${image1}.export
112 cmp $TMPDIR/${image}.export $TMPDIR/${image1}.export
114 rbd journal reset ${journal}
116 rbd journal inspect --verbose ${journal} | expect_false grep 'event_type'
118 rbd snap purge ${image1}
128 local expected_val=$4
130 local val=$(rbd --format xml ${cmd} --image ${image} |
131 $XMLSTARLET sel -t -v "${param}")
132 test "${val}" = "${expected_val}"
137 local image=testrbdcreate$$
139 rbd create --image-feature exclusive-lock --image-feature journaling \
141 --journal-object-size 20M \
142 --journal-splay-width 6 \
145 rbd_assert_eq ${image} 'journal info' '//journal/order' 25
146 rbd_assert_eq ${image} 'journal info' '//journal/splay_width' 6
147 rbd_assert_eq ${image} 'journal info' '//journal/object_pool' rbd
154 local src=testrbdcopys$$
155 rbd create --size 256 ${src}
157 local image=testrbdcopy$$
158 rbd copy --image-feature exclusive-lock --image-feature journaling \
160 --journal-object-size 20M \
161 --journal-splay-width 6 \
166 rbd_assert_eq ${image} 'journal info' '//journal/order' 25
167 rbd_assert_eq ${image} 'journal info' '//journal/splay_width' 6
168 rbd_assert_eq ${image} 'journal info' '//journal/object_pool' rbd
175 local parent=testrbdclonep$$
176 rbd create --image-feature layering --size 256 ${parent}
177 rbd snap create ${parent}@snap
178 rbd snap protect ${parent}@snap
180 local image=testrbdclone$$
181 rbd clone --image-feature layering --image-feature exclusive-lock --image-feature journaling \
183 --journal-object-size 20M \
184 --journal-splay-width 6 \
185 ${parent}@snap ${image}
187 rbd_assert_eq ${image} 'journal info' '//journal/order' 25
188 rbd_assert_eq ${image} 'journal info' '//journal/splay_width' 6
189 rbd_assert_eq ${image} 'journal info' '//journal/object_pool' rbd
192 rbd snap unprotect ${parent}@snap
193 rbd snap purge ${parent}
199 local src=testrbdimports$$
200 rbd create --size 256 ${src}
202 rbd export ${src} $TMPDIR/${src}.export
205 local image=testrbdimport$$
206 rbd import --image-feature exclusive-lock --image-feature journaling \
208 --journal-object-size 20M \
209 --journal-splay-width 6 \
210 $TMPDIR/${src}.export ${image}
212 rbd_assert_eq ${image} 'journal info' '//journal/order' 25
213 rbd_assert_eq ${image} 'journal info' '//journal/splay_width' 6
214 rbd_assert_eq ${image} 'journal info' '//journal/object_pool' rbd
221 local image=testrbdfeature$$
223 rbd create --image-feature exclusive-lock --size 256 ${image}
225 rbd feature enable ${image} journaling \
227 --journal-object-size 20M \
228 --journal-splay-width 6
230 rbd_assert_eq ${image} 'journal info' '//journal/order' 25
231 rbd_assert_eq ${image} 'journal info' '//journal/splay_width' 6
232 rbd_assert_eq ${image} 'journal info' '//journal/object_pool' rbd
237 TESTS+=" rbd_journal"
242 TESTS+=" rbd_feature"
253 while [[ $# -gt 0 ]]; do
260 "--no-sanity-check" )
268 if [[ -z "$1" ]]; then
269 echo "missing argument to '-t'"
283 if [[ $do_list -eq 1 ]]; then
288 TMPDIR=/tmp/rbd_journal$$
291 trap "rm -fr $TMPDIR" 0
294 if test -z "$tests_to_run" ; then
295 tests_to_run="$TESTS"
298 for i in $tests_to_run; do
299 if $sanity_check ; then
306 if $sanity_check ; then