--- /dev/null
+#!/bin/bash
+# SPDX-License-Identifier: GPL-3.0+
+# Copyright (C) 2019 Logan Gunthorpe
+#
+# Regression test for the following patches:
+# nvme: fix controller removal race with scan work
+# nvme: fix regression upon hot device removal and insertion
+# nvme-core: Fix extra device_put() call on error path
+# nvmet-loop: Flush nvme_delete_wq when removing the port
+# nvmet: Fix use-after-free bug when a port is removed
+#
+# All these patches fix issues related to deleting a controller
+# immediately after setting it up.
+
+. tests/nvme/rc
+
+DESCRIPTION="test deletion of NVMeOF controllers immediately after setup"
+QUICK=1
+
+requires() {
+ _have_program nvme &&
+ _have_modules loop nvme-loop nvmet &&
+ _have_configfs
+}
+
+test() {
+ local subsys="blktests-subsystem-"
+ local iterations=10
+ local loop_dev
+ local port
+
+ echo "Running ${TEST_NAME}"
+
+ _setup_nvmet
+
+ truncate -s 1G "$TMPDIR/img"
+
+ loop_dev="$(losetup -f --show "$TMPDIR/img")"
+
+ port="$(_create_nvmet_port "loop")"
+
+ for ((i = 0; i < iterations; i++)); do
+ _create_nvmet_subsystem "${subsys}$i" "${loop_dev}"
+ _add_nvmet_subsys_to_port "${port}" "${subsys}$i"
+ nvme connect -t loop -n "${subsys}$i"
+ nvme disconnect -n "${subsys}$i" >> "${FULL}" 2>&1
+ _remove_nvmet_subsystem_from_port "${port}" "${subsys}$i"
+ _remove_nvmet_subsystem "${subsys}$i"
+ done
+
+ _remove_nvmet_port "${port}"
+
+ echo "Test complete"
+}