xfs/007: fix regressions on V4 filesystems
authorDarrick J. Wong <djwong@kernel.org>
Wed, 28 Jul 2021 20:00:45 +0000 (13:00 -0700)
committerEryu Guan <guaneryu@gmail.com>
Sun, 1 Aug 2021 13:16:29 +0000 (21:16 +0800)
Following commit eae40404, I noticed the following regression when
running a V4 fstests run on an 5.13 kernel:

  --- /tmp/fstests/tests/xfs/007.out      2021-05-13 11:47:55.793859995 -0700
  +++ /var/tmp/fstests/xfs/007.out.bad    2021-07-28 09:23:42.856000000 -0700
  @@ -16,4 +16,4 @@
   *** umount
   *** Usage after quotarm ***
   core.nblocks = 0
  -core.nblocks = 0
  +core.nblocks = 1

The underlying cause of this problem is the fact that we now remount the
filesystem with no quota options because that will (soon) become the
only means to turn off quota accounting on XFS.  Because V4 filesystems
don't support simultaneous project and group quotas and play weird
remapping games with the incore superblock field, we actually have to
issue a remove command for the group quota file if we're trying to
truncate the project quota file on a V4 filesystem.

Due to stupid limitations in xfs_quota we actually have to issue a
separate 'remove' command.

Fixes: eae40404 ("xfs/007: unmount after disabling quota")
Signed-off-by: Darrick J. Wong <djwong@kernel.org>
Signed-off-by: Eryu Guan <guaneryu@gmail.com>
tests/xfs/007

index 66f1f10..4f86410 100755 (executable)
@@ -41,10 +41,27 @@ do_test()
        _qmount
        echo "*** turn off $off_opts quotas"
        $XFS_QUOTA_PROG -x -c "off -$off_opts" $SCRATCH_MNT
+
+       # Remount the filesystem with no quota options to force quotas off.
+       # This takes care of newer kernels where quotaoff clears the superblock
+       # quota enforcement flags but doesn't shut down accounting.
        _scratch_unmount
        _qmount_option ""
        _scratch_mount
-       $XFS_QUOTA_PROG -x -c "remove -$off_opts" $SCRATCH_MNT
+
+       rm_commands=(-x -c "remove -$off_opts")
+
+       # Remounting a V4 fs with no quota options means that the internal
+       # gquotino -> pquotino remapping does not happen.  If we want to
+       # truncate the "project" quota file we must run remove -g.  However,
+       # xfs_quota has a nasty sharp edge wherein passing '-g' and '-p' only
+       # results in a QUOTARM call for the group quota file, so we must make
+       # a separate remove call.
+       [ $_fs_has_crcs == 0 ] && [ "$off_opts" = "up" ] && \
+               rm_commands+=(-c "remove -g")
+
+       $XFS_QUOTA_PROG "${rm_commands[@]}" $SCRATCH_MNT
+
        echo "*** umount"
        _scratch_unmount