Skip to content

Commit 37c69b9

Browse files
fweisbectorvalds
authored andcommitted
reiserfs: don't lock journal_init()
journal_init() doesn't need the lock since no operation on the filesystem is involved there. journal_read() and get_list_bitmap() have yet to be reviewed carefully though before removing the lock there. Just keep the it around these two calls for safety. Signed-off-by: Frederic Weisbecker <[email protected]> Cc: Al Viro <[email protected]> Cc: Christoph Hellwig <[email protected]> Cc: Jeff Mahoney <[email protected]> Cc: Jan Kara <[email protected]> Signed-off-by: Andrew Morton <[email protected]> Signed-off-by: Linus Torvalds <[email protected]>
1 parent f32485b commit 37c69b9

File tree

2 files changed

+31
-43
lines changed

2 files changed

+31
-43
lines changed

fs/reiserfs/journal.c

Lines changed: 20 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -2678,27 +2678,19 @@ int journal_init(struct super_block *sb, const char *j_dev_name,
26782678
char b[BDEVNAME_SIZE];
26792679
int ret;
26802680

2681-
/*
2682-
* Unlock here to avoid various RECLAIM-FS-ON <-> IN-RECLAIM-FS
2683-
* dependency inversion warnings.
2684-
*/
2685-
reiserfs_write_unlock(sb);
26862681
journal = SB_JOURNAL(sb) = vzalloc(sizeof(struct reiserfs_journal));
26872682
if (!journal) {
26882683
reiserfs_warning(sb, "journal-1256",
26892684
"unable to get memory for journal structure");
2690-
reiserfs_write_lock(sb);
26912685
return 1;
26922686
}
26932687
INIT_LIST_HEAD(&journal->j_bitmap_nodes);
26942688
INIT_LIST_HEAD(&journal->j_prealloc_list);
26952689
INIT_LIST_HEAD(&journal->j_working_list);
26962690
INIT_LIST_HEAD(&journal->j_journal_list);
26972691
journal->j_persistent_trans = 0;
2698-
ret = reiserfs_allocate_list_bitmaps(sb, journal->j_list_bitmap,
2699-
reiserfs_bmap_count(sb));
2700-
reiserfs_write_lock(sb);
2701-
if (ret)
2692+
if (reiserfs_allocate_list_bitmaps(sb, journal->j_list_bitmap,
2693+
reiserfs_bmap_count(sb)))
27022694
goto free_and_return;
27032695

27042696
allocate_bitmap_nodes(sb);
@@ -2727,27 +2719,11 @@ int journal_init(struct super_block *sb, const char *j_dev_name,
27272719
goto free_and_return;
27282720
}
27292721

2730-
/*
2731-
* We need to unlock here to avoid creating the following
2732-
* dependency:
2733-
* reiserfs_lock -> sysfs_mutex
2734-
* Because the reiserfs mmap path creates the following dependency:
2735-
* mm->mmap -> reiserfs_lock, hence we have
2736-
* mm->mmap -> reiserfs_lock ->sysfs_mutex
2737-
* This would ends up in a circular dependency with sysfs readdir path
2738-
* which does sysfs_mutex -> mm->mmap_sem
2739-
* This is fine because the reiserfs lock is useless in mount path,
2740-
* at least until we call journal_begin. We keep it for paranoid
2741-
* reasons.
2742-
*/
2743-
reiserfs_write_unlock(sb);
27442722
if (journal_init_dev(sb, journal, j_dev_name) != 0) {
2745-
reiserfs_write_lock(sb);
27462723
reiserfs_warning(sb, "sh-462",
27472724
"unable to initialize jornal device");
27482725
goto free_and_return;
27492726
}
2750-
reiserfs_write_lock(sb);
27512727

27522728
rs = SB_DISK_SUPER_BLOCK(sb);
27532729

@@ -2829,9 +2805,7 @@ int journal_init(struct super_block *sb, const char *j_dev_name,
28292805
journal->j_mount_id = 10;
28302806
journal->j_state = 0;
28312807
atomic_set(&(journal->j_jlock), 0);
2832-
reiserfs_write_unlock(sb);
28332808
journal->j_cnode_free_list = allocate_cnodes(num_cnodes);
2834-
reiserfs_write_lock(sb);
28352809
journal->j_cnode_free_orig = journal->j_cnode_free_list;
28362810
journal->j_cnode_free = journal->j_cnode_free_list ? num_cnodes : 0;
28372811
journal->j_cnode_used = 0;
@@ -2848,24 +2822,37 @@ int journal_init(struct super_block *sb, const char *j_dev_name,
28482822

28492823
init_journal_hash(sb);
28502824
jl = journal->j_current_jl;
2825+
2826+
/*
2827+
* get_list_bitmap() may call flush_commit_list() which
2828+
* requires the lock. Calling flush_commit_list() shouldn't happen
2829+
* this early but I like to be paranoid.
2830+
*/
2831+
reiserfs_write_lock(sb);
28512832
jl->j_list_bitmap = get_list_bitmap(sb, jl);
2833+
reiserfs_write_unlock(sb);
28522834
if (!jl->j_list_bitmap) {
28532835
reiserfs_warning(sb, "journal-2005",
28542836
"get_list_bitmap failed for journal list 0");
28552837
goto free_and_return;
28562838
}
2857-
if (journal_read(sb) < 0) {
2839+
2840+
/*
2841+
* Journal_read needs to be inspected in order to push down
2842+
* the lock further inside (or even remove it).
2843+
*/
2844+
reiserfs_write_lock(sb);
2845+
ret = journal_read(sb);
2846+
reiserfs_write_unlock(sb);
2847+
if (ret < 0) {
28582848
reiserfs_warning(sb, "reiserfs-2006",
28592849
"Replay Failure, unable to mount");
28602850
goto free_and_return;
28612851
}
28622852

28632853
reiserfs_mounted_fs_count++;
2864-
if (reiserfs_mounted_fs_count <= 1) {
2865-
reiserfs_write_unlock(sb);
2854+
if (reiserfs_mounted_fs_count <= 1)
28662855
commit_wq = alloc_workqueue("reiserfs", WQ_MEM_RECLAIM, 0);
2867-
reiserfs_write_lock(sb);
2868-
}
28692856

28702857
INIT_DELAYED_WORK(&journal->j_work, flush_async_commits);
28712858
journal->j_work_sb = sb;

fs/reiserfs/super.c

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1826,6 +1826,17 @@ static int reiserfs_fill_super(struct super_block *s, void *data, int silent)
18261826
printk("reiserfs: using flush barriers\n");
18271827
}
18281828

1829+
// set_device_ro(s->s_dev, 1) ;
1830+
if (journal_init(s, jdev_name, old_format, commit_max_age)) {
1831+
SWARN(silent, s, "sh-2022",
1832+
"unable to initialize journal space");
1833+
goto error_unlocked;
1834+
} else {
1835+
jinit_done = 1; /* once this is set, journal_release must be called
1836+
** if we error out of the mount
1837+
*/
1838+
}
1839+
18291840
/*
18301841
* This path assumed to be called with the BKL in the old times.
18311842
* Now we have inherited the big reiserfs lock from it and many
@@ -1836,16 +1847,6 @@ static int reiserfs_fill_super(struct super_block *s, void *data, int silent)
18361847
*/
18371848
reiserfs_write_lock(s);
18381849

1839-
// set_device_ro(s->s_dev, 1) ;
1840-
if (journal_init(s, jdev_name, old_format, commit_max_age)) {
1841-
SWARN(silent, s, "sh-2022",
1842-
"unable to initialize journal space");
1843-
goto error;
1844-
} else {
1845-
jinit_done = 1; /* once this is set, journal_release must be called
1846-
** if we error out of the mount
1847-
*/
1848-
}
18491850
if (reread_meta_blocks(s)) {
18501851
SWARN(silent, s, "jmacd-9",
18511852
"unable to reread meta blocks after journal init");

0 commit comments

Comments
 (0)