]> www.infradead.org Git - users/sagi/blktests.git/commitdiff
block/033: add test to cover gendisk leak
authorMing Lei <ming.lei@redhat.com>
Fri, 24 Feb 2023 12:45:02 +0000 (20:45 +0800)
committerShin'ichiro Kawasaki <shinichiro.kawasaki@wdc.com>
Thu, 2 Mar 2023 06:22:39 +0000 (15:22 +0900)
So far only sync ublk removal is supported, and the device's
last reference is dropped in gendisk's ->free_disk(), so it
can be used to test gendisk leak issue.

Signed-off-by: Ming Lei <ming.lei@redhat.com>
Reviewed-by: Chaitanya Kulkarni <kch@nvidia.com>
Signed-off-by: Shin'ichiro Kawasaki <shinichiro.kawasaki@wdc.com>
common/ublk [new file with mode: 0644]
tests/block/033 [new file with mode: 0755]
tests/block/033.out [new file with mode: 0644]

diff --git a/common/ublk b/common/ublk
new file mode 100644 (file)
index 0000000..932c534
--- /dev/null
@@ -0,0 +1,35 @@
+#!/bin/bash
+# SPDX-License-Identifier: GPL-3.0+
+# Copyright (C) 2023 Ming Lei
+#
+# ublk_drv helper functions.
+
+. common/shellcheck
+
+_have_ublk() {
+       _have_driver ublk_drv
+       _have_src_program miniublk
+}
+
+_remove_ublk_devices() {
+       src/miniublk del -a
+}
+
+_init_ublk() {
+       _remove_ublk_devices
+
+       modprobe -rq ublk_drv
+       if ! modprobe ublk_drv; then
+               SKIP_REASONS+=("requires ublk_drv")
+               return 1
+       fi
+
+       udevadm settle
+       return 0
+}
+
+_exit_ublk() {
+       _remove_ublk_devices
+       udevadm settle
+       modprobe -r -q ublk_drv
+}
diff --git a/tests/block/033 b/tests/block/033
new file mode 100755 (executable)
index 0000000..762f606
--- /dev/null
@@ -0,0 +1,41 @@
+#!/bin/bash
+# SPDX-License-Identifier: GPL-3.0+
+# Copyright (C) 2023 Ming Lei
+#
+# Test if gendisk is leaked, and regression in the following commit
+# c43332fe028c ("blk-cgroup: delay calling blkcg_exit_disk until disk_release")
+# can be covered
+
+. tests/block/rc
+. common/ublk
+
+DESCRIPTION="add & delete ublk device and test if gendisk is leaked"
+QUICK=1
+
+requires() {
+       _have_ublk
+}
+
+test() {
+       local ublk_prog="src/miniublk"
+
+       echo "Running ${TEST_NAME}"
+
+       if ! _init_ublk; then
+               return 1
+       fi
+
+       ${ublk_prog} add -t null -n 0 > "$FULL"
+       udevadm settle
+       if ! ${ublk_prog} list -n 0 >> "$FULL"; then
+               echo "fail to list dev"
+       fi
+       if ! dd if=/dev/ublkb0 iflag=direct of=/dev/null bs=1M count=512 >> "$FULL" 2>&1; then
+               echo "fail io"
+       fi
+       ${ublk_prog} del -n 0 >> "$FULL"
+
+       _exit_ublk
+
+       echo "Test complete"
+}
diff --git a/tests/block/033.out b/tests/block/033.out
new file mode 100644 (file)
index 0000000..067846a
--- /dev/null
@@ -0,0 +1,2 @@
+Running block/033
+Test complete