]> www.infradead.org Git - users/hch/blktests.git/commitdiff
nvmeof-mp, srp: Check multipathd version
authorBart Van Assche <bvanassche@acm.org>
Thu, 21 Feb 2019 23:18:58 +0000 (15:18 -0800)
committerBart Van Assche <bvanassche@acm.org>
Fri, 22 Feb 2019 23:16:28 +0000 (15:16 -0800)
The srp tests reliably report data corruption with multipathd versions
before 0.7.0 due to a multipathd bug. Hence verify that the multipathd
version is at least 0.7.0.

Signed-off-by: Bart Van Assche <bvanassche@acm.org>
common/multipath-over-rdma
tests/nvmeof-mp/rc
tests/srp/rc

index 15201468ca734fa78ef850ab5775fb035145b00f..65ebb7b7f5f789074198a237d069cad7c11dc86c 100644 (file)
@@ -23,6 +23,37 @@ _have_legacy_dm() {
        fi
 }
 
+# Check whether version number $1 is less than or equal to version number $2.
+version_le() {
+       local i v1 v2
+
+       IFS='.' read -ra v1 <<<"$1"
+       IFS='.' read -ra v2 <<<"$2"
+       if [ ${#v1[@]} != ${#v2[@]} ]; then
+               echo "Error: version number mismatch $1 <> $2" >&2
+               return 1
+       fi
+       for ((i=0; i < ${#v1[@]}; i++)); do
+               [ "${v1[i]}" -lt "${v2[i]}" ] && return 0
+               [ "${v1[i]}" -gt "${v2[i]}" ] && return 1
+       done
+       return 0
+}
+
+# Check whether the multipathd version is at least $1. $1 is a version number
+# with three components separated by dots.
+_multipathd_version_ge() {
+       local min_ver=$1 mp_ver
+
+       mp_ver=$(multipath -k 2>&1 |
+               sed -n 's/^multipath-tools v\([0-9]*\.[0-9]*\.[0-9]*\).*/\1/p')
+       if version_le "$min_ver" "$mp_ver"; then
+               return 0
+       fi
+       SKIP_REASON="Need multipathd version $min_ver; found multipathd version $mp_ver."
+       return 1
+}
+
 get_ipv4_addr() {
        ip -4 -o addr show dev "$1" |
                sed -n 's/.*[[:blank:]]inet[[:blank:]]*\([^[:blank:]/]*\).*/\1/p'
@@ -669,3 +700,22 @@ setup_test() {
        start_target || return $?
        echo "Test setup finished" >>"$FULL"
 }
+
+# Run these unit tests as follows:
+# bash -c '. ./common/multipath-over-rdma && unit_tests'
+unit_tests() {
+       local t tests pass=1
+
+       tests=("version_le 0.1.2 1.2.3"
+              "version_le 0.1.2 0.1.3"
+              "version_le 0.1.2 0.1.2"
+              "! version_le 3 2"
+              "! version_le 3.1 2.3")
+       for t in "${tests[@]}"; do
+               if ! eval "$t"; then
+                       echo "FAILED: $t"
+                       pass=0
+               fi
+       done
+       [ $pass = 1 ] && echo PASS
+}
index d4a6511151a8251f99b31a9759860bb2613bc986..9324dd1e8e4f74859b743db4eab98ddced5c1b54 100755 (executable)
@@ -44,6 +44,8 @@ group_requires() {
                _have_program "$p" || return $?
        done
 
+       _multipathd_version_ge 0.7.0 || return $?
+       
        _have_root || return $?
 
        _have_kernel_option DM_UEVENT || return $?
index feb9e7b1a2674075e9016db25acf1e766d37bb5f..52e9fecdc2ab87abc5457202a93ac8aec857b941 100755 (executable)
@@ -62,6 +62,8 @@ group_requires() {
                _have_program "$p" || return $?
        done
 
+       _multipathd_version_ge 0.7.0 || return $?
+
        _have_root || return $?
 
        _have_src_program discontiguous-io || return $?