1#!/bin/ksh -p
2#
3# CDDL HEADER START
4#
5# The contents of this file are subject to the terms of the
6# Common Development and Distribution License (the "License").
7# You may not use this file except in compliance with the License.
8#
9# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10# or http://www.opensolaris.org/os/licensing.
11# See the License for the specific language governing permissions
12# and limitations under the License.
13#
14# When distributing Covered Code, include this CDDL HEADER in each
15# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16# If applicable, add the following below this CDDL HEADER, with the
17# fields enclosed by brackets "[]" replaced with your own identifying
18# information: Portions Copyright [yyyy] [name of copyright owner]
19#
20# CDDL HEADER END
21#
22
23#
24# Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
25# Use is subject to license terms.
26#
27
28#
29# Copyright (c) 2017 by Fan Yong. All rights reserved.
30#
31
32. $STF_SUITE/tests/functional/projectquota/projectquota_common.kshlib
33
34#
35#
36# DESCRIPTION:
37#	Check 'zfs project' is compatible with chattr/lsattr
38#
39#
40# STRATEGY:
41#	Verify the following:
42#	1. "zfs project -p" behaviours the same as "chattr -p"
43#	2. "zfs project" behaviours the same as "lsattr -p"
44#	3. "zfs project -d" behaviours the same as "lsattr -p -d"
45#	4. "zfs project -s" behaviours the same as "chattr +P"
46#	5. "zfs project -s -p" behaviours the same as "chattr +P -p"
47#	6. "zfs project -C" behaviours the same as "chattr -P"
48#
49
50function cleanup
51{
52	log_must rm -rf $PRJDIR
53}
54
55if ! lsattr -pd > /dev/null 2>&1; then
56	log_unsupported "Current e2fsprogs does not support set/show project ID"
57fi
58
59#
60# e2fsprogs-1.44.4 incorrectly reports verity 'V' bit when the project 'P'
61# bit is set.  Skip this test when 1.44.4 is installed to prevent failures.
62#
63# https://github.com/tytso/e2fsprogs/commit/7e5a95e3d
64#
65if lsattr -V 2>&1 | grep "lsattr 1.44.4"; then
66	log_unsupported "Current e2fsprogs incorrectly reports 'V' verity bit"
67fi
68
69log_onexit cleanup
70
71log_assert "Check 'zfs project' is compatible with chattr/lsattr"
72
73log_must mkdir $PRJDIR
74log_must mkdir $PRJDIR/a1
75log_must mkdir $PRJDIR/a2
76log_must touch $PRJDIR/a3
77
78log_must chattr -p $PRJID1 $PRJDIR/a3
79log_must eval "zfs project $PRJDIR/a3 | grep '$PRJID1 \-'"
80
81log_must zfs project -p $PRJID2 $PRJDIR/a3
82log_must eval "lsattr -p $PRJDIR/a3 | grep $PRJID2 | grep -v '\-P[- ]* '"
83
84log_must chattr -p $PRJID1 $PRJDIR/a1
85log_must eval "zfs project -d $PRJDIR/a1 | grep '$PRJID1 \-'"
86
87log_must zfs project -p $PRJID2 $PRJDIR/a1
88log_must eval "lsattr -pd $PRJDIR/a1 | grep $PRJID2 | grep -v '\-P[- ]* '"
89
90log_must chattr +P $PRJDIR/a2
91log_must eval "zfs project -d $PRJDIR/a2 | grep '0 P'"
92
93log_must zfs project -s $PRJDIR/a2
94log_must eval "lsattr -pd $PRJDIR/a2 | grep 0 | grep '\-P[- ]* '"
95
96log_must chattr +P -p $PRJID1 $PRJDIR/a1
97log_must eval "zfs project -d $PRJDIR/a1 | grep '$PRJID1 P'"
98
99log_must zfs project -s -p $PRJID2 $PRJDIR/a2
100log_must eval "lsattr -pd $PRJDIR/a2 | grep $PRJID2 | grep '\-P[- ]* '"
101
102log_must chattr -P $PRJDIR/a1
103log_must eval "zfs project -d $PRJDIR/a1 | grep '$PRJID1 \-'"
104
105log_must zfs project -C -k $PRJDIR/a2
106log_must eval "lsattr -pd $PRJDIR/a2 | grep $PRJID2 | grep -v '\-P[- ]* '"
107
108log_pass "Check 'zfs project' is compatible with chattr/lsattr"
109