blktests: add mini ublk source and blktests/033
Subsystems (2)
v2 cover blktests: add mini ublk source and blktests/033
Hello,
The 1st patch adds one mini ublk program, which only supports null & loop targets.
The 2nd patch add blktests/033 for covering gendisk leak issue.
v2:
- cleanup & bugfix on miniublk.c
- avoid ignoring build warning just for addressing missed liburing or ublk kernel header
- patch style fix
- make 'make check' happy
Ming Lei (2):
src: add mini ublk source code
block/033: add test to cover gendisk leak
Makefile | 2 +- common/ublk | 34 ++ src/Makefile | 18 + src/ublk/miniublk.c | 1376 +++++++++++++++++++++++++++++++++++++++++++ tests/block/033 | 40 ++ tests/block/033.out | 2 + 6 files changed, 1471 insertions(+), 1 deletion(-) create mode 100644 common/ublk create mode 100644 src/ublk/miniublk.c create mode 100755 tests/block/033 create mode 100644 tests/block/033.out
Signature · 1 line
2.31.1
PATCH v2 1/2 src: add mini ublk source code
Prepare for adding ublk related test:
1) ublk delete is sync removal, this way is convenient to blkg/queue/disk instance leak issue
2) mini ublk has two builtin target(null, loop), and loop IO is handled by io_uring, so we can use ublk to cover part of io_uring workloads
3) not like loop/nbd, ublk won't pre-allocate/add disk, and always add/delete disk dynamically, this way may cover disk plug & unplug tests
4) ublk specific test given people starts to use it, so better to let blktest cover ublk related tests
Add mini ublk source for test purpose only, which is easy to use:
./miniublk add -t {null|loop} [-q nr_queues] [-d depth] [-n dev_id]
default: nr_queues=2(max 4), depth=128(max 128), dev_id=-1(auto allocation) -t loop -f backing_file -t null
./miniublk del [-n dev_id] [--disk/-d disk_path ] -a
-a delete all devices, -d delete device by disk path, -n delete specified device
./miniublk list [-n dev_id] -a
-a list all devices, -n list specified device, default -a
ublk depends on liburing 2.2, so allow to ignore ublk build failure in case of missing liburing, and we will check if ublk program exits inside test. Also v6.0 is the 1st linux kernel release with ublk.
--- Makefile | 2 +- src/Makefile | 18 + src/ublk/miniublk.c | 1376 +++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 1395 insertions(+), 1 deletion(-) create mode 100644 src/ublk/miniublk.c
Makefile +1 -1
@@ -2,7 +2,7 @@ prefix ?= /usr/local dest = $(DESTDIR)$(prefix)/blktests all: - $(MAKE) -C src all + $(MAKE) -i -C src all clean: $(MAKE) -C src clean
src/Makefile +18 -0
@@ -2,6 +2,10 @@ HAVE_C_HEADER = $(shell if echo "\#include <$(1)>" | \ $(CC) -E - > /dev/null 2>&1; then echo "$(2)"; \ else echo "$(3)"; fi) +HAVE_C_MACRO = $(shell if echo "#include <$(1)>" | \ + $(CC) -E - 2>&1 /dev/null | grep $(2) > /dev/null 2>&1; \ + then echo 1;else echo 0; fi) + C_TARGETS := \ loblksize \ loop_change_fd \
@@ -13,16 +17,27 @@ C_TARGETS := \ sg/syzkaller1 \ zbdioctl +C_MINIUBLK := ublk/miniublk + +HAVE_LIBURING := $(call HAVE_C_MACRO,liburing.h,IORING_OP_URING_CMD) +HAVE_UBLK_HEADER := $(call HAVE_C_HEADER,linux/ublk_cmd.h,1) + CXX_TARGETS := \ discontiguous-io +ifeq ($(HAVE_LIBURING)$(HAVE_UBLK_HEADER), 11) +TARGETS := $(C_TARGETS) $(CXX_TARGETS) $(C_MINIUBLK) +else +$(info Skip $(C_MINIUBLK) build due to missing kernel header(v6.0+) or liburing(2.2+)) TARGETS := $(C_TARGETS) $(CXX_TARGETS) +endif CONFIG_DEFS := $(call HAVE_C_HEADER,linux/blkzoned.h,-DHAVE_LINUX_BLKZONED_H) override CFLAGS := -O2 -Wall -Wshadow $(CFLAGS) $(CONFIG_DEFS) override CXXFLAGS := -O2 -std=c++11 -Wall -Wextra -Wshadow -Wno-sign-compare \ -Werror $(CXXFLAGS) $(CONFIG_DEFS) +MINIUBLK_FLAGS := -D_GNU_SOURCE -lpthread -luring all: $(TARGETS)
@@ -39,4 +54,7 @@ $(C_TARGETS): %: %.c $(CXX_TARGETS): %: %.cpp $(CXX) $(CPPFLAGS) $(CXXFLAGS) -o $@ $^ +$(C_MINIUBLK): %: ublk/miniublk.c + $(CC) $(CFLAGS) $(MINIUBLK_FLAGS) -o $@ ublk/miniublk.c + .PHONY: all clean install
src/ublk/miniublk.c new file +1376 -0
1,376 lines not on this page · raw message
Signature · 1 line
2.31.1
Re: [PATCH blktests v2 1/2] src: add mini ublk source code
Quoted 45 lines · Ming Lei
Prepare for adding ublk related test:
1) ublk delete is sync removal, this way is convenient to blkg/queue/disk instance leak issue
2) mini ublk has two builtin
target(null, loop), and loop IO is handled byio_uring, so we can use ublk to cover part ofio_uringworkloads3) not like loop/nbd, ublk won't pre-allocate/add disk, and always add/delete disk dynamically, this way may cover disk plug & unplug tests
4) ublk specific test given people starts to use it, so better to let blktest cover ublk related tests
Add mini ublk source for test purpose only, which is easy to use:
./miniublk add -t {null|loop} [-q
nr_queues] [-d depth] [-ndev_id]default: nr_queues=2(max 4), depth=128(max 128), dev_id=-1(auto allocation) -t loop -f backing_file -t null./miniublk del [-n
dev_id] [--disk/-ddisk_path] -a
-a delete all devices, -d delete device by disk path, -n delete specified device
./miniublk list [-ndev_id] -a
-a list all devices, -n list specified device, default -aublk depends on liburing 2.2, so allow to ignore ublk build failure in case of missing liburing, and we will check if ublk program exits inside test. Also v6.0 is the 1st linux kernel release with ublk.
Signed-off-by Ming Lei <[email protected]>--- Makefile | 2 +- src/Makefile | 18 + src/ublk/miniublk.c | 1376 +++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 1395 insertions(+), 1 deletion(-) create mode 100644 src/ublk/miniublk.cMakefile +0
-0
Makefile prefix ?= /usr/local · line 5
Quoted 5 lines
Makefile +1
-1@@ -2,7 +2,7 @@ prefix ?= /usr/local dest = $(DESTDIR)$(prefix)/blktests all: - $(MAKE) -C src all + $(MAKE) -i -C src all
oops, the above change needs to be removed.
Shin'ichiro, I will kill it in V3 if it is needed, otherwise please drop the above change when you merge the patch.
Thanks,
Ming
Re: [PATCH blktests v2 1/2] src: add mini ublk source code
In reply to Ming LeiHi Ming, thanks for the v2 series. Please find my comments in line.
Quoted 28 lines · Ming Lei
Prepare for adding ublk related test:
1) ublk delete is sync removal, this way is convenient to blkg/queue/disk instance leak issue
2) mini ublk has two builtin
target(null, loop), and loop IO is handled byio_uring, so we can use ublk to cover part ofio_uringworkloads3) not like loop/nbd, ublk won't pre-allocate/add disk, and always add/delete disk dynamically, this way may cover disk plug & unplug tests
4) ublk specific test given people starts to use it, so better to let blktest cover ublk related tests
Add mini ublk source for test purpose only, which is easy to use:
./miniublk add -t {null|loop} [-q
nr_queues] [-d depth] [-ndev_id]default: nr_queues=2(max 4), depth=128(max 128), dev_id=-1(auto allocation) -t loop -f backing_file -t null./miniublk del [-n
dev_id] [--disk/-ddisk_path] -a
-a delete all devices, -d delete device by disk path, -n delete specified device
./miniublk list [-ndev_id] -a
-a list all devices, -n list specified device, default -a
Quoted 3 lines
ublk depends on liburing 2.2, so allow to ignore ublk build failure in case of missing liburing, and we will check if ublk program exits inside test. Also v6.0 is the 1st linux kernel release with ublk.
This v2 patch prevents the ublk build failure. Could you rewrite this paragraph?
Quoted 14 lines
Signed-off-by Ming Lei <[email protected]>--- Makefile | 2 +- src/Makefile | 18 + src/ublk/miniublk.c | 1376 +++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 1395 insertions(+), 1 deletion(-) create mode 100644 src/ublk/miniublk.cMakefile +0
-0
Makefile prefix ?= /usr/local · line 5
Quoted 5 lines
Makefile +1
-1@@ -2,7 +2,7 @@ prefix ?= /usr/local dest = $(DESTDIR)$(prefix)/blktests all: - $(MAKE) -C src all + $(MAKE) -i -C src all
As you pointed out in another e-mail, -i is no longer required.
src/ublk/miniublk.c
Quoted 59 lines
Makefile +0
-0clean: $(MAKE) -C src cleansrc/Makefile +18
-0@@ -2,6 +2,10 @@ HAVE_C_HEADER = $(shell if echo "\#include <$(1)>" | \ $(CC) -E - > /dev/null 2>&1; then echo "$(2)"; \ else echo "$(3)"; fi) +HAVE_C_MACRO = $(shell if echo "#include <$(1)>" | \ + $(CC) -E - 2>&1 /dev/null | grep $(2) > /dev/null 2>&1; \ + then echo 1;else echo 0; fi) + C_TARGETS := \ loblksize \ loop_change_fd \@@ -13,16 +17,27 @@ C_TARGETS := \ sg/syzkaller1 \ zbdioctl +C_MINIUBLK := ublk/miniublk + +HAVE_LIBURING := $(call HAVE_C_MACRO,liburing.h,IORING_OP_URING_CMD) +HAVE_UBLK_HEADER := $(call HAVE_C_HEADER,linux/ublk_cmd.h,1) + CXX_TARGETS := \ discontiguous-io +ifeq ($(HAVE_LIBURING)$(HAVE_UBLK_HEADER), 11) +TARGETS := $(C_TARGETS) $(CXX_TARGETS) $(C_MINIUBLK) +else +$(info Skip $(C_MINIUBLK) build due to missing kernel header(v6.0+) or liburing(2.2+)) TARGETS := $(C_TARGETS) $(CXX_TARGETS) +endif CONFIG_DEFS := $(call HAVE_C_HEADER,linux/blkzoned.h,-DHAVE_LINUX_BLKZONED_H) override CFLAGS := -O2 -Wall -Wshadow $(CFLAGS) $(CONFIG_DEFS) override CXXFLAGS := -O2 -std=c++11 -Wall -Wextra -Wshadow -Wno-sign-compare \ -Werror $(CXXFLAGS) $(CONFIG_DEFS) +MINIUBLK_FLAGS := -D_GNU_SOURCE -lpthread -luring all: $(TARGETS)@@ -39,4 +54,7 @@ $(C_TARGETS): %: %.c $(CXX_TARGETS): %: %.cpp $(CXX) $(CPPFLAGS) $(CXXFLAGS) -o $@ $^ +$(C_MINIUBLK): %: ublk/miniublk.c + $(CC) $(CFLAGS) $(MINIUBLK_FLAGS) -o $@ ublk/miniublk.c + .PHONY: all clean installsrc/ublk/miniublk.c new file +0
-0
Do you plan to add more programs in the ublk/ directory? If not, I suggest to place miniublk.c in just under src/.
Also, could you add miniublk to src/.gitignore?
Signature · 1 line
Shin'ichiro Kawasaki
Re: [PATCH blktests v2 1/2] src: add mini ublk source code
Quoted 31 lines · Shinichiro Kawasaki
Hi Ming, thanks for the v2 series. Please find my comments in line.
Quoted 28 lines · Ming Lei
Prepare for adding ublk related test:
1) ublk delete is sync removal, this way is convenient to blkg/queue/disk instance leak issue
2) mini ublk has two builtin
target(null, loop), and loop IO is handled byio_uring, so we can use ublk to cover part ofio_uringworkloads3) not like loop/nbd, ublk won't pre-allocate/add disk, and always add/delete disk dynamically, this way may cover disk plug & unplug tests
4) ublk specific test given people starts to use it, so better to let blktest cover ublk related tests
Add mini ublk source for test purpose only, which is easy to use:
./miniublk add -t {null|loop} [-q
nr_queues] [-d depth] [-ndev_id]default: nr_queues=2(max 4), depth=128(max 128), dev_id=-1(auto allocation) -t loop -f backing_file -t null./miniublk del [-n
dev_id] [--disk/-ddisk_path] -a
-a delete all devices, -d delete device by disk path, -n delete specified device
./miniublk list [-ndev_id] -a
-a list all devices, -n list specified device, default -a
Quoted 5 lines
Quoted 3 lines
ublk depends on liburing 2.2, so allow to ignore ublk build failure in case of missing liburing, and we will check if ublk program exits inside test. Also v6.0 is the 1st linux kernel release with ublk.
This v2 patch prevents the ublk build failure. Could you rewrite this paragraph?
Sure.
Quoted 73 lines
Quoted 15 lines
Signed-off-by Ming Lei <[email protected]>--- Makefile | 2 +- src/Makefile | 18 + src/ublk/miniublk.c | 1376 +++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 1395 insertions(+), 1 deletion(-) create mode 100644 src/ublk/miniublk.cMakefile +0
-0Makefile prefix ?= /usr/local · line 5
Quoted 5 lines
Makefile +1
-1@@ -2,7 +2,7 @@ prefix ?= /usr/local dest = $(DESTDIR)$(prefix)/blktests all: - $(MAKE) -C src all + $(MAKE) -i -C src allAs you pointed out in another e-mail, -i is no longer required.
Quoted 50 lines
Makefile +0
-0clean: $(MAKE) -C src cleansrc/Makefile +15
-0@@ -2,6 +2,10 @@ HAVE_C_HEADER = $(shell if echo "\#include <$(1)>" | \ $(CC) -E - > /dev/null 2>&1; then echo "$(2)"; \ else echo "$(3)"; fi) +HAVE_C_MACRO = $(shell if echo "#include <$(1)>" | \ + $(CC) -E - 2>&1 /dev/null | grep $(2) > /dev/null 2>&1; \ + then echo 1;else echo 0; fi) + C_TARGETS := \ loblksize \ loop_change_fd \@@ -13,16 +17,27 @@ C_TARGETS := \ sg/syzkaller1 \ zbdioctl +C_MINIUBLK := ublk/miniublk + +HAVE_LIBURING := $(call HAVE_C_MACRO,liburing.h,IORING_OP_URING_CMD) +HAVE_UBLK_HEADER := $(call HAVE_C_HEADER,linux/ublk_cmd.h,1) + CXX_TARGETS := \ discontiguous-io +ifeq ($(HAVE_LIBURING)$(HAVE_UBLK_HEADER), 11) +TARGETS := $(C_TARGETS) $(CXX_TARGETS) $(C_MINIUBLK) +else +$(info Skip $(C_MINIUBLK) build due to missing kernel header(v6.0+) or liburing(2.2+)) TARGETS := $(C_TARGETS) $(CXX_TARGETS) +endif CONFIG_DEFS := $(call HAVE_C_HEADER,linux/blkzoned.h,-DHAVE_LINUX_BLKZONED_H) override CFLAGS := -O2 -Wall -Wshadow $(CFLAGS) $(CONFIG_DEFS) override CXXFLAGS := -O2 -std=c++11 -Wall -Wextra -Wshadow -Wno-sign-compare \ -Werror $(CXXFLAGS) $(CONFIG_DEFS) +MINIUBLK_FLAGS := -D_GNU_SOURCE -lpthread -luring all: $(TARGETS)@@ -39,4 +54,7 @@ $(C_TARGETS): %: %.c $(CXX_TARGETS): %: %.cpp $(CXX) $(CPPFLAGS) $(CXXFLAGS) -o $@ $^
Quoted 12 lines
src/ublk/miniublk.c
Quoted 9 lines
src/Makefile +3
-0+$(C_MINIUBLK): %: ublk/miniublk.c + $(CC) $(CFLAGS) $(MINIUBLK_FLAGS) -o $@ ublk/miniublk.c + .PHONY: all clean installsrc/ublk/miniublk.c new file +0
-0Do you plan to add more programs in the ublk/ directory? If not, I suggest to place
miniublk.cin just under src/.
Sounds good.
Quoted 2 lines
Also, could you add miniublk to src/.gitignore?
OK.
Thanks,
Ming
PATCH v2 2/2 block/033: add test to cover gendisk leak
In reply to Ming LeiSo 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.
--- common/ublk | 34 ++++++++++++++++++++++++++++++++++ tests/block/033 | 40 ++++++++++++++++++++++++++++++++++++++++ tests/block/033.out | 2 ++ 3 files changed, 76 insertions(+) create mode 100644 common/ublk create mode 100755 tests/block/033 create mode 100644 tests/block/033.out
common/ublk new file +34 -0
@@ -0,0 +1,34 @@ +#!/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 ublk/miniublk +} + +_remove_ublk_devices() { + src/ublk/miniublk del -a +} + +_init_ublk() { + _remove_ublk_devices + + if ! modprobe -r ublk_drv || ! modprobe ublk_drv; 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 +}
tests/block/033 new file +40 -0
@@ -0,0 +1,40 @@ +#!/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 + + ${ublk_prog} add -t null -n 0 --quiet > /dev/null 2>&1 + if ! ${ublk_prog} list -n 0 > /dev/null 2>&1; then + echo "fail to list dev" + fi + if ! dd if=/dev/ublkb0 iflag=direct of=/dev/null bs=1M count=512 > /dev/null 2>&1; then + echo "fail io" + fi + ${ublk_prog} del -n 0 > /dev/null 2>&1 + + _exit_ublk + + echo "Test complete" +}
tests/block/033.out new file +2 -0
@@ -0,0 +1,2 @@ +Running block/033 +Test complete
Signature · 1 line
2.31.1
Re: [PATCH blktests v2 2/2] block/033: add test to cover gendisk leak
Quoted 31 lines · Ming Lei
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 <[email protected]>--- common/ublk | 34 ++++++++++++++++++++++++++++++++++ tests/block/033 | 40 ++++++++++++++++++++++++++++++++++++++++ tests/block/033.out | 2 ++ 3 files changed, 76 insertions(+) create mode 100644 common/ublk create mode 100755 tests/block/033 create mode 100644 tests/block/033.outcommon/ublk new file +11
-0@@ -0,0 +1,34 @@ +#!/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 ublk/miniublk
common/ublk line 21
Quoted 10 lines
common/ublk new file +10
-0+} + +_remove_ublk_devices() { + src/ublk/miniublk del -a +} + +_init_ublk() { + _remove_ublk_devices + + if ! modprobe -r ublk_drv || ! modprobe ublk_drv; then
When ublk_drv is built as a built-in module, modprobe -r fails and prints out an error. I suggest to modify the line above as follows:
modprobe -rq ublk_drv
if ! modprobe ublk_drv; then
With this, I confirmed that the test case can be run with built-in ublk_drv. I suggest to remove the word "modular" in the message below.
Quoted 40 lines
common/ublk new file +13
-0+ 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 +}tests/block/033 new file +21
-0@@ -0,0 +1,40 @@ +#!/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" +
tests/block/033 line 31
Quoted 10 lines
tests/block/033 new file +10
-0+ echo "Running ${TEST_NAME}" + + if ! _init_ublk; then + return 1 + fi + + ${ublk_prog} add -t null -n 0 --quiet > /dev/null 2>&1 + if ! ${ublk_prog} list -n 0 > /dev/null 2>&1; then + echo "fail to list dev" + fi
When I repeated to run this test case, I often observed failure. The dd below reported an error: "failed to open '/dev/ublkb0': No such file or directory". I added "udevadm settle" here, then the failure disappeared.
tests/block/033 line 35
Quoted 4 lines
tests/block/033 new file +4
-0+ if ! dd if=/dev/ublkb0 iflag=direct of=/dev/null bs=1M count=512 > /dev/null 2>&1; then + echo "fail io" + fi + ${ublk_prog} del -n 0 > /dev/null 2>&1
The outputs of ${ublk_prog} and dd are all redirected to /dev/null, so it was a bit difficult for me to debug the error. I suggest to redirect and append to "$FULL" instead.
Quoted 16 lines
tests/block/033 new file +5
-0+ + _exit_ublk + + echo "Test complete" +}tests/block/033.out new file +2
-0@@ -0,0 +1,2 @@ +Running block/033 +Test completeSignature · 1 line
2.31.1
Signature · 1 line
Shin'ichiro Kawasaki