From: Jan Kara Date: Wed, 20 Feb 2013 02:13:56 +0000 (+1100) Subject: fs: return EAGAIN when O_NONBLOCK write should block on frozen fs X-Git-Tag: next-20130220~1^2~600 X-Git-Url: https://git.karo-electronics.de/?a=commitdiff_plain;h=bac37da448ce96d55ec65e978d03f3563845e979;p=karo-tx-linux.git fs: return EAGAIN when O_NONBLOCK write should block on frozen fs 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 Reviewed-by: Dave Chinner Cc: Al Viro Acked-by: Joel Becker Cc: Mark Fasheh Cc: Nikola Ciprich Cc: Marco Stornelli Signed-off-by: Andrew Morton --- diff --git a/fs/btrfs/file.c b/fs/btrfs/file.c index aeb84469d2c4..b7c956cc68c3 100644 --- a/fs/btrfs/file.c +++ b/fs/btrfs/file.c @@ -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); diff --git a/fs/cifs/file.c b/fs/cifs/file.c index 7936218536a9..30a1b84e160b 100644 --- a/fs/cifs/file.c +++ b/fs/cifs/file.c @@ -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 diff --git a/fs/fuse/file.c b/fs/fuse/file.c index c8071768b950..bb939ebf0e80 100644 --- a/fs/fuse/file.c +++ b/fs/fuse/file.c @@ -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 */ diff --git a/fs/ntfs/file.c b/fs/ntfs/file.c index 5b2d4f0853ac..67fd7f9f6a97 100644 --- a/fs/ntfs/file.c +++ b/fs/ntfs/file.c @@ -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); diff --git a/fs/ocfs2/file.c b/fs/ocfs2/file.c index 0a2924a2d9e6..b5fc161bce79 100644 --- a/fs/ocfs2/file.c +++ b/fs/ocfs2/file.c @@ -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; diff --git a/fs/splice.c b/fs/splice.c index 6909d89d0da5..6a08e16e7f14 100644 --- a/fs/splice.c +++ b/fs/splice.c @@ -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); diff --git a/fs/xfs/xfs_file.c b/fs/xfs/xfs_file.c index 67284edb84d7..8299734ac5a8 100644 --- a/fs/xfs/xfs_file.c +++ b/fs/xfs/xfs_file.c @@ -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; diff --git a/include/linux/fs.h b/include/linux/fs.h index 7d2e893ec3d1..d34254551c61 100644 --- a/include/linux/fs.h +++ b/include/linux/fs.h @@ -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 diff --git a/mm/filemap.c b/mm/filemap.c index 24a7ea583f0c..5e42dd819463 100644 --- a/mm/filemap.c +++ b/mm/filemap.c @@ -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);