From patchwork Fri Jun 7 12:19:54 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shin'ichiro Kawasaki X-Patchwork-Id: 10981599 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 3BAFC15E6 for ; Fri, 7 Jun 2019 12:20:00 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2999426419 for ; Fri, 7 Jun 2019 12:20:00 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 1D5C428B30; Fri, 7 Jun 2019 12:20:00 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.7 required=2.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 99CAC26419 for ; Fri, 7 Jun 2019 12:19:59 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728315AbfFGMT7 (ORCPT ); Fri, 7 Jun 2019 08:19:59 -0400 Received: from esa1.hgst.iphmx.com ([68.232.141.245]:58140 "EHLO esa1.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727762AbfFGMT6 (ORCPT ); Fri, 7 Jun 2019 08:19:58 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1559909998; x=1591445998; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=bYBbw4Ktuqi2MnClo3f1wC1CF0Ikk7vhFh53ZZllDco=; b=F32VfgnDEoL0Q3+4wotZBfUQ6BkQTNZ9BiGyFxekHFkK/P6o9ffJYxKy IAjVKAjLJts23b/Rw1HubzMyHFXWrf/Oaa0Et1p1YxQyapKZDCBGFlJ1Q JLUkysI4DOB95ATheeF1Uf5c0Lr09e3cQuSsDUeEl03//2Ispfn4x25uC Sfoc65n0ZlFbyZ1Y3WL9MrlO+HRqYeQX/KCEo3k7J5oaT48JfouYPP9ju DD1Qxz5YzJBK1cDMRg4BnfSO639omoy9elCmPcQq+XtdpsTq5Ksqvkkbn 5CP0nkjrUnmBxySIMY0k3GjdH5orS1dg2Yp+N0W9eZl6yTi0dMnRilAiD g==; X-IronPort-AV: E=Sophos;i="5.63,563,1557158400"; d="scan'208";a="216339837" Received: from h199-255-45-14.hgst.com (HELO uls-op-cesaep01.wdc.com) ([199.255.45.14]) by ob1.hgst.iphmx.com with ESMTP; 07 Jun 2019 20:19:58 +0800 IronPort-SDR: 7tKAbeGS0ceawc9QgFN//gUc7DtgBYvdyTzAvuHa6rBd7ilZtNeUtAROCxFytCykkI3T+dDbZM EsmBHhfZ5OqicaolEFOIfLPg5nSbzg1cPkPYL0zbGCitIoWn/llH251HpvwKS0enkxkAw6ZIGi APXwNJqMYwBr95CMgjDAJOte5cGDcBpOV4XpoZfDCg0hCAadtaNoG2Zfjux8TX+1iH2VNQdVYH eQZln2lg/TjOpZqCz6AXibF6Wpy5483m/fZaMDgqexzlr1ZCT/796b3/sDNzht5fcIu6abLHDd 3F1vmItCutmEshuIP5sXw7bJ Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep01.wdc.com with ESMTP; 07 Jun 2019 04:54:51 -0700 IronPort-SDR: Vl5fJHIlpi1LqhtmYwsSYsU/icsrs7AmTwo50Fb9DBt4ukYP+GHTzQYFvVHLI9J+nPjmQAsXwV J4b7MYpKosPkI2s+ZFmhp7dwAooxqf5PZ2p2e59FThUsNDKCbDdtOqxkexk0EuYpqySDUqQSKd oYKlRaA4NYGpILMRpqQeTu15vbk7kJ7q+bo/HsEW+woN3T3kkIg8sH+q4D9dYOqnxKzhLY86cS NYselLJwu0BSLGGxRFDZxd/3pGRPpKmTyPyMztxxBJzF1XiGk6kLgwdcRum3YbhZM1+B05bt/v o9I= Received: from shindev.dhcp.fujisawa.hgst.com (HELO shindev.fujisawa.hgst.com) ([10.149.52.166]) by uls-op-cesaip02.wdc.com with ESMTP; 07 Jun 2019 05:19:58 -0700 From: Shin'ichiro Kawasaki To: linux-block@vger.kernel.org, Omar Sandoval Cc: Shinichiro Kawasaki , Masato Suzuki , Damien Le Moal , Omar Sandoval , Chaitanya Kulkarni Subject: [PATCH blktests v3 1/2] zbd/rc: Introduce helper functions for zone mapping test Date: Fri, 7 Jun 2019 21:19:54 +0900 Message-Id: <20190607121955.9368-2-shinichiro.kawasaki@wdc.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190607121955.9368-1-shinichiro.kawasaki@wdc.com> References: <20190607121955.9368-1-shinichiro.kawasaki@wdc.com> MIME-Version: 1.0 Sender: linux-block-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP As a preparation for the zone mapping test case, add several helper functions. _find_last_sequential_zone() and _find_sequential_zone_in_middle() help to select test target zones. _test_dev_is_logical() checks TEST_DEV is the valid test target. _test_dev_has_dm_map() helps to check that the dm target is linear or flakey. _get_dev_container_and_sector() helps to get the container device and sector mappings. Signed-off-by: Shin'ichiro Kawasaki --- tests/zbd/rc | 140 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 140 insertions(+) diff --git a/tests/zbd/rc b/tests/zbd/rc index 5f04c84..5dd2779 100644 --- a/tests/zbd/rc +++ b/tests/zbd/rc @@ -193,6 +193,49 @@ _find_first_sequential_zone() { return 1 } +_find_last_sequential_zone() { + for ((idx = REPORTED_COUNT - 1; idx > 0; idx--)); do + if ((ZONE_TYPES[idx] == ZONE_TYPE_SEQ_WRITE_REQUIRED)); then + echo "${idx}" + return 0 + fi + done + + echo "-1" + return 1 +} + +# Try to find a sequential required zone between given two zone indices +_find_sequential_zone_in_middle() { + local -i s=${1} + local -i e=${2} + local -i idx + local -i i=1 + + if ((s < 0 || e >= REPORTED_COUNT || e <= s + 1)); then + echo "Invalid arguments: ${s} ${e}" + return 1 + fi + + idx=$(((s + e) / 2)) + + while ((idx != s && idx != e)); do + if ((ZONE_TYPES[idx] == ZONE_TYPE_SEQ_WRITE_REQUIRED)); then + echo "${idx}" + return 0 + fi + if ((i%2 == 0)); then + ((idx += i)) + else + ((idx -= i)) + fi + ((i++)) + done + + echo "-1" + return 1 +} + # Search zones and find two contiguous sequential required zones. # Return index of the first zone of the found two zones. # Call _get_blkzone_report() beforehand. @@ -210,3 +253,100 @@ _find_two_contiguous_seq_zones() { echo "Contiguous sequential write required zones not found" return 1 } + +_test_dev_is_dm() { + if [[ ! -r "${TEST_DEV_SYSFS}/dm/name" ]]; then + SKIP_REASON="$TEST_DEV is not device-mapper" + return 1 + fi + return 0 +} + +_test_dev_is_logical() { + if ! _test_dev_is_partition && ! _test_dev_is_dm; then + SKIP_REASON="$TEST_DEV is not a logical device" + return 1 + fi + return 0 +} + +_test_dev_has_dm_map() { + local target_type=${1} + local dm_name + + dm_name=$(<"${TEST_DEV_SYSFS}/dm/name") + if ! dmsetup status "${dm_name}" | grep -qe "${target_type}"; then + SKIP_REASON="$TEST_DEV does not have ${target_type} map" + return 1 + fi + if dmsetup status "${dm_name}" | grep -v "${target_type}"; then + SKIP_REASON="$TEST_DEV has map other than ${target_type}" + return 1 + fi + return 0 +} + +# Get device file path from the device ID "major:minor". +_get_dev_path_by_id() { + for d in /sys/block/* /sys/block/*/*; do + if [[ ! -r "${d}/dev" ]]; then + continue + fi + if [[ "${1}" == "$(<"${d}/dev")" ]]; then + echo "/dev/${d##*/}" + return 0 + fi + done + return 1 +} + +# Given sector of TEST_DEV, return the device which contain the sector and +# corresponding sector of the container device. +_get_dev_container_and_sector() { + local -i sector=${1} + local cont_dev + local -i offset + local -a tbl_line + + if _test_dev_is_partition; then + offset=$(<"${TEST_DEV_PART_SYSFS}/start") + cont_dev=$(_get_dev_path_by_id "$(<"${TEST_DEV_SYSFS}/dev")") + echo "${cont_dev}" "$((offset + sector))" + return 0 + fi + + if ! _test_dev_is_dm; then + echo "${TEST_DEV} is not a logical device" + return 1 + fi + if ! _test_dev_has_dm_map linear && + ! _test_dev_has_dm_map flakey; then + echo -n "dm mapping test other than linear/flakey is" + echo "not implemented" + return 1 + fi + + # Parse dm table lines for dm-linear or dm-flakey target + while read -r -a tbl_line; do + local -i map_start=${tbl_line[0]} + local -i map_end=$((tbl_line[0] + tbl_line[1])) + + if ((sector < map_start)) || (((map_end) <= sector)); then + continue + fi + + offset=${tbl_line[4]} + if ! cont_dev=$(_get_dev_path_by_id "${tbl_line[3]}"); then + echo -n "Cannot access to container device: " + echo "${tbl_line[3]}" + return 1 + fi + + echo "${cont_dev}" "$((offset + sector - map_start))" + return 0 + + done < <(dmsetup table "$(<"${TEST_DEV_SYSFS}/dm/name")") + + echo -n "Cannot find container device of ${TEST_DEV}" + return 1 +} From patchwork Fri Jun 7 12:19:55 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shin'ichiro Kawasaki X-Patchwork-Id: 10981601 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 535C717D2 for ; Fri, 7 Jun 2019 12:20:01 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 426C526419 for ; Fri, 7 Jun 2019 12:20:01 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 3641228B30; Fri, 7 Jun 2019 12:20:01 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.7 required=2.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A6B2926419 for ; Fri, 7 Jun 2019 12:20:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728477AbfFGMUA (ORCPT ); Fri, 7 Jun 2019 08:20:00 -0400 Received: from esa1.hgst.iphmx.com ([68.232.141.245]:58140 "EHLO esa1.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727762AbfFGMUA (ORCPT ); Fri, 7 Jun 2019 08:20:00 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1559909999; x=1591445999; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=Jl3jF4cmoEXxvz+We2qB17Aud3EARTFqMSqejXZ+lyE=; b=ocn3pMvsjiqRpPBws54SZKXr/T4+Ne1pcMmPds1tOlbhhDaYFtdkYyFo w89mliqfGGRGCwI/9MOXeqgcgXXolnt+xKx0JKt7VLsGY2xdbQ7bU0WGh OPdB/2HatpeOYqGZ2nH5bUzI2E22CtZETvPRl3vC1ViD72NqK8Pu/FaQg JXTLxzj2VANVAtNgyNYEz78ODi2k+6uL6edZI3RdsIOCYGqxqz/SikcsM ozRKZvfx6Dnl+kp/4qYCrqznDgexKDFrJ49QlEu9VxKCH0GDEsoklDMZa m66BdDlzMU3tgCyb47pro5vBniqsh/4aWxYBYffBqr2ZceROpLKmQos26 w==; X-IronPort-AV: E=Sophos;i="5.63,563,1557158400"; d="scan'208";a="216339838" Received: from h199-255-45-14.hgst.com (HELO uls-op-cesaep01.wdc.com) ([199.255.45.14]) by ob1.hgst.iphmx.com with ESMTP; 07 Jun 2019 20:19:59 +0800 IronPort-SDR: 5MeQ14V2wjvaYsp4d9CTW/2hWOS1KCicIWmbklQzpFiwp8vwltnLMX37Rs/OIyMYfV2r/gwDaZ xmx73P0ExNhpFI/1c9k4czPOnF69nIllNzeNbDFMTD8OWxM7MjkhbStqrRCQsPvZdbz1faDlC+ TuZ+obxUXWAcSjuSysh1LdppsphfjQKZ0dNGjDfW5gjxCrhsKIn8OvDwLODo/G63cYZ0D52jBs xg6foERGSgkjVBMcp9qu1U1nVjRpmLf9ilmijmLgKsUGB/spC4pegjrU15fqLjiKcceJJDQ9pa imoeYIRgUGRBrMltSR+x0VxE Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep01.wdc.com with ESMTP; 07 Jun 2019 04:54:52 -0700 IronPort-SDR: P7WWzILgIVcNYQSvu23+kZtPZFUdhffHTaX3zPIJL7GCAM4gpHp3UwJKZQVSuzWuJPV43+QX0n iNCYkGgadc7FXq7kJN1UF6fqKWMtFs8NV02sN+mToqYRlItQ3na8Tf+uXy5PaqtdZGPfiP3Ett 60c2EWl1oFvAXeRGzrcEaxTES2KmqCCzpXUn5ZPoMb5cQZ5wL/Cctx4Z5D06Svag8XkSe48izb LUOtnMXKpUsT53t1+cOdI1L2Gf2mAZg1gqFmMn6u3gZXXe36jfVGc9Dzha31F4JK0dp/VtFrrl lmE= Received: from shindev.dhcp.fujisawa.hgst.com (HELO shindev.fujisawa.hgst.com) ([10.149.52.166]) by uls-op-cesaip02.wdc.com with ESMTP; 07 Jun 2019 05:19:59 -0700 From: Shin'ichiro Kawasaki To: linux-block@vger.kernel.org, Omar Sandoval Cc: Shinichiro Kawasaki , Masato Suzuki , Damien Le Moal , Omar Sandoval , Chaitanya Kulkarni Subject: [PATCH blktests v3 2/2] zbd/007: Add zone mapping test for logical devices Date: Fri, 7 Jun 2019 21:19:55 +0900 Message-Id: <20190607121955.9368-3-shinichiro.kawasaki@wdc.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190607121955.9368-1-shinichiro.kawasaki@wdc.com> References: <20190607121955.9368-1-shinichiro.kawasaki@wdc.com> MIME-Version: 1.0 Sender: linux-block-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 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. This test case catches regressions of complex zone remapping problem fixed by commit 9864cd5dc54c "dm: fix report zone remapping to account for partition offset". 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 --- 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