fs: disallow all fallocate operation on active swapfile
authorLukas Czerner <lczerner@redhat.com>
Sat, 12 Apr 2014 14:05:37 +0000 (10:05 -0400)
committerTheodore Ts'o <tytso@mit.edu>
Sat, 12 Apr 2014 14:05:37 +0000 (10:05 -0400)
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>
fs/ceph/file.c
fs/ext4/extents.c
fs/ext4/inode.c
fs/open.c

index 09c7afe32e496c7dfe20d527106c7a184248c3ca..596e6cc9f9c4a173814b03905551334bdea143c4 100644 (file)
@@ -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) {
index ac5460d0d133706d4efd7a1e2affbb43e0c9b46c..b2d3869b576248ef1c980d62ef6178d416a262e0 100644 (file)
@@ -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;
index e2bba76f0d7bea6e0ca2b8e877b0593b10ace97a..b74cfd2a42ec319898befea19916e1a2c7db3645 100644 (file)
@@ -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;
index adf34202213a8bc6e5cb72e6546afebf595f82f7..7b823daa6a935ba7c65c5c19b16a50997146f39e 100644 (file)
--- a/fs/open.c
+++ b/fs/open.c
@@ -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.