diff mbox series

[blktests,v2,03/12] nvme: Add new test to verify the generation counter

Message ID 20190717171259.3311-4-logang@deltatee.com (mailing list archive)
State New, archived
Headers show
Series Fix nvme block test issues | expand

Commit Message

Logan Gunthorpe July 17, 2019, 5:12 p.m. UTC
Now that the other discovery tests ignore the generation counter value,
create a new test to specifically check that it increments when
subsystems are added or removed from ports and when allow_any_host
is set/unset.

Signed-off-by: Logan Gunthorpe <logang@deltatee.com>
---
 tests/nvme/030     | 76 ++++++++++++++++++++++++++++++++++++++++++++++
 tests/nvme/030.out |  2 ++
 tests/nvme/rc      |  5 +++
 3 files changed, 83 insertions(+)
 create mode 100755 tests/nvme/030
 create mode 100644 tests/nvme/030.out

Comments

Johannes Thumshirn July 18, 2019, 7:03 a.m. UTC | #1
On Wed, Jul 17, 2019 at 11:12:50AM -0600, Logan Gunthorpe wrote:
[...]
> +_discovery_genctr() {
> +	nvme discover -t loop |
> +		sed -n -e 's/^.*Generation counter \([0-9]\+\).*$/\1/p'
> +}

Sorry for not having spotted this in v1, but do we really want to hard-core
the transport type in a library function?

Maybe sth like this:

_discovery_genctr() {
	local trtype=$1
	nvme discover -t ${trtype} |
		sed -n -e 's/^.*Generation counter \([0-9]\+\).*$/\1/p'
}

I think Omar can fix it up when applying.

Byte,
	Johannes
Logan Gunthorpe July 18, 2019, 3:55 p.m. UTC | #2
On 2019-07-18 1:03 a.m., Johannes Thumshirn wrote:
> On Wed, Jul 17, 2019 at 11:12:50AM -0600, Logan Gunthorpe wrote:
> [...]
>> +_discovery_genctr() {
>> +	nvme discover -t loop |
>> +		sed -n -e 's/^.*Generation counter \([0-9]\+\).*$/\1/p'
>> +}
> 
> Sorry for not having spotted this in v1, but do we really want to hard-core
> the transport type in a library function?

My opinion is that this is unnecessary until we have users of the
function that need different transport types. It's easy enough for
someone to change when they need it. It's a pretty standard practice in
kernel development to not add a feature that no-one uses.

Logan
diff mbox series

Patch

diff --git a/tests/nvme/030 b/tests/nvme/030
new file mode 100755
index 000000000000..963e1ad7118c
--- /dev/null
+++ b/tests/nvme/030
@@ -0,0 +1,76 @@ 
+#!/bin/bash
+# SPDX-License-Identifier: GPL-3.0+
+# Copyright (C) 2019 Logan Gunthorpe
+#
+# Test nvme discovery generation counter
+
+. tests/nvme/rc
+
+DESCRIPTION="ensure the discovery generation counter is updated appropriately"
+QUICK=1
+
+requires() {
+	_have_program nvme &&
+	_have_modules loop nvme-loop nvmet &&
+	_have_configfs
+}
+
+
+checkgenctr() {
+	local last=$1
+	local msg=$2
+	local genctr
+
+	genctr=$(_discovery_genctr)
+	if (( "${genctr}" <= "${last}" )); then
+		echo "Generation counter not incremented when ${msg} (${genctr} <= ${last})"
+	fi
+
+	echo "${genctr}"
+}
+
+test() {
+	local port
+	local genctr
+	local subsys="blktests-subsystem-"
+
+	echo "Running ${TEST_NAME}"
+
+	modprobe nvmet
+	modprobe nvme-loop
+
+	port="$(_create_nvmet_port "loop")"
+
+	_create_nvmet_subsystem "${subsys}1" "$(losetup -f)"
+	_add_nvmet_subsys_to_port "${port}" "${subsys}1"
+
+	genctr=$(_discovery_genctr)
+
+	_create_nvmet_subsystem "${subsys}2" "$(losetup -f)"
+	_add_nvmet_subsys_to_port "${port}" "${subsys}2"
+
+	genctr=$(checkgenctr "${genctr}" "adding a subsystem to a port")
+
+	echo 0 > "${NVMET_CFS}/subsystems/${subsys}2/attr_allow_any_host"
+
+	genctr=$(checkgenctr "${genctr}" "clearing attr_allow_any_host")
+
+	echo 1 > "${NVMET_CFS}/subsystems/${subsys}2/attr_allow_any_host"
+
+	genctr=$(checkgenctr "${genctr}" "setting attr_allow_any_host")
+
+	_remove_nvmet_subsystem_from_port "${port}" "${subsys}2"
+	_remove_nvmet_subsystem "${subsys}2"
+
+	genctr=$(checkgenctr "${genctr}" "removing a subsystem from a port")
+
+	_remove_nvmet_subsystem_from_port "${port}" "${subsys}1"
+	_remove_nvmet_subsystem "${subsys}1"
+
+	_remove_nvmet_port "${port}"
+
+	modprobe -r nvme-loop
+	modprobe -r nvmet
+
+	echo "Test complete"
+}
diff --git a/tests/nvme/030.out b/tests/nvme/030.out
new file mode 100644
index 000000000000..93e51905b5d4
--- /dev/null
+++ b/tests/nvme/030.out
@@ -0,0 +1,2 @@ 
+Running nvme/030
+Test complete
diff --git a/tests/nvme/rc b/tests/nvme/rc
index 74e316248ef5..7be6c903611b 100644
--- a/tests/nvme/rc
+++ b/tests/nvme/rc
@@ -124,3 +124,8 @@  _filter_discovery() {
 		  -e '/Discovery Log Number|Log Entry|trtype|subnqn/p'
 
 }
+
+_discovery_genctr() {
+	nvme discover -t loop |
+		sed -n -e 's/^.*Generation counter \([0-9]\+\).*$/\1/p'
+}