diff mbox series

[blktests,v2,2/2] zbd/007: Add zone mapping test for logical devices

Message ID 20190531015913.5560-3-shinichiro.kawasaki@wdc.com (mailing list archive)
State New, archived
Headers show
Series Test zone mapping of logical devices | expand

Commit Message

Shin'ichiro Kawasaki May 31, 2019, 1:59 a.m. UTC
Add the test case to check zones sector mapping of logical devices. This
test case requires that such a logical device be specified in TEST_DEVS
in config. The test is skipped for devices that are identified as not
logically created.

To test that the zone mapping is correct, select a few sequential write
required zones of the logical device and move the write pointers of
these zones through the container device of the logical device, using
the physical sector mapping of the zones. The write pointers position of
the selected zones is then checked through a zone report of the logical
device using the logical sector mapping of the zones. The test reports a
success if the position of the zone write pointers relative to the zone
start sector must be identical for both the logical and physical
locations of the zones.

Signed-off-by: Shin'ichiro Kawasaki <shinichiro.kawasaki@wdc.com>
---
 tests/zbd/007     | 110 ++++++++++++++++++++++++++++++++++++++++++++++
 tests/zbd/007.out |   2 +
 2 files changed, 112 insertions(+)
 create mode 100755 tests/zbd/007
 create mode 100644 tests/zbd/007.out

Comments

Chaitanya Kulkarni June 4, 2019, 10:13 p.m. UTC | #1
Looks good to me.

