prid = xfs_get_initial_prid(dp);
 
        /*
-        * Make sure that we have allocated dquot(s) on disk.
+        * Make sure that we have allocated dquot(s) on disk.  The uid/gid
+        * computation code must match what the VFS uses to assign i_[ug]id.
+        * INHERIT adjusts the gid computation for setgid/grpid systems.
         */
-       error = xfs_qm_vop_dqalloc(dp, mapped_fsuid(idmap, &init_user_ns),
-                       mapped_fsgid(idmap, &init_user_ns), prid,
+       error = xfs_qm_vop_dqalloc(dp, mapped_fsuid(idmap, i_user_ns(VFS_I(dp))),
+                       mapped_fsgid(idmap, i_user_ns(VFS_I(dp))), prid,
                        XFS_QMOPT_QUOTALL | XFS_QMOPT_INHERIT,
                        &udqp, &gdqp, &pdqp);
        if (error)
        prid = xfs_get_initial_prid(dp);
 
        /*
-        * Make sure that we have allocated dquot(s) on disk.
+        * Make sure that we have allocated dquot(s) on disk.  The uid/gid
+        * computation code must match what the VFS uses to assign i_[ug]id.
+        * INHERIT adjusts the gid computation for setgid/grpid systems.
         */
-       error = xfs_qm_vop_dqalloc(dp, mapped_fsuid(idmap, &init_user_ns),
-                       mapped_fsgid(idmap, &init_user_ns), prid,
+       error = xfs_qm_vop_dqalloc(dp, mapped_fsuid(idmap, i_user_ns(VFS_I(dp))),
+                       mapped_fsgid(idmap, i_user_ns(VFS_I(dp))), prid,
                        XFS_QMOPT_QUOTALL | XFS_QMOPT_INHERIT,
                        &udqp, &gdqp, &pdqp);
        if (error)
 
        prid = xfs_get_initial_prid(dp);
 
        /*
-        * Make sure that we have allocated dquot(s) on disk.
+        * Make sure that we have allocated dquot(s) on disk.  The uid/gid
+        * computation code must match what the VFS uses to assign i_[ug]id.
+        * INHERIT adjusts the gid computation for setgid/grpid systems.
         */
-       error = xfs_qm_vop_dqalloc(dp, mapped_fsuid(idmap, &init_user_ns),
-                       mapped_fsgid(idmap, &init_user_ns), prid,
+       error = xfs_qm_vop_dqalloc(dp, mapped_fsuid(idmap, i_user_ns(VFS_I(dp))),
+                       mapped_fsgid(idmap, i_user_ns(VFS_I(dp))), prid,
                        XFS_QMOPT_QUOTALL | XFS_QMOPT_INHERIT,
                        &udqp, &gdqp, &pdqp);
        if (error)