diff --git a/test/lib/aux.sh b/test/lib/aux.sh index 91f54c9a4..4128f3017 100644 --- a/test/lib/aux.sh +++ b/test/lib/aux.sh @@ -479,6 +479,18 @@ udev_wait() { fi } +# wait_for_sync +wait_for_sync() { + local i + for i in {1..500} ; do + check in_sync $1 $2 && return + sleep .2 + done + + echo "Sync is taking too long - assume stuck" + return 1 +} + # # Check wheter kernel [dm module] target exist # at least in expected version diff --git a/test/lib/check.sh b/test/lib/check.sh index 9c7872858..95bba4bfc 100644 --- a/test/lib/check.sh +++ b/test/lib/check.sh @@ -151,6 +151,51 @@ linear() { $(lvl $lv -o+devices) } +# in_sync +# Works for "mirror" and "raid*" +in_sync() { + local a + local b + local idx + local type + local lvm_name="$1/$2" + local dm_name=$(echo $lvm_name | sed s:-:--: | sed s:/:-:) + + if ! a=(`dmsetup status $dm_name`); then + die "Unable to get sync status of $1" + elif [ ${a[2]} = "snapshot-origin" ]; then + if ! a=(`dmsetup status ${dm_name}-real`); then + die "Unable to get sync status of $1" + fi + fi + + if [ ${a[2]} = "raid" ]; then + # Last argument is the sync ratio for RAID + idx=$((${#a[@]} - 1)) + type=${a[3]} + elif [ ${a[2]} = "mirror" ]; then + # 4th Arg tells us how far to the sync ratio + idx=$((${a[3]} + 4)) + type=${a[2]} + else + die "Unable to get sync ratio for target type '${a[2]}'" + fi + + b=( $(echo ${a[$idx]} | sed s:/:' ':) ) + + if [ ${b[0]} != ${b[1]} ]; then + echo "$lvm_name ($type) is not in-sync" + return 1 + fi + + if [[ ${a[$(($idx - 1))]} =~ a ]]; then + die "$lvm_name in-sync, but 'a' characters in health status" + fi + + echo "$lvm_name ($type) is in-sync" + return 0 +} + active() { local lv=$1/$2 (get lv_field $lv attr | grep "^....a...$" >/dev/null) || \