]> git.proxmox.com Git - ceph.git/blob - ceph/qa/workunits/rbd/map-unmap.sh
add subtree-ish sources for 12.0.3
[ceph.git] / ceph / qa / workunits / rbd / map-unmap.sh
1 #!/bin/bash -ex
2
3 RUN_TIME=300 # approximate duration of run (seconds)
4
5 [ $# -eq 1 ] && RUN_TIME="$1"
6
7 IMAGE_NAME="image-$$"
8 IMAGE_SIZE="1024" # MB
9
10 function get_time() {
11 date '+%s'
12 }
13
14 function times_up() {
15 local end_time="$1"
16
17 test $(get_time) -ge "${end_time}"
18 }
19
20 function map_unmap() {
21 [ $# -eq 1 ] || exit 99
22 local image_name="$1"
23
24 local dev
25 dev="$(sudo rbd map "${image_name}")"
26 sudo rbd unmap "${dev}"
27 }
28
29 #### Start
30
31 rbd create "${IMAGE_NAME}" --size="${IMAGE_SIZE}"
32
33 COUNT=0
34 START_TIME=$(get_time)
35 END_TIME=$(expr $(get_time) + ${RUN_TIME})
36 while ! times_up "${END_TIME}"; do
37 map_unmap "${IMAGE_NAME}"
38 COUNT=$(expr $COUNT + 1)
39 done
40 ELAPSED=$(expr "$(get_time)" - "${START_TIME}")
41
42 rbd rm "${IMAGE_NAME}"
43
44 echo "${COUNT} iterations completed in ${ELAPSED} seconds"