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. $STF_SUITE/include/libtest.shlib
15
16#
17# DESCRIPTION:
18# Exercise gang block IO paths for non-encrypted and encrypted datasets.
19#
20
21verify_runnable "both"
22log_assert "Verify IO when file system is full and ganging."
23
24function cleanup
25{
26        log_must set_tunable64 METASLAB_FORCE_GANGING $metaslab_force_ganging
27	default_cleanup_noexit
28}
29
30log_onexit cleanup
31
32default_setup_noexit $DISKS
33
34typeset metaslab_force_ganging=$(get_tunable METASLAB_FORCE_GANGING)
35shift=$(random_int_between 15 17)
36log_must set_tunable64 METASLAB_FORCE_GANGING $((2**$shift))
37
38keyfile=/$TESTPOOL/keyencfods
39log_must eval "echo 'password' > $keyfile"
40bs=1024k
41count=512
42
43log_must dd if=/dev/urandom of=$TESTDIR/data bs=$bs count=$count
44data_checksum=$(sha256digest $TESTDIR/data)
45
46# Test common large block configuration.
47log_must zfs create -o recordsize=1m -o primarycache=metadata $TESTPOOL/gang
48mntpnt=$(get_prop mountpoint $TESTPOOL/gang)
49
50log_must dd if=$TESTDIR/data of=$mntpnt/file bs=$bs count=$count
51sync_pool $TESTPOOL
52log_must dd if=$mntpnt/file of=$TESTDIR/out bs=$bs count=$count
53out_checksum=$(sha256digest $TESTDIR/out)
54
55if [[ "$data_checksum" != "$out_checksum" ]]; then
56    log_fail "checksum mismatch ($data_checksum != $out_checksum)"
57fi
58
59log_must rm -f $TESTDIR/out
60log_must zfs destroy $TESTPOOL/gang
61
62# Test common large block configuration with encryption.
63log_must zfs create \
64	-o recordsize=1m \
65	-o primarycache=metadata \
66	-o compression=off \
67	-o encryption=on \
68	-o keyformat=passphrase \
69	-o keylocation=file://$keyfile \
70	-o copies=2 \
71	$TESTPOOL/gang
72mntpnt=$(get_prop mountpoint $TESTPOOL/gang)
73
74log_must dd if=$TESTDIR/data of=$mntpnt/file bs=$bs count=$count
75sync_pool $TESTPOOL
76log_must dd if=$mntpnt/file of=$TESTDIR/out bs=$bs count=$count
77out_checksum=$(sha256digest $TESTDIR/out)
78
79if [[ "$data_checksum" != "$out_checksum" ]]; then
80    log_fail "checksum mismatch ($data_checksum != $out_checksum)"
81fi
82
83log_must rm -f $TESTDIR/out
84log_must zfs destroy $TESTPOOL/gang
85
86log_pass "Verified IO when file system is full and ganging."
87