Commit ebb0173d authored by Al Viro's avatar Al Viro

zram: don't bother with reopening - just use O_EXCL for open

Signed-off-by: default avatarAl Viro <viro@zeniv.linux.org.uk>
parent 51d908b3
...@@ -426,11 +426,10 @@ static void reset_bdev(struct zram *zram) ...@@ -426,11 +426,10 @@ static void reset_bdev(struct zram *zram)
if (!zram->backing_dev) if (!zram->backing_dev)
return; return;
fput(zram->bdev_file);
/* 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_file = NULL; zram->bdev = NULL;
zram->disk->fops = &zram_devops; zram->disk->fops = &zram_devops;
kvfree(zram->bitmap); kvfree(zram->bitmap);
zram->bitmap = NULL; zram->bitmap = NULL;
...@@ -473,10 +472,8 @@ static ssize_t backing_dev_store(struct device *dev, ...@@ -473,10 +472,8 @@ static ssize_t backing_dev_store(struct device *dev,
size_t sz; size_t sz;
struct file *backing_dev = NULL; struct file *backing_dev = NULL;
struct inode *inode; struct inode *inode;
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 file *bdev_file = NULL;
int err; int err;
struct zram *zram = dev_to_zram(dev); struct zram *zram = dev_to_zram(dev);
...@@ -497,15 +494,14 @@ static ssize_t backing_dev_store(struct device *dev, ...@@ -497,15 +494,14 @@ static ssize_t backing_dev_store(struct device *dev,
if (sz > 0 && file_name[sz - 1] == '\n') if (sz > 0 && file_name[sz - 1] == '\n')
file_name[sz - 1] = 0x00; file_name[sz - 1] = 0x00;
backing_dev = filp_open(file_name, O_RDWR|O_LARGEFILE, 0); backing_dev = filp_open(file_name, O_RDWR | O_LARGEFILE | O_EXCL, 0);
if (IS_ERR(backing_dev)) { if (IS_ERR(backing_dev)) {
err = PTR_ERR(backing_dev); err = PTR_ERR(backing_dev);
backing_dev = NULL; backing_dev = NULL;
goto out; goto out;
} }
mapping = backing_dev->f_mapping; inode = backing_dev->f_mapping->host;
inode = mapping->host;
/* Support only block device in this moment */ /* Support only block device in this moment */
if (!S_ISBLK(inode->i_mode)) { if (!S_ISBLK(inode->i_mode)) {
...@@ -513,14 +509,6 @@ static ssize_t backing_dev_store(struct device *dev, ...@@ -513,14 +509,6 @@ static ssize_t backing_dev_store(struct device *dev,
goto out; goto out;
} }
bdev_file = bdev_file_open_by_dev(inode->i_rdev,
BLK_OPEN_READ | BLK_OPEN_WRITE, zram, NULL);
if (IS_ERR(bdev_file)) {
err = PTR_ERR(bdev_file);
bdev_file = NULL;
goto out;
}
nr_pages = i_size_read(inode) >> PAGE_SHIFT; nr_pages = i_size_read(inode) >> PAGE_SHIFT;
bitmap_sz = BITS_TO_LONGS(nr_pages) * sizeof(long); bitmap_sz = BITS_TO_LONGS(nr_pages) * sizeof(long);
bitmap = kvzalloc(bitmap_sz, GFP_KERNEL); bitmap = kvzalloc(bitmap_sz, GFP_KERNEL);
...@@ -531,7 +519,7 @@ static ssize_t backing_dev_store(struct device *dev, ...@@ -531,7 +519,7 @@ static ssize_t backing_dev_store(struct device *dev,
reset_bdev(zram); reset_bdev(zram);
zram->bdev_file = bdev_file; zram->bdev = I_BDEV(inode);
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;
...@@ -544,9 +532,6 @@ static ssize_t backing_dev_store(struct device *dev, ...@@ -544,9 +532,6 @@ static ssize_t backing_dev_store(struct device *dev,
out: out:
kvfree(bitmap); kvfree(bitmap);
if (bdev_file)
fput(bdev_file);
if (backing_dev) if (backing_dev)
filp_close(backing_dev, NULL); filp_close(backing_dev, NULL);
...@@ -587,7 +572,7 @@ static void read_from_bdev_async(struct zram *zram, struct page *page, ...@@ -587,7 +572,7 @@ static void read_from_bdev_async(struct zram *zram, struct page *page,
{ {
struct bio *bio; struct bio *bio;
bio = bio_alloc(file_bdev(zram->bdev_file), 1, parent->bi_opf, GFP_NOIO); bio = bio_alloc(zram->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);
...@@ -703,7 +688,7 @@ static ssize_t writeback_store(struct device *dev, ...@@ -703,7 +688,7 @@ static ssize_t writeback_store(struct device *dev,
continue; continue;
} }
bio_init(&bio, file_bdev(zram->bdev_file), &bio_vec, 1, bio_init(&bio, zram->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);
...@@ -785,7 +770,7 @@ static void zram_sync_read(struct work_struct *work) ...@@ -785,7 +770,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, file_bdev(zw->zram->bdev_file), &bv, 1, REQ_OP_READ); bio_init(&bio, zw->zram->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 file *bdev_file; struct block_device *bdev;
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