]> git.proxmox.com Git - mirror_zfs.git/blob - tests/zfs-tests/tests/functional/cli_root/zfs_copies/zfs_copies_002_pos.ksh
Add the ZFS Test Suite
[mirror_zfs.git] / tests / zfs-tests / tests / functional / cli_root / zfs_copies / zfs_copies_002_pos.ksh
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 . $STF_SUITE/include/libtest.shlib
29 . $STF_SUITE/tests/functional/cli_root/zfs_copies/zfs_copies.kshlib
30
31 #
32 # DESCRIPTION:
33 # Verify that the space used by multiple copies is charged correctly
34 #
35 # STRATEGY:
36 # 1. Create filesystems with copies set as 2,3 respectively;
37 # 2. Copy specified size data into each filesystem;
38 # 3. Verify that the space is charged as expected with zfs list, ls -s, df(1m),
39 # du(1) commands;
40 #
41
42 verify_runnable "both"
43
44 function cleanup
45 {
46 typeset val
47
48 for val in 1 2 3; do
49 if datasetexists $TESTPOOL/fs_$val; then
50 log_must $ZFS destroy $TESTPOOL/fs_$val
51 fi
52 done
53 }
54
55 log_assert "Verify that the space used by multiple copies is charged correctly."
56 log_onexit cleanup
57
58 for val in 1 2 3; do
59 log_must $ZFS create -o copies=$val $TESTPOOL/fs_$val
60
61 log_must $MKFILE $FILESIZE /$TESTPOOL/fs_$val/$FILE
62 done
63
64 #
65 # Sync up the filesystem
66 #
67 $SYNC
68
69 #
70 # Verify 'zfs list' can correctly list the space charged
71 #
72 log_note "Verify 'zfs list' can correctly list the space charged."
73 fsize=${FILESIZE%[m|M]}
74 for val in 1 2 3; do
75 used=$(get_used_prop $TESTPOOL/fs_$val)
76 check_used $used $val
77 done
78
79 log_note "Verify 'ls -s' can correctly list the space charged."
80 for val in 1 2 3; do
81 blks=`$LS -ls /$TESTPOOL/fs_$val/$FILE | $AWK '{print $1}'`
82 (( used = blks * 512 / (1024 * 1024) ))
83 check_used $used $val
84 done
85
86 log_note "Verify df(1M) can corectly display the space charged."
87 for val in 1 2 3; do
88 used=`$DF -F zfs -h /$TESTPOOL/fs_$val/$FILE | $GREP $TESTPOOL/fs_$val \
89 | $AWK '{print $3}'`
90 check_used $used $val
91 done
92
93 log_note "Verify du(1) can correctly display the space charged."
94 for val in 1 2 3; do
95 used=`$DU -h /$TESTPOOL/fs_$val/$FILE | $AWK '{print $1}'`
96 check_used $used $val
97 done
98
99 log_pass "The space used by multiple copies is charged correctly as expected. "