1#!/bin/ksh 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 2007 Sun Microsystems, Inc. All rights reserved. 25# Use is subject to license terms. 26# 27 28# 29# Copyright (c) 2016 by Delphix. All rights reserved. 30# 31 32. $STF_SUITE/include/libtest.shlib 33. $STF_SUITE/tests/functional/cli_root/zfs_copies/zfs_copies.kshlib 34 35# 36# DESCRIPTION: 37# Verify that the space used by multiple copies is charged correctly 38# 39# STRATEGY: 40# 1. Create filesystems with copies set as 2,3 respectively; 41# 2. Copy specified size data into each filesystem; 42# 3. Verify that the space is charged as expected with zfs list, ls -s, df(1m), 43# du(1) commands; 44# 45 46verify_runnable "both" 47 48function cleanup 49{ 50 typeset val 51 52 for val in 1 2 3; do 53 datasetexists $TESTPOOL/fs_$val && \ 54 destroy_dataset $TESTPOOL/fs_$val 55 done 56} 57 58log_assert "Verify that the space used by multiple copies is charged correctly." 59log_onexit cleanup 60 61for val in 1 2 3; do 62 log_must zfs create -o compression=off -o copies=$val $TESTPOOL/fs_$val 63 64 log_must mkfile $FILESIZE /$TESTPOOL/fs_$val/$FILE 65done 66 67# 68# Sync up the filesystem 69# 70sync_all_pools 71 72# 73# Verify 'zfs list' can correctly list the space charged 74# 75log_note "Verify 'zfs list' can correctly list the space charged." 76fsize=${FILESIZE%[m|M]} 77for val in 1 2 3; do 78 used=$(get_prop used $TESTPOOL/fs_$val) 79 check_used $used $val 80done 81 82log_note "Verify 'ls -s' can correctly list the space charged." 83if is_linux || is_freebsd; then 84 blksize=1024 85else 86 blksize=512 87fi 88for val in 1 2 3; do 89 blks=`ls -ls /$TESTPOOL/fs_$val/$FILE | awk '{print $1}'` 90 (( used = blks * $blksize )) # bytes 91 check_used $used $val 92done 93 94log_note "Verify df(1) can correctly display the space charged." 95for val in 1 2 3; do 96 if is_freebsd; then 97 used=`df -m /$TESTPOOL/fs_$val | grep $TESTPOOL/fs_$val \ 98 | awk -v fs=fs_$val '$4 ~ fs {print $3}'` 99 else 100 used=`df -F zfs -k /$TESTPOOL/fs_$val/$FILE | grep $TESTPOOL/fs_$val \ 101 | awk '{print $3}'` 102 (( used = used * 1024 )) # kb -> bytes 103 fi 104 check_used $used $val 105done 106 107log_note "Verify du(1) can correctly display the space charged." 108for val in 1 2 3; do 109 if is_freebsd; then 110 used=`du -h /$TESTPOOL/fs_$val/$FILE | awk '{print $1}'` 111 else 112 used=`du -k /$TESTPOOL/fs_$val/$FILE | awk '{print $1}'` 113 (( used = used * 1024 )) # kb -> bytes 114 fi 115 check_used $used $val 116done 117 118log_pass "The space used by multiple copies is charged correctly as expected. " 119