Skip to content

Commit d4cd187

Browse files
Li DongyangMark Fasheh
authored andcommitted
ocfs2: add OCFS2_INODE_SKIP_ORPHAN_DIR flag and honor it in the inode wipe code
Currently in the error path of ocfs2_symlink and ocfs2_mknod, we just call iput with the inode we failed with, but the inode wipe code will complain because we don't add the inode to orphan dir. One solution would be to lock the orphan dir during the entire transaction, but that's too heavy for a rare error path. Instead, we add a flag, OCFS2_INODE_SKIP_ORPHAN_DIR which tells the inode wipe code that it won't find this inode in the orphan dir. [ Merge fixes and comment style cleanups -Mark ] Signed-off-by: Li Dongyang <lidongyang@novell.com> Signed-off-by: Mark Fasheh <mfasheh@suse.com>
1 parent d5a3045 commit d4cd187

3 files changed

Lines changed: 39 additions & 29 deletions

File tree

‎fs/ocfs2/inode.c‎

Lines changed: 36 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -639,11 +639,13 @@ static int ocfs2_remove_inode(struct inode *inode,
639639
goto bail_unlock;
640640
}
641641

642-
status = ocfs2_orphan_del(osb, handle, orphan_dir_inode, inode,
643-
orphan_dir_bh);
644-
if (status < 0) {
645-
mlog_errno(status);
646-
goto bail_commit;
642+
if (!(OCFS2_I(inode)->ip_flags & OCFS2_INODE_SKIP_ORPHAN_DIR)) {
643+
status = ocfs2_orphan_del(osb, handle, orphan_dir_inode, inode,
644+
orphan_dir_bh);
645+
if (status < 0) {
646+
mlog_errno(status);
647+
goto bail_commit;
648+
}
647649
}
648650

649651
/* set the inodes dtime */
@@ -726,34 +728,35 @@ static int ocfs2_wipe_inode(struct inode *inode,
726728
struct inode *orphan_dir_inode = NULL;
727729
struct buffer_head *orphan_dir_bh = NULL;
728730
struct ocfs2_super *osb = OCFS2_SB(inode->i_sb);
729-
struct ocfs2_dinode *di;
731+
struct ocfs2_dinode *di = (struct ocfs2_dinode *) di_bh->b_data;
730732

731-
di = (struct ocfs2_dinode *) di_bh->b_data;
732-
orphaned_slot = le16_to_cpu(di->i_orphaned_slot);
733+
if (!(OCFS2_I(inode)->ip_flags & OCFS2_INODE_SKIP_ORPHAN_DIR)) {
734+
orphaned_slot = le16_to_cpu(di->i_orphaned_slot);
733735

734-
status = ocfs2_check_orphan_recovery_state(osb, orphaned_slot);
735-
if (status)
736-
return status;
736+
status = ocfs2_check_orphan_recovery_state(osb, orphaned_slot);
737+
if (status)
738+
return status;
737739

738-
orphan_dir_inode = ocfs2_get_system_file_inode(osb,
739-
ORPHAN_DIR_SYSTEM_INODE,
740-
orphaned_slot);
741-
if (!orphan_dir_inode) {
742-
status = -EEXIST;
743-
mlog_errno(status);
744-
goto bail;
745-
}
740+
orphan_dir_inode = ocfs2_get_system_file_inode(osb,
741+
ORPHAN_DIR_SYSTEM_INODE,
742+
orphaned_slot);
743+
if (!orphan_dir_inode) {
744+
status = -EEXIST;
745+
mlog_errno(status);
746+
goto bail;
747+
}
746748

747-
/* Lock the orphan dir. The lock will be held for the entire
748-
* delete_inode operation. We do this now to avoid races with
749-
* recovery completion on other nodes. */
750-
mutex_lock(&orphan_dir_inode->i_mutex);
751-
status = ocfs2_inode_lock(orphan_dir_inode, &orphan_dir_bh, 1);
752-
if (status < 0) {
753-
mutex_unlock(&orphan_dir_inode->i_mutex);
749+
/* Lock the orphan dir. The lock will be held for the entire
750+
* delete_inode operation. We do this now to avoid races with
751+
* recovery completion on other nodes. */
752+
mutex_lock(&orphan_dir_inode->i_mutex);
753+
status = ocfs2_inode_lock(orphan_dir_inode, &orphan_dir_bh, 1);
754+
if (status < 0) {
755+
mutex_unlock(&orphan_dir_inode->i_mutex);
754756

755-
mlog_errno(status);
756-
goto bail;
757+
mlog_errno(status);
758+
goto bail;
759+
}
757760
}
758761

759762
/* we do this while holding the orphan dir lock because we
@@ -794,6 +797,9 @@ static int ocfs2_wipe_inode(struct inode *inode,
794797
mlog_errno(status);
795798

796799
bail_unlock_dir:
800+
if (OCFS2_I(inode)->ip_flags & OCFS2_INODE_SKIP_ORPHAN_DIR)
801+
return status;
802+
797803
ocfs2_inode_unlock(orphan_dir_inode, 1);
798804
mutex_unlock(&orphan_dir_inode->i_mutex);
799805
brelse(orphan_dir_bh);
@@ -889,7 +895,8 @@ static int ocfs2_query_inode_wipe(struct inode *inode,
889895

890896
/* Do some basic inode verification... */
891897
di = (struct ocfs2_dinode *) di_bh->b_data;
892-
if (!(di->i_flags & cpu_to_le32(OCFS2_ORPHANED_FL))) {
898+
if (!(di->i_flags & cpu_to_le32(OCFS2_ORPHANED_FL)) &&
899+
!(oi->ip_flags & OCFS2_INODE_SKIP_ORPHAN_DIR)) {
893900
/*
894901
* Inodes in the orphan dir must have ORPHANED_FL. The only
895902
* inodes that come back out of the orphan dir are reflink

‎fs/ocfs2/inode.h‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,8 @@ struct ocfs2_inode_info
100100
#define OCFS2_INODE_MAYBE_ORPHANED 0x00000020
101101
/* Does someone have the file open O_DIRECT */
102102
#define OCFS2_INODE_OPEN_DIRECT 0x00000040
103+
/* Tell the inode wipe code it's not in orphan dir */
104+
#define OCFS2_INODE_SKIP_ORPHAN_DIR 0x00000080
103105

104106
static inline struct ocfs2_inode_info *OCFS2_I(struct inode *inode)
105107
{

‎fs/ocfs2/namei.c‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1976,6 +1976,7 @@ static int ocfs2_orphan_add(struct ocfs2_super *osb,
19761976
}
19771977

19781978
le32_add_cpu(&fe->i_flags, OCFS2_ORPHANED_FL);
1979+
OCFS2_I(inode)->ip_flags &= ~OCFS2_INODE_SKIP_ORPHAN_DIR;
19791980

19801981
/* Record which orphan dir our inode now resides
19811982
* in. delete_inode will use this to determine which orphan

0 commit comments

Comments
 (0)