2015-11-15 01:40:48 +00:00
|
|
|
#!/bin/bash -ex
|
|
|
|
|
2016-01-13 10:55:32 +00:00
|
|
|
. $(dirname $0)/../ceph-helpers.sh
|
2015-11-15 01:40:48 +00:00
|
|
|
|
2016-01-13 10:55:32 +00:00
|
|
|
POOL=rbd
|
|
|
|
IMAGE=testrbdnbd$$
|
|
|
|
SIZE=64
|
|
|
|
DATA=
|
|
|
|
DEV=
|
|
|
|
|
2016-11-04 10:37:13 +00:00
|
|
|
_sudo()
|
|
|
|
{
|
|
|
|
local cmd
|
|
|
|
|
|
|
|
if [ `id -u` -eq 0 ]
|
|
|
|
then
|
|
|
|
"$@"
|
|
|
|
return $?
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Look for the command in the user path. If it fails run it as is,
|
|
|
|
# supposing it is in sudo path.
|
|
|
|
cmd=`which $1 2>/dev/null` || cmd=$1
|
|
|
|
shift
|
|
|
|
sudo -nE "${cmd}" "$@"
|
|
|
|
}
|
|
|
|
|
2016-01-13 10:55:32 +00:00
|
|
|
setup()
|
|
|
|
{
|
2016-11-04 10:37:13 +00:00
|
|
|
if [ -e CMakeCache.txt ]; then
|
|
|
|
# running under cmake build dir
|
|
|
|
|
|
|
|
CEPH_SRC=$(readlink -f $(dirname $0)/../../../src)
|
|
|
|
CEPH_ROOT=${PWD}
|
|
|
|
CEPH_BIN=${CEPH_ROOT}/bin
|
|
|
|
|
|
|
|
export LD_LIBRARY_PATH=${CEPH_ROOT}/lib:${LD_LIBRARY_PATH}
|
|
|
|
export PYTHONPATH=${PYTHONPATH}:${CEPH_SRC}/pybind
|
|
|
|
for x in ${CEPH_ROOT}/lib/cython_modules/lib* ; do
|
|
|
|
PYTHONPATH="${PYTHONPATH}:${x}"
|
|
|
|
done
|
|
|
|
PATH=${CEPH_BIN}:${PATH}
|
|
|
|
fi
|
|
|
|
|
|
|
|
_sudo echo test sudo
|
|
|
|
|
2016-01-13 10:55:32 +00:00
|
|
|
trap cleanup INT TERM EXIT
|
|
|
|
TEMPDIR=`mktemp -d`
|
|
|
|
DATA=${TEMPDIR}/data
|
|
|
|
dd if=/dev/urandom of=${DATA} bs=1M count=${SIZE}
|
|
|
|
rbd --dest-pool ${POOL} --no-progress import ${DATA} ${IMAGE}
|
|
|
|
}
|
|
|
|
|
|
|
|
function cleanup()
|
|
|
|
{
|
|
|
|
set +e
|
|
|
|
rm -Rf ${TMPDIR}
|
|
|
|
if [ -n "${DEV}" ]
|
|
|
|
then
|
2016-11-04 10:37:13 +00:00
|
|
|
_sudo rbd-nbd unmap ${DEV}
|
2016-01-13 10:55:32 +00:00
|
|
|
fi
|
|
|
|
if rbd -p ${POOL} status ${IMAGE} 2>/dev/null; then
|
2016-10-11 13:35:38 +00:00
|
|
|
for s in 0.5 1 2 4 8 16 32; do
|
2016-01-13 10:55:32 +00:00
|
|
|
sleep $s
|
|
|
|
rbd -p ${POOL} status ${IMAGE} | grep 'Watchers: none' && break
|
|
|
|
done
|
|
|
|
rbd -p ${POOL} remove ${IMAGE}
|
|
|
|
fi
|
|
|
|
}
|
2015-11-15 01:40:48 +00:00
|
|
|
|
|
|
|
function expect_false()
|
|
|
|
{
|
|
|
|
if "$@"; then return 1; else return 0; fi
|
|
|
|
}
|
|
|
|
|
2016-01-13 10:55:32 +00:00
|
|
|
#
|
|
|
|
# main
|
|
|
|
#
|
|
|
|
|
|
|
|
setup
|
|
|
|
|
|
|
|
# exit status test
|
|
|
|
expect_false rbd-nbd
|
|
|
|
expect_false rbd-nbd INVALIDCMD
|
|
|
|
if [ `id -u` -ne 0 ]
|
|
|
|
then
|
|
|
|
expect_false rbd-nbd map ${IMAGE}
|
|
|
|
fi
|
2016-11-04 10:37:13 +00:00
|
|
|
expect_false _sudo rbd-nbd map INVALIDIMAGE
|
|
|
|
expect_false _sudo rbd-nbd --device INVALIDDEV map ${IMAGE}
|
2016-01-13 10:55:32 +00:00
|
|
|
|
|
|
|
# map test using the first unused device
|
2016-11-04 10:37:13 +00:00
|
|
|
DEV=`_sudo rbd-nbd map ${POOL}/${IMAGE}`
|
|
|
|
_sudo rbd-nbd list-mapped | grep "^${DEV}$"
|
2016-01-13 10:55:32 +00:00
|
|
|
|
|
|
|
# map test specifying the device
|
2016-11-04 10:37:13 +00:00
|
|
|
expect_false _sudo rbd-nbd --device ${DEV} map ${POOL}/${IMAGE}
|
2016-01-13 10:55:32 +00:00
|
|
|
dev1=${DEV}
|
2016-11-04 10:37:13 +00:00
|
|
|
_sudo rbd-nbd unmap ${DEV}
|
|
|
|
_sudo rbd-nbd list-mapped | expect_false grep "^${DEV}$"
|
2016-01-13 10:55:32 +00:00
|
|
|
DEV=
|
|
|
|
# XXX: race possible when the device is reused by other process
|
2016-11-04 10:37:13 +00:00
|
|
|
DEV=`_sudo rbd-nbd --device ${dev1} map ${POOL}/${IMAGE}`
|
2016-01-13 10:55:32 +00:00
|
|
|
[ "${DEV}" = "${dev1}" ]
|
2016-11-04 10:37:13 +00:00
|
|
|
_sudo rbd-nbd list-mapped | grep "^${DEV}$"
|
2015-11-15 01:40:48 +00:00
|
|
|
|
2016-06-03 18:11:21 +00:00
|
|
|
# read test
|
2016-11-04 10:37:13 +00:00
|
|
|
[ "`dd if=${DATA} bs=1M | md5sum`" = "`_sudo dd if=${DEV} bs=1M | md5sum`" ]
|
2015-11-15 01:40:48 +00:00
|
|
|
|
2016-06-03 18:11:21 +00:00
|
|
|
# write test
|
2016-01-13 10:55:32 +00:00
|
|
|
dd if=/dev/urandom of=${DATA} bs=1M count=${SIZE}
|
2016-11-04 10:37:13 +00:00
|
|
|
_sudo dd if=${DATA} of=${DEV} bs=1M oflag=direct
|
2016-01-13 10:55:32 +00:00
|
|
|
[ "`dd if=${DATA} bs=1M | md5sum`" = "`rbd -p ${POOL} --no-progress export ${IMAGE} - | md5sum`" ]
|
2015-11-15 01:40:48 +00:00
|
|
|
|
2016-06-03 18:11:21 +00:00
|
|
|
# trim test
|
2016-01-13 10:55:32 +00:00
|
|
|
provisioned=`rbd -p ${POOL} --format xml du ${IMAGE} |
|
|
|
|
$XMLSTARLET sel -t -m "//stats/images/image/provisioned_size" -v .`
|
|
|
|
used=`rbd -p ${POOL} --format xml du ${IMAGE} |
|
|
|
|
$XMLSTARLET sel -t -m "//stats/images/image/used_size" -v .`
|
|
|
|
[ "${used}" -eq "${provisioned}" ]
|
2016-11-04 10:37:13 +00:00
|
|
|
_sudo mkfs.ext4 -E discard ${DEV} # better idea?
|
2015-11-15 01:40:48 +00:00
|
|
|
sync
|
2016-01-13 10:55:32 +00:00
|
|
|
provisioned=`rbd -p ${POOL} --format xml du ${IMAGE} |
|
|
|
|
$XMLSTARLET sel -t -m "//stats/images/image/provisioned_size" -v .`
|
|
|
|
used=`rbd -p ${POOL} --format xml du ${IMAGE} |
|
|
|
|
$XMLSTARLET sel -t -m "//stats/images/image/used_size" -v .`
|
|
|
|
[ "${used}" -lt "${provisioned}" ]
|
2015-11-15 01:40:48 +00:00
|
|
|
|
2016-06-03 18:11:21 +00:00
|
|
|
# resize test
|
|
|
|
devname=$(basename ${DEV})
|
|
|
|
blocks=$(awk -v dev=${devname} '$4 == dev {print $3}' /proc/partitions)
|
|
|
|
test -n "${blocks}"
|
|
|
|
rbd resize ${POOL}/${IMAGE} --size $((SIZE * 2))M
|
|
|
|
rbd info ${POOL}/${IMAGE}
|
|
|
|
blocks2=$(awk -v dev=${devname} '$4 == dev {print $3}' /proc/partitions)
|
|
|
|
test -n "${blocks2}"
|
|
|
|
test ${blocks2} -eq $((blocks * 2))
|
|
|
|
rbd resize ${POOL}/${IMAGE} --allow-shrink --size ${SIZE}M
|
|
|
|
blocks2=$(awk -v dev=${devname} '$4 == dev {print $3}' /proc/partitions)
|
|
|
|
test -n "${blocks2}"
|
|
|
|
test ${blocks2} -eq ${blocks}
|
|
|
|
|
2016-10-11 13:35:38 +00:00
|
|
|
# read-only option test
|
2016-11-04 10:37:13 +00:00
|
|
|
_sudo rbd-nbd unmap ${DEV}
|
|
|
|
DEV=`_sudo rbd-nbd map --read-only ${POOL}/${IMAGE}`
|
|
|
|
_sudo rbd-nbd list-mapped | grep "^${DEV}$"
|
|
|
|
_sudo dd if=${DEV} of=/dev/null bs=1M
|
|
|
|
expect_false _sudo dd if=${DATA} of=${DEV} bs=1M oflag=direct
|
|
|
|
_sudo rbd-nbd unmap ${DEV}
|
2016-10-11 13:35:38 +00:00
|
|
|
|
|
|
|
# exclusive option test
|
2016-11-04 10:37:13 +00:00
|
|
|
DEV=`_sudo rbd-nbd map --exclusive ${POOL}/${IMAGE}`
|
|
|
|
_sudo rbd-nbd list-mapped | grep "^${DEV}$"
|
|
|
|
_sudo dd if=${DATA} of=${DEV} bs=1M oflag=direct
|
2016-10-11 13:35:38 +00:00
|
|
|
expect_false timeout 10 \
|
|
|
|
rbd bench ${IMAGE} --io-type write --io-size=1024 --io-total=1024
|
2016-11-04 10:37:13 +00:00
|
|
|
_sudo rbd-nbd unmap ${DEV}
|
2016-10-11 13:35:38 +00:00
|
|
|
DEV=
|
|
|
|
rbd bench ${IMAGE} --io-type write --io-size=1024 --io-total=1024
|
|
|
|
|
2015-11-15 01:40:48 +00:00
|
|
|
echo OK
|