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