xfs: fix delalloc quota accounting on failure
PATCH 1/1 xfs: fix delalloc quota accounting on failure
From: Dave Chinner <[email protected]>
xfstest 270 was causing quota reservations way beyond what was sane (ten to hundreds of TB) for a 4GB filesystem. There's a sign problem in the error handling path of xfs_bmapi_reserve_delalloc() because xfs_trans_unreserve_quota_nblks() simple negates the value passed - which doesn't work for an unsigned variable. This causes reservations of close to 2^32 block instead of removing a reservation of a handful of blocks.
Fix the same problem in the other xfs_trans_unreserve_quota_nblks() callers where unsigned integer variables are used, too.
--- fs/xfs/xfs_bmap.c | 2 +- fs/xfs/xfs_iomap.c | 2 +- fs/xfs/xfs_vnodeops.c | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-)
fs/xfs/xfs_bmap.c +1 -1
@@ -4526,7 +4526,7 @@ out_unreserve_blocks:xfs_icsb_modify_counters (mp,XFS_SBS_FDBLOCKS , alen,0 ); out_unreserve_quota:if (XFS_IS_QUOTA_ON (mp)) -xfs_trans_unreserve_quota_nblks (NULL , ip, alen,0 , rt ? +xfs_trans_unreserve_quota_nblks (NULL , ip, (long )alen,0 , rt ?XFS_QMOPT_RES_RTBLKS :XFS_QMOPT_RES_REGBLKS );return error; }
fs/xfs/xfs_iomap.c +1 -1
@@ -246,7 +246,7 @@ out_unlock: out_bmap_cancel:xfs_bmap_cancel (&free_list); -xfs_trans_unreserve_quota_nblks (tp, ip, qblocks,0 , quota_flag); +xfs_trans_unreserve_quota_nblks (tp, ip, (long )qblocks,0 , quota_flag); out_trans_cancel:xfs_trans_cancel (tp,XFS_TRANS_RELEASE_LOG_RES |XFS_TRANS_ABORT ); goto out_unlock;
fs/xfs/xfs_vnodeops.c +1 -1
@@ -1916,7 +1916,7 @@ xfs_alloc_file_space( error0:/* Cancel bmap, unlock inode, unreserve quota blocks, cancel trans */ xfs_bmap_cancel (&free_list); -xfs_trans_unreserve_quota_nblks (tp, ip, qblocks,0 , quota_flag); +xfs_trans_unreserve_quota_nblks (tp, ip, (long )qblocks,0 , quota_flag); error1:/* Just cancel transaction */ xfs_trans_cancel (tp,XFS_TRANS_RELEASE_LOG_RES |XFS_TRANS_ABORT );
Signature · 6 lines
1.7.10 _______________________________________________ xfs mailing list [email protected] http://oss.sgi.com/mailman/listinfo/xfs
Quoted 10 lines · Dave Chinner
From: Dave Chinner <[email protected]>
xfstest 270 was causing quota reservations way beyond what was sane (ten to hundreds of TB) for a 4GB filesystem. There's a sign problem in the error handling path of
xfs_bmapi_reserve_delalloc()becausexfs_trans_unreserve_quota_nblks()simple negates the value passed - which doesn't work for an unsigned variable. This causes reservations of close to 2^32 block instead of removing a reservation of a handful of blocks.
Quoted 4 lines
Fix the same problem in the other
xfs_trans_unreserve_quota_nblks()callers where unsigned integer variables are used, too.Signed-off-by Dave Chinner <[email protected]>
Ouch!
as far as it goes, but a couple thoughts:
1) Should the cast be done in the macro so new callers don't get tripped up?
2) Should we just remove the ninos argument from the macro? It's always passed as 0 (and could potentially suffer the same problem)
something like:
fs/xfs/xfs_quota.h +2 -2
@@ -370,8 +370,8 @@ static inline int xfs_trans_reserve_quota_bydquots(struct xfs_trans *tp,#define xfs_qm_unmount_quotas (mp)#endif /* CONFIG_XFS_QUOTA */ -#define xfs_trans_unreserve_quota_nblks (tp, ip, nblks, ninos, flags) \ - xfs_trans_reserve_quota_nblks(tp, ip, -(nblks), -(ninos), flags) +#define xfs_trans_unreserve_quota_nblks (tp, ip, nblks, flags) \ + xfs_trans_reserve_quota_nblks(tp, ip, -((long)nblks), 0, flags)#define xfs_trans_reserve_quota (tp, mp, ud, gd, nb, ni, f) \ xfs_trans_reserve_quota_bydquots(tp, mp, ud, gd, nb, ni, \ f | XFS_QMOPT_RES_REGBLKS)
Quoted 37 lines
--- fs/xfs/xfs_bmap.c | 2 +- fs/xfs/xfs_iomap.c | 2 +- fs/xfs/xfs_vnodeops.c | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-)fs/xfs/xfs_bmap.c +1
-1@@ -4526,7 +4526,7 @@ out_unreserve_blocks:xfs_icsb_modify_counters (mp,XFS_SBS_FDBLOCKS , alen,0 ); out_unreserve_quota:if (XFS_IS_QUOTA_ON (mp)) -xfs_trans_unreserve_quota_nblks (NULL , ip, alen,0 , rt ? +xfs_trans_unreserve_quota_nblks (NULL , ip, (long )alen,0 , rt ?XFS_QMOPT_RES_RTBLKS :XFS_QMOPT_RES_REGBLKS );return error; }fs/xfs/xfs_iomap.c +1
-1@@ -246,7 +246,7 @@ out_unlock: out_bmap_cancel:xfs_bmap_cancel (&free_list); -xfs_trans_unreserve_quota_nblks (tp, ip, qblocks,0 , quota_flag); +xfs_trans_unreserve_quota_nblks (tp, ip, (long )qblocks,0 , quota_flag); out_trans_cancel:xfs_trans_cancel (tp,XFS_TRANS_RELEASE_LOG_RES |XFS_TRANS_ABORT ); goto out_unlock;fs/xfs/xfs_vnodeops.c +0
-0
fs/xfs/xfs_vnodeops.c xfs_alloc_file_space( · line 1922
Quoted 8 lines
fs/xfs/xfs_vnodeops.c +1
-1@@ -1916,7 +1916,7 @@ xfs_alloc_file_space( error0:/* Cancel bmap, unlock inode, unreserve quota blocks, cancel trans */ xfs_bmap_cancel (&free_list); -xfs_trans_unreserve_quota_nblks (tp, ip, qblocks,0 , quota_flag); +xfs_trans_unreserve_quota_nblks (tp, ip, (long )qblocks,0 , quota_flag); error1:/* Just cancel transaction */ xfs_trans_cancel (tp,XFS_TRANS_RELEASE_LOG_RES |XFS_TRANS_ABORT );
_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs
Quoted 10 lines · Dave Chinner
From: Dave Chinner <[email protected]>
xfstest 270 was causing quota reservations way beyond what was sane (ten to hundreds of TB) for a 4GB filesystem. There's a sign problem in the error handling path of
xfs_bmapi_reserve_delalloc()becausexfs_trans_unreserve_quota_nblks()simple negates the value passed - which doesn't work for an unsigned variable. This causes reservations of close to 2^32 block instead of removing a reservation of a handful of blocks.
Quoted 2 lines
Fix the same problem in the other
xfs_trans_unreserve_quota_nblks()callers where unsigned integer variables are used, too.
eww. Wouldn't it be better to make handle that inside xfs_trans_unreserve_quota_nblks?
_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs
Quoted 32 lines · Eric Sandeen
Quoted 10 lines · Dave Chinner
From: Dave Chinner <[email protected]>
xfstest 270 was causing quota reservations way beyond what was sane (ten to hundreds of TB) for a 4GB filesystem. There's a sign problem in the error handling path of
xfs_bmapi_reserve_delalloc()becausexfs_trans_unreserve_quota_nblks()simple negates the value passed - which doesn't work for an unsigned variable. This causes reservations of close to 2^32 block instead of removing a reservation of a handful of blocks.Quoted 4 lines
Fix the same problem in the other
xfs_trans_unreserve_quota_nblks()callers where unsigned integer variables are used, too.Signed-off-by Dave Chinner <[email protected]>Ouch!
Reviewed-by Eric Sandeen <[email protected]>as far as it goes, but a couple thoughts:
1) Should the cast be done in the macro so new callers don't get tripped up?
2) Should we just remove the ninos argument from the macro? It's always passed as 0 (and could potentially suffer the same problem)something like:
fs/xfs/xfs_quota.h +0
-0
fs/xfs/xfs_quota.h static inline int xfs_trans_reserve_quota_bydquots(struct xfs_trans *tp, · line 377
Quoted 10 lines
fs/xfs/xfs_quota.h +2
-2@@ -370,8 +370,8 @@ static inline int xfs_trans_reserve_quota_bydquots(struct xfs_trans *tp,#define xfs_qm_unmount_quotas (mp)#endif /* CONFIG_XFS_QUOTA */ -#define xfs_trans_unreserve_quota_nblks (tp, ip, nblks, ninos, flags) \ - xfs_trans_reserve_quota_nblks(tp, ip, -(nblks), -(ninos), flags) +#define xfs_trans_unreserve_quota_nblks (tp, ip, nblks, flags) \ + xfs_trans_reserve_quota_nblks(tp, ip, -((long)nblks), 0, flags)#define xfs_trans_reserve_quota (tp, mp, ud, gd, nb, ni, f) \ xfs_trans_reserve_quota_bydquots(tp, mp, ud, gd, nb, ni, \ f | XFS_QMOPT_RES_REGBLKS)
There are also 2 other callers that "already" fixed this, sortakinda:
xfs_bunmapi()
/* Update realtime/data freespace, unreserve quota */
...
(void)xfs_trans_reserve_quota_nblks(NULL,
ip, -((long)del.br_blockcount), 0,
XFS_QMOPT_RES_REGBLKS);
(void)xfs_trans_reserve_quota_nblks(NULL,
ip, -((long)del.br_blockcount), 0,
XFS_QMOPT_RES_REGBLKS);those could be an unreserve call instead, with the sign fix embedded in the macro.
And while we're at it it seems nobody calls xfs_trans_reserve_quota_nblks() with ninos != 0 so I think that arg could be removed from that function too, not just the macro, in another patch.
-Eric
_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs
Quoted 18 lines · Eric Sandeen
Quoted 10 lines · Dave Chinner
From: Dave Chinner <[email protected]>
xfstest 270 was causing quota reservations way beyond what was sane (ten to hundreds of TB) for a 4GB filesystem. There's a sign problem in the error handling path of
xfs_bmapi_reserve_delalloc()becausexfs_trans_unreserve_quota_nblks()simple negates the value passed - which doesn't work for an unsigned variable. This causes reservations of close to 2^32 block instead of removing a reservation of a handful of blocks.Quoted 4 lines
Fix the same problem in the other
xfs_trans_unreserve_quota_nblks()callers where unsigned integer variables are used, too.Signed-off-by Dave Chinner <[email protected]>Ouch!
Quoted 7 lines
Reviewed-by Eric Sandeen <[email protected]>as far as it goes, but a couple thoughts:
1) Should the cast be done in the macro so new callers don't get tripped up?
2) Should we just remove the ninos argument from the macro? It's always passed as 0 (and could potentially suffer the same problem)something like:
3) I'm going to remove the problematic macro altogether.
I just wanted to get this fix out there while I look at the other quota problems I've found. Hint: xfstests _check_quota_usage() doesn't actually work *at all* on XFS (always passes without actually checking quotas), and so it has been hiding problems with either the tests that use it or the quota code for some time....
Cheers,
Dave.
Signature · 7 lines
Dave Chinner [email protected] _______________________________________________ xfs mailing list [email protected] http://oss.sgi.com/mailman/listinfo/xfs