Skip to content

Commit ddf4b77

Browse files
josephhztorvalds
authored andcommitted
ocfs2: fix a deadlock when commit trans
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/[email protected] Fixes: 6f1b228 ("ocfs2: fix race between searching chunks and release journal_head from buffer_head") Signed-off-by: Joseph Qi <[email protected]> Reported-by: Gautham Ananthakrishna <[email protected]> Tested-by: Gautham Ananthakrishna <[email protected]> Reported-by: Saeed Mirzamohammadi <[email protected]> Cc: "Theodore Ts'o" <[email protected]> Cc: Andreas Dilger <[email protected]> Cc: Changwei Ge <[email protected]> Cc: Gang He <[email protected]> Cc: Joel Becker <[email protected]> Cc: Jun Piao <[email protected]> Cc: Junxiao Bi <[email protected]> Cc: Mark Fasheh <[email protected]> Cc: <[email protected]> Signed-off-by: Andrew Morton <[email protected]> Signed-off-by: Linus Torvalds <[email protected]>
1 parent 4cd1103 commit ddf4b77

File tree

1 file changed

+11
-14
lines changed

1 file changed

+11
-14
lines changed

fs/ocfs2/suballoc.c

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

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

1259-
if (!buffer_jbd(bg_bh))
1259+
jh = jbd2_journal_grab_journal_head(bg_bh);
1260+
if (!jh)
12601261
return 1;
12611262

1262-
jbd_lock_bh_journal_head(bg_bh);
1263-
if (buffer_jbd(bg_bh)) {
1264-
jh = bh2jh(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-
}
1273-
jbd_unlock_bh_journal_head(bg_bh);
1263+
spin_lock(&jh->b_state_lock);
1264+
bg = (struct ocfs2_group_desc *) jh->b_committed_data;
1265+
if (bg)
1266+
ret = !ocfs2_test_bit(nr, (unsigned long *)bg->bg_bitmap);
1267+
else
1268+
ret = 1;
1269+
spin_unlock(&jh->b_state_lock);
1270+
jbd2_journal_put_journal_head(jh);
12741271

12751272
return ret;
12761273
}

0 commit comments

Comments
 (0)