xref: /illumos-gate/usr/src/test/zfs-tests/tests/functional/holes/holes_sanity.ksh (revision 2a6e99a0f1f7d22c0396e8b2ce9b9babbd1056cf)
1#!/bin/ksh
2
3#
4# This file and its contents are supplied under the terms of the
5# Common Development and Distribution License ("CDDL"), version 1.0.
6# You may only use this file in accordance with the terms of version
7# 1.0 of the CDDL.
8#
9# A full copy of the text of the CDDL should have accompanied this
10# source.  A copy of the CDDL is also available via the Internet at
11# http://www.illumos.org/license/CDDL.
12#
13
14#
15# Copyright (c) 2014, 2016 by Delphix. All rights reserved.
16#
17
18#
19# Description:
20# Verify that holes can be written and read back correctly in ZFS.
21#
22# Strategy:
23# 1. Create a testfile with varying holes and data throughout the file.
24# 2. Verify that each created file has the correct number of holes and
25# data blocks as seen by both lseek and libzfs.
26# 3. Do the same verification for a largefile.
27# 4. Repeat for each recsize.
28#
29
30. $STF_SUITE/include/libtest.shlib
31. $STF_SUITE/tests/functional/holes/holes.shlib
32
33verify_runnable "both"
34testfile="$TESTDIR/testfile"
35
36for bs in 512 1024 2048 4096 8192 16384 32768 65536 131072; do
37	log_must zfs set recsize=$bs $TESTPOOL/$TESTFS
38
39	#
40	# Create combinations of holes and data to verify holes ending files
41	# and the like. (hhh, hhd, hdh...)
42	#
43	log_must mkholes -h 0:$((bs * 6)) $testfile
44	verify_holes_and_data_blocks $testfile 6 0
45	log_must rm $testfile
46
47	log_must mkholes -h 0:$((bs * 4)) -d $((bs * 4)):$((bs * 2)) $testfile
48	verify_holes_and_data_blocks $testfile 4 2
49	log_must rm $testfile
50
51	log_must mkholes -h 0:$((bs * 2)) -d $((bs * 2)):$((bs * 2)) \
52	    -h $((bs * 4)):$((bs * 2)) $testfile
53	verify_holes_and_data_blocks $testfile 4 2
54	log_must rm $testfile
55
56	log_must mkholes -h 0:$((bs * 2)) -d $((bs * 2)):$((bs * 4)) $testfile
57	verify_holes_and_data_blocks $testfile 2 4
58	log_must rm $testfile
59
60	log_must mkholes -d 0:$((bs * 2)) -h $((bs * 2)):$((bs * 4)) $testfile
61	verify_holes_and_data_blocks $testfile 4 2
62	log_must rm $testfile
63
64	log_must mkholes -d 0:$((bs * 2)) -h $((bs * 2)):$((bs * 2)) \
65	    -d $((bs * 4)):$((bs * 2)) $testfile
66	verify_holes_and_data_blocks $testfile 2 4
67	log_must rm $testfile
68
69	log_must mkholes -d 0:$((bs * 4)) -h $((bs * 4)):$((bs * 2)) $testfile
70	verify_holes_and_data_blocks $testfile 2 4
71	log_must rm $testfile
72
73	log_must mkholes -d 0:$((bs * 6)) $testfile
74	verify_holes_and_data_blocks $testfile 0 6
75	log_must rm $testfile
76
77	# Verify holes are correctly seen past the largefile limit.
78	len=$((1024**3 * 5))
79	nblks=$((len / bs))
80	log_must mkholes -h 0:$len -d $len:$bs $testfile
81	verify_holes_and_data_blocks $testfile $nblks 1
82	log_must rm $testfile
83done
84
85log_pass "Basic hole tests pass."
86