1 #!/usr/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 #
24 # Copyright 2007 Sun Microsystems, Inc. All rights reserved.
25 # Use is subject to license terms.
26 #
27
28 . ${STF_SUITE}/include/libtest.shlib
29
30 # Perform a bunch of read/writes on some newly created datasets.
31 # Create, mount and set the properties on a dataset before clobbering it
32 # with a bunch of cfile commands.
33 # @parameter: $1 the pool from which to draw these test file systems
34 # @return: 0 if all the work completed ok
35 # @use: NUM_CREATORS TOTAL_COUNT LOG COUNT
36 # dataset_set_defaultproperties TEST_BASE_DIR
37
38 typeset -i runat=0
39 typeset -i block_size=$(pagesize)
40 typeset dataset=$1
41 typeset ddirb=${TEST_BASE_DIR%%/}/dir.$$
42 typeset fn=dataset_create_write_destroy
43 typeset runpids
44 typeset tfilesys=
45 typeset tmntpnt=
46
47 set -A sizes
48
49 function remove_entities
50 {
51 [[ -n $runpids ]] && kill -9 $runpids
52 [[ -d $tmntpnt ]] && zfs umount -f $tmntpnt
53 [[ -n $tfilesys ]] && zfs destroy -f $tfilesys
54 rm -rf $tmntpnt
55 }
56
57 log_onexit remove_entities
58
59 if [[ -z $dataset ]]; then
60 log_note "$fn: Insufficient parameters (need 1, got $#)"
61 exit 1
62 fi
63
64 while (( block_size <= MAX_BLOCKSIZE )); do
65 # +A isn't append, this would be easier if it was.
66 set -A sizes ${sizes[@]} $block_size
67 (( block_size = block_size * 2 ))
68 done
69
70 (( count = TOTAL_COUNT * NUM_CREATORS ))
71
72 USE_F=""
73 while (( runat < count )); do
74 typeset -i atfile=0
75 typeset -i size=0
76 typeset pid=
77
78 tdir=$ddirb/$runat
79 tfilesys=$dataset/file.$$.$runat
80
81 log_must mkdir -p $tdir
82 log_must zfs create $tfilesys
83 log_must zfs set mountpoint=$tdir $tfilesys
84 dataset_set_defaultproperties $tfilesys
85 if (( $? != 0 )); then
86 log_fail "dataset_set_defaultproperties failed"
87 fi
88
89 while (( atfile < NUM_CREATORS )); do
90 file_write -o create -f $tdir/file${atfile} \
91 -b ${sizes[$size]} -d 0 -c $COUNT -wr &
92 runpids="$! $runpids"
93 (( size = size + 1 ))
94 (( size > ${#sizes[@]} )) && size=0
95 (( atfile = atfile + 1 ))
96 log_must zfs snapshot $tfilesys@snap${atfile}
97 done
98
99 mkfile 1g $tdir/mkfile.out &
100 runpids="$! $runpids"
101
102 dd if=/dev/urandom of=$tdir/dd.out bs=512 oseek=$RANDOM count=10000 &
103 runpids="$! $runpids"
104
105 for sn in 1 2 3 4 5 6 7 8 9
106 do
107 log_must zfs snapshot $tfilesys@snap${atfile}.${sn}
108 sleep 1
109 done
110
111 for pid in $runpids; do
112 wait $pid
113 typeset status=$?
114 if [ $status -ne 0 ]; then
115 log_note "file_write failed ($status)"
116 fi
117 done
118 runpids=
119
120 log_must rm -f $tdir/file*
121 # Issue a forced unmount on every second iteration
122 if [[ -n $USE_F ]] ; then
123 USE_F=""
124 else
125 USE_F="-f"
126 fi
127
128 log_must zfs unmount $USE_F $tdir
129 log_must zfs destroy -r $tfilesys
130 log_must rm -rf $tdir
131 tdir=
132 tfilesys=
133 (( runat = runat + 1 ))
134 done