]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - tests/zfs-tests/tests/functional/projectquota/projectspace_001_pos.ksh
Vendor import of openzfs master @ 184df27eef0abdc7ab2105b21257f753834b936b
[FreeBSD/FreeBSD.git] / tests / zfs-tests / tests / functional / projectquota / projectspace_001_pos.ksh
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. Fan rights reserved.
30 #
31
32 . $STF_SUITE/tests/functional/projectquota/projectquota_common.kshlib
33
34 #
35 # DESCRIPTION:
36 #       Check the zfs projectspace with kinds of parameters
37 #
38 #
39 # STRATEGY:
40 #       1. set zfs projectspace to a fs
41 #       2. write some data to the fs with specified project ID
42 #       3. use zfs projectspace with all possible parameters to check the result
43 #       4. use zfs projectspace with some bad parameters to check the result
44 #
45
46 function cleanup
47 {
48         if datasetexists $snap_fs; then
49                 log_must zfs destroy $snap_fs
50         fi
51
52         log_must cleanup_projectquota
53 }
54
55 if ! lsattr -pd > /dev/null 2>&1; then
56         log_unsupported "Current e2fsprogs does not support set/show project ID"
57 fi
58
59 log_onexit cleanup
60
61 log_assert "Check the zfs projectspace with all possible parameters"
62
63 set -A good_params -- "-H" "-p" "-o type,name,used,quota" "-o name,used,quota" \
64     "-o used,quota" "-o objused" "-o quota" "-s type" "-s name" "-s used" \
65     "-s quota" "-S type" "-S name" "-S used" "-S quota"
66
67 typeset snap_fs=$QFS@snap
68
69 log_must zfs set projectquota@$PRJID1=100m $QFS
70 log_must zfs set projectobjquota@$PRJID1=100 $QFS
71 mkmount_writable $QFS
72 log_must user_run $PUSER mkdir $PRJDIR
73 log_must chattr +P -p $PRJID1 $PRJDIR
74 log_must user_run $PUSER mkfile 50m $PRJDIR/qf
75 sync
76
77 log_must zfs snapshot $snap_fs
78
79 for param in "${good_params[@]}"; do
80         log_must eval "zfs projectspace $param $QFS >/dev/null 2>&1"
81         log_must eval "zfs projectspace $param $snap_fs >/dev/null 2>&1"
82 done
83
84 log_assert "Check the zfs projectspace with some bad parameters"
85
86 set -A bad_params -- "-i" "-n" "-P" "-t posixuser"
87
88 for param in "${bad_params[@]}"; do
89         log_mustnot eval "zfs projectspace $param $QFS >/dev/null 2>&1"
90         log_mustnot eval "zfs projectspace $param $snap_fs >/dev/null 2>&1"
91 done
92
93 log_pass "zfs projectspace with kinds of parameters pass"