7290 ZFS test suite needs to control what utilities it can run
[unleashed.git] / usr / src / test / zfs-tests / tests / functional / cli_root / zfs_send / zfs_send_007_pos.ksh
blob35644f4f55096d5c2e4d99516f03d4487060bcef
1 #!/bin/ksh
3 # CDDL HEADER START
5 # This file and its contents are supplied under the terms of the
6 # Common Development and Distribution License ("CDDL"), version 1.0.
7 # You may only use this file in accordance with the terms of version
8 # 1.0 of the CDDL.
10 # A full copy of the text of the CDDL should have accompanied this
11 # source. A copy of the CDDL is also available via the Internet at
12 # http://www.illumos.org/license/CDDL.
14 # CDDL HEADER END
18 # Copyright (c) 2015, 2016 by Delphix. All rights reserved.
21 . $STF_SUITE/include/libtest.shlib
23 # DESCRIPTION:
24 # Verify 'zfs send' drills holes appropriately when files are replaced
26 # STRATEGY:
27 # 1. Create dataset
28 # 2. Write block 0 in a bunch of files
29 # 3. Snapshot the dataset
30 # 4. Remove all the files and rewrite some files with just block 1
31 # 5. Snapshot the dataset
32 # 6. Send both snapshots and receive them locally
33 # 7. diff the received dataset and the old datasets.
34 # 8. Repeat steps 1-7 above with pool that never had hole birth enabled.
37 verify_runnable "both"
39 function cleanup
41 zfs destroy -rf $TESTPOOL/fs
42 zfs destroy -rf $TESTPOOL/recvfs
43 rm $streamfile
44 rm $vdev
45 zpool destroy testpool
49 log_assert "Verify that 'zfs send' drills appropriate holes"
50 log_onexit cleanup
51 streamfile=$(mktemp /var/tmp/file.XXXXXX)
52 vdev=$(mktemp /var/tmp/file.XXXXXX)
55 test_pool ()
57 POOL=$1
58 log_must zfs create -o recordsize=512 $POOL/fs
59 mntpnt=$(get_prop mountpoint "$POOL/fs")
60 log_must dd if=/dev/urandom of=${mntpnt}/file bs=512 count=1 2>/dev/null
61 first_object=$(ls -i $mntpnt | awk '{print $1}')
62 log_must zfs snapshot $POOL/fs@a
63 while true; do
64 log_must find $mntpnt -delete
65 sync
66 log_must mkfiles "$mntpnt/" 4000
67 FILE=$(ls -i $mntpnt | awk \
68 '{if ($1 == '$first_object') {print $2}}')
69 if [[ -n "$FILE" ]]; then
70 break
72 done
73 dd if=/dev/urandom of=${mntpnt}/$FILE bs=512 count=1 seek=1 2>/dev/null
75 log_must zfs snapshot $POOL/fs@b
77 log_must eval "zfs send $POOL/fs@a > $streamfile"
78 cat $streamfile | log_must zfs receive $POOL/recvfs
80 log_must eval "zfs send -i @a $POOL/fs@b > $streamfile"
81 cat $streamfile | log_must zfs receive $POOL/recvfs
83 recv_mntpnt=$(get_prop mountpoint "$POOL/recvfs")
84 log_must diff -r $mntpnt $recv_mntpnt
85 log_must zfs destroy -rf $POOL/fs
86 log_must zfs destroy -rf $POOL/recvfs
89 test_pool $TESTPOOL
90 log_must truncate --size=1G $vdev
91 log_must zpool create -o version=1 testpool $vdev
92 test_pool testpool
93 log_must zpool destroy testpool
94 log_must zpool create -d testpool $vdev
95 test_pool testpool
96 log_must zpool destroy testpool
99 log_pass "'zfs send' drills appropriate holes"