]> www.infradead.org Git - users/hch/blktests.git/commitdiff
nbd: add a module load and device connect test
authorSun Ke <sunke32@huawei.com>
Tue, 19 Jul 2022 07:12:16 +0000 (15:12 +0800)
committerShin'ichiro Kawasaki <shinichiro.kawasaki@wdc.com>
Fri, 22 Jul 2022 00:44:23 +0000 (09:44 +0900)
This is a regression test for commit 06c4da89c24e
nbd: call genl_unregister_family() first in nbd_cleanup()

Two concurrent processes,one load and unload nbd module
cyclically, the other one connect and disconnect nbd device cyclically.
Last for 10 seconds.

Signed-off-by: Sun Ke <sunke32@huawei.com>
Signed-off-by: Shin'ichiro Kawasaki <shinichiro.kawasaki@wdc.com>
tests/nbd/004 [new file with mode: 0755]
tests/nbd/004.out [new file with mode: 0644]
tests/nbd/rc

diff --git a/tests/nbd/004 b/tests/nbd/004
new file mode 100755 (executable)
index 0000000..98afd09
--- /dev/null
@@ -0,0 +1,58 @@
+#!/bin/bash
+# SPDX-License-Identifier: GPL-3.0+
+# Copyright (C) 2022 Sun Ke
+#
+# Regression test for commit 06c4da89c24e
+# nbd: call genl_unregister_family() first in nbd_cleanup()
+
+. tests/nbd/rc
+
+DESCRIPTION="module load/unload concurrently with connect/disconnect"
+QUICK=1
+
+requires() {
+       _have_modules nbd
+}
+
+module_load_and_unload() {
+       while true; do
+               modprobe nbd >/dev/null 2>&1
+               modprobe -r nbd >/dev/null 2>&1
+       done
+}
+
+connect_and_disconnect() {
+       while true; do
+               _netlink_connect >/dev/null 2>&1
+               _netlink_disconnect >/dev/null 2>&1
+       done
+}
+
+test() {
+       echo "Running ${TEST_NAME}"
+
+       _start_nbd_server_netlink
+
+       module_load_and_unload &
+       pid1=$!
+       connect_and_disconnect &
+       pid2=$!
+
+       sleep 10
+       {
+               kill -9 $pid1
+               wait $pid1
+               kill -9 $pid2
+               wait $pid2
+       } 2>/dev/null
+
+       _stop_nbd_server_netlink
+
+       if _dmesg_since_test_start | grep -q -e "couldn't allocate config" \
+               -e "cannot create duplicate filename"; then
+                       echo "Fail"
+       fi
+
+       echo "Test complete"
+}
+
diff --git a/tests/nbd/004.out b/tests/nbd/004.out
new file mode 100644 (file)
index 0000000..05ced0c
--- /dev/null
@@ -0,0 +1,2 @@
+Running nbd/004
+Test complete
index 5cfb2cc6f64c314f1328e6e53ea9a484b33e084f..9c1c15b1a96164f7f1fe9442c4f5f804665e3c1c 100644 (file)
@@ -76,3 +76,21 @@ _stop_nbd_server() {
        rm -f "${TMPDIR}/nbd.pid"
        rm -f "${TMPDIR}/export"
 }
+
+_start_nbd_server_netlink() {
+       truncate -s 10G "${TMPDIR}/export"
+       nbd-server 8000 "${TMPDIR}/export" >/dev/null 2>&1
+}
+
+_stop_nbd_server_netlink() {
+       killall -SIGTERM nbd-server
+       rm -f "${TMPDIR}/export"
+}
+
+_netlink_connect() {
+       nbd-client localhost 8000 /dev/nbd0 >> "$FULL" 2>&1
+}
+
+_netlink_disconnect() {
+       nbd-client -d /dev/nbd0 >> "$FULL" 2>&1
+}