xref: /linux/Documentation/admin-guide/blockdev/zoned_loop.rst (revision 6f59de9bc0d576eb5a5edfea470527902315e924)
1*9e4f11c1SDamien Le Moal.. SPDX-License-Identifier: GPL-2.0
2*9e4f11c1SDamien Le Moal
3*9e4f11c1SDamien Le Moal=======================
4*9e4f11c1SDamien Le MoalZoned Loop Block Device
5*9e4f11c1SDamien Le Moal=======================
6*9e4f11c1SDamien Le Moal
7*9e4f11c1SDamien Le Moal.. Contents:
8*9e4f11c1SDamien Le Moal
9*9e4f11c1SDamien Le Moal	1) Overview
10*9e4f11c1SDamien Le Moal	2) Creating a Zoned Device
11*9e4f11c1SDamien Le Moal	3) Deleting a Zoned Device
12*9e4f11c1SDamien Le Moal	4) Example
13*9e4f11c1SDamien Le Moal
14*9e4f11c1SDamien Le Moal
15*9e4f11c1SDamien Le Moal1) Overview
16*9e4f11c1SDamien Le Moal-----------
17*9e4f11c1SDamien Le Moal
18*9e4f11c1SDamien Le MoalThe zoned loop block device driver (zloop) allows a user to create a zoned block
19*9e4f11c1SDamien Le Moaldevice using one regular file per zone as backing storage. This driver does not
20*9e4f11c1SDamien Le Moaldirectly control any hardware and uses read, write and truncate operations to
21*9e4f11c1SDamien Le Moalregular files of a file system to emulate a zoned block device.
22*9e4f11c1SDamien Le Moal
23*9e4f11c1SDamien Le MoalUsing zloop, zoned block devices with a configurable capacity, zone size and
24*9e4f11c1SDamien Le Moalnumber of conventional zones can be created. The storage for each zone of the
25*9e4f11c1SDamien Le Moaldevice is implemented using a regular file with a maximum size equal to the zone
26*9e4f11c1SDamien Le Moalsize. The size of a file backing a conventional zone is always equal to the zone
27*9e4f11c1SDamien Le Moalsize. The size of a file backing a sequential zone indicates the amount of data
28*9e4f11c1SDamien Le Moalsequentially written to the file, that is, the size of the file directly
29*9e4f11c1SDamien Le Moalindicates the position of the write pointer of the zone.
30*9e4f11c1SDamien Le Moal
31*9e4f11c1SDamien Le MoalWhen resetting a sequential zone, its backing file size is truncated to zero.
32*9e4f11c1SDamien Le MoalConversely, for a zone finish operation, the backing file is truncated to the
33*9e4f11c1SDamien Le Moalzone size. With this, the maximum capacity of a zloop zoned block device created
34*9e4f11c1SDamien Le Moalcan be larger configured to be larger than the storage space available on the
35*9e4f11c1SDamien Le Moalbacking file system. Of course, for such configuration, writing more data than
36*9e4f11c1SDamien Le Moalthe storage space available on the backing file system will result in write
37*9e4f11c1SDamien Le Moalerrors.
38*9e4f11c1SDamien Le Moal
39*9e4f11c1SDamien Le MoalThe zoned loop block device driver implements a complete zone transition state
40*9e4f11c1SDamien Le Moalmachine. That is, zones can be empty, implicitly opened, explicitly opened,
41*9e4f11c1SDamien Le Moalclosed or full. The current implementation does not support any limits on the
42*9e4f11c1SDamien Le Moalmaximum number of open and active zones.
43*9e4f11c1SDamien Le Moal
44*9e4f11c1SDamien Le MoalNo user tools are necessary to create and delete zloop devices.
45*9e4f11c1SDamien Le Moal
46*9e4f11c1SDamien Le Moal2) Creating a Zoned Device
47*9e4f11c1SDamien Le Moal--------------------------
48*9e4f11c1SDamien Le Moal
49*9e4f11c1SDamien Le MoalOnce the zloop module is loaded (or if zloop is compiled in the kernel), the
50*9e4f11c1SDamien Le Moalcharacter device file /dev/zloop-control can be used to add a zloop device.
51*9e4f11c1SDamien Le MoalThis is done by writing an "add" command directly to the /dev/zloop-control
52*9e4f11c1SDamien Le Moaldevice::
53*9e4f11c1SDamien Le Moal
54*9e4f11c1SDamien Le Moal	$ modprobe zloop
55*9e4f11c1SDamien Le Moal        $ ls -l /dev/zloop*
56*9e4f11c1SDamien Le Moal        crw-------. 1 root root 10, 123 Jan  6 19:18 /dev/zloop-control
57*9e4f11c1SDamien Le Moal
58*9e4f11c1SDamien Le Moal        $ mkdir -p <base directory/<device ID>
59*9e4f11c1SDamien Le Moal        $ echo "add [options]" > /dev/zloop-control
60*9e4f11c1SDamien Le Moal
61*9e4f11c1SDamien Le MoalThe options available for the add command can be listed by reading the
62*9e4f11c1SDamien Le Moal/dev/zloop-control device::
63*9e4f11c1SDamien Le Moal
64*9e4f11c1SDamien Le Moal	$ cat /dev/zloop-control
65*9e4f11c1SDamien Le Moal        add id=%d,capacity_mb=%u,zone_size_mb=%u,zone_capacity_mb=%u,conv_zones=%u,base_dir=%s,nr_queues=%u,queue_depth=%u,buffered_io
66*9e4f11c1SDamien Le Moal        remove id=%d
67*9e4f11c1SDamien Le Moal
68*9e4f11c1SDamien Le MoalIn more details, the options that can be used with the "add" command are as
69*9e4f11c1SDamien Le Moalfollows.
70*9e4f11c1SDamien Le Moal
71*9e4f11c1SDamien Le Moal================   ===========================================================
72*9e4f11c1SDamien Le Moalid                 Device number (the X in /dev/zloopX).
73*9e4f11c1SDamien Le Moal                   Default: automatically assigned.
74*9e4f11c1SDamien Le Moalcapacity_mb        Device total capacity in MiB. This is always rounded up to
75*9e4f11c1SDamien Le Moal                   the nearest higher multiple of the zone size.
76*9e4f11c1SDamien Le Moal                   Default: 16384 MiB (16 GiB).
77*9e4f11c1SDamien Le Moalzone_size_mb       Device zone size in MiB. Default: 256 MiB.
78*9e4f11c1SDamien Le Moalzone_capacity_mb   Device zone capacity (must always be equal to or lower than
79*9e4f11c1SDamien Le Moal                   the zone size. Default: zone size.
80*9e4f11c1SDamien Le Moalconv_zones         Total number of conventioanl zones starting from sector 0.
81*9e4f11c1SDamien Le Moal                   Default: 8.
82*9e4f11c1SDamien Le Moalbase_dir           Path to the base directoy where to create the directory
83*9e4f11c1SDamien Le Moal                   containing the zone files of the device.
84*9e4f11c1SDamien Le Moal                   Default=/var/local/zloop.
85*9e4f11c1SDamien Le Moal                   The device directory containing the zone files is always
86*9e4f11c1SDamien Le Moal                   named with the device ID. E.g. the default zone file
87*9e4f11c1SDamien Le Moal                   directory for /dev/zloop0 is /var/local/zloop/0.
88*9e4f11c1SDamien Le Moalnr_queues          Number of I/O queues of the zoned block device. This value is
89*9e4f11c1SDamien Le Moal                   always capped by the number of online CPUs
90*9e4f11c1SDamien Le Moal                   Default: 1
91*9e4f11c1SDamien Le Moalqueue_depth        Maximum I/O queue depth per I/O queue.
92*9e4f11c1SDamien Le Moal                   Default: 64
93*9e4f11c1SDamien Le Moalbuffered_io        Do buffered IOs instead of direct IOs (default: false)
94*9e4f11c1SDamien Le Moal================   ===========================================================
95*9e4f11c1SDamien Le Moal
96*9e4f11c1SDamien Le Moal3) Deleting a Zoned Device
97*9e4f11c1SDamien Le Moal--------------------------
98*9e4f11c1SDamien Le Moal
99*9e4f11c1SDamien Le MoalDeleting an unused zoned loop block device is done by issuing the "remove"
100*9e4f11c1SDamien Le Moalcommand to /dev/zloop-control, specifying the ID of the device to remove::
101*9e4f11c1SDamien Le Moal
102*9e4f11c1SDamien Le Moal        $ echo "remove id=X" > /dev/zloop-control
103*9e4f11c1SDamien Le Moal
104*9e4f11c1SDamien Le MoalThe remove command does not have any option.
105*9e4f11c1SDamien Le Moal
106*9e4f11c1SDamien Le MoalA zoned device that was removed can be re-added again without any change to the
107*9e4f11c1SDamien Le Moalstate of the device zones: the device zones are restored to their last state
108*9e4f11c1SDamien Le Moalbefore the device was removed. Adding again a zoned device after it was removed
109*9e4f11c1SDamien Le Moalmust always be done using the same configuration as when the device was first
110*9e4f11c1SDamien Le Moaladded. If a zone configuration change is detected, an error will be returned and
111*9e4f11c1SDamien Le Moalthe zoned device will not be created.
112*9e4f11c1SDamien Le Moal
113*9e4f11c1SDamien Le MoalTo fully delete a zoned device, after executing the remove operation, the device
114*9e4f11c1SDamien Le Moalbase directory containing the backing files of the device zones must be deleted.
115*9e4f11c1SDamien Le Moal
116*9e4f11c1SDamien Le Moal4) Example
117*9e4f11c1SDamien Le Moal----------
118*9e4f11c1SDamien Le Moal
119*9e4f11c1SDamien Le MoalThe following sequence of commands creates a 2GB zoned device with zones of 64
120*9e4f11c1SDamien Le MoalMB and a zone capacity of 63 MB::
121*9e4f11c1SDamien Le Moal
122*9e4f11c1SDamien Le Moal        $ modprobe zloop
123*9e4f11c1SDamien Le Moal        $ mkdir -p /var/local/zloop/0
124*9e4f11c1SDamien Le Moal        $ echo "add capacity_mb=2048,zone_size_mb=64,zone_capacity=63MB" > /dev/zloop-control
125*9e4f11c1SDamien Le Moal
126*9e4f11c1SDamien Le MoalFor the device created (/dev/zloop0), the zone backing files are all created
127*9e4f11c1SDamien Le Moalunder the default base directory (/var/local/zloop)::
128*9e4f11c1SDamien Le Moal
129*9e4f11c1SDamien Le Moal        $ ls -l /var/local/zloop/0
130*9e4f11c1SDamien Le Moal        total 0
131*9e4f11c1SDamien Le Moal        -rw-------. 1 root root 67108864 Jan  6 22:23 cnv-000000
132*9e4f11c1SDamien Le Moal        -rw-------. 1 root root 67108864 Jan  6 22:23 cnv-000001
133*9e4f11c1SDamien Le Moal        -rw-------. 1 root root 67108864 Jan  6 22:23 cnv-000002
134*9e4f11c1SDamien Le Moal        -rw-------. 1 root root 67108864 Jan  6 22:23 cnv-000003
135*9e4f11c1SDamien Le Moal        -rw-------. 1 root root 67108864 Jan  6 22:23 cnv-000004
136*9e4f11c1SDamien Le Moal        -rw-------. 1 root root 67108864 Jan  6 22:23 cnv-000005
137*9e4f11c1SDamien Le Moal        -rw-------. 1 root root 67108864 Jan  6 22:23 cnv-000006
138*9e4f11c1SDamien Le Moal        -rw-------. 1 root root 67108864 Jan  6 22:23 cnv-000007
139*9e4f11c1SDamien Le Moal        -rw-------. 1 root root        0 Jan  6 22:23 seq-000008
140*9e4f11c1SDamien Le Moal        -rw-------. 1 root root        0 Jan  6 22:23 seq-000009
141*9e4f11c1SDamien Le Moal        ...
142*9e4f11c1SDamien Le Moal
143*9e4f11c1SDamien Le MoalThe zoned device created (/dev/zloop0) can then be used normally::
144*9e4f11c1SDamien Le Moal
145*9e4f11c1SDamien Le Moal        $ lsblk -z
146*9e4f11c1SDamien Le Moal        NAME   ZONED        ZONE-SZ ZONE-NR ZONE-AMAX ZONE-OMAX ZONE-APP ZONE-WGRAN
147*9e4f11c1SDamien Le Moal        zloop0 host-managed     64M      32         0         0       1M         4K
148*9e4f11c1SDamien Le Moal        $ blkzone report /dev/zloop0
149*9e4f11c1SDamien Le Moal          start: 0x000000000, len 0x020000, cap 0x020000, wptr 0x000000 reset:0 non-seq:0, zcond: 0(nw) [type: 1(CONVENTIONAL)]
150*9e4f11c1SDamien Le Moal          start: 0x000020000, len 0x020000, cap 0x020000, wptr 0x000000 reset:0 non-seq:0, zcond: 0(nw) [type: 1(CONVENTIONAL)]
151*9e4f11c1SDamien Le Moal          start: 0x000040000, len 0x020000, cap 0x020000, wptr 0x000000 reset:0 non-seq:0, zcond: 0(nw) [type: 1(CONVENTIONAL)]
152*9e4f11c1SDamien Le Moal          start: 0x000060000, len 0x020000, cap 0x020000, wptr 0x000000 reset:0 non-seq:0, zcond: 0(nw) [type: 1(CONVENTIONAL)]
153*9e4f11c1SDamien Le Moal          start: 0x000080000, len 0x020000, cap 0x020000, wptr 0x000000 reset:0 non-seq:0, zcond: 0(nw) [type: 1(CONVENTIONAL)]
154*9e4f11c1SDamien Le Moal          start: 0x0000a0000, len 0x020000, cap 0x020000, wptr 0x000000 reset:0 non-seq:0, zcond: 0(nw) [type: 1(CONVENTIONAL)]
155*9e4f11c1SDamien Le Moal          start: 0x0000c0000, len 0x020000, cap 0x020000, wptr 0x000000 reset:0 non-seq:0, zcond: 0(nw) [type: 1(CONVENTIONAL)]
156*9e4f11c1SDamien Le Moal          start: 0x0000e0000, len 0x020000, cap 0x020000, wptr 0x000000 reset:0 non-seq:0, zcond: 0(nw) [type: 1(CONVENTIONAL)]
157*9e4f11c1SDamien Le Moal          start: 0x000100000, len 0x020000, cap 0x01f800, wptr 0x000000 reset:0 non-seq:0, zcond: 1(em) [type: 2(SEQ_WRITE_REQUIRED)]
158*9e4f11c1SDamien Le Moal          start: 0x000120000, len 0x020000, cap 0x01f800, wptr 0x000000 reset:0 non-seq:0, zcond: 1(em) [type: 2(SEQ_WRITE_REQUIRED)]
159*9e4f11c1SDamien Le Moal          ...
160*9e4f11c1SDamien Le Moal
161*9e4f11c1SDamien Le MoalDeleting this device is done using the command::
162*9e4f11c1SDamien Le Moal
163*9e4f11c1SDamien Le Moal        $ echo "remove id=0" > /dev/zloop-control
164*9e4f11c1SDamien Le Moal
165*9e4f11c1SDamien Le MoalThe removed device can be re-added again using the same "add" command as when
166*9e4f11c1SDamien Le Moalthe device was first created. To fully delete a zoned device, its backing files
167*9e4f11c1SDamien Le Moalshould also be deleted after executing the remove command::
168*9e4f11c1SDamien Le Moal
169*9e4f11c1SDamien Le Moal        $ rm -r /var/local/zloop/0
170