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 d6c1b00a4fc8ca88b185bfd09e3c3b47a06fb9d2..3c7506c7553cc6b04ca5f4fa08d345fe4f4115ef 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 8f3cba14ada32a6f6071c38eaf9770a22f84b339..1e7b6b209ee89aee1b553272904a295ec0adf85c 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 8d528d35b7254b7032abcfe58c7fb000b182ae67..b11870d07c5652c605901d0a2b8af7be6211a721 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 80e5026bba44ac719f5047706f9a135b546b2738..3de5287e98d84cc1743b1ecef978289de418e4ce 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 47fe60e1a887319f2751b3a1a1e46677f2c13bda..7d5a31827681dc8f3cf94a80e8a9996bf0afd54b 100644 (file)
@@ -302,13 +302,6 @@ xfs_qm_scall_setqlim(
        if ((newlim->d_fieldmask & XFS_QC_MASK) == 0)
                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
@@ -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;
 }