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 ceph osd pool create
$poolname 1 1
50 poolid
=$
(ceph osd dump |
grep "^pool.*[']test[']" |
awk '{ print $2 }')
52 dd if=/dev
/urandom of
=$TESTDATA bs
=1032 count
=1
55 rados
-p $poolname put obj
${i} $TESTDATA
59 rados
-p $poolname mksnap snap
${SNAP}
60 dd if=/dev
/urandom of
=$TESTDATA bs
=256 count
=${SNAP}
61 rados
-p $poolname put obj1
$TESTDATA
62 rados
-p $poolname put obj5
$TESTDATA
63 rados
-p $poolname put obj3
$TESTDATA
65 do rados
-p $poolname put obj
${i} $TESTDATA
69 rados
-p $poolname mksnap snap
${SNAP}
70 dd if=/dev
/urandom of
=$TESTDATA bs
=256 count
=${SNAP}
71 rados
-p $poolname put obj5
$TESTDATA
74 rados
-p $poolname mksnap snap
${SNAP}
75 dd if=/dev
/urandom of
=$TESTDATA bs
=256 count
=${SNAP}
76 rados
-p $poolname put obj3
$TESTDATA
79 rados
-p $poolname mksnap snap
${SNAP}
80 dd if=/dev
/urandom of
=$TESTDATA bs
=256 count
=${SNAP}
81 rados
-p $poolname put obj5
$TESTDATA
82 rados
-p $poolname put obj2
$TESTDATA
85 rados
-p $poolname mksnap snap
${SNAP}
87 rados
-p $poolname mksnap snap
${SNAP}
88 dd if=/dev
/urandom of
=$TESTDATA bs
=256 count
=${SNAP}
89 rados
-p $poolname put obj5
$TESTDATA
92 rados
-p $poolname mksnap snap
${SNAP}
94 rados
-p $poolname rm obj4
95 rados
-p $poolname rm obj2
97 kill_daemons
$dir TERM osd ||
return 1
99 # Don't need to ceph_objectstore_tool function because osd stopped
101 JSON
="$(ceph-objectstore-tool --data-path $dir/0 --journal-path $dir/0/journal --head --op list obj1)"
102 ceph-objectstore-tool
--data-path $dir/0 --journal-path $dir/0/journal
"$JSON" --force remove
104 JSON
="$(ceph-objectstore-tool --data-path $dir/0 --journal-path $dir/0/journal --op list obj5 | grep \"snapid\":2)"
105 ceph-objectstore-tool
--data-path $dir/0 --journal-path $dir/0/journal
"$JSON" remove
107 JSON
="$(ceph-objectstore-tool --data-path $dir/0 --journal-path $dir/0/journal --op list obj5 | grep \"snapid\":1)"
109 ceph-objectstore-tool
--data-path $dir/0 --journal-path $dir/0/journal
"$JSON" remove
111 JSON
="$(ceph-objectstore-tool --data-path $dir/0 --journal-path $dir/0/journal --op list obj5 | grep \"snapid\":4)"
112 dd if=/dev
/urandom of
=$TESTDATA bs
=256 count
=18
113 ceph-objectstore-tool
--data-path $dir/0 --journal-path $dir/0/journal
"$JSON" set-bytes
$TESTDATA
115 JSON
="$(ceph-objectstore-tool --data-path $dir/0 --journal-path $dir/0/journal --head --op list obj3)"
116 dd if=/dev
/urandom of
=$TESTDATA bs
=256 count
=15
117 ceph-objectstore-tool
--data-path $dir/0 --journal-path $dir/0/journal
"$JSON" set-bytes
$TESTDATA
119 JSON
="$(ceph-objectstore-tool --data-path $dir/0 --journal-path $dir/0/journal --op list obj4 | grep \"snapid\":7)"
120 ceph-objectstore-tool
--data-path $dir/0 --journal-path $dir/0/journal
"$JSON" remove
122 JSON
="$(ceph-objectstore-tool --data-path $dir/0 --journal-path $dir/0/journal --head --op list obj2)"
123 ceph-objectstore-tool
--data-path $dir/0 --journal-path $dir/0/journal
"$JSON" rm-attr snapset
125 # Create a clone which isn't in snapset and doesn't have object info
126 JSON
="$(echo "$OBJ5SAVE" | sed s/snapid\":1/snapid\":7/)"
127 dd if=/dev
/urandom of
=$TESTDATA bs
=256 count
=7
128 ceph-objectstore-tool
--data-path $dir/0 --journal-path $dir/0/journal
"$JSON" set-bytes
$TESTDATA
132 JSON
="$(ceph-objectstore-tool --data-path $dir/0 --journal-path $dir/0/journal --head --op list obj6)"
133 ceph-objectstore-tool
--data-path $dir/0 --journal-path $dir/0/journal
"$JSON" clear-snapset
134 JSON
="$(ceph-objectstore-tool --data-path $dir/0 --journal-path $dir/0/journal --head --op list obj7)"
135 ceph-objectstore-tool
--data-path $dir/0 --journal-path $dir/0/journal
"$JSON" clear-snapset corrupt
136 JSON
="$(ceph-objectstore-tool --data-path $dir/0 --journal-path $dir/0/journal --head --op list obj8)"
137 ceph-objectstore-tool
--data-path $dir/0 --journal-path $dir/0/journal
"$JSON" clear-snapset
seq
138 JSON
="$(ceph-objectstore-tool --data-path $dir/0 --journal-path $dir/0/journal --head --op list obj9)"
139 ceph-objectstore-tool
--data-path $dir/0 --journal-path $dir/0/journal
"$JSON" clear-snapset clone_size
140 JSON
="$(ceph-objectstore-tool --data-path $dir/0 --journal-path $dir/0/journal --head --op list obj10)"
141 ceph-objectstore-tool
--data-path $dir/0 --journal-path $dir/0/journal
"$JSON" clear-snapset clone_overlap
142 JSON
="$(ceph-objectstore-tool --data-path $dir/0 --journal-path $dir/0/journal --head --op list obj11)"
143 ceph-objectstore-tool
--data-path $dir/0 --journal-path $dir/0/journal
"$JSON" clear-snapset clones
144 JSON
="$(ceph-objectstore-tool --data-path $dir/0 --journal-path $dir/0/journal --head --op list obj12)"
145 ceph-objectstore-tool
--data-path $dir/0 --journal-path $dir/0/journal
"$JSON" clear-snapset
head
146 JSON
="$(ceph-objectstore-tool --data-path $dir/0 --journal-path $dir/0/journal --head --op list obj13)"
147 ceph-objectstore-tool
--data-path $dir/0 --journal-path $dir/0/journal
"$JSON" clear-snapset snaps
148 JSON
="$(ceph-objectstore-tool --data-path $dir/0 --journal-path $dir/0/journal --head --op list obj14)"
149 ceph-objectstore-tool
--data-path $dir/0 --journal-path $dir/0/journal
"$JSON" clear-snapset size
151 echo "garbage" > $dir/bad
152 JSON
="$(ceph-objectstore-tool --data-path $dir/0 --journal-path $dir/0/journal --head --op list obj15)"
153 ceph-objectstore-tool
--data-path $dir/0 --journal-path $dir/0/journal
"$JSON" set-attr snapset
$dir/bad
156 run_osd
$dir 0 ||
return 1
157 create_rbd_pool ||
return 1
158 wait_for_clean ||
return 1
160 local pgid
="${poolid}.0"
161 if ! pg_scrub
"$pgid" ; then
165 grep 'log_channel' $dir/osd
.0.log
167 rados list-inconsistent-pg
$poolname > $dir/json ||
return 1
169 test $
(jq
'. | length' $dir/json
) = "1" ||
return 1
171 test $
(jq
-r '.[0]' $dir/json
) = $pgid ||
return 1
173 rados list-inconsistent-snapset
$pgid > $dir/json ||
return 1
174 test $
(jq
'.inconsistents | length' $dir/json
) = "21" ||
return 1
176 local jqfilter
='.inconsistents'
177 local sortkeys
='import json; import sys ; JSON=sys.stdin.read() ; ud = json.loads(JSON) ; print json.dumps(ud, sort_keys=True, indent=2)'
179 jq
"$jqfilter" << EOF | python -c "$sortkeys" > $dir/checkcsjson
403 jq
"$jqfilter" $dir/json | python
-c "$sortkeys" > $dir/csjson
404 diff ${DIFFCOLOPTS} $dir/checkcsjson
$dir/csjson ||
return 1
406 if which jsonschema
> /dev
/null
;
408 jsonschema
-i $dir/json
$CEPH_ROOT/doc
/rados
/command
/list-inconsistent-snap.json ||
return 1
413 rados
-p $poolname rmsnap snap
$i
418 pidfile
=$
(find $dir 2>/dev
/null |
grep $name_prefix'[^/]*\.pid')
422 echo "OSD crash occurred"
423 tail -100 $dir/osd
.0.log
424 ERRORS
=$
(expr $ERRORS + 1)
427 kill_daemons
$dir ||
return 1
429 declare -a err_strings
430 err_strings
[0]="log_channel[(]cluster[)] log [[]ERR[]] : scrub [0-9]*[.]0 .*::obj10:.* is missing in clone_overlap"
431 err_strings
[1]="log_channel[(]cluster[)] log [[]ERR[]] : scrub [0-9]*[.]0 .*::obj5:7 no '_' attr"
432 err_strings
[2]="log_channel[(]cluster[)] log [[]ERR[]] : scrub [0-9]*[.]0 .*::obj5:7 is an unexpected clone"
433 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[)]"
434 err_strings
[4]="log_channel[(]cluster[)] log [[]ERR[]] : scrub [0-9]*[.]0 .*:::obj5:head expected clone .*:::obj5:2"
435 err_strings
[5]="log_channel[(]cluster[)] log [[]ERR[]] : scrub [0-9]*[.]0 .*:::obj5:head expected clone .*:::obj5:1"
436 err_strings
[6]="log_channel[(]cluster[)] log [[]INF[]] : scrub [0-9]*[.]0 .*:::obj5:head 2 missing clone[(]s[)]"
437 err_strings
[7]="log_channel[(]cluster[)] log [[]ERR[]] : scrub [0-9]*[.]0 .*:::obj12:head snapset.head_exists=false, but head exists"
438 err_strings
[8]="log_channel[(]cluster[)] log [[]ERR[]] : scrub [0-9]*[.]0 .*:::obj8:head snaps.seq not set"
439 err_strings
[9]="log_channel[(]cluster[)] log [[]ERR[]] : scrub [0-9]*[.]0 .*:::obj7:head snapset.head_exists=false, but head exists"
440 err_strings
[10]="log_channel[(]cluster[)] log [[]ERR[]] : scrub [0-9]*[.]0 .*:::obj7:1 is an unexpected clone"
441 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[)]"
442 err_strings
[12]="log_channel[(]cluster[)] log [[]ERR[]] : scrub [0-9]*[.]0 .*:::obj6:1 is an unexpected clone"
443 err_strings
[13]="log_channel[(]cluster[)] log [[]ERR[]] : scrub [0-9]*[.]0 .*:::obj2:head no 'snapset' attr"
444 err_strings
[14]="log_channel[(]cluster[)] log [[]ERR[]] : scrub [0-9]*[.]0 .*:::obj2:7 clone ignored due to missing snapset"
445 err_strings
[15]="log_channel[(]cluster[)] log [[]ERR[]] : scrub [0-9]*[.]0 .*:::obj2:4 clone ignored due to missing snapset"
446 err_strings
[16]="log_channel[(]cluster[)] log [[]ERR[]] : scrub [0-9]*[.]0 .*:::obj4:head expected clone .*:::obj4:7"
447 err_strings
[17]="log_channel[(]cluster[)] log [[]INF[]] : scrub [0-9]*[.]0 .*:::obj4:head 1 missing clone[(]s[)]"
448 err_strings
[18]="log_channel[(]cluster[)] log [[]ERR[]] : scrub [0-9]*[.]0 .*:::obj1:1 is an unexpected clone"
449 err_strings
[19]="log_channel[(]cluster[)] log [[]ERR[]] : scrub [0-9]*[.]0 .*:::obj9:1 is missing in clone_size"
450 err_strings
[20]="log_channel[(]cluster[)] log [[]ERR[]] : scrub [0-9]*[.]0 .*:::obj11:1 is an unexpected clone"
451 err_strings
[21]="log_channel[(]cluster[)] log [[]ERR[]] : scrub [0-9]*[.]0 .*:::obj14:1 size 1032 != clone_size 1033"
452 err_strings
[22]="log_channel[(]cluster[)] log [[]ERR[]] : [0-9]*[.]0 scrub 23 errors"
453 err_strings
[23]="log_channel[(]cluster[)] log [[]ERR[]] : scrub [0-9]*[.]0 .*:::obj15:head can't decode 'snapset' attr buffer"
454 err_strings
[24]="log_channel[(]cluster[)] log [[]ERR[]] : scrub [0-9]*[.]0 .*:::obj12:1 has no oi or legacy_snaps; cannot convert 1=[[]1[]]:[[]1[]].stray_clone_snaps=[{]1=[[]1[]][}]"
456 for i
in `seq 0 ${#err_strings[@]}`
458 if ! grep "${err_strings[$i]}" $dir/osd
.0.log
> /dev
/null
;
460 echo "Missing log message '${err_strings[$i]}'"
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"