4 CEPH_SECRET_FILE
=${CEPH_SECRET_FILE:-}
5 CEPH_ID
=${CEPH_ID:-admin}
7 if [ ! -z $CEPH_SECRET_FILE ]; then
8 SECRET_ARGS
="--secret $CEPH_SECRET_FILE"
11 TMP_FILES
="/tmp/img1 /tmp/img1.small /tmp/img1.snap1 /tmp/img1.export /tmp/img1.trunc"
13 function expect_false
() {
14 if "$@"; then return 1; else return 0; fi
17 function get_device_dir
{
21 rbd device list |
tail -n +2 |
egrep "\s+$POOL\s+$IMAGE\s+$SNAP\s+" |
26 [ -e /dev
/rbd
/rbd
/testimg1@snap1
] &&
27 sudo rbd device unmap
/dev
/rbd
/rbd
/testimg1@snap1
28 if [ -e /dev
/rbd
/rbd
/testimg1
]; then
29 sudo rbd device unmap
/dev
/rbd
/rbd
/testimg1
30 rbd snap purge testimg1 || true
32 rbd
ls |
grep testimg1
> /dev
/null
&& rbd
rm testimg1 || true
38 trap clean_up INT TERM EXIT
41 dd if=/bin
/sh of
=/tmp
/img1 bs
=1k count
=1 seek
=10
42 dd if=/bin
/dd of
=/tmp
/img1 bs
=1k count
=10 seek
=100
43 dd if=/bin
/rm of
=/tmp
/img1 bs
=1k count
=100 seek
=1000
44 dd if=/bin
/ls of
=/tmp
/img1 bs
=1k seek
=10000
45 dd if=/bin
/ln of
=/tmp
/img1 bs
=1k seek
=100000
46 dd if=/dev
/zero of
=/tmp
/img1 count
=0 seek
=150000
49 rbd import
/tmp
/img1 testimg1
50 sudo rbd device map testimg1
--user $CEPH_ID $SECRET_ARGS
52 DEV_ID1
=$
(get_device_dir rbd testimg1
-)
53 echo "dev_id1 = $DEV_ID1"
54 cat /sys
/bus
/rbd
/devices
/$DEV_ID1/size
55 cat /sys
/bus
/rbd
/devices
/$DEV_ID1/size |
grep 76800000
57 sudo
dd if=/dev
/rbd
/rbd
/testimg1 of
=/tmp
/img1.
export
58 cmp /tmp
/img1
/tmp
/img1.
export
61 rbd snap create testimg1
--snap=snap1
62 sudo rbd device map
--snap=snap1 testimg1
--user $CEPH_ID $SECRET_ARGS
64 DEV_ID2
=$
(get_device_dir rbd testimg1 snap1
)
65 cat /sys
/bus
/rbd
/devices
/$DEV_ID2/size |
grep 76800000
67 sudo
dd if=/dev
/rbd
/rbd
/testimg1@snap1 of
=/tmp
/img1.snap1
68 cmp /tmp
/img1
/tmp
/img1.snap1
71 rbd resize testimg1
--size=40 --allow-shrink
72 cat /sys
/bus
/rbd
/devices
/$DEV_ID1/size |
grep 41943040
73 cat /sys
/bus
/rbd
/devices
/$DEV_ID2/size |
grep 76800000
75 sudo
dd if=/dev
/rbd
/rbd
/testimg1 of
=/tmp
/img1.small
76 cp /tmp
/img1
/tmp
/img1.trunc
77 truncate
-s 41943040 /tmp
/img1.trunc
78 cmp /tmp
/img1.trunc
/tmp
/img1.small
80 # rollback expects an unlocked image
81 # (acquire and) release the lock as a side effect
82 rbd bench
--io-type read --io-size 1 --io-threads 1 --io-total 1 testimg1
84 # rollback and check data again
85 rbd snap rollback
--snap=snap1 testimg1
86 cat /sys
/bus
/rbd
/devices
/$DEV_ID1/size |
grep 76800000
87 cat /sys
/bus
/rbd
/devices
/$DEV_ID2/size |
grep 76800000
88 sudo
rm -f /tmp
/img1.snap1
/tmp
/img1.
export
90 sudo
dd if=/dev
/rbd
/rbd
/testimg1@snap1 of
=/tmp
/img1.snap1
91 cmp /tmp
/img1
/tmp
/img1.snap1
92 sudo
dd if=/dev
/rbd
/rbd
/testimg1 of
=/tmp
/img1.
export
93 cmp /tmp
/img1
/tmp
/img1.
export
95 # zeros are returned if an image or a snapshot is removed
96 expect_false
cmp -n 76800000 /dev
/rbd
/rbd
/testimg1@snap1
/dev
/zero
97 rbd snap
rm --snap=snap1 testimg1
98 cmp -n 76800000 /dev
/rbd
/rbd
/testimg1@snap1
/dev
/zero