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 <hch@lst.de>
Reviewed-by: Mark Tinguely <tinguely@sgi.com>
Reviewed-by: Dave Chinner <dchinner@redhat.com>
Signed-off-by: Ben Myers <bpm@sgi.com>
This commit is contained in:
Christoph Hellwig 2012-03-27 10:34:46 -04:00 committed by Ben Myers
parent 8a00ebe4cf
commit b4d05e3019

View File

@ -483,6 +483,23 @@ xfs_qm_dqattach_grouphint(
xfs_dqunlock(udq); xfs_dqunlock(udq);
} }
static bool
xfs_qm_need_dqattach(
struct xfs_inode *ip)
{
struct xfs_mount *mp = ip->i_mount;
if (!XFS_IS_QUOTA_RUNNING(mp))
return false;
if (!XFS_IS_QUOTA_ON(mp))
return false;
if (!XFS_NOT_DQATTACHED(mp, ip))
return false;
if (ip->i_ino == mp->m_sb.sb_uquotino ||
ip->i_ino == mp->m_sb.sb_gquotino)
return false;
return true;
}
/* /*
* Given a locked inode, attach dquot(s) to it, taking U/G/P-QUOTAON * Given a locked inode, attach dquot(s) to it, taking U/G/P-QUOTAON
@ -500,11 +517,7 @@ xfs_qm_dqattach_locked(
uint nquotas = 0; uint nquotas = 0;
int error = 0; int error = 0;
if (!XFS_IS_QUOTA_RUNNING(mp) || if (!xfs_qm_need_dqattach(ip))
!XFS_IS_QUOTA_ON(mp) ||
!XFS_NOT_DQATTACHED(mp, ip) ||
ip->i_ino == mp->m_sb.sb_uquotino ||
ip->i_ino == mp->m_sb.sb_gquotino)
return 0; return 0;
ASSERT(xfs_isilocked(ip, XFS_ILOCK_EXCL)); ASSERT(xfs_isilocked(ip, XFS_ILOCK_EXCL));
@ -575,6 +588,9 @@ xfs_qm_dqattach(
{ {
int error; int error;
if (!xfs_qm_need_dqattach(ip))
return 0;
xfs_ilock(ip, XFS_ILOCK_EXCL); xfs_ilock(ip, XFS_ILOCK_EXCL);
error = xfs_qm_dqattach_locked(ip, flags); error = xfs_qm_dqattach_locked(ip, flags);
xfs_iunlock(ip, XFS_ILOCK_EXCL); xfs_iunlock(ip, XFS_ILOCK_EXCL);