summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlex Elder <elder@inktank.com>2012-12-14 15:58:39 -0600
committerAlex Elder <elder@inktank.com>2012-12-14 15:58:39 -0600
commitbf01b7b2e21d6f391afa5de97cf3c8c21d6d7700 (patch)
treea2231cd728199fbebf1208f13dd1bb90123c649a
parentc728171b91ff477466ed11e7f48091a7fa5200f5 (diff)
downloadceph-bf01b7b2e21d6f391afa5de97cf3c8c21d6d7700.tar.gz
map-unmap.sh: use udevadm settle for synchronization
This script was heuristically using short sleep commands in order to give udev activity time to complete. There's a command "udevadm settle" which actually looks at the udev queue and waits until its processing is done. Much, much better. This rearranges the get_id function a bit too, breaking it into one function that gets the id and another that loops back and tries again after a short delay in the event the get_id fails. Signed-off-by: Alex Elder <elder@inktank.com>
-rwxr-xr-xqa/workunits/rbd/map-unmap.sh39
1 files changed, 23 insertions, 16 deletions
diff --git a/qa/workunits/rbd/map-unmap.sh b/qa/workunits/rbd/map-unmap.sh
index 417f95580bf..341a0be081c 100755
--- a/qa/workunits/rbd/map-unmap.sh
+++ b/qa/workunits/rbd/map-unmap.sh
@@ -10,8 +10,6 @@ IMAGE_SIZE="1024" # MB
ID_TIMEOUT="10" # seconds to wait to get rbd id after mapping
ID_DELAY=".1" # floating-point seconds to delay before rescan
-MAP_DELAY=".25" # floating-point seconds to delay before unmap
-
function get_time() {
date '+%s'
}
@@ -22,26 +20,34 @@ function times_up() {
test $(get_time) -ge "${end_time}"
}
-function get_id() {
+function _get_id() {
[ $# -eq 1 ] || exit 99
local image_name="$1"
local id=""
- local end_time=$(expr $(get_time) + ${ID_TIMEOUT})
cd /sys/bus/rbd/devices
-
- while [ -z "${id}" ]; do
- if times_up "${end_time}"; then
- break;
+ for i in *; do
+ if [ "$(cat $i/name)" = "${image_name}" ]; then
+ id="$i"
+ break
fi
- for i in *; do
- if [ "$(cat $i/name)" = "${image_name}" ]; then
- id=$i
- break
- fi
- done
+ done
+ cd - >/dev/null
+
+ echo $id
+ test -n "${id}" # return code 0 if id was found
+}
+function get_id() {
+ [ $# -eq 1 ] || exit 99
+ local image_name="$1"
+ local id=""
+ local end_time=$(expr $(get_time) + ${ID_TIMEOUT})
+
+ while ! id=$(_get_id "${image_name}") && ! times_up "${end_time}"; do
+ echo "get_id: image not mapped; trying again after delay" >&2
sleep "${ID_DELAY}"
done
+
echo $id
test -n "${id}" # return code 0 if id was found
}
@@ -51,11 +57,12 @@ function map_unmap() {
local image_name="$1"
rbd map "${image_name}"
- RBD_ID=$(get_id "${image_name}")
+ udevadm settle
- sleep "${MAP_DELAY}"
+ RBD_ID=$(get_id "${image_name}")
rbd unmap "/dev/rbd${RBD_ID}"
+ udevadm settle
}
function setup() {