Commit eed993a0 authored by Jan Kara's avatar Jan Kara Committed by Christian Brauner

zram: Convert to use bdev_open_by_dev()

Convert zram to use bdev_open_by_dev() and pass the handle around.

CC: Minchan Kim <minchan@kernel.org>
CC: Sergey Senozhatsky <senozhatsky@chromium.org>
Acked-by: default avatarChristoph Hellwig <hch@lst.de>
Acked-by: default avatarChristian Brauner <brauner@kernel.org>
Reviewed-by: default avatarSergey Senozhatsky <senozhatsky@chromium.org>
Signed-off-by: default avatarJan Kara <jack@suse.cz>
Link: https://lore.kernel.org/r/20230927093442.25915-8-jack@suse.czSigned-off-by: default avatarChristian Brauner <brauner@kernel.org>
parent 436d3705
...@@ -414,17 +414,14 @@ static ssize_t writeback_limit_show(struct device *dev, ...@@ -414,17 +414,14 @@ static ssize_t writeback_limit_show(struct device *dev,
static void reset_bdev(struct zram *zram) static void reset_bdev(struct zram *zram)
{ {
struct block_device *bdev;
if (!zram->backing_dev) if (!zram->backing_dev)
return; return;
bdev = zram->bdev; bdev_release(zram->bdev_handle);
blkdev_put(bdev, zram);
/* hope filp_close flush all of IO */ /* hope filp_close flush all of IO */
filp_close(zram->backing_dev, NULL); filp_close(zram->backing_dev, NULL);
zram->backing_dev = NULL; zram->backing_dev = NULL;
zram->bdev = NULL; zram->bdev_handle = NULL;
zram->disk->fops = &zram_devops; zram->disk->fops = &zram_devops;
kvfree(zram->bitmap); kvfree(zram->bitmap);
zram->bitmap = NULL; zram->bitmap = NULL;
...@@ -470,7 +467,7 @@ static ssize_t backing_dev_store(struct device *dev, ...@@ -470,7 +467,7 @@ static ssize_t backing_dev_store(struct device *dev,
struct address_space *mapping; struct address_space *mapping;
unsigned int bitmap_sz; unsigned int bitmap_sz;
unsigned long nr_pages, *bitmap = NULL; unsigned long nr_pages, *bitmap = NULL;
struct block_device *bdev = NULL; struct bdev_handle *bdev_handle = NULL;
int err; int err;
struct zram *zram = dev_to_zram(dev); struct zram *zram = dev_to_zram(dev);
...@@ -507,11 +504,11 @@ static ssize_t backing_dev_store(struct device *dev, ...@@ -507,11 +504,11 @@ static ssize_t backing_dev_store(struct device *dev,
goto out; goto out;
} }
bdev = blkdev_get_by_dev(inode->i_rdev, BLK_OPEN_READ | BLK_OPEN_WRITE, bdev_handle = bdev_open_by_dev(inode->i_rdev,
zram, NULL); BLK_OPEN_READ | BLK_OPEN_WRITE, zram, NULL);
if (IS_ERR(bdev)) { if (IS_ERR(bdev_handle)) {
err = PTR_ERR(bdev); err = PTR_ERR(bdev_handle);
bdev = NULL; bdev_handle = NULL;
goto out; goto out;
} }
...@@ -525,7 +522,7 @@ static ssize_t backing_dev_store(struct device *dev, ...@@ -525,7 +522,7 @@ static ssize_t backing_dev_store(struct device *dev,
reset_bdev(zram); reset_bdev(zram);
zram->bdev = bdev; zram->bdev_handle = bdev_handle;
zram->backing_dev = backing_dev; zram->backing_dev = backing_dev;
zram->bitmap = bitmap; zram->bitmap = bitmap;
zram->nr_pages = nr_pages; zram->nr_pages = nr_pages;
...@@ -538,8 +535,8 @@ static ssize_t backing_dev_store(struct device *dev, ...@@ -538,8 +535,8 @@ static ssize_t backing_dev_store(struct device *dev,
out: out:
kvfree(bitmap); kvfree(bitmap);
if (bdev) if (bdev_handle)
blkdev_put(bdev, zram); bdev_release(bdev_handle);
if (backing_dev) if (backing_dev)
filp_close(backing_dev, NULL); filp_close(backing_dev, NULL);
...@@ -581,7 +578,7 @@ static void read_from_bdev_async(struct zram *zram, struct page *page, ...@@ -581,7 +578,7 @@ static void read_from_bdev_async(struct zram *zram, struct page *page,
{ {
struct bio *bio; struct bio *bio;
bio = bio_alloc(zram->bdev, 1, parent->bi_opf, GFP_NOIO); bio = bio_alloc(zram->bdev_handle->bdev, 1, parent->bi_opf, GFP_NOIO);
bio->bi_iter.bi_sector = entry * (PAGE_SIZE >> 9); bio->bi_iter.bi_sector = entry * (PAGE_SIZE >> 9);
__bio_add_page(bio, page, PAGE_SIZE, 0); __bio_add_page(bio, page, PAGE_SIZE, 0);
bio_chain(bio, parent); bio_chain(bio, parent);
...@@ -697,7 +694,7 @@ static ssize_t writeback_store(struct device *dev, ...@@ -697,7 +694,7 @@ static ssize_t writeback_store(struct device *dev,
continue; continue;
} }
bio_init(&bio, zram->bdev, &bio_vec, 1, bio_init(&bio, zram->bdev_handle->bdev, &bio_vec, 1,
REQ_OP_WRITE | REQ_SYNC); REQ_OP_WRITE | REQ_SYNC);
bio.bi_iter.bi_sector = blk_idx * (PAGE_SIZE >> 9); bio.bi_iter.bi_sector = blk_idx * (PAGE_SIZE >> 9);
__bio_add_page(&bio, page, PAGE_SIZE, 0); __bio_add_page(&bio, page, PAGE_SIZE, 0);
...@@ -779,7 +776,7 @@ static void zram_sync_read(struct work_struct *work) ...@@ -779,7 +776,7 @@ static void zram_sync_read(struct work_struct *work)
struct bio_vec bv; struct bio_vec bv;
struct bio bio; struct bio bio;
bio_init(&bio, zw->zram->bdev, &bv, 1, REQ_OP_READ); bio_init(&bio, zw->zram->bdev_handle->bdev, &bv, 1, REQ_OP_READ);
bio.bi_iter.bi_sector = zw->entry * (PAGE_SIZE >> 9); bio.bi_iter.bi_sector = zw->entry * (PAGE_SIZE >> 9);
__bio_add_page(&bio, zw->page, PAGE_SIZE, 0); __bio_add_page(&bio, zw->page, PAGE_SIZE, 0);
zw->error = submit_bio_wait(&bio); zw->error = submit_bio_wait(&bio);
......
...@@ -132,7 +132,7 @@ struct zram { ...@@ -132,7 +132,7 @@ struct zram {
spinlock_t wb_limit_lock; spinlock_t wb_limit_lock;
bool wb_limit_enable; bool wb_limit_enable;
u64 bd_wb_limit; u64 bd_wb_limit;
struct block_device *bdev; struct bdev_handle *bdev_handle;
unsigned long *bitmap; unsigned long *bitmap;
unsigned long nr_pages; unsigned long nr_pages;
#endif #endif
......
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