* [PATCH 0/3 RESEND] Fix hang with BSD process accounting and fs freezing
@ 2012-12-22 1:07 Jan Kara
2012-12-22 1:07 ` [PATCH 1/3] fs: Return EAGAIN when O_NONBLOCK write should block on frozen fs Jan Kara
` (2 more replies)
0 siblings, 3 replies; 9+ messages in thread
From: Jan Kara @ 2012-12-22 1:07 UTC (permalink / raw)
To: Al Viro; +Cc: linux-fsdevel
Hello,
I'm resending my patch series to fix a deadlock when BSD process accounting
is logging into a filesystem that is frozen since I didn't see it in your
last pull request. Is there any problem with the patches or you just missed
them?
Honza
^ permalink raw reply [flat|nested] 9+ messages in thread
* [PATCH 1/3] fs: Return EAGAIN when O_NONBLOCK write should block on frozen fs
2012-12-22 1:07 [PATCH 0/3 RESEND] Fix hang with BSD process accounting and fs freezing Jan Kara
@ 2012-12-22 1:07 ` Jan Kara
2012-12-22 1:07 ` [PATCH 2/3] fs: Fix hang with BSD accounting on frozen filesystem Jan Kara
2012-12-22 1:07 ` [PATCH 3/3] ocfs2: Add freeze protection to ocfs2_file_splice_write() Jan Kara
2 siblings, 0 replies; 9+ messages in thread
From: Jan Kara @ 2012-12-22 1:07 UTC (permalink / raw)
To: Al Viro; +Cc: linux-fsdevel, Jan Kara
When user asks for O_NONBLOCK behavior for a file descriptor, return
EAGAIN instead of blocking on a frozen filesystem.
Reviewed-by: Dave Chinner <dchinner@redhat.com>
Signed-off-by: Jan Kara <jack@suse.cz>
---
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(-)
diff --git a/fs/btrfs/file.c b/fs/btrfs/file.c
index 77061bf..8418825 100644
--- a/fs/btrfs/file.c
+++ b/fs/btrfs/file.c
@@ -1495,7 +1495,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 0a6677b..b2c55ff 100644
--- a/fs/cifs/file.c
+++ b/fs/cifs/file.c
@@ -2474,7 +2474,8 @@ cifs_pagecache_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 e21d4d8..13a6d4b 100644
--- a/fs/fuse/file.c
+++ b/fs/fuse/file.c
@@ -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 */
diff --git a/fs/ntfs/file.c b/fs/ntfs/file.c
index 5b2d4f0..67fd7f9 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 37d313e..3898499 100644
--- a/fs/ocfs2/file.c
+++ b/fs/ocfs2/file.c
@@ -2247,7 +2247,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 8890604..5213a9a 100644
--- a/fs/splice.c
+++ b/fs/splice.c
@@ -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);
diff --git a/fs/xfs/xfs_file.c b/fs/xfs/xfs_file.c
index 67284ed..8299734 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 7617ee0..9f5e27c 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 83efee7..3b2812b 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);
--
1.7.1
^ permalink raw reply related [flat|nested] 9+ messages in thread
* [PATCH 2/3] fs: Fix hang with BSD accounting on frozen filesystem
2012-12-22 1:07 [PATCH 0/3 RESEND] Fix hang with BSD process accounting and fs freezing Jan Kara
2012-12-22 1:07 ` [PATCH 1/3] fs: Return EAGAIN when O_NONBLOCK write should block on frozen fs Jan Kara
@ 2012-12-22 1:07 ` Jan Kara
2012-12-22 1:07 ` [PATCH 3/3] ocfs2: Add freeze protection to ocfs2_file_splice_write() Jan Kara
2 siblings, 0 replies; 9+ messages in thread
From: Jan Kara @ 2012-12-22 1:07 UTC (permalink / raw)
To: Al Viro; +Cc: linux-fsdevel, Jan Kara
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.
Reported-and-tested-by: Nikola Ciprich <nikola.ciprich@linuxbox.cz>
Reviewed-by: Dave Chinner <dchinner@redhat.com>
Signed-off-by: Jan Kara <jack@suse.cz>
---
kernel/acct.c | 3 ++-
1 files changed, 2 insertions(+), 1 deletions(-)
diff --git a/kernel/acct.c b/kernel/acct.c
index 051e071..a061116 100644
--- a/kernel/acct.c
+++ b/kernel/acct.c
@@ -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);
--
1.7.1
^ permalink raw reply related [flat|nested] 9+ messages in thread
* [PATCH 3/3] ocfs2: Add freeze protection to ocfs2_file_splice_write()
2012-12-22 1:07 [PATCH 0/3 RESEND] Fix hang with BSD process accounting and fs freezing Jan Kara
2012-12-22 1:07 ` [PATCH 1/3] fs: Return EAGAIN when O_NONBLOCK write should block on frozen fs Jan Kara
2012-12-22 1:07 ` [PATCH 2/3] fs: Fix hang with BSD accounting on frozen filesystem Jan Kara
@ 2012-12-22 1:07 ` Jan Kara
2 siblings, 0 replies; 9+ messages in thread
From: Jan Kara @ 2012-12-22 1:07 UTC (permalink / raw)
To: Al Viro; +Cc: linux-fsdevel, Jan Kara, Joel Becker, ocfs2-devel
ocfs2_file_splice_write() was missed when adding freeze protection to all
write paths. Fix that.
CC: Joel Becker <jlbec@evilplan.org>
CC: ocfs2-devel@oss.oracle.com
Signed-off-by: Jan Kara <jack@suse.cz>
---
fs/ocfs2/file.c | 4 ++++
1 files changed, 4 insertions(+), 0 deletions(-)
diff --git a/fs/ocfs2/file.c b/fs/ocfs2/file.c
index 3898499..1f6916c 100644
--- a/fs/ocfs2/file.c
+++ b/fs/ocfs2/file.c
@@ -2468,6 +2468,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);
@@ -2506,6 +2509,7 @@ static ssize_t ocfs2_file_splice_write(struct pipe_inode_info *pipe,
balance_dirty_pages_ratelimited(mapping);
}
+ sb_end_write(inode->i_sb);
return ret;
}
--
1.7.1
^ permalink raw reply related [flat|nested] 9+ messages in thread
* [PATCH 0/3 RESEND] Fix hang of BSD accounting on frozen filesystem
@ 2013-02-07 14:52 Jan Kara
2013-02-07 14:52 ` [PATCH 1/3] fs: Return EAGAIN when O_NONBLOCK write should block on frozen fs Jan Kara
0 siblings, 1 reply; 9+ messages in thread
From: Jan Kara @ 2013-02-07 14:52 UTC (permalink / raw)
To: Al Viro; +Cc: linux-fsdevel
Al,
I'm trying to push this series to you for several months already but I
didn't get a word from you... This is a third resend or so. Can you
please share your opinion or merge it? Thanks! There is actually a user
who hit the deadlock...
Honza
^ permalink raw reply [flat|nested] 9+ messages in thread
* [PATCH 1/3] fs: Return EAGAIN when O_NONBLOCK write should block on frozen fs
2013-02-07 14:52 [PATCH 0/3 RESEND] Fix hang of BSD accounting on frozen filesystem Jan Kara
@ 2013-02-07 14:52 ` Jan Kara
0 siblings, 0 replies; 9+ messages in thread
From: Jan Kara @ 2013-02-07 14:52 UTC (permalink / raw)
To: Al Viro; +Cc: linux-fsdevel, Jan Kara
When user asks for O_NONBLOCK behavior for a file descriptor, return
EAGAIN instead of blocking on a frozen filesystem.
Reviewed-by: Dave Chinner <dchinner@redhat.com>
Signed-off-by: Jan Kara <jack@suse.cz>
---
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(-)
diff --git a/fs/btrfs/file.c b/fs/btrfs/file.c
index 77061bf..8418825 100644
--- a/fs/btrfs/file.c
+++ b/fs/btrfs/file.c
@@ -1495,7 +1495,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 0a6677b..b2c55ff 100644
--- a/fs/cifs/file.c
+++ b/fs/cifs/file.c
@@ -2474,7 +2474,8 @@ cifs_pagecache_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 e21d4d8..13a6d4b 100644
--- a/fs/fuse/file.c
+++ b/fs/fuse/file.c
@@ -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 */
diff --git a/fs/ntfs/file.c b/fs/ntfs/file.c
index 5b2d4f0..67fd7f9 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 37d313e..3898499 100644
--- a/fs/ocfs2/file.c
+++ b/fs/ocfs2/file.c
@@ -2247,7 +2247,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 8890604..5213a9a 100644
--- a/fs/splice.c
+++ b/fs/splice.c
@@ -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);
diff --git a/fs/xfs/xfs_file.c b/fs/xfs/xfs_file.c
index 67284ed..8299734 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 7617ee0..9f5e27c 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 83efee7..3b2812b 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);
--
1.7.1
^ permalink raw reply related [flat|nested] 9+ messages in thread
* [PATCH 1/3] fs: Return EAGAIN when O_NONBLOCK write should block on frozen fs
@ 2012-11-12 11:17 Jan Kara
2012-11-12 14:03 ` Jan Kara
` (2 more replies)
0 siblings, 3 replies; 9+ messages in thread
From: Jan Kara @ 2012-11-12 11:17 UTC (permalink / raw)
To: Al Viro; +Cc: linux-fsdevel, dchinner, Jan Kara
When user asks for O_NONBLOCK behavior for a file descriptor, return
EAGAIN instead of blocking on a frozen filesystem.
Signed-off-by: Jan Kara <jack@suse.cz>
---
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(-)
diff --git a/fs/btrfs/file.c b/fs/btrfs/file.c
index 9ab1bed..6eb2e30 100644
--- a/fs/btrfs/file.c
+++ b/fs/btrfs/file.c
@@ -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);
diff --git a/fs/cifs/file.c b/fs/cifs/file.c
index edb25b4..1629e47 100644
--- a/fs/cifs/file.c
+++ b/fs/cifs/file.c
@@ -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
diff --git a/fs/fuse/file.c b/fs/fuse/file.c
index 78d2837..641df9e 100644
--- a/fs/fuse/file.c
+++ b/fs/fuse/file.c
@@ -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 */
diff --git a/fs/ntfs/file.c b/fs/ntfs/file.c
index 1ecf464..028b349 100644
--- a/fs/ntfs/file.c
+++ b/fs/ntfs/file.c
@@ -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);
diff --git a/fs/ocfs2/file.c b/fs/ocfs2/file.c
index 5a4ee77..93ef34d 100644
--- a/fs/ocfs2/file.c
+++ b/fs/ocfs2/file.c
@@ -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;
diff --git a/fs/splice.c b/fs/splice.c
index 13e5b47..a5ae831 100644
--- a/fs/splice.c
+++ b/fs/splice.c
@@ -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);
diff --git a/fs/xfs/xfs_file.c b/fs/xfs/xfs_file.c
index aa473fa..7d8af61 100644
--- a/fs/xfs/xfs_file.c
+++ b/fs/xfs/xfs_file.c
@@ -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;
diff --git a/include/linux/fs.h b/include/linux/fs.h
index b33cfc9..2325e95 100644
--- a/include/linux/fs.h
+++ b/include/linux/fs.h
@@ -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
diff --git a/mm/filemap.c b/mm/filemap.c
index 83efee7..3b2812b 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);
--
1.7.1
^ permalink raw reply related [flat|nested] 9+ messages in thread
* Re: [PATCH 1/3] fs: Return EAGAIN when O_NONBLOCK write should block on frozen fs
2012-11-12 11:17 Jan Kara
@ 2012-11-12 14:03 ` Jan Kara
2012-11-12 23:37 ` Dave Chinner
2012-12-05 13:36 ` Jan Kara
2 siblings, 0 replies; 9+ messages in thread
From: Jan Kara @ 2012-11-12 14:03 UTC (permalink / raw)
To: Al Viro; +Cc: linux-fsdevel, dchinner, Jan Kara
On Mon 12-11-12 12:17:50, Jan Kara wrote:
> When user asks for O_NONBLOCK behavior 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
> Signed-off-by: Jan Kara <jack@suse.cz>
> ---
> 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(-)
>
> diff --git a/fs/btrfs/file.c b/fs/btrfs/file.c
> index 9ab1bed..6eb2e30 100644
> --- a/fs/btrfs/file.c
> +++ b/fs/btrfs/file.c
> @@ -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);
>
> diff --git a/fs/cifs/file.c b/fs/cifs/file.c
> index edb25b4..1629e47 100644
> --- a/fs/cifs/file.c
> +++ b/fs/cifs/file.c
> @@ -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
> diff --git a/fs/fuse/file.c b/fs/fuse/file.c
> index 78d2837..641df9e 100644
> --- a/fs/fuse/file.c
> +++ b/fs/fuse/file.c
> @@ -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 */
> diff --git a/fs/ntfs/file.c b/fs/ntfs/file.c
> index 1ecf464..028b349 100644
> --- a/fs/ntfs/file.c
> +++ b/fs/ntfs/file.c
> @@ -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);
> diff --git a/fs/ocfs2/file.c b/fs/ocfs2/file.c
> index 5a4ee77..93ef34d 100644
> --- a/fs/ocfs2/file.c
> +++ b/fs/ocfs2/file.c
> @@ -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;
> diff --git a/fs/splice.c b/fs/splice.c
> index 13e5b47..a5ae831 100644
> --- a/fs/splice.c
> +++ b/fs/splice.c
> @@ -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);
>
> diff --git a/fs/xfs/xfs_file.c b/fs/xfs/xfs_file.c
> index aa473fa..7d8af61 100644
> --- a/fs/xfs/xfs_file.c
> +++ b/fs/xfs/xfs_file.c
> @@ -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;
> diff --git a/include/linux/fs.h b/include/linux/fs.h
> index b33cfc9..2325e95 100644
> --- a/include/linux/fs.h
> +++ b/include/linux/fs.h
> @@ -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
> diff --git a/mm/filemap.c b/mm/filemap.c
> index 83efee7..3b2812b 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);
> --
> 1.7.1
>
> --
> To unsubscribe from this list: send the line "unsubscribe linux-fsdevel" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at http://vger.kernel.org/majordomo-info.html
--
Jan Kara <jack@suse.cz>
SUSE Labs, CR
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH 1/3] fs: Return EAGAIN when O_NONBLOCK write should block on frozen fs
2012-11-12 11:17 Jan Kara
2012-11-12 14:03 ` Jan Kara
@ 2012-11-12 23:37 ` Dave Chinner
2012-12-05 13:36 ` Jan Kara
2 siblings, 0 replies; 9+ messages in thread
From: Dave Chinner @ 2012-11-12 23:37 UTC (permalink / raw)
To: Jan Kara; +Cc: Al Viro, linux-fsdevel, dchinner
On Mon, Nov 12, 2012 at 12:17:50PM +0100, Jan Kara wrote:
> When user asks for O_NONBLOCK behavior for a file descriptor, return
> EAGAIN instead of blocking on a frozen filesystem.
>
> Signed-off-by: Jan Kara <jack@suse.cz>
Looks good.
Reviewed-by: Dave Chinner <dchinner@redhat.com>
--
Dave Chinner
david@fromorbit.com
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH 1/3] fs: Return EAGAIN when O_NONBLOCK write should block on frozen fs
2012-11-12 11:17 Jan Kara
2012-11-12 14:03 ` Jan Kara
2012-11-12 23:37 ` Dave Chinner
@ 2012-12-05 13:36 ` Jan Kara
2 siblings, 0 replies; 9+ messages in thread
From: Jan Kara @ 2012-12-05 13:36 UTC (permalink / raw)
To: Al Viro; +Cc: linux-fsdevel, dchinner, Jan Kara
On Mon 12-11-12 12:17:50, Jan Kara wrote:
> When user asks for O_NONBLOCK behavior 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
> Signed-off-by: Jan Kara <jack@suse.cz>
> ---
> 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(-)
>
> diff --git a/fs/btrfs/file.c b/fs/btrfs/file.c
> index 9ab1bed..6eb2e30 100644
> --- a/fs/btrfs/file.c
> +++ b/fs/btrfs/file.c
> @@ -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);
>
> diff --git a/fs/cifs/file.c b/fs/cifs/file.c
> index edb25b4..1629e47 100644
> --- a/fs/cifs/file.c
> +++ b/fs/cifs/file.c
> @@ -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
> diff --git a/fs/fuse/file.c b/fs/fuse/file.c
> index 78d2837..641df9e 100644
> --- a/fs/fuse/file.c
> +++ b/fs/fuse/file.c
> @@ -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 */
> diff --git a/fs/ntfs/file.c b/fs/ntfs/file.c
> index 1ecf464..028b349 100644
> --- a/fs/ntfs/file.c
> +++ b/fs/ntfs/file.c
> @@ -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);
> diff --git a/fs/ocfs2/file.c b/fs/ocfs2/file.c
> index 5a4ee77..93ef34d 100644
> --- a/fs/ocfs2/file.c
> +++ b/fs/ocfs2/file.c
> @@ -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;
> diff --git a/fs/splice.c b/fs/splice.c
> index 13e5b47..a5ae831 100644
> --- a/fs/splice.c
> +++ b/fs/splice.c
> @@ -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);
>
> diff --git a/fs/xfs/xfs_file.c b/fs/xfs/xfs_file.c
> index aa473fa..7d8af61 100644
> --- a/fs/xfs/xfs_file.c
> +++ b/fs/xfs/xfs_file.c
> @@ -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;
> diff --git a/include/linux/fs.h b/include/linux/fs.h
> index b33cfc9..2325e95 100644
> --- a/include/linux/fs.h
> +++ b/include/linux/fs.h
> @@ -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
> diff --git a/mm/filemap.c b/mm/filemap.c
> index 83efee7..3b2812b 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);
> --
> 1.7.1
>
--
Jan Kara <jack@suse.cz>
SUSE Labs, CR
^ permalink raw reply [flat|nested] 9+ messages in thread
end of thread, other threads:[~2013-02-07 14:52 UTC | newest]
Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-12-22 1:07 [PATCH 0/3 RESEND] Fix hang with BSD process accounting and fs freezing Jan Kara
2012-12-22 1:07 ` [PATCH 1/3] fs: Return EAGAIN when O_NONBLOCK write should block on frozen fs Jan Kara
2012-12-22 1:07 ` [PATCH 2/3] fs: Fix hang with BSD accounting on frozen filesystem Jan Kara
2012-12-22 1:07 ` [PATCH 3/3] ocfs2: Add freeze protection to ocfs2_file_splice_write() Jan Kara
-- strict thread matches above, loose matches on Subject: below --
2013-02-07 14:52 [PATCH 0/3 RESEND] Fix hang of BSD accounting on frozen filesystem Jan Kara
2013-02-07 14:52 ` [PATCH 1/3] fs: Return EAGAIN when O_NONBLOCK write should block on frozen fs Jan Kara
2012-11-12 11:17 Jan Kara
2012-11-12 14:03 ` Jan Kara
2012-11-12 23:37 ` Dave Chinner
2012-12-05 13:36 ` Jan Kara
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).