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>
This commit is contained in:
Li Dongyang 2010-04-22 16:11:19 +08:00 committed by Mark Fasheh
parent d5a30458a9
commit d4cd1871cf
3 changed files with 39 additions and 29 deletions

View File

@ -639,11 +639,13 @@ static int ocfs2_remove_inode(struct inode *inode,
goto bail_unlock; goto bail_unlock;
} }
status = ocfs2_orphan_del(osb, handle, orphan_dir_inode, inode, if (!(OCFS2_I(inode)->ip_flags & OCFS2_INODE_SKIP_ORPHAN_DIR)) {
orphan_dir_bh); status = ocfs2_orphan_del(osb, handle, orphan_dir_inode, inode,
if (status < 0) { orphan_dir_bh);
mlog_errno(status); if (status < 0) {
goto bail_commit; mlog_errno(status);
goto bail_commit;
}
} }
/* set the inodes dtime */ /* set the inodes dtime */
@ -726,34 +728,35 @@ static int ocfs2_wipe_inode(struct inode *inode,
struct inode *orphan_dir_inode = NULL; struct inode *orphan_dir_inode = NULL;
struct buffer_head *orphan_dir_bh = NULL; struct buffer_head *orphan_dir_bh = NULL;
struct ocfs2_super *osb = OCFS2_SB(inode->i_sb); struct ocfs2_super *osb = OCFS2_SB(inode->i_sb);
struct ocfs2_dinode *di; struct ocfs2_dinode *di = (struct ocfs2_dinode *) di_bh->b_data;
di = (struct ocfs2_dinode *) di_bh->b_data; if (!(OCFS2_I(inode)->ip_flags & OCFS2_INODE_SKIP_ORPHAN_DIR)) {
orphaned_slot = le16_to_cpu(di->i_orphaned_slot); orphaned_slot = le16_to_cpu(di->i_orphaned_slot);
status = ocfs2_check_orphan_recovery_state(osb, orphaned_slot); status = ocfs2_check_orphan_recovery_state(osb, orphaned_slot);
if (status) if (status)
return status; return status;
orphan_dir_inode = ocfs2_get_system_file_inode(osb, orphan_dir_inode = ocfs2_get_system_file_inode(osb,
ORPHAN_DIR_SYSTEM_INODE, ORPHAN_DIR_SYSTEM_INODE,
orphaned_slot); orphaned_slot);
if (!orphan_dir_inode) { if (!orphan_dir_inode) {
status = -EEXIST; status = -EEXIST;
mlog_errno(status); mlog_errno(status);
goto bail; goto bail;
} }
/* Lock the orphan dir. The lock will be held for the entire /* Lock the orphan dir. The lock will be held for the entire
* delete_inode operation. We do this now to avoid races with * delete_inode operation. We do this now to avoid races with
* recovery completion on other nodes. */ * recovery completion on other nodes. */
mutex_lock(&orphan_dir_inode->i_mutex); mutex_lock(&orphan_dir_inode->i_mutex);
status = ocfs2_inode_lock(orphan_dir_inode, &orphan_dir_bh, 1); status = ocfs2_inode_lock(orphan_dir_inode, &orphan_dir_bh, 1);
if (status < 0) { if (status < 0) {
mutex_unlock(&orphan_dir_inode->i_mutex); mutex_unlock(&orphan_dir_inode->i_mutex);
mlog_errno(status); mlog_errno(status);
goto bail; goto bail;
}
} }
/* we do this while holding the orphan dir lock because we /* we do this while holding the orphan dir lock because we
@ -794,6 +797,9 @@ static int ocfs2_wipe_inode(struct inode *inode,
mlog_errno(status); mlog_errno(status);
bail_unlock_dir: bail_unlock_dir:
if (OCFS2_I(inode)->ip_flags & OCFS2_INODE_SKIP_ORPHAN_DIR)
return status;
ocfs2_inode_unlock(orphan_dir_inode, 1); ocfs2_inode_unlock(orphan_dir_inode, 1);
mutex_unlock(&orphan_dir_inode->i_mutex); mutex_unlock(&orphan_dir_inode->i_mutex);
brelse(orphan_dir_bh); brelse(orphan_dir_bh);
@ -889,7 +895,8 @@ static int ocfs2_query_inode_wipe(struct inode *inode,
/* Do some basic inode verification... */ /* Do some basic inode verification... */
di = (struct ocfs2_dinode *) di_bh->b_data; di = (struct ocfs2_dinode *) di_bh->b_data;
if (!(di->i_flags & cpu_to_le32(OCFS2_ORPHANED_FL))) { if (!(di->i_flags & cpu_to_le32(OCFS2_ORPHANED_FL)) &&
!(oi->ip_flags & OCFS2_INODE_SKIP_ORPHAN_DIR)) {
/* /*
* Inodes in the orphan dir must have ORPHANED_FL. The only * Inodes in the orphan dir must have ORPHANED_FL. The only
* inodes that come back out of the orphan dir are reflink * inodes that come back out of the orphan dir are reflink

View File

@ -100,6 +100,8 @@ struct ocfs2_inode_info
#define OCFS2_INODE_MAYBE_ORPHANED 0x00000020 #define OCFS2_INODE_MAYBE_ORPHANED 0x00000020
/* Does someone have the file open O_DIRECT */ /* Does someone have the file open O_DIRECT */
#define OCFS2_INODE_OPEN_DIRECT 0x00000040 #define OCFS2_INODE_OPEN_DIRECT 0x00000040
/* Tell the inode wipe code it's not in orphan dir */
#define OCFS2_INODE_SKIP_ORPHAN_DIR 0x00000080
static inline struct ocfs2_inode_info *OCFS2_I(struct inode *inode) static inline struct ocfs2_inode_info *OCFS2_I(struct inode *inode)
{ {

View File

@ -1976,6 +1976,7 @@ static int ocfs2_orphan_add(struct ocfs2_super *osb,
} }
le32_add_cpu(&fe->i_flags, OCFS2_ORPHANED_FL); le32_add_cpu(&fe->i_flags, OCFS2_ORPHANED_FL);
OCFS2_I(inode)->ip_flags &= ~OCFS2_INODE_SKIP_ORPHAN_DIR;
/* Record which orphan dir our inode now resides /* Record which orphan dir our inode now resides
* in. delete_inode will use this to determine which orphan * in. delete_inode will use this to determine which orphan