Stefan Hajnoczi <stefa...@redhat.com> 于2023年8月21日周一 21:31写道: > > On Mon, Aug 14, 2023 at 04:58:00PM +0800, Sam Li wrote: > > diff --git a/block/qcow2.h b/block/qcow2.h > > index f789ce3ae0..3694c8d217 100644 > > --- a/block/qcow2.h > > +++ b/block/qcow2.h > > @@ -236,6 +236,20 @@ typedef struct Qcow2CryptoHeaderExtension { > > uint64_t length; > > } QEMU_PACKED Qcow2CryptoHeaderExtension; > > > > +typedef struct Qcow2ZonedHeaderExtension { > > + /* Zoned device attributes */ > > + uint8_t zoned_profile; > > + uint8_t zoned; > > + uint16_t reserved16; > > + uint32_t zone_size; > > + uint32_t zone_capacity; > > Should zone capacity be stored individually for each zone (alongside the > write pointer and other per zone metadata) instead of as a global value > for all zones? My understanding is that NVMe ZNS does not have a global > value and each zone could have a different zone capacity value. > > > + uint32_t nr_zones; > > Is this field necessary since it can be derived from other image > options: nr_zones = DIV_ROUND_UP(total_length, zone_capacity)?
Yes. The bs->total_sectors in refresh_limits is zero. Keeping a persistent nr_zones helps assigning right value instead of zero. The process is roughly like this: *_qcow2_create: calculate nr_zones and write it to zoned_header -> *_qcow2_update_header: update nr_zones -> *_qcow2_read_extensions: read nr_zones in zoned_header to Qcow2State and check if right (valid total size here) -> *_refresh_limits(): set bl.nr_zones to zoned_header.nr_zones Sam