Skip to content

Commit 49887e4

Browse files
zhangyi089tytso
authored andcommitted
jbd2: cleanup journal_init_common()
Adjust the initialization sequence and error handle of journal_t, moving load superblock to the begin, and classify others initialization. Signed-off-by: Zhang Yi <[email protected]> Reviewed-by: Jan Kara <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Theodore Ts'o <[email protected]>
1 parent 0dbc759 commit 49887e4

File tree

1 file changed

+24
-21
lines changed

1 file changed

+24
-21
lines changed

fs/jbd2/journal.c

Lines changed: 24 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1533,6 +1533,16 @@ static journal_t *journal_init_common(struct block_device *bdev,
15331533
if (!journal)
15341534
return NULL;
15351535

1536+
journal->j_blocksize = blocksize;
1537+
journal->j_dev = bdev;
1538+
journal->j_fs_dev = fs_dev;
1539+
journal->j_blk_offset = start;
1540+
journal->j_total_len = len;
1541+
1542+
err = journal_load_superblock(journal);
1543+
if (err)
1544+
goto err_cleanup;
1545+
15361546
init_waitqueue_head(&journal->j_wait_transaction_locked);
15371547
init_waitqueue_head(&journal->j_wait_done_commit);
15381548
init_waitqueue_head(&journal->j_wait_commit);
@@ -1544,12 +1554,15 @@ static journal_t *journal_init_common(struct block_device *bdev,
15441554
mutex_init(&journal->j_checkpoint_mutex);
15451555
spin_lock_init(&journal->j_revoke_lock);
15461556
spin_lock_init(&journal->j_list_lock);
1557+
spin_lock_init(&journal->j_history_lock);
15471558
rwlock_init(&journal->j_state_lock);
15481559

15491560
journal->j_commit_interval = (HZ * JBD2_DEFAULT_MAX_COMMIT_AGE);
15501561
journal->j_min_batch_time = 0;
15511562
journal->j_max_batch_time = 15000; /* 15ms */
15521563
atomic_set(&journal->j_reserved_credits, 0);
1564+
lockdep_init_map(&journal->j_trans_commit_map, "jbd2_handle",
1565+
&jbd2_trans_commit_key, 0);
15531566

15541567
/* The journal is marked for error until we succeed with recovery! */
15551568
journal->j_flags = JBD2_ABORT;
@@ -1559,18 +1572,10 @@ static journal_t *journal_init_common(struct block_device *bdev,
15591572
if (err)
15601573
goto err_cleanup;
15611574

1562-
spin_lock_init(&journal->j_history_lock);
1563-
1564-
lockdep_init_map(&journal->j_trans_commit_map, "jbd2_handle",
1565-
&jbd2_trans_commit_key, 0);
1566-
1567-
/* journal descriptor can store up to n blocks -bzzz */
1568-
journal->j_blocksize = blocksize;
1569-
journal->j_dev = bdev;
1570-
journal->j_fs_dev = fs_dev;
1571-
journal->j_blk_offset = start;
1572-
journal->j_total_len = len;
1573-
/* We need enough buffers to write out full descriptor block. */
1575+
/*
1576+
* journal descriptor can store up to n blocks, we need enough
1577+
* buffers to write out full descriptor block.
1578+
*/
15741579
n = journal->j_blocksize / jbd2_min_tag_size();
15751580
journal->j_wbufsize = n;
15761581
journal->j_fc_wbuf = NULL;
@@ -1579,7 +1584,8 @@ static journal_t *journal_init_common(struct block_device *bdev,
15791584
if (!journal->j_wbuf)
15801585
goto err_cleanup;
15811586

1582-
err = journal_load_superblock(journal);
1587+
err = percpu_counter_init(&journal->j_checkpoint_jh_count, 0,
1588+
GFP_KERNEL);
15831589
if (err)
15841590
goto err_cleanup;
15851591

@@ -1588,21 +1594,18 @@ static journal_t *journal_init_common(struct block_device *bdev,
15881594
journal->j_shrinker.count_objects = jbd2_journal_shrink_count;
15891595
journal->j_shrinker.seeks = DEFAULT_SEEKS;
15901596
journal->j_shrinker.batch = journal->j_max_transaction_buffers;
1591-
1592-
if (percpu_counter_init(&journal->j_checkpoint_jh_count, 0, GFP_KERNEL))
1597+
err = register_shrinker(&journal->j_shrinker, "jbd2-journal:(%u:%u)",
1598+
MAJOR(bdev->bd_dev), MINOR(bdev->bd_dev));
1599+
if (err)
15931600
goto err_cleanup;
15941601

1595-
if (register_shrinker(&journal->j_shrinker, "jbd2-journal:(%u:%u)",
1596-
MAJOR(bdev->bd_dev), MINOR(bdev->bd_dev))) {
1597-
percpu_counter_destroy(&journal->j_checkpoint_jh_count);
1598-
goto err_cleanup;
1599-
}
16001602
return journal;
16011603

16021604
err_cleanup:
1603-
brelse(journal->j_sb_buffer);
1605+
percpu_counter_destroy(&journal->j_checkpoint_jh_count);
16041606
kfree(journal->j_wbuf);
16051607
jbd2_journal_destroy_revoke(journal);
1608+
journal_fail_superblock(journal);
16061609
kfree(journal);
16071610
return NULL;
16081611
}

0 commit comments

Comments
 (0)