Skip to content

Commit b4d05e3

Browse files
Christoph HellwigBen Myers
authored andcommitted
xfs: avoid taking the ilock unnessecarily in xfs_qm_dqattach
Check if we actually need to attach a dquot before taking the ilock in xfs_qm_dqattach. This avoid superflous lock roundtrips for the common cases of quota support compiled in but not activated on a filesystem and an inode that already has the dquots attached. Signed-off-by: Christoph Hellwig <[email protected]> Reviewed-by: Mark Tinguely <[email protected]> Reviewed-by: Dave Chinner <[email protected]> Signed-off-by: Ben Myers <[email protected]>
1 parent 8a00ebe commit b4d05e3

File tree

1 file changed

+21
-5
lines changed

1 file changed

+21
-5
lines changed

fs/xfs/xfs_qm.c

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -483,6 +483,23 @@ xfs_qm_dqattach_grouphint(
483483
xfs_dqunlock(udq);
484484
}
485485

486+
static bool
487+
xfs_qm_need_dqattach(
488+
struct xfs_inode *ip)
489+
{
490+
struct xfs_mount *mp = ip->i_mount;
491+
492+
if (!XFS_IS_QUOTA_RUNNING(mp))
493+
return false;
494+
if (!XFS_IS_QUOTA_ON(mp))
495+
return false;
496+
if (!XFS_NOT_DQATTACHED(mp, ip))
497+
return false;
498+
if (ip->i_ino == mp->m_sb.sb_uquotino ||
499+
ip->i_ino == mp->m_sb.sb_gquotino)
500+
return false;
501+
return true;
502+
}
486503

487504
/*
488505
* Given a locked inode, attach dquot(s) to it, taking U/G/P-QUOTAON
@@ -500,11 +517,7 @@ xfs_qm_dqattach_locked(
500517
uint nquotas = 0;
501518
int error = 0;
502519

503-
if (!XFS_IS_QUOTA_RUNNING(mp) ||
504-
!XFS_IS_QUOTA_ON(mp) ||
505-
!XFS_NOT_DQATTACHED(mp, ip) ||
506-
ip->i_ino == mp->m_sb.sb_uquotino ||
507-
ip->i_ino == mp->m_sb.sb_gquotino)
520+
if (!xfs_qm_need_dqattach(ip))
508521
return 0;
509522

510523
ASSERT(xfs_isilocked(ip, XFS_ILOCK_EXCL));
@@ -575,6 +588,9 @@ xfs_qm_dqattach(
575588
{
576589
int error;
577590

591+
if (!xfs_qm_need_dqattach(ip))
592+
return 0;
593+
578594
xfs_ilock(ip, XFS_ILOCK_EXCL);
579595
error = xfs_qm_dqattach_locked(ip, flags);
580596
xfs_iunlock(ip, XFS_ILOCK_EXCL);

0 commit comments

Comments
 (0)