*/
static unsigned int dmz_dev_zone_id(struct dmz_metadata *zmd, struct dm_zone *zone)
{
- unsigned int zone_id;
-
if (WARN_ON(!zone))
return 0;
- zone_id = zone->id;
- if (zmd->nr_devs > 1 &&
- (zone_id >= zmd->dev[1].zone_offset))
- zone_id -= zmd->dev[1].zone_offset;
- return zone_id;
+ return zone->id - zone->dev->zone_offset;
}
sector_t dmz_start_sect(struct dmz_metadata *zmd, struct dm_zone *zone)
return (sector_t)zone_id << zmd->zone_nr_blocks_shift;
}
-struct dmz_dev *dmz_zone_to_dev(struct dmz_metadata *zmd, struct dm_zone *zone)
-{
- if (WARN_ON(!zone))
- return &zmd->dev[0];
-
- if (zmd->nr_devs > 1 &&
- zone->id >= zmd->dev[1].zone_offset)
- return &zmd->dev[1];
-
- return &zmd->dev[0];
-}
-
unsigned int dmz_zone_nr_blocks(struct dmz_metadata *zmd)
{
return zmd->zone_nr_blocks;
}
static struct dm_zone *dmz_insert(struct dmz_metadata *zmd,
- unsigned int zone_id)
+ unsigned int zone_id, struct dmz_dev *dev)
{
struct dm_zone *zone = kzalloc(sizeof(struct dm_zone), GFP_KERNEL);
atomic_set(&zone->refcount, 0);
zone->id = zone_id;
zone->chunk = DMZ_MAP_UNMAPPED;
+ zone->dev = dev;
return zone;
}
/* Read and check the primary super block */
zmd->sb[0].block = dmz_start_block(zmd, zmd->sb[0].zone);
- zmd->sb[0].dev = dmz_zone_to_dev(zmd, zmd->sb[0].zone);
+ zmd->sb[0].dev = zmd->sb[0].zone->dev;
ret = dmz_get_sb(zmd, &zmd->sb[0], 0);
if (ret) {
dmz_dev_err(zmd->sb[0].dev, "Read primary super block failed");
int idx = num + dev->zone_offset;
struct dm_zone *zone;
- zone = dmz_insert(zmd, idx);
+ zone = dmz_insert(zmd, idx, dev);
if (IS_ERR(zone))
return PTR_ERR(zone);
for(idx = 0; idx < dev->nr_zones; idx++) {
struct dm_zone *zone;
- zone = dmz_insert(zmd, idx);
+ zone = dmz_insert(zmd, idx, dev);
if (IS_ERR(zone))
return PTR_ERR(zone);
set_bit(DMZ_CACHE, &zone->flags);
*/
static int dmz_update_zone(struct dmz_metadata *zmd, struct dm_zone *zone)
{
- struct dmz_dev *dev = dmz_zone_to_dev(zmd, zone);
+ struct dmz_dev *dev = zone->dev;
unsigned int noio_flag;
int ret;
static int dmz_handle_seq_write_err(struct dmz_metadata *zmd,
struct dm_zone *zone)
{
- struct dmz_dev *dev = dmz_zone_to_dev(zmd, zone);
+ struct dmz_dev *dev = zone->dev;
unsigned int wp = 0;
int ret;
return 0;
if (!dmz_is_empty(zone) || dmz_seq_write_err(zone)) {
- struct dmz_dev *dev = dmz_zone_to_dev(zmd, zone);
+ struct dmz_dev *dev = zone->dev;
ret = blkdev_zone_mgmt(dev->bdev, REQ_OP_ZONE_RESET,
dmz_start_sect(zmd, zone),
goto again;
}
if (dmz_is_meta(zone)) {
- struct dmz_dev *dev = dmz_zone_to_dev(zmd, zone);
-
- dmz_dev_warn(dev, "Zone %u has metadata", zone->id);
+ dmz_zmd_warn(zmd, "Zone %u has metadata", zone->id);
zone = NULL;
goto again;
}
sector_t block)
{
struct dmz_metadata *zmd = zrc->metadata;
- struct dmz_dev *dev = dmz_zone_to_dev(zmd, zone);
+ struct dmz_dev *dev = zone->dev;
sector_t wp_block = zone->wp_block;
unsigned int nr_blocks;
int ret;
struct dm_zone *src_zone, struct dm_zone *dst_zone)
{
struct dmz_metadata *zmd = zrc->metadata;
- struct dmz_dev *src_dev, *dst_dev;
struct dm_io_region src, dst;
sector_t block = 0, end_block;
sector_t nr_blocks;
else
end_block = dmz_zone_nr_blocks(zmd);
src_zone_block = dmz_start_block(zmd, src_zone);
- src_dev = dmz_zone_to_dev(zmd, src_zone);
dst_zone_block = dmz_start_block(zmd, dst_zone);
- dst_dev = dmz_zone_to_dev(zmd, dst_zone);
if (dmz_is_seq(dst_zone))
set_bit(DM_KCOPYD_WRITE_SEQ, &flags);
while (block < end_block) {
- if (src_dev->flags & DMZ_BDEV_DYING)
+ if (src_zone->dev->flags & DMZ_BDEV_DYING)
return -EIO;
- if (dst_dev->flags & DMZ_BDEV_DYING)
+ if (dst_zone->dev->flags & DMZ_BDEV_DYING)
return -EIO;
if (dmz_reclaim_should_terminate(src_zone))
return ret;
}
- src.bdev = src_dev->bdev;
+ src.bdev = src_zone->dev->bdev;
src.sector = dmz_blk2sect(src_zone_block + block);
src.count = dmz_blk2sect(nr_blocks);
- dst.bdev = dst_dev->bdev;
+ dst.bdev = dst_zone->dev->bdev;
dst.sector = dmz_blk2sect(dst_zone_block + block);
dst.count = src.count;
/* For listing the zone depending on its state */
struct list_head link;
+ /* Device containing this zone */
+ struct dmz_dev *dev;
+
/* Zone type and state */
unsigned long flags;
sector_t dmz_start_sect(struct dmz_metadata *zmd, struct dm_zone *zone);
sector_t dmz_start_block(struct dmz_metadata *zmd, struct dm_zone *zone);
unsigned int dmz_nr_chunks(struct dmz_metadata *zmd);
-struct dmz_dev *dmz_zone_to_dev(struct dmz_metadata *zmd, struct dm_zone *zone);
bool dmz_check_dev(struct dmz_metadata *zmd);
bool dmz_dev_is_dying(struct dmz_metadata *zmd);