3 # Copyright (C) 2015 Red Hat <contact@redhat.com>
5 # Author: David Zafman <dzafman@redhat.com>
7 # This program is free software; you can redistribute it and/or modify
8 # it under the terms of the GNU Library Public License as published by
9 # the Free Software Foundation; either version 2, or (at your option)
12 # This program is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU Library Public License for more details.
17 source $CEPH_ROOT/qa
/standalone
/ceph-helpers.sh
23 export CEPH_MON
="127.0.0.1:7121" # git grep '\<7121\>' : there must be only one
25 CEPH_ARGS
+="--fsid=$(uuidgen) --auth-supported=none "
26 CEPH_ARGS
+="--mon-host=$CEPH_MON "
28 local funcs
=${@:-$(set | sed -n -e 's/^\(TEST_[0-9a-z_]*\) .*/\1/p')}
29 for func
in $funcs ; do
30 $func $dir ||
return 1
34 function TEST_scrub_snaps
() {
38 TESTDATA
="testdata.$$"
40 setup
$dir ||
return 1
41 run_mon
$dir a
--osd_pool_default_size=1 ||
return 1
42 run_mgr
$dir x ||
return 1
43 run_osd
$dir 0 ||
return 1
45 create_rbd_pool ||
return 1
46 wait_for_clean ||
return 1
48 # Create a pool with a single pg
49 create_pool
$poolname 1 1
50 wait_for_clean ||
return 1
51 poolid
=$
(ceph osd dump |
grep "^pool.*[']test[']" |
awk '{ print $2 }')
53 dd if=/dev
/urandom of
=$TESTDATA bs
=1032 count
=1
56 rados
-p $poolname put obj
${i} $TESTDATA
60 rados
-p $poolname mksnap snap
${SNAP}
61 dd if=/dev
/urandom of
=$TESTDATA bs
=256 count
=${SNAP}
62 rados
-p $poolname put obj1
$TESTDATA
63 rados
-p $poolname put obj5
$TESTDATA
64 rados
-p $poolname put obj3
$TESTDATA
66 do rados
-p $poolname put obj
${i} $TESTDATA
70 rados
-p $poolname mksnap snap
${SNAP}
71 dd if=/dev
/urandom of
=$TESTDATA bs
=256 count
=${SNAP}
72 rados
-p $poolname put obj5
$TESTDATA
75 rados
-p $poolname mksnap snap
${SNAP}
76 dd if=/dev
/urandom of
=$TESTDATA bs
=256 count
=${SNAP}
77 rados
-p $poolname put obj3
$TESTDATA
80 rados
-p $poolname mksnap snap
${SNAP}
81 dd if=/dev
/urandom of
=$TESTDATA bs
=256 count
=${SNAP}
82 rados
-p $poolname put obj5
$TESTDATA
83 rados
-p $poolname put obj2
$TESTDATA
86 rados
-p $poolname mksnap snap
${SNAP}
88 rados
-p $poolname mksnap snap
${SNAP}
89 dd if=/dev
/urandom of
=$TESTDATA bs
=256 count
=${SNAP}
90 rados
-p $poolname put obj5
$TESTDATA
93 rados
-p $poolname mksnap snap
${SNAP}
95 rados
-p $poolname rm obj4
96 rados
-p $poolname rm obj2
98 kill_daemons
$dir TERM osd ||
return 1
100 # Don't need to ceph_objectstore_tool function because osd stopped
102 JSON
="$(ceph-objectstore-tool --data-path $dir/0 --journal-path $dir/0/journal --head --op list obj1)"
103 ceph-objectstore-tool
--data-path $dir/0 --journal-path $dir/0/journal
"$JSON" --force remove
105 JSON
="$(ceph-objectstore-tool --data-path $dir/0 --journal-path $dir/0/journal --op list obj5 | grep \"snapid\":2)"
106 ceph-objectstore-tool
--data-path $dir/0 --journal-path $dir/0/journal
"$JSON" remove
108 JSON
="$(ceph-objectstore-tool --data-path $dir/0 --journal-path $dir/0/journal --op list obj5 | grep \"snapid\":1)"
110 ceph-objectstore-tool
--data-path $dir/0 --journal-path $dir/0/journal
"$JSON" remove
112 JSON
="$(ceph-objectstore-tool --data-path $dir/0 --journal-path $dir/0/journal --op list obj5 | grep \"snapid\":4)"
113 dd if=/dev
/urandom of
=$TESTDATA bs
=256 count
=18
114 ceph-objectstore-tool
--data-path $dir/0 --journal-path $dir/0/journal
"$JSON" set-bytes
$TESTDATA
116 JSON
="$(ceph-objectstore-tool --data-path $dir/0 --journal-path $dir/0/journal --head --op list obj3)"
117 dd if=/dev
/urandom of
=$TESTDATA bs
=256 count
=15
118 ceph-objectstore-tool
--data-path $dir/0 --journal-path $dir/0/journal
"$JSON" set-bytes
$TESTDATA
120 JSON
="$(ceph-objectstore-tool --data-path $dir/0 --journal-path $dir/0/journal --op list obj4 | grep \"snapid\":7)"
121 ceph-objectstore-tool
--data-path $dir/0 --journal-path $dir/0/journal
"$JSON" remove
123 JSON
="$(ceph-objectstore-tool --data-path $dir/0 --journal-path $dir/0/journal --head --op list obj2)"
124 ceph-objectstore-tool
--data-path $dir/0 --journal-path $dir/0/journal
"$JSON" rm-attr snapset
126 # Create a clone which isn't in snapset and doesn't have object info
127 JSON
="$(echo "$OBJ5SAVE" | sed s/snapid\":1/snapid\":7/)"
128 dd if=/dev
/urandom of
=$TESTDATA bs
=256 count
=7
129 ceph-objectstore-tool
--data-path $dir/0 --journal-path $dir/0/journal
"$JSON" set-bytes
$TESTDATA
133 JSON
="$(ceph-objectstore-tool --data-path $dir/0 --journal-path $dir/0/journal --head --op list obj6)"
134 ceph-objectstore-tool
--data-path $dir/0 --journal-path $dir/0/journal
"$JSON" clear-snapset
135 JSON
="$(ceph-objectstore-tool --data-path $dir/0 --journal-path $dir/0/journal --head --op list obj7)"
136 ceph-objectstore-tool
--data-path $dir/0 --journal-path $dir/0/journal
"$JSON" clear-snapset corrupt
137 JSON
="$(ceph-objectstore-tool --data-path $dir/0 --journal-path $dir/0/journal --head --op list obj8)"
138 ceph-objectstore-tool
--data-path $dir/0 --journal-path $dir/0/journal
"$JSON" clear-snapset
seq
139 JSON
="$(ceph-objectstore-tool --data-path $dir/0 --journal-path $dir/0/journal --head --op list obj9)"
140 ceph-objectstore-tool
--data-path $dir/0 --journal-path $dir/0/journal
"$JSON" clear-snapset clone_size
141 JSON
="$(ceph-objectstore-tool --data-path $dir/0 --journal-path $dir/0/journal --head --op list obj10)"
142 ceph-objectstore-tool
--data-path $dir/0 --journal-path $dir/0/journal
"$JSON" clear-snapset clone_overlap
143 JSON
="$(ceph-objectstore-tool --data-path $dir/0 --journal-path $dir/0/journal --head --op list obj11)"
144 ceph-objectstore-tool
--data-path $dir/0 --journal-path $dir/0/journal
"$JSON" clear-snapset clones
145 JSON
="$(ceph-objectstore-tool --data-path $dir/0 --journal-path $dir/0/journal --head --op list obj12)"
146 ceph-objectstore-tool
--data-path $dir/0 --journal-path $dir/0/journal
"$JSON" clear-snapset
head
147 JSON
="$(ceph-objectstore-tool --data-path $dir/0 --journal-path $dir/0/journal --head --op list obj13)"
148 ceph-objectstore-tool
--data-path $dir/0 --journal-path $dir/0/journal
"$JSON" clear-snapset snaps
149 JSON
="$(ceph-objectstore-tool --data-path $dir/0 --journal-path $dir/0/journal --head --op list obj14)"
150 ceph-objectstore-tool
--data-path $dir/0 --journal-path $dir/0/journal
"$JSON" clear-snapset size
152 echo "garbage" > $dir/bad
153 JSON
="$(ceph-objectstore-tool --data-path $dir/0 --journal-path $dir/0/journal --head --op list obj15)"
154 ceph-objectstore-tool
--data-path $dir/0 --journal-path $dir/0/journal
"$JSON" set-attr snapset
$dir/bad
157 run_osd
$dir 0 ||
return 1
158 create_rbd_pool ||
return 1
159 wait_for_clean ||
return 1
161 local pgid
="${poolid}.0"
162 if ! pg_scrub
"$pgid" ; then
166 grep 'log_channel' $dir/osd
.0.log
168 rados list-inconsistent-pg
$poolname > $dir/json ||
return 1
170 test $
(jq
'. | length' $dir/json
) = "1" ||
return 1
172 test $
(jq
-r '.[0]' $dir/json
) = $pgid ||
return 1
174 rados list-inconsistent-snapset
$pgid > $dir/json ||
return 1
175 test $
(jq
'.inconsistents | length' $dir/json
) = "21" ||
return 1
177 local jqfilter
='.inconsistents'
178 local sortkeys
='import json; import sys ; JSON=sys.stdin.read() ; ud = json.loads(JSON) ; print json.dumps(ud, sort_keys=True, indent=2)'
180 jq
"$jqfilter" << EOF | python -c "$sortkeys" > $dir/checkcsjson
404 jq
"$jqfilter" $dir/json | python
-c "$sortkeys" > $dir/csjson
405 diff ${DIFFCOLOPTS} $dir/checkcsjson
$dir/csjson ||
return 1
407 if which jsonschema
> /dev
/null
;
409 jsonschema
-i $dir/json
$CEPH_ROOT/doc
/rados
/command
/list-inconsistent-snap.json ||
return 1
414 rados
-p $poolname rmsnap snap
$i
419 pidfile
=$
(find $dir 2>/dev
/null |
grep $name_prefix'[^/]*\.pid')
423 echo "OSD crash occurred"
424 tail -100 $dir/osd
.0.log
425 ERRORS
=$
(expr $ERRORS + 1)
428 kill_daemons
$dir ||
return 1
430 declare -a err_strings
431 err_strings
[0]="log_channel[(]cluster[)] log [[]ERR[]] : scrub [0-9]*[.]0 .*::obj10:.* is missing in clone_overlap"
432 err_strings
[1]="log_channel[(]cluster[)] log [[]ERR[]] : scrub [0-9]*[.]0 .*::obj5:7 no '_' attr"
433 err_strings
[2]="log_channel[(]cluster[)] log [[]ERR[]] : scrub [0-9]*[.]0 .*::obj5:7 is an unexpected clone"
434 err_strings
[3]="log_channel[(]cluster[)] log [[]ERR[]] : scrub [0-9]*[.]0 .*::obj5:4 on disk size [(]4608[)] does not match object info size [(]512[)] adjusted for ondisk to [(]512[)]"
435 err_strings
[4]="log_channel[(]cluster[)] log [[]ERR[]] : scrub [0-9]*[.]0 .*:::obj5:head expected clone .*:::obj5:2"
436 err_strings
[5]="log_channel[(]cluster[)] log [[]ERR[]] : scrub [0-9]*[.]0 .*:::obj5:head expected clone .*:::obj5:1"
437 err_strings
[6]="log_channel[(]cluster[)] log [[]INF[]] : scrub [0-9]*[.]0 .*:::obj5:head 2 missing clone[(]s[)]"
438 err_strings
[7]="log_channel[(]cluster[)] log [[]ERR[]] : scrub [0-9]*[.]0 .*:::obj12:head snapset.head_exists=false, but head exists"
439 err_strings
[8]="log_channel[(]cluster[)] log [[]ERR[]] : scrub [0-9]*[.]0 .*:::obj8:head snaps.seq not set"
440 err_strings
[9]="log_channel[(]cluster[)] log [[]ERR[]] : scrub [0-9]*[.]0 .*:::obj7:head snapset.head_exists=false, but head exists"
441 err_strings
[10]="log_channel[(]cluster[)] log [[]ERR[]] : scrub [0-9]*[.]0 .*:::obj7:1 is an unexpected clone"
442 err_strings
[11]="log_channel[(]cluster[)] log [[]ERR[]] : scrub [0-9]*[.]0 .*:::obj3:head on disk size [(]3840[)] does not match object info size [(]768[)] adjusted for ondisk to [(]768[)]"
443 err_strings
[12]="log_channel[(]cluster[)] log [[]ERR[]] : scrub [0-9]*[.]0 .*:::obj6:1 is an unexpected clone"
444 err_strings
[13]="log_channel[(]cluster[)] log [[]ERR[]] : scrub [0-9]*[.]0 .*:::obj2:head no 'snapset' attr"
445 err_strings
[14]="log_channel[(]cluster[)] log [[]ERR[]] : scrub [0-9]*[.]0 .*:::obj2:7 clone ignored due to missing snapset"
446 err_strings
[15]="log_channel[(]cluster[)] log [[]ERR[]] : scrub [0-9]*[.]0 .*:::obj2:4 clone ignored due to missing snapset"
447 err_strings
[16]="log_channel[(]cluster[)] log [[]ERR[]] : scrub [0-9]*[.]0 .*:::obj4:head expected clone .*:::obj4:7"
448 err_strings
[17]="log_channel[(]cluster[)] log [[]INF[]] : scrub [0-9]*[.]0 .*:::obj4:head 1 missing clone[(]s[)]"
449 err_strings
[18]="log_channel[(]cluster[)] log [[]ERR[]] : scrub [0-9]*[.]0 .*:::obj1:1 is an unexpected clone"
450 err_strings
[19]="log_channel[(]cluster[)] log [[]ERR[]] : scrub [0-9]*[.]0 .*:::obj9:1 is missing in clone_size"
451 err_strings
[20]="log_channel[(]cluster[)] log [[]ERR[]] : scrub [0-9]*[.]0 .*:::obj11:1 is an unexpected clone"
452 err_strings
[21]="log_channel[(]cluster[)] log [[]ERR[]] : scrub [0-9]*[.]0 .*:::obj14:1 size 1032 != clone_size 1033"
453 err_strings
[22]="log_channel[(]cluster[)] log [[]ERR[]] : [0-9]*[.]0 scrub 22 errors"
454 err_strings
[23]="log_channel[(]cluster[)] log [[]ERR[]] : scrub [0-9]*[.]0 .*:::obj15:head can't decode 'snapset' attr buffer"
456 for err_string
in "${err_strings[@]}"
458 if ! grep "$err_string" $dir/osd
.0.log
> /dev
/null
;
460 echo "Missing log message '$err_string'"
461 ERRORS
=$
(expr $ERRORS + 1)
465 teardown
$dir ||
return 1
467 if [ $ERRORS != "0" ];
469 echo "TEST FAILED WITH $ERRORS ERRORS"
477 main osd-scrub-snaps
"$@"
480 # compile-command: "cd ../.. ; make -j4 && \
481 # test/osd/osd-scrub-snaps.sh"