2011-06-22 03:31:00 +00:00
|
|
|
#!/bin/sh -ex
|
|
|
|
|
2012-12-21 03:53:07 +00:00
|
|
|
# return list of object numbers populated in image
|
|
|
|
objects () {
|
|
|
|
image=$1
|
|
|
|
prefix=$(rbd info $image | grep block_name_prefix | awk '{print $NF;}')
|
2014-04-21 23:47:10 +00:00
|
|
|
|
2012-12-21 03:53:07 +00:00
|
|
|
# strip off prefix and leading zeros from objects; sort, although
|
|
|
|
# it doesn't necessarily make sense as they're hex, at least it makes
|
|
|
|
# the list repeatable and comparable
|
|
|
|
objects=$(rados ls -p rbd | grep $prefix | \
|
2015-01-14 23:01:38 +00:00
|
|
|
sed -e 's/'$prefix'\.//' -e 's/^0*\([0-9a-f]\)/\1/' | sort -u)
|
2012-12-21 03:53:07 +00:00
|
|
|
echo $objects
|
|
|
|
}
|
|
|
|
|
|
|
|
# return false if either files don't compare or their ondisk
|
|
|
|
# sizes don't compare
|
|
|
|
|
|
|
|
compare_files_and_ondisk_sizes () {
|
|
|
|
cmp -l $1 $2 || return 1
|
|
|
|
origsize=$(stat $1 --format %b)
|
|
|
|
exportsize=$(stat $2 --format %b)
|
2014-11-12 02:16:02 +00:00
|
|
|
difference=$(($exportsize - $origsize))
|
|
|
|
difference=${difference#-} # absolute value
|
|
|
|
test $difference -ge 0 -a $difference -lt 4096
|
2012-12-21 03:53:07 +00:00
|
|
|
}
|
|
|
|
|
2013-05-21 19:15:49 +00:00
|
|
|
# cannot import a dir
|
|
|
|
mkdir foo.$$
|
|
|
|
rbd import foo.$$ foo.dir && exit 1 || true # should fail
|
|
|
|
rmdir foo.$$
|
|
|
|
|
2011-06-22 03:31:00 +00:00
|
|
|
# create a sparse file
|
|
|
|
dd if=/bin/sh of=/tmp/img bs=1k count=1 seek=10
|
|
|
|
dd if=/bin/dd of=/tmp/img bs=1k count=10 seek=100
|
|
|
|
dd if=/bin/rm of=/tmp/img bs=1k count=100 seek=1000
|
|
|
|
dd if=/bin/ls of=/tmp/img bs=1k seek=10000
|
|
|
|
dd if=/bin/ln of=/tmp/img bs=1k seek=100000
|
|
|
|
dd if=/bin/grep of=/tmp/img bs=1k seek=1000000
|
|
|
|
|
|
|
|
rbd rm testimg || true
|
|
|
|
|
2012-06-08 15:43:43 +00:00
|
|
|
rbd import $RBD_CREATE_ARGS /tmp/img testimg
|
2011-06-22 03:31:00 +00:00
|
|
|
rbd export testimg /tmp/img2
|
2012-11-28 01:06:43 +00:00
|
|
|
rbd export testimg - > /tmp/img3
|
2012-07-14 19:37:38 +00:00
|
|
|
rbd rm testimg
|
2012-11-28 01:06:43 +00:00
|
|
|
cmp /tmp/img /tmp/img2
|
|
|
|
cmp /tmp/img /tmp/img3
|
|
|
|
rm /tmp/img2 /tmp/img3
|
2012-07-14 19:37:38 +00:00
|
|
|
|
2012-11-28 00:54:43 +00:00
|
|
|
# try again, importing from stdin
|
|
|
|
rbd import $RBD_CREATE_ARGS - testimg < /tmp/img
|
|
|
|
rbd export testimg /tmp/img2
|
|
|
|
rbd export testimg - > /tmp/img3
|
|
|
|
rbd rm testimg
|
2011-06-22 03:31:00 +00:00
|
|
|
cmp /tmp/img /tmp/img2
|
2012-11-28 00:54:43 +00:00
|
|
|
cmp /tmp/img /tmp/img3
|
2011-06-22 03:31:00 +00:00
|
|
|
|
2012-11-28 00:54:43 +00:00
|
|
|
rm /tmp/img /tmp/img2 /tmp/img3
|
2011-06-22 03:31:00 +00:00
|
|
|
|
2014-04-21 23:47:10 +00:00
|
|
|
|
|
|
|
tiered=0
|
|
|
|
if ceph osd dump | grep ^pool | grep "'rbd'" | grep tier; then
|
|
|
|
tiered=1
|
|
|
|
fi
|
|
|
|
|
2012-12-21 03:53:07 +00:00
|
|
|
# create specifically sparse files
|
|
|
|
# 1 1M block of sparse, 1 1M block of random
|
|
|
|
dd if=/dev/urandom bs=1M seek=1 count=1 of=/tmp/sparse1
|
|
|
|
|
|
|
|
# 1 1M block of random, 1 1M block of sparse
|
|
|
|
dd if=/dev/urandom bs=1M count=1 of=/tmp/sparse2; truncate /tmp/sparse2 -s 2M
|
|
|
|
|
|
|
|
# 1M-block images; validate resulting blocks
|
|
|
|
|
|
|
|
# 1M sparse, 1M data
|
|
|
|
rbd import $RBD_CREATE_ARGS --order 20 /tmp/sparse1
|
2014-10-15 19:26:00 +00:00
|
|
|
rbd ls -l | grep sparse1 | grep -i '2048k'
|
2014-04-21 23:47:10 +00:00
|
|
|
[ $tiered -eq 1 -o "$(objects sparse1)" = '1' ]
|
2012-12-21 03:53:07 +00:00
|
|
|
|
|
|
|
# export, compare contents and on-disk size
|
|
|
|
rbd export sparse1 /tmp/sparse1.out
|
|
|
|
compare_files_and_ondisk_sizes /tmp/sparse1 /tmp/sparse1.out
|
|
|
|
rm /tmp/sparse1.out
|
|
|
|
rbd rm sparse1
|
|
|
|
|
|
|
|
# 1M data, 1M sparse
|
|
|
|
rbd import $RBD_CREATE_ARGS --order 20 /tmp/sparse2
|
2014-10-15 19:26:00 +00:00
|
|
|
rbd ls -l | grep sparse2 | grep -i '2048k'
|
2014-04-21 23:47:10 +00:00
|
|
|
[ $tiered -eq 1 -o "$(objects sparse2)" = '0' ]
|
2012-12-21 03:53:07 +00:00
|
|
|
rbd export sparse2 /tmp/sparse2.out
|
|
|
|
compare_files_and_ondisk_sizes /tmp/sparse2 /tmp/sparse2.out
|
|
|
|
rm /tmp/sparse2.out
|
|
|
|
rbd rm sparse2
|
|
|
|
|
|
|
|
# extend sparse1 to 10 1M blocks, sparse at the end
|
|
|
|
truncate /tmp/sparse1 -s 10M
|
|
|
|
# import from stdin just for fun, verify still sparse
|
|
|
|
rbd import $RBD_CREATE_ARGS --order 20 - sparse1 < /tmp/sparse1
|
2014-10-15 19:26:00 +00:00
|
|
|
rbd ls -l | grep sparse1 | grep -i '10240k'
|
2014-04-21 23:47:10 +00:00
|
|
|
[ $tiered -eq 1 -o "$(objects sparse1)" = '1' ]
|
2012-12-21 03:53:07 +00:00
|
|
|
rbd export sparse1 /tmp/sparse1.out
|
|
|
|
compare_files_and_ondisk_sizes /tmp/sparse1 /tmp/sparse1.out
|
|
|
|
rm /tmp/sparse1.out
|
|
|
|
rbd rm sparse1
|
|
|
|
|
|
|
|
# extend sparse2 to 4M total with two more nonsparse megs
|
|
|
|
dd if=/dev/urandom bs=2M count=1 of=/tmp/sparse2 oflag=append conv=notrunc
|
|
|
|
# again from stding
|
|
|
|
rbd import $RBD_CREATE_ARGS --order 20 - sparse2 < /tmp/sparse2
|
2014-10-15 19:26:00 +00:00
|
|
|
rbd ls -l | grep sparse2 | grep -i '4096k'
|
2014-04-21 23:47:10 +00:00
|
|
|
[ $tiered -eq 1 -o "$(objects sparse2)" = '0 2 3' ]
|
2012-12-21 03:53:07 +00:00
|
|
|
rbd export sparse2 /tmp/sparse2.out
|
|
|
|
compare_files_and_ondisk_sizes /tmp/sparse2 /tmp/sparse2.out
|
|
|
|
rm /tmp/sparse2.out
|
|
|
|
rbd rm sparse2
|
|
|
|
|
|
|
|
# zeros import to a sparse image. Note: all zeros currently
|
|
|
|
# doesn't work right now due to the way we handle 'empty' fiemaps;
|
|
|
|
# the image ends up zero-filled.
|
|
|
|
|
|
|
|
echo "partially-sparse file imports to partially-sparse image"
|
|
|
|
rbd import $RBD_CREATE_ARGS --order 20 /tmp/sparse1 sparse
|
2014-04-21 23:47:10 +00:00
|
|
|
[ $tiered -eq 1 -o "$(objects sparse)" = '1' ]
|
2012-12-21 03:53:07 +00:00
|
|
|
rbd rm sparse
|
|
|
|
|
|
|
|
echo "zeros import through stdin to sparse image"
|
|
|
|
# stdin
|
|
|
|
dd if=/dev/zero bs=1M count=4 | rbd import $RBD_CREATE_ARGS - sparse
|
2014-04-21 23:47:10 +00:00
|
|
|
[ $tiered -eq 1 -o "$(objects sparse)" = '' ]
|
2012-12-21 03:53:07 +00:00
|
|
|
rbd rm sparse
|
|
|
|
|
|
|
|
echo "zeros export to sparse file"
|
|
|
|
# Must be tricky to make image "by hand" ; import won't create a zero image
|
|
|
|
rbd create sparse --size 4
|
|
|
|
prefix=$(rbd info sparse | grep block_name_prefix | awk '{print $NF;}')
|
|
|
|
# drop in 0 object directly
|
|
|
|
dd if=/dev/zero bs=4M count=1 | rados -p rbd put ${prefix}.000000000000 -
|
2014-04-21 23:47:10 +00:00
|
|
|
[ $tiered -eq 1 -o "$(objects sparse)" = '0' ]
|
2012-12-21 03:53:07 +00:00
|
|
|
# 1 object full of zeros; export should still create 0-disk-usage file
|
|
|
|
rm /tmp/sparse || true
|
|
|
|
rbd export sparse /tmp/sparse
|
|
|
|
[ $(stat /tmp/sparse --format=%b) = '0' ]
|
|
|
|
rbd rm sparse
|
|
|
|
|
|
|
|
rm /tmp/sparse /tmp/sparse1 /tmp/sparse2 /tmp/sparse3 || true
|
|
|
|
|
2012-06-08 15:43:43 +00:00
|
|
|
echo OK
|