diff mbox series

[3/3] xfs: attach dquots before performing xfs_swap_extents

Message ID 157343511427.1948946.2692071497822316839.stgit@magnolia (mailing list archive)
State Accepted
Headers show
Series xfs: various fixes | expand

Commit Message

Darrick J. Wong Nov. 11, 2019, 1:18 a.m. UTC
From: Darrick J. Wong <darrick.wong@oracle.com>

Make sure we attach dquots to both inodes before swapping their extents.
This was found via manual code inspection by looking for places where we
could call xfs_trans_mod_dquot without dquots attached to inodes, and
confirmed by instrumenting the kernel and running xfs/328.

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
---
 fs/xfs/xfs_bmap_util.c |    8 ++++++++
 1 file changed, 8 insertions(+)

Comments

Christoph Hellwig Nov. 11, 2019, 8:05 a.m. UTC | #1
On Sun, Nov 10, 2019 at 05:18:34PM -0800, Darrick J. Wong wrote:
> From: Darrick J. Wong <darrick.wong@oracle.com>
> 
> Make sure we attach dquots to both inodes before swapping their extents.
> This was found via manual code inspection by looking for places where we
> could call xfs_trans_mod_dquot without dquots attached to inodes, and
> confirmed by instrumenting the kernel and running xfs/328.

Looks good:

Reviewed-by: Christoph Hellwig <hch@lst.de>

Btw, for  while I've been wondering if we could just get rid of the
concepts of attached dquots.  With the radix-tree/xarray looks up
are be fairly cheap, and could be done lockless using RCU.  So we could
try to just kill the concept of attaching the dquot to the inode and
just look it up once per operation, where operation preferally is
something high-level like the actual file/inode operation and not a
low-level thing inside xfs.
Dave Chinner Nov. 12, 2019, 10:14 p.m. UTC | #2
On Mon, Nov 11, 2019 at 12:05:03AM -0800, Christoph Hellwig wrote:
> On Sun, Nov 10, 2019 at 05:18:34PM -0800, Darrick J. Wong wrote:
> > From: Darrick J. Wong <darrick.wong@oracle.com>
> > 
> > Make sure we attach dquots to both inodes before swapping their extents.
> > This was found via manual code inspection by looking for places where we
> > could call xfs_trans_mod_dquot without dquots attached to inodes, and
> > confirmed by instrumenting the kernel and running xfs/328.
> 
> Looks good:
> 
> Reviewed-by: Christoph Hellwig <hch@lst.de>
> 
> Btw, for  while I've been wondering if we could just get rid of the
> concepts of attached dquots.  With the radix-tree/xarray looks up
> are be fairly cheap, and could be done lockless using RCU.  So we could
> try to just kill the concept of attaching the dquot to the inode and
> just look it up once per operation, where operation preferally is
> something high-level like the actual file/inode operation and not a
> low-level thing inside xfs.

If the dquots are not attached to the inode, how would you pass the
3 dquots per inode down the stack to where they are actually used
inside the filesystem? I mean, we have to get the dquots attached to
the transaction so we can update them in xfs_trans_commit ->
xfs_trans_apply_dquot_deltas(), so somehow we'd have to get them
from the high level file/inode operations down to the XFS
transaction context. And things like writeback need dquots attached
for delayed allocation, so various aops would need to do dquot
lookups, too...

I can see the advantage of doing rcu dquot cache lookups in the xfs
context where we are attaching the dquots to the transaction rather
than attaching them to the inode, but I can't see how the "do it at
a high level" aspect of this would work....

Cheers,

Dave.
Christoph Hellwig Nov. 14, 2019, 2:53 p.m. UTC | #3
On Wed, Nov 13, 2019 at 09:14:48AM +1100, Dave Chinner wrote:
> If the dquots are not attached to the inode, how would you pass the
> 3 dquots per inode down the stack to where they are actually used
> inside the filesystem? I mean, we have to get the dquots attached to
> the transaction so we can update them in xfs_trans_commit ->
> xfs_trans_apply_dquot_deltas(), so somehow we'd have to get them
> from the high level file/inode operations down to the XFS
> transaction context. And things like writeback need dquots attached
> for delayed allocation, so various aops would need to do dquot
> lookups, too...

My prime idea was to attach them to the transaction and keep them
over transaction roles.  Then see what is left and probably use an
on-stack struct containing three dquots.  At that point I know if
that idea was feasible, because if we have too many deep callstacks
where we need to pass that struct it obviously isn't.

> I can see the advantage of doing rcu dquot cache lookups in the xfs
> context where we are attaching the dquots to the transaction rather
> than attaching them to the inode, but I can't see how the "do it at
> a high level" aspect of this would work....

Most of our ops really just have one transaction / set of rolled
over permanent transactions, because if they didn't they wouldn't
be atomic..
diff mbox series

Patch

diff --git a/fs/xfs/xfs_bmap_util.c b/fs/xfs/xfs_bmap_util.c
index 9d731b71e84f..2efd78a9719e 100644
--- a/fs/xfs/xfs_bmap_util.c
+++ b/fs/xfs/xfs_bmap_util.c
@@ -1569,6 +1569,14 @@  xfs_swap_extents(
 		goto out_unlock;
 	}
 
+	error = xfs_qm_dqattach(ip);
+	if (error)
+		goto out_unlock;
+
+	error = xfs_qm_dqattach(tip);
+	if (error)
+		goto out_unlock;
+
 	error = xfs_swap_extent_flush(ip);
 	if (error)
 		goto out_unlock;