Message ID | 20200406143505.133271-2-hare@suse.de (mailing list archive) |
---|---|
State | Superseded, archived |
Delegated to: | Mike Snitzer |
Headers | show |
Series | dm-zoned: metadata version 2 | expand |
On 2020/04/07 2:26, Hannes Reinecke wrote: > Instead of calculating the zone index by the offset within the > zone array store the index within the structure itself. > > Signed-off-by: Hannes Reinecke <hare@suse.de> > --- > drivers/md/dm-zoned-metadata.c | 3 ++- > drivers/md/dm-zoned.h | 3 +++ > 2 files changed, 5 insertions(+), 1 deletion(-) > > diff --git a/drivers/md/dm-zoned-metadata.c b/drivers/md/dm-zoned-metadata.c > index c8787560fa9f..afce594067fb 100644 > --- a/drivers/md/dm-zoned-metadata.c > +++ b/drivers/md/dm-zoned-metadata.c > @@ -189,7 +189,7 @@ struct dmz_metadata { > */ > unsigned int dmz_id(struct dmz_metadata *zmd, struct dm_zone *zone) > { > - return ((unsigned int)(zone - zmd->zones)); > + return zone->id; The zmd argument is now unused, and the helper does not make much sense anymore. Why not just drop it entirely ? Callers directly referencing the ->id field of a zone is simple and clear. > } > > sector_t dmz_start_sect(struct dmz_metadata *zmd, struct dm_zone *zone) > @@ -1119,6 +1119,7 @@ static int dmz_init_zone(struct blk_zone *blkz, unsigned int idx, void *data) > > INIT_LIST_HEAD(&zone->link); > atomic_set(&zone->refcount, 0); > + zone->id = idx; > zone->chunk = DMZ_MAP_UNMAPPED; > > switch (blkz->type) { > diff --git a/drivers/md/dm-zoned.h b/drivers/md/dm-zoned.h > index 884c0e586082..39d59898abbe 100644 > --- a/drivers/md/dm-zoned.h > +++ b/drivers/md/dm-zoned.h > @@ -87,6 +87,9 @@ struct dm_zone { > /* Zone activation reference count */ > atomic_t refcount; > > + /* Zone id */ > + unsigned int id; > + > /* Zone write pointer block (relative to the zone start block) */ > unsigned int wp_block; > >
On 4/7/20 3:47 AM, Damien Le Moal wrote: > On 2020/04/07 2:26, Hannes Reinecke wrote: >> Instead of calculating the zone index by the offset within the >> zone array store the index within the structure itself. >> >> Signed-off-by: Hannes Reinecke <hare@suse.de> >> --- >> drivers/md/dm-zoned-metadata.c | 3 ++- >> drivers/md/dm-zoned.h | 3 +++ >> 2 files changed, 5 insertions(+), 1 deletion(-) >> >> diff --git a/drivers/md/dm-zoned-metadata.c b/drivers/md/dm-zoned-metadata.c >> index c8787560fa9f..afce594067fb 100644 >> --- a/drivers/md/dm-zoned-metadata.c >> +++ b/drivers/md/dm-zoned-metadata.c >> @@ -189,7 +189,7 @@ struct dmz_metadata { >> */ >> unsigned int dmz_id(struct dmz_metadata *zmd, struct dm_zone *zone) >> { >> - return ((unsigned int)(zone - zmd->zones)); >> + return zone->id; > > The zmd argument is now unused, and the helper does not make much sense anymore. > Why not just drop it entirely ? Callers directly referencing the ->id field of a > zone is simple and clear. > >> } >> >> sector_t dmz_start_sect(struct dmz_metadata *zmd, struct dm_zone *zone) >> @@ -1119,6 +1119,7 @@ static int dmz_init_zone(struct blk_zone *blkz, unsigned int idx, void *data) >> >> INIT_LIST_HEAD(&zone->link); >> atomic_set(&zone->refcount, 0); >> + zone->id = idx; >> zone->chunk = DMZ_MAP_UNMAPPED; >> >> switch (blkz->type) { >> diff --git a/drivers/md/dm-zoned.h b/drivers/md/dm-zoned.h >> index 884c0e586082..39d59898abbe 100644 >> --- a/drivers/md/dm-zoned.h >> +++ b/drivers/md/dm-zoned.h >> @@ -87,6 +87,9 @@ struct dm_zone { >> /* Zone activation reference count */ >> atomic_t refcount; >> >> + /* Zone id */ >> + unsigned int id; >> + >> /* Zone write pointer block (relative to the zone start block) */ >> unsigned int wp_block; >> >> > > Indeed, you are right. Will be doing so for the next round. Cheers, Hannes
diff --git a/drivers/md/dm-zoned-metadata.c b/drivers/md/dm-zoned-metadata.c index c8787560fa9f..afce594067fb 100644 --- a/drivers/md/dm-zoned-metadata.c +++ b/drivers/md/dm-zoned-metadata.c @@ -189,7 +189,7 @@ struct dmz_metadata { */ unsigned int dmz_id(struct dmz_metadata *zmd, struct dm_zone *zone) { - return ((unsigned int)(zone - zmd->zones)); + return zone->id; } sector_t dmz_start_sect(struct dmz_metadata *zmd, struct dm_zone *zone) @@ -1119,6 +1119,7 @@ static int dmz_init_zone(struct blk_zone *blkz, unsigned int idx, void *data) INIT_LIST_HEAD(&zone->link); atomic_set(&zone->refcount, 0); + zone->id = idx; zone->chunk = DMZ_MAP_UNMAPPED; switch (blkz->type) { diff --git a/drivers/md/dm-zoned.h b/drivers/md/dm-zoned.h index 884c0e586082..39d59898abbe 100644 --- a/drivers/md/dm-zoned.h +++ b/drivers/md/dm-zoned.h @@ -87,6 +87,9 @@ struct dm_zone { /* Zone activation reference count */ atomic_t refcount; + /* Zone id */ + unsigned int id; + /* Zone write pointer block (relative to the zone start block) */ unsigned int wp_block;
Instead of calculating the zone index by the offset within the zone array store the index within the structure itself. Signed-off-by: Hannes Reinecke <hare@suse.de> --- drivers/md/dm-zoned-metadata.c | 3 ++- drivers/md/dm-zoned.h | 3 +++ 2 files changed, 5 insertions(+), 1 deletion(-)