ceph/qa/workunits/rbd/kernel.sh
Alex Elder 6bac8ac06c rbd/kernel.sh: quit looking for snapshot sysfs entries
The sysfs entries for snapshots went away a while ago, and this
script used them to verify sizes matched what was expected.

Instead, look at the mapped size of the snapshot in the places
that used to look for the image's snapshot sysfs files.

Also, switch over to using "udevadm settle" rather than a delay to
wait for udev to do its thing.  Insert them at more appropriate
places--right after "rmd map" commands and before and after the
"rbd unmap" calls.

Stop doing the manual refresh calls as well.  The osd will trigger
refreshes whenever the image size or shapshot context changes.

Finally, the cleanup routine is called initially, when there really
isn't expected to be anything to clean up.  Change the rbd commands
to run there conditionally, only if the target of the command
already exists.

Signed-off-by: Alex Elder <elder@inktank.com>
2013-05-30 18:38:53 -05:00

100 lines
2.8 KiB
Bash
Executable File

#!/bin/bash -ex
CEPH_SECRET_FILE=${CEPH_SECRET_FILE:-}
CEPH_ID=${CEPH_ID:-admin}
SECRET_ARGS=''
if [ ! -z $CEPH_SECRET_FILE ]; then
SECRET_ARGS="--secret $CEPH_SECRET_FILE"
fi
TMP_FILES="/tmp/img1 /tmp/img1.small /tmp/img1.snap1 /tmp/img1.export /tmp/img1.trunc"
function get_device_dir {
local POOL=$1
local IMAGE=$2
local SNAP=$3
rbd showmapped | tail -n +2 | egrep "\s+$POOL\s+$IMAGE\s+$SNAP\s+" | awk '{print $1;}'
}
function clean_up {
udevadm settle
[ -e /dev/rbd/rbd/testimg1@snap1 ] &&
rbd unmap /dev/rbd/rbd/testimg1@snap1 || true
if [ -e /dev/rbd/rbd/testimg1 ]; then
rbd unmap /dev/rbd/rbd/testimg1 || true
rbd snap purge testimg1 || true
fi
udevadm settle
sudo chown root /sys/bus/rbd/add /sys/bus/rbd/remove
rbd ls | grep testimg1 > /dev/null && rbd rm testimg1 || true
sudo rm -f $TMP_FILES
}
clean_up
trap clean_up INT TERM EXIT
# allow ubuntu user to map/unmap rbd devices
sudo chown ubuntu /sys/bus/rbd/add /sys/bus/rbd/remove
# create an image
dd if=/bin/sh of=/tmp/img1 bs=1k count=1 seek=10
dd if=/bin/dd of=/tmp/img1 bs=1k count=10 seek=100
dd if=/bin/rm of=/tmp/img1 bs=1k count=100 seek=1000
dd if=/bin/ls of=/tmp/img1 bs=1k seek=10000
dd if=/bin/ln of=/tmp/img1 bs=1k seek=100000
dd if=/dev/zero of=/tmp/img1 count=0 seek=150000
# import
rbd import /tmp/img1 testimg1
rbd map testimg1 --user $CEPH_ID $SECRET_ARGS
# wait for udev to catch up
udevadm settle
DEV_ID1=$(get_device_dir rbd testimg1 -)
echo "dev_id1 = $DEV_ID1"
cat /sys/bus/rbd/devices/$DEV_ID1/size
cat /sys/bus/rbd/devices/$DEV_ID1/size | grep 76800000
sudo dd if=/dev/rbd/rbd/testimg1 of=/tmp/img1.export
cmp /tmp/img1 /tmp/img1.export
# snapshot
rbd snap create testimg1 --snap=snap1
rbd map --snap=snap1 testimg1 --user $CEPH_ID $SECRET_ARGS
# wait for udev to catch up
udevadm settle
DEV_ID2=$(get_device_dir rbd testimg1 snap1)
cat /sys/bus/rbd/devices/$DEV_ID2/size | grep 76800000
sudo dd if=/dev/rbd/rbd/testimg1@snap1 of=/tmp/img1.snap1
cmp /tmp/img1 /tmp/img1.snap1
# resize
rbd resize testimg1 --size=40 --allow-shrink
cat /sys/bus/rbd/devices/$DEV_ID1/size | grep 41943040
cat /sys/bus/rbd/devices/$DEV_ID2/size | grep 76800000
sudo dd if=/dev/rbd/rbd/testimg1 of=/tmp/img1.small
cp /tmp/img1 /tmp/img1.trunc
truncate -s 41943040 /tmp/img1.trunc
cmp /tmp/img1.trunc /tmp/img1.small
# rollback and check data again
rbd snap rollback --snap=snap1 testimg1
cat /sys/bus/rbd/devices/$DEV_ID1/size | grep 76800000
cat /sys/bus/rbd/devices/$DEV_ID2/size | grep 76800000
sudo rm -f /tmp/img1.snap1 /tmp/img1.export
sudo dd if=/dev/rbd/rbd/testimg1@snap1 of=/tmp/img1.snap1
cmp /tmp/img1 /tmp/img1.snap1
sudo dd if=/dev/rbd/rbd/testimg1 of=/tmp/img1.export
cmp /tmp/img1 /tmp/img1.export
# remove snapshot and detect error from mapped snapshot
rbd snap rm --snap=snap1 testimg1
sudo dd if=/dev/rbd/rbd/testimg1@snap1 of=/tmp/img1.snap1 2>&1 | grep 'Input/output error'
echo OK