1*f67950b2SNasf-Fan#!/bin/ksh -p
2*f67950b2SNasf-Fan#
3*f67950b2SNasf-Fan# CDDL HEADER START
4*f67950b2SNasf-Fan#
5*f67950b2SNasf-Fan# The contents of this file are subject to the terms of the
6*f67950b2SNasf-Fan# Common Development and Distribution License (the "License").
7*f67950b2SNasf-Fan# You may not use this file except in compliance with the License.
8*f67950b2SNasf-Fan#
9*f67950b2SNasf-Fan# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10*f67950b2SNasf-Fan# or http://www.opensolaris.org/os/licensing.
11*f67950b2SNasf-Fan# See the License for the specific language governing permissions
12*f67950b2SNasf-Fan# and limitations under the License.
13*f67950b2SNasf-Fan#
14*f67950b2SNasf-Fan# When distributing Covered Code, include this CDDL HEADER in each
15*f67950b2SNasf-Fan# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16*f67950b2SNasf-Fan# If applicable, add the following below this CDDL HEADER, with the
17*f67950b2SNasf-Fan# fields enclosed by brackets "[]" replaced with your own identifying
18*f67950b2SNasf-Fan# information: Portions Copyright [yyyy] [name of copyright owner]
19*f67950b2SNasf-Fan#
20*f67950b2SNasf-Fan# CDDL HEADER END
21*f67950b2SNasf-Fan#
22*f67950b2SNasf-Fan
23*f67950b2SNasf-Fan#
24*f67950b2SNasf-Fan# Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
25*f67950b2SNasf-Fan# Use is subject to license terms.
26*f67950b2SNasf-Fan#
27*f67950b2SNasf-Fan
28*f67950b2SNasf-Fan#
29*f67950b2SNasf-Fan# Copyright (c) 2017 by Fan Yong. Fan rights reserved.
30*f67950b2SNasf-Fan# Copyright 2019 Joyent, Inc.
31*f67950b2SNasf-Fan#
32*f67950b2SNasf-Fan
33*f67950b2SNasf-Fan. $STF_SUITE/tests/functional/projectquota/projectquota_common.kshlib
34*f67950b2SNasf-Fan
35*f67950b2SNasf-Fan#
36*f67950b2SNasf-Fan# DESCRIPTION:
37*f67950b2SNasf-Fan#	Check 'df' command on the directory with INHERIT (project ID) flag
38*f67950b2SNasf-Fan#
39*f67950b2SNasf-Fan#
40*f67950b2SNasf-Fan# STRATEGY:
41*f67950b2SNasf-Fan#	1. set project [obj]quota on the directory
42*f67950b2SNasf-Fan#	2. set project ID and inherit flag on the directoty
43*f67950b2SNasf-Fan#	3. run 'df [-i]' on the directory and check the result
44*f67950b2SNasf-Fan#
45*f67950b2SNasf-Fan
46*f67950b2SNasf-Fanfunction cleanup
47*f67950b2SNasf-Fan{
48*f67950b2SNasf-Fan	if datasetexists $snap_fs; then
49*f67950b2SNasf-Fan		log_must zfs destroy $snap_fs
50*f67950b2SNasf-Fan	fi
51*f67950b2SNasf-Fan
52*f67950b2SNasf-Fan	log_must cleanup_projectquota
53*f67950b2SNasf-Fan}
54*f67950b2SNasf-Fan
55*f67950b2SNasf-Fanlog_onexit cleanup
56*f67950b2SNasf-Fan
57*f67950b2SNasf-Fanlog_assert "Check 'df' on dir with inherit project shows the project quota/used"
58*f67950b2SNasf-Fan
59*f67950b2SNasf-Fanlog_must zfs set projectquota@$PRJID1=100m $QFS
60*f67950b2SNasf-Fanlog_must zfs set projectobjquota@$PRJID1=100 $QFS
61*f67950b2SNasf-Fanmkmount_writable $QFS
62*f67950b2SNasf-Fanlog_must user_run $PUSER mkdir $PRJDIR
63*f67950b2SNasf-Fan# log_must chattr +P -p $PRJID1 $PRJDIR
64*f67950b2SNasf-Fanlog_must zfs project -s -p $PRJID1 $PRJDIR
65*f67950b2SNasf-Fanlog_must user_run $PUSER mkfile 50m $PRJDIR/qf
66*f67950b2SNasf-Fansync_pool
67*f67950b2SNasf-Fan
68*f67950b2SNasf-Fantotal=$(df -b $PRJDIR | tail -n 1 | awk '{ print $2 }')
69*f67950b2SNasf-Fan[[ $total -ge 9590000 && $total -le 9598900 ]] || \
70*f67950b2SNasf-Fan    log_fail "expect '9590000-9598900' resource, but got '$total'"
71*f67950b2SNasf-Fan
72*f67950b2SNasf-Fan# -i invalid on illumos
73*f67950b2SNasf-Fan# used=$(df -i $PRJDIR | tail -n 1 | awk '{ print $5 }')
74*f67950b2SNasf-Fan# [[ "$used" == "2%" ]] || log_fail "expect '2%' used, but got '$used'"
75*f67950b2SNasf-Fan
76*f67950b2SNasf-Fanlog_pass "'df' on the directory with inherit project ID flag pass as expect"
77