Skip to content

Commit ad69482

Browse files
josephhztorvalds
authored andcommitted
ocfs2: fix race between crashed dio and rm
There is a race case between crashed dio and rm, which will lead to OCFS2_VALID_FL not set read-only. N1 N2 ------------------------------------------------------------------------ dd with direct flag rm file crashed with an dio entry left in orphan dir clear OCFS2_VALID_FL in ocfs2_remove_inode recover N1 and read the corrupted inode, and set filesystem read-only So we skip the inode deletion this time and wait for dio entry recovered first. Signed-off-by: Joseph Qi <joseph.qi@huawei.com> Reviewed-by: Mark Fasheh <mfasheh@suse.de> 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 f57a22d commit ad69482

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

fs/ocfs2/inode.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -971,6 +971,7 @@ static void ocfs2_delete_inode(struct inode *inode)
971971
int wipe, status;
972972
sigset_t oldset;
973973
struct buffer_head *di_bh = NULL;
974+
struct ocfs2_dinode *di = NULL;
974975

975976
trace_ocfs2_delete_inode(inode->i_ino,
976977
(unsigned long long)OCFS2_I(inode)->ip_blkno,
@@ -1025,6 +1026,14 @@ static void ocfs2_delete_inode(struct inode *inode)
10251026
goto bail_unlock_nfs_sync;
10261027
}
10271028

1029+
di = (struct ocfs2_dinode *)di_bh->b_data;
1030+
/* Skip inode deletion and wait for dio orphan entry recovered
1031+
* first */
1032+
if (unlikely(di->i_flags & cpu_to_le32(OCFS2_DIO_ORPHANED_FL))) {
1033+
ocfs2_cleanup_delete_inode(inode, 0);
1034+
goto bail_unlock_inode;
1035+
}
1036+
10281037
/* Query the cluster. This will be the final decision made
10291038
* before we go ahead and wipe the inode. */
10301039
status = ocfs2_query_inode_wipe(inode, di_bh, &wipe);

fs/ocfs2/journal.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2210,7 +2210,9 @@ static int ocfs2_recover_orphans(struct ocfs2_super *osb,
22102210
* ocfs2_delete_inode. */
22112211
oi->ip_flags |= OCFS2_INODE_MAYBE_ORPHANED;
22122212
spin_unlock(&oi->ip_lock);
2213-
} else if ((orphan_reco_type == ORPHAN_NEED_TRUNCATE) &&
2213+
}
2214+
2215+
if ((orphan_reco_type == ORPHAN_NEED_TRUNCATE) &&
22142216
(di->i_flags & cpu_to_le32(OCFS2_DIO_ORPHANED_FL))) {
22152217
ret = ocfs2_truncate_file(inode, di_bh,
22162218
i_size_read(inode));

0 commit comments

Comments
 (0)