1 fs: disallow all fallocate operation on active swapfile
3 From: Lukas Czerner <lczerner@redhat.com>
5 Currently some file system have IS_SWAPFILE check in their fallocate
6 implementations and some do not. However we should really prevent any
7 fallocate operation on swapfile so move the check to vfs and remove the
8 redundant checks from the file systems fallocate implementations.
10 Signed-off-by: Lukas Czerner <lczerner@redhat.com>
11 Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
13 fs/ceph/file.c | 3 ---
14 fs/ext4/extents.c | 5 -----
15 fs/ext4/inode.c | 5 -----
17 4 files changed, 7 insertions(+), 13 deletions(-)
19 diff --git a/fs/ceph/file.c b/fs/ceph/file.c
20 index 66075a4..3a69d80 100644
23 @@ -1219,9 +1219,6 @@ static long ceph_fallocate(struct file *file, int mode,
24 if (!S_ISREG(inode->i_mode))
27 - if (IS_SWAPFILE(inode))
30 mutex_lock(&inode->i_mutex);
32 if (ceph_snap(inode) != CEPH_NOSNAP) {
33 diff --git a/fs/ext4/extents.c b/fs/ext4/extents.c
34 index ff823b7..517b376 100644
35 --- a/fs/ext4/extents.c
36 +++ b/fs/ext4/extents.c
37 @@ -5394,11 +5394,6 @@ int ext4_collapse_range(struct inode *inode, loff_t offset, loff_t len)
41 - if (IS_SWAPFILE(inode)) {
46 /* Currently just for extent based files */
47 if (!ext4_test_inode_flag(inode, EXT4_INODE_EXTENTS)) {
49 diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c
50 index 56f1ff4..d8a270d 100644
53 @@ -3529,11 +3529,6 @@ int ext4_punch_hole(struct inode *inode, loff_t offset, loff_t length)
55 mutex_lock(&inode->i_mutex);
57 - if (IS_SWAPFILE(inode)) {
62 /* No need to punch hole beyond i_size */
63 if (offset >= inode->i_size)
65 diff --git a/fs/open.c b/fs/open.c
66 index 14af6be..48e3fd0 100644
69 @@ -266,6 +266,13 @@ int do_fallocate(struct file *file, int mode, loff_t offset, loff_t len)
73 + * We can not allow to do any fallocate operation on an active
76 + if (IS_SWAPFILE(inode))
80 * Revalidate the write permissions, in case security policy has
81 * changed since the files were opened.