Lines Matching refs:nullb

230 static void null_del_dev(struct nullb *nullb);
232 static struct nullb *null_find_dev_by_name(const char *name);
337 if (!dev->nullb) in nullb_update_nr_hw_queues()
362 set = dev->nullb->tag_set; in nullb_update_nr_hw_queues()
444 null_del_dev(dev->nullb); in nullb_device_power_store()
581 null_del_dev(dev->nullb); in nullb_group_drop_item()
621 static inline int null_cache_active(struct nullb *nullb) in null_cache_active() argument
623 return test_bit(NULLB_DEV_FL_CACHE, &nullb->dev->flags); in null_cache_active()
815 static void null_free_sector(struct nullb *nullb, sector_t sector, in null_free_sector() argument
823 root = is_cache ? &nullb->dev->cache : &nullb->dev->data; in null_free_sector()
836 nullb->dev->curr_cache -= PAGE_SIZE; in null_free_sector()
841 static struct nullb_page *null_radix_tree_insert(struct nullb *nullb, u64 idx, in null_radix_tree_insert() argument
846 root = is_cache ? &nullb->dev->cache : &nullb->dev->data; in null_radix_tree_insert()
853 nullb->dev->curr_cache += PAGE_SIZE; in null_radix_tree_insert()
887 static struct nullb_page *__null_lookup_page(struct nullb *nullb, in __null_lookup_page() argument
898 root = is_cache ? &nullb->dev->cache : &nullb->dev->data; in __null_lookup_page()
908 static struct nullb_page *null_lookup_page(struct nullb *nullb, in null_lookup_page() argument
914 page = __null_lookup_page(nullb, sector, for_write, true); in null_lookup_page()
917 return __null_lookup_page(nullb, sector, for_write, false); in null_lookup_page()
920 static struct nullb_page *null_insert_page(struct nullb *nullb, in null_insert_page() argument
922 __releases(&nullb->lock) in null_insert_page()
923 __acquires(&nullb->lock) in null_insert_page()
928 t_page = null_lookup_page(nullb, sector, true, ignore_cache); in null_insert_page()
932 spin_unlock_irq(&nullb->lock); in null_insert_page()
941 spin_lock_irq(&nullb->lock); in null_insert_page()
944 t_page = null_radix_tree_insert(nullb, idx, t_page, !ignore_cache); in null_insert_page()
951 spin_lock_irq(&nullb->lock); in null_insert_page()
952 return null_lookup_page(nullb, sector, true, ignore_cache); in null_insert_page()
955 static int null_flush_cache_page(struct nullb *nullb, struct nullb_page *c_page) in null_flush_cache_page() argument
965 t_page = null_insert_page(nullb, idx << PAGE_SECTORS_SHIFT, true); in null_flush_cache_page()
971 ret = radix_tree_delete_item(&nullb->dev->data, in null_flush_cache_page()
985 i += (nullb->dev->blocksize >> SECTOR_SHIFT)) { in null_flush_cache_page()
989 nullb->dev->blocksize); in null_flush_cache_page()
997 ret = radix_tree_delete_item(&nullb->dev->cache, idx, c_page); in null_flush_cache_page()
999 nullb->dev->curr_cache -= PAGE_SIZE; in null_flush_cache_page()
1004 static int null_make_cache_space(struct nullb *nullb, unsigned long n) in null_make_cache_space() argument
1011 if ((nullb->dev->cache_size * 1024 * 1024) > in null_make_cache_space()
1012 nullb->dev->curr_cache + n || nullb->dev->curr_cache == 0) in null_make_cache_space()
1015 nr_pages = radix_tree_gang_lookup(&nullb->dev->cache, in null_make_cache_space()
1016 (void **)c_pages, nullb->cache_flush_pos, FREE_BATCH); in null_make_cache_space()
1022 nullb->cache_flush_pos = c_pages[i]->page->index; in null_make_cache_space()
1037 err = null_flush_cache_page(nullb, c_pages[i]); in null_make_cache_space()
1046 nullb->cache_flush_pos = 0; in null_make_cache_space()
1049 spin_unlock_irq(&nullb->lock); in null_make_cache_space()
1050 spin_lock_irq(&nullb->lock); in null_make_cache_space()
1057 static int copy_to_nullb(struct nullb *nullb, struct page *source, in copy_to_nullb() argument
1066 temp = min_t(size_t, nullb->dev->blocksize, n - count); in copy_to_nullb()
1068 if (null_cache_active(nullb) && !is_fua) in copy_to_nullb()
1069 null_make_cache_space(nullb, PAGE_SIZE); in copy_to_nullb()
1072 t_page = null_insert_page(nullb, sector, in copy_to_nullb()
1073 !null_cache_active(nullb) || is_fua); in copy_to_nullb()
1086 null_free_sector(nullb, sector, true); in copy_to_nullb()
1094 static int copy_from_nullb(struct nullb *nullb, struct page *dest, in copy_from_nullb() argument
1103 temp = min_t(size_t, nullb->dev->blocksize, n - count); in copy_from_nullb()
1106 t_page = null_lookup_page(nullb, sector, false, in copy_from_nullb()
1107 !null_cache_active(nullb)); in copy_from_nullb()
1126 static void nullb_fill_pattern(struct nullb *nullb, struct page *page, in nullb_fill_pattern() argument
1139 struct nullb *nullb = dev->nullb; in null_handle_discard() local
1143 spin_lock_irq(&nullb->lock); in null_handle_discard()
1146 null_free_sector(nullb, sector, false); in null_handle_discard()
1147 if (null_cache_active(nullb)) in null_handle_discard()
1148 null_free_sector(nullb, sector, true); in null_handle_discard()
1152 spin_unlock_irq(&nullb->lock); in null_handle_discard()
1157 static int null_handle_flush(struct nullb *nullb) in null_handle_flush() argument
1161 if (!null_cache_active(nullb)) in null_handle_flush()
1164 spin_lock_irq(&nullb->lock); in null_handle_flush()
1166 err = null_make_cache_space(nullb, in null_handle_flush()
1167 nullb->dev->cache_size * 1024 * 1024); in null_handle_flush()
1168 if (err || nullb->dev->curr_cache == 0) in null_handle_flush()
1172 WARN_ON(!radix_tree_empty(&nullb->dev->cache)); in null_handle_flush()
1173 spin_unlock_irq(&nullb->lock); in null_handle_flush()
1177 static int null_transfer(struct nullb *nullb, struct page *page, in null_transfer() argument
1181 struct nullb_device *dev = nullb->dev; in null_transfer()
1187 valid_len = null_zone_valid_read_len(nullb, in null_transfer()
1191 err = copy_from_nullb(nullb, page, off, in null_transfer()
1198 nullb_fill_pattern(nullb, page, len, off); in null_transfer()
1202 err = copy_to_nullb(nullb, page, off, sector, len, is_fua); in null_transfer()
1211 struct nullb *nullb = cmd->nq->dev->nullb; in null_handle_rq() local
1218 spin_lock_irq(&nullb->lock); in null_handle_rq()
1221 err = null_transfer(nullb, bvec.bv_page, len, bvec.bv_offset, in null_handle_rq()
1225 spin_unlock_irq(&nullb->lock); in null_handle_rq()
1230 spin_unlock_irq(&nullb->lock); in null_handle_rq()
1238 struct nullb *nullb = cmd->nq->dev->nullb; in null_handle_bio() local
1245 spin_lock_irq(&nullb->lock); in null_handle_bio()
1248 err = null_transfer(nullb, bvec.bv_page, len, bvec.bv_offset, in null_handle_bio()
1252 spin_unlock_irq(&nullb->lock); in null_handle_bio()
1257 spin_unlock_irq(&nullb->lock); in null_handle_bio()
1261 static void null_stop_queue(struct nullb *nullb) in null_stop_queue() argument
1263 struct request_queue *q = nullb->q; in null_stop_queue()
1265 if (nullb->dev->queue_mode == NULL_Q_MQ) in null_stop_queue()
1269 static void null_restart_queue_async(struct nullb *nullb) in null_restart_queue_async() argument
1271 struct request_queue *q = nullb->q; in null_restart_queue_async()
1273 if (nullb->dev->queue_mode == NULL_Q_MQ) in null_restart_queue_async()
1280 struct nullb *nullb = dev->nullb; in null_handle_throttled() local
1284 if (!hrtimer_active(&nullb->bw_timer)) in null_handle_throttled()
1285 hrtimer_restart(&nullb->bw_timer); in null_handle_throttled()
1287 if (atomic_long_sub_return(blk_rq_bytes(rq), &nullb->cur_bytes) < 0) { in null_handle_throttled()
1288 null_stop_queue(nullb); in null_handle_throttled()
1290 if (atomic_long_read(&nullb->cur_bytes) > 0) in null_handle_throttled()
1291 null_restart_queue_async(nullb); in null_handle_throttled()
1407 struct nullb *nullb = dev->nullb; in null_handle_cmd() local
1417 cmd->error = errno_to_blk_status(null_handle_flush(nullb)); in null_handle_cmd()
1437 struct nullb *nullb = container_of(timer, struct nullb, bw_timer); in nullb_bwtimer_fn() local
1439 unsigned int mbps = nullb->dev->mbps; in nullb_bwtimer_fn()
1441 if (atomic_long_read(&nullb->cur_bytes) == mb_per_tick(mbps)) in nullb_bwtimer_fn()
1444 atomic_long_set(&nullb->cur_bytes, mb_per_tick(mbps)); in nullb_bwtimer_fn()
1445 null_restart_queue_async(nullb); in nullb_bwtimer_fn()
1447 hrtimer_forward_now(&nullb->bw_timer, timer_interval); in nullb_bwtimer_fn()
1452 static void nullb_setup_bwtimer(struct nullb *nullb) in nullb_setup_bwtimer() argument
1456 hrtimer_init(&nullb->bw_timer, CLOCK_MONOTONIC, HRTIMER_MODE_REL); in nullb_setup_bwtimer()
1457 nullb->bw_timer.function = nullb_bwtimer_fn; in nullb_setup_bwtimer()
1458 atomic_long_set(&nullb->cur_bytes, mb_per_tick(nullb->dev->mbps)); in nullb_setup_bwtimer()
1459 hrtimer_start(&nullb->bw_timer, timer_interval, HRTIMER_MODE_REL); in nullb_setup_bwtimer()
1462 static struct nullb_queue *nullb_to_queue(struct nullb *nullb) in nullb_to_queue() argument
1466 if (nullb->nr_queues != 1) in nullb_to_queue()
1467 index = raw_smp_processor_id() / ((nr_cpu_ids + nullb->nr_queues - 1) / nullb->nr_queues); in nullb_to_queue()
1469 return &nullb->queues[index]; in nullb_to_queue()
1476 struct nullb *nullb = bio->bi_bdev->bd_disk->private_data; in null_submit_bio() local
1477 struct nullb_queue *nq = nullb_to_queue(nullb); in null_submit_bio()
1502 struct nullb *nullb = set->driver_data; in null_map_queues() local
1507 if (nullb) { in null_map_queues()
1508 struct nullb_device *dev = nullb->dev; in null_map_queues()
1663 static void cleanup_queues(struct nullb *nullb) in cleanup_queues() argument
1667 for (i = 0; i < nullb->nr_queues; i++) in cleanup_queues()
1668 cleanup_queue(&nullb->queues[i]); in cleanup_queues()
1670 kfree(nullb->queues); in cleanup_queues()
1676 struct nullb *nullb = nq->dev->nullb; in null_exit_hctx() local
1678 nullb->nr_queues--; in null_exit_hctx()
1681 static void null_init_queue(struct nullb *nullb, struct nullb_queue *nq) in null_init_queue() argument
1684 nq->queue_depth = nullb->queue_depth; in null_init_queue()
1685 nq->dev = nullb->dev; in null_init_queue()
1693 struct nullb *nullb = hctx->queue->queuedata; in null_init_hctx() local
1701 nq = &nullb->queues[hctx_idx]; in null_init_hctx()
1703 null_init_queue(nullb, nq); in null_init_hctx()
1704 nullb->nr_queues++; in null_init_hctx()
1719 static void null_del_dev(struct nullb *nullb) in null_del_dev() argument
1723 if (!nullb) in null_del_dev()
1726 dev = nullb->dev; in null_del_dev()
1728 ida_simple_remove(&nullb_indexes, nullb->index); in null_del_dev()
1730 list_del_init(&nullb->list); in null_del_dev()
1732 del_gendisk(nullb->disk); in null_del_dev()
1734 if (test_bit(NULLB_DEV_FL_THROTTLED, &nullb->dev->flags)) { in null_del_dev()
1735 hrtimer_cancel(&nullb->bw_timer); in null_del_dev()
1736 atomic_long_set(&nullb->cur_bytes, LONG_MAX); in null_del_dev()
1737 null_restart_queue_async(nullb); in null_del_dev()
1740 blk_cleanup_disk(nullb->disk); in null_del_dev()
1742 nullb->tag_set == &nullb->__tag_set) in null_del_dev()
1743 blk_mq_free_tag_set(nullb->tag_set); in null_del_dev()
1744 cleanup_queues(nullb); in null_del_dev()
1745 if (null_cache_active(nullb)) in null_del_dev()
1746 null_free_device_storage(nullb->dev, true); in null_del_dev()
1747 kfree(nullb); in null_del_dev()
1748 dev->nullb = NULL; in null_del_dev()
1751 static void null_config_discard(struct nullb *nullb) in null_config_discard() argument
1753 if (nullb->dev->discard == false) in null_config_discard()
1756 if (!nullb->dev->memory_backed) { in null_config_discard()
1757 nullb->dev->discard = false; in null_config_discard()
1762 if (nullb->dev->zoned) { in null_config_discard()
1763 nullb->dev->discard = false; in null_config_discard()
1768 nullb->q->limits.discard_granularity = nullb->dev->blocksize; in null_config_discard()
1769 blk_queue_max_discard_sectors(nullb->q, UINT_MAX >> 9); in null_config_discard()
1807 static int setup_queues(struct nullb *nullb) in setup_queues() argument
1814 nullb->queues = kcalloc(nqueues, sizeof(struct nullb_queue), in setup_queues()
1816 if (!nullb->queues) in setup_queues()
1819 nullb->queue_depth = nullb->dev->hw_queue_depth; in setup_queues()
1823 static int init_driver_queues(struct nullb *nullb) in init_driver_queues() argument
1828 for (i = 0; i < nullb->dev->submit_queues; i++) { in init_driver_queues()
1829 nq = &nullb->queues[i]; in init_driver_queues()
1831 null_init_queue(nullb, nq); in init_driver_queues()
1836 nullb->nr_queues++; in init_driver_queues()
1841 static int null_gendisk_register(struct nullb *nullb) in null_gendisk_register() argument
1843 sector_t size = ((sector_t)nullb->dev->size * SZ_1M) >> SECTOR_SHIFT; in null_gendisk_register()
1844 struct gendisk *disk = nullb->disk; in null_gendisk_register()
1849 disk->first_minor = nullb->index; in null_gendisk_register()
1851 if (queue_is_mq(nullb->q)) in null_gendisk_register()
1855 disk->private_data = nullb; in null_gendisk_register()
1856 strncpy(disk->disk_name, nullb->disk_name, DISK_NAME_LEN); in null_gendisk_register()
1858 if (nullb->dev->zoned) { in null_gendisk_register()
1859 int ret = null_register_zoned_dev(nullb); in null_gendisk_register()
1868 static int null_init_tag_set(struct nullb *nullb, struct blk_mq_tag_set *set) in null_init_tag_set() argument
1873 set->nr_hw_queues = nullb ? nullb->dev->submit_queues : in null_init_tag_set()
1875 poll_queues = nullb ? nullb->dev->poll_queues : g_poll_queues; in null_init_tag_set()
1878 set->queue_depth = nullb ? nullb->dev->hw_queue_depth : in null_init_tag_set()
1880 set->numa_node = nullb ? nullb->dev->home_node : g_home_node; in null_init_tag_set()
1887 set->driver_data = nullb; in null_init_tag_set()
1893 if ((nullb && nullb->dev->blocking) || g_blocking) in null_init_tag_set()
1970 struct nullb *nullb; in null_add_dev() local
1977 nullb = kzalloc_node(sizeof(*nullb), GFP_KERNEL, dev->home_node); in null_add_dev()
1978 if (!nullb) { in null_add_dev()
1982 nullb->dev = dev; in null_add_dev()
1983 dev->nullb = nullb; in null_add_dev()
1985 spin_lock_init(&nullb->lock); in null_add_dev()
1987 rv = setup_queues(nullb); in null_add_dev()
1993 nullb->tag_set = &tag_set; in null_add_dev()
1996 nullb->tag_set = &nullb->__tag_set; in null_add_dev()
1997 rv = null_init_tag_set(nullb, nullb->tag_set); in null_add_dev()
2006 nullb->tag_set->timeout = 5 * HZ; in null_add_dev()
2007 nullb->disk = blk_mq_alloc_disk(nullb->tag_set, nullb); in null_add_dev()
2008 if (IS_ERR(nullb->disk)) { in null_add_dev()
2009 rv = PTR_ERR(nullb->disk); in null_add_dev()
2012 nullb->q = nullb->disk->queue; in null_add_dev()
2015 nullb->disk = blk_alloc_disk(nullb->dev->home_node); in null_add_dev()
2016 if (!nullb->disk) in null_add_dev()
2019 nullb->q = nullb->disk->queue; in null_add_dev()
2020 rv = init_driver_queues(nullb); in null_add_dev()
2027 nullb_setup_bwtimer(nullb); in null_add_dev()
2031 set_bit(NULLB_DEV_FL_CACHE, &nullb->dev->flags); in null_add_dev()
2032 blk_queue_write_cache(nullb->q, true, true); in null_add_dev()
2036 rv = null_init_zoned_dev(dev, nullb->q); in null_add_dev()
2041 nullb->q->queuedata = nullb; in null_add_dev()
2042 blk_queue_flag_set(QUEUE_FLAG_NONROT, nullb->q); in null_add_dev()
2043 blk_queue_flag_clear(QUEUE_FLAG_ADD_RANDOM, nullb->q); in null_add_dev()
2051 nullb->index = rv; in null_add_dev()
2055 blk_queue_logical_block_size(nullb->q, dev->blocksize); in null_add_dev()
2056 blk_queue_physical_block_size(nullb->q, dev->blocksize); in null_add_dev()
2058 dev->max_sectors = queue_max_hw_sectors(nullb->q); in null_add_dev()
2061 blk_queue_max_hw_sectors(nullb->q, dev->max_sectors); in null_add_dev()
2064 blk_queue_virt_boundary(nullb->q, PAGE_SIZE - 1); in null_add_dev()
2066 null_config_discard(nullb); in null_add_dev()
2070 snprintf(nullb->disk_name, sizeof(nullb->disk_name), in null_add_dev()
2073 sprintf(nullb->disk_name, "nullb%d", nullb->index); in null_add_dev()
2076 rv = null_gendisk_register(nullb); in null_add_dev()
2081 list_add_tail(&nullb->list, &nullb_list); in null_add_dev()
2084 pr_info("disk %s created\n", nullb->disk_name); in null_add_dev()
2089 ida_free(&nullb_indexes, nullb->index); in null_add_dev()
2093 blk_cleanup_disk(nullb->disk); in null_add_dev()
2095 if (dev->queue_mode == NULL_Q_MQ && nullb->tag_set == &nullb->__tag_set) in null_add_dev()
2096 blk_mq_free_tag_set(nullb->tag_set); in null_add_dev()
2098 cleanup_queues(nullb); in null_add_dev()
2100 kfree(nullb); in null_add_dev()
2101 dev->nullb = NULL; in null_add_dev()
2106 static struct nullb *null_find_dev_by_name(const char *name) in null_find_dev_by_name()
2108 struct nullb *nullb = NULL, *nb; in null_find_dev_by_name() local
2113 nullb = nb; in null_find_dev_by_name()
2119 return nullb; in null_find_dev_by_name()
2140 static void null_destroy_dev(struct nullb *nullb) in null_destroy_dev() argument
2142 struct nullb_device *dev = nullb->dev; in null_destroy_dev()
2144 null_del_dev(nullb); in null_destroy_dev()
2152 struct nullb *nullb; in null_init() local
2220 nullb = list_entry(nullb_list.next, struct nullb, list); in null_init()
2221 null_destroy_dev(nullb); in null_init()
2234 struct nullb *nullb; in null_exit() local
2242 nullb = list_entry(nullb_list.next, struct nullb, list); in null_exit()
2243 null_destroy_dev(nullb); in null_exit()