~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/Documentation/block/ublk.rst

Version: ~ [ linux-6.12-rc7 ] ~ [ linux-6.11.7 ] ~ [ linux-6.10.14 ] ~ [ linux-6.9.12 ] ~ [ linux-6.8.12 ] ~ [ linux-6.7.12 ] ~ [ linux-6.6.60 ] ~ [ linux-6.5.13 ] ~ [ linux-6.4.16 ] ~ [ linux-6.3.13 ] ~ [ linux-6.2.16 ] ~ [ linux-6.1.116 ] ~ [ linux-6.0.19 ] ~ [ linux-5.19.17 ] ~ [ linux-5.18.19 ] ~ [ linux-5.17.15 ] ~ [ linux-5.16.20 ] ~ [ linux-5.15.171 ] ~ [ linux-5.14.21 ] ~ [ linux-5.13.19 ] ~ [ linux-5.12.19 ] ~ [ linux-5.11.22 ] ~ [ linux-5.10.229 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.285 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.323 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.336 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.337 ] ~ [ linux-4.4.302 ] ~ [ linux-3.10.108 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.12 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

Diff markup

Differences between /Documentation/block/ublk.rst (Architecture m68k) and /Documentation/block/ublk.rst (Architecture mips)


  1 .. SPDX-License-Identifier: GPL-2.0                 1 .. SPDX-License-Identifier: GPL-2.0
  2                                                     2 
  3 ===========================================         3 ===========================================
  4 Userspace block device driver (ublk driver)         4 Userspace block device driver (ublk driver)
  5 ===========================================         5 ===========================================
  6                                                     6 
  7 Overview                                            7 Overview
  8 ========                                            8 ========
  9                                                     9 
 10 ublk is a generic framework for implementing b     10 ublk is a generic framework for implementing block device logic from userspace.
 11 The motivation behind it is that moving virtua     11 The motivation behind it is that moving virtual block drivers into userspace,
 12 such as loop, nbd and similar can be very help     12 such as loop, nbd and similar can be very helpful. It can help to implement
 13 new virtual block device such as ublk-qcow2 (t     13 new virtual block device such as ublk-qcow2 (there are several attempts of
 14 implementing qcow2 driver in kernel).              14 implementing qcow2 driver in kernel).
 15                                                    15 
 16 Userspace block devices are attractive because     16 Userspace block devices are attractive because:
 17                                                    17 
 18 - They can be written many programming languag     18 - They can be written many programming languages.
 19 - They can use libraries that are not availabl     19 - They can use libraries that are not available in the kernel.
 20 - They can be debugged with tools familiar to      20 - They can be debugged with tools familiar to application developers.
 21 - Crashes do not kernel panic the machine.         21 - Crashes do not kernel panic the machine.
 22 - Bugs are likely to have a lower security imp     22 - Bugs are likely to have a lower security impact than bugs in kernel
 23   code.                                            23   code.
 24 - They can be installed and updated independen     24 - They can be installed and updated independently of the kernel.
 25 - They can be used to simulate block device ea     25 - They can be used to simulate block device easily with user specified
 26   parameters/setting for test/debug purpose        26   parameters/setting for test/debug purpose
 27                                                    27 
 28 ublk block device (``/dev/ublkb*``) is added b     28 ublk block device (``/dev/ublkb*``) is added by ublk driver. Any IO request
 29 on the device will be forwarded to ublk usersp     29 on the device will be forwarded to ublk userspace program. For convenience,
 30 in this document, ``ublk server`` refers to ge     30 in this document, ``ublk server`` refers to generic ublk userspace
 31 program. ``ublksrv`` [#userspace]_ is one of s     31 program. ``ublksrv`` [#userspace]_ is one of such implementation. It
 32 provides ``libublksrv`` [#userspace_lib]_ libr     32 provides ``libublksrv`` [#userspace_lib]_ library for developing specific
 33 user block device conveniently, while also gen     33 user block device conveniently, while also generic type block device is
 34 included, such as loop and null. Richard W.M.      34 included, such as loop and null. Richard W.M. Jones wrote userspace nbd device
 35 ``nbdublk`` [#userspace_nbdublk]_  based on ``     35 ``nbdublk`` [#userspace_nbdublk]_  based on ``libublksrv`` [#userspace_lib]_.
 36                                                    36 
 37 After the IO is handled by userspace, the resu     37 After the IO is handled by userspace, the result is committed back to the
 38 driver, thus completing the request cycle. Thi     38 driver, thus completing the request cycle. This way, any specific IO handling
 39 logic is totally done by userspace, such as lo     39 logic is totally done by userspace, such as loop's IO handling, NBD's IO
 40 communication, or qcow2's IO mapping.              40 communication, or qcow2's IO mapping.
 41                                                    41 
 42 ``/dev/ublkb*`` is driven by blk-mq request-ba     42 ``/dev/ublkb*`` is driven by blk-mq request-based driver. Each request is
 43 assigned by one queue wide unique tag. ublk se     43 assigned by one queue wide unique tag. ublk server assigns unique tag to each
 44 IO too, which is 1:1 mapped with IO of ``/dev/     44 IO too, which is 1:1 mapped with IO of ``/dev/ublkb*``.
 45                                                    45 
 46 Both the IO request forward and IO handling re     46 Both the IO request forward and IO handling result committing are done via
 47 ``io_uring`` passthrough command; that is why      47 ``io_uring`` passthrough command; that is why ublk is also one io_uring based
 48 block driver. It has been observed that using      48 block driver. It has been observed that using io_uring passthrough command can
 49 give better IOPS than block IO; which is why u     49 give better IOPS than block IO; which is why ublk is one of high performance
 50 implementation of userspace block device: not      50 implementation of userspace block device: not only IO request communication is
 51 done by io_uring, but also the preferred IO ha     51 done by io_uring, but also the preferred IO handling in ublk server is io_uring
 52 based approach too.                                52 based approach too.
 53                                                    53 
 54 ublk provides control interface to set/get ubl     54 ublk provides control interface to set/get ublk block device parameters.
 55 The interface is extendable and kabi compatibl     55 The interface is extendable and kabi compatible: basically any ublk request
 56 queue's parameter or ublk generic feature para     56 queue's parameter or ublk generic feature parameters can be set/get via the
 57 interface. Thus, ublk is generic userspace blo     57 interface. Thus, ublk is generic userspace block device framework.
 58 For example, it is easy to setup a ublk device     58 For example, it is easy to setup a ublk device with specified block
 59 parameters from userspace.                         59 parameters from userspace.
 60                                                    60 
 61 Using ublk                                         61 Using ublk
 62 ==========                                         62 ==========
 63                                                    63 
 64 ublk requires userspace ublk server to handle      64 ublk requires userspace ublk server to handle real block device logic.
 65                                                    65 
 66 Below is example of using ``ublksrv`` to provi     66 Below is example of using ``ublksrv`` to provide ublk-based loop device.
 67                                                    67 
 68 - add a device::                                   68 - add a device::
 69                                                    69 
 70      ublk add -t loop -f ublk-loop.img             70      ublk add -t loop -f ublk-loop.img
 71                                                    71 
 72 - format with xfs, then use it::                   72 - format with xfs, then use it::
 73                                                    73 
 74      mkfs.xfs /dev/ublkb0                          74      mkfs.xfs /dev/ublkb0
 75      mount /dev/ublkb0 /mnt                        75      mount /dev/ublkb0 /mnt
 76      # do anything. all IOs are handled by io_     76      # do anything. all IOs are handled by io_uring
 77      ...                                           77      ...
 78      umount /mnt                                   78      umount /mnt
 79                                                    79 
 80 - list the devices with their info::               80 - list the devices with their info::
 81                                                    81 
 82      ublk list                                     82      ublk list
 83                                                    83 
 84 - delete the device::                              84 - delete the device::
 85                                                    85 
 86      ublk del -a                                   86      ublk del -a
 87      ublk del -n $ublk_dev_id                      87      ublk del -n $ublk_dev_id
 88                                                    88 
 89 See usage details in README of ``ublksrv`` [#u     89 See usage details in README of ``ublksrv`` [#userspace_readme]_.
 90                                                    90 
 91 Design                                             91 Design
 92 ======                                             92 ======
 93                                                    93 
 94 Control plane                                      94 Control plane
 95 -------------                                      95 -------------
 96                                                    96 
 97 ublk driver provides global misc device node (     97 ublk driver provides global misc device node (``/dev/ublk-control``) for
 98 managing and controlling ublk devices with hel     98 managing and controlling ublk devices with help of several control commands:
 99                                                    99 
100 - ``UBLK_CMD_ADD_DEV``                            100 - ``UBLK_CMD_ADD_DEV``
101                                                   101 
102   Add a ublk char device (``/dev/ublkc*``) whi    102   Add a ublk char device (``/dev/ublkc*``) which is talked with ublk server
103   WRT IO command communication. Basic device i    103   WRT IO command communication. Basic device info is sent together with this
104   command. It sets UAPI structure of ``ublksrv    104   command. It sets UAPI structure of ``ublksrv_ctrl_dev_info``,
105   such as ``nr_hw_queues``, ``queue_depth``, a    105   such as ``nr_hw_queues``, ``queue_depth``, and max IO request buffer size,
106   for which the info is negotiated with the dr    106   for which the info is negotiated with the driver and sent back to the server.
107   When this command is completed, the basic de    107   When this command is completed, the basic device info is immutable.
108                                                   108 
109 - ``UBLK_CMD_SET_PARAMS`` / ``UBLK_CMD_GET_PAR    109 - ``UBLK_CMD_SET_PARAMS`` / ``UBLK_CMD_GET_PARAMS``
110                                                   110 
111   Set or get parameters of the device, which c    111   Set or get parameters of the device, which can be either generic feature
112   related, or request queue limit related, but    112   related, or request queue limit related, but can't be IO logic specific,
113   because the driver does not handle any IO lo    113   because the driver does not handle any IO logic. This command has to be
114   sent before sending ``UBLK_CMD_START_DEV``.     114   sent before sending ``UBLK_CMD_START_DEV``.
115                                                   115 
116 - ``UBLK_CMD_START_DEV``                          116 - ``UBLK_CMD_START_DEV``
117                                                   117 
118   After the server prepares userspace resource    118   After the server prepares userspace resources (such as creating per-queue
119   pthread & io_uring for handling ublk IO), th    119   pthread & io_uring for handling ublk IO), this command is sent to the
120   driver for allocating & exposing ``/dev/ublk    120   driver for allocating & exposing ``/dev/ublkb*``. Parameters set via
121   ``UBLK_CMD_SET_PARAMS`` are applied for crea    121   ``UBLK_CMD_SET_PARAMS`` are applied for creating the device.
122                                                   122 
123 - ``UBLK_CMD_STOP_DEV``                           123 - ``UBLK_CMD_STOP_DEV``
124                                                   124 
125   Halt IO on ``/dev/ublkb*`` and remove the de    125   Halt IO on ``/dev/ublkb*`` and remove the device. When this command returns,
126   ublk server will release resources (such as     126   ublk server will release resources (such as destroying per-queue pthread &
127   io_uring).                                      127   io_uring).
128                                                   128 
129 - ``UBLK_CMD_DEL_DEV``                            129 - ``UBLK_CMD_DEL_DEV``
130                                                   130 
131   Remove ``/dev/ublkc*``. When this command re    131   Remove ``/dev/ublkc*``. When this command returns, the allocated ublk device
132   number can be reused.                           132   number can be reused.
133                                                   133 
134 - ``UBLK_CMD_GET_QUEUE_AFFINITY``                 134 - ``UBLK_CMD_GET_QUEUE_AFFINITY``
135                                                   135 
136   When ``/dev/ublkc`` is added, the driver cre    136   When ``/dev/ublkc`` is added, the driver creates block layer tagset, so
137   that each queue's affinity info is available    137   that each queue's affinity info is available. The server sends
138   ``UBLK_CMD_GET_QUEUE_AFFINITY`` to retrieve     138   ``UBLK_CMD_GET_QUEUE_AFFINITY`` to retrieve queue affinity info. It can
139   set up the per-queue context efficiently, su    139   set up the per-queue context efficiently, such as bind affine CPUs with IO
140   pthread and try to allocate buffers in IO th    140   pthread and try to allocate buffers in IO thread context.
141                                                   141 
142 - ``UBLK_CMD_GET_DEV_INFO``                       142 - ``UBLK_CMD_GET_DEV_INFO``
143                                                   143 
144   For retrieving device info via ``ublksrv_ctr    144   For retrieving device info via ``ublksrv_ctrl_dev_info``. It is the server's
145   responsibility to save IO target specific in    145   responsibility to save IO target specific info in userspace.
146                                                   146 
147 - ``UBLK_CMD_GET_DEV_INFO2``                      147 - ``UBLK_CMD_GET_DEV_INFO2``
148   Same purpose with ``UBLK_CMD_GET_DEV_INFO``,    148   Same purpose with ``UBLK_CMD_GET_DEV_INFO``, but ublk server has to
149   provide path of the char device of ``/dev/ub    149   provide path of the char device of ``/dev/ublkc*`` for kernel to run
150   permission check, and this command is added     150   permission check, and this command is added for supporting unprivileged
151   ublk device, and introduced with ``UBLK_F_UN    151   ublk device, and introduced with ``UBLK_F_UNPRIVILEGED_DEV`` together.
152   Only the user owning the requested device ca    152   Only the user owning the requested device can retrieve the device info.
153                                                   153 
154   How to deal with userspace/kernel compatibil    154   How to deal with userspace/kernel compatibility:
155                                                   155 
156   1) if kernel is capable of handling ``UBLK_F    156   1) if kernel is capable of handling ``UBLK_F_UNPRIVILEGED_DEV``
157                                                   157 
158     If ublk server supports ``UBLK_F_UNPRIVILE    158     If ublk server supports ``UBLK_F_UNPRIVILEGED_DEV``:
159                                                   159 
160     ublk server should send ``UBLK_CMD_GET_DEV    160     ublk server should send ``UBLK_CMD_GET_DEV_INFO2``, given anytime
161     unprivileged application needs to query de    161     unprivileged application needs to query devices the current user owns,
162     when the application has no idea if ``UBLK    162     when the application has no idea if ``UBLK_F_UNPRIVILEGED_DEV`` is set
163     given the capability info is stateless, an    163     given the capability info is stateless, and application should always
164     retrieve it via ``UBLK_CMD_GET_DEV_INFO2``    164     retrieve it via ``UBLK_CMD_GET_DEV_INFO2``
165                                                   165 
166     If ublk server doesn't support ``UBLK_F_UN    166     If ublk server doesn't support ``UBLK_F_UNPRIVILEGED_DEV``:
167                                                   167 
168     ``UBLK_CMD_GET_DEV_INFO`` is always sent t    168     ``UBLK_CMD_GET_DEV_INFO`` is always sent to kernel, and the feature of
169     UBLK_F_UNPRIVILEGED_DEV isn't available fo    169     UBLK_F_UNPRIVILEGED_DEV isn't available for user
170                                                   170 
171   2) if kernel isn't capable of handling ``UBL    171   2) if kernel isn't capable of handling ``UBLK_F_UNPRIVILEGED_DEV``
172                                                   172 
173     If ublk server supports ``UBLK_F_UNPRIVILE    173     If ublk server supports ``UBLK_F_UNPRIVILEGED_DEV``:
174                                                   174 
175     ``UBLK_CMD_GET_DEV_INFO2`` is tried first,    175     ``UBLK_CMD_GET_DEV_INFO2`` is tried first, and will be failed, then
176     ``UBLK_CMD_GET_DEV_INFO`` needs to be retr    176     ``UBLK_CMD_GET_DEV_INFO`` needs to be retried given
177     ``UBLK_F_UNPRIVILEGED_DEV`` can't be set      177     ``UBLK_F_UNPRIVILEGED_DEV`` can't be set
178                                                   178 
179     If ublk server doesn't support ``UBLK_F_UN    179     If ublk server doesn't support ``UBLK_F_UNPRIVILEGED_DEV``:
180                                                   180 
181     ``UBLK_CMD_GET_DEV_INFO`` is always sent t    181     ``UBLK_CMD_GET_DEV_INFO`` is always sent to kernel, and the feature of
182     ``UBLK_F_UNPRIVILEGED_DEV`` isn't availabl    182     ``UBLK_F_UNPRIVILEGED_DEV`` isn't available for user
183                                                   183 
184 - ``UBLK_CMD_START_USER_RECOVERY``                184 - ``UBLK_CMD_START_USER_RECOVERY``
185                                                   185 
186   This command is valid if ``UBLK_F_USER_RECOV    186   This command is valid if ``UBLK_F_USER_RECOVERY`` feature is enabled. This
187   command is accepted after the old process ha    187   command is accepted after the old process has exited, ublk device is quiesced
188   and ``/dev/ublkc*`` is released. User should    188   and ``/dev/ublkc*`` is released. User should send this command before he starts
189   a new process which re-opens ``/dev/ublkc*``    189   a new process which re-opens ``/dev/ublkc*``. When this command returns, the
190   ublk device is ready for the new process.       190   ublk device is ready for the new process.
191                                                   191 
192 - ``UBLK_CMD_END_USER_RECOVERY``                  192 - ``UBLK_CMD_END_USER_RECOVERY``
193                                                   193 
194   This command is valid if ``UBLK_F_USER_RECOV    194   This command is valid if ``UBLK_F_USER_RECOVERY`` feature is enabled. This
195   command is accepted after ublk device is qui    195   command is accepted after ublk device is quiesced and a new process has
196   opened ``/dev/ublkc*`` and get all ublk queu    196   opened ``/dev/ublkc*`` and get all ublk queues be ready. When this command
197   returns, ublk device is unquiesced and new I    197   returns, ublk device is unquiesced and new I/O requests are passed to the
198   new process.                                    198   new process.
199                                                   199 
200 - user recovery feature description               200 - user recovery feature description
201                                                   201 
202   Two new features are added for user recovery    202   Two new features are added for user recovery: ``UBLK_F_USER_RECOVERY`` and
203   ``UBLK_F_USER_RECOVERY_REISSUE``.               203   ``UBLK_F_USER_RECOVERY_REISSUE``.
204                                                   204 
205   With ``UBLK_F_USER_RECOVERY`` set, after one    205   With ``UBLK_F_USER_RECOVERY`` set, after one ubq_daemon(ublk server's io
206   handler) is dying, ublk does not delete ``/d    206   handler) is dying, ublk does not delete ``/dev/ublkb*`` during the whole
207   recovery stage and ublk device ID is kept. I    207   recovery stage and ublk device ID is kept. It is ublk server's
208   responsibility to recover the device context    208   responsibility to recover the device context by its own knowledge.
209   Requests which have not been issued to users    209   Requests which have not been issued to userspace are requeued. Requests
210   which have been issued to userspace are abor    210   which have been issued to userspace are aborted.
211                                                   211 
212   With ``UBLK_F_USER_RECOVERY_REISSUE`` set, a    212   With ``UBLK_F_USER_RECOVERY_REISSUE`` set, after one ubq_daemon(ublk
213   server's io handler) is dying, contrary to `    213   server's io handler) is dying, contrary to ``UBLK_F_USER_RECOVERY``,
214   requests which have been issued to userspace    214   requests which have been issued to userspace are requeued and will be
215   re-issued to the new process after handling     215   re-issued to the new process after handling ``UBLK_CMD_END_USER_RECOVERY``.
216   ``UBLK_F_USER_RECOVERY_REISSUE`` is designed    216   ``UBLK_F_USER_RECOVERY_REISSUE`` is designed for backends who tolerate
217   double-write since the driver may issue the     217   double-write since the driver may issue the same I/O request twice. It
218   might be useful to a read-only FS or a VM ba    218   might be useful to a read-only FS or a VM backend.
219                                                   219 
220 Unprivileged ublk device is supported by passi    220 Unprivileged ublk device is supported by passing ``UBLK_F_UNPRIVILEGED_DEV``.
221 Once the flag is set, all control commands can    221 Once the flag is set, all control commands can be sent by unprivileged
222 user. Except for command of ``UBLK_CMD_ADD_DEV    222 user. Except for command of ``UBLK_CMD_ADD_DEV``, permission check on
223 the specified char device(``/dev/ublkc*``) is     223 the specified char device(``/dev/ublkc*``) is done for all other control
224 commands by ublk driver, for doing that, path     224 commands by ublk driver, for doing that, path of the char device has to
225 be provided in these commands' payload from ub    225 be provided in these commands' payload from ublk server. With this way,
226 ublk device becomes container-ware, and device    226 ublk device becomes container-ware, and device created in one container
227 can be controlled/accessed just inside this co    227 can be controlled/accessed just inside this container.
228                                                   228 
229 Data plane                                        229 Data plane
230 ----------                                        230 ----------
231                                                   231 
232 ublk server needs to create per-queue IO pthre    232 ublk server needs to create per-queue IO pthread & io_uring for handling IO
233 commands via io_uring passthrough. The per-que    233 commands via io_uring passthrough. The per-queue IO pthread
234 focuses on IO handling and shouldn't handle an    234 focuses on IO handling and shouldn't handle any control & management
235 tasks.                                            235 tasks.
236                                                   236 
237 The's IO is assigned by a unique tag, which is    237 The's IO is assigned by a unique tag, which is 1:1 mapping with IO
238 request of ``/dev/ublkb*``.                       238 request of ``/dev/ublkb*``.
239                                                   239 
240 UAPI structure of ``ublksrv_io_desc`` is defin    240 UAPI structure of ``ublksrv_io_desc`` is defined for describing each IO from
241 the driver. A fixed mmapped area (array) on ``    241 the driver. A fixed mmapped area (array) on ``/dev/ublkc*`` is provided for
242 exporting IO info to the server; such as IO of    242 exporting IO info to the server; such as IO offset, length, OP/flags and
243 buffer address. Each ``ublksrv_io_desc`` insta    243 buffer address. Each ``ublksrv_io_desc`` instance can be indexed via queue id
244 and IO tag directly.                              244 and IO tag directly.
245                                                   245 
246 The following IO commands are communicated via    246 The following IO commands are communicated via io_uring passthrough command,
247 and each command is only for forwarding the IO    247 and each command is only for forwarding the IO and committing the result
248 with specified IO tag in the command data:        248 with specified IO tag in the command data:
249                                                   249 
250 - ``UBLK_IO_FETCH_REQ``                           250 - ``UBLK_IO_FETCH_REQ``
251                                                   251 
252   Sent from the server IO pthread for fetching    252   Sent from the server IO pthread for fetching future incoming IO requests
253   destined to ``/dev/ublkb*``. This command is    253   destined to ``/dev/ublkb*``. This command is sent only once from the server
254   IO pthread for ublk driver to setup IO forwa    254   IO pthread for ublk driver to setup IO forward environment.
255                                                   255 
256 - ``UBLK_IO_COMMIT_AND_FETCH_REQ``                256 - ``UBLK_IO_COMMIT_AND_FETCH_REQ``
257                                                   257 
258   When an IO request is destined to ``/dev/ubl    258   When an IO request is destined to ``/dev/ublkb*``, the driver stores
259   the IO's ``ublksrv_io_desc`` to the specifie    259   the IO's ``ublksrv_io_desc`` to the specified mapped area; then the
260   previous received IO command of this IO tag     260   previous received IO command of this IO tag (either ``UBLK_IO_FETCH_REQ``
261   or ``UBLK_IO_COMMIT_AND_FETCH_REQ)`` is comp    261   or ``UBLK_IO_COMMIT_AND_FETCH_REQ)`` is completed, so the server gets
262   the IO notification via io_uring.               262   the IO notification via io_uring.
263                                                   263 
264   After the server handles the IO, its result     264   After the server handles the IO, its result is committed back to the
265   driver by sending ``UBLK_IO_COMMIT_AND_FETCH    265   driver by sending ``UBLK_IO_COMMIT_AND_FETCH_REQ`` back. Once ublkdrv
266   received this command, it parses the result     266   received this command, it parses the result and complete the request to
267   ``/dev/ublkb*``. In the meantime setup envir    267   ``/dev/ublkb*``. In the meantime setup environment for fetching future
268   requests with the same IO tag. That is, ``UB    268   requests with the same IO tag. That is, ``UBLK_IO_COMMIT_AND_FETCH_REQ``
269   is reused for both fetching request and comm    269   is reused for both fetching request and committing back IO result.
270                                                   270 
271 - ``UBLK_IO_NEED_GET_DATA``                       271 - ``UBLK_IO_NEED_GET_DATA``
272                                                   272 
273   With ``UBLK_F_NEED_GET_DATA`` enabled, the W    273   With ``UBLK_F_NEED_GET_DATA`` enabled, the WRITE request will be firstly
274   issued to ublk server without data copy. The    274   issued to ublk server without data copy. Then, IO backend of ublk server
275   receives the request and it can allocate dat    275   receives the request and it can allocate data buffer and embed its addr
276   inside this new io command. After the kernel    276   inside this new io command. After the kernel driver gets the command,
277   data copy is done from request pages to this    277   data copy is done from request pages to this backend's buffer. Finally,
278   backend receives the request again with data    278   backend receives the request again with data to be written and it can
279   truly handle the request.                       279   truly handle the request.
280                                                   280 
281   ``UBLK_IO_NEED_GET_DATA`` adds one additiona    281   ``UBLK_IO_NEED_GET_DATA`` adds one additional round-trip and one
282   io_uring_enter() syscall. Any user thinks th    282   io_uring_enter() syscall. Any user thinks that it may lower performance
283   should not enable UBLK_F_NEED_GET_DATA. ublk    283   should not enable UBLK_F_NEED_GET_DATA. ublk server pre-allocates IO
284   buffer for each IO by default. Any new proje    284   buffer for each IO by default. Any new project should try to use this
285   buffer to communicate with ublk driver. Howe    285   buffer to communicate with ublk driver. However, existing project may
286   break or not able to consume the new buffer     286   break or not able to consume the new buffer interface; that's why this
287   command is added for backwards compatibility    287   command is added for backwards compatibility so that existing projects
288   can still consume existing buffers.             288   can still consume existing buffers.
289                                                   289 
290 - data copy between ublk server IO buffer and     290 - data copy between ublk server IO buffer and ublk block IO request
291                                                   291 
292   The driver needs to copy the block IO reques    292   The driver needs to copy the block IO request pages into the server buffer
293   (pages) first for WRITE before notifying the    293   (pages) first for WRITE before notifying the server of the coming IO, so
294   that the server can handle WRITE request.       294   that the server can handle WRITE request.
295                                                   295 
296   When the server handles READ request and sen    296   When the server handles READ request and sends
297   ``UBLK_IO_COMMIT_AND_FETCH_REQ`` to the serv    297   ``UBLK_IO_COMMIT_AND_FETCH_REQ`` to the server, ublkdrv needs to copy
298   the server buffer (pages) read to the IO req    298   the server buffer (pages) read to the IO request pages.
299                                                   299 
300 Future development                                300 Future development
301 ==================                                301 ==================
302                                                   302 
303 Zero copy                                         303 Zero copy
304 ---------                                         304 ---------
305                                                   305 
306 Zero copy is a generic requirement for nbd, fu    306 Zero copy is a generic requirement for nbd, fuse or similar drivers. A
307 problem [#xiaoguang]_ Xiaoguang mentioned is t    307 problem [#xiaoguang]_ Xiaoguang mentioned is that pages mapped to userspace
308 can't be remapped any more in kernel with exis    308 can't be remapped any more in kernel with existing mm interfaces. This can
309 occurs when destining direct IO to ``/dev/ublk    309 occurs when destining direct IO to ``/dev/ublkb*``. Also, he reported that
310 big requests (IO size >= 256 KB) may benefit a    310 big requests (IO size >= 256 KB) may benefit a lot from zero copy.
311                                                   311 
312                                                   312 
313 References                                        313 References
314 ==========                                        314 ==========
315                                                   315 
316 .. [#userspace] https://github.com/ming1/ubdsr    316 .. [#userspace] https://github.com/ming1/ubdsrv
317                                                   317 
318 .. [#userspace_lib] https://github.com/ming1/u    318 .. [#userspace_lib] https://github.com/ming1/ubdsrv/tree/master/lib
319                                                   319 
320 .. [#userspace_nbdublk] https://gitlab.com/rwm    320 .. [#userspace_nbdublk] https://gitlab.com/rwmjones/libnbd/-/tree/nbdublk
321                                                   321 
322 .. [#userspace_readme] https://github.com/ming    322 .. [#userspace_readme] https://github.com/ming1/ubdsrv/blob/master/README
323                                                   323 
324 .. [#stefan] https://lore.kernel.org/linux-blo    324 .. [#stefan] https://lore.kernel.org/linux-block/YoOr6jBfgVm8GvWg@stefanha-x1.localdomain/
325                                                   325 
326 .. [#xiaoguang] https://lore.kernel.org/linux-    326 .. [#xiaoguang] https://lore.kernel.org/linux-block/YoOr6jBfgVm8GvWg@stefanha-x1.localdomain/
                                                      

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

sflogo.php