I suggest the commit title: block/033: add test to cover gendisk leak On Feb 16, 2023 / 11:01, Ming Lei wrote: > 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@xxxxxxxxxx> > --- > common/ublk | 32 ++++++++++++++++++++++++++++++++ > tests/block/033 | 33 +++++++++++++++++++++++++++++++++ > tests/block/033.out | 2 ++ > 3 files changed, 67 insertions(+) > create mode 100644 common/ublk > create mode 100755 tests/block/033 > create mode 100644 tests/block/033.out > > diff --git a/common/ublk b/common/ublk > new file mode 100644 > index 0000000..66b3a58 > --- /dev/null > +++ b/common/ublk > @@ -0,0 +1,32 @@ > +#!/bin/bash > +# SPDX-License-Identifier: GPL-3.0+ > +# Copyright (C) 2023 Ming Lei > +# > +# null_blk helper functions. I think you meant s/null_blk/ublk/ > + > +. common/shellcheck > + > +_have_ublk() { > + _have_driver ublk_drv The _init_ublk() below looks assuming the ublk_drv modules is loadable. If so, the live above should be: _have_module ublk_drv Of note is that some of the blkteste users run tests with all drivers as built-in modules. So it is the better that the new test case can run with built-in ublk_drv, if possible. (Or it can be a left work.) > + _have_src_program ublk/miniublk > +} > + > +_remove_ublk_devices() { > + src/ublk/miniublk del -a > +} > + > +_init_ublk() { > + if ! modprobe -r ublk_drv || ! modprobe ublk_drv "${args[@]}" ; then > + SKIP_REASONS+=("requires modular 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 > index 0000000..342ccf3 > --- /dev/null > +++ b/tests/block/033 > @@ -0,0 +1,33 @@ > +#!/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/ublk/miniublk" > + echo "Running ${TEST_NAME}" > + > + if ! _init_ublk; then > + return 1 > + fi > + > + local ublk_dev=`$ublk_prog add -t null --quiet` > + $ublk_prog del --disk=$ublk_dev > /dev/null 2>&1 > + > + _exit_ublk > + > + echo "Test complete" > +} > diff --git a/tests/block/033.out b/tests/block/033.out > new file mode 100644 > index 0000000..067846a > --- /dev/null > +++ b/tests/block/033.out > @@ -0,0 +1,2 @@ > +Running block/033 > +Test complete > -- > 2.31.1 > -- Shin'ichiro Kawasaki