Lines Matching refs:brd

49 static struct page *brd_lookup_page(struct brd_device *brd, sector_t sector)  in brd_lookup_page()  argument
52 XA_STATE(xas, &brd->brd_pages, sector >> PAGE_SECTORS_SHIFT); in brd_lookup_page()
85 static struct page *brd_insert_page(struct brd_device *brd, sector_t sector, in brd_insert_page() argument
95 xa_lock(&brd->brd_pages); in brd_insert_page()
96 ret = __xa_cmpxchg(&brd->brd_pages, sector >> PAGE_SECTORS_SHIFT, NULL, in brd_insert_page()
99 brd->brd_nr_pages++; in brd_insert_page()
101 xa_unlock(&brd->brd_pages); in brd_insert_page()
107 xa_unlock(&brd->brd_pages); in brd_insert_page()
112 xa_unlock(&brd->brd_pages); in brd_insert_page()
121 static void brd_free_pages(struct brd_device *brd) in brd_free_pages() argument
126 xa_for_each(&brd->brd_pages, idx, page) { in brd_free_pages()
131 xa_destroy(&brd->brd_pages); in brd_free_pages()
138 static bool brd_rw_bvec(struct brd_device *brd, struct bio *bio) in brd_rw_bvec() argument
149 page = brd_lookup_page(brd, sector); in brd_rw_bvec()
151 page = brd_insert_page(brd, sector, opf); in brd_rw_bvec()
180 static void brd_do_discard(struct brd_device *brd, sector_t sector, u32 size) in brd_do_discard() argument
190 xa_lock(&brd->brd_pages); in brd_do_discard()
192 page = __xa_erase(&brd->brd_pages, aligned_sector >> PAGE_SECTORS_SHIFT); in brd_do_discard()
195 brd->brd_nr_pages--; in brd_do_discard()
199 xa_unlock(&brd->brd_pages); in brd_do_discard()
204 struct brd_device *brd = bio->bi_bdev->bd_disk->private_data; in brd_submit_bio() local
207 brd_do_discard(brd, bio->bi_iter.bi_sector, in brd_submit_bio()
214 if (!brd_rw_bvec(brd, bio)) in brd_submit_bio()
265 struct brd_device *brd; in brd_find_or_alloc_device() local
268 list_for_each_entry(brd, &brd_devices, brd_list) { in brd_find_or_alloc_device()
269 if (brd->brd_number == i) { in brd_find_or_alloc_device()
275 brd = kzalloc_obj(*brd); in brd_find_or_alloc_device()
276 if (!brd) { in brd_find_or_alloc_device()
280 brd->brd_number = i; in brd_find_or_alloc_device()
281 list_add_tail(&brd->brd_list, &brd_devices); in brd_find_or_alloc_device()
283 return brd; in brd_find_or_alloc_device()
286 static void brd_free_device(struct brd_device *brd) in brd_free_device() argument
289 list_del(&brd->brd_list); in brd_free_device()
291 kfree(brd); in brd_free_device()
296 struct brd_device *brd; in brd_alloc() local
316 brd = brd_find_or_alloc_device(i); in brd_alloc()
317 if (IS_ERR(brd)) in brd_alloc()
318 return PTR_ERR(brd); in brd_alloc()
320 xa_init(&brd->brd_pages); in brd_alloc()
325 &brd->brd_nr_pages); in brd_alloc()
327 disk = brd->brd_disk = blk_alloc_disk(&lim, NUMA_NO_NODE); in brd_alloc()
336 disk->private_data = brd; in brd_alloc()
349 brd_free_device(brd); in brd_alloc()
360 struct brd_device *brd, *next; in brd_cleanup() local
364 list_for_each_entry_safe(brd, next, &brd_devices, brd_list) { in brd_cleanup()
365 del_gendisk(brd->brd_disk); in brd_cleanup()
366 put_disk(brd->brd_disk); in brd_cleanup()
367 brd_free_pages(brd); in brd_cleanup()
368 brd_free_device(brd); in brd_cleanup()