Lines Matching refs:zone
137 struct dm_zone *zone; member
221 static unsigned int dmz_dev_zone_id(struct dmz_metadata *zmd, struct dm_zone *zone) in dmz_dev_zone_id() argument
223 if (WARN_ON(!zone)) in dmz_dev_zone_id()
226 return zone->id - zone->dev->zone_offset; in dmz_dev_zone_id()
229 sector_t dmz_start_sect(struct dmz_metadata *zmd, struct dm_zone *zone) in dmz_start_sect() argument
231 unsigned int zone_id = dmz_dev_zone_id(zmd, zone); in dmz_start_sect()
236 sector_t dmz_start_block(struct dmz_metadata *zmd, struct dm_zone *zone) in dmz_start_block() argument
238 unsigned int zone_id = dmz_dev_zone_id(zmd, zone); in dmz_start_block()
311 struct dm_zone *zone = kzalloc(sizeof(struct dm_zone), GFP_KERNEL); in dmz_insert() local
313 if (!zone) in dmz_insert()
316 if (xa_insert(&zmd->zones, zone_id, zone, GFP_KERNEL)) { in dmz_insert()
317 kfree(zone); in dmz_insert()
321 INIT_LIST_HEAD(&zone->link); in dmz_insert()
322 atomic_set(&zone->refcount, 0); in dmz_insert()
323 zone->id = zone_id; in dmz_insert()
324 zone->chunk = DMZ_MAP_UNMAPPED; in dmz_insert()
325 zone->dev = dev; in dmz_insert()
327 return zone; in dmz_insert()
793 sb_block = zmd->sb[set].zone->id << zmd->zone_nr_blocks_shift; in dmz_write_sb()
1016 if (sb_block != (u64)dsb->zone->id << zmd->zone_nr_blocks_shift) { in dmz_check_sb()
1018 sb_block, (u64)dsb->zone->id << zmd->zone_nr_blocks_shift); in dmz_check_sb()
1116 unsigned int zone_id = zmd->sb[0].zone->id; in dmz_lookup_secondary_sb()
1129 zmd->sb[1].zone = dmz_get(zmd, zone_id + 1); in dmz_lookup_secondary_sb()
1137 zmd->sb[1].zone = dmz_get(zmd, zone_id + i); in dmz_lookup_secondary_sb()
1142 zmd->sb[1].zone = NULL; in dmz_lookup_secondary_sb()
1188 zmd->sb[0].block = dmz_start_block(zmd, zmd->sb[0].zone); in dmz_recover_mblocks()
1190 zmd->sb[1].block = dmz_start_block(zmd, zmd->sb[1].zone); in dmz_recover_mblocks()
1234 if (!zmd->sb[0].zone) { in dmz_load_sb()
1240 zmd->sb[0].block = dmz_start_block(zmd, zmd->sb[0].zone); in dmz_load_sb()
1241 zmd->sb[0].dev = zmd->sb[0].zone->dev; in dmz_load_sb()
1253 if (!zmd->sb[1].zone) { in dmz_load_sb()
1255 zmd->sb[0].zone->id + zmd->nr_meta_zones; in dmz_load_sb()
1257 zmd->sb[1].zone = dmz_get(zmd, zone_id); in dmz_load_sb()
1259 zmd->sb[1].block = dmz_start_block(zmd, zmd->sb[1].zone); in dmz_load_sb()
1324 sb->zone = dmz_get(zmd, zmd->dev[i].zone_offset); in dmz_load_sb()
1326 if (!dmz_is_meta(sb->zone)) { in dmz_load_sb()
1329 sb->zone->id); in dmz_load_sb()
1359 struct dm_zone *zone; in dmz_init_zone() local
1361 zone = dmz_insert(zmd, idx, dev); in dmz_init_zone()
1362 if (IS_ERR(zone)) in dmz_init_zone()
1363 return PTR_ERR(zone); in dmz_init_zone()
1368 set_bit(DMZ_OFFLINE, &zone->flags); in dmz_init_zone()
1384 set_bit(DMZ_RND, &zone->flags); in dmz_init_zone()
1388 set_bit(DMZ_SEQ, &zone->flags); in dmz_init_zone()
1394 if (dmz_is_rnd(zone)) in dmz_init_zone()
1395 zone->wp_block = 0; in dmz_init_zone()
1397 zone->wp_block = dmz_sect2blk(blkz->wp - blkz->start); in dmz_init_zone()
1400 set_bit(DMZ_OFFLINE, &zone->flags); in dmz_init_zone()
1402 set_bit(DMZ_READ_ONLY, &zone->flags); in dmz_init_zone()
1405 if (dmz_is_rnd(zone)) { in dmz_init_zone()
1407 if (zmd->nr_devs == 1 && !zmd->sb[0].zone) { in dmz_init_zone()
1409 zmd->sb[0].zone = zone; in dmz_init_zone()
1418 set_bit(DMZ_META, &zone->flags); in dmz_init_zone()
1430 struct dm_zone *zone; in dmz_emulate_zones() local
1432 zone = dmz_insert(zmd, idx, dev); in dmz_emulate_zones()
1433 if (IS_ERR(zone)) in dmz_emulate_zones()
1434 return PTR_ERR(zone); in dmz_emulate_zones()
1435 set_bit(DMZ_CACHE, &zone->flags); in dmz_emulate_zones()
1436 zone->wp_block = 0; in dmz_emulate_zones()
1441 set_bit(DMZ_OFFLINE, &zone->flags); in dmz_emulate_zones()
1457 struct dm_zone *zone = xa_load(&zmd->zones, idx); in dmz_drop_zones() local
1459 kfree(zone); in dmz_drop_zones()
1524 zmd->sb[0].zone = dmz_get(zmd, 0); in dmz_init_zones()
1562 struct dm_zone *zone = data; in dmz_update_zone_cb() local
1564 clear_bit(DMZ_OFFLINE, &zone->flags); in dmz_update_zone_cb()
1565 clear_bit(DMZ_READ_ONLY, &zone->flags); in dmz_update_zone_cb()
1567 set_bit(DMZ_OFFLINE, &zone->flags); in dmz_update_zone_cb()
1569 set_bit(DMZ_READ_ONLY, &zone->flags); in dmz_update_zone_cb()
1571 if (dmz_is_seq(zone)) in dmz_update_zone_cb()
1572 zone->wp_block = dmz_sect2blk(blkz->wp - blkz->start); in dmz_update_zone_cb()
1574 zone->wp_block = 0; in dmz_update_zone_cb()
1581 static int dmz_update_zone(struct dmz_metadata *zmd, struct dm_zone *zone) in dmz_update_zone() argument
1583 struct dmz_dev *dev = zone->dev; in dmz_update_zone()
1597 ret = blkdev_report_zones(dev->bdev, dmz_start_sect(zmd, zone), 1, in dmz_update_zone()
1598 dmz_update_zone_cb, zone); in dmz_update_zone()
1605 zone->id); in dmz_update_zone()
1618 struct dm_zone *zone) in dmz_handle_seq_write_err() argument
1620 struct dmz_dev *dev = zone->dev; in dmz_handle_seq_write_err()
1624 wp = zone->wp_block; in dmz_handle_seq_write_err()
1625 ret = dmz_update_zone(zmd, zone); in dmz_handle_seq_write_err()
1630 zone->id, zone->wp_block, wp); in dmz_handle_seq_write_err()
1632 if (zone->wp_block < wp) { in dmz_handle_seq_write_err()
1633 dmz_invalidate_blocks(zmd, zone, zone->wp_block, in dmz_handle_seq_write_err()
1634 wp - zone->wp_block); in dmz_handle_seq_write_err()
1643 static int dmz_reset_zone(struct dmz_metadata *zmd, struct dm_zone *zone) in dmz_reset_zone() argument
1651 if (dmz_is_offline(zone) || in dmz_reset_zone()
1652 dmz_is_readonly(zone) || in dmz_reset_zone()
1653 dmz_is_rnd(zone)) in dmz_reset_zone()
1656 if (!dmz_is_empty(zone) || dmz_seq_write_err(zone)) { in dmz_reset_zone()
1657 struct dmz_dev *dev = zone->dev; in dmz_reset_zone()
1662 dmz_start_sect(zmd, zone), in dmz_reset_zone()
1667 zone->id, ret); in dmz_reset_zone()
1673 clear_bit(DMZ_SEQ_WRITE_ERR, &zone->flags); in dmz_reset_zone()
1674 zone->wp_block = 0; in dmz_reset_zone()
1679 static void dmz_get_zone_weight(struct dmz_metadata *zmd, struct dm_zone *zone);
1850 static void __dmz_lru_zone(struct dmz_metadata *zmd, struct dm_zone *zone) in __dmz_lru_zone() argument
1852 if (list_empty(&zone->link)) in __dmz_lru_zone()
1855 list_del_init(&zone->link); in __dmz_lru_zone()
1856 if (dmz_is_seq(zone)) { in __dmz_lru_zone()
1858 list_add_tail(&zone->link, &zone->dev->map_seq_list); in __dmz_lru_zone()
1859 } else if (dmz_is_cache(zone)) { in __dmz_lru_zone()
1861 list_add_tail(&zone->link, &zmd->map_cache_list); in __dmz_lru_zone()
1864 list_add_tail(&zone->link, &zone->dev->map_rnd_list); in __dmz_lru_zone()
1872 static void dmz_lru_zone(struct dmz_metadata *zmd, struct dm_zone *zone) in dmz_lru_zone() argument
1874 __dmz_lru_zone(zmd, zone); in dmz_lru_zone()
1875 if (zone->bzone) in dmz_lru_zone()
1876 __dmz_lru_zone(zmd, zone->bzone); in dmz_lru_zone()
1902 int dmz_lock_zone_reclaim(struct dm_zone *zone) in dmz_lock_zone_reclaim() argument
1905 if (dmz_is_active(zone)) in dmz_lock_zone_reclaim()
1908 return !test_and_set_bit(DMZ_RECLAIM, &zone->flags); in dmz_lock_zone_reclaim()
1914 void dmz_unlock_zone_reclaim(struct dm_zone *zone) in dmz_unlock_zone_reclaim() argument
1916 WARN_ON(dmz_is_active(zone)); in dmz_unlock_zone_reclaim()
1917 WARN_ON(!dmz_in_reclaim(zone)); in dmz_unlock_zone_reclaim()
1919 clear_bit_unlock(DMZ_RECLAIM, &zone->flags); in dmz_unlock_zone_reclaim()
1921 wake_up_bit(&zone->flags, DMZ_RECLAIM); in dmz_unlock_zone_reclaim()
1927 static void dmz_wait_for_reclaim(struct dmz_metadata *zmd, struct dm_zone *zone) in dmz_wait_for_reclaim() argument
1931 set_bit(DMZ_RECLAIM_TERMINATE, &zone->flags); in dmz_wait_for_reclaim()
1932 wait_on_bit_timeout(&zone->flags, DMZ_RECLAIM, TASK_UNINTERRUPTIBLE, HZ); in dmz_wait_for_reclaim()
1933 clear_bit(DMZ_RECLAIM_TERMINATE, &zone->flags); in dmz_wait_for_reclaim()
1945 struct dm_zone *zone, *maxw_z = NULL; in dmz_get_rnd_zone_for_reclaim() local
1961 list_for_each_entry(zone, zone_list, link) { in dmz_get_rnd_zone_for_reclaim()
1962 if (dmz_is_buf(zone)) { in dmz_get_rnd_zone_for_reclaim()
1963 dzone = zone->bzone; in dmz_get_rnd_zone_for_reclaim()
1969 dzone = zone; in dmz_get_rnd_zone_for_reclaim()
1983 list_for_each_entry(zone, zone_list, link) { in dmz_get_rnd_zone_for_reclaim()
1984 if (dmz_is_buf(zone)) { in dmz_get_rnd_zone_for_reclaim()
1985 dzone = zone->bzone; in dmz_get_rnd_zone_for_reclaim()
1989 dzone = zone; in dmz_get_rnd_zone_for_reclaim()
2003 struct dm_zone *zone; in dmz_get_seq_zone_for_reclaim() local
2005 list_for_each_entry(zone, &zmd->dev[idx].map_seq_list, link) { in dmz_get_seq_zone_for_reclaim()
2006 if (!zone->bzone) in dmz_get_seq_zone_for_reclaim()
2008 if (dmz_lock_zone_reclaim(zone)) in dmz_get_seq_zone_for_reclaim()
2009 return zone; in dmz_get_seq_zone_for_reclaim()
2021 struct dm_zone *zone = NULL; in dmz_get_zone_for_reclaim() local
2033 zone = dmz_get_seq_zone_for_reclaim(zmd, dev_idx); in dmz_get_zone_for_reclaim()
2034 if (!zone) in dmz_get_zone_for_reclaim()
2035 zone = dmz_get_rnd_zone_for_reclaim(zmd, dev_idx, idle); in dmz_get_zone_for_reclaim()
2038 return zone; in dmz_get_zone_for_reclaim()
2212 struct dm_zone *zone; in dmz_alloc_zone() local
2248 zone = list_first_entry_or_null(&zmd->reserved_seq_zones_list, in dmz_alloc_zone()
2250 if (zone) { in dmz_alloc_zone()
2251 list_del_init(&zone->link); in dmz_alloc_zone()
2254 return zone; in dmz_alloc_zone()
2257 zone = list_first_entry(list, struct dm_zone, link); in dmz_alloc_zone()
2258 list_del_init(&zone->link); in dmz_alloc_zone()
2260 if (dmz_is_cache(zone)) in dmz_alloc_zone()
2262 else if (dmz_is_rnd(zone)) in dmz_alloc_zone()
2263 atomic_dec(&zone->dev->unmap_nr_rnd); in dmz_alloc_zone()
2265 atomic_dec(&zone->dev->unmap_nr_seq); in dmz_alloc_zone()
2267 if (dmz_is_offline(zone)) { in dmz_alloc_zone()
2268 dmz_zmd_warn(zmd, "Zone %u is offline", zone->id); in dmz_alloc_zone()
2269 zone = NULL; in dmz_alloc_zone()
2272 if (dmz_is_meta(zone)) { in dmz_alloc_zone()
2273 dmz_zmd_warn(zmd, "Zone %u has metadata", zone->id); in dmz_alloc_zone()
2274 zone = NULL; in dmz_alloc_zone()
2277 return zone; in dmz_alloc_zone()
2284 void dmz_free_zone(struct dmz_metadata *zmd, struct dm_zone *zone) in dmz_free_zone() argument
2287 if (dmz_is_seq(zone)) in dmz_free_zone()
2288 dmz_reset_zone(zmd, zone); in dmz_free_zone()
2291 if (dmz_is_cache(zone)) { in dmz_free_zone()
2292 list_add_tail(&zone->link, &zmd->unmap_cache_list); in dmz_free_zone()
2294 } else if (dmz_is_rnd(zone)) { in dmz_free_zone()
2295 list_add_tail(&zone->link, &zone->dev->unmap_rnd_list); in dmz_free_zone()
2296 atomic_inc(&zone->dev->unmap_nr_rnd); in dmz_free_zone()
2297 } else if (dmz_is_reserved(zone)) { in dmz_free_zone()
2298 list_add_tail(&zone->link, &zmd->reserved_seq_zones_list); in dmz_free_zone()
2301 list_add_tail(&zone->link, &zone->dev->unmap_seq_list); in dmz_free_zone()
2302 atomic_inc(&zone->dev->unmap_nr_seq); in dmz_free_zone()
2331 void dmz_unmap_zone(struct dmz_metadata *zmd, struct dm_zone *zone) in dmz_unmap_zone() argument
2333 unsigned int chunk = zone->chunk; in dmz_unmap_zone()
2341 if (test_and_clear_bit(DMZ_BUF, &zone->flags)) { in dmz_unmap_zone()
2346 dzone_id = zone->bzone->id; in dmz_unmap_zone()
2347 zone->bzone->bzone = NULL; in dmz_unmap_zone()
2348 zone->bzone = NULL; in dmz_unmap_zone()
2355 if (WARN_ON(zone->bzone)) { in dmz_unmap_zone()
2356 zone->bzone->bzone = NULL; in dmz_unmap_zone()
2357 zone->bzone = NULL; in dmz_unmap_zone()
2364 zone->chunk = DMZ_MAP_UNMAPPED; in dmz_unmap_zone()
2365 list_del_init(&zone->link); in dmz_unmap_zone()
2404 struct dm_zone *zone, in dmz_get_bitmap() argument
2408 (sector_t)(zone->id * zmd->zone_nr_bitmap_blocks) + in dmz_get_bitmap()
2479 int dmz_validate_blocks(struct dmz_metadata *zmd, struct dm_zone *zone, in dmz_validate_blocks() argument
2488 zone->id, (unsigned long long)chunk_block, in dmz_validate_blocks()
2495 mblk = dmz_get_bitmap(zmd, zone, chunk_block); in dmz_validate_blocks()
2514 if (likely(zone->weight + n <= zone_nr_blocks)) in dmz_validate_blocks()
2515 zone->weight += n; in dmz_validate_blocks()
2518 zone->id, zone->weight, in dmz_validate_blocks()
2520 zone->weight = zone_nr_blocks; in dmz_validate_blocks()
2560 int dmz_invalidate_blocks(struct dmz_metadata *zmd, struct dm_zone *zone, in dmz_invalidate_blocks() argument
2568 zone->id, (u64)chunk_block, nr_blocks); in dmz_invalidate_blocks()
2574 mblk = dmz_get_bitmap(zmd, zone, chunk_block); in dmz_invalidate_blocks()
2594 if (zone->weight >= n) in dmz_invalidate_blocks()
2595 zone->weight -= n; in dmz_invalidate_blocks()
2598 zone->id, zone->weight, n); in dmz_invalidate_blocks()
2599 zone->weight = 0; in dmz_invalidate_blocks()
2608 static int dmz_test_block(struct dmz_metadata *zmd, struct dm_zone *zone, in dmz_test_block() argument
2617 mblk = dmz_get_bitmap(zmd, zone, chunk_block); in dmz_test_block()
2634 static int dmz_to_next_set_block(struct dmz_metadata *zmd, struct dm_zone *zone, in dmz_to_next_set_block() argument
2648 mblk = dmz_get_bitmap(zmd, zone, chunk_block); in dmz_to_next_set_block()
2677 int dmz_block_valid(struct dmz_metadata *zmd, struct dm_zone *zone, in dmz_block_valid() argument
2682 valid = dmz_test_block(zmd, zone, chunk_block); in dmz_block_valid()
2687 return dmz_to_next_set_block(zmd, zone, chunk_block, in dmz_block_valid()
2697 int dmz_first_valid_block(struct dmz_metadata *zmd, struct dm_zone *zone, in dmz_first_valid_block() argument
2703 ret = dmz_to_next_set_block(zmd, zone, start_block, in dmz_first_valid_block()
2711 return dmz_to_next_set_block(zmd, zone, start_block, in dmz_first_valid_block()
2746 static void dmz_get_zone_weight(struct dmz_metadata *zmd, struct dm_zone *zone) in dmz_get_zone_weight() argument
2757 mblk = dmz_get_bitmap(zmd, zone, chunk_block); in dmz_get_zone_weight()
2775 zone->weight = n; in dmz_get_zone_weight()
2873 struct dm_zone *zone; in dmz_ctr_metadata() local
2913 zone = dmz_get(zmd, zmd->sb[0].zone->id + i); in dmz_ctr_metadata()
2914 if (!zone) { in dmz_ctr_metadata()
2920 if (!dmz_is_rnd(zone) && !dmz_is_cache(zone)) { in dmz_ctr_metadata()
2926 set_bit(DMZ_META, &zone->flags); in dmz_ctr_metadata()
3014 struct dm_zone *zone; in dmz_resume_metadata() local
3021 zone = dmz_get(zmd, i); in dmz_resume_metadata()
3022 if (!zone) { in dmz_resume_metadata()
3026 wp_block = zone->wp_block; in dmz_resume_metadata()
3028 ret = dmz_update_zone(zmd, zone); in dmz_resume_metadata()
3034 if (dmz_is_offline(zone)) { in dmz_resume_metadata()
3040 if (!dmz_is_seq(zone)) in dmz_resume_metadata()
3041 zone->wp_block = 0; in dmz_resume_metadata()
3042 else if (zone->wp_block != wp_block) { in dmz_resume_metadata()
3044 i, (u64)zone->wp_block, (u64)wp_block); in dmz_resume_metadata()
3045 zone->wp_block = wp_block; in dmz_resume_metadata()
3046 dmz_invalidate_blocks(zmd, zone, zone->wp_block, in dmz_resume_metadata()
3047 zmd->zone_nr_blocks - zone->wp_block); in dmz_resume_metadata()