Skip to content

Commit b8a052d

Browse files
Eric Sandeenjankara
authored andcommitted
ext3: Replace lock/unlock_super() with an explicit lock for the orphan list
Use a separate lock to protect the orphan list, so we can stop overloading the use of lock_super(). Port of ext4 commit 3b9d4ed by Theodore Ts'o <tytso@mit.edu>. CC: Theodore Ts'o <tytso@mit.edu> Signed-off-by: Eric Sandeen <sandeen@redhat.com> Signed-off-by: Jan Kara <jack@suse.cz>
1 parent 4854a5f commit b8a052d

3 files changed

Lines changed: 13 additions & 9 deletions

File tree

‎fs/ext3/namei.c‎

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1920,7 +1920,7 @@ int ext3_orphan_add(handle_t *handle, struct inode *inode)
19201920
struct ext3_iloc iloc;
19211921
int err = 0, rc;
19221922

1923-
lock_super(sb);
1923+
mutex_lock(&EXT3_SB(sb)->s_orphan_lock);
19241924
if (!list_empty(&EXT3_I(inode)->i_orphan))
19251925
goto out_unlock;
19261926

@@ -1929,9 +1929,13 @@ int ext3_orphan_add(handle_t *handle, struct inode *inode)
19291929

19301930
/* @@@ FIXME: Observation from aviro:
19311931
* I think I can trigger J_ASSERT in ext3_orphan_add(). We block
1932-
* here (on lock_super()), so race with ext3_link() which might bump
1932+
* here (on s_orphan_lock), so race with ext3_link() which might bump
19331933
* ->i_nlink. For, say it, character device. Not a regular file,
19341934
* not a directory, not a symlink and ->i_nlink > 0.
1935+
*
1936+
* tytso, 4/25/2009: I'm not sure how that could happen;
1937+
* shouldn't the fs core protect us from these sort of
1938+
* unlink()/link() races?
19351939
*/
19361940
J_ASSERT ((S_ISREG(inode->i_mode) || S_ISDIR(inode->i_mode) ||
19371941
S_ISLNK(inode->i_mode)) || inode->i_nlink == 0);
@@ -1968,7 +1972,7 @@ int ext3_orphan_add(handle_t *handle, struct inode *inode)
19681972
jbd_debug(4, "orphan inode %lu will point to %d\n",
19691973
inode->i_ino, NEXT_ORPHAN(inode));
19701974
out_unlock:
1971-
unlock_super(sb);
1975+
mutex_unlock(&EXT3_SB(sb)->s_orphan_lock);
19721976
ext3_std_error(inode->i_sb, err);
19731977
return err;
19741978
}
@@ -1986,11 +1990,9 @@ int ext3_orphan_del(handle_t *handle, struct inode *inode)
19861990
struct ext3_iloc iloc;
19871991
int err = 0;
19881992

1989-
lock_super(inode->i_sb);
1990-
if (list_empty(&ei->i_orphan)) {
1991-
unlock_super(inode->i_sb);
1992-
return 0;
1993-
}
1993+
mutex_lock(&EXT3_SB(inode->i_sb)->s_orphan_lock);
1994+
if (list_empty(&ei->i_orphan))
1995+
goto out;
19941996

19951997
ino_next = NEXT_ORPHAN(inode);
19961998
prev = ei->i_orphan.prev;
@@ -2040,7 +2042,7 @@ int ext3_orphan_del(handle_t *handle, struct inode *inode)
20402042
out_err:
20412043
ext3_std_error(inode->i_sb, err);
20422044
out:
2043-
unlock_super(inode->i_sb);
2045+
mutex_unlock(&EXT3_SB(inode->i_sb)->s_orphan_lock);
20442046
return err;
20452047

20462048
out_brelse:

‎fs/ext3/super.c‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1928,6 +1928,7 @@ static int ext3_fill_super (struct super_block *sb, void *data, int silent)
19281928
sb->dq_op = &ext3_quota_operations;
19291929
#endif
19301930
INIT_LIST_HEAD(&sbi->s_orphan); /* unlinked but open files */
1931+
mutex_init(&sbi->s_orphan_lock);
19311932

19321933
sb->s_root = NULL;
19331934

‎include/linux/ext3_fs_sb.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ struct ext3_sb_info {
7272
struct inode * s_journal_inode;
7373
struct journal_s * s_journal;
7474
struct list_head s_orphan;
75+
struct mutex s_orphan_lock;
7576
unsigned long s_commit_interval;
7677
struct block_device *journal_bdev;
7778
#ifdef CONFIG_JBD_DEBUG

0 commit comments

Comments
 (0)