Whamcloud - gitweb
LU-14286 osd-ldiskfs: fallocate() should zero new blocks
[fs/lustre-release.git] / lustre / tests / large-lun.sh
1 #!/bin/bash
2 #
3 # This script is used to test large size LUN support in Lustre.
4 #
5
6 set -e
7
8 LUSTRE=${LUSTRE:-$(dirname $0)/..}
9 . $LUSTRE/tests/test-framework.sh
10 init_test_env $@
11 init_logging
12
13 ALWAYS_EXCEPT="$LARGE_LUN_EXCEPT"
14 build_test_filter
15
16 if [ "$REFORMAT" != "yes" ]; then
17         skip_env "$0 reformats all devices,\
18                 please set REFORMAT to run this test"
19 fi
20
21 # Variable to run mdsrate
22 THREADS_PER_CLIENT=${THREADS_PER_CLIENT:-5}    # thread(s) per client node
23 NODES_TO_USE=${NODES_TO_USE:-$CLIENTS}
24 NUM_CLIENTS=$(get_node_count ${NODES_TO_USE//,/ })
25
26 LARGE_LUN_RESTORE_MOUNT=false
27 if is_mounted $MOUNT || is_mounted $MOUNT2; then
28         LARGE_LUN_RESTORE_MOUNT=true
29 fi
30 # Unmount and cleanup the Lustre filesystem
31 cleanupall
32 load_modules
33
34 FULL_MODE=${FULL_MODE:-false}
35 RUN_FSCK=${RUN_FSCK:-true}
36 # if SLOW=yes, enable the FULL_MODE
37 [[ $SLOW = yes ]] && FULL_MODE=true
38 #########################################################################
39 # Dump the super block information for the filesystem present on device.
40 run_dumpfs() {
41         local facet=$1
42         local dev=$2
43         local cmd
44
45         log "dump the super block information on $facet device $dev"
46         local fstype=$(facet_fstype $facet)
47
48         case $fstype in
49                 ldiskfs )
50                         cmd="$DUMPE2FS -h $dev" ;;
51                 zfs )
52                         cmd="$ZDB -l $(zpool_name $facet)" ;;
53                 * )
54                         error "unknown fstype!" ;;
55         esac
56
57         do_facet $facet "$cmd"
58 }
59
60 # Report Lustre filesystem disk space usage and inodes usage of each MDT/OST.
61 client_df() {
62         local mnt_pnt=$1
63         local cmd
64
65         cmd="df -h"
66         echo -e "\n# $cmd"
67         eval $cmd
68
69         cmd="lfs df -h $mnt_pnt"
70         echo -e "\n# $cmd"
71         eval $cmd
72
73         cmd="lfs df -i $mnt_pnt"
74         echo -e "\n# $cmd"
75         eval $cmd
76 }
77
78 # Cleanup the directories and files created by llverfs utility.
79 cleanup_dirs() {
80         local target=$1
81         local mnt=${2:-$MOUNT}
82         local cmd="rm -rf $mnt/{llverfs,dir}*"
83         do_facet $target "$cmd"
84 }
85
86 # Run mdsrate.
87 run_mdsrate() {
88         generate_machine_file $NODES_TO_USE $MACHINEFILE ||
89                 error "can not generate machinefile"
90
91         # set the default stripe count for files in this test to one
92         local testdir=$MOUNT/mdsrate
93         mkdir -p $testdir
94         chmod 0777 $testdir
95         $LFS setstripe $testdir -i 0 -c 1
96         get_stripe $testdir
97
98         local num_dirs=$THREADS_PER_CLIENT
99         [[ $num_dirs -eq 0 ]] && num_dirs=1
100         local free_inodes=$(lfs df -i $MOUNT | grep "OST:0" | awk '{print $4}')
101         local num_files
102         num_files=$((free_inodes / num_dirs))
103
104         local command="$MDSRATE $MDSRATE_DEBUG --create --verbose \
105                 --ndirs $num_dirs --dirfmt '$testdir/dir%d' \
106                 --nfiles $num_files --filefmt 'file%%d'"
107
108         echo "# $command"
109         mpi_run -machinefile $MACHINEFILE \
110                 -np $((NUM_CLIENTS * THREADS_PER_CLIENT)) $command
111
112         if [ ${PIPESTATUS[0]} != 0 ]; then
113                 error "mdsrate create failed"
114         fi
115 }
116
117 check_fsfacet() {
118         local facet=$1
119         local fstype=$(facet_fstype $facet)
120
121         case $fstype in
122             ldiskfs)
123                 run_e2fsck $(facet_active_host $facet) $(facet_device $facet) \
124                     "-y" || error "run e2fsck error"
125                 ;;
126             zfs)
127                 # Could call fsck.zfs, but currently it does nothing,
128                 # Could also call zpool scrub, but that could take a LONG time
129                 # do_facet $facet "fsck.zfs $(facet_device $facet)"
130                 ;;
131         esac
132 }
133
134 # Run e2fsck on MDS and OST
135 do_fsck() {
136         $RUN_FSCK || return
137
138         check_fsfacet $SINGLEMDS
139
140         for num in $(seq $OSTCOUNT); do
141                 check_fsfacet ost${num}
142         done
143 }
144 ################################## Main Flow ###################################
145 trap cleanupall EXIT
146
147 test_1 () {
148         [ "$mds1_FSTYPE" != ldiskfs ] && skip_env "ldiskfs only test"
149
150         local dev
151
152         for num in $(seq $OSTCOUNT); do
153                 dev=$(ostdevname $num)
154                 log "run llverdev on the OST $dev"
155                 do_rpc_nodes $(facet_host ost${num}) run_llverdev $dev -vpf ||
156                         error "llverdev on $dev failed!"
157         done
158         # restore format overwritten by llverdev
159         formatall
160 }
161 run_test 1 "run llverdev on raw LUN"
162
163 test_2 () {
164         local dev
165         local ostmnt
166         local fstype
167         local zostsize_restore=${OSTSIZE}
168         local zmin=$((30 << 30)) # 30GiB in bytes
169         local skipped=1
170
171         stack_trap "export OSTSIZE=$zostsize_restore" EXIT
172
173         for num in $(seq $OSTCOUNT); do
174                 dev=$(ostdevname $num)
175                 ostmnt=$(facet_mntpt ost${num})
176                 fstype=$(facet_fstype ost${num})
177
178                 if [[ $fstype == "zfs" ]] && [[ ${OSTSIZE} -lt ${zmin} ]]; then
179                         local real_dev=$(ostvdevname $num)
180                         local num_sectors=$(get_num_sectors $facet $real_dev)
181                         local phy_bytes=$((num_sectors * 512))
182
183                         if [ ${phy_bytes} -lt ${zmin} ] ; then
184                                 log "ost${num}: OSTSIZE ${OSTSIZE} less than 30GiB"
185                                 log "ost${num}: Block device ${phy_bytes} too small"
186                                 log " .. skipping this ost"
187                                 continue
188                         fi
189                         # Backing block device is big enough
190                         skipped=0
191                         log "ost${num}: OSTSIZE ${OSTSIZE} too small, increasing to 30GiB [temporarily]"
192                         format_ost ${num}
193                         # NOTE: OSTSIZE is in KB
194                         export OSTSIZE=$((zmin >> 10))
195                 fi
196
197                 # Mount the OST as an ldiskfs or zfs filesystem.
198                 log "mount the OST $dev as a $fstype filesystem"
199                 add ost${num} $(mkfs_opts ost${num} $dev) $FSTYPE_OPT \
200                         --reformat $(ostdevname $num) \
201                         $(ostvdevname $num) > /dev/null ||
202                         error "format ost${num} error"
203                 if [ $fstype == zfs ]; then
204                         import_zpool ost${num}
205                         do_facet ost${num} \
206                             "$ZFS set canmount=on $dev; " \
207                             "$ZFS set mountpoint=legacy $dev; " \
208                             "$ZFS list $dev"
209                 fi
210                 run_dumpfs ost${num} $dev
211                 do_facet ost${num} mount -t $fstype $dev \
212                         $ostmnt "$OST_MOUNT_OPTS"
213
214                 # Run llverfs on the mounted filesystem in partial mode
215                 # to ensure that the kernel can perform filesystem operations
216                 # on the complete device without any errors.
217                 log "run llverfs in partial mode on the OST $fstype $ostmnt"
218                 do_rpc_nodes $(facet_host ost${num}) run_llverfs $ostmnt -vpl \
219                         "no" || error "run_llverfs error on $fstype"
220
221                 # Unmount the OST.
222                 log "unmount the OST $dev"
223                 stop ost${num}
224
225                 # After llverfs is run on the filesystem in partial
226                 # mode, a full e2fsck should be run to catch any errors early.
227                 $RUN_FSCK && check_fsfacet ost${num}
228
229                 if $FULL_MODE; then
230                         log "full mode, mount the OST $dev as a $fstype again"
231                         if [ $fstype == zfs ]; then
232                                 import_zpool ost${num}
233                         fi
234                         do_facet ost${num} mount -t $(facet_fstype ost${num}) \
235                                 $dev $ostmnt "$OST_MOUNT_OPTS"
236                         cleanup_dirs ost${num} $ostmnt
237                         do_facet ost${num} "sync"
238
239                         run_dumpfs ost${num} $dev
240
241                         # Run llverfs on the mounted ldiskfs filesystem in full
242                         # mode to ensure that the kernel can perform filesystem
243                         # operations on the complete device without any errors.
244                         log "run llverfs in full mode on OST $fstype $ostmnt"
245                         do_rpc_nodes $(facet_host ost${num}) run_llverfs \
246                                 $ostmnt -vl "no" ||
247                                 error "run_llverfs error on $fstype"
248
249                         # Unmount the OST.
250                         log "unmount the OST $dev"
251                         stop ost${num}
252
253                         # After llverfs is run on the ldiskfs filesystem in
254                         # full mode, a full e2fsck should be run to catch any
255                         #  errors early.
256                         $RUN_FSCK && check_fsfacet ost${num}
257                 fi
258                 export OSTSIZE=${zostsize_restore}
259         done
260         [[ $skipped -ne 0 ]] && skip_env "No OST with enough space is available."
261         # there is no reason to continue using ost devices
262         # filled by llverfs as ldiskfs
263         formatall
264 }
265 run_test 2 "run llverfs on OST ldiskfs/zfs filesystem"
266
267 test_3 () {
268         [ -z "$CLIENTS" ] && skip_env "CLIENTS not defined, skipping"
269         [ -z "$MPIRUN" ] && skip_env "MIPRUN not defined, skipping"
270         [ -z "$MDSRATE" ] && skip_env "MDSRATE not defined, skipping"
271         [ ! -x $MDSRATE ] && skip_env "$MDSRATE not built, skipping"
272         # Setup the Lustre filesystem.
273         log "setup the lustre filesystem"
274         REFORMAT="yes" check_and_setup_lustre
275
276         log "run mdsrate to use up the free inodes."
277         # Run the mdsrate test suite.
278         run_mdsrate
279         client_df $MOUNT
280
281         sync; sleep 5; sync
282         stopall
283         do_fsck
284 }
285 run_test 3 "use up free inodes on the OST with mdsrate"
286
287 test_4 () {
288         # Setup the Lustre filesystem.
289         log "setup the lustre filesystem"
290         REFORMAT="yes" check_and_setup_lustre
291         local dev
292
293         for num in $(seq $OSTCOUNT); do
294                 dev=$(ostdevname $num)
295                 run_dumpfs ost${num} $dev
296         done
297
298         # Run llverfs on the mounted Lustre filesystem both in partial and
299         # full mode to to fill the filesystem and verify the file contents.
300         log "run llverfs in partial mode on the Lustre filesystem $MOUNT"
301         run_llverfs $MOUNT -vp "no" || error "run_llverfs error on lustre"
302         client_df $MOUNT
303
304         sync; sleep 5; sync
305         stopall
306         do_fsck
307
308         if $FULL_MODE; then
309                 # Setup the Lustre filesystem again.
310                 log "setup the lustre filesystem again"
311                 setupall
312
313                 cleanup_dirs client $MOUNT
314                 sync
315                 client_df $MOUNT
316
317                 for num in $(seq $OSTCOUNT); do
318                         dev=$(ostdevname $num)
319                         run_dumpfs ost${num} $dev
320                 done
321
322                 log "run llverfs in full mode on the Lustre filesystem $MOUNT"
323                 run_llverfs $MOUNT -vl "no" ||
324                         error "run_llverfs error on lustre"
325                 client_df $MOUNT
326
327                 sync; sleep 5; sync
328                 stopall
329                 do_fsck
330         fi
331 }
332 run_test 4 "run llverfs on lustre filesystem"
333
334 complete $SECONDS
335 $LARGE_LUN_RESTORE_MOUNT && setupall
336 check_and_cleanup_lustre
337 exit_status