common/populate: enable xfs quota accounting
authorDarrick J. Wong <darrick.wong@oracle.com>
Fri, 21 Jul 2017 22:04:52 +0000 (15:04 -0700)
committerEryu Guan <eguan@redhat.com>
Thu, 24 Aug 2017 03:15:52 +0000 (11:15 +0800)
When we're creating a populated xfs image, turn on quotas so that we can
fuzz those fields too.

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Signed-off-by: Eryu Guan <eguan@redhat.com>
common/populate

index 498151f3e7504a2b7228cc7a6d6580219686a32c..b77c508107fefed346b6bb4b010001ffe764e1aa 100644 (file)
@@ -21,6 +21,7 @@
 #  Contact information: Silicon Graphics, Inc., 1500 Crittenden Lane,
 #  Mountain View, CA 94043, USA, or: http://www.sgi.com
 #-----------------------------------------------------------------------
+. ./common/quota
 
 _require_populate_commands() {
        _require_xfs_io_command "falloc"
@@ -94,6 +95,47 @@ __populate_fill_fs() {
        done
 }
 
+# For XFS, force on all the quota options if quota is enabled
+# and the user didn't feed us noquota.
+_populate_xfs_qmount_option()
+{
+       # User explicitly told us not to quota
+       if echo "${MOUNT_OPTIONS}" | grep -q 'noquota'; then
+               return
+       fi
+
+       # Don't bother if we can't turn on quotas
+       if [ ! -f /proc/fs/xfs/xqmstat ]; then
+               # No quota support
+               return
+       elif [ "${USE_EXTERNAL}" = "yes" ] && [ ! -z "${SCRATCH_RTDEV}" ]; then
+               # Quotas not supported on rt filesystems
+               return
+       elif [ -z "${XFS_QUOTA_PROG}" ]; then
+               # xfs quota tools not installed
+               return
+       fi
+
+       # Turn on all the quotas
+       if xfs_info "${TEST_DIR}" | grep -q 'crc=1'; then
+               # v5 filesystems can have group & project quotas
+               quota="usrquota,grpquota,prjquota"
+       else
+               # v4 filesystems cannot mix group & project quotas
+               quota="usrquota,grpquota"
+       fi
+
+       # Inject our quota mount options
+       if echo "${MOUNT_OPTIONS}" | grep -q "${quota}"; then
+               return
+       elif echo "${MOUNT_OPTIONS}" | egrep -q '(quota|noenforce)'; then
+               _qmount_option "${quota}"
+       else
+               export MOUNT_OPTIONS="$MOUNT_OPTIONS -o ${quota}"
+               echo "MOUNT_OPTIONS = $MOUNT_OPTIONS" >>$seqres.full
+       fi
+}
+
 # Populate an XFS on the scratch device with (we hope) all known
 # types of metadata block
 _scratch_xfs_populate() {
@@ -106,6 +148,7 @@ _scratch_xfs_populate() {
                esac
        done
 
+       _populate_xfs_qmount_option
        _scratch_mount
        blksz="$(stat -f -c '%s' "${SCRATCH_MNT}")"
        dblksz="$(xfs_info "${SCRATCH_MNT}" | grep naming.*bsize | sed -e 's/^.*bsize=//g' -e 's/\([0-9]*\).*$/\1/g')"
@@ -720,7 +763,12 @@ _scratch_populate_cached() {
                test -n "${SCRATCH_LOGDEV}" && rm -f "${POPULATE_METADUMP}"
                ;;
        "xfs")
-               extra_descr="LOGDEV ${SCRATCH_LOGDEV} USE_EXTERNAL ${USE_EXTERNAL} RTDEV ${SCRATCH_RTDEV}";;
+               extra_descr="LOGDEV ${SCRATCH_LOGDEV} USE_EXTERNAL ${USE_EXTERNAL} RTDEV ${SCRATCH_RTDEV}"
+               _populate_xfs_qmount_option
+               if echo "${MOUNT_OPTIONS}" | grep -q 'usrquota'; then
+                       extra_descr="${extra_descr} QUOTAS"
+               fi
+               ;;
        *)
                extra_descr="";;
        esac