• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/bin/sh
2# SPDX-License-Identifier: GPL-2.0-or-later
3# Copyright (c) Jan Kara <jack@suse.cz>, 2008
4# Copyright (c) International Business Machines  Corp., 2009
5# Copyright (c) Köry Maincent <kory.maincent@bootlin.com> 2021
6# Copyright (c) 2021 Petr Vorel <pvorel@suse.cz>
7
8TST_NEEDS_CMDS="dd mkfs.ext3 mount quota quotacheck quotaon sed tail"
9TST_NEEDS_DRIVERS="quota_v2"
10TST_NEEDS_ROOT=1
11TST_NEEDS_TMPDIR=1
12TST_SETUP=do_setup
13TST_CLEANUP=do_clean
14TST_TESTFUNC=do_test
15TST_MIN_KVER="2.6.26"
16
17. tst_test.sh
18
19do_setup()
20{
21	if [ ! -d /proc/sys/fs/quota ]; then
22		tst_brk TCONF "quota not supported in kernel"
23	fi
24
25	MNTDIR="mnt.$$"
26	IMAGE="ltp-$$-fs-image"
27	ROD dd if=/dev/zero of=$IMAGE bs=4096 count=8000 2>/dev/null
28	ROD mkfs.ext3 -q -F -b 4096 $IMAGE
29	mkdir $MNTDIR
30}
31
32do_clean()
33{
34	[ "$mounted" ] || return
35	tst_umount "$PWD/$MNTDIR"
36	mounted=
37}
38
39get_blocks()
40{
41	quota -f $MNTDIR -v -w | tail -n 1 | sed -e 's/ *[^ ]* *\([0-9]*\) .*/\1/'
42}
43
44do_test()
45{
46	tst_res TINFO "testing quota on remount"
47
48	local blocks newblocks
49
50	ROD mount -t ext3 -o loop,usrquota,grpquota $IMAGE $MNTDIR
51	mounted=1
52
53	# some distros (CentOS 6.x, for example) doesn't permit creating
54	# of quota files in a directory with SELinux file_t type
55	if tst_selinux_enforced &&
56		tst_cmd_available chcon && ! chcon -t tmp_t $MNTDIR; then
57			tst_brk TCONF "could not change SELinux file type"
58	fi
59
60	ROD quotacheck -cug $MNTDIR
61	ROD quotaon -ug $MNTDIR
62	ROD echo "blah" />$MNTDIR/file
63
64	blocks=$(get_blocks)
65	ROD mount -o remount,ro $MNTDIR
66	ROD mount -o remount,rw $MNTDIR
67
68	ROD rm $MNTDIR/file
69	newblocks=$(get_blocks)
70
71	if [ $blocks -eq $newblocks ]; then
72	   tst_brk TFAIL "usage did not change after remount"
73	fi
74
75	tst_res TPASS "quota on remount passed"
76
77	do_clean
78}
79
80tst_run
81