Skip to content

Commit 71f28f3

Browse files
Ming Leiaxboe
authored andcommitted
ublk_drv: add io_uring based userspace block driver
This is the driver part of userspace block driver(ublk driver), the other part is userspace daemon part(ublksrv)[1]. The two parts communicate by io_uring's IORING_OP_URING_CMD with one shared cmd buffer for storing io command, and the buffer is read only for ublksrv, each io command is indexed by io request tag directly, and is written by ublk driver. For example, when one READ io request is submitted to ublk block driver, ublk driver stores the io command into cmd buffer first, then completes one IORING_OP_URING_CMD for notifying ublksrv, and the URING_CMD is issued to ublk driver beforehand by ublksrv for getting notification of any new io request, and each URING_CMD is associated with one io request by tag. After ublksrv gets the io command, it translates and handles the ublk io request, such as, for the ublk-loop target, ublksrv translates the request into same request on another file or disk, like the kernel loop block driver. In ublksrv's implementation, the io is still handled by io_uring, and share same ring with IORING_OP_URING_CMD command. When the target io request is done, the same IORING_OP_URING_CMD is issued to ublk driver for both committing io request result and getting future notification of new io request. Another thing done by ublk driver is to copy data between kernel io request and ublksrv's io buffer: 1) before ubsrv handles WRITE request, copy the request's data into ublksrv's userspace io buffer, so that ublksrv can handle the write request 2) after ubsrv handles READ request, copy ublksrv's userspace io buffer into this READ request, then ublk driver can complete the READ request Zero copy may be switched if mm is ready to support it. ublk driver doesn't handle any logic of the specific user space driver, so it is small/simple enough. [1] ublksrv https://github.com/ming1/ubdsrv Signed-off-by: Ming Lei <ming.lei@redhat.com> Link: https://lore.kernel.org/r/20220713140711.97356-2-ming.lei@redhat.com Signed-off-by: Jens Axboe <axboe@kernel.dk>
1 parent 96388f5 commit 71f28f3

File tree

4 files changed

+1697
-0
lines changed

4 files changed

+1697
-0
lines changed

drivers/block/Kconfig

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -408,6 +408,15 @@ config BLK_DEV_RBD
408408

409409
If unsure, say N.
410410

411+
config BLK_DEV_UBLK
412+
tristate "Userspace block driver (Experimental)"
413+
select IO_URING
414+
help
415+
io_uring based userspace block driver. Together with ublk server, ublk
416+
has been working well, but interface with userspace or command data
417+
definition isn't finalized yet, and might change according to future
418+
requirement, so mark is as experimental now.
419+
411420
source "drivers/block/rnbd/Kconfig"
412421

413422
endif # BLK_DEV

drivers/block/Makefile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,4 +39,6 @@ obj-$(CONFIG_BLK_DEV_RNBD) += rnbd/
3939

4040
obj-$(CONFIG_BLK_DEV_NULL_BLK) += null_blk/
4141

42+
obj-$(CONFIG_BLK_DEV_UBLK) += ublk_drv.o
43+
4244
swim_mod-y := swim.o swim_asm.o

0 commit comments

Comments
 (0)