]> www.infradead.org Git - users/sagi/blktests.git/commitdiff
Make group/rc and common/rc sources explicit and reenable SC2034
authorOmar Sandoval <osandov@fb.com>
Tue, 26 Jun 2018 18:27:11 +0000 (11:27 -0700)
committerOmar Sandoval <osandov@fb.com>
Tue, 26 Jun 2018 18:45:28 +0000 (11:45 -0700)
SC2034 (unused variable) is a useful warning, but we disabled it because
we set a bunch of global variables as test metadata. However, this is
easy to work around: as Bart demonstrated, an echo "$VAR" > /dev/null
does the trick.

However, we don't want to copy-and-paste this everywhere, so we need to
source something everywhere. Bart's idea was to put this in
common/shellcheck and source that everywhere. Sourcing a file just to
appease the linter is silly, though, so instead, this adds explicit
sources of tests/*/rc to each test, which in turn sources common/rc,
which in turn sources common/shellcheck.

Signed-off-by: Omar Sandoval <osandov@fb.com>
74 files changed:
Makefile
check
common/cpuhotplug
common/fio
common/iopoll
common/nbd [deleted file]
common/nvme [deleted file]
common/rc
common/scsi [deleted file]
common/shellcheck [moved from common/loop with 71% similarity]
new
tests/block/001
tests/block/002
tests/block/003
tests/block/004
tests/block/005
tests/block/006
tests/block/007
tests/block/008
tests/block/009
tests/block/010
tests/block/011
tests/block/012
tests/block/013
tests/block/014
tests/block/015
tests/block/016
tests/block/017
tests/block/018
tests/block/019
tests/block/020
tests/block/021
tests/block/rc
tests/loop/001
tests/loop/002
tests/loop/003
tests/loop/004
tests/loop/005
tests/loop/rc
tests/meta/001
tests/meta/002
tests/meta/003
tests/meta/004
tests/meta/005
tests/meta/006
tests/meta/007
tests/meta/008
tests/meta/009
tests/meta/010
tests/meta/011
tests/meta/012
tests/meta/rc
tests/nbd/001
tests/nbd/002
tests/nbd/rc
tests/nvme/001
tests/nvme/002
tests/nvme/003
tests/nvme/004
tests/nvme/005
tests/nvme/006
tests/nvme/007
tests/nvme/008
tests/nvme/009
tests/nvme/010
tests/nvme/011
tests/nvme/012
tests/nvme/013
tests/nvme/rc
tests/scsi/001
tests/scsi/002
tests/scsi/003
tests/scsi/004
tests/scsi/rc

index e3c379f64568c63208b72c15cbce28361d4c37b0..38b8ad165790d7d83fb7751efe57ac629fcf8a1e 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -4,15 +4,13 @@ all:
 clean:
        $(MAKE) -C src clean
 
-# SC2034: "VARIABLE appears unused". All test scripts use this for the test
-# metadata, and many helper functions define global variables.
 # SC2119: "Use foo "$@" if function's $1 should mean script's $1". False
 # positives on helpers like _init_scsi_debug.
-SHELLCHECK_EXCLUDE := SC2034,SC2119
+SHELLCHECK_EXCLUDE := SC2119
 
 check:
        shellcheck -x -e $(SHELLCHECK_EXCLUDE) -f gcc check new common/* \
                tests/*/rc tests/*/[0-9]*[0-9]
-       ! grep TODO tests/*/[0-9]*[0-9]
+       ! grep TODO tests/*/rc tests/*/[0-9]*[0-9]
 
 .PHONY: all check
