1#! /bin/ksh -p
2#
3# CDDL HEADER START
4#
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.
9#
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.
13#
14# CDDL HEADER END
15#
16
17#
18# Copyright (c) 2014, 2016 by Delphix. All rights reserved.
19#
20
21. $STF_SUITE/include/libtest.shlib
22. $STF_SUITE/tests/functional/removal/removal.kshlib
23
24#
25# DESCRIPTION:
26#
27# For device removal a file's contents should transfer
28# completely from one disk to another. That should remain
29# to be the case even if multiple levels of indirection
30# are introduced as we remove more and more devices.
31#
32# STRATEGY:
33#
34# 1. We create a file of size 128k and we save its contents
35#    in a local variable.
36# 2. We set the limit of the maximum copied segment size of
37#    removals to 32k, so during removal our 128k file will
38#    be split to 4 blocks.
39# 3. We start removing disks and adding them back in a loop.
40#    This way the file is moved around and introduces split
41#    blocks.
42# 4. The loop itself tests that we don't have any problem
43#    when removing many devices. Within the loop we test
44#    that the files contents remain the same across transfers.
45#
46
47TMPDIR=${TMPDIR:-$TEST_BASE_DIR}
48log_must mkfile $(($MINVDEVSIZE * 2)) $TMPDIR/dsk1
49log_must mkfile $(($MINVDEVSIZE * 2)) $TMPDIR/dsk2
50DISKS="$TMPDIR/dsk1 $TMPDIR/dsk2"
51REMOVEDISK=$TMPDIR/dsk1
52
53log_must default_setup_noexit "$DISKS"
54
55function cleanup
56{
57	default_cleanup_noexit
58	log_must rm -f $DISKS
59
60	# reset zfs_remove_max_segment to 1M
61	log_must mdb_set_uint32 zfs_remove_max_segment 1048576
62}
63
64log_onexit cleanup
65
66# set zfs_remove_max_segment to 32k
67log_must mdb_set_uint32 zfs_remove_max_segment 32768
68
69log_must dd if=/dev/urandom of=$TESTDIR/$TESTFILE0 bs=128k count=1
70FILE_CONTENTS=`cat $TESTDIR/$TESTFILE0`
71log_must [ "x$(cat $TESTDIR/$TESTFILE0)" = "x$FILE_CONTENTS" ]
72
73for i in {1..100}; do
74	log_must zpool remove $TESTPOOL $TMPDIR/dsk1
75	log_must wait_for_removal $TESTPOOL
76	log_mustnot vdevs_in_pool $TESTPOOL $TMPDIR/dsk1
77	log_must zpool add $TESTPOOL $TMPDIR/dsk1
78
79	log_must zinject -a
80	log_must dd if=$TESTDIR/$TESTFILE0 of=/dev/null
81	log_must [ "x$(cat $TESTDIR/$TESTFILE0)" = "x$FILE_CONTENTS" ]
82
83	log_must zpool remove $TESTPOOL $TMPDIR/dsk2
84	log_must wait_for_removal $TESTPOOL
85	log_mustnot vdevs_in_pool $TESTPOOL $TMPDIR/dsk2
86	log_must zpool add $TESTPOOL $TMPDIR/dsk2
87
88	log_must zinject -a
89	log_must dd if=$TESTDIR/$TESTFILE0 of=/dev/null
90	log_must [ "x$(cat $TESTDIR/$TESTFILE0)" = "x$FILE_CONTENTS" ]
91done
92
93log_pass "File contents transfered completely from one disk to another."
94