Message ID | 20200327071459.67796-4-hare@suse.de (mailing list archive) |
---|---|
State | Superseded, archived |
Delegated to: | Mike Snitzer |
Headers | show |
Series | dm-zoned: Metadata V2 | expand |
On 2020/03/27 16:15, Hannes Reinecke wrote: > Add 'V2' metadata which includes UUIDs for the dmz set and for > the device itself. > > Signed-off-by: Hannes Reinecke <hare@suse.de> Looks good. Reviewed-by: Damien Le Moal <damien.lemoal@wdc.com> > --- > drivers/md/dm-zoned-metadata.c | 80 +++++++++++++++++++++++++++++++++--------- > drivers/md/dm-zoned-target.c | 2 +- > 2 files changed, 64 insertions(+), 18 deletions(-) > > diff --git a/drivers/md/dm-zoned-metadata.c b/drivers/md/dm-zoned-metadata.c > index dc1d17bc3bbb..026f285fba33 100644 > --- a/drivers/md/dm-zoned-metadata.c > +++ b/drivers/md/dm-zoned-metadata.c > @@ -16,7 +16,8 @@ > /* > * Metadata version. > */ > -#define DMZ_META_VER 1 > +#define DMZ_META_COMPAT_VER 1 > +#define DMZ_META_VER 2 > > /* > * On-disk super block magic. > @@ -69,8 +70,17 @@ struct dmz_super { > /* Checksum */ > __le32 crc; /* 48 */ > > - /* Padding to full 512B sector */ > - u8 reserved[464]; /* 512 */ > + /* DM-Zoned label */ > + u8 dmz_label[32]; /* 80 */ > + > + /* DM-Zoned UUID */ > + u8 dmz_uuid[16]; /* 96 */ > + > + /* Device UUID */ > + u8 dev_uuid[16]; /* 112 */ > + > + /* Padding to full 512B - CRC sector */ > + u8 reserved[400]; /* 512 */ > }; > > /* > @@ -133,6 +143,10 @@ struct dmz_sb { > struct dmz_metadata { > struct dmz_dev *dev; > > + char dmz_label[BDEVNAME_SIZE]; > + uuid_t dmz_uuid; > + uuid_t dev_uuid; > + > sector_t zone_bitmap_size; > unsigned int zone_nr_bitmap_blocks; > unsigned int zone_bits_per_mblk; > @@ -659,7 +673,14 @@ static int dmz_write_sb(struct dmz_metadata *zmd, unsigned int set) > int ret; > > sb->magic = cpu_to_le32(DMZ_MAGIC); > - sb->version = cpu_to_le32(DMZ_META_VER); > + > + if (!uuid_is_null(&zmd->dmz_uuid)) { > + sb->version = cpu_to_le32(DMZ_META_VER); > + uuid_copy((uuid_t *)sb->dmz_uuid, &zmd->dmz_uuid); > + memcpy(sb->dmz_label, zmd->dmz_label, BDEVNAME_SIZE); > + uuid_copy((uuid_t *)sb->dev_uuid, &zmd->dev_uuid); > + } else > + sb->version = cpu_to_le32(DMZ_META_COMPAT_VER); > > sb->gen = cpu_to_le64(sb_gen); > > @@ -848,28 +869,29 @@ static int dmz_check_sb(struct dmz_metadata *zmd, struct dmz_super *sb) > { > unsigned int nr_meta_zones, nr_data_zones; > struct dmz_dev *dev = zmd->dev; > - u32 crc, stored_crc; > + u32 crc, stored_crc, dmz_version; > u64 gen; > > - gen = le64_to_cpu(sb->gen); > - stored_crc = le32_to_cpu(sb->crc); > - sb->crc = 0; > - crc = crc32_le(gen, (unsigned char *)sb, DMZ_BLOCK_SIZE); > - if (crc != stored_crc) { > - dmz_dev_err(dev, "Invalid checksum (needed 0x%08x, got 0x%08x)", > - crc, stored_crc); > - return -ENXIO; > - } > - > if (le32_to_cpu(sb->magic) != DMZ_MAGIC) { > dmz_dev_err(dev, "Invalid meta magic (needed 0x%08x, got 0x%08x)", > DMZ_MAGIC, le32_to_cpu(sb->magic)); > return -ENXIO; > } > > - if (le32_to_cpu(sb->version) != DMZ_META_VER) { > + dmz_version = le32_to_cpu(sb->version); > + if (dmz_version > DMZ_META_VER) { > dmz_dev_err(dev, "Invalid meta version (needed %d, got %d)", > - DMZ_META_VER, le32_to_cpu(sb->version)); > + DMZ_META_VER, dmz_version); > + return -ENXIO; > + } > + > + gen = le64_to_cpu(sb->gen); > + stored_crc = le32_to_cpu(sb->crc); > + sb->crc = 0; > + crc = crc32_le(gen, (unsigned char *)sb, DMZ_BLOCK_SIZE); > + if (crc != stored_crc) { > + dmz_dev_err(dev, "Invalid checksum (needed 0x%08x, got 0x%08x)", > + crc, stored_crc); > return -ENXIO; > } > > @@ -895,6 +917,21 @@ static int dmz_check_sb(struct dmz_metadata *zmd, struct dmz_super *sb) > return -ENXIO; > } > > + if (dmz_version == DMZ_META_VER) { > + if (uuid_is_null((uuid_t *)sb->dmz_uuid)) { > + dmz_dev_err(dev, "NULL DM-Zoned uuid"); > + return -ENXIO; > + } > + uuid_copy(&zmd->dmz_uuid, (uuid_t *)sb->dmz_uuid); > + memcpy(zmd->dmz_label, sb->dmz_label, BDEVNAME_SIZE); > + if (uuid_is_null((uuid_t *)sb->dev_uuid)) { > + dmz_dev_err(dev, "NULL device uuid"); > + return -ENXIO; > + } > + uuid_copy(&zmd->dev_uuid, (uuid_t *)sb->dev_uuid); > + > + } > + > /* OK */ > zmd->nr_meta_blocks = le32_to_cpu(sb->nr_meta_blocks); > zmd->nr_reserved_seq = le32_to_cpu(sb->nr_reserved_seq); > @@ -2460,9 +2497,18 @@ int dmz_ctr_metadata(struct dmz_dev *dev, struct dmz_metadata **metadata) > goto err; > } > > + dmz_dev_info(dev, "DM-Zoned version %d", > + uuid_is_null(&zmd->dmz_uuid) ? > + DMZ_META_COMPAT_VER : DMZ_META_VER); > + if (!uuid_is_null(&zmd->dmz_uuid)) > + dmz_dev_info(dev, "DM UUID %pUl", &zmd->dmz_uuid); > + if (strlen(zmd->dmz_label)) > + dmz_dev_info(dev, "DM Label %s", zmd->dmz_label); > dmz_dev_info(dev, "Host-%s zoned block device", > bdev_zoned_model(dev->bdev) == BLK_ZONED_HA ? > "aware" : "managed"); > + if (!uuid_is_null(&zmd->dev_uuid)) > + dmz_dev_info(dev, " uuid %pUl", &zmd->dev_uuid); > dmz_dev_info(dev, " %llu 512-byte logical sectors", > (u64)dev->capacity); > dmz_dev_info(dev, " %u zones of %llu 512-byte logical sectors", > diff --git a/drivers/md/dm-zoned-target.c b/drivers/md/dm-zoned-target.c > index 44e30a7de8b9..7ec9dde24516 100644 > --- a/drivers/md/dm-zoned-target.c > +++ b/drivers/md/dm-zoned-target.c > @@ -1008,7 +1008,7 @@ static int dmz_message(struct dm_target *ti, unsigned int argc, char **argv, > > static struct target_type dmz_type = { > .name = "zoned", > - .version = {1, 1, 0}, > + .version = {1, 2, 0}, > .features = DM_TARGET_SINGLETON | DM_TARGET_ZONED_HM, > .module = THIS_MODULE, > .ctr = dmz_ctr, >
On 3/27/20 3:14 PM, Hannes Reinecke wrote: > Add 'V2' metadata which includes UUIDs for the dmz set and for > the device itself. > > Signed-off-by: Hannes Reinecke <hare@suse.de> Reviewed-by: Bob Liu <bob.liu@oracle.com> > --- > drivers/md/dm-zoned-metadata.c | 80 +++++++++++++++++++++++++++++++++--------- > drivers/md/dm-zoned-target.c | 2 +- > 2 files changed, 64 insertions(+), 18 deletions(-) > > diff --git a/drivers/md/dm-zoned-metadata.c b/drivers/md/dm-zoned-metadata.c > index dc1d17bc3bbb..026f285fba33 100644 > --- a/drivers/md/dm-zoned-metadata.c > +++ b/drivers/md/dm-zoned-metadata.c > @@ -16,7 +16,8 @@ > /* > * Metadata version. > */ > -#define DMZ_META_VER 1 > +#define DMZ_META_COMPAT_VER 1 > +#define DMZ_META_VER 2 > > /* > * On-disk super block magic. > @@ -69,8 +70,17 @@ struct dmz_super { > /* Checksum */ > __le32 crc; /* 48 */ > > - /* Padding to full 512B sector */ > - u8 reserved[464]; /* 512 */ > + /* DM-Zoned label */ > + u8 dmz_label[32]; /* 80 */ > + > + /* DM-Zoned UUID */ > + u8 dmz_uuid[16]; /* 96 */ > + > + /* Device UUID */ > + u8 dev_uuid[16]; /* 112 */ > + > + /* Padding to full 512B - CRC sector */ > + u8 reserved[400]; /* 512 */ > }; > > /* > @@ -133,6 +143,10 @@ struct dmz_sb { > struct dmz_metadata { > struct dmz_dev *dev; > > + char dmz_label[BDEVNAME_SIZE]; > + uuid_t dmz_uuid; > + uuid_t dev_uuid; > + > sector_t zone_bitmap_size; > unsigned int zone_nr_bitmap_blocks; > unsigned int zone_bits_per_mblk; > @@ -659,7 +673,14 @@ static int dmz_write_sb(struct dmz_metadata *zmd, unsigned int set) > int ret; > > sb->magic = cpu_to_le32(DMZ_MAGIC); > - sb->version = cpu_to_le32(DMZ_META_VER); > + > + if (!uuid_is_null(&zmd->dmz_uuid)) { > + sb->version = cpu_to_le32(DMZ_META_VER); > + uuid_copy((uuid_t *)sb->dmz_uuid, &zmd->dmz_uuid); > + memcpy(sb->dmz_label, zmd->dmz_label, BDEVNAME_SIZE); > + uuid_copy((uuid_t *)sb->dev_uuid, &zmd->dev_uuid); > + } else > + sb->version = cpu_to_le32(DMZ_META_COMPAT_VER); > > sb->gen = cpu_to_le64(sb_gen); > > @@ -848,28 +869,29 @@ static int dmz_check_sb(struct dmz_metadata *zmd, struct dmz_super *sb) > { > unsigned int nr_meta_zones, nr_data_zones; > struct dmz_dev *dev = zmd->dev; > - u32 crc, stored_crc; > + u32 crc, stored_crc, dmz_version; > u64 gen; > > - gen = le64_to_cpu(sb->gen); > - stored_crc = le32_to_cpu(sb->crc); > - sb->crc = 0; > - crc = crc32_le(gen, (unsigned char *)sb, DMZ_BLOCK_SIZE); > - if (crc != stored_crc) { > - dmz_dev_err(dev, "Invalid checksum (needed 0x%08x, got 0x%08x)", > - crc, stored_crc); > - return -ENXIO; > - } > - > if (le32_to_cpu(sb->magic) != DMZ_MAGIC) { > dmz_dev_err(dev, "Invalid meta magic (needed 0x%08x, got 0x%08x)", > DMZ_MAGIC, le32_to_cpu(sb->magic)); > return -ENXIO; > } > > - if (le32_to_cpu(sb->version) != DMZ_META_VER) { > + dmz_version = le32_to_cpu(sb->version); > + if (dmz_version > DMZ_META_VER) { > dmz_dev_err(dev, "Invalid meta version (needed %d, got %d)", > - DMZ_META_VER, le32_to_cpu(sb->version)); > + DMZ_META_VER, dmz_version); > + return -ENXIO; > + } > + > + gen = le64_to_cpu(sb->gen); > + stored_crc = le32_to_cpu(sb->crc); > + sb->crc = 0; > + crc = crc32_le(gen, (unsigned char *)sb, DMZ_BLOCK_SIZE); > + if (crc != stored_crc) { > + dmz_dev_err(dev, "Invalid checksum (needed 0x%08x, got 0x%08x)", > + crc, stored_crc); > return -ENXIO; > } > > @@ -895,6 +917,21 @@ static int dmz_check_sb(struct dmz_metadata *zmd, struct dmz_super *sb) > return -ENXIO; > } > > + if (dmz_version == DMZ_META_VER) { > + if (uuid_is_null((uuid_t *)sb->dmz_uuid)) { > + dmz_dev_err(dev, "NULL DM-Zoned uuid"); > + return -ENXIO; > + } > + uuid_copy(&zmd->dmz_uuid, (uuid_t *)sb->dmz_uuid); > + memcpy(zmd->dmz_label, sb->dmz_label, BDEVNAME_SIZE); > + if (uuid_is_null((uuid_t *)sb->dev_uuid)) { > + dmz_dev_err(dev, "NULL device uuid"); > + return -ENXIO; > + } > + uuid_copy(&zmd->dev_uuid, (uuid_t *)sb->dev_uuid); > + > + } > + > /* OK */ > zmd->nr_meta_blocks = le32_to_cpu(sb->nr_meta_blocks); > zmd->nr_reserved_seq = le32_to_cpu(sb->nr_reserved_seq); > @@ -2460,9 +2497,18 @@ int dmz_ctr_metadata(struct dmz_dev *dev, struct dmz_metadata **metadata) > goto err; > } > > + dmz_dev_info(dev, "DM-Zoned version %d", > + uuid_is_null(&zmd->dmz_uuid) ? > + DMZ_META_COMPAT_VER : DMZ_META_VER); > + if (!uuid_is_null(&zmd->dmz_uuid)) > + dmz_dev_info(dev, "DM UUID %pUl", &zmd->dmz_uuid); > + if (strlen(zmd->dmz_label)) > + dmz_dev_info(dev, "DM Label %s", zmd->dmz_label); > dmz_dev_info(dev, "Host-%s zoned block device", > bdev_zoned_model(dev->bdev) == BLK_ZONED_HA ? > "aware" : "managed"); > + if (!uuid_is_null(&zmd->dev_uuid)) > + dmz_dev_info(dev, " uuid %pUl", &zmd->dev_uuid); > dmz_dev_info(dev, " %llu 512-byte logical sectors", > (u64)dev->capacity); > dmz_dev_info(dev, " %u zones of %llu 512-byte logical sectors", > diff --git a/drivers/md/dm-zoned-target.c b/drivers/md/dm-zoned-target.c > index 44e30a7de8b9..7ec9dde24516 100644 > --- a/drivers/md/dm-zoned-target.c > +++ b/drivers/md/dm-zoned-target.c > @@ -1008,7 +1008,7 @@ static int dmz_message(struct dm_target *ti, unsigned int argc, char **argv, > > static struct target_type dmz_type = { > .name = "zoned", > - .version = {1, 1, 0}, > + .version = {1, 2, 0}, > .features = DM_TARGET_SINGLETON | DM_TARGET_ZONED_HM, > .module = THIS_MODULE, > .ctr = dmz_ctr, > -- dm-devel mailing list dm-devel@redhat.com https://www.redhat.com/mailman/listinfo/dm-devel
I'm worried about hardcoding uuid members as u8[16]. May I ask why you're not using uuid_t to define it in the on-disk structure? It would save the casting of the uuid members to (uuid_t *) every time you use a uuid.h function. Possibly it is customary to use only raw datatypes on disk rather than opaque types like uuid_t, I'm not sure. But in that case, perhaps using the named constant UUID_SIZE instead of 16 would make the meaning clearer? Thanks! -- dm-devel mailing list dm-devel@redhat.com https://www.redhat.com/mailman/listinfo/dm-devel
On 4/2/20 4:53 PM, John Dorminy wrote: > I'm worried about hardcoding uuid members as u8[16]. > > May I ask why you're not using uuid_t to define it in the on-disk > structure? It would save the casting of the uuid members to (uuid_t *) > every time you use a uuid.h function. > > Possibly it is customary to use only raw datatypes on disk rather than > opaque types like uuid_t, I'm not sure. But in that case, perhaps using > the named constant UUID_SIZE instead of 16 would make the meaning clearer? > I prefer to use absolute types (like __u8) when describing the on-disk format. When using opaque types like uuid_t there always is the risk that the internal representation will change, leading to an involuntary change of the on-disk format structure and subsequent compability issues. Cheers, Hannes
That does make sense. May I request, then, using UUID_SIZE instead of 16? Perhaps with a compile-time assertion that UUID_SIZE has not change from 16? On Thu, Apr 2, 2020 at 11:10 AM Hannes Reinecke <hare@suse.de> wrote: > On 4/2/20 4:53 PM, John Dorminy wrote: > > I'm worried about hardcoding uuid members as u8[16]. > > > > May I ask why you're not using uuid_t to define it in the on-disk > > structure? It would save the casting of the uuid members to (uuid_t *) > > every time you use a uuid.h function. > > > > Possibly it is customary to use only raw datatypes on disk rather than > > opaque types like uuid_t, I'm not sure. But in that case, perhaps using > > the named constant UUID_SIZE instead of 16 would make the meaning > clearer? > > > I prefer to use absolute types (like __u8) when describing the on-disk > format. > When using opaque types like uuid_t there always is the risk that the > internal representation will change, leading to an involuntary change of > the on-disk format structure and subsequent compability issues. > > Cheers, > > Hannes > -- > Dr. Hannes Reinecke Teamlead Storage & Networking > hare@suse.de +49 911 74053 688 > SUSE Software Solutions GmbH, Maxfeldstr. 5, 90409 Nürnberg > HRB 36809 (AG Nürnberg), Geschäftsführer: Felix Imendörffer > > -- dm-devel mailing list dm-devel@redhat.com https://www.redhat.com/mailman/listinfo/dm-devel
Actually, I take that back. If it is a worry that the internal representation will change, it seems also unsafe to be casting the sixteen bytes as a uuid_t when copying into them with uuid_copy(). If the internal representation changed to add a new field, then there would be a buffer overrun when using uuid_copy(). If the internal representation changed the order of the bytes, uuid_copy() would propagate that to the on-disk structure and yield compatibility issues. Perhaps it would be safer to store the UUIDs on disk as a string. Or add to uuid.[ch] a function to get the raw bytes in a fixed order suitable for storing on disk? On Thu, Apr 2, 2020 at 11:52 AM John Dorminy <jdorminy@redhat.com> wrote: > That does make sense. May I request, then, using UUID_SIZE instead of 16? > Perhaps with a compile-time assertion that UUID_SIZE has not change from 16? > > On Thu, Apr 2, 2020 at 11:10 AM Hannes Reinecke <hare@suse.de> wrote: > >> On 4/2/20 4:53 PM, John Dorminy wrote: >> > I'm worried about hardcoding uuid members as u8[16]. >> > >> > May I ask why you're not using uuid_t to define it in the on-disk >> > structure? It would save the casting of the uuid members to (uuid_t *) >> > every time you use a uuid.h function. >> > >> > Possibly it is customary to use only raw datatypes on disk rather than >> > opaque types like uuid_t, I'm not sure. But in that case, perhaps using >> > the named constant UUID_SIZE instead of 16 would make the meaning >> clearer? >> > >> I prefer to use absolute types (like __u8) when describing the on-disk >> format. >> When using opaque types like uuid_t there always is the risk that the >> internal representation will change, leading to an involuntary change of >> the on-disk format structure and subsequent compability issues. >> >> Cheers, >> >> Hannes >> -- >> Dr. Hannes Reinecke Teamlead Storage & Networking >> hare@suse.de +49 911 74053 688 >> SUSE Software Solutions GmbH, Maxfeldstr. 5, 90409 Nürnberg >> HRB 36809 (AG Nürnberg), Geschäftsführer: Felix Imendörffer >> >> -- dm-devel mailing list dm-devel@redhat.com https://www.redhat.com/mailman/listinfo/dm-devel
On 2020/04/03 5:01, John Dorminy wrote: > Actually, I take that back. If it is a worry that the internal representation > will change, it seems also unsafe to be casting the sixteen bytes as a uuid_t > when copying into them with uuid_copy(). If the internal representation changed > to add a new field, then there would be a buffer overrun when using uuid_copy(). > If the internal representation changed the order of the bytes, uuid_copy() would > propagate that to the on-disk structure and yield compatibility issues. > > Perhaps it would be safer to store the UUIDs on disk as a string. Or add to > uuid.[ch] a function to get the raw bytes in a fixed order suitable for storing > on disk? Please have a look at file systems on-disk metadata definition and checks. There are plenty of examples of how UUIDs are handled. For instance, XFS has in fs/xfs/libxfs/xfs_format.h: typedef struct xfs_dsb { ... uuid_t sb_uuid; /* user-visible file system unique id */ ... } For the on-disk super block UUID and the same for the in-memory version. And you can see code like: memcpy(&to->sb_uuid, &from->sb_uuid, sizeof(to->sb_uuid)); uuid_copy(&to->sb_meta_uuid, &from->sb_uuid); and checks such as: BUILD_BUG_ON(sizeof(geo->uuid) != sizeof(sbp->sb_uuid)); for some UUID declared with: unsigned char uuid[16]; /* unique id of the filesystem */ (struct xfs_fsop_geom_v1 in fs/xfs/libxfs/xfs_fs.h. On the other hand, f2fs defines its on-disk and in-memory super block UUID as: __u8 uuid[16]; /* 128-bit uuid for volume */ And copies it with: memcpy(&sb->s_uuid, raw_super->uuid, sizeof(raw_super->uuid)); The general pattern is: * For UUIDs defined as uuid_t, use uuid_copy() or memcpy() * For UUIDs defined as an array of bytes or char, use memcpy() * Add BUILD_BUG_ON() checks when mixing both definitions. There is no need to go as far as using a string for the UUID.
diff --git a/drivers/md/dm-zoned-metadata.c b/drivers/md/dm-zoned-metadata.c index dc1d17bc3bbb..026f285fba33 100644 --- a/drivers/md/dm-zoned-metadata.c +++ b/drivers/md/dm-zoned-metadata.c @@ -16,7 +16,8 @@ /* * Metadata version. */ -#define DMZ_META_VER 1 +#define DMZ_META_COMPAT_VER 1 +#define DMZ_META_VER 2 /* * On-disk super block magic. @@ -69,8 +70,17 @@ struct dmz_super { /* Checksum */ __le32 crc; /* 48 */ - /* Padding to full 512B sector */ - u8 reserved[464]; /* 512 */ + /* DM-Zoned label */ + u8 dmz_label[32]; /* 80 */ + + /* DM-Zoned UUID */ + u8 dmz_uuid[16]; /* 96 */ + + /* Device UUID */ + u8 dev_uuid[16]; /* 112 */ + + /* Padding to full 512B - CRC sector */ + u8 reserved[400]; /* 512 */ }; /* @@ -133,6 +143,10 @@ struct dmz_sb { struct dmz_metadata { struct dmz_dev *dev; + char dmz_label[BDEVNAME_SIZE]; + uuid_t dmz_uuid; + uuid_t dev_uuid; + sector_t zone_bitmap_size; unsigned int zone_nr_bitmap_blocks; unsigned int zone_bits_per_mblk; @@ -659,7 +673,14 @@ static int dmz_write_sb(struct dmz_metadata *zmd, unsigned int set) int ret; sb->magic = cpu_to_le32(DMZ_MAGIC); - sb->version = cpu_to_le32(DMZ_META_VER); + + if (!uuid_is_null(&zmd->dmz_uuid)) { + sb->version = cpu_to_le32(DMZ_META_VER); + uuid_copy((uuid_t *)sb->dmz_uuid, &zmd->dmz_uuid); + memcpy(sb->dmz_label, zmd->dmz_label, BDEVNAME_SIZE); + uuid_copy((uuid_t *)sb->dev_uuid, &zmd->dev_uuid); + } else + sb->version = cpu_to_le32(DMZ_META_COMPAT_VER); sb->gen = cpu_to_le64(sb_gen); @@ -848,28 +869,29 @@ static int dmz_check_sb(struct dmz_metadata *zmd, struct dmz_super *sb) { unsigned int nr_meta_zones, nr_data_zones; struct dmz_dev *dev = zmd->dev; - u32 crc, stored_crc; + u32 crc, stored_crc, dmz_version; u64 gen; - gen = le64_to_cpu(sb->gen); - stored_crc = le32_to_cpu(sb->crc); - sb->crc = 0; - crc = crc32_le(gen, (unsigned char *)sb, DMZ_BLOCK_SIZE); - if (crc != stored_crc) { - dmz_dev_err(dev, "Invalid checksum (needed 0x%08x, got 0x%08x)", - crc, stored_crc); - return -ENXIO; - } - if (le32_to_cpu(sb->magic) != DMZ_MAGIC) { dmz_dev_err(dev, "Invalid meta magic (needed 0x%08x, got 0x%08x)", DMZ_MAGIC, le32_to_cpu(sb->magic)); return -ENXIO; } - if (le32_to_cpu(sb->version) != DMZ_META_VER) { + dmz_version = le32_to_cpu(sb->version); + if (dmz_version > DMZ_META_VER) { dmz_dev_err(dev, "Invalid meta version (needed %d, got %d)", - DMZ_META_VER, le32_to_cpu(sb->version)); + DMZ_META_VER, dmz_version); + return -ENXIO; + } + + gen = le64_to_cpu(sb->gen); + stored_crc = le32_to_cpu(sb->crc); + sb->crc = 0; + crc = crc32_le(gen, (unsigned char *)sb, DMZ_BLOCK_SIZE); + if (crc != stored_crc) { + dmz_dev_err(dev, "Invalid checksum (needed 0x%08x, got 0x%08x)", + crc, stored_crc); return -ENXIO; } @@ -895,6 +917,21 @@ static int dmz_check_sb(struct dmz_metadata *zmd, struct dmz_super *sb) return -ENXIO; } + if (dmz_version == DMZ_META_VER) { + if (uuid_is_null((uuid_t *)sb->dmz_uuid)) { + dmz_dev_err(dev, "NULL DM-Zoned uuid"); + return -ENXIO; + } + uuid_copy(&zmd->dmz_uuid, (uuid_t *)sb->dmz_uuid); + memcpy(zmd->dmz_label, sb->dmz_label, BDEVNAME_SIZE); + if (uuid_is_null((uuid_t *)sb->dev_uuid)) { + dmz_dev_err(dev, "NULL device uuid"); + return -ENXIO; + } + uuid_copy(&zmd->dev_uuid, (uuid_t *)sb->dev_uuid); + + } + /* OK */ zmd->nr_meta_blocks = le32_to_cpu(sb->nr_meta_blocks); zmd->nr_reserved_seq = le32_to_cpu(sb->nr_reserved_seq); @@ -2460,9 +2497,18 @@ int dmz_ctr_metadata(struct dmz_dev *dev, struct dmz_metadata **metadata) goto err; } + dmz_dev_info(dev, "DM-Zoned version %d", + uuid_is_null(&zmd->dmz_uuid) ? + DMZ_META_COMPAT_VER : DMZ_META_VER); + if (!uuid_is_null(&zmd->dmz_uuid)) + dmz_dev_info(dev, "DM UUID %pUl", &zmd->dmz_uuid); + if (strlen(zmd->dmz_label)) + dmz_dev_info(dev, "DM Label %s", zmd->dmz_label); dmz_dev_info(dev, "Host-%s zoned block device", bdev_zoned_model(dev->bdev) == BLK_ZONED_HA ? "aware" : "managed"); + if (!uuid_is_null(&zmd->dev_uuid)) + dmz_dev_info(dev, " uuid %pUl", &zmd->dev_uuid); dmz_dev_info(dev, " %llu 512-byte logical sectors", (u64)dev->capacity); dmz_dev_info(dev, " %u zones of %llu 512-byte logical sectors", diff --git a/drivers/md/dm-zoned-target.c b/drivers/md/dm-zoned-target.c index 44e30a7de8b9..7ec9dde24516 100644 --- a/drivers/md/dm-zoned-target.c +++ b/drivers/md/dm-zoned-target.c @@ -1008,7 +1008,7 @@ static int dmz_message(struct dm_target *ti, unsigned int argc, char **argv, static struct target_type dmz_type = { .name = "zoned", - .version = {1, 1, 0}, + .version = {1, 2, 0}, .features = DM_TARGET_SINGLETON | DM_TARGET_ZONED_HM, .module = THIS_MODULE, .ctr = dmz_ctr,
Add 'V2' metadata which includes UUIDs for the dmz set and for the device itself. Signed-off-by: Hannes Reinecke <hare@suse.de> --- drivers/md/dm-zoned-metadata.c | 80 +++++++++++++++++++++++++++++++++--------- drivers/md/dm-zoned-target.c | 2 +- 2 files changed, 64 insertions(+), 18 deletions(-)