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# Copyright 2019 Joyent, Inc. 31# 32 33. $STF_SUITE/tests/functional/projectquota/projectquota_common.kshlib 34 35# 36# DESCRIPTION: 37# Check the project used object accounting in zfs projectspace 38# 39# 40# STRATEGY: 41# 1. create a bunch of files by specific project 42# 2. use zfs projectspace to check the used objects 43# 3. change the project ID of test files and verify object count 44# 4. delete files and verify object count 45# 46 47function cleanup 48{ 49 if datasetexists $snapfs; then 50 log_must zfs destroy $snapfs 51 fi 52 53 log_must cleanup_projectquota 54} 55 56log_onexit cleanup 57 58log_assert "Check the zfs projectspace object used" 59 60mkmount_writable $QFS 61log_must zfs set xattr=on $QFS 62log_must user_run $PUSER mkdir $PRJDIR1 63log_must user_run $PUSER mkdir $PRJDIR2 64# log_must chattr +P -p $PRJID1 $PRJDIR1 65# log_must chattr +P -p $PRJID2 $PRJDIR2 66log_must zfs project -s -p $PRJID1 $PRJDIR1 67log_must zfs project -s -p $PRJID2 $PRJDIR2 68 69((prj_cnt1 = RANDOM % 100 + 2)) 70((prj_cnt2 = RANDOM % 100 + 2)) 71 72log_must user_run $PUSER mkfiles $PRJDIR1/qf $((prj_cnt1 - 1)) 73log_must user_run $PUSER mkfiles $PRJDIR2/qf $((prj_cnt2 - 1)) 74sync_pool 75 76typeset snapfs=$QFS@snap 77 78log_must zfs snapshot $snapfs 79 80log_must eval "zfs projectspace $QFS >/dev/null 2>&1" 81log_must eval "zfs projectspace $snapfs >/dev/null 2>&1" 82 83for fs in "$QFS" "$snapfs"; do 84 log_note "check the project used objects in zfs projectspace $fs" 85 prjused=$(project_obj_count $fs $PRJID1) 86 [[ $prjused -ge $prj_cnt1 ]] || 87 log_fail "($PRJID1) expected $prj_cnt1, got $prjused" 88 prjused=$(project_obj_count $fs $PRJID2) 89 [[ $prjused -ge $prj_cnt2 ]] || 90 log_fail "($PRJID2) expected $prj_cnt2, got $prjused" 91done 92 93log_note "change the project of files" 94# log_must chattr -p $PRJID2 $PRJDIR1/qf* 95log_must zfs project -s -p $PRJID2 $PRJDIR1/qf* 96sync_pool 97 98prjused=$(project_obj_count $QFS $PRJID1) 99[[ $prjused -lt 10 ]] || 100 log_fail "expected less than 10 for project $PRJID1, got $prjused" 101 102prjused=$(project_obj_count $snapfs $PRJID1) 103[[ $prjused -ge $prj_cnt1 ]] || 104 log_fail "expected $prj_cnt1 for $PRJID1 in snapfs, got $prjused" 105 106prjused=$(project_obj_count $QFS $PRJID2) 107[[ $prjused -ge $((prj_cnt1 + prj_cnt2 - 1)) ]] || 108 log_fail "($PRJID2) expected $((prj_cnt1 + prj_cnt2 - 1)), got $prjused" 109 110log_note "file removal" 111log_must rm -rf $PRJDIR1 112sync_pool 113 114prjused=$(project_obj_count $QFS $PRJID1) 115[[ $prjused -lt 10 ]] || log_fail "expected less than 10 for $PRJID1, " \ 116 "got $prjused" 117 118cleanup 119log_pass "Check the zfs projectspace object used" 120