]> git.kernelconcepts.de Git - karo-tx-linux.git/blobdiff - fs/xfs/quota/xfs_qm.c
[XFS] Make project quota enforcement return an error code consistent with
[karo-tx-linux.git] / fs / xfs / quota / xfs_qm.c
index 5328a2937127dedd66344460025e339839de75de..7fb5eca9bd5017df4ba44267ef496c7319b260f7 100644 (file)
@@ -68,6 +68,9 @@ kmem_zone_t   *qm_dqzone;
 kmem_zone_t    *qm_dqtrxzone;
 STATIC kmem_shaker_t   xfs_qm_shaker;
 
+STATIC cred_t  xfs_zerocr;
+STATIC xfs_inode_t     xfs_zeroino;
+
 STATIC void    xfs_qm_list_init(xfs_dqlist_t *, char *, int);
 STATIC void    xfs_qm_list_destroy(xfs_dqlist_t *);
 
@@ -167,7 +170,7 @@ xfs_Gqm_init(void)
        xqm->qm_dqfree_ratio = XFS_QM_DQFREE_RATIO;
        xqm->qm_nrefs = 0;
 #ifdef DEBUG
-       mutex_init(&qcheck_lock, MUTEX_DEFAULT, "qchk");
+       mutex_init(&qcheck_lock);
 #endif
        return xqm;
 }
