fs: Return EAGAIN when O_NONBLOCK write should block on frozen fs
Subsystems (8)
Jan Kara
maintainerPATCH 1/3 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.
--- fs/btrfs/file.c | 3 ++- fs/cifs/file.c | 3 ++- fs/fuse/file.c | 3 ++- fs/ntfs/file.c | 3 ++- fs/ocfs2/file.c | 3 ++- fs/splice.c | 3 ++- fs/xfs/xfs_file.c | 3 ++- include/linux/fs.h | 10 ++++++++++ mm/filemap.c | 3 ++- 9 files changed, 26 insertions(+), 8 deletions(-)
fs/btrfs/file.c +2 -1
@@ -1411,7 +1411,8 @@ static ssize_t btrfs_file_aio_write(struct kiocb *iocb,ssize_t err =0 ;size_t count, ocount; -sb_start_write (inode->i_sb); +if (!sb_start_file_write (file)) +return -EAGAIN ;mutex_lock (&inode->i_mutex);
fs/cifs/file.c +2 -1
@@ -2448,7 +2448,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
fs/fuse/file.c +2 -1
@@ -947,7 +947,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 */
fs/ntfs/file.c +2 -1
@@ -2118,7 +2118,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);
fs/ocfs2/file.c +2 -1
@@ -2265,7 +2265,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 ;
fs/splice.c +2 -1
@@ -996,7 +996,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);
fs/xfs/xfs_file.c +2 -1
@@ -771,7 +771,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 ;
include/linux/fs.h +10 -0
@@ -1401,6 +1401,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
mm/filemap.c +2 -1
@@ -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);
Signature · 1 line
1.7.1
Jan Kara
maintainerPATCH 2/3 fs: Fix hang with BSD accounting on frozen filesystem
When BSD process accounting is enabled and logs information to a filesystem which gets frozen, system easily becomes unusable because each attempt to account process information blocks. Thus e.g. every task gets blocked in exit.
It seems better to drop accounting information (which can already happen when filesystem is running out of space) instead of locking system up. So we open the accounting file with O_NONBLOCK.
--- kernel/acct.c | 3 ++- 1 files changed, 2 insertions(+), 1 deletions(-)
kernel/acct.c +2 -1
@@ -201,7 +201,8 @@ static int acct_on(struct filename *pathname)struct bsd_acct_struct *acct =NULL ;/* Difference from BSD - they don't do O_APPEND */ - file =file_open_name (pathname,O_WRONLY |O_APPEND |O_LARGEFILE ,0 ); + file =file_open_name (pathname, +O_WRONLY |O_APPEND |O_LARGEFILE |O_NONBLOCK ,0 );if (IS_ERR (file))return PTR_ERR (file);
Signature · 1 line
1.7.1
Jan Kara
maintainerPATCH 3/3 ocfs2: Add freeze protection to ocfs2_file_splice_write()
In reply to Jan Karaocfs2_file_splice_write() was missed when adding freeze protection to all write paths. Fix that.
--- fs/ocfs2/file.c | 4 ++++ 1 files changed, 4 insertions(+), 0 deletions(-)
fs/ocfs2/file.c +4 -0
@@ -2486,6 +2486,9 @@ static ssize_t ocfs2_file_splice_write(struct pipe_inode_info *pipe, out->f_path.dentry->d_name.len, out->f_path.dentry->d_name.name, len); +if (!sb_start_file_write (out)) +return -EAGAIN ; +if (pipe->inode)mutex_lock_nested (&pipe->inode->i_mutex,I_MUTEX_PARENT );
@@ -2527,6 +2530,7 @@ static ssize_t ocfs2_file_splice_write(struct pipe_inode_info *pipe,balance_dirty_pages_ratelimited_nr (mapping, nr_pages); } +sb_end_write (inode->i_sb);return ret; }
Signature · 1 line
1.7.1
Jan Kara
maintainerQuoted 2 lines · Jan Kara
When user asks for
O_NONBLOCKbehavior for a file descriptor, return EAGAIN instead of blocking on a frozen filesystem.
Ups, forgot to add version into the subject. This is v3 of the series.
Honza
Quoted 153 lines
Signed-off-by Jan Kara <[email protected]>--- fs/btrfs/file.c | 3 ++- fs/cifs/file.c | 3 ++- fs/fuse/file.c | 3 ++- fs/ntfs/file.c | 3 ++- fs/ocfs2/file.c | 3 ++- fs/splice.c | 3 ++- fs/xfs/xfs_file.c | 3 ++- include/linux/fs.h | 10 ++++++++++ mm/filemap.c | 3 ++- 9 files changed, 26 insertions(+), 8 deletions(-)fs/btrfs/file.c +2
-1@@ -1411,7 +1411,8 @@ static ssize_t btrfs_file_aio_write(struct kiocb *iocb,ssize_t err =0 ;size_t count, ocount; -sb_start_write (inode->i_sb); +if (!sb_start_file_write (file)) +return -EAGAIN ;mutex_lock (&inode->i_mutex);fs/cifs/file.c +2
-1@@ -2448,7 +2448,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 fs/fuse/file.c +2
-1@@ -947,7 +947,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 */ fs/ntfs/file.c +2
-1@@ -2118,7 +2118,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);fs/ocfs2/file.c +2
-1@@ -2265,7 +2265,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 ;fs/splice.c +2
-1@@ -996,7 +996,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);fs/xfs/xfs_file.c +2
-1@@ -771,7 +771,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 ;include/linux/fs.h +10
-0@@ -1401,6 +1401,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 mm/filemap.c +2
-1@@ -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);Signature · 6 lines
1.7.1 -- To unsubscribe from this list: send the line "unsubscribe linux-fsdevel" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Signature · 2 lines
Jan Kara <[email protected]> SUSE Labs, CR
Quoted 4 lines · Jan Kara
When user asks for
O_NONBLOCKbehavior for a file descriptor, return EAGAIN instead of blocking on a frozen filesystem.Signed-off-by Jan Kara <[email protected]>
Looks good.
Signature · 2 lines
Dave Chinner [email protected]
Jan Kara
maintainerQuoted 2 lines · Jan Kara
When user asks for
O_NONBLOCKbehavior for a file descriptor, return EAGAIN instead of blocking on a frozen filesystem.
Al, what do you think about these patches? They fix deadlock with BSD
process accounting and fs freezing...
Honza
Quoted 149 lines
Signed-off-by Jan Kara <[email protected]>--- fs/btrfs/file.c | 3 ++- fs/cifs/file.c | 3 ++- fs/fuse/file.c | 3 ++- fs/ntfs/file.c | 3 ++- fs/ocfs2/file.c | 3 ++- fs/splice.c | 3 ++- fs/xfs/xfs_file.c | 3 ++- include/linux/fs.h | 10 ++++++++++ mm/filemap.c | 3 ++- 9 files changed, 26 insertions(+), 8 deletions(-)fs/btrfs/file.c +2
-1@@ -1411,7 +1411,8 @@ static ssize_t btrfs_file_aio_write(struct kiocb *iocb,ssize_t err =0 ;size_t count, ocount; -sb_start_write (inode->i_sb); +if (!sb_start_file_write (file)) +return -EAGAIN ;mutex_lock (&inode->i_mutex);fs/cifs/file.c +2
-1@@ -2448,7 +2448,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 fs/fuse/file.c +2
-1@@ -947,7 +947,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 */ fs/ntfs/file.c +2
-1@@ -2118,7 +2118,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);fs/ocfs2/file.c +2
-1@@ -2265,7 +2265,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 ;fs/splice.c +2
-1@@ -996,7 +996,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);fs/xfs/xfs_file.c +2
-1@@ -771,7 +771,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 ;include/linux/fs.h +10
-0@@ -1401,6 +1401,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 mm/filemap.c +2
-1@@ -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);Signature · 1 line
1.7.1
Signature · 2 lines
Jan Kara <[email protected]> SUSE Labs, CR