Add zoned storage emulation to virtio-blk driver
Subsystems (2)
v9 cover Add zoned storage emulation to virtio-blk driver
This patch adds zoned storage emulation to the virtio-blk driver. It implements the virtio-blk ZBD support standardization that is recently accepted by virtio-spec. The link to related commit is at
https://github.com/oasis-tcs/virtio-spec/commit/b4e8efa0fa6c8d844328090ad15db65af8d7d981
The Linux zoned device code that implemented by Dmitry Fomichev has been released at the latest Linux version v6.3-rc1.
Aside: adding zoned=on alike options to virtio-blk device will be considered in following-up plan.
Note: Sorry to send it again because of the previous incoherent patches caused by network error.
v9:
- address review comments
* add docs for zoned emulation use case [Matias]
* add the zoned feature bit to qmp monitor [Matias]
* add the version number for newly added configs of accounting [Markus]
v8:
- address Stefan's review comments
* rm aio_context_acquire/release in handle_req
* rename function return type
* rename BLOCK_ACCT_APPEND to BLOCK_ACCT_ZONE_APPEND for clarity
v7:
- update headers to v6.3-rc1
v6:
- address Stefan's review comments
* add accounting for zone append operation
* fix in_iov usage in handle_request, error handling and typos
v5:
- address Stefan's review comments
* restore the way writing zone append result to buffer
* fix error checking case and other errands
v4:
- change the way writing zone append request result to buffer
- change zone state, zone type value of virtio_blk_zone_descriptor
- add trace events for new zone APIs
v3:
- use qemuio_from_buffer to write status bit [Stefan]
- avoid using req->elem directly [Stefan]
- fix error checkings and memory leak [Stefan]
v2:
- change units of emulated zone op coresponding to block layer APIs
- modify error checking cases [Stefan, Damien]
v1:
- add zoned storage emulation
Sam Li (5):
include: update virtio_blk headers to v6.3-rc1
virtio-blk: add zoned storage emulation for zoned devices
block: add accounting for zone append operation
virtio-blk: add some trace events for zoned emulation docs/zoned-storage:add zoned emulation use case
block/qapi-sysemu.c | 11 + block/qapi.c | 18 + docs/devel/zoned-storage.rst | 17 + hw/block/trace-events | 7 + hw/block/virtio-blk-common.c | 2 + hw/block/virtio-blk.c | 405 +++++++++++++++++++ hw/virtio/virtio-qmp.c | 2 + include/block/accounting.h | 1 + include/standard-headers/drm/drm_fourcc.h | 12 + include/standard-headers/linux/ethtool.h | 48 ++- include/standard-headers/linux/fuse.h | 45 ++- include/standard-headers/linux/pci_regs.h | 1 + include/standard-headers/linux/vhost_types.h | 2 + include/standard-headers/linux/virtio_blk.h | 105 +++++ linux-headers/asm-arm64/kvm.h | 1 + linux-headers/asm-x86/kvm.h | 34 +- linux-headers/linux/kvm.h | 9 + linux-headers/linux/vfio.h | 15 +- linux-headers/linux/vhost.h | 8 + qapi/block-core.json | 68 +++- qapi/block.json | 4 + 21 files changed, 794 insertions(+), 21 deletions(-)
Signature · 1 line
2.39.2
PATCH v9 1/5 include: update virtio_blk headers to v6.3-rc1
Use scripts/update-linux-headers.sh to update headers to 6.3-rc1.
--- include/standard-headers/drm/drm_fourcc.h | 12 +++ include/standard-headers/linux/ethtool.h | 48 ++++++++- include/standard-headers/linux/fuse.h | 45 +++++++- include/standard-headers/linux/pci_regs.h | 1 + include/standard-headers/linux/vhost_types.h | 2 + include/standard-headers/linux/virtio_blk.h | 105 +++++++++++++++++++ linux-headers/asm-arm64/kvm.h | 1 + linux-headers/asm-x86/kvm.h | 34 +++++- linux-headers/linux/kvm.h | 9 ++ linux-headers/linux/vfio.h | 15 +-- linux-headers/linux/vhost.h | 8 ++ 11 files changed, 270 insertions(+), 10 deletions(-)
include/standard-headers/drm/drm_fourcc.h +12 -0
@@ -87,6 +87,18 @@ extern "C" {* * The authoritative list of format modifier codes is found in * `include/uapi/drm/drm_fourcc.h` +* +* Open Source User Waiver +* ----------------------- +* +* Because this is the authoritative source for pixel formats and modifiers +* referenced by GL, Vulkan extensions and other standards and hence used both +* by open source and closed source driver stacks, the usual requirement for an +* upstream in-kernel or open source userspace user does not apply. +* +* To ensure, as much as feasible, compatibility across stacks and avoid +* confusion with incompatible enumerations stakeholders for all relevant driver +* stacks should approve additions. */ #define fourcc_code (a, b, c, d) ((uint32_t)(a) | ((uint32_t)(b) << 8) | \
include/standard-headers/linux/ethtool.h +47 -1
72 lines not on this page · raw message
include/standard-headers/linux/fuse.h +44 -1
79 lines not on this page · raw message
include/standard-headers/linux/pci_regs.h +1 -0
@@ -693,6 +693,7 @@#define PCI_EXP_LNKCTL2_TX_MARGIN 0x0380/* Transmit Margin */ #define PCI_EXP_LNKCTL2_HASD 0x0020/* HW Autonomous Speed Disable */ #define PCI_EXP_LNKSTA2 0x32/* Link Status 2 */ +#define PCI_EXP_LNKSTA2_FLIT 0x0400/* Flit Mode Status */ #define PCI_CAP_EXP_ENDPOINT_SIZEOF_V2 0x32/* end of v2 EPs w/ link */ #define PCI_EXP_SLTCAP2 0x34/* Slot Capabilities 2 */ #define PCI_EXP_SLTCAP2_IBPD 0x00000001/* In-band PD Disable Supported */
include/standard-headers/linux/vhost_types.h +2 -0
@@ -163,5 +163,7 @@ struct vhost_vdpa_iova_range {#define VHOST_BACKEND_F_IOTLB_ASID 0x3/* Device can be suspended */ #define VHOST_BACKEND_F_SUSPEND 0x4 +/* Device can be resumed */ +#define VHOST_BACKEND_F_RESUME 0x5#endif
include/standard-headers/linux/virtio_blk.h +105 -0
133 lines not on this page · raw message
linux-headers/asm-arm64/kvm.h +1 -0
@@ -109,6 +109,7 @@ struct kvm_regs {#define KVM_ARM_VCPU_SVE 4/* enable SVE for this CPU */ #define KVM_ARM_VCPU_PTRAUTH_ADDRESS 5/* VCPU uses address authentication */ #define KVM_ARM_VCPU_PTRAUTH_GENERIC 6/* VCPU uses generic authentication */ +#define KVM_ARM_VCPU_HAS_EL2 7/* Support nested virtualization */ struct kvm_vcpu_init {__u32 target;
linux-headers/asm-x86/kvm.h +32 -2
@@ -9,6 +9,7 @@#include <linux/types.h> #include <linux/ioctl.h> +#include <linux/stddef.h> #define KVM_PIO_PAGE_OFFSET 1#define KVM_COALESCED_MMIO_PAGE_OFFSET 2
@@ -505,8 +506,8 @@ struct kvm_nested_state {* KVM_{GET,PUT}_NESTED_STATE ioctl values. */ union { -struct kvm_vmx_nested_state_data vmx[0 ]; -struct kvm_svm_nested_state_data svm[0 ]; + __DECLARE_FLEX_ARRAY(struct kvm_vmx_nested_state_data, vmx); + __DECLARE_FLEX_ARRAY(struct kvm_svm_nested_state_data, svm); } data; };
@@ -523,6 +524,35 @@ struct kvm_pmu_event_filter {#define KVM_PMU_EVENT_ALLOW 0#define KVM_PMU_EVENT_DENY 1 +#define KVM_PMU_EVENT_FLAG_MASKED_EVENTS BIT(0) +#define KVM_PMU_EVENT_FLAGS_VALID_MASK (KVM_PMU_EVENT_FLAG_MASKED_EVENTS) + +/* +* Masked event layout. +* Bits Description +* ---- ----------- +* 7:0 event select (low bits) +* 15:8 umask match +* 31:16 unused +* 35:32 event select (high bits) +* 36:54 unused +* 55 exclude bit +* 63:56 umask mask +*/ + +#define KVM_PMU_ENCODE_MASKED_ENTRY (event_select, mask, match, exclude) \ + (((event_select) & 0xFFULL) | (((event_select) & 0XF00ULL) << 24) | \ + (((mask) & 0xFFULL) << 56) | \ + (((match) & 0xFFULL) << 8) | \ + ((__u64)(!!(exclude)) << 55)) + +#define KVM_PMU_MASKED_ENTRY_EVENT_SELECT \ + (GENMASK_ULL(7, 0) | GENMASK_ULL(35, 32)) +#define KVM_PMU_MASKED_ENTRY_UMASK_MASK (GENMASK_ULL(63, 56)) +#define KVM_PMU_MASKED_ENTRY_UMASK_MATCH (GENMASK_ULL(15, 8)) +#define KVM_PMU_MASKED_ENTRY_EXCLUDE (BIT_ULL(55)) +#define KVM_PMU_MASKED_ENTRY_UMASK_MASK_SHIFT (56) +/* for KVM_{GET,SET,HAS}_DEVICE_ATTR */ #define KVM_VCPU_TSC_CTRL 0/* control group for the timestamp counter (TSC) */ #define KVM_VCPU_TSC_OFFSET 0/* attribute for the TSC offset */
linux-headers/linux/kvm.h +9 -0
@@ -581,6 +581,8 @@ struct kvm_s390_mem_op {struct {__u8 ar;/* the access register number */ __u8 key;/* access key, ignored if flag unset */ +__u8 pad1[6 ];/* ignored */ +__u64 old_addr;/* ignored if cmpxchg flag unset */ };__u32 sida_offset;/* offset into the sida */ __u8 reserved[32 ];/* ignored */
@@ -593,11 +595,17 @@ struct kvm_s390_mem_op {#define KVM_S390_MEMOP_SIDA_WRITE 3#define KVM_S390_MEMOP_ABSOLUTE_READ 4#define KVM_S390_MEMOP_ABSOLUTE_WRITE 5 +#define KVM_S390_MEMOP_ABSOLUTE_CMPXCHG 6 +/* flags for kvm_s390_mem_op->flags */ #define KVM_S390_MEMOP_F_CHECK_ONLY (1ULL << 0)#define KVM_S390_MEMOP_F_INJECT_EXCEPTION (1ULL << 1)#define KVM_S390_MEMOP_F_SKEY_PROTECTION (1ULL << 2) +/* flags specifying extension support via KVM_CAP_S390_MEM_OP_EXTENSION */ +#define KVM_S390_MEMOP_EXTENSION_CAP_BASE (1 << 0) +#define KVM_S390_MEMOP_EXTENSION_CAP_CMPXCHG (1 << 1) +/* for KVM_INTERRUPT */ struct kvm_interrupt {/* in */
@@ -1173,6 +1181,7 @@ struct kvm_ppc_resize_hpt {#define KVM_CAP_DIRTY_LOG_RING_ACQ_REL 223#define KVM_CAP_S390_PROTECTED_ASYNC_DISABLE 224#define KVM_CAP_DIRTY_LOG_RING_WITH_BITMAP 225 +#define KVM_CAP_PMU_EVENT_MASKED_EVENTS 226#ifdef KVM_CAP_IRQ_ROUTING
linux-headers/linux/vfio.h +9 -6
@@ -49,7 +49,11 @@/* Supports VFIO_DMA_UNMAP_FLAG_ALL */ #define VFIO_UNMAP_ALL 9 -/* Supports the vaddr flag for DMA map and unmap */ +/* +* Supports the vaddr flag for DMA map and unmap. Not supported for mediated +* devices, so this capability is subject to change as groups are added or +* removed. +*/ #define VFIO_UPDATE_VADDR 10/*
@@ -1343,8 +1347,7 @@ struct vfio_iommu_type1_info_dma_avail {* Map process virtual addresses to IO virtual addresses using the * provided struct vfio_dma_map. Caller sets argsz. READ &/ WRITE required. * -* If flags & VFIO_DMA_MAP_FLAG_VADDR, update the base vaddr for iova, and -* unblock translation of host virtual addresses in the iova range. The vaddr +* If flags & VFIO_DMA_MAP_FLAG_VADDR, update the base vaddr for iova. The vaddr * must have previously been invalidated with VFIO_DMA_UNMAP_FLAG_VADDR. To * maintain memory consistency within the user application, the updated vaddr * must address the same memory object as originally mapped. Failure to do so
@@ -1395,9 +1398,9 @@ struct vfio_bitmap {* must be 0. This cannot be combined with the get-dirty-bitmap flag. * * If flags & VFIO_DMA_UNMAP_FLAG_VADDR, do not unmap, but invalidate host -* virtual addresses in the iova range. Tasks that attempt to translate an -* iova's vaddr will block. DMA to already-mapped pages continues. This -* cannot be combined with the get-dirty-bitmap flag. +* virtual addresses in the iova range. DMA to already-mapped pages continues. +* Groups may not be added to the container while any addresses are invalid. +* This cannot be combined with the get-dirty-bitmap flag. */ struct vfio_iommu_type1_dma_unmap {__u32 argsz;
linux-headers/linux/vhost.h +8 -0
@@ -180,4 +180,12 @@*/ #define VHOST_VDPA_SUSPEND _IO(VHOST_VIRTIO, 0x7D) +/* Resume a device so it can resume processing virtqueue requests +* +* After the return of this ioctl the device will have restored all the +* necessary states and it is fully operational to continue processing the +* virtqueue descriptors. +*/ +#define VHOST_VDPA_RESUME _IO(VHOST_VIRTIO, 0x7E) +#endif
Signature · 1 line
2.39.2
PATCH v9 2/5 virtio-blk: add zoned storage emulation for zoned devices
In reply to Sam LiThis patch extends virtio-blk emulation to handle zoned device commands by calling the new block layer APIs to perform zoned device I/O on behalf of the guest. It supports Report Zone, four zone oparations (open, close, finish, reset), and Append Zone.
The VIRTIO_BLK_F_ZONED feature bit will only be set if the host does support zoned block devices. Regular block devices(conventional zones) will not be set.
The guest os can use blktests, fio to test those commands on zoned devices. Furthermore, using zonefs to test zone append write is also supported.
--- hw/block/virtio-blk-common.c | 2 + hw/block/virtio-blk.c | 389 +++++++++++++++++++++++++++++++++++ hw/virtio/virtio-qmp.c | 2 + 3 files changed, 393 insertions(+)
hw/block/virtio-blk-common.c +2 -0
@@ -29,6 +29,8 @@ static const VirtIOFeature feature_sizes[] = { .end = endof(struct virtio_blk_config, discard_sector_alignment)}, {.flags = 1ULL << VIRTIO_BLK_F_WRITE_ZEROES, .end = endof(struct virtio_blk_config, write_zeroes_may_unmap)}, + {.flags = 1ULL << VIRTIO_BLK_F_ZONED, + .end = endof(struct virtio_blk_config, zoned)}, {} };
hw/block/virtio-blk.c +389 -0
437 lines not on this page · raw message
hw/virtio/virtio-qmp.c +2 -0
@@ -176,6 +176,8 @@ static const qmp_virtio_feature_map_t virtio_blk_feature_map[] = { "VIRTIO_BLK_F_DISCARD: Discard command supported"),FEATURE_ENTRY (VIRTIO_BLK_F_WRITE_ZEROES , \"VIRTIO_BLK_F_WRITE_ZEROES: Write zeroes command supported" ), +FEATURE_ENTRY (VIRTIO_BLK_F_ZONED , \ +"VIRTIO_BLK_F_ZONED: Zoned block devices" ), #ifndef VIRTIO_BLK_NO_LEGACYFEATURE_ENTRY (VIRTIO_BLK_F_BARRIER , \ "VIRTIO_BLK_F_BARRIER: Request barriers supported"),
Signature · 1 line
2.39.2
PATCH v9 3/5 block: add accounting for zone append operation
In reply to Sam LiTaking account of the new zone append write operation for zoned devices, BLOCK_ACCT_ZONE_APPEND enum is introduced as other I/O request type (read, write, flush).
--- block/qapi-sysemu.c | 11 ++++++ block/qapi.c | 18 ++++++++++ hw/block/virtio-blk.c | 4 +++ include/block/accounting.h | 1 + qapi/block-core.json | 68 ++++++++++++++++++++++++++++++++------ qapi/block.json | 4 +++ 6 files changed, 95 insertions(+), 11 deletions(-)
block/qapi-sysemu.c +11 -0
@@ -517,6 +517,7 @@ void qmp_block_latency_histogram_set( bool has_boundaries, uint64List *boundaries, bool has_boundaries_read, uint64List *boundaries_read, bool has_boundaries_write, uint64List *boundaries_write, + bool has_boundaries_append, uint64List *boundaries_append, bool has_boundaries_flush, uint64List *boundaries_flush, Error **errp) {
@@ -557,6 +558,16 @@ void qmp_block_latency_histogram_set( } } +if (has_boundaries || has_boundaries_append) { + ret =block_latency_histogram_set ( + stats,BLOCK_ACCT_ZONE_APPEND , + has_boundaries_append ? boundaries_append : boundaries); +if (ret) { +error_setg (errp,"Device '%s' set append write boundaries fail" , id); +return ; + } + } +if (has_boundaries || has_boundaries_flush) { ret = block_latency_histogram_set( stats, BLOCK_ACCT_FLUSH,
block/qapi.c +18 -0
@@ -533,27 +533,36 @@ static void bdrv_query_blk_stats(BlockDeviceStats *ds, BlockBackend *blk) ds->rd_bytes = stats->nr_bytes[BLOCK_ACCT_READ ]; ds->wr_bytes = stats->nr_bytes[BLOCK_ACCT_WRITE ]; + ds->zone_append_bytes = stats->nr_bytes[BLOCK_ACCT_ZONE_APPEND ]; ds->unmap_bytes = stats->nr_bytes[BLOCK_ACCT_UNMAP ]; ds->rd_operations = stats->nr_ops[BLOCK_ACCT_READ ]; ds->wr_operations = stats->nr_ops[BLOCK_ACCT_WRITE ]; + ds->zone_append_operations = stats->nr_ops[BLOCK_ACCT_ZONE_APPEND ]; ds->unmap_operations = stats->nr_ops[BLOCK_ACCT_UNMAP ]; ds->failed_rd_operations = stats->failed_ops[BLOCK_ACCT_READ ]; ds->failed_wr_operations = stats->failed_ops[BLOCK_ACCT_WRITE ]; + ds->failed_zone_append_operations = + stats->failed_ops[BLOCK_ACCT_ZONE_APPEND ]; ds->failed_flush_operations = stats->failed_ops[BLOCK_ACCT_FLUSH ]; ds->failed_unmap_operations = stats->failed_ops[BLOCK_ACCT_UNMAP ]; ds->invalid_rd_operations = stats->invalid_ops[BLOCK_ACCT_READ ]; ds->invalid_wr_operations = stats->invalid_ops[BLOCK_ACCT_WRITE ]; + ds->invalid_zone_append_operations = + stats->invalid_ops[BLOCK_ACCT_ZONE_APPEND ]; ds->invalid_flush_operations = stats->invalid_ops[BLOCK_ACCT_FLUSH ]; ds->invalid_unmap_operations = stats->invalid_ops[BLOCK_ACCT_UNMAP ]; ds->rd_merged = stats->merged[BLOCK_ACCT_READ ]; ds->wr_merged = stats->merged[BLOCK_ACCT_WRITE ]; + ds->zone_append_merged = stats->merged[BLOCK_ACCT_ZONE_APPEND ]; ds->unmap_merged = stats->merged[BLOCK_ACCT_UNMAP ]; ds->flush_operations = stats->nr_ops[BLOCK_ACCT_FLUSH ]; ds->wr_total_time_ns = stats->total_time_ns[BLOCK_ACCT_WRITE ]; + ds->zone_append_total_time_ns = + stats->total_time_ns[BLOCK_ACCT_ZONE_APPEND ]; ds->rd_total_time_ns = stats->total_time_ns[BLOCK_ACCT_READ ]; ds->flush_total_time_ns = stats->total_time_ns[BLOCK_ACCT_FLUSH ]; ds->unmap_total_time_ns = stats->total_time_ns[BLOCK_ACCT_UNMAP ];
@@ -571,6 +580,7 @@ static void bdrv_query_blk_stats(BlockDeviceStats *ds, BlockBackend *blk)TimedAverage *rd = &ts->latency[BLOCK_ACCT_READ ];TimedAverage *wr = &ts->latency[BLOCK_ACCT_WRITE ]; +TimedAverage *zap = &ts->latency[BLOCK_ACCT_ZONE_APPEND ];TimedAverage *fl = &ts->latency[BLOCK_ACCT_FLUSH ]; dev_stats->interval_length = ts->interval_length;
@@ -583,6 +593,10 @@ static void bdrv_query_blk_stats(BlockDeviceStats *ds, BlockBackend *blk) dev_stats->max_wr_latency_ns =timed_average_max (wr); dev_stats->avg_wr_latency_ns =timed_average_avg (wr); + dev_stats->min_zone_append_latency_ns =timed_average_min (zap); + dev_stats->max_zone_append_latency_ns =timed_average_max (zap); + dev_stats->avg_zone_append_latency_ns =timed_average_avg (zap); + dev_stats->min_flush_latency_ns =timed_average_min (fl); dev_stats->max_flush_latency_ns =timed_average_max (fl); dev_stats->avg_flush_latency_ns =timed_average_avg (fl);
@@ -591,6 +605,8 @@ static void bdrv_query_blk_stats(BlockDeviceStats *ds, BlockBackend *blk)block_acct_queue_depth (ts,BLOCK_ACCT_READ ); dev_stats->avg_wr_queue_depth =block_acct_queue_depth (ts,BLOCK_ACCT_WRITE ); + dev_stats->avg_zone_append_queue_depth = +block_acct_queue_depth (ts,BLOCK_ACCT_ZONE_APPEND );QAPI_LIST_PREPEND (ds->timed_stats, dev_stats); }
@@ -600,6 +616,8 @@ static void bdrv_query_blk_stats(BlockDeviceStats *ds, BlockBackend *blk) = bdrv_latency_histogram_stats(&hgram[BLOCK_ACCT_READ]); ds->wr_latency_histogram =bdrv_latency_histogram_stats (&hgram[BLOCK_ACCT_WRITE ]); + ds->zone_append_latency_histogram + =bdrv_latency_histogram_stats (&hgram[BLOCK_ACCT_ZONE_APPEND ]); ds->flush_latency_histogram =bdrv_latency_histogram_stats (&hgram[BLOCK_ACCT_FLUSH ]); }
hw/block/virtio-blk.c +4 -0
@@ -919,6 +919,10 @@ static int virtio_blk_handle_zone_append(VirtIOBlockReq *req, data->in_num = in_num; data->zone_append_data.offset = offset;qemu_iovec_init_external (&req->qiov, out_iov, out_num); + +block_acct_start (blk_get_stats (s->blk), &req->acct, len, +BLOCK_ACCT_ZONE_APPEND ); +blk_aio_zone_append (s->blk, &data->zone_append_data.offset, &req->qiov,0 , virtio_blk_zone_append_complete, data);return 0 ;
include/block/accounting.h +1 -0
@@ -37,6 +37,7 @@ enum BlockAcctType {BLOCK_ACCT_READ ,BLOCK_ACCT_WRITE ,BLOCK_ACCT_FLUSH , +BLOCK_ACCT_ZONE_APPEND ,BLOCK_ACCT_UNMAP , BLOCK_MAX_IOTYPE, };
qapi/block-core.json +57 -11
153 lines not on this page · raw message
qapi/block.json +4 -0
@@ -525,6 +525,9 @@ # @boundaries-write: list of interval boundary values for write latency # histogram. # +# @boundaries-zap: list of interval boundary values for zone append write +# latency histogram. +# # @boundaries-flush: list of interval boundary values for flush latency # histogram. #
@@ -573,5 +576,6 @@ '*boundaries': ['uint64'], '*boundaries-read': ['uint64'], '*boundaries-write': ['uint64'], + '*boundaries-zap': ['uint64'], '*boundaries-flush': ['uint64'] }, 'allow-preconfig': true }
Signature · 1 line
2.39.2
PATCH v9 4/5 virtio-blk: add some trace events for zoned emulation
In reply to Sam Li--- hw/block/trace-events | 7 +++++++ hw/block/virtio-blk.c | 12 ++++++++++++ 2 files changed, 19 insertions(+)
hw/block/trace-events +7 -0
@@ -44,9 +44,16 @@ pflash_write_unknown(const char *name, uint8_t cmd) "%s: unknown command 0x%02x" # virtio-blk.c virtio_blk_req_complete(void *vdev, void *req, int status) "vdev %p req %p status %d" virtio_blk_rw_complete(void *vdev, void *req, int ret) "vdev %p req %p ret %d" +virtio_blk_zone_report_complete(void *vdev, void *req, unsigned int nr_zones, int ret) "vdev %p req %p nr_zones %u ret %d" +virtio_blk_zone_mgmt_complete(void *vdev, void *req, int ret) "vdev %p req %p ret %d" +virtio_blk_zone_append_complete(void *vdev, void *req, int64_t sector, int ret) "vdev %p req %p, append sector 0x%" PRIx64 " ret %d" virtio_blk_handle_write(void *vdev, void *req, uint64_t sector, size_t nsectors) "vdev %p req %p sector %"PRIu64" nsectors %zu" virtio_blk_handle_read(void *vdev, void *req, uint64_t sector, size_t nsectors) "vdev %p req %p sector %"PRIu64" nsectors %zu" virtio_blk_submit_multireq(void *vdev, void *mrb, int start, int num_reqs, uint64_t offset, size_t size, bool is_write) "vdev %p mrb %p start %d num_reqs %d offset %"PRIu64" size %zu is_write %d" +virtio_blk_handle_zone_report(void *vdev, void *req, int64_t sector, unsigned int nr_zones) "vdev %p req %p sector 0x%" PRIx64 " nr_zones %u" +virtio_blk_handle_zone_mgmt(void *vdev, void *req, uint8_t op, int64_t sector, int64_t len) "vdev %p req %p op 0x%x sector 0x%" PRIx64 " len 0x%" PRIx64 "" +virtio_blk_handle_zone_reset_all(void *vdev, void *req, int64_t sector, int64_t len) "vdev %p req %p sector 0x%" PRIx64 " cap 0x%" PRIx64 "" +virtio_blk_handle_zone_append(void *vdev, void *req, int64_t sector) "vdev %p req %p, append sector 0x%" PRIx64 "" # hd-geometry.c hd_geometry_lchs_guess(void *blk, int cyls, int heads, int secs) "blk %p LCHS %d %d %d"
hw/block/virtio-blk.c +12 -0
@@ -676,6 +676,7 @@ static void virtio_blk_zone_report_complete(void *opaque, int ret)int64_t nz = data->zone_report_data.nr_zones;int8_t err_status =VIRTIO_BLK_S_OK ; +trace_virtio_blk_zone_report_complete (vdev, req, nz, ret);if (ret) { err_status =VIRTIO_BLK_S_ZONE_INVALID_CMD ; goto out;
@@ -792,6 +793,8 @@ static void virtio_blk_handle_zone_report(VirtIOBlockReq *req, nr_zones = (req->in_len -sizeof (struct virtio_blk_inhdr ) -sizeof (struct virtio_blk_zone_report )) /sizeof (struct virtio_blk_zone_descriptor ); +trace_virtio_blk_handle_zone_report (vdev, req, + offset >>BDRV_SECTOR_BITS , nr_zones); zone_size =sizeof (BlockZoneDescriptor) * nr_zones; data =g_malloc (sizeof (ZoneCmdData));
@@ -814,7 +817,9 @@ static void virtio_blk_zone_mgmt_complete(void *opaque, int ret) {VirtIOBlockReq *req = opaque;VirtIOBlock *s = req->dev; +VirtIODevice *vdev =VIRTIO_DEVICE (s);int8_t err_status =VIRTIO_BLK_S_OK ; +trace_virtio_blk_zone_mgmt_complete (vdev, req,ret);if (ret) { err_status =VIRTIO_BLK_S_ZONE_INVALID_CMD ;
@@ -841,6 +846,8 @@ static int virtio_blk_handle_zone_mgmt(VirtIOBlockReq *req, BlockZoneOp op)/* Entire drive capacity */ offset =0 ; len = capacity; +trace_virtio_blk_handle_zone_reset_all (vdev, req,0 , + bs->total_sectors); }else {if (bs->bl.zone_size > capacity - offset) {/* The zoned device allows the last smaller zone. */
@@ -848,6 +855,9 @@ static int virtio_blk_handle_zone_mgmt(VirtIOBlockReq *req, BlockZoneOp op) }else { len = bs->bl.zone_size; } +trace_virtio_blk_handle_zone_mgmt (vdev, req, op, + offset >>BDRV_SECTOR_BITS , + len >>BDRV_SECTOR_BITS ); }if (!check_zoned_request (s, offset, len, false, &err_status)) {
@@ -888,6 +898,7 @@ static void virtio_blk_zone_append_complete(void *opaque, int ret) err_status =VIRTIO_BLK_S_ZONE_INVALID_CMD ; goto out; } +trace_virtio_blk_zone_append_complete (vdev, req, append_sector, ret); out:aio_context_acquire (blk_get_aio_context (s->conf.conf.blk));
@@ -909,6 +920,7 @@ static int virtio_blk_handle_zone_append(VirtIOBlockReq *req,int64_t offset =virtio_ldq_p (vdev, &req->out.sector) <<BDRV_SECTOR_BITS ;int64_t len =iov_size (out_iov, out_num); +trace_virtio_blk_handle_zone_append (vdev, req, offset >>BDRV_SECTOR_BITS );if (!check_zoned_request (s, offset, len, true, &err_status)) { goto out; }
Signature · 1 line
2.39.2
PATCH v9 5/5 docs/zoned-storage:add zoned emulation use case
In reply to Sam LiAdd the documentation about the example of using virtio-blk driver to pass the zoned block devices through to the guest.
--- docs/devel/zoned-storage.rst | 17 +++++++++++++++++ 1 file changed, 17 insertions(+)
docs/devel/zoned-storage.rst +17 -0
@@ -41,3 +41,20 @@ APIs for zoned storage emulation or testing. For example, to test zone_report on a null_blk device using qemu-io is: $ path/to/qemu-io --image-opts -n driver=host_device,filename=/dev/nullb0 -c "zrp offset nr_zones" + +To expose the host's zoned block device through virtio-blk, the command line +can be (includes the -device parameter): + -blockdev node-name=drive0,driver=host_device,filename=/dev/nullb0, + cache.direct=on \ + -device virtio-blk-pci,drive=drive0 +Or only use the -drive parameter: + -driver driver=host_device,file=/dev/nullb0,if=virtio,cache.direct=on + +Additionally, QEMU has several ways of supporting zoned storage, including: +(1) Using virtio-scsi: --device scsi-block allows for the passing through of +SCSI ZBC devices, enabling the attachment of ZBC or ZAC HDDs to QEMU. +(2) PCI device pass-through: While NVMe ZNS emulation is available for testing +purposes, it cannot yet pass through a zoned device from the host. To pass on +the NVMe ZNS device to the guest, use VFIO PCI pass the entire NVMe PCI adapter +through to the guest. Likewise, an HDD HBA can be passed on to QEMU all HDDs +attached to the HBA.
Signature · 1 line
2.39.2
Quoted 6 lines · Sam Li
This patch adds zoned storage emulation to the virtio-blk driver. It implements the virtio-blk ZBD support standardization that is recently accepted by virtio-spec. The link to related commit is at
https://github.com/oasis-tcs/virtio-spec/commit/b4e8efa0fa6c8d844328090ad15db65af8d7d981
Quoted 8 lines
The Linux zoned device code that implemented by Dmitry Fomichev has been released at the latest Linux version v6.3-rc1.
Aside: adding zoned=on alike options to virtio-blk device will be considered in following-up plan.
Note: Sorry to send it again because of the previous incoherent patches caused by network error.
virtio bits look ok.
merge through block layer tree I'm guessing?
Quoted 74 lines
v9:
- address review comments
* add docs for zoned emulation use case [Matias]
* add the zoned feature bit to qmp monitor [Matias]
* add the version number for newly added configs of accounting [Markus]v8:
- address Stefan's review comments
* rm aio_context_acquire/release inhandle_req
* rename function return type
* renameBLOCK_ACCT_APPENDtoBLOCK_ACCT_ZONE_APPENDfor clarityv7:
- update headers to v6.3-rc1v6:
- address Stefan's review comments
* add accounting for zone append operation
* fixin_iovusage inhandle_request, error handling and typosv5:
- address Stefan's review comments
* restore the way writing zone append result to buffer
* fix error checking case and other errandsv4:
- change the way writing zone append request result to buffer
- change zone state, zone type value ofvirtio_blk_zone_descriptor
- add trace events for new zone APIsv3:
- useqemuio_from_bufferto write status bit [Stefan]
- avoid usingreq->elemdirectly [Stefan]
- fix error checkings and memory leak [Stefan]v2:
- change units of emulated zone op coresponding to block layer APIs
- modify error checking cases [Stefan, Damien]v1:
- add zoned storage emulationSam Li (5):
include: updatevirtio_blkheaders to v6.3-rc1
virtio-blk: add zoned storage emulation for zoned devices
block: add accounting for zone append operation
virtio-blk: add some trace events for zoned emulation docs/zoned-storage:add zoned emulation use caseblock/qapi-sysemu.c | 11 + block/qapi.c | 18 + docs/devel/zoned-storage.rst | 17 + hw/block/trace-events | 7 + hw/block/virtio-blk-common.c | 2 + hw/block/virtio-blk.c | 405 +++++++++++++++++++ hw/virtio/virtio-qmp.c | 2 + include/block/accounting.h | 1 + include/standard-headers/drm/drm_fourcc.h | 12 + include/standard-headers/linux/ethtool.h | 48 ++- include/standard-headers/linux/fuse.h | 45 ++- include/standard-headers/linux/pci_regs.h | 1 + include/standard-headers/linux/vhost_types.h | 2 + include/standard-headers/linux/virtio_blk.h | 105 +++++ linux-headers/asm-arm64/kvm.h | 1 + linux-headers/asm-x86/kvm.h | 34 +- linux-headers/linux/kvm.h | 9 + linux-headers/linux/vfio.h | 15 +- linux-headers/linux/vhost.h | 8 + qapi/block-core.json | 68 +++- qapi/block.json | 4 + 21 files changed, 794 insertions(+), 21 deletions(-)Signature · 1 line
2.39.2
Quoted 14 lines · Michael S. Tsirkin
Quoted 12 lines · Sam Li
This patch adds zoned storage emulation to the virtio-blk driver. It implements the virtio-blk ZBD support standardization that is recently accepted by virtio-spec. The link to related commit is at
https://github.com/oasis-tcs/virtio-spec/commit/b4e8efa0fa6c8d844328090ad15db65af8d7d981
The Linux zoned device code that implemented by Dmitry Fomichev has been released at the latest Linux version v6.3-rc1.
Aside: adding zoned=on alike options to virtio-blk device will be considered in following-up plan.
Quoted 8 lines
Quoted 2 lines
Note: Sorry to send it again because of the previous incoherent patches caused by network error.
virtio bits look ok.
Reviewed-by Michael S. Tsirkin <[email protected]>merge through block layer tree I'm guessing?
Sounds good. Thank you!
Stefan
Quoted 5 lines · Stefan Hajnoczi <[email protected]> 于2023年4月3日周一 20:18写道:
Quoted 3 lines · Michael S. Tsirkin
On Mon, Mar 27, 2023 at 10:45:48PM +0800, Sam Li wrote:
Quoted 7 lines
Quoted 5 lines
virtio bits look ok.
Reviewed-by Michael S. Tsirkin <[email protected]>merge through block layer tree I'm guessing?
Sounds good. Thank you!
Hi Stefan,
I've sent the v8 zone append write to the list where I move the wps field to BlockDriverState. It will make a small change the emulation code, which is in hw/block/virtio-blk.c of [2/5] virtio-blk: add zoned storage emulation for zoned devices:
- if (BDRV_ZT_IS_CONV(bs->bl.wps->wp[index])) {
+ if (BDRV_ZT_IS_CONV(bs->wps->wp[index])) {
Please let me know if you prefer a new version or not.
Thanks,
Sam
Quoted 16 lines · Sam Li
Quoted 5 lines · Stefan Hajnoczi <[email protected]> 于2023年4月3日周一 20:18写道:
Quoted 3 lines · Michael S. Tsirkin
On Mon, Mar 27, 2023 at 10:45:48PM +0800, Sam Li wrote:
Quoted 7 lines
Quoted 5 lines
virtio bits look ok.
Reviewed-by Michael S. Tsirkin <[email protected]>merge through block layer tree I'm guessing?
Sounds good. Thank you!
Hi Stefan,
Quoted 8 lines
I've sent the v8 zone append write to the list where I move the wps field to BlockDriverState. It will make a small change the emulation code, which is in
hw/block/virtio-blk.cof [2/5] virtio-blk: add zoned storage emulation for zoned devices:
- if (BDRV_ZT_IS_CONV(bs->bl.wps->wp[index])) {
+ if (BDRV_ZT_IS_CONV(bs->wps->wp[index])) {Please let me know if you prefer a new version or not.
Yes, please.
Stefan