@@ -286,7 +289,7 @@ xfs_qm_rele_quotafs_ref(
 
 /*
  * This is called at mount time from xfs_mountfs to initialize the quotainfo
- * structure and start the global quotamanager (xfs_Gqm) if it hasn't done
+ * structure and start the global quota manager (xfs_Gqm) if it hasn't done
  * so already. Note that the superblock has not been read in yet.
  */
 void
@@ -497,7 +500,7 @@ xfs_qm_dqflush_all(
        int             error;
 
        if (mp->m_quotainfo == NULL)
-               return (0);
+               return 0;
        niters = 0;
 again:
        xfs_qm_mplist_lock(mp);
@@ -528,7 +531,7 @@ again:
                error = xfs_qm_dqflush(dqp, flags);
                xfs_dqunlock(dqp);
                if (error)
-                       return (error);
+                       return error;
 
                xfs_qm_mplist_lock(mp);
                if (recl != XFS_QI_MPLRECLAIMS(mp)) {
@@ -540,7 +543,7 @@ again:
 
        xfs_qm_mplist_unlock(mp);
        /* return ! busy */
-       return (0);
+       return 0;
 }
 /*
  * Release the group dquot pointers the user dquots may be
@@ -599,7 +602,7 @@ xfs_qm_dqpurge_int(
        int             nmisses;
 
        if (mp->m_quotainfo == NULL)
-               return (0);
+               return 0;
 
        dqtype = (flags & XFS_QMOPT_UQUOTA) ? XFS_DQ_USER : 0;
        dqtype |= (flags & XFS_QMOPT_PQUOTA) ? XFS_DQ_PROJ : 0;
@@ -796,7 +799,7 @@ xfs_qm_dqattach_one(
                        ASSERT(XFS_DQ_IS_LOCKED(dqp));
        }
 #endif
-       return (error);
+       return error;
 }
 
 
@@ -804,7 +807,7 @@ xfs_qm_dqattach_one(
  * Given a udquot and gdquot, attach a ptr to the group dquot in the
  * udquot as a hint for future lookups. The idea sounds simple, but the
  * execution isn't, because the udquot might have a group dquot attached
- * already and getting rid of that gets us into lock ordering contraints.
+ * already and getting rid of that gets us into lock ordering constraints.
  * The process is complicated more by the fact that the dquots may or may not
  * be locked on entry.
  */
@@ -897,7 +900,7 @@ xfs_qm_dqattach(
            (! XFS_NOT_DQATTACHED(mp, ip)) ||
            (ip->i_ino == mp->m_sb.sb_uquotino) ||
            (ip->i_ino == mp->m_sb.sb_gquotino))
-               return (0);
+               return 0;
 
        ASSERT((flags & XFS_QMOPT_ILOCKED) == 0 ||
               XFS_ISLOCKED_INODE_EXCL(ip));
@@ -984,7 +987,7 @@ xfs_qm_dqattach(
        else
                ASSERT(XFS_ISLOCKED_INODE_EXCL(ip));
 #endif
-       return (error);
+       return error;
 }
 
 /*
@@ -1049,7 +1052,7 @@ xfs_qm_sync(
         */
        if (! XFS_IS_QUOTA_ON(mp)) {
                xfs_qm_mplist_unlock(mp);
-               return (0);
+               return 0;
        }
        FOREACH_DQUOT_IN_MP(dqp, mp) {
                /*
@@ -1091,10 +1094,10 @@ xfs_qm_sync(
                        }
                        /*
                         * If we can't grab the flush lock then if the caller
-                        * really wanted us to give this our best shot,
+                        * really wanted us to give this our best shot, so
                         * see if we can give a push to the buffer before we wait
                         * on the flush lock. At this point, we know that
-                        * eventhough the dquot is being flushed,
+                        * even though the dquot is being flushed,
                         * it has (new) dirty data.
                         */
                        xfs_qm_dqflock_pushbuf_wait(dqp);
@@ -1109,9 +1112,9 @@ xfs_qm_sync(
                error = xfs_qm_dqflush(dqp, flush_flags);
                xfs_dqunlock(dqp);
                if (error && XFS_FORCED_SHUTDOWN(mp))
-                       return(0);      /* Need to prevent umount failure */
+                       return 0;       /* Need to prevent umount failure */
                else if (error)
-                       return (error);
+                       return error;
 
                xfs_qm_mplist_lock(mp);
                if (recl != XFS_QI_MPLRECLAIMS(mp)) {
@@ -1124,7 +1127,7 @@ xfs_qm_sync(
        }
 
        xfs_qm_mplist_unlock(mp);
-       return (0);
+       return 0;
 }
 
 
@@ -1146,7 +1149,7 @@ xfs_qm_init_quotainfo(
         * Tell XQM that we exist as soon as possible.
         */
        if ((error = xfs_qm_hold_quotafs_ref(mp))) {
-               return (error);
+               return error;
        }
 
        qinf = mp->m_quotainfo = kmem_zalloc(sizeof(xfs_quotainfo_t), KM_SLEEP);
@@ -1158,7 +1161,7 @@ xfs_qm_init_quotainfo(
        if ((error = xfs_qm_init_quotainos(mp))) {
                kmem_free(qinf, sizeof(xfs_quotainfo_t));
                mp->m_quotainfo = NULL;
-               return (error);
+               return error;
        }
 
        spinlock_init(&qinf->qi_pinlock, "xfs_qinf_pin");
@@ -1166,7 +1169,7 @@ xfs_qm_init_quotainfo(
        qinf->qi_dqreclaims = 0;
 
        /* mutex used to serialize quotaoffs */
-       mutex_init(&qinf->qi_quotaofflock, MUTEX_DEFAULT, "qoff");
+       mutex_init(&qinf->qi_quotaofflock);
 
        /* Precalc some constants */
        qinf->qi_dqchunklen = XFS_FSB_TO_BB(mp, XFS_DQUOT_CLUSTER_SIZE_FSB);
@@ -1232,7 +1235,7 @@ xfs_qm_init_quotainfo(
                qinf->qi_rtbwarnlimit = XFS_QM_RTBWARNLIMIT;
        }
 
-       return (0);
+       return 0;
 }
 
 
@@ -1285,7 +1288,7 @@ xfs_qm_list_init(
        char            *str,
        int             n)
 {
-       mutex_init(&list->qh_lock, MUTEX_DEFAULT, str);
+       mutex_init(&list->qh_lock);
        list->qh_next = NULL;
        list->qh_version = 0;
        list->qh_nelems = 0;
@@ -1332,7 +1335,7 @@ xfs_qm_dqget_noattach(
                         */
                        ASSERT(error != ESRCH);
                        ASSERT(error != ENOENT);
-                       return (error);
+                       return error;
                }
                ASSERT(udqp);
        }
@@ -1355,7 +1358,7 @@ xfs_qm_dqget_noattach(
                                xfs_qm_dqrele(udqp);
                        ASSERT(error != ESRCH);
                        ASSERT(error != ENOENT);
-                       return (error);
+                       return error;
                }
                ASSERT(gdqp);
 
@@ -1376,7 +1379,7 @@ xfs_qm_dqget_noattach(
        if (udqp) ASSERT(XFS_DQ_IS_LOCKED(udqp));
        if (gdqp) ASSERT(XFS_DQ_IS_LOCKED(gdqp));
 #endif
-       return (0);
+       return 0;
 }
 
 /*
@@ -1392,26 +1395,24 @@ xfs_qm_qino_alloc(
 {
        xfs_trans_t     *tp;
        int             error;
-       unsigned long s;
-       cred_t          zerocr;
+       unsigned long   s;
        int             committed;
 
-       tp = xfs_trans_alloc(mp,XFS_TRANS_QM_QINOCREATE);
+       tp = xfs_trans_alloc(mp, XFS_TRANS_QM_QINOCREATE);
        if ((error = xfs_trans_reserve(tp,
                                      XFS_QM_QINOCREATE_SPACE_RES(mp),
                                      XFS_CREATE_LOG_RES(mp), 0,
                                      XFS_TRANS_PERM_LOG_RES,
                                      XFS_CREATE_LOG_COUNT))) {
                xfs_trans_cancel(tp, 0);
-               return (error);
+               return error;
        }
-       memset(&zerocr, 0, sizeof(zerocr));
 
-       if ((error = xfs_dir_ialloc(&tp, mp->m_rootip, S_IFREG, 1, 0,
-                                  &zerocr, 0, 1, ip, &committed))) {
+       if ((error = xfs_dir_ialloc(&tp, &xfs_zeroino, S_IFREG, 1, 0,
+                                  &xfs_zerocr, 0, 1, ip, &committed))) {
                xfs_trans_cancel(tp, XFS_TRANS_RELEASE_LOG_RES |
                                 XFS_TRANS_ABORT);
-               return (error);
+               return error;
        }
 
        /*
@@ -1459,9 +1460,9 @@ xfs_qm_qino_alloc(
        if ((error = xfs_trans_commit(tp, XFS_TRANS_RELEASE_LOG_RES,
                                     NULL))) {
                xfs_fs_cmn_err(CE_ALERT, mp, "XFS qino_alloc failed!");
-               return (error);
+               return error;
        }
-       return (0);
+       return 0;
 }
 
 
@@ -1490,7 +1491,7 @@ xfs_qm_reset_dqcounts(
                /*
                 * Do a sanity check, and if needed, repair the dqblk. Don't
                 * output any warnings because it's perfectly possible to
-                * find unitialized dquot blks. See comment in xfs_qm_dqcheck.
+                * find uninitialised dquot blks. See comment in xfs_qm_dqcheck.
                 */
                (void) xfs_qm_dqcheck(ddq, id+j, type, XFS_QMOPT_DQREPAIR,
                                      "xfs_quotacheck");
@@ -1506,7 +1507,7 @@ xfs_qm_reset_dqcounts(
                ddq = (xfs_disk_dquot_t *) ((xfs_dqblk_t *)ddq + 1);
        }
 
-       return (0);
+       return 0;
 }
 
 STATIC int
@@ -1555,7 +1556,7 @@ xfs_qm_dqiter_bufs(
                bno++;
                firstid += XFS_QM_DQPERBLK(mp);
        }
-       return (error);
+       return error;
 }
 
 /*
@@ -1579,12 +1580,12 @@ xfs_qm_dqiterate(
 
        error = 0;
        /*
-        * This looks racey, but we can't keep an inode lock across a
+        * This looks racy, but we can't keep an inode lock across a
         * trans_reserve. But, this gets called during quotacheck, and that
         * happens only at mount time which is single threaded.
         */
        if (qip->i_d.di_nblocks == 0)
-               return (0);
+               return 0;
 
        map = kmem_alloc(XFS_DQITER_MAP_SIZE * sizeof(*map), KM_SLEEP);
 
@@ -1653,7 +1654,7 @@ xfs_qm_dqiterate(
 
        kmem_free(map, XFS_DQITER_MAP_SIZE * sizeof(*map));
 
-       return (error);
+       return error;
 }
 
 /*
@@ -1703,9 +1704,9 @@ xfs_qm_get_rtblks(
        xfs_qcnt_t      *O_rtblks)
 {
        xfs_filblks_t   rtblks;                 /* total rt blks */
+       xfs_extnum_t    idx;                    /* extent record index */
        xfs_ifork_t     *ifp;                   /* inode fork pointer */
        xfs_extnum_t    nextents;               /* number of extent entries */
-       xfs_bmbt_rec_t  *base;                  /* base of extent array */
        xfs_bmbt_rec_t  *ep;                    /* pointer to an extent entry */
        int             error;
 
@@ -1713,15 +1714,16 @@ xfs_qm_get_rtblks(
        ifp = XFS_IFORK_PTR(ip, XFS_DATA_FORK);
        if (!(ifp->if_flags & XFS_IFEXTENTS)) {
                if ((error = xfs_iread_extents(NULL, ip, XFS_DATA_FORK)))
-                       return (error);
+                       return error;
        }
        rtblks = 0;
-       nextents = ifp->if_bytes / sizeof(xfs_bmbt_rec_t);
-       base = &ifp->if_u1.if_extents[0];
-       for (ep = base; ep < &base[nextents]; ep++)
+       nextents = ifp->if_bytes / (uint)sizeof(xfs_bmbt_rec_t);
+       for (idx = 0; idx < nextents; idx++) {
+               ep = xfs_iext_get_ext(ifp, idx);
                rtblks += xfs_bmbt_get_blockcount(ep);
+       }
        *O_rtblks = (xfs_qcnt_t)rtblks;
-       return (0);
+       return 0;
 }
 
 /*
@@ -1765,7 +1767,7 @@ xfs_qm_dqusage_adjust(
         */
        if ((error = xfs_iget(mp, NULL, ino, 0, XFS_ILOCK_EXCL, &ip, bno))) {
                *res = BULKSTAT_RV_NOTHING;
-               return (error);
+               return error;
        }
 
        if (ip->i_d.di_mode == 0) {
@@ -1783,7 +1785,7 @@ xfs_qm_dqusage_adjust(
        if ((error = xfs_qm_dqget_noattach(ip, &udqp, &gdqp))) {
                xfs_iput(ip, XFS_ILOCK_EXCL);
                *res = BULKSTAT_RV_GIVEUP;
-               return (error);
+               return error;
        }
 
        rtblks = 0;
@@ -1800,7 +1802,7 @@ xfs_qm_dqusage_adjust(
                        if (gdqp)
                                xfs_qm_dqput(gdqp);
                        *res = BULKSTAT_RV_GIVEUP;
-                       return (error);
+                       return error;
                }
                nblks = (xfs_qcnt_t)ip->i_d.di_nblocks - rtblks;
        }
@@ -1822,7 +1824,7 @@ xfs_qm_dqusage_adjust(
         * we have to start from the beginning anyway.
         * Once we're done, we'll log all the dquot bufs.
         *
-        * The *QUOTA_ON checks below may look pretty racey, but quotachecks
+        * The *QUOTA_ON checks below may look pretty racy, but quotachecks
         * and quotaoffs don't race. (Quotachecks happen at mount time only).
         */
        if (XFS_IS_UQUOTA_ON(mp)) {
@@ -1845,7 +1847,7 @@ xfs_qm_dqusage_adjust(
         * Goto next inode.
         */
        *res = BULKSTAT_RV_DIDONE;
-       return (0);
+       return 0;
 }
 
 /*
@@ -1918,9 +1920,7 @@ xfs_qm_quotacheck(
         * at this point (because we intentionally didn't in dqget_noattach).
         */
        if (error) {
-               xfs_qm_dqpurge_all(mp,
-                                  XFS_QMOPT_UQUOTA|XFS_QMOPT_GQUOTA|
-                                  XFS_QMOPT_PQUOTA|XFS_QMOPT_QUOTAOFF);
+               xfs_qm_dqpurge_all(mp, XFS_QMOPT_QUOTALL | XFS_QMOPT_QUOTAOFF);
                goto error_return;
        }
        /*
@@ -2041,7 +2041,7 @@ xfs_qm_init_quotainos(
        XFS_QI_UQIP(mp) = uip;
        XFS_QI_GQIP(mp) = gip;
 
-       return (0);
+       return 0;
 }
 
 
@@ -2062,7 +2062,7 @@ xfs_qm_shake_freelist(
        int             nflushes;
 
        if (howmany <= 0)
-               return (0);
+               return 0;
 
        nreclaimed = 0;
        restarts = 0;
@@ -2088,7 +2088,7 @@ xfs_qm_shake_freelist(
                        xfs_dqunlock(dqp);
                        xfs_qm_freelist_unlock(xfs_Gqm);
                        if (++restarts >= XFS_QM_RECLAIM_MAX_RESTARTS)
-                               return (nreclaimed);
+                               return nreclaimed;
                        XQM_STATS_INC(xqmstats.xs_qm_dqwants);
                        goto tryagain;
                }
@@ -2163,7 +2163,7 @@ xfs_qm_shake_freelist(
                        XFS_DQ_HASH_UNLOCK(hash);
                        xfs_qm_freelist_unlock(xfs_Gqm);
                        if (++restarts >= XFS_QM_RECLAIM_MAX_RESTARTS)
-                               return (nreclaimed);
+                               return nreclaimed;
                        goto tryagain;
                }
                xfs_dqtrace_entry(dqp, "DQSHAKE: UNLINKING");
@@ -2188,7 +2188,7 @@ xfs_qm_shake_freelist(
                dqp = nextdqp;
        }
        xfs_qm_freelist_unlock(xfs_Gqm);
-       return (nreclaimed);
+       return nreclaimed;
 }
 
 
@@ -2202,9 +2202,9 @@ xfs_qm_shake(int nr_to_scan, gfp_t gfp_mask)
        int     ndqused, nfree, n;
 
        if (!kmem_shake_allow(gfp_mask))
-               return (0);
+               return 0;
        if (!xfs_Gqm)
-               return (0);
+               return 0;
 
        nfree = xfs_Gqm->qm_dqfreelist.qh_nelems; /* free dquots */
        /* incore dquots in all f/s's */
@@ -2213,7 +2213,7 @@ xfs_qm_shake(int nr_to_scan, gfp_t gfp_mask)
        ASSERT(ndqused >= 0);
 
        if (nfree <= ndqused && nfree < ndquot)
-               return (0);
+               return 0;
 
        ndqused *= xfs_Gqm->qm_dqfree_ratio;    /* target # of free dquots */
        n = nfree - ndqused - ndquot;           /* # over target */
@@ -2257,7 +2257,7 @@ xfs_qm_dqreclaim_one(void)
                        xfs_dqunlock(dqp);
                        xfs_qm_freelist_unlock(xfs_Gqm);
                        if (++restarts >= XFS_QM_RECLAIM_MAX_RESTARTS)
-                               return (NULL);
+                               return NULL;
                        XQM_STATS_INC(xqmstats.xs_qm_dqwants);
                        goto startagain;
                }
@@ -2333,7 +2333,7 @@ xfs_qm_dqreclaim_one(void)
        }
 
        xfs_qm_freelist_unlock(xfs_Gqm);
-       return (dqpout);
+       return dqpout;
 }
 
 
@@ -2369,7 +2369,7 @@ xfs_qm_dqalloc_incore(
                         */
                        memset(&dqp->q_core, 0, sizeof(dqp->q_core));
                        *O_dqpp = dqp;
-                       return (B_FALSE);
+                       return B_FALSE;
                }
                XQM_STATS_INC(xqmstats.xs_qm_dqreclaim_misses);
        }
@@ -2382,7 +2382,7 @@ xfs_qm_dqalloc_incore(
        *O_dqpp = kmem_zone_zalloc(xfs_Gqm->qm_dqzone, KM_SLEEP);
        atomic_inc(&xfs_Gqm->qm_totaldquots);
 
-       return (B_TRUE);
+       return B_TRUE;
 }
 
 
@@ -2407,13 +2407,13 @@ xfs_qm_write_sb_changes(
                                      0,
                                      XFS_DEFAULT_LOG_COUNT))) {
                xfs_trans_cancel(tp, 0);
-               return (error);
+               return error;
        }
 
        xfs_mod_sb(tp, flags);
        (void) xfs_trans_commit(tp, 0, NULL);
 
-       return (0);
+       return 0;
 }
 
 
