Skip to content

Commit

Permalink
fs: disallow all fallocate operation on active swapfile
Browse files Browse the repository at this point in the history
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 <lczerner@redhat.com>
Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
  • Loading branch information
Lukas Czerner authored and Theodore Ts'o committed Apr 12, 2014
1 parent 23fffa9 commit 0790b31
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 13 deletions.
3 changes: 0 additions & 3 deletions fs/ceph/file.c
Original file line number Diff line number Diff line change
Expand Up @@ -1215,9 +1215,6 @@ static long ceph_fallocate(struct file *file, int mode,
if (!S_ISREG(inode->i_mode))
return -EOPNOTSUPP;

if (IS_SWAPFILE(inode))
return -ETXTBSY;

mutex_lock(&inode->i_mutex);

if (ceph_snap(inode) != CEPH_NOSNAP) {
Expand Down
5 changes: 0 additions & 5 deletions fs/ext4/extents.c
Original file line number Diff line number Diff line change
Expand Up @@ -5405,11 +5405,6 @@ int ext4_collapse_range(struct inode *inode, loff_t offset, loff_t len)
goto out_mutex;
}

if (IS_SWAPFILE(inode)) {
ret = -ETXTBSY;
goto out_mutex;
}

/* Currently just for extent based files */
if (!ext4_test_inode_flag(inode, EXT4_INODE_EXTENTS)) {
ret = -EOPNOTSUPP;
Expand Down
5 changes: 0 additions & 5 deletions fs/ext4/inode.c
Original file line number Diff line number Diff line change
Expand Up @@ -3542,11 +3542,6 @@ int ext4_punch_hole(struct inode *inode, loff_t offset, loff_t length)

mutex_lock(&inode->i_mutex);

if (IS_SWAPFILE(inode)) {
ret = -ETXTBSY;
goto out_mutex;
}

/* No need to punch hole beyond i_size */
if (offset >= inode->i_size)
goto out_mutex;
Expand Down
7 changes: 7 additions & 0 deletions fs/open.c
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,13 @@ int do_fallocate(struct file *file, int mode, loff_t offset, loff_t len)
if (IS_IMMUTABLE(inode))
return -EPERM;

/*
* We can not allow to do any fallocate operation on an active
* swapfile
*/
if (IS_SWAPFILE(inode))
ret = -ETXTBSY;

/*
* Revalidate the write permissions, in case security policy has
* changed since the files were opened.
Expand Down

0 comments on commit 0790b31

Please sign in to comment.