Skip to content

Add full zoned storage emulation to the qcow2 driver

Niklas Cassel qemu-devel 3 versions – In review

Get series with b4
b4 am [email protected]

Versions newest first · linked by author and title

  1. v17 Latest9 patches 5 repliesIn review
  2. v169 patches 1 replySuperseded
  3. v157 patches 0 repliesSuperseded

Changes in v17 from the cover letter

- Rebase on master (v11.2.0-rc0)
- Report the errors of qcow2_check_zone_options() through errp instead of warn_report() (Stefan Hajnoczi)
- Move the zone lists, the write pointer tracking and their fields in BDRVQcow2State from "qcow2: add configurations for zoned format extension" to "qcow2: add zoned emulation capability", the first patch that uses them (Stefan Hajnoczi)
- Move the check that the zoned metadata fits in the image file to "qcow2: add zoned emulation capability" as well, where the zoned metadata is read. In the earlier patch, it checked an offset that was not byte-swapped yet.
- Reject an image whose write pointer table starts at offset 0, where the image header is, or not on a cluster boundary: the write pointer cache reads and writes the table in whole clusters, aborts on an offset of 0, and marks the image corrupt on an unaligned one. Add a test for the same.
- Declare variables at the start of blocks, as the coding style requires.
- Pick up Stefan Hajnoczi's Reviewed-by on "qcow2: add configurations for zoned format extension"

Patches in v17 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/9docs/qcow2: add the zoned format featuredocs/system/qemu-block-drivers.rst.inc+44 -00 replies
2/9qcow2: add configurations for zoned format extensionblock/io.c block/qcow2.c block/qcow2.h +11 more+727 -270 replies
3/9block: define errnos for zone protocol errorsinclude/block/block-common.h include/qemu/osdep.h+23 -01 reply
4/9qcow2: add zoned emulation capabilityblock/qcow2-cache.c block/qcow2-refcount.c block/qcow2.c +2 more+1380 -50 replies
5/9iotests: test the zoned format feature for qcow2 fileMAINTAINERS tests/qemu-iotests/tests/zoned-qcow2 tests/qemu-iotests/tests/zoned-qcow2.out+618 -00 replies
6/9qcow2: validate the write pointer table when opening an imageblock/qcow2.c tests/qemu-iotests/tests/zoned-qcow2 tests/qemu-iotests/tests/zoned-qcow2.out+96 -00 replies
7/9virtio-blk: report zone errors with their zone status codeshw/block/virtio-blk.c+45 -41 reply
8/9block: add accessors for the zone model, capacity and open zone limitblock/block-backend.c include/system/block-backend-io.h+36 -01 reply
9/9scsi: add the sense codes of zoned block devicesinclude/scsi/utils.h scsi/utils.c+21 -01 reply

Reviews trailers per patch

6 of 9 patches have a Reviewed-by or Acked-by.

PatchMarkus ArmbrusterStefan HajnocziNiklas CasselDamien Le Moal
1/9R-b R-b
2/9A-b R-b
3/9R-b
4/9
5/9
6/9
7/9R-b
8/9R-b
9/9R-b

Trailers given in replies are filled; those carried in the patches from earlier versions are outlined with dashes. Scroll the table sideways for all 4 reviewers.

Read the v17 thread

Cover letter [PATCH v17 0/9] Add full zoned storage emulation to the qcow2 driver

This patch series adds a new extension - zoned format - to the qcow2 driver, allowing full zoned storage emulation on a qcow2 image file. A user can attach such an image to a guest and have it appear as a host-managed zoned block device.

The zoned format is opt-in through a new qcow2 header extension that pins the zone geometry. Behind the extension is a dedicated zoned metadata region that stores one 8-byte write pointer (WP) per zone. The extension is gated by an incompatible bit, so an older qcow2 implementation cannot accidentally open the image.

Each write pointer is routed through the write pointer cache, a Qcow2Cache object. The write pointer cache is written to disk after the qcow2 metadata is written, thus guaranteeing that the write pointer is updated after the corresponding data is written.

Zone states are in memory. Read-only and offline states are device-internal events, which are not modelled in qcow2 emulation for simplicity. The other zone states (closed, empty, full) can be inferred from write pointer values, persistent across QEMU reboots. The open states are kept in memory using open zone lists.

To create a qcow2 file with the zoned format:

    qemu-img create -f qcow2 zbc.qcow2 \
        -o size=768M \
        -o zone.size=64M \
        -o zone.capacity=64M \
        -o zone.conventional_zones=0 \
        -o zone.max_open_zones=6 \
        -o zone.max_active_zones=8 \
        -o zone.mode=host-managed

