#! /bin/bash
# SPDX-License-Identifier: GPL-2.0
# Copyright (c) 2009 Christoph Hellwig.  All Rights Reserved.
#
# FS QA Test No. 220
#
# Test quota off handling.
#
# Based on bug reports from Utako Kusaka <u-kusaka@wm.jp.nec.com> and
# Ryota Yamauchi <r-yamauchi@vf.jp.nec.com>.
#
. ./common/preamble
_begin_fstest auto quota quick

# Override the default cleanup function.
_cleanup()
{
	cd /
	_scratch_unmount >/dev/null 2>&1
}

# Import common functions.
. ./common/filter
. ./common/quota

# real QA test starts here
_supported_fs xfs

_require_scratch
_require_quota

# Only mount with the specific quota options mentioned below
_qmount_option "defaults"

echo "Silence is golden."

# create scratch filesystem
_scratch_mkfs_xfs >/dev/null 2>&1

# mount  with quotas enabled
_scratch_mount -o uquota

# turn off quota
$XFS_QUOTA_PROG -x -c off $SCRATCH_DEV

# and unmount (this used to crash)
_scratch_unmount

# create scratch filesystem
_scratch_mkfs_xfs >/dev/null 2>&1

# mount  with quotas enabled
_scratch_mount -o uquota

# turn off quota and remove space allocated to the quota files
# (this used to give wrong ENOSYS returns in 2.6.31)
#
# The sed expression below replaces a notrun to cater for kernels that have
# removed the ability to disable quota accounting at runtime.  On those
# kernel this test is rather useless, and in a few years we can drop it.
$XFS_QUOTA_PROG -x -c off -c remove $SCRATCH_DEV 2>&1 | \
	sed -e '/XFS_QUOTARM: Invalid argument/d'

# and unmount again
_scratch_unmount

status=0
exit $status
