Add a test that triggers the blk_mq_realloc_hw_ctxs() error path
v2 cover Add a test that triggers the blk_mq_realloc_hw_ctxs() error path
Hi Omar,
Please consider this patch series for the upstream blktests repository.
Compared to v1, three patches have been added that refactor null_blk loading, unloading and configuration.
Thanks,
Bart.
Bart Van Assche (4):
Make _exit_null_blk remove all null_blk device instances Use _{init,exit}_null_blk instead of open-coding these functions Introduce the function _configure_null_blk()
Add a test that triggers the blk_mq_realloc_hw_ctxs() error path
common/multipath-over-rdma | 29 ++++++++------------------ common/null_blk | 26 +++++++++++++++++++---- tests/block/022 | 3 --- tests/block/029 | 17 ++------------- tests/block/030 | 42 ++++++++++++++++++++++++++++++++++++++ tests/block/030.out | 1 + tests/nvmeof-mp/rc | 2 +- 7 files changed, 76 insertions(+), 44 deletions(-) create mode 100755 tests/block/030 create mode 100644 tests/block/030.out
PATCH v2 1/4 Make _exit_null_blk remove all null_blk device instances
Instead of making every test remove null_blk device instances before calling _exit_null_blk(), move the null_blk device instance removal code into _exit_null_blk().
--- common/null_blk | 12 ++++++++---- tests/block/022 | 3 --- tests/block/029 | 1 - 3 files changed, 8 insertions(+), 8 deletions(-)
common/null_blk +8 -4
@@ -8,11 +8,14 @@ _have_null_blk() { _have_modules null_blk } +_remove_null_blk_devices() { + local d + + for d in /sys/kernel/config/nullb/*; do [ -d "$d" ] && rmdir "$d"; done +} + _init_null_blk() { - if [[ -d /sys/kernel/config/nullb ]]; then - find /sys/kernel/config/nullb -mindepth 1 -maxdepth 1 \ - -type d -delete - fi + _remove_null_blk_devices local zoned="" if (( RUN_FOR_ZONED )); then zoned="zoned=1"; fi
@@ -27,5 +30,6 @@ _init_null_blk() { _exit_null_blk() { udevadm settle + _remove_null_blk_devices modprobe -r null_blk }
tests/block/022 +0 -3
@@ -50,9 +50,6 @@ test() { wait $pid1 } 2>/dev/null - rmdir /sys/kernel/config/nullb/1 - rmdir /sys/kernel/config/nullb/0 - _exit_null_blk echo "Test complete" }
tests/block/029 +0 -1
@@ -58,7 +58,6 @@ test() { else echo "Skipping test because $sq cannot be modified" >>"$FULL" fi - rmdir /sys/kernel/config/nullb/nullb0 _exit_null_blk echo Passed }
Re: [PATCH blktests v2 1/4] Make _exit_null_blk remove all null_blk device instances
Looks good, except the commit log is > 80 char, can be fixed at the time of applying the patch.
Quoted 5 lines · Bart Van Assche
Instead of making every test remove
null_blkdevice instances before calling_exit_null_blk(), move thenull_blkdevice instance removal code into_exit_null_blk().Signed-off-by Bart Van Assche<[email protected]>
Re: [PATCH blktests v2 1/4] Make _exit_null_blk remove all null_blk device instances
Quoted 4 lines · Chaitanya Kulkarni
Looks good, except the commit log is > 80 char, can be fixed at the time of applying the patch.
Reviewed-by Chaitanya Kulkarni <[email protected]>
Thanks for the reviews, but I have two comments:
* The commit message is only 76 characters wide.
* Please do not top-post. From https://en.wikipedia.org/wiki/Posting_style:
A: Because it messes up the order in which people normally read text.
Q: Why is top-posting such a bad thing?
A: Top-posting.
Q: What is the most annoying thing in e-mail?
Thanks,
Bart.
Re: [PATCH blktests v2 1/4] Make _exit_null_blk remove all null_blk device instances
In reply to Bart Van AsscheQuoted 16 lines · Bart Van Assche
Instead of making every test remove
null_blkdevice instances before calling_exit_null_blk(), move thenull_blkdevice instance removal code into_exit_null_blk().Signed-off-by Bart Van Assche <[email protected]>--- common/null_blk | 12 ++++++++---- tests/block/022 | 3 --- tests/block/029 | 1 - 3 files changed, 8 insertions(+), 8 deletions(-)common/null_blk +0
-0
common/null_blk _have_null_blk() { · line 14
Quoted 7 lines
common/null_blk +4
-0@@ -8,11 +8,14 @@ _have_null_blk() { _have_modules null_blk } +_remove_null_blk_devices() { + local d + + for d in /sys/kernel/config/nullb/*; do [ -d "$d" ] && rmdir "$d"; done
I'd prefer to keep the deletion code using find from _init_null_blk.
Quoted 12 lines
common/null_blk +3
-4+} + _init_null_blk() { - if [[ -d /sys/kernel/config/nullb ]]; then - find /sys/kernel/config/nullb -mindepth 1 -maxdepth 1 \ - -type d -delete - fi + _remove_null_blk_devices local zoned="" if (( RUN_FOR_ZONED )); then zoned="zoned=1"; fi
common/null_blk _init_null_blk() { · line 33
Quoted 4 lines
common/null_blk +1
-0@@ -27,5 +30,6 @@ _init_null_blk() { _exit_null_blk() { udevadm settle + _remove_null_blk_devices
This needs to happen before the udevadm settle.
PATCH v2 2/4 Use _{init,exit}_null_blk instead of open-coding these functions
In reply to Bart Van AsscheThis patch reduces code duplication.
--- common/multipath-over-rdma | 12 +++--------- tests/nvmeof-mp/rc | 2 +- 2 files changed, 4 insertions(+), 10 deletions(-)
common/multipath-over-rdma +3 -9
@@ -5,6 +5,7 @@ # Functions and global variables used by both the srp and nvmeof-mp tests. . common/shellcheck +. common/null_blk debug= filesystem_type=ext4
@@ -634,13 +635,6 @@ configure_null_blk() { ls -l /dev/nullb* &>>"$FULL" } -unload_null_blk() { - local d - - for d in /sys/kernel/config/nullb/*; do [ -d "$d" ] && rmdir "$d"; done - unload_module null_blk -} - setup_rdma() { start_soft_rdma (
@@ -662,7 +656,7 @@ teardown_uncond() { rm -f /etc/multipath.conf stop_target stop_soft_rdma - unload_null_blk + _exit_null_blk } teardown() {
@@ -698,7 +692,7 @@ setup_test() { [ -e "/sys/module/$m" ] || modprobe "$m" || return $? done - modprobe null_blk nr_devices=0 || return $? + _init_null_blk nr_devices=0 || return $? configure_null_blk || return $?
tests/nvmeof-mp/rc +1 -1
@@ -278,7 +278,7 @@ stop_nvme_target() { ) unload_module nvmet_rdma && unload_module nvmet && - unload_null_blk + _exit_null_blk } start_target() {
Re: [PATCH blktests v2 2/4] Use _{init,exit}_null_blk instead of open-coding these functions
LGTM.
Quoted 3 lines · Bart Van Assche
This patch reduces code duplication.
Signed-off-by Bart Van Assche<[email protected]>
PATCH v2 3/4 Introduce the function _configure_null_blk()
In reply to Bart Van AsscheIntroduce a function for creating a null_blk device instance through configfs.
--- common/multipath-over-rdma | 17 +++++------------ common/null_blk | 14 ++++++++++++++ tests/block/029 | 16 ++-------------- 3 files changed, 21 insertions(+), 26 deletions(-)
common/multipath-over-rdma +5 -12
@@ -620,18 +620,11 @@ run_fio() { configure_null_blk() { local i - ( - cd /sys/kernel/config/nullb || return $? - for i in nullb0 nullb1; do ( - { mkdir -p $i && - cd $i && - echo 0 > completion_nsec && - echo 512 > blocksize && - echo $((ramdisk_size>>20)) > size && - echo 1 > memory_backed && - echo 1 > power; } || exit $? - ) done - ) + for i in nullb0 nullb1; do + _configure_null_blk nullb$i completion_nsec=0 blocksize=512 \ + size=$((ramdisk_size>>20)) memory_backed=1 \ + power=1 || return $? + done ls -l /dev/nullb* &>>"$FULL" }
common/null_blk +14 -0
@@ -28,6 +28,20 @@ _init_null_blk() { return 0 } +# Configure one null_blk instance with name $1 and parameters $2..${$#}. +_configure_null_blk() { + local nullb=/sys/kernel/config/nullb/$1 param val + + shift + mkdir "$nullb" && + while [ -n "$1" ]; do + param="${1//=*}" + val="${1#${param}=}" + shift + echo "$val" > "$nullb/$param" || return $? + done +} + _exit_null_blk() { udevadm settle _remove_null_blk_devices
tests/block/029 +2 -14
@@ -14,19 +14,6 @@ requires() { _have_null_blk } -# Configure one null_blk instance. -configure_null_blk() { - local nullb0="/sys/kernel/config/nullb/nullb0" - - mkdir "$nullb0" && - echo 0 > "$nullb0/completion_nsec" && - echo 512 > "$nullb0/blocksize" && - echo 16 > "$nullb0/size" && - echo 1 > "$nullb0/memory_backed" && - echo 1 > "$nullb0/power" && - ls -l /dev/nullb* &>>"$FULL" -} - modify_nr_hw_queues() { local deadline num_cpus
@@ -45,7 +32,8 @@ test() { : "${TIMEOUT:=30}" _init_null_blk nr_devices=0 queue_mode=2 && - configure_null_blk + _configure_null_blk nullb0 completion_nsec=0 blocksize=512 \ + size=16 memory_backed=1 power=1 && if { echo 1 >$sq; } 2>/dev/null; then modify_nr_hw_queues & fio --rw=randwrite --bs=4K --loops=$((10**6)) \
Re: [PATCH blktests v2 3/4] Introduce the function _configure_null_blk()
LGTM.
Quoted 5 lines · Bart Van Assche
Introduce a function for creating a
null_blkdevice instance through configfs.Suggested-by Chaitanya Kulkarni<[email protected]>Signed-off-by Bart Van Assche<[email protected]>
Re: [PATCH blktests v2 3/4] Introduce the function _configure_null_blk()
In reply to Bart Van AsscheQuoted 44 lines · Bart Van Assche
Introduce a function for creating a
null_blkdevice instance through configfs.Suggested-by Chaitanya Kulkarni <[email protected]>Signed-off-by Bart Van Assche <[email protected]>--- common/multipath-over-rdma | 17 +++++------------ common/null_blk | 14 ++++++++++++++ tests/block/029 | 16 ++-------------- 3 files changed, 21 insertions(+), 26 deletions(-)common/multipath-over-rdma +5
-12@@ -620,18 +620,11 @@ run_fio() { configure_null_blk() { local i - ( - cd /sys/kernel/config/nullb || return $? - for i in nullb0 nullb1; do ( - { mkdir -p $i && - cd $i && - echo 0 > completion_nsec && - echo 512 > blocksize && - echo $((ramdisk_size>>20)) > size && - echo 1 > memory_backed && - echo 1 > power; } || exit $? - ) done - ) + for i in nullb0 nullb1; do + _configure_null_blk nullb$i completion_nsec=0 blocksize=512 \ + size=$((ramdisk_size>>20)) memory_backed=1 \ + power=1 || return $? + done ls -l /dev/nullb* &>>"$FULL" }common/null_blk +0
-0
common/null_blk _init_null_blk() { · line 36
Quoted 9 lines
common/null_blk +6
-0@@ -28,6 +28,20 @@ _init_null_blk() { return 0 } +# Configure one null_blk instance with name $1 and parameters $2..${$#}. +_configure_null_blk() { + local nullb=/sys/kernel/config/nullb/$1 param val + + shift + mkdir "$nullb" &&
Just make this mkdir "$nullb" || return $?
common/null_blk _init_null_blk() { · line 37
Quoted 1 line
common/null_blk +1
-0+ while [ -n "$1" ]; do
The intention is clearer with while [[ $# > 0 ]]
common/null_blk _init_null_blk() { · line 39
Quoted 2 lines
common/null_blk +2
-0+ param="${1//=*}" + val="${1#${param}=}"
These are all arcane bash incantations, but the following seem slighly clearer to me:
param="${1%%=*}"
val="${1#*=}"
I.e., for param we remove the equal sign and everything after it, and for val we remove everything up to the equal sign.
Quoted 5 lines
common/null_blk +5
-0+ shift + echo "$val" > "$nullb/$param" || return $? + done +} +
PATCH v2 4/4 Add a test that triggers the blk_mq_realloc_hw_ctxs() error path
In reply to Bart Van AsscheAdd a test that triggers the code touched by commit d0930bb8f46b ("blk-mq:
Fix a recently introduced regression in blk_mq_realloc_hw_ctxs()"). This test only runs if a recently added fault injection feature is available, namely commit 596444e75705 ("null_blk: Add support for init_hctx() fault injection").
--- tests/block/030 | 42 ++++++++++++++++++++++++++++++++++++++++++ tests/block/030.out | 1 + 2 files changed, 43 insertions(+) create mode 100755 tests/block/030 create mode 100644 tests/block/030.out
tests/block/030 new file +42 -0
@@ -0,0 +1,42 @@ +#!/bin/bash +# SPDX-License-Identifier: GPL-2.0 +# Copyright 2020 Google LLC +# +# Trigger the blk_mq_realloc_hw_ctxs() error path. + +. tests/block/rc +. common/null_blk + +DESCRIPTION="trigger the blk_mq_realloc_hw_ctxs() error path" +QUICK=1 + +requires() { + _have_null_blk || return $? + _have_module_param null_blk init_hctx || return $? +} + +test() { + local i sq=/sys/kernel/config/nullb/nullb0/submit_queues + + : "${TIMEOUT:=30}" + if ! _init_null_blk nr_devices=0 queue_mode=2 "init_hctx=$(nproc),100,0,0"; then + echo "Loading null_blk failed" + return 1 + fi + if ! _configure_null_blk nullb0 completion_nsec=0 blocksize=512 size=16\ + submit_queues="$(nproc)" memory_backed=1 power=1; then + echo "Configuring null_blk failed" + return 1 + fi + if { echo "$(<"$sq")" >$sq; } 2>/dev/null; then + for ((i=0;i<100;i++)); do + echo 1 >$sq + nproc >$sq + done + else + echo "Skipping test because $sq cannot be modified" >>"$FULL" + fi + rmdir /sys/kernel/config/nullb/nullb0 + _exit_null_blk + echo Passed +}
tests/block/030.out new file +1 -0
@@ -0,0 +1 @@ +Passed
LGTM.
Quoted 8 lines · Bart Van Assche
Add a test that triggers the code touched by commit
d0930bb8f46b("blk-mq:
Fix a recently introduced regression inblk_mq_realloc_hw_ctxs()"). This test only runs if a recently added fault injection feature is available, namely commit596444e75705("null_blk: Add support forinit_hctx()fault injection").Cc Ming Lei<[email protected]>Signed-off-by Bart Van Assche<[email protected]>
Quoted 48 lines · Bart Van Assche
Add a test that triggers the code touched by commit
d0930bb8f46b("blk-mq:
Fix a recently introduced regression inblk_mq_realloc_hw_ctxs()"). This test only runs if a recently added fault injection feature is available, namely commit596444e75705("null_blk: Add support forinit_hctx()fault injection").Cc Ming Lei <[email protected]>Signed-off-by Bart Van Assche <[email protected]>--- tests/block/030 | 42 ++++++++++++++++++++++++++++++++++++++++++ tests/block/030.out | 1 + 2 files changed, 43 insertions(+) create mode 100755 tests/block/030 create mode 100644 tests/block/030.outtests/block/030 new file +27
-0@@ -0,0 +1,42 @@ +#!/bin/bash +# SPDX-License-Identifier: GPL-2.0 +# Copyright 2020 Google LLC +# +# Trigger the blk_mq_realloc_hw_ctxs() error path. + +. tests/block/rc +. common/null_blk + +DESCRIPTION="trigger the blk_mq_realloc_hw_ctxs() error path" +QUICK=1 + +requires() { + _have_null_blk || return $? + _have_module_param null_blk init_hctx || return $? +} + +test() { + local i sq=/sys/kernel/config/nullb/nullb0/submit_queues + + : "${TIMEOUT:=30}" + if ! _init_null_blk nr_devices=0 queue_mode=2 "init_hctx=$(nproc),100,0,0"; then + echo "Loading null_blk failed" + return 1 + fi + if ! _configure_null_blk nullb0 completion_nsec=0 blocksize=512 size=16\ + submit_queues="$(nproc)" memory_backed=1 power=1; then
tests/block/030 line 37
Quoted 10 lines
tests/block/030 new file +10
-0+ echo "Configuring null_blk failed" + return 1 + fi + if { echo "$(<"$sq")" >$sq; } 2>/dev/null; then + for ((i=0;i<100;i++)); do + echo 1 >$sq + nproc >$sq + done + else + echo "Skipping test because $sq cannot be modified" >>"$FULL"
I just pushed the support for allowing skipping from the middle of a test, so now you could make this
SKIP_REASON="Skipping test because $sq cannot be modified"
Quoted 12 lines
tests/block/030 new file +5
-0+ fi + rmdir /sys/kernel/config/nullb/nullb0 + _exit_null_blk + echo Passed +}tests/block/030.out new file +1
-0@@ -0,0 +1 @@ +Passed
Quoted 63 lines · Omar Sandoval
Quoted 48 lines · Bart Van Assche
Add a test that triggers the code touched by commit
d0930bb8f46b("blk-mq:
Fix a recently introduced regression inblk_mq_realloc_hw_ctxs()"). This test only runs if a recently added fault injection feature is available, namely commit596444e75705("null_blk: Add support forinit_hctx()fault injection").Cc Ming Lei <[email protected]>Signed-off-by Bart Van Assche <[email protected]>--- tests/block/030 | 42 ++++++++++++++++++++++++++++++++++++++++++ tests/block/030.out | 1 + 2 files changed, 43 insertions(+) create mode 100755 tests/block/030 create mode 100644 tests/block/030.outtests/block/030 new file +27
-0@@ -0,0 +1,42 @@ +#!/bin/bash +# SPDX-License-Identifier: GPL-2.0 +# Copyright 2020 Google LLC +# +# Trigger the blk_mq_realloc_hw_ctxs() error path. + +. tests/block/rc +. common/null_blk + +DESCRIPTION="trigger the blk_mq_realloc_hw_ctxs() error path" +QUICK=1 + +requires() { + _have_null_blk || return $? + _have_module_param null_blk init_hctx || return $? +} + +test() { + local i sq=/sys/kernel/config/nullb/nullb0/submit_queues + + : "${TIMEOUT:=30}" + if ! _init_null_blk nr_devices=0 queue_mode=2 "init_hctx=$(nproc),100,0,0"; then + echo "Loading null_blk failed" + return 1 + fi + if ! _configure_null_blk nullb0 completion_nsec=0 blocksize=512 size=16\ + submit_queues="$(nproc)" memory_backed=1 power=1; thentests/block/030 line 37
Quoted 10 lines
tests/block/030 new file +10
-0+ echo "Configuring null_blk failed" + return 1 + fi + if { echo "$(<"$sq")" >$sq; } 2>/dev/null; then + for ((i=0;i<100;i++)); do + echo 1 >$sq + nproc >$sq + done + else + echo "Skipping test because $sq cannot be modified" >>"$FULL"I just pushed the support for allowing skipping from the middle of a test, so now you could make this
Quoted 2 lines
SKIP_REASON="Skipping test because $sq cannot be modified"
Hi Omar,
I noticed the commit cd11d001fe86 ("Support skipping tests from test{,_device}()") have side effects to some test cases. The unexpected run result "not run" is reported to test cases as follows:
- block/005 ... for non-rotational drives such as nullb
- zbd/00[1-5]
- zbd/007 ... for dm-linear device
Some helper functions _test_dev_is_rotational, _test_dev_is_partition or so are called within test_device() context, and left SKIP_REASON with values. It resulted in the "not run" result.
To fix this, I can think of two approaches. One is to unset SKIP_REASON after calling _test_dev_is_X helper functions within the test cases affected. This fix is straight forward but it will require similar care for future test case additions and changes. The other approach is to flag the test cases which judge skip during test run. For example, SKIP_DURING_RUN=1 can be defined in those test cases (block/030). The check script validates SKIP_REASON only if the test case is flagged. This second approach looks less costly for me.
Please let me know your thoughts about the fix approach. Thanks!
Signature · 2 lines
Best Regards, Shin'ichiro Kawasaki
Quoted 89 lines · Shinichiro Kawasaki
Quoted 63 lines · Omar Sandoval
Quoted 48 lines · Bart Van Assche
Add a test that triggers the code touched by commit
d0930bb8f46b("blk-mq:
Fix a recently introduced regression inblk_mq_realloc_hw_ctxs()"). This test only runs if a recently added fault injection feature is available, namely commit596444e75705("null_blk: Add support forinit_hctx()fault injection").Cc Ming Lei <[email protected]>Signed-off-by Bart Van Assche <[email protected]>--- tests/block/030 | 42 ++++++++++++++++++++++++++++++++++++++++++ tests/block/030.out | 1 + 2 files changed, 43 insertions(+) create mode 100755 tests/block/030 create mode 100644 tests/block/030.outtests/block/030 new file +27
-0@@ -0,0 +1,42 @@ +#!/bin/bash +# SPDX-License-Identifier: GPL-2.0 +# Copyright 2020 Google LLC +# +# Trigger the blk_mq_realloc_hw_ctxs() error path. + +. tests/block/rc +. common/null_blk + +DESCRIPTION="trigger the blk_mq_realloc_hw_ctxs() error path" +QUICK=1 + +requires() { + _have_null_blk || return $? + _have_module_param null_blk init_hctx || return $? +} + +test() { + local i sq=/sys/kernel/config/nullb/nullb0/submit_queues + + : "${TIMEOUT:=30}" + if ! _init_null_blk nr_devices=0 queue_mode=2 "init_hctx=$(nproc),100,0,0"; then + echo "Loading null_blk failed" + return 1 + fi + if ! _configure_null_blk nullb0 completion_nsec=0 blocksize=512 size=16\ + submit_queues="$(nproc)" memory_backed=1 power=1; thentests/block/030 line 37
Quoted 10 lines
tests/block/030 new file +10
-0+ echo "Configuring null_blk failed" + return 1 + fi + if { echo "$(<"$sq")" >$sq; } 2>/dev/null; then + for ((i=0;i<100;i++)); do + echo 1 >$sq + nproc >$sq + done + else + echo "Skipping test because $sq cannot be modified" >>"$FULL"I just pushed the support for allowing skipping from the middle of a test, so now you could make this
Quoted 2 lines
SKIP_REASON="Skipping test because $sq cannot be modified"
Hi Omar,
I noticed the commit
cd11d001fe86("Support skipping tests from test{,_device}()") have side effects to some test cases. The unexpected run result "not run" is reported to test cases as follows:- block/005 ... for non-rotational drives such as nullb
- zbd/00[1-5]
- zbd/007 ... for dm-linear deviceSome helper functions
_test_dev_is_rotational,_test_dev_is_partitionor so are called withintest_device()context, and leftSKIP_REASONwith values. It resulted in the "not run" result.To fix this, I can think of two approaches. One is to unset
SKIP_REASONafter calling_test_dev_is_Xhelper functions within the test cases affected. This fix is straight forward but it will require similar care for future test case additions and changes. The other approach is to flag the test cases which judge skip during test run. For example, SKIP_DURING_RUN=1 can be defined in those test cases (block/030). The check script validatesSKIP_REASONonly if the test case is flagged. This second approach looks less costly for me.
Quoted 1 line
Please let me know your thoughts about the fix approach. Thanks!
Now I found that Klaus Jensen already reported this and posted his fix patch. My report was not necessary. Sorry about this noise.
Signature · 2 lines
Best Regards, Shin'ichiro Kawasaki