diff options
author | Wengang Wang <wen.gang.wang@oracle.com> | 2018-11-16 18:08:25 -0500 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2018-11-18 13:15:09 -0500 |
commit | 5040f8df56fb90c7919f1c9b0b6e54c843437456 (patch) | |
tree | 4f85a758e8dcd76ff7320a2cc35412b9eff65dc7 | |
parent | f5f67cc0e0d3d17ee046ba83f831f267767b8554 (diff) |
ocfs2: free up write context when direct IO failed
The write context should also be freed even when direct IO failed.
Otherwise a memory leak is introduced and entries remain in
oi->ip_unwritten_list causing the following BUG later in unlink path:
ERROR: bug expression: !list_empty(&oi->ip_unwritten_list)
ERROR: Clear inode of 215043, inode has unwritten extents
...
Call Trace:
? __set_current_blocked+0x42/0x68
ocfs2_evict_inode+0x91/0x6a0 [ocfs2]
? bit_waitqueue+0x40/0x33
evict+0xdb/0x1af
iput+0x1a2/0x1f7
do_unlinkat+0x194/0x28f
SyS_unlinkat+0x1b/0x2f
do_syscall_64+0x79/0x1ae
entry_SYSCALL_64_after_hwframe+0x151/0x0
This patch also logs, with frequency limit, direct IO failures.
Link: http://lkml.kernel.org/r/20181102170632.25921-1-wen.gang.wang@oracle.com
Signed-off-by: Wengang Wang <wen.gang.wang@oracle.com>
Reviewed-by: Junxiao Bi <junxiao.bi@oracle.com>
Reviewed-by: Changwei Ge <ge.changwei@h3c.com>
Reviewed-by: Joseph Qi <jiangqi903@gmail.com>
Cc: Mark Fasheh <mark@fasheh.com>
Cc: Joel Becker <jlbec@evilplan.org>
Cc: <stable@vger.kernel.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
-rw-r--r-- | fs/ocfs2/aops.c | 12 | ||||
-rw-r--r-- | fs/ocfs2/cluster/masklog.h | 9 |
2 files changed, 19 insertions, 2 deletions
diff --git a/fs/ocfs2/aops.c b/fs/ocfs2/aops.c index da578ad4c08f..eb1ce30412dc 100644 --- a/fs/ocfs2/aops.c +++ b/fs/ocfs2/aops.c | |||
@@ -2411,8 +2411,16 @@ static int ocfs2_dio_end_io(struct kiocb *iocb, | |||
2411 | /* this io's submitter should not have unlocked this before we could */ | 2411 | /* this io's submitter should not have unlocked this before we could */ |
2412 | BUG_ON(!ocfs2_iocb_is_rw_locked(iocb)); | 2412 | BUG_ON(!ocfs2_iocb_is_rw_locked(iocb)); |
2413 | 2413 | ||
2414 | if (bytes > 0 && private) | 2414 | if (bytes <= 0) |
2415 | ret = ocfs2_dio_end_io_write(inode, private, offset, bytes); | 2415 | mlog_ratelimited(ML_ERROR, "Direct IO failed, bytes = %lld", |
2416 | (long long)bytes); | ||
2417 | if (private) { | ||
2418 | if (bytes > 0) | ||
2419 | ret = ocfs2_dio_end_io_write(inode, private, offset, | ||
2420 | bytes); | ||
2421 | else | ||
2422 | ocfs2_dio_free_write_ctx(inode, private); | ||
2423 | } | ||
2416 | 2424 | ||
2417 | ocfs2_iocb_clear_rw_locked(iocb); | 2425 | ocfs2_iocb_clear_rw_locked(iocb); |
2418 | 2426 | ||
diff --git a/fs/ocfs2/cluster/masklog.h b/fs/ocfs2/cluster/masklog.h index 308ea0eb35fd..a396096a5099 100644 --- a/fs/ocfs2/cluster/masklog.h +++ b/fs/ocfs2/cluster/masklog.h | |||
@@ -178,6 +178,15 @@ do { \ | |||
178 | ##__VA_ARGS__); \ | 178 | ##__VA_ARGS__); \ |
179 | } while (0) | 179 | } while (0) |
180 | 180 | ||
181 | #define mlog_ratelimited(mask, fmt, ...) \ | ||
182 | do { \ | ||
183 | static DEFINE_RATELIMIT_STATE(_rs, \ | ||
184 | DEFAULT_RATELIMIT_INTERVAL, \ | ||
185 | DEFAULT_RATELIMIT_BURST); \ | ||
186 | if (__ratelimit(&_rs)) \ | ||
187 | mlog(mask, fmt, ##__VA_ARGS__); \ | ||
188 | } while (0) | ||
189 | |||
181 | #define mlog_errno(st) ({ \ | 190 | #define mlog_errno(st) ({ \ |
182 | int _st = (st); \ | 191 | int _st = (st); \ |
183 | if (_st != -ERESTARTSYS && _st != -EINTR && \ | 192 | if (_st != -ERESTARTSYS && _st != -EINTR && \ |