]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
xfs: return the dquot unlocked from xfs_qm_dqget
authorChristoph Hellwig <hch@lst.de>
Mon, 10 Nov 2025 13:23:02 +0000 (14:23 +0100)
committerCarlos Maiolino <cem@kernel.org>
Tue, 11 Nov 2025 10:45:58 +0000 (11:45 +0100)
There is no reason to lock the dquot in xfs_qm_dqget, which just acquires
a reference.  Move the locking to the callers, or remove it in cases where
the caller instantly unlocks the dquot.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Darrick J. Wong <djwong@kernel.org>
Signed-off-by: Carlos Maiolino <cem@kernel.org>
fs/xfs/scrub/dqiterate.c
fs/xfs/scrub/quotacheck.c
fs/xfs/scrub/quotacheck_repair.c
fs/xfs/xfs_dquot.c
fs/xfs/xfs_qm.c
fs/xfs/xfs_qm_bhv.c
fs/xfs/xfs_qm_syscalls.c

index 20c4daedd48df27168b806fed31b9b7a61d68dee..6f1185afbf3960c77892861c3e76c3cd2484b412 100644 (file)
@@ -205,6 +205,7 @@ xchk_dquot_iter(
        if (error)
                return error;
 
+       mutex_lock(&dq->q_qlock);
        cursor->id = dq->q_id + 1;
        *dqpp = dq;
        return 1;
index 180449f654f68f0c0f2a3d5ce32a359ff332efa3..bef63f19cd8772149827d14980c1c3475f7173e7 100644 (file)
@@ -635,6 +635,7 @@ xqcheck_walk_observations(
                if (error)
                        return error;
 
+               mutex_lock(&dq->q_qlock);
                error = xqcheck_compare_dquot(xqc, dqtype, dq);
                mutex_unlock(&dq->q_qlock);
                xfs_qm_dqrele(dq);
index 11153e24b565dc9ceb1e7a23aa02052ccc03a258..3b23219d43eda822b13f0b1f127d36a5112315ed 100644 (file)
@@ -187,6 +187,7 @@ xqcheck_commit_dqtype(
                if (error)
                        return error;
 
+               mutex_lock(&dq->q_qlock);
                error = xqcheck_commit_dquot(xqc, dqtype, dq);
                mutex_unlock(&dq->q_qlock);
                xfs_qm_dqrele(dq);
index 862fec529512fb14fcf5e92936455cf14da04b8c..1c9c17892874f03d64ebca7451aaa2873847ccb9 100644 (file)
@@ -895,7 +895,7 @@ xfs_qm_dqget_checks(
 
 /*
  * Given the file system, id, and type (UDQUOT/GDQUOT/PDQUOT), return a
- * locked dquot, doing an allocation (if requested) as needed.
+ * dquot, doing an allocation (if requested) as needed.
  */
 int
 xfs_qm_dqget(
@@ -940,7 +940,6 @@ restart:
        trace_xfs_dqget_miss(dqp);
 found:
        *O_dqpp = dqp;
-       mutex_lock(&dqp->q_qlock);
        return 0;
 }
 
@@ -1098,6 +1097,7 @@ xfs_qm_dqget_next(
                else if (error != 0)
                        break;
 
+               mutex_lock(&dqp->q_qlock);
                if (!XFS_IS_DQUOT_UNINITIALIZED(dqp)) {
                        *dqpp = dqp;
                        return 0;
index f3f7947bc4ed401e80d9283734fcc6c67f56db28..a81b8b7a4e4f528dfb579ade024f65f4ed5ac85b 100644 (file)
@@ -1268,6 +1268,7 @@ xfs_qm_quotacheck_dqadjust(
                return error;
        }
 
+       mutex_lock(&dqp->q_qlock);
        error = xfs_dquot_attach_buf(NULL, dqp);
        if (error)
                goto out_unlock;
@@ -1907,7 +1908,6 @@ xfs_qm_vop_dqalloc(
                        /*
                         * Get the ilock in the right order.
                         */
-                       mutex_unlock(&uq->q_qlock);
                        lockflags = XFS_ILOCK_SHARED;
                        xfs_ilock(ip, lockflags);
                } else {
@@ -1929,7 +1929,6 @@ xfs_qm_vop_dqalloc(
                                ASSERT(error != -ENOENT);
                                goto error_rele;
                        }
-                       mutex_unlock(&gq->q_qlock);
                        lockflags = XFS_ILOCK_SHARED;
                        xfs_ilock(ip, lockflags);
                } else {
@@ -1947,7 +1946,6 @@ xfs_qm_vop_dqalloc(
                                ASSERT(error != -ENOENT);
                                goto error_rele;
                        }
-                       mutex_unlock(&pq->q_qlock);
                        lockflags = XFS_ILOCK_SHARED;
                        xfs_ilock(ip, lockflags);
                } else {
index e5a30b12253c65e0a49658b6b7da3ef02bf30bb1..edc0aef3cf34a3e7dfd6538d8382dedf2ae84845 100644 (file)
@@ -73,6 +73,7 @@ xfs_qm_statvfs(
        struct xfs_dquot        *dqp;
 
        if (!xfs_qm_dqget(mp, ip->i_projid, XFS_DQTYPE_PROJ, false, &dqp)) {
+               mutex_lock(&dqp->q_qlock);
                xfs_fill_statvfs_from_dquot(statp, ip, dqp);
                mutex_unlock(&dqp->q_qlock);
                xfs_qm_dqrele(dqp);
index 441f9806cddb1aad0d736e74976e809f97ebd758..6c8924780d7a6983766efeeed5d7ca41c2dff271 100644 (file)
@@ -302,6 +302,7 @@ xfs_qm_scall_setqlim(
                return error;
        }
 
+       mutex_lock(&dqp->q_qlock);
        defq = xfs_get_defquota(q, xfs_dquot_type(dqp));
        mutex_unlock(&dqp->q_qlock);
 
@@ -459,6 +460,7 @@ xfs_qm_scall_getquota(
         * If everything's NULL, this dquot doesn't quite exist as far as
         * our utility programs are concerned.
         */
+       mutex_lock(&dqp->q_qlock);
        if (XFS_IS_DQUOT_UNINITIALIZED(dqp)) {
                error = -ENOENT;
                goto out_put;