Skip to content

Commit afbde45

Browse files
josephhzgregkh
authored andcommitted
ocfs2: fix a deadlock when commit trans
commit ddf4b77 upstream. commit 6f1b228 introduces a regression which can deadlock as follows: Task1: Task2: jbd2_journal_commit_transaction ocfs2_test_bg_bit_allocatable spin_lock(&jh->b_state_lock) jbd_lock_bh_journal_head __jbd2_journal_remove_checkpoint spin_lock(&jh->b_state_lock) jbd2_journal_put_journal_head jbd_lock_bh_journal_head Task1 and Task2 lock bh->b_state and jh->b_state_lock in different order, which finally result in a deadlock. So use jbd2_journal_[grab|put]_journal_head instead in ocfs2_test_bg_bit_allocatable() to fix it. Link: https://lkml.kernel.org/r/20220121071205.100648-3-joseph.qi@linux.alibaba.com Fixes: 6f1b228 ("ocfs2: fix race between searching chunks and release journal_head from buffer_head") Signed-off-by: Joseph Qi <joseph.qi@linux.alibaba.com> Reported-by: Gautham Ananthakrishna <gautham.ananthakrishna@oracle.com> Tested-by: Gautham Ananthakrishna <gautham.ananthakrishna@oracle.com> Reported-by: Saeed Mirzamohammadi <saeed.mirzamohammadi@oracle.com> Cc: "Theodore Ts'o" <tytso@mit.edu> Cc: Andreas Dilger <adilger.kernel@dilger.ca> Cc: Changwei Ge <gechangwei@live.cn> Cc: Gang He <ghe@suse.com> Cc: Joel Becker <jlbec@evilplan.org> Cc: Jun Piao <piaojun@huawei.com> Cc: Junxiao Bi <junxiao.bi@oracle.com> Cc: Mark Fasheh <mark@fasheh.com> Cc: <stable@vger.kernel.org> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 97f75e7 commit afbde45

1 file changed

Lines changed: 11 additions & 14 deletions

File tree

‎fs/ocfs2/suballoc.c‎

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1253,26 +1253,23 @@ static int ocfs2_test_bg_bit_allocatable(struct buffer_head *bg_bh,
12531253
{
12541254
struct ocfs2_group_desc *bg = (struct ocfs2_group_desc *) bg_bh->b_data;
12551255
struct journal_head *jh;
1256-
int ret = 1;
1256+
int ret;
12571257

12581258
if (ocfs2_test_bit(nr, (unsigned long *)bg->bg_bitmap))
12591259
return 0;
12601260

1261-
if (!buffer_jbd(bg_bh))
1261+
jh = jbd2_journal_grab_journal_head(bg_bh);
1262+
if (!jh)
12621263
return 1;
12631264

1264-
jbd_lock_bh_journal_head(bg_bh);
1265-
if (buffer_jbd(bg_bh)) {
1266-
jh = bh2jh(bg_bh);
1267-
spin_lock(&jh->b_state_lock);
1268-
bg = (struct ocfs2_group_desc *) jh->b_committed_data;
1269-
if (bg)
1270-
ret = !ocfs2_test_bit(nr, (unsigned long *)bg->bg_bitmap);
1271-
else
1272-
ret = 1;
1273-
spin_unlock(&jh->b_state_lock);
1274-
}
1275-
jbd_unlock_bh_journal_head(bg_bh);
1265+
spin_lock(&jh->b_state_lock);
1266+
bg = (struct ocfs2_group_desc *) jh->b_committed_data;
1267+
if (bg)
1268+
ret = !ocfs2_test_bit(nr, (unsigned long *)bg->bg_bitmap);
1269+
else
1270+
ret = 1;
1271+
spin_unlock(&jh->b_state_lock);
1272+
jbd2_journal_put_journal_head(jh);
12761273

12771274
return ret;
12781275
}

0 commit comments

Comments
 (0)