요약·해설과 원문, 전문 번역을 서로 분리했습니다. API 이름, symbol, source path는 원문 표기를 사용합니다.
1. 요약·해설
원문의 핵심 논리와 kernel programming 관점의 보충 설명입니다. 아래의 전문 번역과는 별도로 작성했습니다.
Create a device
zoned_loop.rst:46-95/dev/zloop-control의 add command와 capacity·zone·queue option을 정리합니다.
Remove and restore
zoned_loop.rst:96-115동일 설정 재추가는 zone state를 복원하고 backing directory 삭제는 device를 완전히 지웁니다.
2-GiB example
zoned_loop.rst:116-16932개 zone의 file layout과 lsblk·blkzone 출력, 제거 절차를 보여 줍니다.
2. 영어 원문 전체
번역 기준이 된 Linux v6.18.37 원문입니다. 줄 번호는 이 버전의 파일 좌표입니다.
원문 전체 펼치기
.. SPDX-License-Identifier: GPL-2.0
=======================
Zoned Loop Block Device
=======================
.. Contents:
1) Overview
2) Creating a Zoned Device
3) Deleting a Zoned Device
4) Example
1) Overview
-----------
The zoned loop block device driver (zloop) allows a user to create a zoned block
device using one regular file per zone as backing storage. This driver does not
directly control any hardware and uses read, write and truncate operations to
regular files of a file system to emulate a zoned block device.
Using zloop, zoned block devices with a configurable capacity, zone size and
number of conventional zones can be created. The storage for each zone of the
device is implemented using a regular file with a maximum size equal to the zone
size. The size of a file backing a conventional zone is always equal to the zone
size. The size of a file backing a sequential zone indicates the amount of data
sequentially written to the file, that is, the size of the file directly
indicates the position of the write pointer of the zone.
When resetting a sequential zone, its backing file size is truncated to zero.
Conversely, for a zone finish operation, the backing file is truncated to the
zone size. With this, the maximum capacity of a zloop zoned block device created
can be larger configured to be larger than the storage space available on the
backing file system. Of course, for such configuration, writing more data than
the storage space available on the backing file system will result in write
errors.
The zoned loop block device driver implements a complete zone transition state
machine. That is, zones can be empty, implicitly opened, explicitly opened,
closed or full. The current implementation does not support any limits on the
maximum number of open and active zones.
No user tools are necessary to create and delete zloop devices.
2) Creating a Zoned Device
--------------------------
Once the zloop module is loaded (or if zloop is compiled in the kernel), the
character device file /dev/zloop-control can be used to add a zloop device.
This is done by writing an "add" command directly to the /dev/zloop-control
device::
$ modprobe zloop
$ ls -l /dev/zloop*
crw-------. 1 root root 10, 123 Jan 6 19:18 /dev/zloop-control
$ mkdir -p <base directory/<device ID>
$ echo "add [options]" > /dev/zloop-control
The options available for the add command can be listed by reading the
/dev/zloop-control device::
$ cat /dev/zloop-control
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
remove id=%d
In more details, the options that can be used with the "add" command are as
follows.
================ ===========================================================
id Device number (the X in /dev/zloopX).
Default: automatically assigned.
capacity_mb Device total capacity in MiB. This is always rounded up to
the nearest higher multiple of the zone size.
Default: 16384 MiB (16 GiB).
zone_size_mb Device zone size in MiB. Default: 256 MiB.
zone_capacity_mb Device zone capacity (must always be equal to or lower than
the zone size. Default: zone size.
conv_zones Total number of conventioanl zones starting from sector 0.
Default: 8.
base_dir Path to the base directory where to create the directory
containing the zone files of the device.
Default=/var/local/zloop.
The device directory containing the zone files is always
named with the device ID. E.g. the default zone file
directory for /dev/zloop0 is /var/local/zloop/0.
nr_queues Number of I/O queues of the zoned block device. This value is
always capped by the number of online CPUs
Default: 1
queue_depth Maximum I/O queue depth per I/O queue.
Default: 64
buffered_io Do buffered IOs instead of direct IOs (default: false)
================ ===========================================================
3) Deleting a Zoned Device
--------------------------
Deleting an unused zoned loop block device is done by issuing the "remove"
command to /dev/zloop-control, specifying the ID of the device to remove::
$ echo "remove id=X" > /dev/zloop-control
The remove command does not have any option.
A zoned device that was removed can be re-added again without any change to the
state of the device zones: the device zones are restored to their last state
before the device was removed. Adding again a zoned device after it was removed
must always be done using the same configuration as when the device was first
added. If a zone configuration change is detected, an error will be returned and
the zoned device will not be created.
To fully delete a zoned device, after executing the remove operation, the device
base directory containing the backing files of the device zones must be deleted.
4) Example
----------
The following sequence of commands creates a 2GB zoned device with zones of 64
MB and a zone capacity of 63 MB::
$ modprobe zloop
$ mkdir -p /var/local/zloop/0
$ echo "add capacity_mb=2048,zone_size_mb=64,zone_capacity=63MB" > /dev/zloop-control
For the device created (/dev/zloop0), the zone backing files are all created
under the default base directory (/var/local/zloop)::
$ ls -l /var/local/zloop/0
total 0
-rw-------. 1 root root 67108864 Jan 6 22:23 cnv-000000
-rw-------. 1 root root 67108864 Jan 6 22:23 cnv-000001
-rw-------. 1 root root 67108864 Jan 6 22:23 cnv-000002
-rw-------. 1 root root 67108864 Jan 6 22:23 cnv-000003
-rw-------. 1 root root 67108864 Jan 6 22:23 cnv-000004
-rw-------. 1 root root 67108864 Jan 6 22:23 cnv-000005
-rw-------. 1 root root 67108864 Jan 6 22:23 cnv-000006
-rw-------. 1 root root 67108864 Jan 6 22:23 cnv-000007
-rw-------. 1 root root 0 Jan 6 22:23 seq-000008
-rw-------. 1 root root 0 Jan 6 22:23 seq-000009
...
The zoned device created (/dev/zloop0) can then be used normally::
$ lsblk -z
NAME ZONED ZONE-SZ ZONE-NR ZONE-AMAX ZONE-OMAX ZONE-APP ZONE-WGRAN
zloop0 host-managed 64M 32 0 0 1M 4K
$ blkzone report /dev/zloop0
start: 0x000000000, len 0x020000, cap 0x020000, wptr 0x000000 reset:0 non-seq:0, zcond: 0(nw) [type: 1(CONVENTIONAL)]
start: 0x000020000, len 0x020000, cap 0x020000, wptr 0x000000 reset:0 non-seq:0, zcond: 0(nw) [type: 1(CONVENTIONAL)]
start: 0x000040000, len 0x020000, cap 0x020000, wptr 0x000000 reset:0 non-seq:0, zcond: 0(nw) [type: 1(CONVENTIONAL)]
start: 0x000060000, len 0x020000, cap 0x020000, wptr 0x000000 reset:0 non-seq:0, zcond: 0(nw) [type: 1(CONVENTIONAL)]
start: 0x000080000, len 0x020000, cap 0x020000, wptr 0x000000 reset:0 non-seq:0, zcond: 0(nw) [type: 1(CONVENTIONAL)]
start: 0x0000a0000, len 0x020000, cap 0x020000, wptr 0x000000 reset:0 non-seq:0, zcond: 0(nw) [type: 1(CONVENTIONAL)]
start: 0x0000c0000, len 0x020000, cap 0x020000, wptr 0x000000 reset:0 non-seq:0, zcond: 0(nw) [type: 1(CONVENTIONAL)]
start: 0x0000e0000, len 0x020000, cap 0x020000, wptr 0x000000 reset:0 non-seq:0, zcond: 0(nw) [type: 1(CONVENTIONAL)]
start: 0x000100000, len 0x020000, cap 0x01f800, wptr 0x000000 reset:0 non-seq:0, zcond: 1(em) [type: 2(SEQ_WRITE_REQUIRED)]
start: 0x000120000, len 0x020000, cap 0x01f800, wptr 0x000000 reset:0 non-seq:0, zcond: 1(em) [type: 2(SEQ_WRITE_REQUIRED)]
...
Deleting this device is done using the command::
$ echo "remove id=0" > /dev/zloop-control
The removed device can be re-added again using the same "add" command as when
the device was first created. To fully delete a zoned device, its backing files
should also be deleted after executing the remove command::
$ rm -r /var/local/zloop/0
3. 한국어 전문 번역
영어 원문의 문단 순서와 의미를 유지한 전체 번역입니다. 코드, 함수명, symbol과 URL은 원문 표기를 유지합니다.
Zoned loop block device 개요
1-45이 GPL-2.0 문서는 zoned loop block device의 개요, 생성, 삭제, 예제를 차례로 설명합니다. Zoned loop block device driver(`zloop`)를 사용하면 zone 하나마다 regular file 하나를 backing storage로 두는 zoned block device를 만들 수 있습니다.
`zloop`는 hardware를 직접 제어하지 않습니다. Filesystem의 regular file에 read, write, truncate operation을 수행해 zoned block device를 emulate합니다. Device 전체 capacity, zone size, conventional zone 수를 구성할 수 있으며, 각 zone의 backing file 최대 크기는 zone size와 같습니다.
Conventional zone을 backing하는 file 크기는 언제나 zone size와 같습니다. Sequential zone의 file 크기는 순차적으로 기록된 data 양이며, 그 file 크기가 곧 zone write pointer 위치를 나타냅니다.
Zone 종류와 operation이 backing file 크기에 어떤 의미를 갖는지 정리합니다.
Sequential zone을 reset하면 backing file을 0으로 truncate합니다. 반대로 zone finish operation은 file을 zone size까지 truncate합니다. 이 sparse한 표현 덕분에 zloop device의 configured maximum capacity를 backing filesystem의 실제 여유 공간보다 크게 잡을 수 있지만, 실제 여유 공간을 넘겨 쓰면 write error가 발생합니다.
Driver는 완전한 zone transition state machine을 구현합니다. Zone은 empty, implicitly opened, explicitly opened, closed, full 상태를 가질 수 있습니다. 현재 구현은 open zone과 active zone의 최대 개수 제한을 지원하지 않습니다.
구현되는 주요 zone 상태와 완료 경로입니다.
Hardware 없이 filesystem operation으로 zoned device를 구성합니다.
Zloop device를 만들거나 삭제하는 데 별도의 user tool은 필요하지 않습니다.
Zoned device 생성
46-95`zloop` module을 load했거나 kernel에 built-in한 뒤 character device `/dev/zloop-control`에 `add` command를 직접 쓰면 zloop device를 추가할 수 있습니다. 먼저 device ID에 대응하는 base directory를 준비합니다.
$ modprobe zloop
$ ls -l /dev/zloop*
crw-------. 1 root root 10, 123 Jan 6 19:18 /dev/zloop-control
$ mkdir -p <base directory/<device ID>
$ echo "add [options]" > /dev/zloop-control
`/dev/zloop-control`을 읽으면 지원하는 `add` option 형식과 `remove` command 형식을 확인할 수 있습니다.
$ cat /dev/zloop-control
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
remove id=%d
`add` command의 값, 제약과 default입니다.
`id`를 생략하면 번호를 자동 할당합니다. `capacity_mb`는 zone size의 정수 배수가 되도록 위쪽으로 반올림됩니다. `zone_capacity_mb`는 zone size를 넘을 수 없습니다. `conv_zones`는 sector 0에서 시작하는 conventional zone 수입니다.
`base_dir` 아래에는 device ID 이름의 directory를 만들고 그 안에 zone file을 둡니다. `nr_queues`는 online CPU 수를 상한으로 하며, `queue_depth`는 queue별 최대 I/O 깊이입니다. `buffered_io`를 지정하지 않으면 direct I/O를 사용합니다.
Control device에 add command를 보내기까지의 최소 절차입니다.
Zoned device 제거와 복원
96-115사용하지 않는 zoned loop block device를 제거하려면 `/dev/zloop-control`에 제거할 device ID를 지정한 `remove` command를 씁니다.
$ echo "remove id=X" > /dev/zloop-control
`remove` command에는 다른 option이 없습니다. 제거한 device를 다시 추가하면 각 zone은 제거 직전 상태로 복원됩니다. 단, 최초 추가 때와 완전히 같은 configuration을 사용해야 합니다. Zone configuration 변경을 감지하면 error를 반환하고 device를 만들지 않습니다.
Device를 완전히 삭제하려면 `remove` operation 뒤에 zone backing file이 들어 있는 device base directory도 삭제해야 합니다.
Control-plane 제거와 backing-file 삭제는 서로 다른 단계입니다.
2 GiB zoned device 예제
116-169다음 명령은 전체 capacity 2 GiB, zone size 64 MiB, zone capacity 63 MiB인 zoned device를 만듭니다. 원문의 `add` 명령은 `zone_capacity=63MB`라고 적혀 있으며 이 표기를 그대로 보존합니다.
$ modprobe zloop
$ mkdir -p /var/local/zloop/0
$ echo "add capacity_mb=2048,zone_size_mb=64,zone_capacity=63MB" > /dev/zloop-control
생성된 `/dev/zloop0`의 zone backing file은 모두 기본 base directory `/var/local/zloop/0` 아래에 생깁니다. `cnv-000000`부터 `cnv-000007`까지 conventional-zone file은 각각 67,108,864 byte(64 MiB)이고, 아직 비어 있는 `seq-000008` 이후 sequential-zone file은 크기가 0입니다.
$ ls -l /var/local/zloop/0
total 0
-rw-------. 1 root root 67108864 Jan 6 22:23 cnv-000000
-rw-------. 1 root root 67108864 Jan 6 22:23 cnv-000001
-rw-------. 1 root root 67108864 Jan 6 22:23 cnv-000002
-rw-------. 1 root root 67108864 Jan 6 22:23 cnv-000003
-rw-------. 1 root root 67108864 Jan 6 22:23 cnv-000004
-rw-------. 1 root root 67108864 Jan 6 22:23 cnv-000005
-rw-------. 1 root root 67108864 Jan 6 22:23 cnv-000006
-rw-------. 1 root root 67108864 Jan 6 22:23 cnv-000007
-rw-------. 1 root root 0 Jan 6 22:23 seq-000008
-rw-------. 1 root root 0 Jan 6 22:23 seq-000009
...
예제 설정과 생성 직후 file 상태입니다.
이 device는 일반 zoned block device처럼 사용할 수 있습니다. `lsblk -z`는 host-managed device, zone 32개, active/open 최대값 0, append granularity 1 MiB, write granularity 4 KiB를 보여 줍니다. `blkzone report`에서 앞 8개 zone은 `CONVENTIONAL`이고, 다음 zone은 capacity가 `0x01f800`인 `SEQ_WRITE_REQUIRED` empty zone입니다.
$ lsblk -z
NAME ZONED ZONE-SZ ZONE-NR ZONE-AMAX ZONE-OMAX ZONE-APP ZONE-WGRAN
zloop0 host-managed 64M 32 0 0 1M 4K
$ blkzone report /dev/zloop0
start: 0x000000000, len 0x020000, cap 0x020000, wptr 0x000000 reset:0 non-seq:0, zcond: 0(nw) [type: 1(CONVENTIONAL)]
start: 0x000020000, len 0x020000, cap 0x020000, wptr 0x000000 reset:0 non-seq:0, zcond: 0(nw) [type: 1(CONVENTIONAL)]
start: 0x000040000, len 0x020000, cap 0x020000, wptr 0x000000 reset:0 non-seq:0, zcond: 0(nw) [type: 1(CONVENTIONAL)]
start: 0x000060000, len 0x020000, cap 0x020000, wptr 0x000000 reset:0 non-seq:0, zcond: 0(nw) [type: 1(CONVENTIONAL)]
start: 0x000080000, len 0x020000, cap 0x020000, wptr 0x000000 reset:0 non-seq:0, zcond: 0(nw) [type: 1(CONVENTIONAL)]
start: 0x0000a0000, len 0x020000, cap 0x020000, wptr 0x000000 reset:0 non-seq:0, zcond: 0(nw) [type: 1(CONVENTIONAL)]
start: 0x0000c0000, len 0x020000, cap 0x020000, wptr 0x000000 reset:0 non-seq:0, zcond: 0(nw) [type: 1(CONVENTIONAL)]
start: 0x0000e0000, len 0x020000, cap 0x020000, wptr 0x000000 reset:0 non-seq:0, zcond: 0(nw) [type: 1(CONVENTIONAL)]
start: 0x000100000, len 0x020000, cap 0x01f800, wptr 0x000000 reset:0 non-seq:0, zcond: 1(em) [type: 2(SEQ_WRITE_REQUIRED)]
start: 0x000120000, len 0x020000, cap 0x01f800, wptr 0x000000 reset:0 non-seq:0, zcond: 1(em) [type: 2(SEQ_WRITE_REQUIRED)]
...
Device를 제거할 때는 ID 0으로 `remove` command를 보냅니다.
$ echo "remove id=0" > /dev/zloop-control
제거한 device는 처음과 같은 `add` command로 다시 추가할 수 있습니다. 완전히 삭제하려면 `remove` 뒤 backing file directory도 삭제합니다.
$ rm -r /var/local/zloop/0
생성·검사·제거·완전 삭제 명령의 관계입니다.
Storage and zone states
zoned_loop.rst:1-45Zone file 크기로 sequential write pointer를 나타내며 reset과 finish는 truncate로 구현합니다.