12fae26bdSAlan Somers#!/usr/local/bin/ksh93 -p
22fae26bdSAlan Somers#
32fae26bdSAlan Somers# CDDL HEADER START
42fae26bdSAlan Somers#
52fae26bdSAlan Somers# The contents of this file are subject to the terms of the
62fae26bdSAlan Somers# Common Development and Distribution License (the "License").
72fae26bdSAlan Somers# You may not use this file except in compliance with the License.
82fae26bdSAlan Somers#
92fae26bdSAlan Somers# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
102fae26bdSAlan Somers# or http://www.opensolaris.org/os/licensing.
112fae26bdSAlan Somers# See the License for the specific language governing permissions
122fae26bdSAlan Somers# and limitations under the License.
132fae26bdSAlan Somers#
142fae26bdSAlan Somers# When distributing Covered Code, include this CDDL HEADER in each
152fae26bdSAlan Somers# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
162fae26bdSAlan Somers# If applicable, add the following below this CDDL HEADER, with the
172fae26bdSAlan Somers# fields enclosed by brackets "[]" replaced with your own identifying
182fae26bdSAlan Somers# information: Portions Copyright [yyyy] [name of copyright owner]
192fae26bdSAlan Somers#
202fae26bdSAlan Somers# CDDL HEADER END
212fae26bdSAlan Somers#
222fae26bdSAlan Somers
232fae26bdSAlan Somers#
242fae26bdSAlan Somers# Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
252fae26bdSAlan Somers# Use is subject to license terms.
262fae26bdSAlan Somers
272fae26bdSAlan Somers. $STF_SUITE/include/libtest.kshlib
282fae26bdSAlan Somers. $STF_SUITE/tests/snapused/snapused.kshlib
292fae26bdSAlan Somers
302fae26bdSAlan Somers#################################################################################
312fae26bdSAlan Somers#
322fae26bdSAlan Somers# __stc_assertion_start
332fae26bdSAlan Somers#
342fae26bdSAlan Somers# ID: snapused_003_pos
352fae26bdSAlan Somers#
362fae26bdSAlan Somers# DESCRIPTION:
372fae26bdSAlan Somers#	Verify usedbydataset is correct.
382fae26bdSAlan Somers#
392fae26bdSAlan Somers# STRATEGY:
402fae26bdSAlan Somers#	1. Create a filesystem.
412fae26bdSAlan Somers#	2. Make file in the filesystem.
422fae26bdSAlan Somers#	3. Snapshot it.
432fae26bdSAlan Somers#	4. Clone it and make file in the cloned filesystem.
442fae26bdSAlan Somers#	5. Check usedbydataset is correct.
452fae26bdSAlan Somers#
462fae26bdSAlan Somers# TESTABILITY: explicit
472fae26bdSAlan Somers#
482fae26bdSAlan Somers# TEST_AUTOMATION_LEVEL: automated
492fae26bdSAlan Somers#
502fae26bdSAlan Somers# CODING_STATUS: COMPLETED (2009-04-28)
512fae26bdSAlan Somers#
522fae26bdSAlan Somers# __stc_assertion_end
532fae26bdSAlan Somers#
542fae26bdSAlan Somers################################################################################
552fae26bdSAlan Somers
562fae26bdSAlan Somersif ! usedby_supported ; then
572fae26bdSAlan Somers	log_unsupported "snapused property is not supported."
582fae26bdSAlan Somersfi
592fae26bdSAlan Somers
602fae26bdSAlan Somersverify_runnable "both"
612fae26bdSAlan Somers
622fae26bdSAlan Somersfunction cleanup
632fae26bdSAlan Somers{
642fae26bdSAlan Somers	log_must $ZFS destroy -rR $USEDTEST
652fae26bdSAlan Somers}
662fae26bdSAlan Somers
672fae26bdSAlan Somerslog_assert "Verify usedbydataset is correct."
682fae26bdSAlan Somerslog_onexit cleanup
692fae26bdSAlan Somers
702fae26bdSAlan Somerslog_must $ZFS create $USEDTEST
712fae26bdSAlan Somerscheck_usedbydataset $USEDTEST
722fae26bdSAlan Somers
732fae26bdSAlan Somerstypeset -i i=0
742fae26bdSAlan Somerstypeset -i r_size=0
752fae26bdSAlan Somersmntpnt=$(get_prop mountpoint $USEDTEST)
762fae26bdSAlan Somerswhile (( i < 5 )); do
772fae26bdSAlan Somers	((r_size=(i+1)*16))
782fae26bdSAlan Somers
792fae26bdSAlan Somers	log_must $MKFILE 16M $mntpnt/file$i
802fae26bdSAlan Somers	log_must $MKFILE "$r_size"M $mntpnt/file_var$i
812fae26bdSAlan Somers	log_must $ZFS snapshot -r $USEDTEST@snap$i
822fae26bdSAlan Somers
832fae26bdSAlan Somers	log_must $ZFS clone $USEDTEST@snap$i $USEDTEST/cln$i
842fae26bdSAlan Somers	log_must $ZFS set is:cloned=yes $USEDTEST/cln$i
852fae26bdSAlan Somers
862fae26bdSAlan Somers	mntpnt_cln=$(get_prop mountpoint $USEDTEST/cln$i)
872fae26bdSAlan Somers	log_must $MKFILE 16M $mntpnt_cln/file_cln$i
882fae26bdSAlan Somers	log_must $MKFILE "$r_size"M $mntpnt_cln/file_cln_var$i
892fae26bdSAlan Somers
902fae26bdSAlan Somers	check_usedbydataset $USEDTEST
912fae26bdSAlan Somers
922fae26bdSAlan Somers        ((i = i + 1))
932fae26bdSAlan Somersdone
942fae26bdSAlan Somers
952fae26bdSAlan Somerslog_pass "Verify usedbydataset is correct."
962fae26bdSAlan Somers
97