Then attach it to a guest via the QEMU command line:

    -blockdev node-name=drive1,driver=qcow2,file.driver=file,file.filename=zbc.qcow2 \
    -device virtio-blk-pci,drive=drive1 \

Tested with blktests, fio, zbd_state (an internal test suite) and zonefs, comparing a zoned qcow2 image attached via virtio-blk with zloop, null_blk and scsi_debug (passed/failed/skipped):

    +--------------------+----------+---------+-----------+---------+
    | Testrun            | blktests | fio     | zbd_state | zonefs  |
    +--------------------+----------+---------+-----------+---------+
    | zloop              | 9/0/10   | 57/0/18 | 29/0/8    | 113/0/0 |
    | null_blk           | 9/0/10   | 57/0/18 | 29/0/8    | 113/0/0 |
    | scsi_debug         | 10/0/12  | 61/0/14 | 29/0/8    | 113/0/0 |
    | virtio-blk + qcow2 | 9/0/10   | 57/0/18 | 29/0/8    | 113/0/0 |
    +--------------------+----------+---------+-----------+---------+

The last two patches are not used by the qcow2 driver. Both Daejun Park's zoned UFS series and an upcoming series that adds zoned support to ATA depend on this series, and both also require these two patches, so they are included here, to avoid both series needing to carry them separately as dependencies.

Git branch can be found at:
https://github.com/floatious/qemu/tree/qcow2-v17

v16->v17:
- Rebase on master (v11.2.0-rc0)
- Report the errors of qcow2_check_zone_options() through errp instead of warn_report() (Stefan Hajnoczi)
- Move the zone lists, the write pointer tracking and their fields in BDRVQcow2State from "qcow2: add configurations for zoned format extension" to "qcow2: add zoned emulation capability", the first patch that uses them (Stefan Hajnoczi)
- Move the check that the zoned metadata fits in the image file to "qcow2: add zoned emulation capability" as well, where the zoned metadata is read. In the earlier patch, it checked an offset that was not byte-swapped yet.
- Reject an image whose write pointer table starts at offset 0, where the image header is, or not on a cluster boundary: the write pointer cache reads and writes the table in whole clusters, aborts on an offset of 0, and marks the image corrupt on an unaligned one. Add a test for the same.
- Declare variables at the start of blocks, as the coding style requires.
- Pick up Stefan Hajnoczi's Reviewed-by on "qcow2: add configurations for zoned format extension"

Niklas Cassel (5):
block: define errnos for zone protocol errors
qcow2: validate the write pointer table when opening an image
virtio-blk: report zone errors with their zone status codes
block: add accessors for the zone model, capacity and open zone limit
scsi: add the sense codes of zoned block devices

Sam Li (4):
docs/qcow2: add the zoned format feature
qcow2: add configurations for zoned format extension
qcow2: add zoned emulation capability
iotests: test the zoned format feature for qcow2 file

 MAINTAINERS                                   |    1 +
 block/block-backend.c                         |   33 +
 block/io.c                                    |   13 +-
 block/qcow2-cache.c                           |   11 +-
 block/qcow2-refcount.c                        |   18 +
 block/qcow2.c                                 | 1724 ++++++++++++++++-
 block/qcow2.h                                 |   86 +-
 block/trace-events                            |   10 +
 docs/interop/qcow2.rst                        |  115 +-
 docs/system/qemu-block-drivers.rst.inc        |   44 +
 hw/block/block.c                              |    7 +
 hw/block/virtio-blk.c                         |   49 +-
 include/block/block-common.h                  |   17 +
 include/block/block-io.h                      |    6 +
 include/block/block_int-common.h              |   12 +
 include/qemu/osdep.h                          |    6 +
 include/scsi/utils.h                          |    6 +
 include/system/block-backend-io.h             |    3 +
 qapi/block-core.json                          |   86 +-
 scsi/utils.c                                  |   15 +
 tests/qemu-iotests/031.out                    |    8 +-
 tests/qemu-iotests/036.out                    |    4 +-
 tests/qemu-iotests/061.out                    |   14 +-
 tests/qemu-iotests/082.out                    |  108 ++
 tests/qemu-iotests/303.out                    |    4 +-
 tests/qemu-iotests/tests/qcow2-encryption.out |    4 +-
 tests/qemu-iotests/tests/zoned-qcow2          |  379 ++++
 tests/qemu-iotests/tests/zoned-qcow2.out      |  267 +++
 28 files changed, 3002 insertions(+), 48 deletions(-)
 create mode 100755 tests/qemu-iotests/tests/zoned-qcow2
 create mode 100644 tests/qemu-iotests/tests/zoned-qcow2.out

base-commit: 29760efaf96bbe5928f8111881eddbf5ac06439e

Signature · 1 line
2.56.0