Commit 912e8875 authored by Damien Le Moal's avatar Damien Le Moal Committed by Mike Snitzer

dm: Introduce dm_report_zones()

To simplify the implementation of the report_zones operation of a zoned
target, introduce the function dm_report_zones() to set a target
mapping start sector in struct dm_report_zones_args and call
blkdev_report_zones(). This new function is exported and the report
zones callback function dm_report_zones_cb() is not.

dm-linear, dm-flakey and dm-crypt are modified to use dm_report_zones().
Signed-off-by: default avatarDamien Le Moal <damien.lemoal@wdc.com>
Reviewed-by: default avatarJohannes Thumshirn <johannes.thumshirn@wdc.com>
Reviewed-by: default avatarHannes Reinecke <hare@suse.de>
Reviewed-by: default avatarHimanshu Madhani <himanshu.madhani@oracle.com>
Signed-off-by: default avatarMike Snitzer <snitzer@redhat.com>
parent 7fc18728
...@@ -3138,11 +3138,10 @@ static int crypt_report_zones(struct dm_target *ti, ...@@ -3138,11 +3138,10 @@ static int crypt_report_zones(struct dm_target *ti,
struct dm_report_zones_args *args, unsigned int nr_zones) struct dm_report_zones_args *args, unsigned int nr_zones)
{ {
struct crypt_config *cc = ti->private; struct crypt_config *cc = ti->private;
sector_t sector = cc->start + dm_target_offset(ti, args->next_sector);
args->start = cc->start; return dm_report_zones(cc->dev->bdev, cc->start,
return blkdev_report_zones(cc->dev->bdev, sector, nr_zones, cc->start + dm_target_offset(ti, args->next_sector),
dm_report_zones_cb, args); args, nr_zones);
} }
#else #else
#define crypt_report_zones NULL #define crypt_report_zones NULL
......
...@@ -463,11 +463,10 @@ static int flakey_report_zones(struct dm_target *ti, ...@@ -463,11 +463,10 @@ static int flakey_report_zones(struct dm_target *ti,
struct dm_report_zones_args *args, unsigned int nr_zones) struct dm_report_zones_args *args, unsigned int nr_zones)
{ {
struct flakey_c *fc = ti->private; struct flakey_c *fc = ti->private;
sector_t sector = flakey_map_sector(ti, args->next_sector);
args->start = fc->start; return dm_report_zones(fc->dev->bdev, fc->start,
return blkdev_report_zones(fc->dev->bdev, sector, nr_zones, flakey_map_sector(ti, args->next_sector),
dm_report_zones_cb, args); args, nr_zones);
} }
#else #else
#define flakey_report_zones NULL #define flakey_report_zones NULL
......
...@@ -140,11 +140,10 @@ static int linear_report_zones(struct dm_target *ti, ...@@ -140,11 +140,10 @@ static int linear_report_zones(struct dm_target *ti,
struct dm_report_zones_args *args, unsigned int nr_zones) struct dm_report_zones_args *args, unsigned int nr_zones)
{ {
struct linear_c *lc = ti->private; struct linear_c *lc = ti->private;
sector_t sector = linear_map_sector(ti, args->next_sector);
args->start = lc->start; return dm_report_zones(lc->dev->bdev, lc->start,
return blkdev_report_zones(lc->dev->bdev, sector, nr_zones, linear_map_sector(ti, args->next_sector),
dm_report_zones_cb, args); args, nr_zones);
} }
#else #else
#define linear_report_zones NULL #define linear_report_zones NULL
......
...@@ -56,7 +56,8 @@ int dm_blk_report_zones(struct gendisk *disk, sector_t sector, ...@@ -56,7 +56,8 @@ int dm_blk_report_zones(struct gendisk *disk, sector_t sector,
return ret; return ret;
} }
int dm_report_zones_cb(struct blk_zone *zone, unsigned int idx, void *data) static int dm_report_zones_cb(struct blk_zone *zone, unsigned int idx,
void *data)
{ {
struct dm_report_zones_args *args = data; struct dm_report_zones_args *args = data;
sector_t sector_diff = args->tgt->begin - args->start; sector_t sector_diff = args->tgt->begin - args->start;
...@@ -84,7 +85,24 @@ int dm_report_zones_cb(struct blk_zone *zone, unsigned int idx, void *data) ...@@ -84,7 +85,24 @@ int dm_report_zones_cb(struct blk_zone *zone, unsigned int idx, void *data)
args->next_sector = zone->start + zone->len; args->next_sector = zone->start + zone->len;
return args->orig_cb(zone, args->zone_idx++, args->orig_data); return args->orig_cb(zone, args->zone_idx++, args->orig_data);
} }
EXPORT_SYMBOL_GPL(dm_report_zones_cb);
/*
* Helper for drivers of zoned targets to implement struct target_type
* report_zones operation.
*/
int dm_report_zones(struct block_device *bdev, sector_t start, sector_t sector,
struct dm_report_zones_args *args, unsigned int nr_zones)
{
/*
* Set the target mapping start sector first so that
* dm_report_zones_cb() can correctly remap zone information.
*/
args->start = start;
return blkdev_report_zones(bdev, sector, nr_zones,
dm_report_zones_cb, args);
}
EXPORT_SYMBOL_GPL(dm_report_zones);
void dm_set_zones_restrictions(struct dm_table *t, struct request_queue *q) void dm_set_zones_restrictions(struct dm_table *t, struct request_queue *q)
{ {
......
...@@ -478,7 +478,8 @@ struct dm_report_zones_args { ...@@ -478,7 +478,8 @@ struct dm_report_zones_args {
/* must be filled by ->report_zones before calling dm_report_zones_cb */ /* must be filled by ->report_zones before calling dm_report_zones_cb */
sector_t start; sector_t start;
}; };
int dm_report_zones_cb(struct blk_zone *zone, unsigned int idx, void *data); int dm_report_zones(struct block_device *bdev, sector_t start, sector_t sector,
struct dm_report_zones_args *args, unsigned int nr_zones);
#endif /* CONFIG_BLK_DEV_ZONED */ #endif /* CONFIG_BLK_DEV_ZONED */
/* /*
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment