Skip to contentSkip to conversation

nvme: move _find_nvme_loop_dev to common code

PATCH New Johannes Thumshirn 3 participants 7 messages May 3, 2018 – May 15, 2018 NVMe

lore
Share & tools
lore
#0 lore raw

PATCH 1/3 nvme: move _find_nvme_loop_dev to common code

_find_nvme_loop_dev is quite useful for all nvme test, so move it over to common code.

Signed-off-by Johannes Thumshirn <jthumshirn at suse.de>
---
 common/nvme    | 10 ++++++++++
 tests/nvme/004 | 14 ++------------
 2 files changed, 12 insertions(+), 12 deletions(-)
common/nvme +10 -0
index c6718f04811b..c4a44065cd9f 100644
@@ -93,3 +93,13 @@ _remove_nvmet_subsystem_from_port() {
 
 	rm "${nvmet_cfs}/ports/${port}/subsystems/${nvmet_subsystem}"
 }
+
+_find_nvme_loop_dev() {
+	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
+}
tests/nvme/004 +2 -12
index 65bcd40d86d1..2f970b366d41 100755
@@ -27,16 +27,6 @@ requires() {
 		_have_configfs
 }
 
-_find_nvme_loop_dev() {
-	for dev in /sys/block/nvme*; do
-		dev="$(basename "$dev")"
-		transport="$(cat "/sys/block/${dev}/device/transport")"
-		if [[ "$transport" == "loop" ]]; then
-			echo "$dev"
-		fi
-	done
-}
-
 test() {
 	echo "Running ${TEST_NAME}"
 
@@ -59,8 +49,8 @@ test() {
 
 	local nvmedev
 	nvmedev="$(_find_nvme_loop_dev)"
-	cat "/sys/block/${nvmedev}/uuid"
-	cat "/sys/block/${nvmedev}/wwid"
+	cat "/sys/block/${nvmedev}n1/uuid"
+	cat "/sys/block/${nvmedev}n1/wwid"
 
 	_remove_nvmet_subsystem_from_port "${port}" "blktests-subsystem-1"
 	_remove_nvmet_subsystem "blktests-subsystem-1"
Signature · 1 line
2.16.3
#1 lore raw

PATCH 2/3 nvme: fix counting the target port

Signed-off-by Johannes Thumshirn <jthumshirn at suse.de>
---
 common/nvme | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
common/nvme +2 -2
index c4a44065cd9f..3e20eeaa5744 100644
@@ -27,11 +27,11 @@ _test_dev_is_nvme() {
 
 _create_nvmet_port() {
 	local trtype="$1"
-	local nvmet_cfs="/sys/kernel/config/nvmet/"
+	local nvmet_cfs="/sys/kernel/config/nvmet"
 
 	local port
 	for ((port = 0; ; port++)); do
-		if [[ ! -e "${nvmet_cfs}/${port}" ]]; then
+		if [[ ! -e "${nvmet_cfs}/ports/${port}" ]]; then
 			break
 		fi
 	done
Signature · 1 line
2.16.3
#2 lore raw

PATCH 3/3 nvme: add test for resetting the loopback controller

In reply to Johannes Thumshirn
Signed-off-by Johannes Thumshirn <jthumshirn at suse.de>
---
 tests/nvme/005     | 77 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
 tests/nvme/005.out |  2 ++
 2 files changed, 79 insertions(+)
 create mode 100755 tests/nvme/005
 create mode 100644 tests/nvme/005.out
tests/nvme/005 new file +77 -0
new file mode 100755
index 000000000000..77f843fed692
@@ -0,0 +1,77 @@
+#!/bin/bash
+#
+# Regression test for patch "nvmet: switch loopback target state to connecting
+# when resetting"
+#
+# 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/>.
+
+DESCRIPTION="reset local loopback target"
+
+QUICK=1
+
+requires() {
+ 	_have_module nvme-loop && _have_module nvmet && _have_module loop && \
+		_have_configfs && _have_module nvme-core && \
+		_have_module_param nvme-core multipath
+}
+
+test() {
+	echo "Running ${TEST_NAME}"
+
+	# Clean up all stale modules
+	modprobe -r nvme-loop
+	modprobe -r nvme-core
+	modprobe -r nvmet
+
+	modprobe nvme-core multipath=1
+	modprobe nvmet
+	modprobe nvme-loop
+
+	local port
+	port=$(_create_nvmet_port "loop")
+
+	truncate -s 1G "$TMPDIR/img"
+
+	local loop_dev
+	loop_dev="$(losetup -f --show "$TMPDIR/img")"
+
+	_create_nvmet_subsystem "blktests-subsystem-1" "${loop_dev}" \
+		"91fdba0d-f87b-4c25-b80f-db7be1418b9e"
+	_add_nvmet_subsys_to_port "${port}" "blktests-subsystem-1"
+
+	nvme connect -t loop -n blktests-subsystem-1
+
+	local nvmedev
+	nvmedev="$(_find_nvme_loop_dev)"
+
+	udevadm settle
+
+	echo 1 > "/sys/class/nvme/${nvmedev}/reset_controller"
+
+	nvme disconnect -d "${nvmedev}"
+	_remove_nvmet_subsystem_from_port "${port}" "blktests-subsystem-1"
+	_remove_nvmet_port "${port}"
+
+	_remove_nvmet_subsystem "blktests-subsystem-1"
+	losetup -d "$loop_dev"
+	rm "$TMPDIR/img"
+
+	modprobe -r nvme-loop
+	modprobe -r nvme-core
+	modprobe -r nvmet
+
+	echo "Test complete"
+}
tests/nvme/005.out new file +2 -0
new file mode 100644
index 000000000000..6146a7b8b1a7
@@ -0,0 +1,2 @@
+Running nvme/005
+Test complete
Signature · 1 line
2.16.3
#3 lore raw

PATCH 3/3 nvme: add test for resetting the loopback controller

Hi Johannes,

Thanks for submitting the test.

I was wondering if we can move the generic setup and clean up functionality to the helpers for reference:-

+pre()
+{
+ # Clean up all stale modules

+       modprobe -r nvme-loop
+       modprobe -r nvme-core
+       modprobe -r nvmet

+
}

+post()
+{

+       modprobe -r nvme-loop
+       modprobe -r nvme-core
+       modprobe -r nvmet

+
+}

+test() {
+ echo "Running ${TEST_NAME}"
+
+ pre
+

+       modprobe nvme-core multipath=1
+       modprobe nvmet
+       modprobe nvme-loop

+
+ local port
+ port=$(_create_nvmet_port "loop")
+
+ truncate -s 1G "$TMPDIR/img"
+
+ local loop_dev
+ loop_dev="$(losetup -f --show "$TMPDIR/img")"
+
+ _create_nvmet_subsystem "blktests-subsystem-1" "${loop_dev}" \
+ "91fdba0d-f87b-4c25-b80f-db7be1418b9e"
+ _add_nvmet_subsys_to_port "${port}" "blktests-subsystem-1"
+
+ nvme connect -t loop -n blktests-subsystem-1
+
+ local nvmedev
+ nvmedev="$(_find_nvme_loop_dev)"
+
+ udevadm settle
+
+ echo 1 > "/sys/class/nvme/${nvmedev}/reset_controller"
+

+       nvme disconnect -d "${nvmedev}"
+       _remove_nvmet_subsystem_from_port "${port}" "blktests-subsystem-1"
+       _remove_nvmet_port "${port}"
+
+       _remove_nvmet_subsystem "blktests-subsystem-1"
+       losetup -d "$loop_dev"
+       rm "$TMPDIR/img"

+
+ post
+
+ echo "Test complete"
+}

In this way, we can move generic pre and post to the nvme/lib so that all other tests can also use that?

Quoted 107 lines · Johannes Thumshirn
Signed-off-by Johannes Thumshirn <jthumshirn at suse.de>
---
 tests/nvme/005     | 77 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
 tests/nvme/005.out |  2 ++
 2 files changed, 79 insertions(+)
 create mode 100755 tests/nvme/005
 create mode 100644 tests/nvme/005.out
tests/nvme/005 new file +77 -0
new file mode 100755
index 000000000000..77f843fed692
@@ -0,0 +1,77 @@
+#!/bin/bash
+#
+# Regression test for patch "nvmet: switch loopback target state to connecting
+# when resetting"
+#
+# 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/>.
+
+DESCRIPTION="reset local loopback target"
+
+QUICK=1
+
+requires() {
+       _have_module nvme-loop && _have_module nvmet && _have_module loop && \
+               _have_configfs && _have_module nvme-core && \
+               _have_module_param nvme-core multipath
+}
+
+test() {
+       echo "Running ${TEST_NAME}"
+
+       # Clean up all stale modules
+       modprobe -r nvme-loop
+       modprobe -r nvme-core
+       modprobe -r nvmet
+
+       modprobe nvme-core multipath=1
+       modprobe nvmet
+       modprobe nvme-loop
+
+       local port
+       port=$(_create_nvmet_port "loop")
+
+       truncate -s 1G "$TMPDIR/img"
+
+       local loop_dev
+       loop_dev="$(losetup -f --show "$TMPDIR/img")"
+
+       _create_nvmet_subsystem "blktests-subsystem-1" "${loop_dev}" \
+               "91fdba0d-f87b-4c25-b80f-db7be1418b9e"
+       _add_nvmet_subsys_to_port "${port}" "blktests-subsystem-1"
+
+       nvme connect -t loop -n blktests-subsystem-1
+
+       local nvmedev
+       nvmedev="$(_find_nvme_loop_dev)"
+
+       udevadm settle
+
+       echo 1 > "/sys/class/nvme/${nvmedev}/reset_controller"
+
+       nvme disconnect -d "${nvmedev}"
+       _remove_nvmet_subsystem_from_port "${port}" "blktests-subsystem-1"
+       _remove_nvmet_port "${port}"
+
+       _remove_nvmet_subsystem "blktests-subsystem-1"
+       losetup -d "$loop_dev"
+       rm "$TMPDIR/img"
+
+       modprobe -r nvme-loop
+       modprobe -r nvme-core
+       modprobe -r nvmet
+
+       echo "Test complete"
+}
tests/nvme/005.out new file +2 -1
new file mode 100644
index 000000000000..6146a7b8b1a7
@@ -0,0 +1,2 @@
+Running nvme/005
+Test complete
--

2.16.3

_______________________________________________
Linux-nvme mailing list
Linux-nvme at lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-nvme

#4 lore raw

PATCH 3/3 nvme: add test for resetting the loopback controller

Quoted 16 lines · chaitany kulkarni

Hi Johannes,

Thanks for submitting the test.

I was wondering if we can move the generic setup and clean up functionality to the helpers for reference:-

tests/nvme/005 new file +7 -0
+pre()
+{
+      # Clean up all stale modules
+       modprobe -r nvme-loop
+       modprobe -r nvme-core
+       modprobe -r nvmet
+

}

tests/nvme/005 line 77

Quoted 7 lines
tests/nvme/005 new file +7 -0
+post()
+{
+       modprobe -r nvme-loop
+       modprobe -r nvme-core
+       modprobe -r nvmet
+
+}

I was thinking of the same as well but then I'd rather love "generic" pre()/post() callbacks which the framework calles and not the actual test case (just like requires() et al).

You can't really make the content's of pre()/post() generically enough for all tests of a category unfortunately so I think placing them into common/ won't work (i.e. for the next test I have in the pipeline I need nvme-fcloop not nvme-loop, and so on).

Let me think a bit more about it.

Johannes

Signature · 6 lines
Johannes Thumshirn                                          Storage
jthumshirn at suse.de                                +49 911 74053 689
SUSE LINUX GmbH, Maxfeldstr. 5, 90409 N?rnberg
GF: Felix Imend?rffer, Jane Smithard, Graham Norton
HRB 21284 (AG N?rnberg)
Key fingerprint = EC38 9CAB C2C4 F25D 8600 D0D0 0393 969D 2D76 0850
#5 lore raw

PATCH 1/3 nvme: move _find_nvme_loop_dev to common code

In reply to Johannes Thumshirn
Quoted 62 lines · Johannes Thumshirn

_find_nvme_loop_dev is quite useful for all nvme test, so move it over to common code.

Signed-off-by Johannes Thumshirn <jthumshirn at suse.de>
---
 common/nvme    | 10 ++++++++++
 tests/nvme/004 | 14 ++------------
 2 files changed, 12 insertions(+), 12 deletions(-)
common/nvme +10 -0
index c6718f04811b..c4a44065cd9f 100644
@@ -93,3 +93,13 @@ _remove_nvmet_subsystem_from_port() {
 
 	rm "${nvmet_cfs}/ports/${port}/subsystems/${nvmet_subsystem}"
 }
+
+_find_nvme_loop_dev() {
+	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
+}
tests/nvme/004 +2 -12
index 65bcd40d86d1..2f970b366d41 100755
@@ -27,16 +27,6 @@ requires() {
 		_have_configfs
 }
 
-_find_nvme_loop_dev() {
-	for dev in /sys/block/nvme*; do
-		dev="$(basename "$dev")"
-		transport="$(cat "/sys/block/${dev}/device/transport")"
-		if [[ "$transport" == "loop" ]]; then
-			echo "$dev"
-		fi
-	done
-}
-
 test() {
 	echo "Running ${TEST_NAME}"
 
@@ -59,8 +49,8 @@ test() {
 
 	local nvmedev
 	nvmedev="$(_find_nvme_loop_dev)"
-	cat "/sys/block/${nvmedev}/uuid"
-	cat "/sys/block/${nvmedev}/wwid"
+	cat "/sys/block/${nvmedev}n1/uuid"
+	cat "/sys/block/${nvmedev}n1/wwid"
 
 	_remove_nvmet_subsystem_from_port "${port}" "blktests-subsystem-1"
 	_remove_nvmet_subsystem "blktests-subsystem-1"
Signature · 1 line
2.16.3

Thanks, Johannes, applied. I split patch 1 into two, though; one fixing the test, and one just moving the function.

#6 lore raw

PATCH 1/3 nvme: move _find_nvme_loop_dev to common code

Quoted 2 lines · Omar Sandoval

Thanks, Johannes, applied. I split patch 1 into two, though; one fixing the test, and one just moving the function.

Thanks Omar

Signature · 6 lines
Johannes Thumshirn                                          Storage
jthumshirn at suse.de                                +49 911 74053 689
SUSE LINUX GmbH, Maxfeldstr. 5, 90409 N?rnberg
GF: Felix Imend?rffer, Jane Smithard, Graham Norton
HRB 21284 (AG N?rnberg)
Key fingerprint = EC38 9CAB C2C4 F25D 8600 D0D0 0393 969D 2D76 0850