forked from ublk-org/ublksrv
-
Notifications
You must be signed in to change notification settings - Fork 0
/
README
112 lines (77 loc) · 3.29 KB
/
README
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
Userspace block driver(ublk)
1 Introduction
This is the userspace daemon part(ublksrv) of the ublk framework, the other
part is ublk blk-mq block driver[1] which supports multiple queue.
The two parts communicate by io_uring's IORING_OP_URING_CMD with one
per-queue shared cmd buffer for storing io command, and the buffer is
read only for ublksrv, each io command can be indexed by io request tag
directly, and the command is written by ublk driver, and read by ublksrv
after getting notification from 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,
so depth for URING_CMD is same with queue depth of ublk block device.
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.
So far, the ublk driver needs to copy io request pages into userspace buffer
(pages) first for write before notifying the request to ublksrv, and copy
userspace buffer(pages) to the io request pages after ublksrv handles
READ. Also looks linux-mm can't support zero copy for this case yet[3].
More ublk targets will be added with this framework in future even though only
ublk-loop and ublk-null are implemented now.
libublksrv is also generated, and it helps to integrate ublk into existed
project. One example of demo_null is provided for how to make a ublk
device over libublksrv.
2 Quick start
2.1 how to build ublksrv:
1) build & install liburing, and make sure IORING_SETUP_SQE128 is supported
2) cd ublksrv && make
2.2 help
- ublk help
2.3 add one ublk-null disk
- ublk add -t null
2.4 add one ublk-loop disk
- ublk add -t loop -f /dev/vdb
or
- ublk add -t loop -f 1.img
2.5 remove one ublk disk
- ublk del -n 0 #remove /dev/ublkb0
- ublk del -a #remove all ublk devices
2.6 list ublk devices
- ublk list
- ublk list -v #with all device info dumped
3 build
3.1 run 'make' directly
3.2 dependency
1) liburing with IORING_SETUP_SQE128 support
2) linux kernel v5.19(IORING_SETUP_SQE128 support)
3) linux kernel v5.20 with ublk kernel driver(drivers/block/ublk_drv.c)
merged
4 test
4.1 run all built tests
make test T=all
4.2 run test group
make test T=null
make test T=loop
make test T=generic
4.3 run single test
make test T=generic/001
make test T=null/001
make test T=loop/001
...
5 License
nlohmann(include/nlohmann/json.hpp) is from [1], which is covered by MIT
license.
The library functions (all code in lib/ directory and include/ublksrv.h)
are covered by dual licensed LGPL and MIT, see COPYING.LGPL and LICENSE.
All other source code are covered by dual licensed GPL and MIT, see
COPYING and LICENSE.
[1] https://github.com/nlohmann/json