Skip to content

Commit ea45466

Browse files
Younger Liutorvalds
authored andcommitted
ocfs2: need rollback when journal_access failed in ocfs2_orphan_add()
While adding a file into orphan dir in ocfs2_orphan_add(), it calls __ocfs2_add_entry() before ocfs2_journal_access_di(). If ocfs2_journal_access_di() failed, the file is added into orphan dir, and orphan dir dinode updated, but file dinode has not been updated. Accordingly, the data is not consistent between file dinode and orphan dir. So, need to call ocfs2_journal_access_di() before __ocfs2_add_entry(), and if ocfs2_journal_access_di() failed, orphan_fe and orphan_dir_inode->i_nlink need rollback. This bug was added by 3939fda ("Ocfs2: Journaling i_flags and i_orphaned_slot when adding inode to orphan dir."). Signed-off-by: Younger Liu <younger.liu@huawei.com> Acked-by: Jeff Liu <jeff.liu@oracle.com> Cc: Sunil Mushran <sunil.mushran@gmail.com> Cc: Mark Fasheh <mfasheh@suse.com> Cc: Joel Becker <jlbec@evilplan.org> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent 096b2ef commit ea45466

1 file changed

Lines changed: 23 additions & 18 deletions

File tree

‎fs/ocfs2/namei.c‎

Lines changed: 23 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2012,6 +2012,21 @@ static int ocfs2_orphan_add(struct ocfs2_super *osb,
20122012
goto leave;
20132013
}
20142014

2015+
/*
2016+
* We're going to journal the change of i_flags and i_orphaned_slot.
2017+
* It's safe anyway, though some callers may duplicate the journaling.
2018+
* Journaling within the func just make the logic look more
2019+
* straightforward.
2020+
*/
2021+
status = ocfs2_journal_access_di(handle,
2022+
INODE_CACHE(inode),
2023+
fe_bh,
2024+
OCFS2_JOURNAL_ACCESS_WRITE);
2025+
if (status < 0) {
2026+
mlog_errno(status);
2027+
goto leave;
2028+
}
2029+
20152030
/* we're a cluster, and nlink can change on disk from
20162031
* underneath us... */
20172032
orphan_fe = (struct ocfs2_dinode *) orphan_dir_bh->b_data;
@@ -2026,22 +2041,7 @@ static int ocfs2_orphan_add(struct ocfs2_super *osb,
20262041
orphan_dir_bh, lookup);
20272042
if (status < 0) {
20282043
mlog_errno(status);
2029-
goto leave;
2030-
}
2031-
2032-
/*
2033-
* We're going to journal the change of i_flags and i_orphaned_slot.
2034-
* It's safe anyway, though some callers may duplicate the journaling.
2035-
* Journaling within the func just make the logic look more
2036-
* straightforward.
2037-
*/
2038-
status = ocfs2_journal_access_di(handle,
2039-
INODE_CACHE(inode),
2040-
fe_bh,
2041-
OCFS2_JOURNAL_ACCESS_WRITE);
2042-
if (status < 0) {
2043-
mlog_errno(status);
2044-
goto leave;
2044+
goto rollback;
20452045
}
20462046

20472047
fe->i_flags |= cpu_to_le32(OCFS2_ORPHANED_FL);
@@ -2057,11 +2057,16 @@ static int ocfs2_orphan_add(struct ocfs2_super *osb,
20572057
trace_ocfs2_orphan_add_end((unsigned long long)OCFS2_I(inode)->ip_blkno,
20582058
osb->slot_num);
20592059

2060+
rollback:
2061+
if (status < 0) {
2062+
if (S_ISDIR(inode->i_mode))
2063+
ocfs2_add_links_count(orphan_fe, -1);
2064+
set_nlink(orphan_dir_inode, ocfs2_read_links_count(orphan_fe));
2065+
}
2066+
20602067
leave:
20612068
brelse(orphan_dir_bh);
20622069

2063-
if (status)
2064-
mlog_errno(status);
20652070
return status;
20662071
}
20672072

0 commit comments

Comments
 (0)