]> git.proxmox.com Git - ceph.git/blame - ceph/qa/workunits/rbd/kernel.sh
import new upstream nautilus stable release 14.2.8
[ceph.git] / ceph / qa / workunits / rbd / kernel.sh
CommitLineData
11fdf7f2
TL
1#!/usr/bin/env bash
2set -ex
7c673cae
FG
3
4CEPH_SECRET_FILE=${CEPH_SECRET_FILE:-}
5CEPH_ID=${CEPH_ID:-admin}
6SECRET_ARGS=''
7if [ ! -z $CEPH_SECRET_FILE ]; then
8 SECRET_ARGS="--secret $CEPH_SECRET_FILE"
9fi
10
11TMP_FILES="/tmp/img1 /tmp/img1.small /tmp/img1.snap1 /tmp/img1.export /tmp/img1.trunc"
12
92f5a8d4
TL
13function expect_false() {
14 if "$@"; then return 1; else return 0; fi
15}
16
7c673cae
FG
17function get_device_dir {
18 local POOL=$1
19 local IMAGE=$2
20 local SNAP=$3
11fdf7f2
TL
21 rbd device list | tail -n +2 | egrep "\s+$POOL\s+$IMAGE\s+$SNAP\s+" |
22 awk '{print $1;}'
7c673cae
FG
23}
24
25function clean_up {
26 [ -e /dev/rbd/rbd/testimg1@snap1 ] &&
11fdf7f2 27 sudo rbd device unmap /dev/rbd/rbd/testimg1@snap1
7c673cae 28 if [ -e /dev/rbd/rbd/testimg1 ]; then
11fdf7f2 29 sudo rbd device unmap /dev/rbd/rbd/testimg1
7c673cae
FG
30 rbd snap purge testimg1 || true
31 fi
32 rbd ls | grep testimg1 > /dev/null && rbd rm testimg1 || true
33 sudo rm -f $TMP_FILES
34}
35
36clean_up
37
38trap clean_up INT TERM EXIT
39
40# create an image
41dd if=/bin/sh of=/tmp/img1 bs=1k count=1 seek=10
42dd if=/bin/dd of=/tmp/img1 bs=1k count=10 seek=100
43dd if=/bin/rm of=/tmp/img1 bs=1k count=100 seek=1000
44dd if=/bin/ls of=/tmp/img1 bs=1k seek=10000
45dd if=/bin/ln of=/tmp/img1 bs=1k seek=100000
46dd if=/dev/zero of=/tmp/img1 count=0 seek=150000
47
48# import
49rbd import /tmp/img1 testimg1
11fdf7f2 50sudo rbd device map testimg1 --user $CEPH_ID $SECRET_ARGS
7c673cae
FG
51
52DEV_ID1=$(get_device_dir rbd testimg1 -)
53echo "dev_id1 = $DEV_ID1"
54cat /sys/bus/rbd/devices/$DEV_ID1/size
55cat /sys/bus/rbd/devices/$DEV_ID1/size | grep 76800000
56
57sudo dd if=/dev/rbd/rbd/testimg1 of=/tmp/img1.export
58cmp /tmp/img1 /tmp/img1.export
59
60# snapshot
61rbd snap create testimg1 --snap=snap1
11fdf7f2 62sudo rbd device map --snap=snap1 testimg1 --user $CEPH_ID $SECRET_ARGS
7c673cae
FG
63
64DEV_ID2=$(get_device_dir rbd testimg1 snap1)
65cat /sys/bus/rbd/devices/$DEV_ID2/size | grep 76800000
66
67sudo dd if=/dev/rbd/rbd/testimg1@snap1 of=/tmp/img1.snap1
68cmp /tmp/img1 /tmp/img1.snap1
69
70# resize
71rbd resize testimg1 --size=40 --allow-shrink
72cat /sys/bus/rbd/devices/$DEV_ID1/size | grep 41943040
73cat /sys/bus/rbd/devices/$DEV_ID2/size | grep 76800000
74
75sudo dd if=/dev/rbd/rbd/testimg1 of=/tmp/img1.small
76cp /tmp/img1 /tmp/img1.trunc
77truncate -s 41943040 /tmp/img1.trunc
78cmp /tmp/img1.trunc /tmp/img1.small
79
92f5a8d4
TL
80# rollback expects an unlocked image
81# (acquire and) release the lock as a side effect
82rbd bench --io-type read --io-size 1 --io-threads 1 --io-total 1 testimg1
83
7c673cae
FG
84# rollback and check data again
85rbd snap rollback --snap=snap1 testimg1
86cat /sys/bus/rbd/devices/$DEV_ID1/size | grep 76800000
87cat /sys/bus/rbd/devices/$DEV_ID2/size | grep 76800000
88sudo rm -f /tmp/img1.snap1 /tmp/img1.export
89
90sudo dd if=/dev/rbd/rbd/testimg1@snap1 of=/tmp/img1.snap1
91cmp /tmp/img1 /tmp/img1.snap1
92sudo dd if=/dev/rbd/rbd/testimg1 of=/tmp/img1.export
93cmp /tmp/img1 /tmp/img1.export
94
92f5a8d4
TL
95# zeros are returned if an image or a snapshot is removed
96expect_false cmp -n 76800000 /dev/rbd/rbd/testimg1@snap1 /dev/zero
7c673cae 97rbd snap rm --snap=snap1 testimg1
92f5a8d4 98cmp -n 76800000 /dev/rbd/rbd/testimg1@snap1 /dev/zero
7c673cae
FG
99
100echo OK