Commit 4c6bca43 authored by Jan Kara's avatar Jan Kara Committed by Christian Brauner

mm/swap: Convert to use bdev_open_by_dev()

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

CC: linux-mm@kvack.org
CC: Andrew Morton <akpm@linux-foundation.org>
Acked-by: default avatarChristoph Hellwig <hch@lst.de>
Acked-by: default avatarChristian Brauner <brauner@kernel.org>
Signed-off-by: default avatarJan Kara <jack@suse.cz>
Link: https://lore.kernel.org/r/20230927093442.25915-18-jack@suse.czSigned-off-by: default avatarChristian Brauner <brauner@kernel.org>
parent 93745df1
...@@ -298,6 +298,7 @@ struct swap_info_struct { ...@@ -298,6 +298,7 @@ struct swap_info_struct {
unsigned int __percpu *cluster_next_cpu; /*percpu index for next allocation */ unsigned int __percpu *cluster_next_cpu; /*percpu index for next allocation */
struct percpu_cluster __percpu *percpu_cluster; /* per cpu's swap location */ struct percpu_cluster __percpu *percpu_cluster; /* per cpu's swap location */
struct rb_root swap_extent_root;/* root of the swap extent rbtree */ struct rb_root swap_extent_root;/* root of the swap extent rbtree */
struct bdev_handle *bdev_handle;/* open handle of the bdev */
struct block_device *bdev; /* swap device or bdev of swap file */ struct block_device *bdev; /* swap device or bdev of swap file */
struct file *swap_file; /* seldom referenced */ struct file *swap_file; /* seldom referenced */
unsigned int old_block_size; /* seldom referenced */ unsigned int old_block_size; /* seldom referenced */
......
...@@ -2530,11 +2530,10 @@ SYSCALL_DEFINE1(swapoff, const char __user *, specialfile) ...@@ -2530,11 +2530,10 @@ SYSCALL_DEFINE1(swapoff, const char __user *, specialfile)
exit_swap_address_space(p->type); exit_swap_address_space(p->type);
inode = mapping->host; inode = mapping->host;
if (S_ISBLK(inode->i_mode)) { if (p->bdev_handle) {
struct block_device *bdev = I_BDEV(inode); set_blocksize(p->bdev, old_block_size);
bdev_release(p->bdev_handle);
set_blocksize(bdev, old_block_size); p->bdev_handle = NULL;
blkdev_put(bdev, p);
} }
inode_lock(inode); inode_lock(inode);
...@@ -2764,13 +2763,14 @@ static int claim_swapfile(struct swap_info_struct *p, struct inode *inode) ...@@ -2764,13 +2763,14 @@ static int claim_swapfile(struct swap_info_struct *p, struct inode *inode)
int error; int error;
if (S_ISBLK(inode->i_mode)) { if (S_ISBLK(inode->i_mode)) {
p->bdev = blkdev_get_by_dev(inode->i_rdev, p->bdev_handle = bdev_open_by_dev(inode->i_rdev,
BLK_OPEN_READ | BLK_OPEN_WRITE, p, NULL); BLK_OPEN_READ | BLK_OPEN_WRITE, p, NULL);
if (IS_ERR(p->bdev)) { if (IS_ERR(p->bdev_handle)) {
error = PTR_ERR(p->bdev); error = PTR_ERR(p->bdev_handle);
p->bdev = NULL; p->bdev_handle = NULL;
return error; return error;
} }
p->bdev = p->bdev_handle->bdev;
p->old_block_size = block_size(p->bdev); p->old_block_size = block_size(p->bdev);
error = set_blocksize(p->bdev, PAGE_SIZE); error = set_blocksize(p->bdev, PAGE_SIZE);
if (error < 0) if (error < 0)
...@@ -3206,9 +3206,10 @@ SYSCALL_DEFINE2(swapon, const char __user *, specialfile, int, swap_flags) ...@@ -3206,9 +3206,10 @@ SYSCALL_DEFINE2(swapon, const char __user *, specialfile, int, swap_flags)
p->percpu_cluster = NULL; p->percpu_cluster = NULL;
free_percpu(p->cluster_next_cpu); free_percpu(p->cluster_next_cpu);
p->cluster_next_cpu = NULL; p->cluster_next_cpu = NULL;
if (inode && S_ISBLK(inode->i_mode) && p->bdev) { if (p->bdev_handle) {
set_blocksize(p->bdev, p->old_block_size); set_blocksize(p->bdev, p->old_block_size);
blkdev_put(p->bdev, p); bdev_release(p->bdev_handle);
p->bdev_handle = NULL;
} }
inode = NULL; inode = NULL;
destroy_swap_extents(p); destroy_swap_extents(p);
......
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