Skip to content

Commit 51d908b

Browse files
author
Al Viro
committed
swapon(2): open swap with O_EXCL
... eliminating the need to reopen block devices so they could be exclusively held. Reviewed-by: Christoph Hellwig <[email protected]> Reviewed-by: Christian Brauner <[email protected]> Signed-off-by: Al Viro <[email protected]>
1 parent 798cb7f commit 51d908b

File tree

2 files changed

+2
-18
lines changed

2 files changed

+2
-18
lines changed

include/linux/swap.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -298,7 +298,6 @@ struct swap_info_struct {
298298
unsigned int __percpu *cluster_next_cpu; /*percpu index for next allocation */
299299
struct percpu_cluster __percpu *percpu_cluster; /* per cpu's swap location */
300300
struct rb_root swap_extent_root;/* root of the swap extent rbtree */
301-
struct file *bdev_file; /* open handle of the bdev */
302301
struct block_device *bdev; /* swap device or bdev of swap file */
303302
struct file *swap_file; /* seldom referenced */
304303
struct completion comp; /* seldom referenced */

mm/swapfile.c

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2550,10 +2550,6 @@ SYSCALL_DEFINE1(swapoff, const char __user *, specialfile)
25502550
exit_swap_address_space(p->type);
25512551

25522552
inode = mapping->host;
2553-
if (p->bdev_file) {
2554-
fput(p->bdev_file);
2555-
p->bdev_file = NULL;
2556-
}
25572553

25582554
inode_lock(inode);
25592555
inode->i_flags &= ~S_SWAPFILE;
@@ -2780,14 +2776,7 @@ static struct swap_info_struct *alloc_swap_info(void)
27802776
static int claim_swapfile(struct swap_info_struct *p, struct inode *inode)
27812777
{
27822778
if (S_ISBLK(inode->i_mode)) {
2783-
p->bdev_file = bdev_file_open_by_dev(inode->i_rdev,
2784-
BLK_OPEN_READ | BLK_OPEN_WRITE, p, NULL);
2785-
if (IS_ERR(p->bdev_file)) {
2786-
int error = PTR_ERR(p->bdev_file);
2787-
p->bdev_file = NULL;
2788-
return error;
2789-
}
2790-
p->bdev = file_bdev(p->bdev_file);
2779+
p->bdev = I_BDEV(inode);
27912780
/*
27922781
* Zoned block devices contain zones that have a sequential
27932782
* write only restriction. Hence zoned block devices are not
@@ -3028,7 +3017,7 @@ SYSCALL_DEFINE2(swapon, const char __user *, specialfile, int, swap_flags)
30283017
name = NULL;
30293018
goto bad_swap;
30303019
}
3031-
swap_file = file_open_name(name, O_RDWR|O_LARGEFILE, 0);
3020+
swap_file = file_open_name(name, O_RDWR | O_LARGEFILE | O_EXCL, 0);
30323021
if (IS_ERR(swap_file)) {
30333022
error = PTR_ERR(swap_file);
30343023
swap_file = NULL;
@@ -3225,10 +3214,6 @@ SYSCALL_DEFINE2(swapon, const char __user *, specialfile, int, swap_flags)
32253214
p->percpu_cluster = NULL;
32263215
free_percpu(p->cluster_next_cpu);
32273216
p->cluster_next_cpu = NULL;
3228-
if (p->bdev_file) {
3229-
fput(p->bdev_file);
3230-
p->bdev_file = NULL;
3231-
}
32323217
inode = NULL;
32333218
destroy_swap_extents(p);
32343219
swap_cgroup_swapoff(p->type);

0 commit comments

Comments
 (0)