Skip to content

Commit 0494f04

Browse files
Christoph Hellwigcmaiolino
authored andcommitted
xfs: consolidate q_qlock locking in xfs_qm_dqget and xfs_qm_dqget_inode
Move taking q_qlock from the cache lookup / insert helpers into the main functions and do it just before returning to the caller. 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 6b6e6e7 commit 0494f04

1 file changed

Lines changed: 9 additions & 14 deletions

File tree

fs/xfs/xfs_dquot.c

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -826,15 +826,13 @@ xfs_qm_dqget_cache_lookup(
826826

827827
trace_xfs_dqget_hit(dqp);
828828
XFS_STATS_INC(mp, xs_qm_dqcachehits);
829-
mutex_lock(&dqp->q_qlock);
830829
return dqp;
831830
}
832831

833832
/*
834833
* Try to insert a new dquot into the in-core cache. If an error occurs the
835834
* caller should throw away the dquot and start over. Otherwise, the dquot
836-
* is returned locked (and held by the cache) as if there had been a cache
837-
* hit.
835+
* is returned (and held by the cache) as if there had been a cache hit.
838836
*
839837
* The insert needs to be done under memalloc_nofs context because the radix
840838
* tree can do memory allocation during insert. The qi->qi_tree_lock is taken in
@@ -861,8 +859,6 @@ xfs_qm_dqget_cache_insert(
861859
goto out_unlock;
862860
}
863861

864-
/* Return a locked dquot to the caller, with a reference taken. */
865-
mutex_lock(&dqp->q_qlock);
866862
lockref_init(&dqp->q_lockref);
867863
qi->qi_dquots++;
868864

@@ -920,10 +916,8 @@ xfs_qm_dqget(
920916

921917
restart:
922918
dqp = xfs_qm_dqget_cache_lookup(mp, qi, tree, id);
923-
if (dqp) {
924-
*O_dqpp = dqp;
925-
return 0;
926-
}
919+
if (dqp)
920+
goto found;
927921

928922
error = xfs_qm_dqread(mp, id, type, can_alloc, &dqp);
929923
if (error)
@@ -944,7 +938,9 @@ xfs_qm_dqget(
944938
}
945939

946940
trace_xfs_dqget_miss(dqp);
941+
found:
947942
*O_dqpp = dqp;
943+
mutex_lock(&dqp->q_qlock);
948944
return 0;
949945
}
950946

@@ -1019,10 +1015,8 @@ xfs_qm_dqget_inode(
10191015

10201016
restart:
10211017
dqp = xfs_qm_dqget_cache_lookup(mp, qi, tree, id);
1022-
if (dqp) {
1023-
*O_dqpp = dqp;
1024-
return 0;
1025-
}
1018+
if (dqp)
1019+
goto found;
10261020

10271021
/*
10281022
* Dquot cache miss. We don't want to keep the inode lock across
@@ -1048,7 +1042,6 @@ xfs_qm_dqget_inode(
10481042
if (dqp1) {
10491043
xfs_qm_dqdestroy(dqp);
10501044
dqp = dqp1;
1051-
mutex_lock(&dqp->q_qlock);
10521045
goto dqret;
10531046
}
10541047
} else {
@@ -1074,7 +1067,9 @@ xfs_qm_dqget_inode(
10741067
dqret:
10751068
xfs_assert_ilocked(ip, XFS_ILOCK_EXCL);
10761069
trace_xfs_dqget_miss(dqp);
1070+
found:
10771071
*O_dqpp = dqp;
1072+
mutex_lock(&dqp->q_qlock);
10781073
return 0;
10791074
}
10801075

0 commit comments

Comments
 (0)