diff mbox series

[blktests,3/6] common/{rc,dm}: introduce functions to set scheduler of dm destinations

Message ID 20230719071510.530623-4-shinichiro.kawasaki@wdc.com (mailing list archive)
State New, archived
Headers show
Series fix failures with bio based device-mapper | expand

Commit Message

Shinichiro Kawasaki July 19, 2023, 7:15 a.m. UTC
Since version v6.5, kernel no longer provides scheduler sysfs attribute
of bio based device-mapper. If TEST_DEV is a bio based device-mapper and
the test case requires specific scheduler, it is required to modify
sysfs attributes of destination devices instead of TEST_DEV.

To set scheduler to the sysfs attribute of destination devices, add the
helper function _dm_destination_dev_set_scheduler. It saves the original
scheduler value in the associative array SYSFS_QUEUE_SAVED so that it is
restored at each test case end. Also add _test_dev_set_scheduler which
sets scheduler regardless whether TEST_DEV is a bio based device-mapper
or not.

Signed-off-by: Shin'ichiro Kawasaki <shinichiro.kawasaki@wdc.com>
---
 common/dm | 21 +++++++++++++++++++++
 common/rc |  9 +++++++++
 2 files changed, 30 insertions(+)
diff mbox series

Patch

diff --git a/common/dm b/common/dm
index 85e1ed9..14f4265 100644
--- a/common/dm
+++ b/common/dm
@@ -21,3 +21,24 @@  _get_dev_path_by_id() {
 	done
 	return 1
 }
+
+_dm_destination_dev_set_scheduler() {
+	local dest_dev_id dest_dev path
+
+	while read -r dest_dev_id; do
+		if ! dest_dev=$(_get_dev_path_by_id "${dest_dev_id}"); then
+			continue
+		fi
+		path=${dest_dev/dev/sys\/block}/queue/scheduler
+		if [[ ! -w ${path} ]]; then
+			echo "Can not set scheduler of device mapper destination: ${dest_dev}"
+			continue
+		fi
+		if [[ ${SYSFS_QUEUE_SAVED["$path"]-unset} == unset ]]; then
+			SYSFS_QUEUE_SAVED["$path"]="$(sed \
+					-e 's/.*\[//' -e 's/\].*//' "${path}")"
+		fi
+		echo "${1}" > "${path}"
+	done < <(dmsetup table "$(<"${TEST_DEV_SYSFS}/dm/name")" |
+			 sed -n  's/.* \([0-9]*:[0-9]*\).*/\1/p')
+}
diff --git a/common/rc b/common/rc
index 4984100..52d1602 100644
--- a/common/rc
+++ b/common/rc
@@ -10,6 +10,7 @@  shopt -s extglob
 # Include fio helpers by default.
 . common/fio
 . common/cgroup
+. common/dm
 
 # If a test runs multiple "subtests", then each subtest should typically run
 # for TIMEOUT / number of subtests.
@@ -294,6 +295,14 @@  _test_dev_queue_set() {
 	echo "$2" >"$path"
 }
 
+_test_dev_set_scheduler() {
+	if [[ -w "${TEST_DEV_SYSFS}/queue/scheduler" ]]; then
+		_test_dev_queue_set scheduler "$1"
+	elif _test_dev_is_dm; then
+		_dm_destination_dev_set_scheduler "$1"
+	fi
+}
+
 _require_test_dev_is_pci() {
 	if ! readlink -f "$TEST_DEV_SYSFS/device" | grep -q pci; then
 		# nvme needs some special casing