• 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
17do_setup()
18{
19	if [ ! -d /proc/sys/fs/quota ]; then
20		tst_brk TCONF "quota not supported in kernel"
21	fi
22
23	MNTDIR="mnt.$$"
24	IMAGE="ltp-$$-fs-image"
25	ROD dd if=/dev/zero of=$IMAGE bs=4096 count=8000 2>/dev/null
26	ROD mkfs.ext3 -q -F -b 4096 $IMAGE
27	mkdir $MNTDIR
28}
29
30do_clean()
31{
32	[ "$mounted" ] || return
33	tst_umount "$PWD/$MNTDIR"
34	mounted=
35}
36
37get_blocks()
38{
39	quota -f $MNTDIR -v -w | tail -n 1 | sed -e 's/ *[^ ]* *\([0-9]*\) .*/\1/'
40}
41
42do_test()
43{
44	tst_res TINFO "testing quota on remount"
45
46	local blocks newblocks
47
48	ROD mount -t ext3 -o loop,usrquota,grpquota $IMAGE $MNTDIR
49	mounted=1
50
51	# some distros (CentOS 6.x, for example) doesn't permit creating
52	# of quota files in a directory with SELinux file_t type
53	if tst_selinux_enforced &&
54		tst_cmd_available chcon && ! chcon -t tmp_t $MNTDIR; then
55			tst_brk TCONF "could not change SELinux file type"
56	fi
57
58	ROD quotacheck -cug $MNTDIR
59	ROD quotaon -ug $MNTDIR
60	ROD echo "blah" />$MNTDIR/file
61
62	blocks=$(get_blocks)
63	ROD mount -o remount,ro $MNTDIR
64	ROD mount -o remount,rw $MNTDIR
65
66	ROD rm $MNTDIR/file
67	newblocks=$(get_blocks)
68
69	if [ $blocks -eq $newblocks ]; then
70	   tst_brk TFAIL "usage did not change after remount"
71	fi
72
73	tst_res TPASS "quota on remount passed"
74
75	do_clean
76}
77
78. tst_test.sh
79tst_run
80