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. All rights reserved.
30*f67950b2SNasf-Fan#
31*f67950b2SNasf-Fan
32*f67950b2SNasf-Fan. $STF_SUITE/tests/functional/projectquota/projectquota_common.kshlib
33*f67950b2SNasf-Fan
34*f67950b2SNasf-Fan#
35*f67950b2SNasf-Fan#
36*f67950b2SNasf-Fan# DESCRIPTION:
37*f67950b2SNasf-Fan#	Check 'zfs project' is compatible with chattr/lsattr
38*f67950b2SNasf-Fan#
39*f67950b2SNasf-Fan#
40*f67950b2SNasf-Fan# STRATEGY:
41*f67950b2SNasf-Fan#	Verify the following:
42*f67950b2SNasf-Fan#	1. "zfs project -p" behaviours the same as "chattr -p"
43*f67950b2SNasf-Fan#	2. "zfs project" behaviours the same as "lsattr -p"
44*f67950b2SNasf-Fan#	3. "zfs project -d" behaviours the same as "lsattr -p -d"
45*f67950b2SNasf-Fan#	4. "zfs project -s" behaviours the same as "chattr +P"
46*f67950b2SNasf-Fan#	5. "zfs project -s -p" behaviours the same as "chattr +P -p"
47*f67950b2SNasf-Fan#	6. "zfs project -C" behaviours the same as "chattr -P"
48*f67950b2SNasf-Fan#
49*f67950b2SNasf-Fan
50*f67950b2SNasf-Fanfunction cleanup
51*f67950b2SNasf-Fan{
52*f67950b2SNasf-Fan	log_must rm -rf $PRJDIR
53*f67950b2SNasf-Fan}
54*f67950b2SNasf-Fan
55*f67950b2SNasf-Fanif ! lsattr -pd > /dev/null 2>&1; then
56*f67950b2SNasf-Fan	log_unsupported "Current e2fsprogs does not support set/show project ID"
57*f67950b2SNasf-Fanfi
58*f67950b2SNasf-Fan
59*f67950b2SNasf-Fan#
60*f67950b2SNasf-Fan# e2fsprogs-1.44.4 incorrectly reports verity 'V' bit when the project 'P'
61*f67950b2SNasf-Fan# bit is set.  Skip this test when 1.44.4 is installed to prevent failures.
62*f67950b2SNasf-Fan#
63*f67950b2SNasf-Fan# https://github.com/tytso/e2fsprogs/commit/7e5a95e3d
64*f67950b2SNasf-Fan#
65*f67950b2SNasf-Fanif lsattr -V 2>&1 | grep "lsattr 1.44.4"; then
66*f67950b2SNasf-Fan	log_unsupported "Current e2fsprogs incorrectly reports 'V' verity bit"
67*f67950b2SNasf-Fanfi
68*f67950b2SNasf-Fan
69*f67950b2SNasf-Fanlog_onexit cleanup
70*f67950b2SNasf-Fan
71*f67950b2SNasf-Fanlog_assert "Check 'zfs project' is compatible with chattr/lsattr"
72*f67950b2SNasf-Fan
73*f67950b2SNasf-Fanlog_must mkdir $PRJDIR
74*f67950b2SNasf-Fanlog_must mkdir $PRJDIR/a1
75*f67950b2SNasf-Fanlog_must mkdir $PRJDIR/a2
76*f67950b2SNasf-Fanlog_must touch $PRJDIR/a3
77*f67950b2SNasf-Fan
78*f67950b2SNasf-Fanlog_must chattr -p $PRJID1 $PRJDIR/a3
79*f67950b2SNasf-Fanlog_must eval "zfs project $PRJDIR/a3 | grep '$PRJID1 \-'"
80*f67950b2SNasf-Fan
81*f67950b2SNasf-Fanlog_must zfs project -p $PRJID2 $PRJDIR/a3
82*f67950b2SNasf-Fanlog_must eval "lsattr -p $PRJDIR/a3 | grep $PRJID2 | grep -v '\-P[- ]* '"
83*f67950b2SNasf-Fan
84*f67950b2SNasf-Fanlog_must chattr -p $PRJID1 $PRJDIR/a1
85*f67950b2SNasf-Fanlog_must eval "zfs project -d $PRJDIR/a1 | grep '$PRJID1 \-'"
86*f67950b2SNasf-Fan
87*f67950b2SNasf-Fanlog_must zfs project -p $PRJID2 $PRJDIR/a1
88*f67950b2SNasf-Fanlog_must eval "lsattr -pd $PRJDIR/a1 | grep $PRJID2 | grep -v '\-P[- ]* '"
89*f67950b2SNasf-Fan
90*f67950b2SNasf-Fanlog_must chattr +P $PRJDIR/a2
91*f67950b2SNasf-Fanlog_must eval "zfs project -d $PRJDIR/a2 | grep '0 P'"
92*f67950b2SNasf-Fan
93*f67950b2SNasf-Fanlog_must zfs project -s $PRJDIR/a2
94*f67950b2SNasf-Fanlog_must eval "lsattr -pd $PRJDIR/a2 | grep 0 | grep '\-P[- ]* '"
95*f67950b2SNasf-Fan
96*f67950b2SNasf-Fanlog_must chattr +P -p $PRJID1 $PRJDIR/a1
97*f67950b2SNasf-Fanlog_must eval "zfs project -d $PRJDIR/a1 | grep '$PRJID1 P'"
98*f67950b2SNasf-Fan
99*f67950b2SNasf-Fanlog_must zfs project -s -p $PRJID2 $PRJDIR/a2
100*f67950b2SNasf-Fanlog_must eval "lsattr -pd $PRJDIR/a2 | grep $PRJID2 | grep '\-P[- ]* '"
101*f67950b2SNasf-Fan
102*f67950b2SNasf-Fanlog_must chattr -P $PRJDIR/a1
103*f67950b2SNasf-Fanlog_must eval "zfs project -d $PRJDIR/a1 | grep '$PRJID1 \-'"
104*f67950b2SNasf-Fan
105*f67950b2SNasf-Fanlog_must zfs project -C -k $PRJDIR/a2
106*f67950b2SNasf-Fanlog_must eval "lsattr -pd $PRJDIR/a2 | grep $PRJID2 | grep -v '\-P[- ]* '"
107*f67950b2SNasf-Fan
108*f67950b2SNasf-Fanlog_pass "Check 'zfs project' is compatible with chattr/lsattr"
109