Skip to content

Commit 6a7bb6c

Browse files
Christoph Hellwigcmaiolino
authored andcommitted
xfs: reduce ilock roundtrips in xfs_qm_vop_dqalloc
xfs_qm_vop_dqalloc only needs the (exclusive) ilock for attaching dquots to the inode if not done so yet. All the other locks don't touch the inode and don't need the ilock - the i_rwsem / iolock protects against changes to the IDs while we are in a method, and the ilock would not help because dropping it for the dqget calls would be racy anyway. Signed-off-by: Christoph Hellwig <hch@lst.de> Reviewed-by: Darrick J. Wong <djwong@kernel.org> Signed-off-by: Carlos Maiolino <cem@kernel.org>
1 parent 13d3c1a commit 6a7bb6c

1 file changed

Lines changed: 3 additions & 29 deletions

File tree

fs/xfs/xfs_qm.c

Lines changed: 3 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1861,16 +1861,12 @@ xfs_qm_vop_dqalloc(
18611861
struct xfs_dquot *gq = NULL;
18621862
struct xfs_dquot *pq = NULL;
18631863
int error;
1864-
uint lockflags;
18651864

18661865
if (!XFS_IS_QUOTA_ON(mp))
18671866
return 0;
18681867

18691868
ASSERT(!xfs_is_metadir_inode(ip));
18701869

1871-
lockflags = XFS_ILOCK_EXCL;
1872-
xfs_ilock(ip, lockflags);
1873-
18741870
if ((flags & XFS_QMOPT_INHERIT) && XFS_INHERIT_GID(ip))
18751871
gid = inode->i_gid;
18761872

@@ -1879,37 +1875,22 @@ xfs_qm_vop_dqalloc(
18791875
* if necessary. The dquot(s) will not be locked.
18801876
*/
18811877
if (XFS_NOT_DQATTACHED(mp, ip)) {
1878+
xfs_ilock(ip, XFS_ILOCK_EXCL);
18821879
error = xfs_qm_dqattach_locked(ip, true);
1883-
if (error) {
1884-
xfs_iunlock(ip, lockflags);
1880+
xfs_iunlock(ip, XFS_ILOCK_EXCL);
1881+
if (error)
18851882
return error;
1886-
}
18871883
}
18881884

18891885
if ((flags & XFS_QMOPT_UQUOTA) && XFS_IS_UQUOTA_ON(mp)) {
18901886
ASSERT(O_udqpp);
18911887
if (!uid_eq(inode->i_uid, uid)) {
1892-
/*
1893-
* What we need is the dquot that has this uid, and
1894-
* if we send the inode to dqget, the uid of the inode
1895-
* takes priority over what's sent in the uid argument.
1896-
* We must unlock inode here before calling dqget if
1897-
* we're not sending the inode, because otherwise
1898-
* we'll deadlock by doing trans_reserve while
1899-
* holding ilock.
1900-
*/
1901-
xfs_iunlock(ip, lockflags);
19021888
error = xfs_qm_dqget(mp, from_kuid(user_ns, uid),
19031889
XFS_DQTYPE_USER, true, &uq);
19041890
if (error) {
19051891
ASSERT(error != -ENOENT);
19061892
return error;
19071893
}
1908-
/*
1909-
* Get the ilock in the right order.
1910-
*/
1911-
lockflags = XFS_ILOCK_SHARED;
1912-
xfs_ilock(ip, lockflags);
19131894
} else {
19141895
/*
19151896
* Take an extra reference, because we'll return
@@ -1922,15 +1903,12 @@ xfs_qm_vop_dqalloc(
19221903
if ((flags & XFS_QMOPT_GQUOTA) && XFS_IS_GQUOTA_ON(mp)) {
19231904
ASSERT(O_gdqpp);
19241905
if (!gid_eq(inode->i_gid, gid)) {
1925-
xfs_iunlock(ip, lockflags);
19261906
error = xfs_qm_dqget(mp, from_kgid(user_ns, gid),
19271907
XFS_DQTYPE_GROUP, true, &gq);
19281908
if (error) {
19291909
ASSERT(error != -ENOENT);
19301910
goto error_rele;
19311911
}
1932-
lockflags = XFS_ILOCK_SHARED;
1933-
xfs_ilock(ip, lockflags);
19341912
} else {
19351913
ASSERT(ip->i_gdquot);
19361914
gq = xfs_qm_dqhold(ip->i_gdquot);
@@ -1939,23 +1917,19 @@ xfs_qm_vop_dqalloc(
19391917
if ((flags & XFS_QMOPT_PQUOTA) && XFS_IS_PQUOTA_ON(mp)) {
19401918
ASSERT(O_pdqpp);
19411919
if (ip->i_projid != prid) {
1942-
xfs_iunlock(ip, lockflags);
19431920
error = xfs_qm_dqget(mp, prid,
19441921
XFS_DQTYPE_PROJ, true, &pq);
19451922
if (error) {
19461923
ASSERT(error != -ENOENT);
19471924
goto error_rele;
19481925
}
1949-
lockflags = XFS_ILOCK_SHARED;
1950-
xfs_ilock(ip, lockflags);
19511926
} else {
19521927
ASSERT(ip->i_pdquot);
19531928
pq = xfs_qm_dqhold(ip->i_pdquot);
19541929
}
19551930
}
19561931
trace_xfs_dquot_dqalloc(ip);
19571932

1958-
xfs_iunlock(ip, lockflags);
19591933
if (O_udqpp)
19601934
*O_udqpp = uq;
19611935
else

0 commit comments

Comments
 (0)