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