xref: /linux/Documentation/admin-guide/blockdev/zoned_loop.rst (revision 40286d6379aacfcc053253ef78dc78b09addffda)
1.. SPDX-License-Identifier: GPL-2.0
2
3=======================
4Zoned Loop Block Device
5=======================
6
7.. Contents:
8
9	1) Overview
10	2) Creating a Zoned Device
11	3) Deleting a Zoned Device
12	4) Example
13
14
151) Overview
16-----------
17
18The zoned loop block device driver (zloop) allows a user to create a zoned block
19device using one regular file per zone as backing storage. This driver does not
20directly control any hardware and uses read, write and truncate operations to
21regular files of a file system to emulate a zoned block device.
22
23Using zloop, zoned block devices with a configurable capacity, zone size and
24number of conventional zones can be created. The storage for each zone of the
25device is implemented using a regular file with a maximum size equal to the zone
26size. The size of a file backing a conventional zone is always equal to the zone
27size. The size of a file backing a sequential zone indicates the amount of data
28sequentially written to the file, that is, the size of the file directly
29indicates the position of the write pointer of the zone.
30
31When resetting a sequential zone, its backing file size is truncated to zero.
32Conversely, for a zone finish operation, the backing file is truncated to the
33zone size. With this, the maximum capacity of a zloop zoned block device created
34can be larger configured to be larger than the storage space available on the
35backing file system. Of course, for such configuration, writing more data than
36the storage space available on the backing file system will result in write
37errors.
38
39The zoned loop block device driver implements a complete zone transition state
40machine. That is, zones can be empty, implicitly opened, explicitly opened,
41closed or full. The current implementation does not support any limits on the
42maximum number of open and active zones.
43
44No user tools are necessary to create and delete zloop devices.
45
462) Creating a Zoned Device
47--------------------------
48
49Once the zloop module is loaded (or if zloop is compiled in the kernel), the
50character device file /dev/zloop-control can be used to add a zloop device.
51This is done by writing an "add" command directly to the /dev/zloop-control
52device::
53
54	$ modprobe zloop
55        $ ls -l /dev/zloop*
56        crw-------. 1 root root 10, 123 Jan  6 19:18 /dev/zloop-control
57
58        $ mkdir -p <base directory/<device ID>
59        $ echo "add [options]" > /dev/zloop-control
60
61The options available for the add command can be listed by reading the
62/dev/zloop-control device::
63
64	$ cat /dev/zloop-control
65        add id=%d,capacity_mb=%u,zone_size_mb=%u,zone_capacity_mb=%u,conv_zones=%u,max_open_zones=%u,base_dir=%s,nr_queues=%u,queue_depth=%u,buffered_io,zone_append=%u,ordered_zone_append,discard_write_cache
66        remove id=%d
67
68In more details, the options that can be used with the "add" command are as
69follows.
70
71===================   =========================================================
72id                    Device number (the X in /dev/zloopX).
73                      Default: automatically assigned.
74capacity_mb           Device total capacity in MiB. This is always rounded up
75                      to the nearest higher multiple of the zone size.
76                      Default: 16384 MiB (16 GiB).
77zone_size_mb          Device zone size in MiB. Default: 256 MiB.
78zone_capacity_mb      Device zone capacity (must always be equal to or lower
79                      than the zone size. Default: zone size.
80conv_zones            Total number of conventioanl zones starting from
81                      sector 0
82                      Default: 8
83max_open_zones        Maximum number of open sequential write required zones
84                      (0 for no limit).
85                      Default: 0
86base_dir              Path to the base directory where to create the directory
87                      containing the zone files of the device.
88                      Default=/var/local/zloop.
89                      The device directory containing the zone files is always
90                      named with the device ID. E.g. the default zone file
91                      directory for /dev/zloop0 is /var/local/zloop/0.
92nr_queues             Number of I/O queues of the zoned block device. This
93                      value is always capped by the number of online CPUs
94                      Default: 1
95queue_depth           Maximum I/O queue depth per I/O queue.
96                      Default: 64
97buffered_io           Do buffered IOs instead of direct IOs (default: false)
98zone_append           Enable or disable a zloop device native zone append
99                      support.
100                      Default: 1 (enabled).
101                      If native zone append support is disabled, the block layer
102                      will emulate this operation using regular write
103                      operations.
104ordered_zone_append   Enable zloop mitigation of zone append reordering.
105                      Default: disabled.
106                      This is useful for testing file systems file data mapping
107                      (extents), as when enabled, this can significantly reduce
108                      the number of data extents needed to for a file data
109                      mapping.
110discard_write_cache   Discard all data that was not explicitly persisted using a
111                      flush operation when the device is removed by truncating
112                      each zone file to the size recorded during the last flush
113                      operation. This simulates power fail events where
114                      uncommitted data is lost.
115===================   =========================================================
116
1173) Deleting a Zoned Device
118--------------------------
119
120Deleting an unused zoned loop block device is done by issuing the "remove"
121command to /dev/zloop-control, specifying the ID of the device to remove::
122
123        $ echo "remove id=X" > /dev/zloop-control
124
125The remove command does not have any option.
126
127A zoned device that was removed can be re-added again without any change to the
128state of the device zones: the device zones are restored to their last state
129before the device was removed. Adding again a zoned device after it was removed
130must always be done using the same configuration as when the device was first
131added. If a zone configuration change is detected, an error will be returned and
132the zoned device will not be created.
133
134To fully delete a zoned device, after executing the remove operation, the device
135base directory containing the backing files of the device zones must be deleted.
136
1374) Example
138----------
139
140The following sequence of commands creates a 2GB zoned device with zones of 64
141MB and a zone capacity of 63 MB::
142
143        $ modprobe zloop
144        $ mkdir -p /var/local/zloop/0
145        $ echo "add capacity_mb=2048,zone_size_mb=64,zone_capacity_mb=63" > /dev/zloop-control
146
147For the device created (/dev/zloop0), the zone backing files are all created
148under the default base directory (/var/local/zloop)::
149
150        $ ls -l /var/local/zloop/0
151        total 0
152        -rw-------. 1 root root 67108864 Jan  6 22:23 cnv-000000
153        -rw-------. 1 root root 67108864 Jan  6 22:23 cnv-000001
154        -rw-------. 1 root root 67108864 Jan  6 22:23 cnv-000002
155        -rw-------. 1 root root 67108864 Jan  6 22:23 cnv-000003
156        -rw-------. 1 root root 67108864 Jan  6 22:23 cnv-000004
157        -rw-------. 1 root root 67108864 Jan  6 22:23 cnv-000005
158        -rw-------. 1 root root 67108864 Jan  6 22:23 cnv-000006
159        -rw-------. 1 root root 67108864 Jan  6 22:23 cnv-000007
160        -rw-------. 1 root root        0 Jan  6 22:23 seq-000008
161        -rw-------. 1 root root        0 Jan  6 22:23 seq-000009
162        ...
163
164The zoned device created (/dev/zloop0) can then be used normally::
165
166        $ lsblk -z
167        NAME   ZONED        ZONE-SZ ZONE-NR ZONE-AMAX ZONE-OMAX ZONE-APP ZONE-WGRAN
168        zloop0 host-managed     64M      32         0         0       1M         4K
169        $ blkzone report /dev/zloop0
170          start: 0x000000000, len 0x020000, cap 0x020000, wptr 0x000000 reset:0 non-seq:0, zcond: 0(nw) [type: 1(CONVENTIONAL)]
171          start: 0x000020000, len 0x020000, cap 0x020000, wptr 0x000000 reset:0 non-seq:0, zcond: 0(nw) [type: 1(CONVENTIONAL)]
172          start: 0x000040000, len 0x020000, cap 0x020000, wptr 0x000000 reset:0 non-seq:0, zcond: 0(nw) [type: 1(CONVENTIONAL)]
173          start: 0x000060000, len 0x020000, cap 0x020000, wptr 0x000000 reset:0 non-seq:0, zcond: 0(nw) [type: 1(CONVENTIONAL)]
174          start: 0x000080000, len 0x020000, cap 0x020000, wptr 0x000000 reset:0 non-seq:0, zcond: 0(nw) [type: 1(CONVENTIONAL)]
175          start: 0x0000a0000, len 0x020000, cap 0x020000, wptr 0x000000 reset:0 non-seq:0, zcond: 0(nw) [type: 1(CONVENTIONAL)]
176          start: 0x0000c0000, len 0x020000, cap 0x020000, wptr 0x000000 reset:0 non-seq:0, zcond: 0(nw) [type: 1(CONVENTIONAL)]
177          start: 0x0000e0000, len 0x020000, cap 0x020000, wptr 0x000000 reset:0 non-seq:0, zcond: 0(nw) [type: 1(CONVENTIONAL)]
178          start: 0x000100000, len 0x020000, cap 0x01f800, wptr 0x000000 reset:0 non-seq:0, zcond: 1(em) [type: 2(SEQ_WRITE_REQUIRED)]
179          start: 0x000120000, len 0x020000, cap 0x01f800, wptr 0x000000 reset:0 non-seq:0, zcond: 1(em) [type: 2(SEQ_WRITE_REQUIRED)]
180          ...
181
182Deleting this device is done using the command::
183
184        $ echo "remove id=0" > /dev/zloop-control
185
186The removed device can be re-added again using the same "add" command as when
187the device was first created. To fully delete a zoned device, its backing files
188should also be deleted after executing the remove command::
189
190        $ rm -r /var/local/zloop/0
191