Skip to content

Commit 0790b31

Browse files
Lukas Czernertytso
authored andcommitted
fs: disallow all fallocate operation on active swapfile
Currently some file system have IS_SWAPFILE check in their fallocate implementations and some do not. However we should really prevent any fallocate operation on swapfile so move the check to vfs and remove the redundant checks from the file systems fallocate implementations. Signed-off-by: Lukas Czerner <[email protected]> Signed-off-by: "Theodore Ts'o" <[email protected]>
1 parent 23fffa9 commit 0790b31

File tree

4 files changed

+7
-13
lines changed

4 files changed

+7
-13
lines changed

fs/ceph/file.c

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1215,9 +1215,6 @@ static long ceph_fallocate(struct file *file, int mode,
12151215
if (!S_ISREG(inode->i_mode))
12161216
return -EOPNOTSUPP;
12171217

1218-
if (IS_SWAPFILE(inode))
1219-
return -ETXTBSY;
1220-
12211218
mutex_lock(&inode->i_mutex);
12221219

12231220
if (ceph_snap(inode) != CEPH_NOSNAP) {

fs/ext4/extents.c

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5405,11 +5405,6 @@ int ext4_collapse_range(struct inode *inode, loff_t offset, loff_t len)
54055405
goto out_mutex;
54065406
}
54075407

5408-
if (IS_SWAPFILE(inode)) {
5409-
ret = -ETXTBSY;
5410-
goto out_mutex;
5411-
}
5412-
54135408
/* Currently just for extent based files */
54145409
if (!ext4_test_inode_flag(inode, EXT4_INODE_EXTENTS)) {
54155410
ret = -EOPNOTSUPP;

fs/ext4/inode.c

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3542,11 +3542,6 @@ int ext4_punch_hole(struct inode *inode, loff_t offset, loff_t length)
35423542

35433543
mutex_lock(&inode->i_mutex);
35443544

3545-
if (IS_SWAPFILE(inode)) {
3546-
ret = -ETXTBSY;
3547-
goto out_mutex;
3548-
}
3549-
35503545
/* No need to punch hole beyond i_size */
35513546
if (offset >= inode->i_size)
35523547
goto out_mutex;

fs/open.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,13 @@ int do_fallocate(struct file *file, int mode, loff_t offset, loff_t len)
262262
if (IS_IMMUTABLE(inode))
263263
return -EPERM;
264264

265+
/*
266+
* We can not allow to do any fallocate operation on an active
267+
* swapfile
268+
*/
269+
if (IS_SWAPFILE(inode))
270+
ret = -ETXTBSY;
271+
265272
/*
266273
* Revalidate the write permissions, in case security policy has
267274
* changed since the files were opened.

0 commit comments

Comments
 (0)