Commit 8f04c47a authored by Christoph Hellwig's avatar Christoph Hellwig

xfs: split xfs_itruncate_finish

Split the guts of xfs_itruncate_finish that loop over the existing extents
and calls xfs_bunmapi on them into a new helper, xfs_itruncate_externs.
Make xfs_attr_inactive call it directly instead of xfs_itruncate_finish,
which allows to simplify the latter a lot, by only letting it deal with
the data fork.  As a result xfs_itruncate_finish is renamed to
xfs_itruncate_data to make its use case more obvious.

Also remove the sync parameter from xfs_itruncate_data, which has been
unessecary since the introduction of the busy extent list in 2002, and
completely dead code since 2003 when the XFS_BMAPI_ASYNC parameter was
made a no-op.

I can't actually see why the xfs_attr_inactive needs to set the transaction
sync, but let's keep this patch simple and without changes in behaviour.

Also avoid passing a useless argument to xfs_isize_check, and make it
private to xfs_inode.c.
Signed-off-by: default avatarChristoph Hellwig <hch@lst.de>
Reviewed-by: default avatarAlex Elder <aelder@sgi.com>
Reviewed-by: default avatarDave Chinner <dchinner@redhat.com>
parent 857b9778
...@@ -879,15 +879,7 @@ xfs_setattr_size( ...@@ -879,15 +879,7 @@ xfs_setattr_size(
ip->i_size = iattr->ia_size; ip->i_size = iattr->ia_size;
} else if (iattr->ia_size <= ip->i_size || } else if (iattr->ia_size <= ip->i_size ||
(iattr->ia_size == 0 && ip->i_d.di_nextents)) { (iattr->ia_size == 0 && ip->i_d.di_nextents)) {
/* error = xfs_itruncate_data(&tp, ip, iattr->ia_size);
* Signal a sync transaction unless we are truncating an
* already unlinked file on a wsync filesystem.
*/
error = xfs_itruncate_finish(&tp, ip, iattr->ia_size,
XFS_DATA_FORK,
((ip->i_d.di_nlink != 0 ||
!(mp->m_flags & XFS_MOUNT_WSYNC))
? 1 : 0));
if (error) if (error)
goto out_trans_abort; goto out_trans_abort;
......
...@@ -1055,8 +1055,8 @@ DECLARE_EVENT_CLASS(xfs_itrunc_class, ...@@ -1055,8 +1055,8 @@ DECLARE_EVENT_CLASS(xfs_itrunc_class,
DEFINE_EVENT(xfs_itrunc_class, name, \ DEFINE_EVENT(xfs_itrunc_class, name, \
TP_PROTO(struct xfs_inode *ip, xfs_fsize_t new_size), \ TP_PROTO(struct xfs_inode *ip, xfs_fsize_t new_size), \
TP_ARGS(ip, new_size)) TP_ARGS(ip, new_size))
DEFINE_ITRUNC_EVENT(xfs_itruncate_finish_start); DEFINE_ITRUNC_EVENT(xfs_itruncate_data_start);
DEFINE_ITRUNC_EVENT(xfs_itruncate_finish_end); DEFINE_ITRUNC_EVENT(xfs_itruncate_data_end);
TRACE_EVENT(xfs_pagecache_inval, TRACE_EVENT(xfs_pagecache_inval,
TP_PROTO(struct xfs_inode *ip, xfs_off_t start, xfs_off_t finish), TP_PROTO(struct xfs_inode *ip, xfs_off_t start, xfs_off_t finish),
......
...@@ -263,7 +263,7 @@ xfs_qm_scall_trunc_qfile( ...@@ -263,7 +263,7 @@ xfs_qm_scall_trunc_qfile(
xfs_ilock(ip, XFS_ILOCK_EXCL); xfs_ilock(ip, XFS_ILOCK_EXCL);
xfs_trans_ijoin(tp, ip); xfs_trans_ijoin(tp, ip);
error = xfs_itruncate_finish(&tp, ip, 0, XFS_DATA_FORK, 1); error = xfs_itruncate_data(&tp, ip, 0);
if (error) { if (error) {
xfs_trans_cancel(tp, XFS_TRANS_RELEASE_LOG_RES | xfs_trans_cancel(tp, XFS_TRANS_RELEASE_LOG_RES |
XFS_TRANS_ABORT); XFS_TRANS_ABORT);
......
...@@ -822,17 +822,21 @@ xfs_attr_inactive(xfs_inode_t *dp) ...@@ -822,17 +822,21 @@ xfs_attr_inactive(xfs_inode_t *dp)
error = xfs_attr_root_inactive(&trans, dp); error = xfs_attr_root_inactive(&trans, dp);
if (error) if (error)
goto out; goto out;
/* /*
* signal synchronous inactive transactions unless this * Signal synchronous inactive transactions unless this is a
* is a synchronous mount filesystem in which case we * synchronous mount filesystem in which case we know that we're here
* know that we're here because we've been called out of * because we've been called out of xfs_inactive which means that the
* xfs_inactive which means that the last reference is gone * last reference is gone and the unlink transaction has already hit
* and the unlink transaction has already hit the disk so * the disk so async inactive transactions are safe.
* async inactive transactions are safe.
*/ */
if ((error = xfs_itruncate_finish(&trans, dp, 0LL, XFS_ATTR_FORK, if (!(mp->m_flags & XFS_MOUNT_WSYNC)) {
(!(mp->m_flags & XFS_MOUNT_WSYNC) if (dp->i_d.di_anextents > 0)
? 1 : 0)))) xfs_trans_set_sync(trans);
}
error = xfs_itruncate_extents(&trans, dp, XFS_ATTR_FORK, 0);
if (error)
goto out; goto out;
/* /*
......
This diff is collapsed.
...@@ -491,8 +491,10 @@ uint xfs_ip2xflags(struct xfs_inode *); ...@@ -491,8 +491,10 @@ uint xfs_ip2xflags(struct xfs_inode *);
uint xfs_dic2xflags(struct xfs_dinode *); uint xfs_dic2xflags(struct xfs_dinode *);
int xfs_ifree(struct xfs_trans *, xfs_inode_t *, int xfs_ifree(struct xfs_trans *, xfs_inode_t *,
struct xfs_bmap_free *); struct xfs_bmap_free *);
int xfs_itruncate_finish(struct xfs_trans **, xfs_inode_t *, int xfs_itruncate_extents(struct xfs_trans **, struct xfs_inode *,
xfs_fsize_t, int, int); int, xfs_fsize_t);
int xfs_itruncate_data(struct xfs_trans **, struct xfs_inode *,
xfs_fsize_t);
int xfs_iunlink(struct xfs_trans *, xfs_inode_t *); int xfs_iunlink(struct xfs_trans *, xfs_inode_t *);
void xfs_iext_realloc(xfs_inode_t *, int, int); void xfs_iext_realloc(xfs_inode_t *, int, int);
...@@ -568,13 +570,6 @@ void xfs_iext_irec_update_extoffs(xfs_ifork_t *, int, int); ...@@ -568,13 +570,6 @@ void xfs_iext_irec_update_extoffs(xfs_ifork_t *, int, int);
#define xfs_ipincount(ip) ((unsigned int) atomic_read(&ip->i_pincount)) #define xfs_ipincount(ip) ((unsigned int) atomic_read(&ip->i_pincount))
#ifdef DEBUG
void xfs_isize_check(struct xfs_mount *, struct xfs_inode *,
xfs_fsize_t);
#else /* DEBUG */
#define xfs_isize_check(mp, ip, isize)
#endif /* DEBUG */
#if defined(DEBUG) #if defined(DEBUG)
void xfs_inobp_check(struct xfs_mount *, struct xfs_buf *); void xfs_inobp_check(struct xfs_mount *, struct xfs_buf *);
#else #else
......
...@@ -220,15 +220,12 @@ xfs_free_eofblocks( ...@@ -220,15 +220,12 @@ xfs_free_eofblocks(
xfs_ilock(ip, XFS_ILOCK_EXCL); xfs_ilock(ip, XFS_ILOCK_EXCL);
xfs_trans_ijoin(tp, ip); xfs_trans_ijoin(tp, ip);
error = xfs_itruncate_finish(&tp, ip, error = xfs_itruncate_data(&tp, ip, ip->i_size);
ip->i_size, if (error) {
XFS_DATA_FORK,
0);
/* /*
* If we get an error at this point we * If we get an error at this point we simply don't
* simply don't bother truncating the file. * bother truncating the file.
*/ */
if (error) {
xfs_trans_cancel(tp, xfs_trans_cancel(tp,
(XFS_TRANS_RELEASE_LOG_RES | (XFS_TRANS_RELEASE_LOG_RES |
XFS_TRANS_ABORT)); XFS_TRANS_ABORT));
...@@ -665,16 +662,7 @@ xfs_inactive( ...@@ -665,16 +662,7 @@ xfs_inactive(
xfs_ilock(ip, XFS_ILOCK_EXCL); xfs_ilock(ip, XFS_ILOCK_EXCL);
xfs_trans_ijoin(tp, ip); xfs_trans_ijoin(tp, ip);
/* error = xfs_itruncate_data(&tp, ip, 0);
* normally, we have to run xfs_itruncate_finish sync.
* But if filesystem is wsync and we're in the inactive
* path, then we know that nlink == 0, and that the
* xaction that made nlink == 0 is permanently committed
* since xfs_remove runs as a synchronous transaction.
*/
error = xfs_itruncate_finish(&tp, ip, 0, XFS_DATA_FORK,
(!(mp->m_flags & XFS_MOUNT_WSYNC) ? 1 : 0));
if (error) { if (error) {
xfs_trans_cancel(tp, xfs_trans_cancel(tp,
XFS_TRANS_RELEASE_LOG_RES | XFS_TRANS_ABORT); XFS_TRANS_RELEASE_LOG_RES | XFS_TRANS_ABORT);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment