]> git.karo-electronics.de Git - karo-tx-linux.git/commitdiff
fs: return EAGAIN when O_NONBLOCK write should block on frozen fs
authorJan Kara <jack@suse.cz>
Wed, 20 Feb 2013 02:13:56 +0000 (13:13 +1100)
committerStephen Rothwell <sfr@canb.auug.org.au>
Wed, 20 Feb 2013 05:52:18 +0000 (16:52 +1100)
When user asks for O_NONBLOCK behavior for a file descriptor, return
EAGAIN instead of blocking on a frozen filesystem.

This is needed so we can fix a hang with BSD accounting on frozen
filesystems.

Signed-off-by: Jan Kara <jack@suse.cz>
Reviewed-by: Dave Chinner <dchinner@redhat.com>
Cc: Al Viro <viro@ZenIV.linux.org.uk>
Acked-by: Joel Becker <jlbec@evilplan.org>
Cc: Mark Fasheh <mfasheh@suse.com>
Cc: Nikola Ciprich <nikola.ciprich@linuxbox.cz>
Cc: Marco Stornelli <marco.stornelli@gmail.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
fs/btrfs/file.c
fs/cifs/file.c
fs/fuse/file.c
fs/ntfs/file.c
fs/ocfs2/file.c
fs/splice.c
fs/xfs/xfs_file.c
include/linux/fs.h
mm/filemap.c

index aeb84469d2c4c0621b002084617578f7ac5f49b1..b7c956cc68c32b4829ff0b478986bbfb5e506b0d 100644 (file)
@@ -1509,7 +1509,8 @@ static ssize_t btrfs_file_aio_write(struct kiocb *iocb,
        size_t count, ocount;
        bool sync = (file->f_flags & O_DSYNC) || IS_SYNC(file->f_mapping->host);
 
-       sb_start_write(inode->i_sb);
+       if (!sb_start_file_write(file))
+               return -EAGAIN;
 
        mutex_lock(&inode->i_mutex);
 
index 7936218536a9b49b831b1efdfe94e294e65382a6..30a1b84e160bcdc76ed36b7f6a6e05acb8138bb8 100644 (file)
@@ -2516,7 +2516,8 @@ cifs_writev(struct kiocb *iocb, const struct iovec *iov,
 
        BUG_ON(iocb->ki_pos != pos);
 
-       sb_start_write(inode->i_sb);
+       if (!sb_start_file_write(file))
+               return -EAGAIN;
 
        /*
         * We need to hold the sem to be sure nobody modifies lock list
index c8071768b9503455f592ff9aac80b71e3a922688..bb939ebf0e8001cd177dbfc5e2a9e61731f799dd 100644 (file)
@@ -971,7 +971,8 @@ static ssize_t fuse_file_aio_write(struct kiocb *iocb, const struct iovec *iov,
                return err;
 
        count = ocount;
-       sb_start_write(inode->i_sb);
+       if (!sb_start_file_write(file))
+               return -EAGAIN;
        mutex_lock(&inode->i_mutex);
 
        /* We can write back this queue in page reclaim */
index 5b2d4f0853acfad180c03d9c10764b3199e31089..67fd7f9f6a97e6080b0c419becd6071c1188409e 100644 (file)
@@ -2129,7 +2129,8 @@ static ssize_t ntfs_file_aio_write(struct kiocb *iocb, const struct iovec *iov,
 
        BUG_ON(iocb->ki_pos != pos);
 
-       sb_start_write(inode->i_sb);
+       if (!sb_start_file_write(file))
+               return -EAGAIN;
        mutex_lock(&inode->i_mutex);
        ret = ntfs_file_aio_write_nolock(iocb, iov, nr_segs, &iocb->ki_pos);
        mutex_unlock(&inode->i_mutex);
index 0a2924a2d9e6e83d62428fcc975a3ce6d1c5cde4..b5fc161bce79692f3d1e4ed67c4572984e2b1f72 100644 (file)
@@ -2248,7 +2248,8 @@ static ssize_t ocfs2_file_aio_write(struct kiocb *iocb,
        if (iocb->ki_left == 0)
                return 0;
 
-       sb_start_write(inode->i_sb);
+       if (!sb_start_file_write(file))
+               return -EAGAIN;
 
        appending = file->f_flags & O_APPEND ? 1 : 0;
        direct_io = file->f_flags & O_DIRECT ? 1 : 0;
index 6909d89d0da56ffd929a2114b0228a03d1f35589..6a08e16e7f144e424d78ff288a16246513cfc61e 100644 (file)
@@ -998,7 +998,8 @@ generic_file_splice_write(struct pipe_inode_info *pipe, struct file *out,
        };
        ssize_t ret;
 
-       sb_start_write(inode->i_sb);
+       if (!sb_start_file_write(out))
+               return -EAGAIN;
 
        pipe_lock(pipe);
 
index 67284edb84d74d2156283c3c34e1b28d179b4861..8299734ac5a803498bafe5dd9a2b7911da1a344d 100644 (file)
@@ -775,7 +775,8 @@ xfs_file_aio_write(
        if (ocount == 0)
                return 0;
 
-       sb_start_write(inode->i_sb);
+       if (!sb_start_file_write(file))
+               return -EAGAIN;
 
        if (XFS_FORCED_SHUTDOWN(ip->i_mount)) {
                ret = -EIO;
index 7d2e893ec3d1903ed4600a00a39221cd14fa3beb..d34254551c61a2a44214ee8ea6c5b2c8bf46e76c 100644 (file)
@@ -1400,6 +1400,16 @@ static inline int sb_start_write_trylock(struct super_block *sb)
        return __sb_start_write(sb, SB_FREEZE_WRITE, false);
 }
 
+/*
+ * sb_start_write() for writing into a file. When file has O_NONBLOCK set,
+ * we use trylock semantics, otherwise we block on frozen filesystem.
+ */
+static inline int sb_start_file_write(struct file *file)
+{
+       return __sb_start_write(file->f_mapping->host->i_sb, SB_FREEZE_WRITE,
+                               !(file->f_flags & O_NONBLOCK));
+}
+
 /**
  * sb_start_pagefault - get write access to a superblock from a page fault
  * @sb: the super we write to
index 24a7ea583f0cf4039525d824ac047f5f9d7eddb0..5e42dd819463e5186e8f4f3bf668735151155761 100644 (file)
@@ -2527,7 +2527,8 @@ ssize_t generic_file_aio_write(struct kiocb *iocb, const struct iovec *iov,
 
        BUG_ON(iocb->ki_pos != pos);
 
-       sb_start_write(inode->i_sb);
+       if (!sb_start_file_write(file))
+               return -EAGAIN;
        mutex_lock(&inode->i_mutex);
        ret = __generic_file_aio_write(iocb, iov, nr_segs, &iocb->ki_pos);
        mutex_unlock(&inode->i_mutex);