xfs: rework xfs_inactive()
v3 cover xfs: rework xfs_inactive()
Hi all,
This set reworks the xfs_inactive() path with the intent to clean up the transaction management overall. This is preparation work for the free inode btree set and subsequent work in the area. The patches clean up the remote symlink work, truncate work and ifree work respectively.
This passes through a quick xfstests run (with debug and lockdep) without any major explosions. Thoughts appreciated.
Brian
v3:
- Error handling fixes: cancel transaction before iunlock. v2:
- Cleaned up error handling throughout the set.
- Added inode locking to xfs_inactive_symlink().
- Added patch 4 to clean up xfs_inactive() after transaction management purge.
Brian Foster (4):
xfs: push down inactive transaction mgmt for remote symlinks
xfs: push down inactive transaction mgmt for truncate
xfs: push down inactive transaction mgmt for ifree
xfs: clean up xfs_inactive() error handling, kill
VN_INACTIVE_[NO]CACHE
fs/xfs/xfs_inode.c | 241 +++++++++++++++++++++++++++++---------------------- fs/xfs/xfs_inode.h | 2 +- fs/xfs/xfs_symlink.c | 86 +++++++++--------- fs/xfs/xfs_symlink.h | 2 +- fs/xfs/xfs_vnode.h | 8 -- 5 files changed, 180 insertions(+), 159 deletions(-)
Signature · 6 lines
1.8.1.4 _______________________________________________ xfs mailing list [email protected] http://oss.sgi.com/mailman/listinfo/xfs
PATCH v3 1/4 xfs: push down inactive transaction mgmt for remote symlinks
Push down the transaction management for remote symlinks from xfs_inactive() down to xfs_inactive_symlink_rmt(). The latter is cleaned up to avoid transaction management intended for the calling context (i.e., trans duplication, reservation, item attachment).
--- fs/xfs/xfs_inode.c | 15 ++++----- fs/xfs/xfs_symlink.c | 86 ++++++++++++++++++++++++---------------------------- fs/xfs/xfs_symlink.h | 2 +- 3 files changed, 49 insertions(+), 54 deletions(-)
fs/xfs/xfs_inode.c +8 -7
@@ -1724,9 +1724,14 @@ xfs_inactive(if (error)return VN_INACTIVE_CACHE ; +if (S_ISLNK (ip->i_d.di_mode)) { + error =xfs_inactive_symlink (ip); +if (error) + goto out; + } + tp =xfs_trans_alloc (mp,XFS_TRANS_INACTIVE ); - resp = (truncate ||S_ISLNK (ip->i_d.di_mode)) ? - &M_RES (mp)->tr_itruncate : &M_RES (mp)->tr_ifree; + resp = truncate ? &M_RES (mp)->tr_itruncate : &M_RES (mp)->tr_ifree; error =xfs_trans_reserve (tp, resp,0 ,0 );if (error) {
@@ -1738,11 +1743,7 @@ xfs_inactive(xfs_ilock (ip,XFS_ILOCK_EXCL );xfs_trans_ijoin (tp, ip,0 ); -if (S_ISLNK (ip->i_d.di_mode)) { - error =xfs_inactive_symlink (ip, &tp); -if (error) - goto out_cancel; - }else if (truncate) { +if (truncate) { ip->i_d.di_size =0 ;xfs_trans_log_inode (tp, ip,XFS_ILOG_CORE );
fs/xfs/xfs_symlink.c +40 -46
184 lines not on this page · raw message
fs/xfs/xfs_symlink.h +1 -1
@@ -22,6 +22,6 @@int xfs_symlink (struct xfs_inode *dp,struct xfs_name *link_name,const char *target_path,umode_t mode,struct xfs_inode **ipp);int xfs_readlink (struct xfs_inode *ip,char *link); -int xfs_inactive_symlink (struct xfs_inode *ip,struct xfs_trans **tpp); +int xfs_inactive_symlink (struct xfs_inode *ip);#endif /* __XFS_SYMLINK_H */
Signature · 6 lines
1.8.1.4 _______________________________________________ xfs mailing list [email protected] http://oss.sgi.com/mailman/listinfo/xfs
Re: [PATCH v3 1/4] xfs: push down inactive transaction mgmt for remote symlinks
Quoted 7 lines · Brian Foster
Push down the transaction management for remote symlinks from
xfs_inactive()down toxfs_inactive_symlink_rmt(). The latter is cleaned up to avoid transaction management intended for the calling context (i.e., trans duplication, reservation, item attachment).Signed-off-by Brian Foster <[email protected]>
Looks good. One minor quibble if you need to respin the patches again, but otherwise:
Quoted 20 lines
fs/xfs/xfs_symlink.c +2
-4@@ -563,41 +552,46 @@ xfs_inactive_symlink_rmt(*/ int xfs_inactive_symlink ( -struct xfs_inode *ip, -struct xfs_trans **tp) +struct xfs_inode *ip) {struct xfs_mount *mp = ip->i_mount;int pathlen;trace_xfs_inactive_symlink (ip); -ASSERT (xfs_isilocked (ip,XFS_ILOCK_EXCL )); -if (XFS_FORCED_SHUTDOWN (mp))return XFS_ERROR (EIO ); +xfs_ilock (ip,XFS_ILOCK_EXCL );
fs/xfs/xfs_symlink.c xfs_inactive_symlink_rmt( · line 574
Quoted 10 lines
fs/xfs/xfs_symlink.c +4
-1+/* * Zero length symlinks _can_ exist. */ pathlen = (int )ip->i_d.di_size; -if (!pathlen) +if (!pathlen) { +xfs_iunlock (ip,XFS_ILOCK_EXCL );return 0 ; + }
Minor quibble: this repeated "unlock, return error" pattern could be done with:
....
if (!pathlen) goto out_unlock; .... /* remove the remote symlink */ return xfs_inactive_symlink_rmt(ip);
out_unlock:
xfs_iunlock(ip, XFS_ILOCK_EXCL); return error; }
But, like I said, there's no need to do this unless I find other things in the rest of the series that require a respin...
Cheers,
Dave.
Signature · 7 lines
Dave Chinner [email protected] _______________________________________________ xfs mailing list [email protected] http://oss.sgi.com/mailman/listinfo/xfs
PATCH v3 2/4 xfs: push down inactive transaction mgmt for truncate
In reply to Brian FosterCreate the new xfs_inactive_truncate() function to handle the truncate portion of xfs_inactive(). Push the locking and transaction management into the new function.
--- fs/xfs/xfs_inode.c | 117 +++++++++++++++++++++++++++++++---------------------- 1 file changed, 68 insertions(+), 49 deletions(-)
fs/xfs/xfs_inode.c +68 -49
@@ -1663,6 +1663,58 @@ xfs_release( }/* +* xfs_inactive_truncate +* +* Called to perform a truncate when an inode becomes unlinked. +*/ +STATIC int +xfs_inactive_truncate ( +struct xfs_inode *ip) +{ +struct xfs_mount *mp = ip->i_mount; +struct xfs_trans *tp; +int error; + + tp =xfs_trans_alloc (mp,XFS_TRANS_INACTIVE ); + error =xfs_trans_reserve (tp, &M_RES (mp)->tr_itruncate,0 ,0 ); +if (error) { +ASSERT (XFS_FORCED_SHUTDOWN (mp)); +xfs_trans_cancel (tp,0 ); +return error; + } + +xfs_ilock (ip,XFS_ILOCK_EXCL ); +xfs_trans_ijoin (tp, ip,0 ); + +/* +* Log the inode size first to prevent stale data exposure in the event +* of a system crash before the truncate completes. See the related +* comment in xfs_setattr_size() for details. +*/ + ip->i_d.di_size =0 ; +xfs_trans_log_inode (tp, ip,XFS_ILOG_CORE ); + + error =xfs_itruncate_extents (&tp, ip,XFS_DATA_FORK ,0 ); +if (error) + goto error_trans_cancel; + +ASSERT (ip->i_d.di_nextents ==0 ); + + error =xfs_trans_commit (tp,XFS_TRANS_RELEASE_LOG_RES ); +if (error) + goto error_unlock; + +xfs_iunlock (ip,XFS_ILOCK_EXCL ); +return 0 ; + +error_trans_cancel: +xfs_trans_cancel (tp,XFS_TRANS_RELEASE_LOG_RES |XFS_TRANS_ABORT ); +error_unlock: +xfs_iunlock (ip,XFS_ILOCK_EXCL ); +return error; +} + +/* * xfs_inactive * * This is called when the vnode reference count for the vnode
@@ -1679,7 +1731,6 @@ xfs_inactive(int committed;struct xfs_trans *tp;struct xfs_mount *mp; -struct xfs_trans_res *resp;int error;int truncate =0 ;
@@ -1724,35 +1775,12 @@ xfs_inactive(if (error)return VN_INACTIVE_CACHE ; -if (S_ISLNK (ip->i_d.di_mode)) { +if (S_ISLNK (ip->i_d.di_mode)) error =xfs_inactive_symlink (ip); -if (error) - goto out; - } - - tp =xfs_trans_alloc (mp,XFS_TRANS_INACTIVE ); - resp = truncate ? &M_RES (mp)->tr_itruncate : &M_RES (mp)->tr_ifree; - - error =xfs_trans_reserve (tp, resp,0 ,0 ); -if (error) { -ASSERT (XFS_FORCED_SHUTDOWN (mp)); -xfs_trans_cancel (tp,0 ); -return VN_INACTIVE_CACHE ; - } - -xfs_ilock (ip,XFS_ILOCK_EXCL ); -xfs_trans_ijoin (tp, ip,0 ); - -if (truncate) { - ip->i_d.di_size =0 ; -xfs_trans_log_inode (tp, ip,XFS_ILOG_CORE ); - - error =xfs_itruncate_extents (&tp, ip,XFS_DATA_FORK ,0 ); -if (error) - goto out_cancel; - -ASSERT (ip->i_d.di_nextents ==0 ); - } +else if (truncate) + error =xfs_inactive_truncate (ip); +if (error) + goto out;/* * If there are attributes associated with the file then blow them away
@@ -1763,25 +1791,9 @@ xfs_inactive(if (ip->i_d.di_anextents >0 ) {ASSERT (ip->i_d.di_forkoff !=0 ); - error =xfs_trans_commit (tp,XFS_TRANS_RELEASE_LOG_RES ); -if (error) - goto out_unlock; - -xfs_iunlock (ip,XFS_ILOCK_EXCL ); - error =xfs_attr_inactive (ip);if (error) goto out; - - tp =xfs_trans_alloc (mp,XFS_TRANS_INACTIVE ); - error =xfs_trans_reserve (tp, &M_RES (mp)->tr_ifree,0 ,0 ); -if (error) { -xfs_trans_cancel (tp,0 ); - goto out; - } - -xfs_ilock (ip,XFS_ILOCK_EXCL ); -xfs_trans_ijoin (tp, ip,0 ); }if (ip->i_afp)
@@ -1789,6 +1801,17 @@ xfs_inactive(ASSERT (ip->i_d.di_anextents ==0 ); + tp =xfs_trans_alloc (mp,XFS_TRANS_INACTIVE ); + error =xfs_trans_reserve (tp, &M_RES (mp)->tr_ifree,0 ,0 ); +if (error) { +ASSERT (XFS_FORCED_SHUTDOWN (mp)); +xfs_trans_cancel (tp,XFS_TRANS_RELEASE_LOG_RES ); + goto out; + } + +xfs_ilock (ip,XFS_ILOCK_EXCL ); +xfs_trans_ijoin (tp, ip,0 ); +/* * Free the inode. */
@@ -1831,13 +1854,9 @@ xfs_inactive(* Release the dquots held by inode, if any. */ xfs_qm_dqdetach (ip); -out_unlock:xfs_iunlock (ip,XFS_ILOCK_EXCL ); out:return VN_INACTIVE_CACHE ; -out_cancel: -xfs_trans_cancel (tp,XFS_TRANS_RELEASE_LOG_RES |XFS_TRANS_ABORT ); - goto out_unlock; }/*
Signature · 6 lines
1.8.1.4 _______________________________________________ xfs mailing list [email protected] http://oss.sgi.com/mailman/listinfo/xfs
Re: [PATCH v3 2/4] xfs: push down inactive transaction mgmt for truncate
Quoted 5 lines · Brian Foster
Create the new
xfs_inactive_truncate()function to handle the truncate portion ofxfs_inactive(). Push the locking and transaction management into the new function.Signed-off-by Brian Foster <[email protected]>
Looks good.
Signature · 7 lines
Dave Chinner [email protected] _______________________________________________ xfs mailing list [email protected] http://oss.sgi.com/mailman/listinfo/xfs
PATCH v3 3/4 xfs: push down inactive transaction mgmt for ifree
In reply to Brian FosterPush the inode free work performed during xfs_inactive() down into a new xfs_inactive_ifree() helper. This clears xfs_inactive() from all inode locking and transaction management more directly associated with freeing the inode xattrs, extents and the inode itself.
--- fs/xfs/xfs_inode.c | 121 +++++++++++++++++++++++++++++++---------------------- 1 file changed, 71 insertions(+), 50 deletions(-)
fs/xfs/xfs_inode.c +71 -50
@@ -1715,6 +1715,74 @@ error_unlock: }/* +* xfs_inactive_ifree() +* +* Perform the inode free when an inode is unlinked. +*/ +STATIC int +xfs_inactive_ifree ( +struct xfs_inode *ip) +{ +xfs_bmap_free_t free_list; +xfs_fsblock_t first_block; +int committed; +struct xfs_mount *mp = ip->i_mount; +struct xfs_trans *tp; +int error; + + tp =xfs_trans_alloc (mp,XFS_TRANS_INACTIVE ); + error =xfs_trans_reserve (tp, &M_RES (mp)->tr_ifree,0 ,0 ); +if (error) { +ASSERT (XFS_FORCED_SHUTDOWN (mp)); +xfs_trans_cancel (tp,XFS_TRANS_RELEASE_LOG_RES ); +return error; + } + +xfs_ilock (ip,XFS_ILOCK_EXCL ); +xfs_trans_ijoin (tp, ip,0 ); + +xfs_bmap_init (&free_list, &first_block); + error =xfs_ifree (tp, ip, &free_list); +if (error) { +/* +* If we fail to free the inode, shut down. The cancel +* might do that, we need to make sure. Otherwise the +* inode might be lost for a long time or forever. +*/ +if (!XFS_FORCED_SHUTDOWN (mp)) { +xfs_notice (mp,"%s: xfs_ifree returned error %d" , + __func__, error); +xfs_force_shutdown (mp,SHUTDOWN_META_IO_ERROR ); + } +xfs_trans_cancel (tp,XFS_TRANS_RELEASE_LOG_RES |XFS_TRANS_ABORT ); +xfs_iunlock (ip,XFS_ILOCK_EXCL ); +return error; + } + +/* +* Credit the quota account(s). The inode is gone. +*/ +xfs_trans_mod_dquot_byino (tp, ip,XFS_TRANS_DQ_ICOUNT ,-1 ); + +/* +* Just ignore errors at this point. There is nothing we can +* do except to try to keep going. Make sure it's not a silent +* error. +*/ + error =xfs_bmap_finish (&tp, &free_list, &committed); +if (error) +xfs_notice (mp,"%s: xfs_bmap_finish returned error %d" , + __func__, error); + error =xfs_trans_commit (tp,XFS_TRANS_RELEASE_LOG_RES ); +if (error) +xfs_notice (mp,"%s: xfs_trans_commit returned error %d" , + __func__, error); + +xfs_iunlock (ip,XFS_ILOCK_EXCL ); +return 0 ; +} + +/* * xfs_inactive * * This is called when the vnode reference count for the vnode
@@ -1726,10 +1794,6 @@ intxfs_inactive ( xfs_inode_t *ip) { -xfs_bmap_free_t free_list; -xfs_fsblock_t first_block; -int committed; -struct xfs_trans *tp;struct xfs_mount *mp;int error;int truncate =0 ;
@@ -1801,60 +1865,17 @@ xfs_inactive(ASSERT (ip->i_d.di_anextents ==0 ); - tp =xfs_trans_alloc (mp,XFS_TRANS_INACTIVE ); - error =xfs_trans_reserve (tp, &M_RES (mp)->tr_ifree,0 ,0 ); -if (error) { -ASSERT (XFS_FORCED_SHUTDOWN (mp)); -xfs_trans_cancel (tp,XFS_TRANS_RELEASE_LOG_RES ); - goto out; - } - -xfs_ilock (ip,XFS_ILOCK_EXCL ); -xfs_trans_ijoin (tp, ip,0 ); -/* * Free the inode. */ -xfs_bmap_init (&free_list, &first_block); - error =xfs_ifree (tp, ip, &free_list); -if (error) { -/* -* If we fail to free the inode, shut down. The cancel -* might do that, we need to make sure. Otherwise the -* inode might be lost for a long time or forever. -*/ -if (!XFS_FORCED_SHUTDOWN (mp)) { -xfs_notice (mp,"%s: xfs_ifree returned error %d" , - __func__, error); -xfs_force_shutdown (mp,SHUTDOWN_META_IO_ERROR ); - } -xfs_trans_cancel (tp,XFS_TRANS_RELEASE_LOG_RES |XFS_TRANS_ABORT ); - }else { -/* -* Credit the quota account(s). The inode is gone. -*/ -xfs_trans_mod_dquot_byino (tp, ip,XFS_TRANS_DQ_ICOUNT ,-1 ); - -/* -* Just ignore errors at this point. There is nothing we can -* do except to try to keep going. Make sure it's not a silent -* error. -*/ - error =xfs_bmap_finish (&tp, &free_list, &committed); -if (error) -xfs_notice (mp,"%s: xfs_bmap_finish returned error %d" , - __func__, error); - error =xfs_trans_commit (tp,XFS_TRANS_RELEASE_LOG_RES ); -if (error) -xfs_notice (mp,"%s: xfs_trans_commit returned error %d" , - __func__, error); - } + error =xfs_inactive_ifree (ip); +if (error) + goto out;/* * Release the dquots held by inode, if any. */ xfs_qm_dqdetach (ip); -xfs_iunlock (ip,XFS_ILOCK_EXCL ); out:return VN_INACTIVE_CACHE ; }
Signature · 6 lines
1.8.1.4 _______________________________________________ xfs mailing list [email protected] http://oss.sgi.com/mailman/listinfo/xfs
Re: [PATCH v3 3/4] xfs: push down inactive transaction mgmt for ifree
Quoted 7 lines · Brian Foster
Push the inode free work performed during
xfs_inactive()down into a newxfs_inactive_ifree()helper. This clearsxfs_inactive()from all inode locking and transaction management more directly associated with freeing the inode xattrs, extents and the inode itself.Signed-off-by Brian Foster <[email protected]>
Looks OK to me.
Signature · 7 lines
Dave Chinner [email protected] _______________________________________________ xfs mailing list [email protected] http://oss.sgi.com/mailman/listinfo/xfs
PATCH v3 4/4 xfs: clean up xfs_inactive() error handling, kill VN_INACTIVE_[NO]CACHE
In reply to Brian FosterThe xfs_inactive() return value is meaningless. Turn xfs_inactive() into a void function and clean up the error handling appropriately. Kill the VN_INACTIVE_[NO]CACHE directives as they are not relevant to Linux.
--- fs/xfs/xfs_inode.c | 28 +++++++++++----------------- fs/xfs/xfs_inode.h | 2 +- fs/xfs/xfs_vnode.h | 8 -------- 3 files changed, 12 insertions(+), 26 deletions(-)
fs/xfs/xfs_inode.c +11 -17
@@ -1790,7 +1790,7 @@ xfs_inactive_ifree(* now be truncated. Also, we clear all of the read-ahead state * kept for the inode here since the file is now closed. */ -int +void xfs_inactive (xfs_inode_t *ip) {
@@ -1805,16 +1805,14 @@ xfs_inactive(if (ip->i_d.di_mode ==0 ||is_bad_inode (VFS_I (ip))) {ASSERT (ip->i_df.if_real_bytes ==0 );ASSERT (ip->i_df.if_broot_bytes ==0 ); -return VN_INACTIVE_CACHE ; +return ; } mp = ip->i_mount; - error =0 ; -/* If this is a read-only mount, don't do this (would generate I/O) */ if (mp->m_flags &XFS_MOUNT_RDONLY ) - goto out; +return ;if (ip->i_d.di_nlink !=0 ) {/*
@@ -1822,12 +1820,10 @@ xfs_inactive(* cache. Post-eof blocks must be freed, lest we end up with * broken free space accounting. */ -if (xfs_can_free_eofblocks (ip, true)) { - error =xfs_free_eofblocks (mp, ip, false); -if (error) -return VN_INACTIVE_CACHE ; - } - goto out; +if (xfs_can_free_eofblocks (ip, true)) +xfs_free_eofblocks (mp, ip, false); + +return ; } if (S_ISREG(ip->i_d.di_mode) &&
@@ -1837,14 +1833,14 @@ xfs_inactive( error =xfs_qm_dqattach (ip,0 );if (error) -return VN_INACTIVE_CACHE ; +return ;if (S_ISLNK (ip->i_d.di_mode)) error =xfs_inactive_symlink (ip);else if (truncate) error =xfs_inactive_truncate (ip);if (error) - goto out; +return ;/* * If there are attributes associated with the file then blow them away
@@ -1857,7 +1853,7 @@ xfs_inactive( error =xfs_attr_inactive (ip);if (error) - goto out; +return ; }if (ip->i_afp)
@@ -1870,14 +1866,12 @@ xfs_inactive(*/ error =xfs_inactive_ifree (ip);if (error) - goto out; +return ;/* * Release the dquots held by inode, if any. */ xfs_qm_dqdetach (ip); -out: -return VN_INACTIVE_CACHE ; }/*
fs/xfs/xfs_inode.h +1 -1
@@ -316,7 +316,7 @@ static inline int xfs_isiflocked(struct xfs_inode *ip)int xfs_release (struct xfs_inode *ip); -int xfs_inactive (struct xfs_inode *ip); +void xfs_inactive (struct xfs_inode *ip);int xfs_lookup (struct xfs_inode *dp,struct xfs_name *name,struct xfs_inode **ipp,struct xfs_name *ci_name); int xfs_create(struct xfs_inode *dp, struct xfs_name *name,
fs/xfs/xfs_vnode.h +0 -8
@@ -25,14 +25,6 @@ struct xfs_inode;struct attrlist_cursor_kern ;/* -* Return values for xfs_inactive. A return value of -* VN_INACTIVE_NOCACHE implies that the file system behavior -* has disassociated its state and bhv_desc_t from the vnode. -*/ -#define VN_INACTIVE_CACHE 0 -#define VN_INACTIVE_NOCACHE 1 - -/* * Flags for read/write calls - same values as IRIX */ #define IO_ISDIRECT 0x00004/* bypass page cache */
Signature · 6 lines
1.8.1.4 _______________________________________________ xfs mailing list [email protected] http://oss.sgi.com/mailman/listinfo/xfs
Quoted 11 lines · Brian Foster
Hi all,
This set reworks the
xfs_inactive()path with the intent to clean up the transaction management overall. This is preparation work for the free inode btree set and subsequent work in the area. The patches clean up the remote symlink work, truncate work and ifree work respectively.This passes through a quick xfstests run (with debug and lockdep) without any major explosions. Thoughts appreciated.
Brian
Applied these four.
Thanks,
Ben
_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs