Skip to content

Commit 9d472e9

Browse files
committed
common/nvme: do not call 'nvme id-ns' to non-nvme devices
The test case block/041 tests PI metadata capability in the block layer. At this moment, nvme is the only one block device that supports the capability. To check that the test target nvme devices fulfills the requirement, the test case calls 'nvme ns-id' command via _test_dev_disable_extended_lba(). However, since the test case is in the block group, TEST_DEVS can specify non-nvme devices. Even though the test case is skipped by _require_test_dev_is_nvme() check, the 'nvme ns-id' is called for the non-nvme device and fails. It spits out unnecessary error messages. To avoid the error message, check if the test device is nvme before calling 'nvme ns-id'. For the check, factor out a helper function _test_dev_is_nvme(). While at it, replace short command options -q and -f with long options --quiet and --canonicalize for readability. Reviewed-by: Chaitanya Kulkarni <[email protected]> Signed-off-by: Shin'ichiro Kawasaki <[email protected]>
1 parent b14a95a commit 9d472e9

1 file changed

Lines changed: 7 additions & 3 deletions

File tree

common/nvme

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1115,8 +1115,12 @@ _nvmet_target_cleanup() {
11151115
fi
11161116
}
11171117

1118+
_test_dev_is_nvme() {
1119+
readlink --canonicalize "$TEST_DEV_SYSFS/device" | grep --quiet nvme
1120+
}
1121+
11181122
_require_test_dev_is_nvme() {
1119-
if ! readlink -f "$TEST_DEV_SYSFS/device" | grep -q nvme; then
1123+
if ! _test_dev_is_nvme; then
11201124
SKIP_REASONS+=("$TEST_DEV is not a NVMe device")
11211125
return 1
11221126
fi
@@ -1144,8 +1148,8 @@ _test_dev_has_no_metadata() {
11441148
_test_dev_disables_extended_lba() {
11451149
local flbas
11461150

1147-
if ! flbas=$(nvme id-ns "$TEST_DEV" | grep flbas | \
1148-
sed --quiet 's/.*: \(.*\)/\1/p'); then
1151+
if ! _test_dev_is_nvme || ! flbas=$(nvme id-ns "$TEST_DEV" | \
1152+
grep flbas | sed --quiet 's/.*: \(.*\)/\1/p'); then
11491153
SKIP_REASONS+=("$TEST_DEV does not have namespace flbas field")
11501154
return 1
11511155
fi

0 commit comments

Comments
 (0)