diff --git a/check b/check
index afd0dcc3e36957174cff31b9999248cca08319ca..fd9f09ca57b4b32415590e919417dc479043fbde 100755 (executable)
--- a/check
+++ b/check
 # You should have received a copy of the GNU General Public License
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
-. common/rc
+shopt -s extglob
+
+_warning() {
+       echo "$0: $*" >&2
+}
+
+_error() {
+       echo "$0: $*" >&2
+       exit 1
+}
 
 _found_test() {
        local test_name="$1"
@@ -303,6 +312,7 @@ _cleanup() {
 _call_test() {
        local test_func="$1"
        local seqres="${RESULTS_DIR}/${TEST_NAME}"
+       # shellcheck disable=SC2034
        FULL="${seqres}.full"
        declare -A TEST_DEV_QUEUE_SAVED
 
@@ -495,6 +505,7 @@ _find_sysfs_dir() {
 
 declare -A TEST_DEV_SYSFS_DIRS
 _check() {
+       # shellcheck disable=SC2034
        SRCDIR="$(realpath src)"
 
        local test_dev
index 70b284f7b7aa74e0d0a57421330e2e238a0950d7..e5b314a98daad6c676355f9f79559e16c2085a95 100644 (file)
@@ -17,6 +17,8 @@
 # You should have received a copy of the GNU General Public License
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
+. common/shellcheck
+
 # Also initializes the ALL_CPUS and HOTPLUGGABLE_CPUS arrays.
 _have_cpu_hotplug() {
        ALL_CPUS=()
@@ -29,6 +31,7 @@ _have_cpu_hotplug() {
                if [[ -w ${cpu_dir}/online ]]; then
                        cpu="${cpu_dir#/sys/devices/system/cpu/cpu}"
                        HOTPLUGGABLE_CPUS+=("$cpu")
+                       # shellcheck disable=SC2034
                        CPUS_ONLINE_SAVED["$cpu"]="$(cat "${cpu_dir}/online")"
                fi
        done
@@ -41,11 +44,13 @@ _have_cpu_hotplug() {
 }
 
 _online_cpu() {
+       # shellcheck disable=SC2034
        RESTORE_CPUS_ONLINE=1
        echo 1 > "/sys/devices/system/cpu/cpu$1/online"
 }
 
 _offline_cpu() {
+       # shellcheck disable=SC2034
        RESTORE_CPUS_ONLINE=1
        echo 0 > "/sys/devices/system/cpu/cpu$1/online"
 }
index 0f93632c0382732e8be211e4d9e2c023afb3f421..949796810a0cc99fa1ec85caea3a40e6b4b3a46f 100644 (file)
@@ -17,6 +17,8 @@
 # You should have received a copy of the GNU General Public License
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
+. common/shellcheck
+
 _have_fio() {
        if ! _have_program fio; then
                return 1
index affdd4332dc2c223e2c6422f2680e51dc568b44d..10ebd16923ada802277574bd2db946a9ced42f60 100644 (file)
@@ -17,6 +17,8 @@
 # You should have received a copy of the GNU General Public License
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
+. common/shellcheck
+
 _have_fio_with_poll() {
        if ! _have_fio; then
                return 1
diff --git a/common/nbd b/common/nbd
deleted file mode 100644 (file)
index 320f456..0000000
+++ /dev/null
@@ -1,85 +0,0 @@
-#!/bin/bash
-#
-# NBD helper functions
-#
-# Copyright (C) 2018 Josef Bacik
-#
-# This program is free software: you can redistribute it and/or modify
-# it under the terms of the GNU General Public License as published by
-# the Free Software Foundation, either version 3 of the License, or
-# (at your option) any later version.
-#
-# This program is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-# GNU General Public License for more details.
-#
-# You should have received a copy of the GNU General Public License
-# along with this program.  If not, see <http://www.gnu.org/licenses/>.
-
-_have_nbd() {
-       if ! _have_module nbd; then
-               return 1
-       fi
-       if ! _have_program nbd-server; then
-               return 1
-       fi
-       if ! _have_program nbd-client; then
-               return 1
-       fi
-       if ! nbd-client --help 2>&1 | grep -q -- -L; then
-               SKIP_REASON="nbd-client does not have -nonetlink/-L option"
-               return 1
-       fi
-       return 0
-}
-
-_have_nbd_netlink() {
-       if ! _have_nbd; then
-               return 1
-       fi
-       if ! _have_program genl-ctrl-list; then
-               return 1
-       fi
-       if ! genl-ctrl-list | grep -q nbd; then
-               SKIP_REASON="nbd does not support netlink"
-               return 1
-       fi
-       return 0
-}
-
-_wait_for_nbd_connect() {
-       for ((i = 0; i < 3; i++)); do
-               if [[ -e /sys/kernel/debug/nbd/nbd0/tasks ]]; then
-                       return 0
-               fi
-               sleep 1
-       done
-       return 1
-}
-
-_wait_for_nbd_disconnect() {
-       for ((i = 0; i < 3; i++)); do
-               if [[ ! -e /sys/kernel/debug/nbd/nbd0/tasks ]]; then
-                       return 0
-               fi
-               sleep 1
-       done
-       return 1
-}
-
-_start_nbd_server() {
-       truncate -s 10G "${TMPDIR}/export"
-       cat > "${TMPDIR}/nbd.conf" << EOF
-[generic]
-[export]
-exportname=${TMPDIR}/export
-EOF
-       nbd-server -p "${TMPDIR}/nbd.pid" -C "${TMPDIR}/nbd.conf"
-}
-
-_stop_nbd_server() {
-       kill -SIGTERM "$(cat "${TMPDIR}/nbd.pid")"
-       rm -f "${TMPDIR}/nbd.pid"
-       rm -f "${TMPDIR}/export"
-}
diff --git a/common/nvme b/common/nvme
deleted file mode 100644 (file)
index 044d7fe..0000000
+++ /dev/null
@@ -1,123 +0,0 @@
-#!/bin/bash
-#
-# Default helper functions for NVMe devices.
-#
-# Copyright (C) 2018 Johannes Thumshirn
-#
-# This program is free software: you can redistribute it and/or modify
-# it under the terms of the GNU General Public License as published by
-# the Free Software Foundation, either version 3 of the License, or
-# (at your option) any later version.
-#
-# This program is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-# GNU General Public License for more details.
-#
-# You should have received a copy of the GNU General Public License
-# along with this program.  If not, see <http://www.gnu.org/licenses/>.
-
-NVMET_CFS="/sys/kernel/config/nvmet/"
-
-_test_dev_is_nvme() {
-       if ! readlink -f "$TEST_DEV_SYSFS/device" | grep -q nvme; then
-               SKIP_REASON="$TEST_DEV is not a NVMe device"
-               return 1
-       fi
-       return 0
-}
-
-_create_nvmet_port() {
-       local trtype="$1"
-
-       local port
-       for ((port = 0; ; port++)); do
-               if [[ ! -e "${NVMET_CFS}/ports/${port}" ]]; then
-                       break
-               fi
-       done
-
-       mkdir "${NVMET_CFS}/ports/${port}"
-       echo "${trtype}" > "${NVMET_CFS}/ports/${port}/addr_trtype"
-
-       echo "${port}"
-}
-
-_remove_nvmet_port() {
-       local port="$1"
-       rmdir "${NVMET_CFS}/ports/${port}"
-}
-
-_create_nvmet_ns() {
-       local nvmet_subsystem="$1"
-       local nsid="$2"
-       local blkdev="$3"
-       local uuid="00000000-0000-0000-0000-000000000000"
-       local subsys_path="${NVMET_CFS}/subsystems/${nvmet_subsystem}"
-       local ns_path="${subsys_path}/namespaces/${nsid}"
-
-       if [[ $# -eq 4 ]]; then
-               uuid="$4"
-       fi
-
-       mkdir "${ns_path}"
-       printf "%s" "${blkdev}" > "${ns_path}/device_path"
-       printf "%s" "${uuid}" > "${ns_path}/device_uuid"
-       printf 1 > "${ns_path}/enable"
-}
-
-_create_nvmet_subsystem() {
-       local nvmet_subsystem="$1"
-       local blkdev="$2"
-       local uuid=$3
-       local cfs_path="${NVMET_CFS}/subsystems/${nvmet_subsystem}"
-
-       mkdir -p "${cfs_path}"
-       echo 1 > "${cfs_path}/attr_allow_any_host"
-       _create_nvmet_ns "${nvmet_subsystem}" "1" "${blkdev}" "${uuid}"
-}
-
-_remove_nvmet_ns() {
-       local nvmet_subsystem="$1"
-       local nsid=$2
-       local subsys_path="${NVMET_CFS}/subsystems/${nvmet_subsystem}"
-       local nvmet_ns_path="${subsys_path}/namespaces/${nsid}"
-
-       echo 0 > "${nvmet_ns_path}/enable"
-       rmdir "${nvmet_ns_path}"
-}
-
-_remove_nvmet_subsystem() {
-       local nvmet_subsystem="$1"
-       local subsys_path="${NVMET_CFS}/subsystems/${nvmet_subsystem}"
-
-       _remove_nvmet_ns "${nvmet_subsystem}" "1"
-       rmdir "${subsys_path}"
-}
-
-_add_nvmet_subsys_to_port() {
-       local port="$1"
-       local nvmet_subsystem="$2"
-
-       ln -s "${NVMET_CFS}/subsystems/${nvmet_subsystem}" \
-               "${NVMET_CFS}/ports/${port}/subsystems/${nvmet_subsystem}"
-}
-
-_remove_nvmet_subsystem_from_port() {
-       local port="$1"
-       local nvmet_subsystem="$2"
-
-       rm "${NVMET_CFS}/ports/${port}/subsystems/${nvmet_subsystem}"
-}
-
-_find_nvme_loop_dev() {
-       local dev
-       local transport
-       for dev in /sys/class/nvme/nvme*; do
-               dev="$(basename "$dev")"
-               transport="$(cat "/sys/class/nvme/${dev}/transport")"
-               if [[ "$transport" == "loop" ]]; then
-                       echo "$dev"
-               fi
-       done
-}
index 7592400dda82e3ada8529ba0c667b2eeab4d2c60..57e1c501c81d4d99cab767e7a7a5fc3e30a1ff32 100644 (file)
--- a/common/rc
+++ b/common/rc
 
 shopt -s extglob
 
+. common/shellcheck
 # Include fio helpers by default.
 . common/fio
 
-_warning() {
-       echo "$0: $*" >&2
-}
-
-_error() {
-       echo "$0: $*" >&2
-       exit 1
-}
-
 # If a test runs multiple "subtests", then each subtest should typically run
 # for TIMEOUT / number of subtests.
 _divide_timeout() {
diff --git a/common/scsi b/common/scsi
deleted file mode 100644 (file)
index d9fcc0e..0000000
+++ /dev/null
@@ -1,34 +0,0 @@
-#!/bin/bash
-#
-# SCSI generic helper functions.
-#
-# Copyright (C) 2017 Johannes Thumshirn
-#
-# This program is free software: you can redistribute it and/or modify
-# it under the terms of the GNU General Public License as published by
-# the Free Software Foundation, either version 3 of the License, or
-# (at your option) any later version.
-#
-# This program is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-# GNU General Public License for more details.
-#
-# You should have received a copy of the GNU General Public License
-# along with this program.  If not, see <http://www.gnu.org/licenses/>.
-
-_have_scsi_generic() {
-       _have_module sg
-}
-
-_test_dev_is_scsi() {
-       if [[ ! -d ${TEST_DEV_SYSFS}/device/scsi_device ]]; then
-               SKIP_REASON="$TEST_DEV is not a SCSI device"
-               return 1
-       fi
-       return 0
-}
-
-_get_test_dev_sg() {
-       echo "${TEST_DEV_SYSFS}"/device/scsi_generic/sg* | grep -Eo "sg[0-9]+"
-}
similarity index 71%
rename from common/loop
rename to common/shellcheck
index 16cc3212a028516f6e10b2c00c1abd11b498911a..347ad62d1b892d5f5d360b26f7a8607f95876e1d 100644 (file)
@@ -1,8 +1,8 @@
 #!/bin/bash
 #
-# Loop device helper functions.
+# Shellcheck workarounds.
 #
-# Copyright (C) 2017 Omar Sandoval
+# Copyright (C) 2018 Omar Sandoval
 #
 # This program is free software: you can redistribute it and/or modify
 # it under the terms of the GNU General Public License as published by
 # You should have received a copy of the GNU General Public License
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
-
-_have_loop_set_block_size() {
-       src/loblksize "$(losetup -f)" 512 &>/dev/null
-       if [[ $? -eq 2 ]]; then
-               SKIP_REASON="kernel does not support LOOP_SET_BLOCK_SIZE"
-               return 1
-       fi
-       return 0
+# Suppress unused global variable warnings.
+_silence_sc2034() {
+       echo "$CHECK_DMESG $DESCRIPTION $DMESG_FILTER $FIO_PERF_FIELDS $FIO_PERF_PREFIX $QUICK $SKIP_REASON ${TEST_RUN[*]} $TIMED" > /dev/null
 }
diff --git a/new b/new
index 1cd3233b0fa7ae1e351c51979f78001675badc74..5c6e1eb3852d5d2836375f5c5458e91adcded349 100755 (executable)
--- a/new
+++ b/new
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
 set -e
+shopt -s extglob
 
-. common/rc
+_error() {
+       echo "$0: $*" >&2
+       exit 1
+}
 
 prompt_yes_no() {
        if [[ $2 =~ ^[Yy] ]]; then
@@ -84,10 +88,8 @@ if [[ ! -e tests/${group} ]]; then
 # You should have received a copy of the GNU General Public License
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
-# TODO: source any common helpers needed for this group. Anything sourced here
-# will also be available in the test scripts. Additionally, any functions
-# defined here will also be available in the test scripts. Note that common/rc
-# and common/fio are automatically sourced for all tests.
+. common/rc
+# TODO: source any more common helpers needed for this group.
 # . common/foo
 
 # TODO: if this test group has any extra requirements, it should define a
@@ -117,6 +119,8 @@ group_requires() {
 # group_device_requires() {
 #      _test_dev_is_foo && _test_dev_supports_bar
 # }
+
+# TODO: define any helpers that are specific to this group.
 EOF
        echo "Created tests/${group}/rc"
 fi
@@ -159,6 +163,9 @@ cat << EOF > "tests/${test_name}"
 # You should have received a copy of the GNU General Public License
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
+. tests/${group}/rc
+# TODO: source any more common helpers needed for this test.
+
 # TODO: fill in a very brief description of what this test does. The
 # description should complete the sentence "This test will...". For example,
 # "run a mixed read/write workload" would be a good description.
@@ -254,9 +261,9 @@ test() {
 # - Variables set and used by the testing framework are in caps with underscores.
 #   E.g., TEST_NAME and GROUPS. Variables local to the test are lowercase
 #   with underscores.
-# - Functions defined by the testing framework, including helpers, have a leading
-#   underscore. E.g., _have_scsi_debug. Functions local to the test or group
-#   should not have a leading underscore.
+# - Functions defined by the testing framework or group scripts, including
+#   helpers, have a leading underscore. E.g., _have_scsi_debug. Functions local
+#   to the test should not have a leading underscore.
 # - Use the bash [[ ]] form of tests instead of [ ].
 # - Always quote variable expansions unless the variable is a number or inside of
 #   a [[ ]] test.
index 7411a0cf04f635a8f259691ae6ea21e0c878a353..7f794f27dba5c520e05d99cc5cff2f743fc16438 100755 (executable)
@@ -19,6 +19,7 @@
 # You should have received a copy of the GNU General Public License
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
+. tests/block/rc
 . common/scsi_debug
 
 DESCRIPTION="stress device hotplugging"
index 57b4f89840954e9f7ed50cc55f8ce5bea2ad9c0b..8d95b57b1c449177b84e2a21cff87a01aecba13c 100755 (executable)
@@ -18,6 +18,7 @@
 # You should have received a copy of the GNU General Public License
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
+. tests/block/rc
 . common/scsi_debug
 
 DESCRIPTION="remove a device while running blktrace"
index 87e30a36e8c202d4d94e559bb9a2765b14f80398..38eb3e0e9f060fb8865f0971f010f1f8749550a0 100755 (executable)
@@ -17,6 +17,8 @@
 # You should have received a copy of the GNU General Public License
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
+. tests/block/rc
+
 DESCRIPTION="run various discard sizes"
 TIMED=1
 
index 754d30260d63cabb700923a64bba122f636b2c55..92a4b1810e9bceb894aec781b6dc4e3a377779e8 100755 (executable)
@@ -17,6 +17,8 @@
 # You should have received a copy of the GNU General Public License
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
+. tests/block/rc
+
 DESCRIPTION="run lots of flushes"
 TIMED=1
 
index fae59272f90b417270645862c565851df136fd80..3bcdc25e6ae1984bd3f56237ed1b84a12fb7f8e0 100755 (executable)
@@ -17,6 +17,8 @@
 # You should have received a copy of the GNU General Public License
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
+. tests/block/rc
+
 DESCRIPTION="switch schedulers while doing IO"
 TIMED=1
 
index 0a472935a48163ea8c5501ebfa83683fc3dbec0d..a5f1310d8ad7b0ce21b132263547623676b68ac3 100755 (executable)
@@ -20,6 +20,8 @@
 # You should have received a copy of the GNU General Public License
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
+. tests/block/rc
+
 DESCRIPTION="run null-blk in blocking mode"
 TIMED=1
 
index e35649ad96cd1829115ed9e5ffdbc8375187ce78..ae8b39760b39dd4a777d498337a0c8368ca4a01c 100755 (executable)
@@ -17,6 +17,7 @@
 # You should have received a copy of the GNU General Public License
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
+. tests/block/rc
 . common/iopoll
 
 DESCRIPTION="test classic and hybrid IO polling"
index fcd905adcfe8ef45ca7a193d016a8b08ee501641..9b41bf55268f0da07f127d78ecba14bb83d0541a 100755 (executable)
@@ -17,6 +17,7 @@
 # You should have received a copy of the GNU General Public License
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
+. tests/block/rc
 . common/cpuhotplug
 
 DESCRIPTION="do IO while hotplugging CPUs"
index cbeeb70701faf2c40f4b35cb9ac435bc2c6fb7cc..9727c127c5082110c0e8bfebb149f257c5d9c079 100755 (executable)
 # You should have received a copy of the GNU General Public License
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
-DESCRIPTION="check page-cache coherency after BLKDISCARD"
-
+. tests/block/rc
 . common/scsi_debug
 
+DESCRIPTION="check page-cache coherency after BLKDISCARD"
+
 requires() {
        _have_scsi_debug && _have_program xfs_io
 }
index 97891d229c0f8ab87d3d76cdb9916cfd0e9e09e1..5b54e71a53f7be8f5d9d0a46a85aff6c47e5daf6 100644 (file)
@@ -20,6 +20,8 @@
 # You should have received a copy of the GNU General Public License
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
+. tests/block/rc
+
 DESCRIPTION="run I/O on null_blk with shared and non-shared tags"
 TIMED=1
 
index 24614420461e7a0a35948b6f918352e091dfa21d..596bc0fccc838735733dc953b8134d2b85cfea77 100755 (executable)
@@ -17,6 +17,8 @@
 # You should have received a copy of the GNU General Public License
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
+. tests/block/rc
+
 DESCRIPTION="disable PCI device while doing I/O"
 TIMED=1
 
index baabdd68b655243972764ceeac6f72125fd33e34..13d2e0e24f7789bff2e20a720ade328030dd2454 100755 (executable)
@@ -17,6 +17,8 @@
 # You should have received a copy of the GNU General Public License
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
+. tests/block/rc
+
 DESCRIPTION="check that a read-only block device fails writes"
 TIMED=1
 
index 415b34dcc5ef47d531beeb9300ed4e5784b916f7..8e2423838a1209acf6c24b74d39d4d8929fdfce2 100755 (executable)
@@ -23,6 +23,8 @@
 # You should have received a copy of the GNU General Public License
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
+. tests/block/rc
+
 DESCRIPTION="try BLKRRPART on a mounted device"
 QUICK=1
 
index 882a9b9f5015bc550690e1660b8b184219c6bb53..1da604f8fb73fc56c9b8ade59a2fd282bb04b6ae 100755 (executable)
@@ -17,6 +17,8 @@
 # You should have received a copy of the GNU General Public License
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
+. tests/block/rc
+
 DESCRIPTION="run null-blk with timeout injection configured"
 
 requires() {
index b236a6d36bf8cdd0cfcaaa825f8c1f4d0c61c031..c44d4da657d8a15088d29c54406f83681f3bbea9 100755 (executable)
@@ -18,8 +18,9 @@
 # You should have received a copy of the GNU General Public License
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
-DESCRIPTION="run null-blk on different schedulers with requeue injection configured"
+. tests/block/rc
 
+DESCRIPTION="run null-blk on different schedulers with requeue injection configured"
 QUICK=1
 
 requires() {
index 6ccfe98f54ce6ef46a862c61e3c03ec6fccf37ff..bef3aa4a1be2c9da5272a691760455455ccafdb0 100755 (executable)
@@ -19,6 +19,8 @@
 # You should have received a copy of the GNU General Public License
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
+. tests/block/rc
+
 DESCRIPTION="send a signal to a process waiting on a frozen queue"
 QUICK=1
 
index 436a8f33615589df4af939c6149d9e6ffd16321b..e1a8afde89bbefb7f78549c9aee6d8955002676f 100755 (executable)
@@ -19,6 +19,8 @@
 # You should have received a copy of the GNU General Public License
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
+. tests/block/rc
+
 DESCRIPTION="do I/O and check the inflight counter"
 QUICK=1
 
index 548f1baeaf594c5b094e01f1835b471fbba124fa..53cf58462d00a73fb1658005edb9eff80d09ed86 100755 (executable)
@@ -17,6 +17,8 @@
 # You should have received a copy of the GNU General Public License
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
+. tests/block/rc
+
 DESCRIPTION="do I/O and check iostats times"
 QUICK=1
 
index 00830d02b67a838a235a87c5bf81dce37c405804..ed005b51e5a3dda7b5f1b6edc478246177e0f08a 100755 (executable)
@@ -17,6 +17,8 @@
 # You should have received a copy of the GNU General Public License
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
+. tests/block/rc
+
 DESCRIPTION="break PCI link device while doing I/O"
 QUICK=1
 
index 36140136369bd08ac780cdaedc8a2c2af5a311aa..a744f6480bf99e5d8e04fe2c47e56125421eb3ea 100755 (executable)
@@ -19,6 +19,8 @@
 # You should have received a copy of the GNU General Public License
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
+. tests/block/rc
+
 DESCRIPTION="run null-blk on different schedulers with only one hardware tag"
 QUICK=1
 
index 74fa709a8e04058706ded2481687f0bc2478c938..3210f58ef27ceea5b7cff7fb622233afd8ebead3 100755 (executable)
@@ -19,6 +19,8 @@
 # You should have received a copy of the GNU General Public License
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
+. tests/block/rc
+
 DESCRIPTION="read/write nr_requests on null-blk with different schedulers"
 QUICK=1
 
index 689cafcb96b4919cb041f3beec1068d358c3d348..fdd84501a1bbd94bf6c63d1acaa9d88fed043a20 100644 (file)
@@ -17,6 +17,8 @@
 # You should have received a copy of the GNU General Public License
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
+. common/rc
+
 group_requires() {
        _have_root
 }
index 1f009bdd1439e606acf80be1110eed5c4ff04512..49caa9e1f230e1796654ba8455bd47071f668a26 100755 (executable)
@@ -18,6 +18,8 @@
 # You should have received a copy of the GNU General Public License
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
+. tests/loop/rc
+
 DESCRIPTION="scan loop device partitions"
 QUICK=1
 
index 2a16dbac8bc7459ea7a07e9f5a939ebde1d15ab6..e89392b7264ccdd4c08776090dab81e2e7a044d2 100755 (executable)
@@ -22,7 +22,7 @@
 # You should have received a copy of the GNU General Public License
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
-. common/loop
+. tests/loop/rc
 
 DESCRIPTION="try various loop device block sizes"
 QUICK=1
index 22f49a8b027e8bf9f13910f26c2cbe3e07fc617c..c6570aa7da59c5144e4e19d53d97e5eb9a446658 100755 (executable)
@@ -18,6 +18,8 @@
 # You should have received a copy of the GNU General Public License
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
+. tests/loop/rc
+
 DESCRIPTION="time opening and closing an unbound loop device"
 QUICK=1
 
index 8dcc85165db68fccd75ae860e02bd347b208e2eb..7b1d6091289f117478f4caf2555b8919d78f7fc1 100755 (executable)
@@ -17,7 +17,7 @@
 # You should have received a copy of the GNU General Public License
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
-. common/loop
+. tests/loop/rc
 . common/scsi_debug
 
 DESCRIPTION="combine loop direct I/O mode and a custom block size"
index b57ddb3d6f1afd85eb01744f8f6843826cbe0921..7ca8c4f9f553ce51ba2fce18429bfe9bf7bace38 100755 (executable)
@@ -19,8 +19,9 @@
 # You should have received a copy of the GNU General Public License
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
-DESCRIPTION="call LOOP_GET_STATUS{,64} with a NULL arg"
+. tests/loop/rc
 
+DESCRIPTION="call LOOP_GET_STATUS{,64} with a NULL arg"
 QUICK=1
 
 requires() {
index 5d0a4e5a78767cf5109b8554025312574a5b7983..a48f9ea48baa2facac3686cfd4f118c479009dbd 100644 (file)
 # You should have received a copy of the GNU General Public License
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
+. common/rc
+
 group_requires() {
        _have_root && _have_loop
 }
+
+_have_loop_set_block_size() {
+       src/loblksize "$(losetup -f)" 512 &>/dev/null
+       if [[ $? -eq 2 ]]; then
+               SKIP_REASON="kernel does not support LOOP_SET_BLOCK_SIZE"
+               return 1
+       fi
+       return 0
+}
index 454fb22554a37628cd97e533a39124d97ce2f002..78b9f3db3de73896242a6cfd0d49e4fbe1c3d6c6 100755 (executable)
@@ -17,6 +17,8 @@
 # You should have received a copy of the GNU General Public License
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
+. tests/meta/rc
+
 DESCRIPTION="do nothing"
 
 test() {
index 5a2cd53f2318849df888b6a992b4c52f309d755b..6fafa00dbf7ed64ce3b7eab01888dae39ee00d2a 100755 (executable)
@@ -17,6 +17,8 @@
 # You should have received a copy of the GNU General Public License
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
+. tests/meta/rc
+
 DESCRIPTION="do nothing"
 
 test_device() {
index eb79bca15ffbcbdda10d2201bfbb2c0f0c737b02..0e39bdd6eb08cba7499fe1a74a2d02aef13610c0 100755 (executable)
@@ -17,6 +17,8 @@
 # You should have received a copy of the GNU General Public License
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
+. tests/meta/rc
+
 DESCRIPTION="exit with non-zero status"
 
 test() {
index bafe6c5e8da877a18f93a32172d0d01fa2e4ea7f..dace17b2b36b9d25f220b997e5f5069d7b05f509 100755 (executable)
@@ -17,6 +17,8 @@
 # You should have received a copy of the GNU General Public License
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
+. tests/meta/rc
+
 DESCRIPTION="exit with non-zero status"
 
 test_device() {
index c9909c64c0220fda52d7916d8b1d35f9565e0ed9..445356f740966fad39f0b3b224a1032c1c6d8a95 100755 (executable)
@@ -17,6 +17,8 @@
 # You should have received a copy of the GNU General Public License
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
+. tests/meta/rc
+
 DESCRIPTION="produce bad output"
 
 test() {
index 9d28bdce01d8755f92301d2d2045f4b53d17e239..027e3244f3355746539f923c5392da7470014407 100755 (executable)
@@ -17,6 +17,8 @@
 # You should have received a copy of the GNU General Public License
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
+. tests/meta/rc
+
 DESCRIPTION="produce lots of bad output"
 
 test() {
index 2516796a333d36e21527c50453ed3e332e73912e..20bb0fe0a22e5688c3aa7a2f51570c5a5803e6de 100755 (executable)
@@ -17,6 +17,8 @@
 # You should have received a copy of the GNU General Public License
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
+. tests/meta/rc
+
 DESCRIPTION="skip in requires()"
 
 requires() {
index 5d24669b290e9ef283d5ca63ff006771cf6f8d6d..ca72fadebbb3c1c0ee7f415f25a04e47a6b6c978 100755 (executable)
@@ -17,6 +17,8 @@
 # You should have received a copy of the GNU General Public License
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
+. tests/meta/rc
+
 DESCRIPTION="skip in device_requires()"
 
 device_requires() {
index abeb56e6ad4f63498a69b1579a29ffcb11bf0250..f2d6c0f617c9c553cebda36cfc0222985ecea181 100755 (executable)
@@ -17,6 +17,8 @@
 # You should have received a copy of the GNU General Public License
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
+. tests/meta/rc
+
 DESCRIPTION="check dmesg"
 
 requires() {
index c179dad3d7c71632e4937c3109c24a3a7646e3f2..bc4b74f719b9594c25a821f37c6e62a2eb35a3d6 100755 (executable)
@@ -17,6 +17,8 @@
 # You should have received a copy of the GNU General Public License
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
+. tests/meta/rc
+
 DESCRIPTION="disable check dmesg"
 CHECK_DMESG=0
 
index 010ba4b142b822ab3cd235ea0426f84f449503b5..e8ccad78447121d9ebc06ecca9ca12b9a2b5b74a 100755 (executable)
@@ -17,6 +17,8 @@
 # You should have received a copy of the GNU General Public License
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
+. tests/meta/rc
+
 DESCRIPTION="filter dmesg"
 DMESG_FILTER="grep -v BUG"
 
index ab8c2a73eaa536e2de5fe9a6e2c0374bb52acd48..4e0a9b037372f750fa47974f981715906404c1be 100755 (executable)
@@ -17,6 +17,8 @@
 # You should have received a copy of the GNU General Public License
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
+. tests/meta/rc
+
 DESCRIPTION="record pid and random junk"
 
 test() {
index 8e3322ebe4c25d85aadebe6c63d3269f505dfb4c..190ee4a74047b1374e9b0e46acca885e4bc3cbc1 100644 (file)
@@ -17,6 +17,8 @@
 # You should have received a copy of the GNU General Public License
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
+. common/rc
+
 group_requires() {
        if [[ -v META_REQUIRES_SKIP ]]; then
                SKIP_REASON="META_REQUIRES_SKIP was set"
index 73ccaec1305abb06a9ad61c420d8954fe80baabd..415a48da6ac7391ab75950b462a651fa46b8bffd 100644 (file)
@@ -18,6 +18,8 @@
 # You should have received a copy of the GNU General Public License
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
+. tests/nbd/rc
+
 DESCRIPTION="resize a connected nbd device"
 QUICK=1
 
index c06c94631aabbb67f736e82d70651fd7a759e100..99acff72c7a1e6f6a5c1c4210e6fd46d65b52b81 100644 (file)
@@ -24,6 +24,8 @@
 # You should have received a copy of the GNU General Public License
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
+. tests/nbd/rc
+
 DESCRIPTION="tests on partition handling for an nbd device"
 QUICK=1
 
index 0d4c1c47f2bcd2e6b6e892426951466e06d72ae5..83a7417bca7b8567fb83ec95c6b35b0bf04a10ad 100644 (file)
 # You should have received a copy of the GNU General Public License
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
-. common/nbd
+. common/rc
 
 group_requires() {
        _have_root && _have_nbd && modprobe nbd
 }
+
+_have_nbd() {
+       if ! _have_module nbd; then
+               return 1
+       fi
+       if ! _have_program nbd-server; then
+               return 1
+       fi
+       if ! _have_program nbd-client; then
+               return 1
+       fi
+       if ! nbd-client --help 2>&1 | grep -q -- -L; then
+               SKIP_REASON="nbd-client does not have -nonetlink/-L option"
+               return 1
+       fi
+       return 0
+}
+
+_have_nbd_netlink() {
+       if ! _have_nbd; then
+               return 1
+       fi
+       if ! _have_program genl-ctrl-list; then
+               return 1
+       fi
+       if ! genl-ctrl-list | grep -q nbd; then
+               SKIP_REASON="nbd does not support netlink"
+               return 1
+       fi
+       return 0
+}
+
+_wait_for_nbd_connect() {
+       for ((i = 0; i < 3; i++)); do
+               if [[ -e /sys/kernel/debug/nbd/nbd0/tasks ]]; then
+                       return 0
+               fi
+               sleep 1
+       done
+       return 1
+}
+
+_wait_for_nbd_disconnect() {
+       for ((i = 0; i < 3; i++)); do
+               if [[ ! -e /sys/kernel/debug/nbd/nbd0/tasks ]]; then
+                       return 0
+               fi
+               sleep 1
+       done
+       return 1
+}
+
+_start_nbd_server() {
+       truncate -s 10G "${TMPDIR}/export"
+       cat > "${TMPDIR}/nbd.conf" << EOF
+[generic]
+[export]
+exportname=${TMPDIR}/export
+EOF
+       nbd-server -p "${TMPDIR}/nbd.pid" -C "${TMPDIR}/nbd.conf"
+}
+
+_stop_nbd_server() {
+       kill -SIGTERM "$(cat "${TMPDIR}/nbd.pid")"
+       rm -f "${TMPDIR}/nbd.pid"
+       rm -f "${TMPDIR}/export"
+}
index 0b5f241efcce735b73756947fe4f44870ab306a5..cfe675ec3aae6a5d6c2f09ec3a3b889e4034a8d0 100755 (executable)
@@ -18,8 +18,9 @@
 # You should have received a copy of the GNU General Public License
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
-DESCRIPTION="enable nvme_setup_nvm_cmd tracepoint and submit I/O to the device"
+. tests/nvme/rc
 
+DESCRIPTION="enable nvme_setup_nvm_cmd tracepoint and submit I/O to the device"
 QUICK=1
 
 requires() {
index 786505e222569bc51fbc5b4fb562062e7f030a2f..7e1815a04740cef240761e694eb356a4a36d86cd 100755 (executable)
@@ -18,6 +18,8 @@
 # You should have received a copy of the GNU General Public License
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
+. tests/nvme/rc
+
 DESCRIPTION="create many subsystems and test discovery"
 
 requires() {
index 96341309baf67eb5a40737c22746caf92290bae1..d22b8cfcc58d1fae09ec089bf78d861987eaef2d 100755 (executable)
@@ -18,8 +18,9 @@
 # You should have received a copy of the GNU General Public License
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
-DESCRIPTION="test if we're sending keep-alives to a discovery controller"
+. tests/nvme/rc
 
+DESCRIPTION="test if we're sending keep-alives to a discovery controller"
 QUICK=1
 
 requires() {
index ad268e2eec839cb323fd2b413ba4f292e0caff1e..3394740900c9cba88af676163e8899c3c3493e9f 100755 (executable)
@@ -19,6 +19,8 @@
 # You should have received a copy of the GNU General Public License
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
+. tests/nvme/rc
+
 DESCRIPTION="test nvme and nvmet UUID NS descriptors"
 QUICK=1
 
index f993019aa1d4c53b3d47a6213fbf75a2d8e0f326..e00f8e043a809150cd2d6dd5bde5ff68230f82e2 100755 (executable)
@@ -18,8 +18,9 @@
 # You should have received a copy of the GNU General Public License
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
-DESCRIPTION="reset local loopback target"
+. tests/nvme/rc
 
+DESCRIPTION="reset local loopback target"
 QUICK=1
 
 requires() {
index ecf0c334ae8bbf16bf494d0889e266d756e245c6..977a36321533b9e944012061aa3a2e22fc9b6057 100755 (executable)
@@ -20,6 +20,8 @@
 #   Author: Chaitanya Kulkarni <chaitanya.kulkarni@wdc.com>
 #
 
+. tests/nvme/rc
+
 DESCRIPTION="create an NVMeOF target with a block device-backed ns"
 QUICK=1
 
index 02633131b868423b0073be060c906f33332a2259..78f717229ee5b6ba908ac8730247555e3d871e09 100755 (executable)
@@ -20,6 +20,8 @@
 #   Author: Chaitanya Kulkarni <chaitanya.kulkarni@wdc.com>
 #
 
+. tests/nvme/rc
+
 DESCRIPTION="create an NVMeOF target with a file-backed ns"
 QUICK=1
 
index dd62b25c533526c11d093d8789b040fea1871b6d..013928dd040d9434dd345855424d039c02a685e3 100755 (executable)
@@ -20,6 +20,8 @@
 #   Author: Chaitanya Kulkarni <chaitanya.kulkarni@wdc.com>
 #
 
+. tests/nvme/rc
+
 DESCRIPTION="create an NVMeOF host with a block device-backed ns"
 QUICK=1
 
index 0372788fef39a799d8e7353f5e5212168e2466fa..9ba46e7d262c6e27482c572ac58399d94281c1ec 100755 (executable)
@@ -20,6 +20,8 @@
 #   Author: Chaitanya Kulkarni <chaitanya.kulkarni@wdc.com>
 #
 
+. tests/nvme/rc
+
 DESCRIPTION="create an NVMeOF host with a file-backed ns"
 QUICK=1
 
index 91e447c98d0a6f589c7a67839cfdb49ab6cdda82..3bdf57da26c748efee8b20d4f569aa08de5501ba 100755 (executable)
@@ -20,6 +20,8 @@
 #   Author: Chaitanya Kulkarni <chaitanya.kulkarni@wdc.com>
 #
 
+. tests/nvme/rc
+
 DESCRIPTION="run data verification fio job on NVMeOF block device-backed ns"
 TIMED=1
 
index 8bf2074c55e7faad5651a24b1bd25d469062c6cb..19484760504f815728065f7df76f51b6ea2cd9a2 100755 (executable)
@@ -20,6 +20,8 @@
 #   Author: Chaitanya Kulkarni <chaitanya.kulkarni@wdc.com>
 #
 
+. tests/nvme/rc
+
 DESCRIPTION="run data verification fio job on NVMeOF file-backed ns"
 TIMED=1
 
index 21a380993a2094bebdc6f7e60b3e63b6f7572d38..bdf3756ace5cd58712e010fe94116b7fa42e7ae6 100755 (executable)
@@ -20,6 +20,8 @@
 #   Author: Chaitanya Kulkarni <chaitanya.kulkarni@wdc.com>
 #
 
+. tests/nvme/rc
+
 DESCRIPTION="run mkfs and data verification fio job on NVMeOF block device-backed ns"
 TIMED=1
 
index 26efe24a0c1403195a6ec2d3b8f942987994b84c..7f42e49f107fc9b03a6f8ee136a4356ca535d2db 100755 (executable)
@@ -20,6 +20,8 @@
 #   Author: Chaitanya Kulkarni <chaitanya.kulkarni@wdc.com>
 #
 
+. tests/nvme/rc
+
 DESCRIPTION="run mkfs and data verification fio job on NVMeOF file-backed ns"
 TIMED=1
 
index 5e4e65c922c785b3fe649eee58f235e11d212cce..fb5dbdfc8e7dd8219d69aa6bc267016858e6be70 100644 (file)
@@ -17,7 +17,7 @@
 # You should have received a copy of the GNU General Public License
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
-. common/nvme
+. common/rc
 
 group_requires() {
        _have_root
@@ -26,3 +26,108 @@ group_requires() {
 group_device_requires() {
        _test_dev_is_nvme
 }
+
+NVMET_CFS="/sys/kernel/config/nvmet/"
+
+_test_dev_is_nvme() {
+       if ! readlink -f "$TEST_DEV_SYSFS/device" | grep -q nvme; then
+               SKIP_REASON="$TEST_DEV is not a NVMe device"
+               return 1
+       fi
+       return 0
+}
+
+_create_nvmet_port() {
+       local trtype="$1"
+
+       local port
+       for ((port = 0; ; port++)); do
+               if [[ ! -e "${NVMET_CFS}/ports/${port}" ]]; then
+                       break
+               fi
+       done
+
+       mkdir "${NVMET_CFS}/ports/${port}"
+       echo "${trtype}" > "${NVMET_CFS}/ports/${port}/addr_trtype"
+
+       echo "${port}"
+}
+
+_remove_nvmet_port() {
+       local port="$1"
+       rmdir "${NVMET_CFS}/ports/${port}"
+}
+
+_create_nvmet_ns() {
+       local nvmet_subsystem="$1"
+       local nsid="$2"
+       local blkdev="$3"
+       local uuid="00000000-0000-0000-0000-000000000000"
+       local subsys_path="${NVMET_CFS}/subsystems/${nvmet_subsystem}"
+       local ns_path="${subsys_path}/namespaces/${nsid}"
+
+       if [[ $# -eq 4 ]]; then
+               uuid="$4"
+       fi
+
+       mkdir "${ns_path}"
+       printf "%s" "${blkdev}" > "${ns_path}/device_path"
+       printf "%s" "${uuid}" > "${ns_path}/device_uuid"
+       printf 1 > "${ns_path}/enable"
+}
+
+_create_nvmet_subsystem() {
+       local nvmet_subsystem="$1"
+       local blkdev="$2"
+       local uuid=$3
+       local cfs_path="${NVMET_CFS}/subsystems/${nvmet_subsystem}"
+
+       mkdir -p "${cfs_path}"
+       echo 1 > "${cfs_path}/attr_allow_any_host"
+       _create_nvmet_ns "${nvmet_subsystem}" "1" "${blkdev}" "${uuid}"
+}
+
+_remove_nvmet_ns() {
+       local nvmet_subsystem="$1"
+       local nsid=$2
+       local subsys_path="${NVMET_CFS}/subsystems/${nvmet_subsystem}"
+       local nvmet_ns_path="${subsys_path}/namespaces/${nsid}"
+
+       echo 0 > "${nvmet_ns_path}/enable"
+       rmdir "${nvmet_ns_path}"
+}
+
+_remove_nvmet_subsystem() {
+       local nvmet_subsystem="$1"
+       local subsys_path="${NVMET_CFS}/subsystems/${nvmet_subsystem}"
+
+       _remove_nvmet_ns "${nvmet_subsystem}" "1"
+       rmdir "${subsys_path}"
+}
+
+_add_nvmet_subsys_to_port() {
+       local port="$1"
+       local nvmet_subsystem="$2"
+
+       ln -s "${NVMET_CFS}/subsystems/${nvmet_subsystem}" \
+               "${NVMET_CFS}/ports/${port}/subsystems/${nvmet_subsystem}"
+}
+
+_remove_nvmet_subsystem_from_port() {
+       local port="$1"
+       local nvmet_subsystem="$2"
+
+       rm "${NVMET_CFS}/ports/${port}/subsystems/${nvmet_subsystem}"
+}
+
+_find_nvme_loop_dev() {
+       local dev
+       local transport
+       for dev in /sys/class/nvme/nvme*; do
+               dev="$(basename "$dev")"
+               transport="$(cat "/sys/class/nvme/${dev}/transport")"
+               if [[ "$transport" == "loop" ]]; then
+                       echo "$dev"
+               fi
+       done
+}
index 17fc0880e65457410dd05f6b5903d5a5037da909..9b238ce786961ad17725b41fd5682dc92623b9b5 100755 (executable)
@@ -18,6 +18,8 @@
 # You should have received a copy of the GNU General Public License
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
+. tests/scsi/rc
+
 DESCRIPTION="try triggering a kernel GPF with 0 byte SG reads"
 QUICK=1
 
index da2d0cc77aa0b91a4236dca831cd052c2c88143c..21e69e021595893dfd2c4d6d1b9031a8389e6fc4 100755 (executable)
@@ -18,6 +18,8 @@
 # You should have received a copy of the GNU General Public License
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
+. tests/scsi/rc
+
 DESCRIPTION="perfom a SG_DXFER_FROM_DEV from the /dev/sg read-write interface"
 QUICK=1
 
index 81015f02f6b368e8d63f8accebb1f3f51c7f5635..4ce71291388a38f545af61eec3f8d5b850bcd238 100755 (executable)
@@ -18,6 +18,8 @@
 # You should have received a copy of the GNU General Public License
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
+. tests/scsi/rc
+
 DESCRIPTION="ensure re-reading the partition table keeps its read-only flag"
 QUICK=1
 
index 8c61d1e438f3a4c547a5f6aa4c79e603bf4f9047..34ffbb772a237e66f6f3fd7f974c62795c19829e 100755 (executable)
@@ -25,6 +25,7 @@
 # You should have received a copy of the GNU General Public License
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
+. tests/scsi/rc
 . common/scsi_debug
 
 DESCRIPTION="ensure repeated TASK SET FULL results in EIO on timing out command"
index e8b3161103d1eb0b6bae6f6b756521a682888ad0..62033faa49061439e76b28c5236e937b73d2c2fe 100644 (file)
@@ -17,7 +17,7 @@
 # You should have received a copy of the GNU General Public License
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
-. common/scsi
+. common/rc
 
 group_requires() {
        _have_root
@@ -26,3 +26,19 @@ group_requires() {
 group_device_requires() {
        _test_dev_is_scsi
 }
+
+_have_scsi_generic() {
+       _have_module sg
+}
+
+_test_dev_is_scsi() {
+       if [[ ! -d ${TEST_DEV_SYSFS}/device/scsi_device ]]; then
+               SKIP_REASON="$TEST_DEV is not a SCSI device"
+               return 1
+       fi
+       return 0
+}
+
+_get_test_dev_sg() {
+       echo "${TEST_DEV_SYSFS}"/device/scsi_generic/sg* | grep -Eo "sg[0-9]+"
+}