xfs: pull up dfops from xfs_itruncate_extents()

xfs_itruncate_extents[_flags]() uses a local dfops with a
transaction provided by the caller. It uses hacky ->t_dfops
replacement logic to avoid stomping over an already populated
->t_dfops.

The latter never occurs for current callers and the logic itself is
not really appropriate. Clean this up by updating all callers to
initialize a dfops and to use that down in xfs_itruncate_extents().
This more closely resembles the upcoming logic where dfops will be
embedded within the transaction. We can also replace the
xfs_defer_init() in the xfs_itruncate_extents_flags() loop with an
assert. Both dfops and firstblock should be in a valid state
after xfs_defer_finish() and the inode joined to the dfops is fixed
throughout the loop.

Signed-off-by: Brian Foster <bfoster@redhat.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Bill O'Donnell <billodo@redhat.com>
Reviewed-by: Darrick J. Wong <darrick.wong@oracle.com>
Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
This commit is contained in:
Brian Foster 2018-07-24 13:43:07 -07:00 коммит произвёл Darrick J. Wong
Родитель f467cad95f
Коммит 02dff7bf81
5 изменённых файлов: 14 добавлений и 5 удалений

Просмотреть файл

@ -26,6 +26,7 @@
#include "xfs_quota.h" #include "xfs_quota.h"
#include "xfs_trace.h" #include "xfs_trace.h"
#include "xfs_dir2.h" #include "xfs_dir2.h"
#include "xfs_defer.h"
/* /*
* Look at all the extents for this logical region, * Look at all the extents for this logical region,
@ -381,6 +382,7 @@ xfs_attr_inactive(
{ {
struct xfs_trans *trans; struct xfs_trans *trans;
struct xfs_mount *mp; struct xfs_mount *mp;
struct xfs_defer_ops dfops;
int lock_mode = XFS_ILOCK_SHARED; int lock_mode = XFS_ILOCK_SHARED;
int error = 0; int error = 0;
@ -397,6 +399,7 @@ xfs_attr_inactive(
error = xfs_trans_alloc(mp, &M_RES(mp)->tr_attrinval, 0, 0, 0, &trans); error = xfs_trans_alloc(mp, &M_RES(mp)->tr_attrinval, 0, 0, 0, &trans);
if (error) if (error)
goto out_destroy_fork; goto out_destroy_fork;
xfs_defer_init(trans, &dfops);
lock_mode = XFS_ILOCK_EXCL; lock_mode = XFS_ILOCK_EXCL;
xfs_ilock(dp, lock_mode); xfs_ilock(dp, lock_mode);

Просмотреть файл

@ -792,6 +792,7 @@ xfs_free_eofblocks(
int nimaps; int nimaps;
struct xfs_bmbt_irec imap; struct xfs_bmbt_irec imap;
struct xfs_mount *mp = ip->i_mount; struct xfs_mount *mp = ip->i_mount;
struct xfs_defer_ops dfops;
/* /*
* Figure out if there are any blocks beyond the end * Figure out if there are any blocks beyond the end
@ -831,6 +832,7 @@ xfs_free_eofblocks(
ASSERT(XFS_FORCED_SHUTDOWN(mp)); ASSERT(XFS_FORCED_SHUTDOWN(mp));
return error; return error;
} }
xfs_defer_init(tp, &dfops);
xfs_ilock(ip, XFS_ILOCK_EXCL); xfs_ilock(ip, XFS_ILOCK_EXCL);
xfs_trans_ijoin(tp, ip, 0); xfs_trans_ijoin(tp, ip, 0);

Просмотреть файл

@ -1541,8 +1541,6 @@ xfs_itruncate_extents_flags(
{ {
struct xfs_mount *mp = ip->i_mount; struct xfs_mount *mp = ip->i_mount;
struct xfs_trans *tp = *tpp; struct xfs_trans *tp = *tpp;
struct xfs_defer_ops *odfops = tp->t_dfops;
struct xfs_defer_ops dfops;
xfs_fileoff_t first_unmap_block; xfs_fileoff_t first_unmap_block;
xfs_fileoff_t last_block; xfs_fileoff_t last_block;
xfs_filblks_t unmap_len; xfs_filblks_t unmap_len;
@ -1579,7 +1577,7 @@ xfs_itruncate_extents_flags(
ASSERT(first_unmap_block < last_block); ASSERT(first_unmap_block < last_block);
unmap_len = last_block - first_unmap_block + 1; unmap_len = last_block - first_unmap_block + 1;
while (!done) { while (!done) {
xfs_defer_init(tp, &dfops); ASSERT(tp->t_firstblock == NULLFSBLOCK);
error = xfs_bunmapi(tp, ip, first_unmap_block, unmap_len, flags, error = xfs_bunmapi(tp, ip, first_unmap_block, unmap_len, flags,
XFS_ITRUNC_MAX_EXTENTS, &done); XFS_ITRUNC_MAX_EXTENTS, &done);
if (error) if (error)
@ -1618,8 +1616,6 @@ xfs_itruncate_extents_flags(
trace_xfs_itruncate_extents_end(ip, new_size); trace_xfs_itruncate_extents_end(ip, new_size);
out: out:
/* ->t_dfops points to local stack, don't leak it! */
tp->t_dfops = odfops;
*tpp = tp; *tpp = tp;
return error; return error;
out_bmap_cancel: out_bmap_cancel:
@ -1723,6 +1719,7 @@ xfs_inactive_truncate(
{ {
struct xfs_mount *mp = ip->i_mount; struct xfs_mount *mp = ip->i_mount;
struct xfs_trans *tp; struct xfs_trans *tp;
struct xfs_defer_ops dfops;
int error; int error;
error = xfs_trans_alloc(mp, &M_RES(mp)->tr_itruncate, 0, 0, 0, &tp); error = xfs_trans_alloc(mp, &M_RES(mp)->tr_itruncate, 0, 0, 0, &tp);
@ -1730,6 +1727,7 @@ xfs_inactive_truncate(
ASSERT(XFS_FORCED_SHUTDOWN(mp)); ASSERT(XFS_FORCED_SHUTDOWN(mp));
return error; return error;
} }
xfs_defer_init(tp, &dfops);
xfs_ilock(ip, XFS_ILOCK_EXCL); xfs_ilock(ip, XFS_ILOCK_EXCL);
xfs_trans_ijoin(tp, ip, 0); xfs_trans_ijoin(tp, ip, 0);

Просмотреть файл

@ -26,6 +26,7 @@
#include "xfs_dir2.h" #include "xfs_dir2.h"
#include "xfs_trans_space.h" #include "xfs_trans_space.h"
#include "xfs_iomap.h" #include "xfs_iomap.h"
#include "xfs_defer.h"
#include <linux/capability.h> #include <linux/capability.h>
#include <linux/xattr.h> #include <linux/xattr.h>
@ -812,6 +813,7 @@ xfs_setattr_size(
struct inode *inode = VFS_I(ip); struct inode *inode = VFS_I(ip);
xfs_off_t oldsize, newsize; xfs_off_t oldsize, newsize;
struct xfs_trans *tp; struct xfs_trans *tp;
struct xfs_defer_ops dfops;
int error; int error;
uint lock_flags = 0; uint lock_flags = 0;
bool did_zeroing = false; bool did_zeroing = false;
@ -915,6 +917,7 @@ xfs_setattr_size(
error = xfs_trans_alloc(mp, &M_RES(mp)->tr_itruncate, 0, 0, 0, &tp); error = xfs_trans_alloc(mp, &M_RES(mp)->tr_itruncate, 0, 0, 0, &tp);
if (error) if (error)
return error; return error;
xfs_defer_init(tp, &dfops);
lock_flags |= XFS_ILOCK_EXCL; lock_flags |= XFS_ILOCK_EXCL;
xfs_ilock(ip, XFS_ILOCK_EXCL); xfs_ilock(ip, XFS_ILOCK_EXCL);

Просмотреть файл

@ -22,6 +22,7 @@
#include "xfs_qm.h" #include "xfs_qm.h"
#include "xfs_trace.h" #include "xfs_trace.h"
#include "xfs_icache.h" #include "xfs_icache.h"
#include "xfs_defer.h"
STATIC int xfs_qm_log_quotaoff(xfs_mount_t *, xfs_qoff_logitem_t **, uint); STATIC int xfs_qm_log_quotaoff(xfs_mount_t *, xfs_qoff_logitem_t **, uint);
STATIC int xfs_qm_log_quotaoff_end(xfs_mount_t *, xfs_qoff_logitem_t *, STATIC int xfs_qm_log_quotaoff_end(xfs_mount_t *, xfs_qoff_logitem_t *,
@ -213,6 +214,7 @@ xfs_qm_scall_trunc_qfile(
{ {
struct xfs_inode *ip; struct xfs_inode *ip;
struct xfs_trans *tp; struct xfs_trans *tp;
struct xfs_defer_ops dfops;
int error; int error;
if (ino == NULLFSINO) if (ino == NULLFSINO)
@ -229,6 +231,7 @@ xfs_qm_scall_trunc_qfile(
xfs_iunlock(ip, XFS_IOLOCK_EXCL); xfs_iunlock(ip, XFS_IOLOCK_EXCL);
goto out_put; goto out_put;
} }
xfs_defer_init(tp, &dfops);
xfs_ilock(ip, XFS_ILOCK_EXCL); xfs_ilock(ip, XFS_ILOCK_EXCL);
xfs_trans_ijoin(tp, ip, 0); xfs_trans_ijoin(tp, ip, 0);