1f67950b2SNasf-Fan#!/bin/ksh -p 2f67950b2SNasf-Fan# 3f67950b2SNasf-Fan# CDDL HEADER START 4f67950b2SNasf-Fan# 5f67950b2SNasf-Fan# The contents of this file are subject to the terms of the 6f67950b2SNasf-Fan# Common Development and Distribution License (the "License"). 7f67950b2SNasf-Fan# You may not use this file except in compliance with the License. 8f67950b2SNasf-Fan# 9f67950b2SNasf-Fan# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 10f67950b2SNasf-Fan# or http://www.opensolaris.org/os/licensing. 11f67950b2SNasf-Fan# See the License for the specific language governing permissions 12f67950b2SNasf-Fan# and limitations under the License. 13f67950b2SNasf-Fan# 14f67950b2SNasf-Fan# When distributing Covered Code, include this CDDL HEADER in each 15f67950b2SNasf-Fan# file and include the License file at usr/src/OPENSOLARIS.LICENSE. 16f67950b2SNasf-Fan# If applicable, add the following below this CDDL HEADER, with the 17f67950b2SNasf-Fan# fields enclosed by brackets "[]" replaced with your own identifying 18f67950b2SNasf-Fan# information: Portions Copyright [yyyy] [name of copyright owner] 19f67950b2SNasf-Fan# 20f67950b2SNasf-Fan# CDDL HEADER END 21f67950b2SNasf-Fan# 22f67950b2SNasf-Fan 23f67950b2SNasf-Fan# 24f67950b2SNasf-Fan# Copyright 2009 Sun Microsystems, Inc. All rights reserved. 25f67950b2SNasf-Fan# Use is subject to license terms. 26f67950b2SNasf-Fan# 27f67950b2SNasf-Fan 28f67950b2SNasf-Fan# 29f67950b2SNasf-Fan# Copyright (c) 2017 by Fan Yong. All rights reserved. 30f67950b2SNasf-Fan# Copyright 2019 Joyent, Inc. 31f67950b2SNasf-Fan# 32f67950b2SNasf-Fan 33f67950b2SNasf-Fan. $STF_SUITE/tests/functional/projectquota/projectquota_common.kshlib 34f67950b2SNasf-Fan 35f67950b2SNasf-Fan# 36f67950b2SNasf-Fan# DESCRIPTION: 37f67950b2SNasf-Fan# Check the project used size and quota in zfs projectspace 38f67950b2SNasf-Fan# 39f67950b2SNasf-Fan# 40f67950b2SNasf-Fan# STRATEGY: 41f67950b2SNasf-Fan# 1. set zfs projectquota to a fs 42f67950b2SNasf-Fan# 2. write some data to the fs with specified project and size 43f67950b2SNasf-Fan# 3. use zfs projectspace to check the used size and quota size 44f67950b2SNasf-Fan# 45f67950b2SNasf-Fan 46f67950b2SNasf-Fanfunction cleanup 47f67950b2SNasf-Fan{ 48f67950b2SNasf-Fan if datasetexists $snapfs; then 49f67950b2SNasf-Fan log_must zfs destroy $snapfs 50f67950b2SNasf-Fan fi 51f67950b2SNasf-Fan 52f67950b2SNasf-Fan log_must cleanup_projectquota 53f67950b2SNasf-Fan} 54f67950b2SNasf-Fan 55f67950b2SNasf-Fanlog_onexit cleanup 56f67950b2SNasf-Fan 57f67950b2SNasf-Fanlog_assert "Check the zfs projectspace used and quota" 58f67950b2SNasf-Fan 59f67950b2SNasf-Fanlog_must zfs set projectquota@$PRJID1=100m $QFS 60f67950b2SNasf-Fan 61f67950b2SNasf-Fanmkmount_writable $QFS 62f67950b2SNasf-Fanlog_must user_run $PUSER mkdir $PRJDIR 63f67950b2SNasf-Fan# log_must chattr +P -p $PRJID1 $PRJDIR 64f67950b2SNasf-Fanlog_must zfs project -s -p $PRJID1 $PRJDIR 65f67950b2SNasf-Fanlog_must user_run $PUSER mkfile 50m $PRJDIR/qf 66*09fbbb7dSAllan Judesync_all_pools 67f67950b2SNasf-Fan 68f67950b2SNasf-Fantypeset snapfs=$QFS@snap 69f67950b2SNasf-Fan 70f67950b2SNasf-Fanlog_must zfs snapshot $snapfs 71f67950b2SNasf-Fan 72f67950b2SNasf-Fanlog_must eval "zfs projectspace $QFS >/dev/null 2>&1" 73f67950b2SNasf-Fanlog_must eval "zfs projectspace $snapfs >/dev/null 2>&1" 74f67950b2SNasf-Fan 75f67950b2SNasf-Fanfor fs in "$QFS" "$snapfs"; do 76f67950b2SNasf-Fan log_note "check the quota size in zfs projectspace $fs" 77f67950b2SNasf-Fan log_must eval "zfs projectspace $fs | grep $PRJID1 | grep 100M" 78f67950b2SNasf-Fan 79f67950b2SNasf-Fan log_note "check the project used size in zfs projectspace $fs" 80f67950b2SNasf-Fan log_must eval "zfs projectspace $fs | grep $PRJID1 | grep 50\\.\*M" 81f67950b2SNasf-Fandone 82f67950b2SNasf-Fan 83f67950b2SNasf-Fanlog_pass "Check the zfs projectspace used and quota" 84