xref: /illumos-gate/usr/src/test/zfs-tests/tests/functional/large_dnode/large_dnode_001_pos.ksh (revision 7e12ceb3ebc63aeb71e91b496032ca22ca55f660)
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. $STF_SUITE/include/libtest.shlib
24
25#
26# DESCRIPTION:
27# Verify that the dnode sizes of newly created files are consistent
28# with the dnodesize dataset property.
29#
30# STRATEGY:
31# 1. Create a file system
32# 2. Set dnodesize to a legal literal value
33# 3. Create a file
34# 4. Repeat 2-3 for all legal literal values of dnodesize values
35# 5. Unmount the file system
36# 6. Use zdb to check expected dnode sizes
37#
38
39TEST_FS=$TESTPOOL/large_dnode
40
41verify_runnable "both"
42
43function cleanup
44{
45	datasetexists $TEST_FS && log_must zfs destroy $TEST_FS
46}
47
48log_onexit cleanup
49log_assert "dnode sizes are consistent with dnodesize dataset property"
50
51log_must zfs create $TEST_FS
52
53set -A dnsizes "512" "1k" "2k" "4k" "8k" "16k"
54set -A inodes
55
56for ((i=0; i < ${#dnsizes[*]}; i++)) ; do
57	size=${dnsizes[$i]}
58	if [[ $size == "512" ]] ; then
59		size="legacy"
60	fi
61	file=/$TEST_FS/file.$size
62	log_must zfs set dnsize=$size $TEST_FS
63	touch $file
64	inodes[$i]=$(ls -li $file | awk '{print $1}')
65done
66
67log_must zfs umount $TEST_FS
68
69for ((i=0; i < ${#dnsizes[*]}; i++)) ; do
70	dnsize=$(zdb -dddd $TEST_FS ${inodes[$i]} |
71	    awk '/ZFS plain file/ {print $6}' | tr K k)
72	if [[ "$dnsize" != "${dnsizes[$i]}" ]]; then
73		log_fail "dnode size is $dnsize (expected ${dnsizes[$i]})"
74	fi
75done
76
77log_pass "dnode sizes are consistent with dnodesize dataset property"
78