提交 6cba611e 编写于 作者: Z Zhang Huan 提交者: Theodore Ts'o

jbd2: fix potential memory leak on transaction commit

There is potential memory leak of journal head in function
jbd2_journal_commit_transaction. The problem is that JBD2 will not
reclaim the journal head of commit record if error occurs or journal
is abotred.

I use the following script to reproduce this issue, on a RHEL6
system. I found it very easy to reproduce with async commit enabled.

mount /dev/sdb /mnt -o journal_checksum,journal_async_commit
touch /mnt/xxx
echo offline > /sys/block/sdb/device/state
sync
umount /mnt
rmmod ext4
rmmod jbd2

Removal of the jbd2 module will make slab complaining that
"cache `jbd2_journal_head': can't free all objects".
Signed-off-by: NZhang Huan <zhhuan@gmail.com>
Signed-off-by: N"Theodore Ts'o" <tytso@mit.edu>
上级 46e4690b
...@@ -105,6 +105,8 @@ static int journal_submit_commit_record(journal_t *journal, ...@@ -105,6 +105,8 @@ static int journal_submit_commit_record(journal_t *journal,
int ret; int ret;
struct timespec now = current_kernel_time(); struct timespec now = current_kernel_time();
*cbh = NULL;
if (is_journal_aborted(journal)) if (is_journal_aborted(journal))
return 0; return 0;
...@@ -806,7 +808,7 @@ void jbd2_journal_commit_transaction(journal_t *journal) ...@@ -806,7 +808,7 @@ void jbd2_journal_commit_transaction(journal_t *journal)
if (err) if (err)
__jbd2_journal_abort_hard(journal); __jbd2_journal_abort_hard(journal);
} }
if (!err && !is_journal_aborted(journal)) if (cbh)
err = journal_wait_on_commit_record(journal, cbh); err = journal_wait_on_commit_record(journal, cbh);
if (JBD2_HAS_INCOMPAT_FEATURE(journal, if (JBD2_HAS_INCOMPAT_FEATURE(journal,
JBD2_FEATURE_INCOMPAT_ASYNC_COMMIT) && JBD2_FEATURE_INCOMPAT_ASYNC_COMMIT) &&
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册