xfs: fix quotaoff mutex usage now that we don't support disabling it
authorDarrick J. Wong <djwong@kernel.org>
Wed, 15 Dec 2021 19:53:16 +0000 (11:53 -0800)
committerDarrick J. Wong <djwong@kernel.org>
Tue, 21 Dec 2021 17:49:41 +0000 (09:49 -0800)
Prior to commit 40b52225e58c ("xfs: remove support for disabling quota
accounting on a mounted file system"), we used the quotaoff mutex to
protect dquot operations against quotaoff trying to pull down dquots as
part of disabling quota.

Now that we only support turning off quota enforcement, the quotaoff
mutex only protects changes in m_qflags/sb_qflags.  We don't need it to
protect dquots, which means we can remove it from setqlimits and the
dquot scrub code.  While we're at it, fix the function that forces
quotacheck, since it should have been taking the quotaoff mutex.

Signed-off-by: Darrick J. Wong <djwong@kernel.org>
Reviewed-by: Dave Chinner <dchinner@redhat.com>
fs/xfs/scrub/quota.c
fs/xfs/scrub/repair.c
fs/xfs/scrub/scrub.c
fs/xfs/scrub/scrub.h
fs/xfs/xfs_qm_syscalls.c

index d6c1b00..3c7506c 100644 (file)
@@ -48,10 +48,10 @@ xchk_setup_quota(
        dqtype = xchk_quota_to_dqtype(sc);
        if (dqtype == 0)
                return -EINVAL;
-       sc->flags |= XCHK_HAS_QUOTAOFFLOCK;
-       mutex_lock(&sc->mp->m_quotainfo->qi_quotaofflock);
+
        if (!xfs_this_quota_on(sc->mp, dqtype))
                return -ENOENT;
+
        error = xchk_setup_fs(sc);
        if (error)
                return error;
index 8f3cba1..1e7b6b2 100644 (file)
@@ -25,6 +25,7 @@
 #include "xfs_ag.h"
 #include "xfs_ag_resv.h"
 #include "xfs_quota.h"
+#include "xfs_qm.h"
 #include "scrub/scrub.h"
 #include "scrub/common.h"
 #include "scrub/trace.h"
@@ -912,11 +913,13 @@ xrep_force_quotacheck(
        if (!(flag & sc->mp->m_qflags))
                return;
 
+       mutex_lock(&sc->mp->m_quotainfo->qi_quotaofflock);
        sc->mp->m_qflags &= ~flag;
        spin_lock(&sc->mp->m_sb_lock);
        sc->mp->m_sb.sb_qflags &= ~flag;
        spin_unlock(&sc->mp->m_sb_lock);
        xfs_log_sb(sc->tp);
+       mutex_unlock(&sc->mp->m_quotainfo->qi_quotaofflock);
 }
 
 /*
index 8d528d3..b11870d 100644 (file)
@@ -173,10 +173,6 @@ xchk_teardown(
                mnt_drop_write_file(sc->file);
        if (sc->flags & XCHK_REAPING_DISABLED)
                xchk_start_reaping(sc);
-       if (sc->flags & XCHK_HAS_QUOTAOFFLOCK) {
-               mutex_unlock(&sc->mp->m_quotainfo->qi_quotaofflock);
-               sc->flags &= ~XCHK_HAS_QUOTAOFFLOCK;
-       }
        if (sc->buf) {
                kmem_free(sc->buf);
                sc->buf = NULL;
index 80e5026..3de5287 100644 (file)
@@ -88,7 +88,6 @@ struct xfs_scrub {
 
 /* XCHK state flags grow up from zero, XREP state flags grown down from 2^31 */
 #define XCHK_TRY_HARDER                (1 << 0)  /* can't get resources, try again */
-#define XCHK_HAS_QUOTAOFFLOCK  (1 << 1)  /* we hold the quotaoff lock */
 #define XCHK_REAPING_DISABLED  (1 << 2)  /* background block reaping paused */
 #define XREP_ALREADY_FIXED     (1 << 31) /* checking our repair work */
 
index 47fe60e..7d5a318 100644 (file)
@@ -303,13 +303,6 @@ xfs_qm_scall_setqlim(
                return 0;
 
        /*
-        * We don't want to race with a quotaoff so take the quotaoff lock.
-        * We don't hold an inode lock, so there's nothing else to stop
-        * a quotaoff from happening.
-        */
-       mutex_lock(&q->qi_quotaofflock);
-
-       /*
         * Get the dquot (locked) before we start, as we need to do a
         * transaction to allocate it if it doesn't exist. Once we have the
         * dquot, unlock it so we can start the next transaction safely. We hold
@@ -319,7 +312,7 @@ xfs_qm_scall_setqlim(
        error = xfs_qm_dqget(mp, id, type, true, &dqp);
        if (error) {
                ASSERT(error != -ENOENT);
-               goto out_unlock;
+               return error;
        }
 
        defq = xfs_get_defquota(q, xfs_dquot_type(dqp));
@@ -415,8 +408,6 @@ xfs_qm_scall_setqlim(
 
 out_rele:
        xfs_qm_dqrele(dqp);
-out_unlock:
-       mutex_unlock(&q->qi_quotaofflock);
        return error;
 }