@@ -2463,7 +2463,7 @@ xfs_qm_vop_dqalloc(
                if ((error = xfs_qm_dqattach(ip, XFS_QMOPT_DQALLOC |
                                            XFS_QMOPT_ILOCKED))) {
                        xfs_iunlock(ip, lockflags);
-                       return (error);
+                       return error;
                }
        }
 
@@ -2486,7 +2486,7 @@ xfs_qm_vop_dqalloc(
                                                 XFS_QMOPT_DOWARN,
                                                 &uq))) {
                                ASSERT(error != ENOENT);
-                               return (error);
+                               return error;
                        }
                        /*
                         * Get the ilock in the right order.
@@ -2517,7 +2517,7 @@ xfs_qm_vop_dqalloc(
                                if (uq)
                                        xfs_qm_dqrele(uq);
                                ASSERT(error != ENOENT);
-                               return (error);
+                               return error;
                        }
                        xfs_dqunlock(gq);
                        lockflags = XFS_ILOCK_SHARED;
@@ -2565,7 +2565,7 @@ xfs_qm_vop_dqalloc(
                *O_gdqpp = gq;
        else if (gq)
                xfs_qm_dqrele(gq);
-       return (0);
+       return 0;
 }
 
 /*
@@ -2608,7 +2608,7 @@ xfs_qm_vop_chown(
        xfs_dqunlock(newdq);
        *IO_olddq = newdq;
 
-       return (prevdq);
+       return prevdq;
 }
 
 /*
@@ -2624,7 +2624,7 @@ xfs_qm_vop_chown_reserve(
 {
        int             error;
        xfs_mount_t     *mp;
-       uint            delblks, blkflags;
+       uint            delblks, blkflags, prjflags = 0;
        xfs_dquot_t     *unresudq, *unresgdq, *delblksudq, *delblksgdq;
 
        ASSERT(XFS_ISLOCKED_INODE(ip));
@@ -2650,10 +2650,13 @@ xfs_qm_vop_chown_reserve(
                }
        }
        if (XFS_IS_OQUOTA_ON(ip->i_mount) && gdqp) {
-               if ((XFS_IS_GQUOTA_ON(ip->i_mount) &&
-                    ip->i_d.di_gid != be32_to_cpu(gdqp->q_core.d_id)) ||
-                   (XFS_IS_PQUOTA_ON(ip->i_mount) &&
-                    ip->i_d.di_projid != be32_to_cpu(gdqp->q_core.d_id))) {
+               if (XFS_IS_PQUOTA_ON(ip->i_mount) &&
+                    ip->i_d.di_projid != be32_to_cpu(gdqp->q_core.d_id))
+                       prjflags = XFS_QMOPT_ENOSPC;
+
+               if (prjflags ||
+                   (XFS_IS_GQUOTA_ON(ip->i_mount) &&
+                    ip->i_d.di_gid != be32_to_cpu(gdqp->q_core.d_id))) {
                        delblksgdq = gdqp;
                        if (delblks) {
                                ASSERT(ip->i_gdquot);
@@ -2664,7 +2667,7 @@ xfs_qm_vop_chown_reserve(
 
        if ((error = xfs_trans_reserve_quota_bydquots(tp, ip->i_mount,
                                delblksudq, delblksgdq, ip->i_d.di_nblocks, 1,
-                               flags | blkflags)))
+                               flags | blkflags | prjflags)))
                return (error);
 
        /*
@@ -2681,7 +2684,7 @@ xfs_qm_vop_chown_reserve(
                ASSERT(unresudq || unresgdq);
                if ((error = xfs_trans_reserve_quota_bydquots(NULL, ip->i_mount,
                                delblksudq, delblksgdq, (xfs_qcnt_t)delblks, 0,
-                               flags | blkflags)))
+                               flags | blkflags | prjflags)))
                        return (error);
                xfs_trans_reserve_quota_bydquots(NULL, ip->i_mount,
                                unresudq, unresgdq, -((xfs_qcnt_t)delblks), 0,
@@ -2702,12 +2705,12 @@ xfs_qm_vop_rename_dqattach(
        ip = i_tab[0];
 
        if (! XFS_IS_QUOTA_ON(ip->i_mount))
-               return (0);
+               return 0;
 
        if (XFS_NOT_DQATTACHED(ip->i_mount, ip)) {
                error = xfs_qm_dqattach(ip, 0);
                if (error)
-                       return (error);
+                       return error;
        }
        for (i = 1; (i < 4 && i_tab[i]); i++) {
                /*
@@ -2717,11 +2720,11 @@ xfs_qm_vop_rename_dqattach(
                        if (XFS_NOT_DQATTACHED(ip->i_mount, ip)) {
                                error = xfs_qm_dqattach(ip, 0);
                                if (error)
-                                       return (error);
+                                       return error;
                        }
                }
        }
-       return (0);
+       return 0;
 }
 
 void
@@ -2743,6 +2746,7 @@ xfs_qm_vop_dqattach_and_dqmod_newinode(
                xfs_dqunlock(udqp);
                ASSERT(ip->i_udquot == NULL);
                ip->i_udquot = udqp;
+               ASSERT(XFS_IS_UQUOTA_ON(tp->t_mountp));
                ASSERT(ip->i_d.di_uid == be32_to_cpu(udqp->q_core.d_id));
                xfs_trans_mod_dquot(tp, udqp, XFS_TRANS_DQ_ICOUNT, 1);
        }
@@ -2752,7 +2756,10 @@ xfs_qm_vop_dqattach_and_dqmod_newinode(
                xfs_dqunlock(gdqp);
                ASSERT(ip->i_gdquot == NULL);
                ip->i_gdquot = gdqp;
-               ASSERT(ip->i_d.di_gid == be32_to_cpu(gdqp->q_core.d_id));
+               ASSERT(XFS_IS_OQUOTA_ON(tp->t_mountp));
+               ASSERT((XFS_IS_GQUOTA_ON(tp->t_mountp) ?
+                       ip->i_d.di_gid : ip->i_d.di_projid) ==
+                               be32_to_cpu(gdqp->q_core.d_id));
                xfs_trans_mod_dquot(tp, gdqp, XFS_TRANS_DQ_ICOUNT, 1);
        }
 }
@@ -2762,7 +2769,7 @@ STATIC void
 xfs_qm_freelist_init(xfs_frlist_t *ql)
 {
        ql->qh_next = ql->qh_prev = (xfs_dquot_t *) ql;
-       mutex_init(&ql->qh_lock, MUTEX_DEFAULT, "dqf");
+       mutex_init(&ql->qh_lock);
        ql->qh_version = 0;
        ql->qh_nelems = 0;
 }
@@ -2772,7 +2779,7 @@ xfs_qm_freelist_destroy(xfs_frlist_t *ql)
 {
        xfs_dquot_t     *dqp, *nextdqp;
 
-       mutex_lock(&ql->qh_lock, PINOD);
+       mutex_lock(&ql->qh_lock);
        for (dqp = ql->qh_next;
             dqp != (xfs_dquot_t *)ql; ) {
                xfs_dqlock(dqp);
@@ -2785,9 +2792,7 @@ xfs_qm_freelist_destroy(xfs_frlist_t *ql)
                xfs_qm_dqdestroy(dqp);
                dqp = nextdqp;
        }
-       /*
-        * Don't bother about unlocking.
-        */
+       mutex_unlock(&ql->qh_lock);
        mutex_destroy(&ql->qh_lock);
 
        ASSERT(ql->qh_nelems == 0);
@@ -2830,7 +2835,7 @@ xfs_qm_dqhashlock_nowait(
        int locked;
 
        locked = mutex_trylock(&((dqp)->q_hash->qh_lock));
-       return (locked);
+       return locked;
 }
 
 int
@@ -2840,7 +2845,7 @@ xfs_qm_freelist_lock_nowait(
        int locked;
 
        locked = mutex_trylock(&(xqm->qm_dqfreelist.qh_lock));
-       return (locked);
+       return locked;
 }
 
 STATIC int
@@ -2851,5 +2856,5 @@ xfs_qm_mplist_nowait(
 
        ASSERT(mp->m_quotainfo);
        locked = mutex_trylock(&(XFS_QI_MPLLOCK(mp)));
-       return (locked);
+       return locked;
 }