Skip to content

Commit bc36cc3

Browse files
committed
common/rc,fio: factor out _compare_three_version_numbers()
The helper functions _have_kver() and _have_fio_ver() have the common logic that compares three numbers with the version string in the format "a.b.c". Factor out the common logic to the new helper function _compare_three_version_numbers(). This prepares for to introduce more functions for version checks. Signed-off-by: Shin'ichiro Kawasaki <[email protected]>
1 parent 968026b commit bc36cc3

2 files changed

Lines changed: 22 additions & 12 deletions

File tree

common/fio

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,11 @@ _have_fio_zbd_zonemode() {
2828

2929
# Check whether the version of the fio is greater than or equal to $1.$2.$3
3030
_have_fio_ver() {
31-
local d=$1 e=$2 f=$3
32-
3331
_have_fio || return $?
3432

35-
IFS='.' read -r a b c < <(fio --version | cut -c 5- | sed 's/-.*//')
36-
if [ $((a * 65536 + b * 256 + c)) -lt $((d * 65536 + e * 256 + f)) ];
37-
then
38-
SKIP_REASONS+=("fio version too old")
33+
if _compare_three_version_numbers \
34+
"$(fio --version | cut -c 5- | sed 's/-.*//')" "$1" "$2" "$3"; then
35+
SKIP_REASONS+=("fio version is older than ${1}.${2}.${3:-0}")
3936
return 1
4037
fi
4138
return 0

common/rc

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -226,15 +226,28 @@ _have_kernel_option() {
226226
return 0
227227
}
228228

229+
# Compare the version string in $1 in "a.b.c" format with "$2.$3.$4".
230+
# If "a.b.c" is smaller than "$2.$3.$4", return true. Otherwise, return
231+
# false.
232+
_compare_three_version_numbers() {
233+
local -i a b c d e f
234+
235+
IFS='.' read -r a b c <<< "$1"
236+
d=${2:0}
237+
e=${3:0}
238+
f=${4:0}
239+
if ((a * 65536 + b * 256 + c < d * 65536 + e * 256 + f)); then
240+
return 0
241+
fi
242+
return 1
243+
}
244+
229245
# Check whether the version of the running kernel is greater than or equal to
230246
# $1.$2.$3
231247
_have_kver() {
232-
local d=$1 e=$2 f=$3
233-
234-
IFS='.' read -r a b c < <(uname -r | sed 's/-.*//;s/[^.0-9]//')
235-
if [ $((a * 65536 + b * 256 + c)) -lt $((d * 65536 + e * 256 + f)) ];
236-
then
237-
SKIP_REASONS+=("Kernel version too old")
248+
if _compare_three_version_numbers \
249+
"$(uname -r | sed 's/-.*//;s/[^.0-9]//')" "$1" "$2" "$3"; then
250+
SKIP_REASONS+=("Kernel version is older than ${1}.${2}.${3}")
238251
return 1
239252
fi
240253
}

0 commit comments

Comments
 (0)