Reviewed-by: Chaitanya Kulkarni <chaitanya.kulkarni@wdc.com>
On 5/30/19 6:59 PM, Shin'ichiro Kawasaki wrote:
> Add the test case to check zones sector mapping of logical devices. This
> test case requires that such a logical device be specified in TEST_DEVS
> in config. The test is skipped for devices that are identified as not
> logically created.
>
> To test that the zone mapping is correct, select a few sequential write
> required zones of the logical device and move the write pointers of
> these zones through the container device of the logical device, using
> the physical sector mapping of the zones. The write pointers position of
> the selected zones is then checked through a zone report of the logical
> device using the logical sector mapping of the zones. The test reports a
> success if the position of the zone write pointers relative to the zone
> start sector must be identical for both the logical and physical
> locations of the zones.
>
> Signed-off-by: Shin'ichiro Kawasaki <shinichiro.kawasaki@wdc.com>
> ---
>  tests/zbd/007     | 110 ++++++++++++++++++++++++++++++++++++++++++++++
>  tests/zbd/007.out |   2 +
>  2 files changed, 112 insertions(+)
>  create mode 100755 tests/zbd/007
>  create mode 100644 tests/zbd/007.out
>
> diff --git a/tests/zbd/007 b/tests/zbd/007
> new file mode 100755
> index 0000000..b4dcbd8
> --- /dev/null
> +++ b/tests/zbd/007
> @@ -0,0 +1,110 @@
> +#!/bin/bash
> +# SPDX-License-Identifier: GPL-3.0+
> +# Copyright (C) 2019 Western Digital Corporation or its affiliates.
> +#
> +# Test zones are mapped correctly between a logical device and its container
> +# device. Move write pointers of sequential write required zones on the
> +# container devices, and confirm same write pointer positions of zones on the
> +# logical devices.
> +
> +. tests/zbd/rc
> +
> +DESCRIPTION="zone mapping between logical and container devices"
> +CAN_BE_ZONED=1
> +QUICK=1
> +
> +requires() {
> +	_have_program dmsetup
> +}
> +
> +device_requires() {
> +	_test_dev_is_logical
> +}
> +
> +# Select test target zones. Pick up the first sequential required zones. If
> +# available, add one or two more sequential required zones. One is at the last
> +# end of TEST_DEV. The other is in middle between the first and the last zones.
> +select_zones() {
> +	local -i zone_idx
> +	local -a zones
> +
> +	zone_idx=$(_find_first_sequential_zone) || return $?
> +	zones=( "${zone_idx}" )
> +	if zone_idx=$(_find_last_sequential_zone); then
> +		zones+=( "${zone_idx}" )
> +		if zone_idx=$(_find_sequential_zone_in_middle \
> +				      "${zones[0]}" "${zones[1]}"); then
> +			zones+=( "${zone_idx}" )
> +		fi
> +	fi
> +	echo "${zones[@]}"
> +}
> +
> +test_device() {
> +	local -i bs
> +	local -a test_z # test target zones
> +	local -a test_z_start
> +
> +	echo "Running ${TEST_NAME}"
> +
> +	# Get physical block size to meet zoned block device I/O requirement
> +	_get_sysfs_variable "${TEST_DEV}" || return $?
> +	bs=${SYSFS_VARS[SV_PHYS_BLK_SIZE]}
> +	_put_sysfs_variable
> +
> +	# Get test target zones
> +	_get_blkzone_report "${TEST_DEV}" || return $?
> +	read -r -a test_z < <(select_zones)
> +	for ((i = 0; i < ${#test_z[@]}; i++)); do
> +		test_z_start+=("${ZONE_STARTS[test_z[i]]}")
> +	done
> +	echo "${test_z[*]}" >> "$FULL"
> +	echo "${test_z_start[*]}" >> "$FULL"
> +	_put_blkzone_report
> +	if ((!${#test_z[@]})); then
> +		echo "Test target zones not available on ${TEST_DEV}"
> +		return 1
> +	fi
> +
> +	# Reset and move write pointers of the container device
> +	for ((i=0; i < ${#test_z[@]}; i++)); do
> +		local -a arr
> +
> +		read -r -a arr < <(_get_dev_container_and_sector \
> +					   "${test_z_start[i]}")
> +		container_dev="${arr[0]}"
> +		container_start="${arr[1]}"
> +
> +		echo "${container_dev}" "${container_start}" >> "$FULL"
> +
> +		if ! blkzone reset -o "${container_start}" -c 1 \
> +		     "${container_dev}"; then
> +			echo "Reset zone failed"
> +			return 1
> +		fi
> +
> +		if ! dd if=/dev/zero of="${container_dev}" bs="${bs}" \
> +		     count=$((4096 * (i + 1) / bs)) oflag=direct \
> +		     seek=$((container_start * 512 / bs)) \
> +		     >> "$FULL" 2>&1 ; then
> +			echo "dd failed"
> +		fi
> +
> +		# Wait for partition table re-read event settles
> +		udevadm settle
> +	done
> +
> +	# Check write pointer positions on the logical device
> +	_get_blkzone_report "${TEST_DEV}" || return $?
> +	for ((i=0; i < ${#test_z[@]}; i++)); do
> +		if ((ZONE_WPTRS[test_z[i]] != 8 * (i + 1))); then
> +			echo "Unexpected write pointer position"
> +			echo -n "zone=${i}, wp=${ZONE_WPTRS[i]}, "
> +			echo "dev=${TEST_DEV}"
> +		fi
> +		echo "${ZONE_WPTRS[${test_z[i]}]}" >> "$FULL"
> +	done
> +	_put_blkzone_report
> +
> +	echo "Test complete"
> +}
> diff --git a/tests/zbd/007.out b/tests/zbd/007.out
> new file mode 100644
> index 0000000..28a1395
> --- /dev/null
> +++ b/tests/zbd/007.out
> @@ -0,0 +1,2 @@
> +Running zbd/007
> +Test complete
Omar Sandoval June 5, 2019, 9:53 p.m. UTC | #2
On Fri, May 31, 2019 at 10:59:13AM +0900, Shin'ichiro Kawasaki wrote:
> Add the test case to check zones sector mapping of logical devices. This
> test case requires that such a logical device be specified in TEST_DEVS
> in config. The test is skipped for devices that are identified as not
> logically created.
> 
> To test that the zone mapping is correct, select a few sequential write
> required zones of the logical device and move the write pointers of
> these zones through the container device of the logical device, using
> the physical sector mapping of the zones. The write pointers position of
> the selected zones is then checked through a zone report of the logical
> device using the logical sector mapping of the zones. The test reports a
> success if the position of the zone write pointers relative to the zone
> start sector must be identical for both the logical and physical
> locations of the zones.
> 
> Signed-off-by: Shin'ichiro Kawasaki <shinichiro.kawasaki@wdc.com>
> ---
>  tests/zbd/007     | 110 ++++++++++++++++++++++++++++++++++++++++++++++
>  tests/zbd/007.out |   2 +
>  2 files changed, 112 insertions(+)
>  create mode 100755 tests/zbd/007
>  create mode 100644 tests/zbd/007.out
> 
> diff --git a/tests/zbd/007 b/tests/zbd/007
> new file mode 100755
> index 0000000..b4dcbd8
> --- /dev/null
> +++ b/tests/zbd/007
> @@ -0,0 +1,110 @@
> +#!/bin/bash
> +# SPDX-License-Identifier: GPL-3.0+
> +# Copyright (C) 2019 Western Digital Corporation or its affiliates.
> +#
> +# Test zones are mapped correctly between a logical device and its container
> +# device. Move write pointers of sequential write required zones on the
> +# container devices, and confirm same write pointer positions of zones on the
> +# logical devices.
> +
> +. tests/zbd/rc
> +
> +DESCRIPTION="zone mapping between logical and container devices"
> +CAN_BE_ZONED=1
> +QUICK=1
> +
> +requires() {
> +	_have_program dmsetup
> +}

Looks like this test doesn't have a fallback device, so I can't run it
here. Is that intentional, or was it just overlooked?

> +device_requires() {
> +	_test_dev_is_logical
> +}
Shin'ichiro Kawasaki June 7, 2019, 5:04 a.m. UTC | #3
On 6/6/19 6:53 AM, Omar Sandoval wrote:
> On Fri, May 31, 2019 at 10:59:13AM +0900, Shin'ichiro Kawasaki wrote:
>> Add the test case to check zones sector mapping of logical devices. This
>> test case requires that such a logical device be specified in TEST_DEVS
>> in config. The test is skipped for devices that are identified as not
>> logically created.
>>
>> To test that the zone mapping is correct, select a few sequential write
>> required zones of the logical device and move the write pointers of
>> these zones through the container device of the logical device, using
>> the physical sector mapping of the zones. The write pointers position of
>> the selected zones is then checked through a zone report of the logical
>> device using the logical sector mapping of the zones. The test reports a
>> success if the position of the zone write pointers relative to the zone
>> start sector must be identical for both the logical and physical
>> locations of the zones.
>>
>> Signed-off-by: Shin'ichiro Kawasaki <shinichiro.kawasaki@wdc.com>
>> ---
>>   tests/zbd/007     | 110 ++++++++++++++++++++++++++++++++++++++++++++++
>>   tests/zbd/007.out |   2 +
>>   2 files changed, 112 insertions(+)
>>   create mode 100755 tests/zbd/007
>>   create mode 100644 tests/zbd/007.out
>>
>> diff --git a/tests/zbd/007 b/tests/zbd/007
>> new file mode 100755
>> index 0000000..b4dcbd8
>> --- /dev/null
>> +++ b/tests/zbd/007
>> @@ -0,0 +1,110 @@
>> +#!/bin/bash
>> +# SPDX-License-Identifier: GPL-3.0+
>> +# Copyright (C) 2019 Western Digital Corporation or its affiliates.
>> +#
>> +# Test zones are mapped correctly between a logical device and its container
>> +# device. Move write pointers of sequential write required zones on the
>> +# container devices, and confirm same write pointer positions of zones on the
>> +# logical devices.
>> +
>> +. tests/zbd/rc
>> +
>> +DESCRIPTION="zone mapping between logical and container devices"
>> +CAN_BE_ZONED=1
>> +QUICK=1
>> +
>> +requires() {
>> +	_have_program dmsetup
>> +}
> 
> Looks like this test doesn't have a fallback device, so I can't run it
> here. Is that intentional, or was it just overlooked?
> 
>> +device_requires() {
>> +	_test_dev_is_logical
>> +}

Zone logical remapping is necessary only and only if the target device is not
the raw entire block device, that is, if the target is a partition block device,
a DM device mapping only a portion of the backend disk, or a combination of
both. When the target device is an entire raw block device, zone remapping
(shifting of zone start and zone write pointer position) is not necessary at
all. If we add a fallback device, the test will still run, but will end up being
a test for a straight report zones, which is already covered by test zbd/002. So 
we thought it not necessary to add here.

This test is rather intended at catching complex zone remapping problems like we
had in the past already: see commit 9864cd5dc54c "dm: fix report zone remapping 
to account for partition offset".
diff mbox series

Patch

diff --git a/tests/zbd/007 b/tests/zbd/007
new file mode 100755
index 0000000..b4dcbd8
--- /dev/null
+++ b/tests/zbd/007
@@ -0,0 +1,110 @@ 
+#!/bin/bash
+# SPDX-License-Identifier: GPL-3.0+
+# Copyright (C) 2019 Western Digital Corporation or its affiliates.
+#
+# Test zones are mapped correctly between a logical device and its container
+# device. Move write pointers of sequential write required zones on the
+# container devices, and confirm same write pointer positions of zones on the
+# logical devices.
+
+. tests/zbd/rc
+
+DESCRIPTION="zone mapping between logical and container devices"
+CAN_BE_ZONED=1
+QUICK=1
+
+requires() {
+	_have_program dmsetup
+}
+
+device_requires() {
+	_test_dev_is_logical
+}
+
+# Select test target zones. Pick up the first sequential required zones. If
+# available, add one or two more sequential required zones. One is at the last
+# end of TEST_DEV. The other is in middle between the first and the last zones.
+select_zones() {
+	local -i zone_idx
+	local -a zones
+
+	zone_idx=$(_find_first_sequential_zone) || return $?
+	zones=( "${zone_idx}" )
+	if zone_idx=$(_find_last_sequential_zone); then
+		zones+=( "${zone_idx}" )
+		if zone_idx=$(_find_sequential_zone_in_middle \
+				      "${zones[0]}" "${zones[1]}"); then
+			zones+=( "${zone_idx}" )
+		fi
+	fi
+	echo "${zones[@]}"
+}
+
+test_device() {
+	local -i bs
+	local -a test_z # test target zones
+	local -a test_z_start
+
+	echo "Running ${TEST_NAME}"
+
+	# Get physical block size to meet zoned block device I/O requirement
+	_get_sysfs_variable "${TEST_DEV}" || return $?
+	bs=${SYSFS_VARS[SV_PHYS_BLK_SIZE]}
+	_put_sysfs_variable
+
+	# Get test target zones
+	_get_blkzone_report "${TEST_DEV}" || return $?
+	read -r -a test_z < <(select_zones)
+	for ((i = 0; i < ${#test_z[@]}; i++)); do
+		test_z_start+=("${ZONE_STARTS[test_z[i]]}")
+	done
+	echo "${test_z[*]}" >> "$FULL"
+	echo "${test_z_start[*]}" >> "$FULL"
+	_put_blkzone_report
+	if ((!${#test_z[@]})); then
+		echo "Test target zones not available on ${TEST_DEV}"
+		return 1
+	fi
+
+	# Reset and move write pointers of the container device
+	for ((i=0; i < ${#test_z[@]}; i++)); do
+		local -a arr
+
+		read -r -a arr < <(_get_dev_container_and_sector \
+					   "${test_z_start[i]}")
+		container_dev="${arr[0]}"
+		container_start="${arr[1]}"
+
+		echo "${container_dev}" "${container_start}" >> "$FULL"
+
+		if ! blkzone reset -o "${container_start}" -c 1 \
+		     "${container_dev}"; then
+			echo "Reset zone failed"
+			return 1
+		fi
+
+		if ! dd if=/dev/zero of="${container_dev}" bs="${bs}" \
+		     count=$((4096 * (i + 1) / bs)) oflag=direct \
+		     seek=$((container_start * 512 / bs)) \
+		     >> "$FULL" 2>&1 ; then
+			echo "dd failed"
+		fi
+
+		# Wait for partition table re-read event settles
+		udevadm settle
+	done
+
+	# Check write pointer positions on the logical device
+	_get_blkzone_report "${TEST_DEV}" || return $?
+	for ((i=0; i < ${#test_z[@]}; i++)); do
+		if ((ZONE_WPTRS[test_z[i]] != 8 * (i + 1))); then
+			echo "Unexpected write pointer position"
+			echo -n "zone=${i}, wp=${ZONE_WPTRS[i]}, "
+			echo "dev=${TEST_DEV}"
+		fi
+		echo "${ZONE_WPTRS[${test_z[i]}]}" >> "$FULL"
+	done
+	_put_blkzone_report
+
+	echo "Test complete"
+}
diff --git a/tests/zbd/007.out b/tests/zbd/007.out
new file mode 100644
index 0000000..28a1395
--- /dev/null
+++ b/tests/zbd/007.out
@@ -0,0 +1,2 @@ 
+Running zbd/007
+Test complete