overlay/075: add test coverage for clearing immutable/append-only flags
[xfstests-dev.git] / common / xfs
1 #
2 # XFS specific common functions.
3 #
4
5 _setup_large_xfs_fs()
6 {
7         fs_size=$1
8         local tmp_dir=/tmp/
9
10         [ "$LARGE_SCRATCH_DEV" != yes ] && return 0
11         [ -z "$SCRATCH_DEV_EMPTY_SPACE" ] && SCRATCH_DEV_EMPTY_SPACE=0
12         [ $SCRATCH_DEV_EMPTY_SPACE -ge $fs_size ] && return 0
13
14         # calculate the size of the file we need to allocate.
15         # Default free space in the FS is 50GB, but you can specify more via
16         # SCRATCH_DEV_EMPTY_SPACE
17         file_size=$(($fs_size - 50*1024*1024*1024))
18         file_size=$(($file_size - $SCRATCH_DEV_EMPTY_SPACE))
19
20         # mount the filesystem, create the file, unmount it
21         _try_scratch_mount 2>&1 >$tmp_dir/mnt.err
22         local status=$?
23         if [ $status -ne 0 ]; then
24                 echo "mount failed"
25                 cat $tmp_dir/mnt.err >&2
26                 rm -f $tmp_dir/mnt.err
27                 return $status
28         fi
29         rm -f $tmp_dir/mnt.err
30
31         xfs_io -F -f \
32                 -c "truncate $file_size" \
33                 -c "falloc -k 0 $file_size" \
34                 -c "chattr +d" \
35                 $SCRATCH_MNT/.use_space 2>&1 > /dev/null
36         export NUM_SPACE_FILES=1
37         status=$?
38         _scratch_unmount
39         if [ $status -ne 0 ]; then
40                 echo "large file prealloc failed"
41                 cat $tmp_dir/mnt.err >&2
42                 return $status
43         fi
44         return 0
45 }
46
47 _scratch_mkfs_xfs_opts()
48 {
49         mkfs_opts=$*
50
51         # remove metadata related mkfs options if mkfs.xfs doesn't them
52         if [ -n "$XFS_MKFS_HAS_NO_META_SUPPORT" ]; then
53                 mkfs_opts=`echo $mkfs_opts | sed "s/-m\s\+\S\+//g"`
54         fi
55
56         _scratch_options mkfs
57
58         echo "$MKFS_XFS_PROG $SCRATCH_OPTIONS $mkfs_opts"
59 }
60
61
62 _scratch_mkfs_xfs_supported()
63 {
64         local mkfs_opts=$*
65
66         _scratch_options mkfs
67
68         $MKFS_XFS_PROG -N $MKFS_OPTIONS $SCRATCH_OPTIONS $mkfs_opts $SCRATCH_DEV
69         local mkfs_status=$?
70
71         # a mkfs failure may be caused by conflicts between $MKFS_OPTIONS and
72         # $mkfs_opts, try again without $MKFS_OPTIONS
73         if [ $mkfs_status -ne 0 -a -n "$mkfs_opts" ]; then
74                 $MKFS_XFS_PROG -N $SCRATCH_OPTIONS $mkfs_opts $SCRATCH_DEV
75                 mkfs_status=$?
76         fi
77         return $mkfs_status
78 }
79
80 # Returns the minimum XFS log size, in units of log blocks.
81 _scratch_find_xfs_min_logblocks()
82 {
83         local mkfs_cmd="`_scratch_mkfs_xfs_opts`"
84
85         # The smallest log size we can specify is 2M (XFS_MIN_LOG_BYTES) so
86         # pass that in and see if mkfs succeeds or tells us what is the
87         # minimum log size.
88         local XFS_MIN_LOG_BYTES=2097152
89
90         # Try formatting the filesystem with all the options given and the
91         # minimum log size.  We hope either that this succeeds or that mkfs
92         # tells us the required minimum log size for the feature set.
93         #
94         # We cannot use _scratch_do_mkfs because it will retry /any/ failed
95         # mkfs with MKFS_OPTIONS removed even if the only "failure" was that
96         # the log was too small.
97         local extra_mkfs_options="$* -N -l size=$XFS_MIN_LOG_BYTES"
98         eval "$mkfs_cmd $MKFS_OPTIONS $extra_mkfs_options $SCRATCH_DEV" \
99                 2>$tmp.mkfserr 1>$tmp.mkfsstd
100         local mkfs_status=$?
101
102         # If the format fails for a reason other than the log being too small,
103         # try again without MKFS_OPTIONS because that's what _scratch_do_mkfs
104         # will do if we pass in the log size option.
105         if [ $mkfs_status -ne 0 ] &&
106            ! egrep -q '(log size.*too small, minimum|external log device.*too small, must be)' $tmp.mkfserr; then
107                 eval "$mkfs_cmd $extra_mkfs_options $SCRATCH_DEV" \
108                         2>$tmp.mkfserr 1>$tmp.mkfsstd
109                 mkfs_status=$?
110         fi
111
112         # mkfs suceeded, so we must pick out the log block size to do the
113         # unit conversion
114         if [ $mkfs_status -eq 0 ]; then
115                 blksz="$(grep '^log.*bsize' $tmp.mkfsstd | \
116                         sed -e 's/log.*bsize=\([0-9]*\).*$/\1/g')"
117                 echo $((XFS_MIN_LOG_BYTES / blksz))
118                 rm -f $tmp.mkfsstd $tmp.mkfserr
119                 return
120         fi
121
122         # Usually mkfs will tell us the minimum log size...
123         if grep -q 'minimum size is' $tmp.mkfserr; then
124                 grep 'minimum size is' $tmp.mkfserr | \
125                         sed -e 's/^.*minimum size is \([0-9]*\) blocks/\1/g'
126                 rm -f $tmp.mkfsstd $tmp.mkfserr
127                 return
128         fi
129         if grep -q 'external log device.*too small, must be' $tmp.mkfserr; then
130                 grep 'external log device.*too small, must be' $tmp.mkfserr | \
131                         sed -e 's/^.*must be at least \([0-9]*\) blocks/\1/g'
132                 rm -f $tmp.mkfsstd $tmp.mkfserr
133                 return
134         fi
135
136         # Don't know what to do, so fail
137         echo "Cannot determine minimum log size" >&2
138         cat $tmp.mkfsstd >> $seqres.full
139         cat $tmp.mkfserr >> $seqres.full
140         rm -f $tmp.mkfsstd $tmp.mkfserr
141 }
142
143 _scratch_mkfs_xfs()
144 {
145         local mkfs_cmd="`_scratch_mkfs_xfs_opts`"
146         local mkfs_filter="sed -e '/less than device physical sector/d' \
147                                -e '/switching to logical sector/d' \
148                                -e '/Default configuration/d'"
149         local tmp=`mktemp -u`
150         local mkfs_status
151
152         _scratch_do_mkfs "$mkfs_cmd" "$mkfs_filter" $* 2>$tmp.mkfserr 1>$tmp.mkfsstd
153         mkfs_status=$?
154
155         grep -q crc=0 $tmp.mkfsstd && _force_xfsv4_mount_options
156
157         if [ $mkfs_status -eq 0 -a "$LARGE_SCRATCH_DEV" = yes ]; then
158                 # manually parse the mkfs output to get the fs size in bytes
159                 local fs_size
160                 fs_size=`cat $tmp.mkfsstd | perl -ne '
161                         if (/^data\s+=\s+bsize=(\d+)\s+blocks=(\d+)/) {
162                                 my $size = $1 * $2;
163                                 print STDOUT "$size\n";
164                         }'`
165                 _setup_large_xfs_fs $fs_size
166                 mkfs_status=$?
167         fi
168
169         # output mkfs stdout and stderr
170         cat $tmp.mkfsstd
171         cat $tmp.mkfserr >&2
172         rm -f $tmp.mkfserr $tmp.mkfsstd
173
174         return $mkfs_status
175 }
176
177 # Get the size of an allocation unit of a file.  Normally this is just the
178 # block size of the file, but for realtime files, this is the realtime extent
179 # size.
180 _xfs_get_file_block_size()
181 {
182         local path="$1"
183
184         if ! ($XFS_IO_PROG -c "stat -v" "$path" 2>&1 | egrep -q '(rt-inherit|realtime)'); then
185                 _get_block_size "$path"
186                 return
187         fi
188
189         # Otherwise, call xfs_info until we find a mount point or the root.
190         path="$(readlink -m "$path")"
191         while ! $XFS_INFO_PROG "$path" &>/dev/null && [ "$path" != "/" ]; do
192                 path="$(dirname "$path")"
193         done
194         $XFS_INFO_PROG "$path" | grep realtime | sed -e 's/^.*extsz=\([0-9]*\).*$/\1/g'
195 }
196
197 # Set or clear the realtime status of every supplied path.  The first argument
198 # is either 'data' or 'realtime'.  All other arguments should be paths to
199 # existing directories or empty regular files.
200 #
201 # For each directory, each file subsequently created will target the given
202 # device for file data allocations.  For each empty regular file, each
203 # subsequent file data allocation will be on the given device.
204 _xfs_force_bdev()
205 {
206         local device="$1"
207         shift
208         local chattr_arg=""
209
210         case "$device" in
211         "data")         chattr_arg="-t";;
212         "realtime")     chattr_arg="+t";;
213         *)
214                 echo "${device}: Don't know what device this is?"
215                 return 1
216                 ;;
217         esac
218
219         $XFS_IO_PROG -c "chattr $chattr_arg" "$@"
220 }
221
222 _xfs_get_fsxattr()
223 {
224         local field="$1"
225         local path="$2"
226
227         local value=$($XFS_IO_PROG -c "stat" "$path" | grep -w "$field")
228         echo ${value##fsxattr.${field} = }
229 }
230
231 # xfs_check script is planned to be deprecated. But, we want to
232 # be able to invoke "xfs_check" behavior in xfstests in order to
233 # maintain the current verification levels.
234 _xfs_check()
235 {
236         OPTS=" "
237         DBOPTS=" "
238         USAGE="Usage: xfs_check [-fsvV] [-l logdev] [-i ino]... [-b bno]... special"
239
240         OPTIND=1
241         while getopts "b:fi:l:stvV" c; do
242                 case $c in
243                         s) OPTS=$OPTS"-s ";;
244                         t) OPTS=$OPTS"-t ";;
245                         v) OPTS=$OPTS"-v ";;
246                         i) OPTS=$OPTS"-i "$OPTARG" ";;
247                         b) OPTS=$OPTS"-b "$OPTARG" ";;
248                         f) DBOPTS=$DBOPTS" -f";;
249                         l) DBOPTS=$DBOPTS" -l "$OPTARG" ";;
250                         V) $XFS_DB_PROG -p xfs_check -V
251                            return $?
252                            ;;
253                 esac
254         done
255         set -- extra $@
256         shift $OPTIND
257         case $# in
258                 1) ${XFS_DB_PROG}${DBOPTS} -F -i -p xfs_check -c "check$OPTS" $1
259                    status=$?
260                    ;;
261                 2) echo $USAGE 1>&1
262                    status=2
263                    ;;
264         esac
265         return $status
266 }
267
268 _scratch_xfs_db_options()
269 {
270         SCRATCH_OPTIONS=""
271         [ "$USE_EXTERNAL" = yes -a ! -z "$SCRATCH_LOGDEV" ] && \
272                 SCRATCH_OPTIONS="-l$SCRATCH_LOGDEV"
273         echo $SCRATCH_OPTIONS $* $SCRATCH_DEV
274 }
275
276 _scratch_xfs_db()
277 {
278         $XFS_DB_PROG "$@" $(_scratch_xfs_db_options)
279 }
280
281 _test_xfs_db_options()
282 {
283         TEST_OPTIONS=""
284         [ "$USE_EXTERNAL" = yes -a ! -z "$TEST_LOGDEV" ] && \
285                 TEST_OPTIONS="-l$TEST_LOGDEV"
286         echo $TEST_OPTIONS $* $TEST_DEV
287 }
288
289 _test_xfs_db()
290 {
291         $XFS_DB_PROG "$@" $(_test_xfs_db_options)
292 }
293
294 _scratch_xfs_admin()
295 {
296         local options=("$SCRATCH_DEV")
297         local rt_opts=()
298         [ "$USE_EXTERNAL" = yes -a ! -z "$SCRATCH_LOGDEV" ] && \
299                 options+=("$SCRATCH_LOGDEV")
300         if [ "$USE_EXTERNAL" = yes ] && [ -n "$SCRATCH_RTDEV" ]; then
301                 $XFS_ADMIN_PROG --help 2>&1 | grep -q 'rtdev' || \
302                         _notrun 'xfs_admin does not support rt devices'
303                 rt_opts+=(-r "$SCRATCH_RTDEV")
304         fi
305
306         # xfs_admin in xfsprogs 5.11 has a bug where an external log device
307         # forces xfs_db to be invoked, potentially with zero command arguments.
308         # When this happens, xfs_db will wait for input on stdin, which causes
309         # fstests to hang.  Since xfs_admin is not an interactive tool, we
310         # can redirect stdin from /dev/null to prevent this issue.
311         $XFS_ADMIN_PROG "${rt_opts[@]}" "$@" "${options[@]}" < /dev/null
312 }
313
314 _scratch_xfs_logprint()
315 {
316         SCRATCH_OPTIONS=""
317         [ "$USE_EXTERNAL" = yes -a ! -z "$SCRATCH_LOGDEV" ] && \
318                 SCRATCH_OPTIONS="-l$SCRATCH_LOGDEV"
319         $XFS_LOGPRINT_PROG $SCRATCH_OPTIONS $* $SCRATCH_DEV
320 }
321
322 _test_xfs_logprint()
323 {
324         TEST_OPTIONS=""
325         [ "$USE_EXTERNAL" = yes -a ! -z "$TEST_LOGDEV" ] && \
326                 TEST_OPTIONS="-l$TEST_LOGDEV"
327         $XFS_LOGPRINT_PROG $TEST_OPTIONS $* $TEST_DEV
328 }
329
330 _scratch_xfs_check()
331 {
332         SCRATCH_OPTIONS=""
333         [ "$USE_EXTERNAL" = yes -a ! -z "$SCRATCH_LOGDEV" ] && \
334                 SCRATCH_OPTIONS="-l $SCRATCH_LOGDEV"
335         [ "$LARGE_SCRATCH_DEV" = yes ] && \
336                 SCRATCH_OPTIONS=$SCRATCH_OPTIONS" -t"
337         _xfs_check $SCRATCH_OPTIONS $* $SCRATCH_DEV
338 }
339
340 # Check for secret debugging hooks in xfs_repair
341 _require_libxfs_debug_flag() {
342         local hook="$1"
343
344         grep -q "$hook" "$(type -P xfs_repair)" || \
345                 _notrun "libxfs debug hook $hook not detected?"
346 }
347
348 _scratch_xfs_repair()
349 {
350         SCRATCH_OPTIONS=""
351         [ "$USE_EXTERNAL" = yes -a ! -z "$SCRATCH_LOGDEV" ] && \
352                 SCRATCH_OPTIONS="-l$SCRATCH_LOGDEV"
353         [ "$USE_EXTERNAL" = yes -a ! -z "$SCRATCH_RTDEV" ] && \
354                 SCRATCH_OPTIONS=$SCRATCH_OPTIONS" -r$SCRATCH_RTDEV"
355         $XFS_REPAIR_PROG $SCRATCH_OPTIONS $* $SCRATCH_DEV
356 }
357
358 # this test requires the projid32bit feature to be available in mkfs.xfs.
359 #
360 _require_projid32bit()
361 {
362        _scratch_mkfs_xfs_supported -i projid32bit=1 >/dev/null 2>&1 \
363            || _notrun "mkfs.xfs doesn't have projid32bit feature"
364 }
365
366 _require_projid16bit()
367 {
368         _scratch_mkfs_xfs_supported -i projid32bit=0 >/dev/null 2>&1 \
369            || _notrun "16 bit project IDs not supported on $SCRATCH_DEV"
370 }
371
372 # this test requires the crc feature to be available in mkfs.xfs
373 #
374 _require_xfs_mkfs_crc()
375 {
376         _scratch_mkfs_xfs_supported -m crc=1 >/dev/null 2>&1 \
377            || _notrun "mkfs.xfs doesn't have crc feature"
378 }
379
380 # this test requires the xfs kernel support crc feature
381 #
382 _require_xfs_crc()
383 {
384         _scratch_mkfs_xfs -m crc=1 >/dev/null 2>&1
385         _try_scratch_mount >/dev/null 2>&1 \
386            || _notrun "Kernel doesn't support crc feature"
387         _scratch_unmount
388 }
389
390 # this test requires the xfs kernel support crc feature on scratch device
391 #
392 _require_scratch_xfs_crc()
393 {
394         _scratch_mkfs_xfs >/dev/null 2>&1
395         _try_scratch_mount >/dev/null 2>&1 \
396            || _notrun "Kernel doesn't support crc feature"
397         $XFS_INFO_PROG $SCRATCH_MNT | grep -q 'crc=1' || _notrun "crc feature not supported by this filesystem"
398         _scratch_unmount
399 }
400
401 # this test requires the finobt feature to be available in mkfs.xfs
402 #
403 _require_xfs_mkfs_finobt()
404 {
405         _scratch_mkfs_xfs_supported -m crc=1,finobt=1 >/dev/null 2>&1 \
406            || _notrun "mkfs.xfs doesn't have finobt feature"
407 }
408
409 # this test requires the xfs kernel support finobt feature
410 #
411 _require_xfs_finobt()
412 {
413         _scratch_mkfs_xfs -m crc=1,finobt=1 >/dev/null 2>&1
414         _try_scratch_mount >/dev/null 2>&1 \
415            || _notrun "Kernel doesn't support finobt feature"
416         _scratch_unmount
417 }
418
419 # this test requires xfs sysfs attribute support
420 #
421 _require_xfs_sysfs()
422 {
423         attr=$1
424         sysfsdir=/sys/fs/xfs
425
426         if [ ! -e $sysfsdir ]; then
427                 _notrun "no kernel support for XFS sysfs attributes"
428         fi
429
430         if [ ! -z $1 ] && [ ! -e $sysfsdir/$attr ]; then
431                 _notrun "sysfs attribute '$attr' is not supported"
432         fi
433 }
434
435 # this test requires the xfs sparse inode feature
436 #
437 _require_xfs_sparse_inodes()
438 {
439         _scratch_mkfs_xfs_supported -m crc=1 -i sparse > /dev/null 2>&1 \
440                 || _notrun "mkfs.xfs does not support sparse inodes"
441         _scratch_mkfs_xfs -m crc=1 -i sparse > /dev/null 2>&1
442         _try_scratch_mount >/dev/null 2>&1 \
443                 || _notrun "kernel does not support sparse inodes"
444         _scratch_unmount
445 }
446
447 # check that xfs_db supports a specific command
448 _require_xfs_db_command()
449 {
450         if [ $# -ne 1 ]; then
451                 echo "Usage: _require_xfs_db_command command" 1>&2
452                 exit 1
453         fi
454         command=$1
455
456         _scratch_mkfs_xfs >/dev/null 2>&1
457         _scratch_xfs_db -x -c "help" | grep $command > /dev/null || \
458                 _notrun "xfs_db $command support is missing"
459 }
460
461 # Does the filesystem mounted from a particular device support scrub?
462 _supports_xfs_scrub()
463 {
464         local mountpoint="$1"
465         local device="$2"
466
467         if [ -z "$device" ] || [ -z "$mountpoint" ]; then
468                 echo "Usage: _supports_xfs_scrub mountpoint device"
469                 return 1
470         fi
471
472         if [ ! -b "$device" ] || [ ! -e "$mountpoint" ]; then
473                 return 1
474         fi
475
476         test "$FSTYP" = "xfs" || return 1
477         test -x "$XFS_SCRUB_PROG" || return 1
478
479         # Probe for kernel support...
480         $XFS_IO_PROG -c 'help scrub' 2>&1 | grep -q 'types are:.*probe' || return 1
481         $XFS_IO_PROG -c "scrub probe" "$mountpoint" 2>&1 | grep -q "Inappropriate ioctl" && return 1
482
483         # Scrub can't run on norecovery mounts
484         _fs_options "$device" | grep -q "norecovery" && return 1
485
486         return 0
487 }
488
489 # Save a snapshot of a corrupt xfs filesystem for later debugging.
490 _xfs_metadump() {
491         local metadump="$1"
492         local device="$2"
493         local logdev="$3"
494         local compressopt="$4"
495         shift; shift; shift; shift
496         local options="$@"
497         test -z "$options" && options="-a -o"
498
499         if [ "$logdev" != "none" ]; then
500                 options="$options -l $logdev"
501         fi
502
503         $XFS_METADUMP_PROG $options "$device" "$metadump"
504         res=$?
505         [ "$compressopt" = "compress" ] && [ -n "$DUMP_COMPRESSOR" ] &&
506                 $DUMP_COMPRESSOR -f "$metadump" &> /dev/null
507         return $res
508 }
509
510 # Snapshot the metadata on the scratch device
511 _scratch_xfs_metadump()
512 {
513         local metadump=$1
514         shift
515         local logdev=none
516
517         [ "$USE_EXTERNAL" = yes -a ! -z "$SCRATCH_LOGDEV" ] && \
518                 logdev=$SCRATCH_LOGDEV
519
520         _xfs_metadump "$metadump" "$SCRATCH_DEV" "$logdev" nocompress "$@"
521 }
522
523 # run xfs_check and friends on a FS.
524 _check_xfs_filesystem()
525 {
526         if [ $# -ne 3 ]; then
527                 echo "Usage: _check_xfs_filesystem device <logdev>|none <rtdev>|none" 1>&2
528                 exit 1
529         fi
530
531         extra_mount_options=""
532         extra_log_options=""
533         extra_options=""
534         device=$1
535         if [ -f $device ]; then
536                 extra_options="-f"
537         fi
538
539         local logdev="$2"
540         if [ "$logdev" != "none" ]; then
541                 extra_log_options="-l$logdev"
542                 extra_mount_options="-ologdev=$logdev"
543         fi
544
545         local rtdev="$3"
546         if [ "$rtdev" != "none" ]; then
547                 extra_rt_options="-r$rtdev"
548                 extra_mount_options=$extra_mount_options" -ortdev=$rtdev"
549         fi
550         extra_mount_options=$extra_mount_options" $MOUNT_OPTIONS"
551
552         [ "$FSTYP" != xfs ] && return 0
553
554         type=`_fs_type $device`
555         ok=1
556
557         # Run online scrub if we can.
558         mntpt="$(_is_dev_mounted $device)"
559         if [ -n "$mntpt" ] && _supports_xfs_scrub "$mntpt" "$device"; then
560                 # Tests can create a scenario in which a call to syncfs() issued
561                 # at the end of the execution of the test script would return an
562                 # error code. xfs_scrub internally calls syncfs() before
563                 # starting the actual online consistency check operation. Since
564                 # such a call to syncfs() fails, xfs_scrub ends up returning
565                 # without performing consistency checks on the test
566                 # filesystem. This can mask a possible on-disk data structure
567                 # corruption. Hence consume such a possible syncfs() failure
568                 # before executing a scrub operation.
569                 $XFS_IO_PROG -c syncfs $mntpt >> $seqres.full 2>&1
570
571                 "$XFS_SCRUB_PROG" $scrubflag -v -d -n $mntpt > $tmp.scrub 2>&1
572                 if [ $? -ne 0 ]; then
573                         _log_err "_check_xfs_filesystem: filesystem on $device failed scrub"
574                         echo "*** xfs_scrub $scrubflag -v -d -n output ***" >> $seqres.full
575                         cat $tmp.scrub >> $seqres.full
576                         echo "*** end xfs_scrub output" >> $serqres.full
577                         ok=0
578                 fi
579                 rm -f $tmp.scrub
580         fi
581
582         if [ "$type" = "xfs" ]; then
583                 # mounted ...
584                 mountpoint=`_umount_or_remount_ro $device`
585         fi
586
587         $XFS_LOGPRINT_PROG -t $extra_log_options $device 2>&1 \
588                 | tee $tmp.logprint | grep -q "<CLEAN>"
589         if [ $? -ne 0 ]; then
590                 _log_err "_check_xfs_filesystem: filesystem on $device has dirty log"
591                 echo "*** xfs_logprint -t output ***"   >>$seqres.full
592                 cat $tmp.logprint                       >>$seqres.full
593                 echo "*** end xfs_logprint output"      >>$seqres.full
594
595                 ok=0
596         fi
597
598         # xfs_check runs out of memory on large files, so even providing the test
599         # option (-t) to avoid indexing the free space trees doesn't make it pass on
600         # large filesystems. Avoid it.
601         if [ "$LARGE_SCRATCH_DEV" != yes ]; then
602                 _xfs_check $extra_log_options $device 2>&1 > $tmp.fs_check
603         fi
604         if [ -s $tmp.fs_check ]; then
605                 _log_err "_check_xfs_filesystem: filesystem on $device is inconsistent (c)"
606                 echo "*** xfs_check output ***"         >>$seqres.full
607                 cat $tmp.fs_check                       >>$seqres.full
608                 echo "*** end xfs_check output"         >>$seqres.full
609
610                 ok=0
611         fi
612
613         $XFS_REPAIR_PROG -n $extra_options $extra_log_options $extra_rt_options $device >$tmp.repair 2>&1
614         if [ $? -ne 0 ]; then
615                 _log_err "_check_xfs_filesystem: filesystem on $device is inconsistent (r)"
616                 echo "*** xfs_repair -n output ***"     >>$seqres.full
617                 cat $tmp.repair                         >>$seqres.full
618                 echo "*** end xfs_repair output"        >>$seqres.full
619
620                 ok=0
621         fi
622         rm -f $tmp.fs_check $tmp.logprint $tmp.repair
623
624         if [ "$ok" -ne 1 ] && [ "$DUMP_CORRUPT_FS" = "1" ]; then
625                 local flatdev="$(basename "$device")"
626                 _xfs_metadump "$seqres.$flatdev.check.md" "$device" "$logdev" \
627                         compress >> $seqres.full
628         fi
629
630         # Optionally test the index rebuilding behavior.
631         if [ -n "$TEST_XFS_REPAIR_REBUILD" ]; then
632                 rebuild_ok=1
633                 $XFS_REPAIR_PROG $extra_options $extra_log_options $extra_rt_options $device >$tmp.repair 2>&1
634                 if [ $? -ne 0 ]; then
635                         _log_err "_check_xfs_filesystem: filesystem on $device is inconsistent (rebuild)"
636                         echo "*** xfs_repair output ***"        >>$seqres.full
637                         cat $tmp.repair                         >>$seqres.full
638                         echo "*** end xfs_repair output"        >>$seqres.full
639
640                         ok=0
641                         rebuild_ok=0
642                 fi
643                 rm -f $tmp.repair
644
645                 $XFS_REPAIR_PROG -n $extra_options $extra_log_options $extra_rt_options $device >$tmp.repair 2>&1
646                 if [ $? -ne 0 ]; then
647                         _log_err "_check_xfs_filesystem: filesystem on $device is inconsistent (rebuild-reverify)"
648                         echo "*** xfs_repair -n output ***"     >>$seqres.full
649                         cat $tmp.repair                         >>$seqres.full
650                         echo "*** end xfs_repair output"        >>$seqres.full
651
652                         ok=0
653                         rebuild_ok=0
654                 fi
655                 rm -f $tmp.repair
656
657                 if [ "$rebuild_ok" -ne 1 ] && [ "$DUMP_CORRUPT_FS" = "1" ]; then
658                         local flatdev="$(basename "$device")"
659                         _xfs_metadump "$seqres.$flatdev.rebuild.md" "$device" \
660                                 "$logdev" compress >> $seqres.full
661                 fi
662         fi
663
664         if [ $ok -eq 0 ]; then
665                 echo "*** mount output ***"             >>$seqres.full
666                 _mount                                  >>$seqres.full
667                 echo "*** end mount output"             >>$seqres.full
668         elif [ "$type" = "xfs" ]; then
669                 _mount_or_remount_rw "$extra_mount_options" $device $mountpoint
670         fi
671
672         if [ $ok -eq 0 ]; then
673                 status=1
674                 if [ "$iam" != "check" ]; then
675                         exit 1
676                 fi
677                 return 1
678         fi
679
680         return 0
681 }
682
683 _check_xfs_test_fs()
684 {
685         TEST_LOG="none"
686         TEST_RT="none"
687         [ "$USE_EXTERNAL" = yes -a ! -z "$TEST_LOGDEV" ] && \
688                 TEST_LOG="$TEST_LOGDEV"
689
690         [ "$USE_EXTERNAL" = yes -a ! -z "$TEST_RTDEV" ] && \
691                 TEST_RT="$TEST_RTDEV"
692
693         _check_xfs_filesystem $TEST_DEV $TEST_LOG $TEST_RT
694         return $?
695 }
696
697 _require_xfs_test_rmapbt()
698 {
699         _require_test
700
701         if [ "$($XFS_INFO_PROG "$TEST_DIR" | grep -c "rmapbt=1")" -ne 1 ]; then
702                 _notrun "rmapbt not supported by test filesystem type: $FSTYP"
703         fi
704 }
705
706 _require_xfs_scratch_rmapbt()
707 {
708         _require_scratch
709
710         _scratch_mkfs > /dev/null
711         _scratch_mount
712         if [ "$($XFS_INFO_PROG "$SCRATCH_MNT" | grep -c "rmapbt=1")" -ne 1 ]; then
713                 _scratch_unmount
714                 _notrun "rmapbt not supported by scratch filesystem type: $FSTYP"
715         fi
716         _scratch_unmount
717 }
718
719 _xfs_bmapx_find()
720 {
721         case "$1" in
722         "attr")
723                 param="a"
724                 ;;
725         "cow")
726                 param="c"
727                 ;;
728         *)
729                 param="e"
730                 ;;
731         esac
732         shift
733         file="$1"
734         shift
735
736         $XFS_IO_PROG -c "bmap -${param}lpv" "$file" | grep -c "$@"
737 }
738
739 # Reset all xfs error handling attributes, set them to original
740 # status.
741 #
742 # Only one argument, and it's mandatory:
743 #  - dev: device name, e.g. $SCRATCH_DEV
744 #
745 # Note: this function only works for XFS
746 _reset_xfs_sysfs_error_handling()
747 {
748         local dev=$1
749
750         if [ ! -b "$dev" -o "$FSTYP" != "xfs" ]; then
751                 _fail "Usage: reset_xfs_sysfs_error_handling <device>"
752         fi
753
754         _set_fs_sysfs_attr $dev error/fail_at_unmount 1
755         echo -n "error/fail_at_unmount="
756         _get_fs_sysfs_attr $dev error/fail_at_unmount
757
758         # Make sure all will be configured to retry forever by default, except
759         # for ENODEV, which is an unrecoverable error, so it will be configured
760         # to not retry on error by default.
761         for e in default EIO ENOSPC; do
762                 _set_fs_sysfs_attr $dev \
763                                    error/metadata/${e}/max_retries -1
764                 echo -n "error/metadata/${e}/max_retries="
765                 _get_fs_sysfs_attr $dev error/metadata/${e}/max_retries
766
767                 _set_fs_sysfs_attr $dev \
768                                    error/metadata/${e}/retry_timeout_seconds 0
769                 echo -n "error/metadata/${e}/retry_timeout_seconds="
770                 _get_fs_sysfs_attr $dev \
771                                    error/metadata/${e}/retry_timeout_seconds
772         done
773 }
774
775 # Skip if we are running an older binary without the stricter input checks.
776 # Make multiple checks to be sure that there is no regression on the one
777 # selected feature check, which would skew the result.
778 #
779 # At first, make a common function that runs the tests and returns
780 # number of failed cases.
781 _xfs_mkfs_validation_check()
782 {
783         local tmpfile=`mktemp`
784         local cmd="$MKFS_XFS_PROG -f -N -d file,name=$tmpfile,size=1g"
785
786         $cmd -s size=8s >/dev/null 2>&1
787         local sum=$?
788
789         $cmd -l version=2,su=260k >/dev/null 2>&1
790         sum=`expr $sum + $?`
791
792         rm -f $tmpfile
793         return $sum
794 }
795
796 # Skip the test if all calls passed - mkfs accepts invalid input
797 _require_xfs_mkfs_validation()
798 {
799         _xfs_mkfs_validation_check
800         if [ "$?" -eq 0 ]; then
801                 _notrun "Requires newer mkfs with stricter input checks: the oldest supported version of xfsprogs is 4.7."
802         fi
803 }
804
805 # The opposite of _require_xfs_mkfs_validation.
806 _require_xfs_mkfs_without_validation()
807 {
808         _xfs_mkfs_validation_check
809         if [ "$?" -ne 0 ]; then
810                 _notrun "Requires older mkfs without strict input checks: the last supported version of xfsprogs is 4.5."
811         fi
812 }
813
814 _require_scratch_xfs_shrink()
815 {
816         _require_scratch
817         _require_command "$XFS_GROWFS_PROG" xfs_growfs
818
819         _scratch_mkfs_xfs | _filter_mkfs 2>$tmp.mkfs >/dev/null
820         . $tmp.mkfs
821         _scratch_mount
822         # here just to check if kernel supports, no need do more extra work
823         local errmsg
824         errmsg=$($XFS_GROWFS_PROG -D$((dblocks-1)) "$SCRATCH_MNT" 2>&1)
825         if [ "$?" -ne 0 ]; then
826                 echo "$errmsg" | grep 'XFS_IOC_FSGROWFSDATA xfsctl failed: Invalid argument' > /dev/null && \
827                         _notrun "kernel does not support shrinking"
828                 echo "$errmsg" | grep 'data size .* too small, old size is ' > /dev/null && \
829                         _notrun "xfsprogs does not support shrinking"
830                 _fail "$XFS_GROWFS_PROG failed unexpectedly: $errmsg"
831         fi
832         _scratch_unmount
833 }
834
835 # XFS ability to change UUIDs on V5/CRC filesystems
836 #
837 _require_meta_uuid()
838 {
839         # This will create a crc fs on $SCRATCH_DEV
840         _require_xfs_crc
841
842         _scratch_xfs_db -x -c "uuid restore" 2>&1 \
843            | grep -q "invalid UUID\|supported on V5 fs" \
844            && _notrun "Userspace doesn't support meta_uuid feature"
845
846         _scratch_xfs_db -x -c "uuid generate" >/dev/null 2>&1
847
848         _try_scratch_mount >/dev/null 2>&1 \
849            || _notrun "Kernel doesn't support meta_uuid feature"
850         _scratch_unmount
851 }
852
853 # this test requires mkfs.xfs have case-insensitive naming support
854 _require_xfs_mkfs_ciname()
855 {
856         _scratch_mkfs_xfs_supported -n version=ci >/dev/null 2>&1 \
857                 || _notrun "need case-insensitive naming support in mkfs.xfs"
858 }
859
860 # this test requires mkfs.xfs have configuration file support
861 _require_xfs_mkfs_cfgfile()
862 {
863         echo > /tmp/a
864         _scratch_mkfs_xfs_supported -c options=/tmp/a >/dev/null 2>&1
865         res=$?
866         rm -rf /tmp/a
867         test $res -eq 0 || _notrun "need configuration file support in mkfs.xfs"
868 }
869
870 # XFS_DEBUG requirements
871 _require_xfs_debug()
872 {
873         if grep -q "debug 0" /proc/fs/xfs/stat; then
874                 _notrun "Require XFS built with CONFIG_XFS_DEBUG"
875         fi
876 }
877 _require_no_xfs_debug()
878 {
879         if grep -q "debug 1" /proc/fs/xfs/stat; then
880                 _notrun "Require XFS built without CONFIG_XFS_DEBUG"
881         fi
882 }
883
884 # Require that assertions will not crash the system.
885 #
886 # Assertions would always crash the system if XFS assert fatal was enabled
887 # (CONFIG_XFS_ASSERT_FATAL=y).  If a test is designed to trigger an assertion,
888 # skip the test on a CONFIG_XFS_ASSERT_FATAL built XFS by default.  Note:
889 # CONFIG_XFS_ASSERT_FATAL can be disabled by setting bug_on_assert to zero if
890 # we want test to run.
891 _require_no_xfs_bug_on_assert()
892 {
893         if [ -f /sys/fs/xfs/debug/bug_on_assert ]; then
894                 grep -q "1" /sys/fs/xfs/debug/bug_on_assert && \
895                    _notrun "test requires XFS bug_on_assert to be off, turn it off to run the test"
896         else
897                 # Note: Prior to the creation of CONFIG_XFS_ASSERT_FATAL (and
898                 # the sysfs knob bug_on_assert), assertions would always crash
899                 # the system if XFS debug was enabled (CONFIG_XFS_DEBUG=y).  If
900                 # a test is designed to trigger an assertion and the test
901                 # designer does not want to hang fstests, skip the test.
902                 _require_no_xfs_debug
903         fi
904 }
905
906 # Get a metadata field
907 # The first arg is the field name
908 # The rest of the arguments are xfs_db commands to find the metadata.
909 _scratch_xfs_get_metadata_field()
910 {
911         local key="$1"
912         shift
913
914         local grep_key="$(echo "${key}" | tr '[]()' '....')"
915         local cmds=()
916         local arg
917         for arg in "$@"; do
918                 cmds+=("-c" "${arg}")
919         done
920         _scratch_xfs_db "${cmds[@]}" -c "print ${key}" | grep "^${grep_key}" | \
921                 sed -e 's/^.* = //g'
922 }
923
924 # Set a metadata field
925 # The first arg is the field name
926 # The second arg is the new value
927 # The rest of the arguments are xfs_db commands to find the metadata.
928 _scratch_xfs_set_metadata_field()
929 {
930         local key="$1"
931         local value="$2"
932         shift; shift
933
934         local cmds=()
935         local arg
936         for arg in "$@"; do
937                 cmds+=("-c" "${arg}")
938         done
939
940         local wr_cmd="write"
941         _scratch_xfs_db -x -c "help write" | egrep -q "(-c|-d)" && value="-- ${value}"
942         _scratch_xfs_db -x -c "help write" | egrep -q "(-d)" && wr_cmd="${wr_cmd} -d"
943         _scratch_xfs_db -x "${cmds[@]}" -c "${wr_cmd} ${key} ${value}"
944 }
945
946 _scratch_xfs_get_sb_field()
947 {
948         _scratch_xfs_get_metadata_field "$1" "sb 0"
949 }
950
951 _scratch_xfs_set_sb_field()
952 {
953         _scratch_xfs_set_metadata_field "$1" "$2" "sb 0"
954 }
955
956 # Before xfsprogs commit 4222d000ed("db: write via array indexing doesn't
957 # work"), xfs_db command to write a specific AGFL index doesn't work. It's a
958 # bug in a diagnostic tool that is only used by XFS developers as a test
959 # infrastructure, so it's fine to treat it as a infrastructure dependency as
960 # all other _require rules.
961 _require_xfs_db_write_array()
962 {
963         local supported=0
964
965         _require_test
966         touch $TEST_DIR/$seq.img
967         $MKFS_XFS_PROG -d file,name=$TEST_DIR/$seq.img,size=512m >/dev/null 2>&1
968         $XFS_DB_PROG -x -c "agfl 0" -c "write bno[32] 78" $TEST_DIR/$seq.img \
969                 >/dev/null 2>&1
970         $XFS_DB_PROG -x -c "agfl 0" -c "print bno[32]" $TEST_DIR/$seq.img \
971                 | grep -q "bno\[32\] = 78" && supported=1
972         rm -f $TEST_DIR/$seq.img
973         [ $supported -eq 0 ] && _notrun "xfs_db write can't support array"
974 }
975
976 _require_xfs_spaceman_command()
977 {
978         if [ -z "$1" ]; then
979                 echo "Usage: _require_xfs_spaceman_command command [switch]" 1>&2
980                 exit 1
981         fi
982         local command=$1
983         shift
984         local param="$*"
985         local param_checked=0
986         local opts=""
987
988         _require_command "$XFS_SPACEMAN_PROG" "xfs_spaceman"
989
990         testfile=$TEST_DIR/$$.xfs_spaceman
991         touch $testfile
992         case $command in
993         "health")
994                 testio=`$XFS_SPACEMAN_PROG -c "health $param" $TEST_DIR 2>&1`
995                 param_checked=1
996                 ;;
997         *)
998                 testio=`$XFS_SPACEMAN_PROG -c "help $command" $TEST_DIR 2>&1`
999         esac
1000
1001         rm -f $testfile 2>&1 > /dev/null
1002         echo $testio | grep -q "not found" && \
1003                 _notrun "xfs_spaceman $command support is missing"
1004         echo $testio | grep -q "Operation not supported" && \
1005                 _notrun "xfs_spaceman $command failed (old kernel/wrong fs?)"
1006         echo $testio | grep -q "Invalid" && \
1007                 _notrun "xfs_spaceman $command failed (old kernel/wrong fs/bad args?)"
1008         echo $testio | grep -q "foreign file active" && \
1009                 _notrun "xfs_spaceman $command not supported on $FSTYP"
1010         echo $testio | grep -q "Inappropriate ioctl for device" && \
1011                 _notrun "xfs_spaceman $command support is missing (missing ioctl?)"
1012         echo $testio | grep -q "Function not implemented" && \
1013                 _notrun "xfs_spaceman $command support is missing (missing syscall?)"
1014
1015         [ -n "$param" ] || return
1016
1017         if [ $param_checked -eq 0 ]; then
1018                 $XFS_SPACEMAN_PROG -c "help $command" | grep -q "^ $param --" || \
1019                         _notrun "xfs_spaceman $command doesn't support $param"
1020         fi
1021 }
1022
1023 _scratch_get_sfdir_prefix() {
1024         local dir_ino="$1"
1025
1026         for prefix in "u.sfdir3" "u.sfdir2" "u3.sfdir3"; do
1027                 if [ -n "$(_scratch_xfs_get_metadata_field \
1028                                 "${prefix}.hdr.parent.i4" \
1029                                 "inode ${dir_ino}")" ]; then
1030                         echo "${prefix}"
1031                         return 0
1032                 fi
1033         done
1034         _scratch_xfs_db -c "inode ${dir_ino}" -c 'p' >> $seqres.full
1035         return 1
1036 }
1037
1038 _scratch_get_bmx_prefix() {
1039         local ino="$1"
1040
1041         for prefix in "u3.bmx" "u.bmx"; do
1042                 if [ -n "$(_scratch_xfs_get_metadata_field \
1043                                 "${prefix}[0].startblock" \
1044                                 "inode ${ino}")" ]; then
1045                         echo "${prefix}"
1046                         return 0
1047                 fi
1048         done
1049         _scratch_xfs_db -c "inode ${ino}" -c 'p' >> $seqres.full
1050         return 1
1051 }
1052
1053 _scratch_get_iext_count()
1054 {
1055         local ino=$1
1056         local whichfork=$2
1057         local field=""
1058
1059         case $whichfork in
1060                 "attr")
1061                         field=core.naextents
1062                         ;;
1063                 "data")
1064                         field=core.nextents
1065                         ;;
1066                 *)
1067                         return 1
1068         esac
1069
1070         _scratch_xfs_get_metadata_field $field "inode $ino"
1071 }
1072
1073 #
1074 # Ensures that we don't pass any mount options incompatible with XFS v4
1075 #
1076 _force_xfsv4_mount_options()
1077 {
1078         local gquota=0
1079         local pquota=0
1080
1081         # Can't have group and project quotas in XFS v4
1082         echo "$MOUNT_OPTIONS" | egrep -q "(gquota|grpquota|grpjquota=|gqnoenforce)" && gquota=1
1083         echo "$MOUNT_OPTIONS" | egrep -q "(\bpquota|prjquota|pqnoenforce)" && pquota=1
1084
1085         if [ $gquota -gt 0 ] && [ $pquota -gt 0 ]; then
1086                 export MOUNT_OPTIONS=$(echo $MOUNT_OPTIONS \
1087                         | sed   -e 's/gquota/QUOTA/g'      \
1088                                 -e 's/grpquota/QUOTA/g'    \
1089                                 -e 's/grpjquota=[^, ]/QUOTA/g' \
1090                                 -e 's/gqnoenforce/QUOTA/g' \
1091                                 -e "s/QUOTA/defaults/g")
1092         fi
1093         echo "MOUNT_OPTIONS = $MOUNT_OPTIONS" >>$seqres.full
1094 }
1095
1096 # Find AG count of mounted filesystem
1097 _xfs_mount_agcount()
1098 {
1099         $XFS_INFO_PROG "$1" | grep agcount= | sed -e 's/^.*agcount=\([0-9]*\),.*$/\1/g'
1100 }
1101
1102 # Wipe the superblock of each XFS AGs
1103 _try_wipe_scratch_xfs()
1104 {
1105         local num='^[0-9]+$'
1106         local agcount
1107         local agsize
1108         local dbsize
1109
1110         # Try to wipe each SB if there's an existed XFS
1111         agcount=`_scratch_xfs_get_sb_field agcount 2>/dev/null`
1112         agsize=`_scratch_xfs_get_sb_field agblocks 2>/dev/null`
1113         dbsize=`_scratch_xfs_get_sb_field blocksize 2>/dev/null`
1114         if [[ $agcount =~ $num && $agsize =~ $num && $dbsize =~ $num ]];then
1115                 for ((i = 0; i < agcount; i++)); do
1116                         $XFS_IO_PROG -c "pwrite $((i * dbsize * agsize)) $dbsize" \
1117                                 $SCRATCH_DEV >/dev/null;
1118                 done
1119         fi
1120
1121         # Try to wipe each SB by default mkfs.xfs geometry
1122         local tmp=`mktemp -u`
1123         unset agcount agsize dbsize
1124         _scratch_mkfs_xfs -N 2>/dev/null | perl -ne '
1125                 if (/^meta-data=.*\s+agcount=(\d+), agsize=(\d+) blks/) {
1126                         print STDOUT "agcount=$1\nagsize=$2\n";
1127                 }
1128                 if (/^data\s+=\s+bsize=(\d+)\s/) {
1129                         print STDOUT "dbsize=$1\n";
1130                 }' > $tmp.mkfs
1131
1132         . $tmp.mkfs
1133         if [[ $agcount =~ $num && $agsize =~ $num && $dbsize =~ $num ]];then
1134                 for ((i = 0; i < agcount; i++)); do
1135                         $XFS_IO_PROG -c "pwrite $((i * dbsize * agsize)) $dbsize" \
1136                                 $SCRATCH_DEV >/dev/null;
1137                 done
1138         fi
1139         rm -f $tmp.mkfs
1140 }
1141
1142 _require_xfs_copy()
1143 {
1144         [ -n "$XFS_COPY_PROG" ] || _notrun "xfs_copy binary not yet installed"
1145         [ "$USE_EXTERNAL" = yes ] && \
1146                 _notrun "Cannot xfs_copy with external devices"
1147 }
1148
1149 __xfs_cowgc_interval_knob1="/proc/sys/fs/xfs/speculative_cow_prealloc_lifetime"
1150 __xfs_cowgc_interval_knob2="/proc/sys/fs/xfs/speculative_prealloc_lifetime"
1151
1152 _xfs_set_cowgc_interval() {
1153         if [ -w $__xfs_cowgc_interval_knob1 ]; then
1154                 echo "$@" > $__xfs_cowgc_interval_knob1
1155         elif [ -w $__xfs_cowgc_interval_knob2 ]; then
1156                 echo "$@" > $__xfs_cowgc_interval_knob2
1157         else
1158                 _fail "Can't find cowgc interval procfs knob?"
1159         fi
1160 }
1161
1162 _xfs_get_cowgc_interval() {
1163         if [ -w $__xfs_cowgc_interval_knob1 ]; then
1164                 cat $__xfs_cowgc_interval_knob1
1165         elif [ -w $__xfs_cowgc_interval_knob2 ]; then
1166                 cat $__xfs_cowgc_interval_knob2
1167         else
1168                 _fail "Can't find cowgc interval procfs knob?"
1169         fi
1170 }
1171
1172 # Print the status of the given features on the scratch filesystem.
1173 # Returns 0 if all features are found, 1 otherwise.
1174 _check_scratch_xfs_features()
1175 {
1176         local features="$(_scratch_xfs_db -c 'version')"
1177         local output=("FEATURES:")
1178         local found=0
1179
1180         for feature in "$@"; do
1181                 local status="NO"
1182                 if echo "${features}" | grep -q -w "${feature}"; then
1183                         status="YES"
1184                         found=$((found + 1))
1185                 fi
1186                 output+=("${feature}:${status}")
1187         done
1188
1189         echo "${output[@]}"
1190         test "${found}" -eq "$#"
1191 }
1192
1193 # Skip a test if any of the given fs features aren't present on the scratch
1194 # filesystem.  The scratch fs must have been formatted already.
1195 _require_scratch_xfs_features()
1196 {
1197         local features="$(_scratch_xfs_db -c 'version' 2>/dev/null)"
1198
1199         for feature in "$@"; do
1200                 echo "${features}" | grep -q -w "${feature}" ||
1201                         _notrun "Missing scratch feature: ${feature}"
1202         done
1203 }
1204
1205 # Decide if xfs_repair knows how to set (or clear) a filesystem feature.
1206 _require_xfs_repair_upgrade()
1207 {
1208         local type="$1"
1209
1210         $XFS_REPAIR_PROG -c "$type=garbagevalue" 2>&1 | \
1211                 grep -q 'unknown option' && \
1212                 _notrun "xfs_repair does not support upgrading fs with $type"
1213 }
1214
1215 # Require that the scratch device exists, that mkfs can format with inobtcount
1216 # enabled, and that the kernel can mount such a filesystem.
1217 _require_scratch_xfs_inobtcount()
1218 {
1219         _require_scratch
1220
1221         _scratch_mkfs -m inobtcount=1 &> /dev/null || \
1222                 _notrun "mkfs.xfs doesn't support inobtcount feature"
1223         _try_scratch_mount || \
1224                 _notrun "kernel doesn't support xfs inobtcount feature"
1225         _scratch_unmount
1226 }
1227
1228 _xfs_timestamp_range()
1229 {
1230         local device="$1"
1231         local use_db=0
1232         local dbprog="$XFS_DB_PROG $device"
1233         test "$device" = "$SCRATCH_DEV" && dbprog=_scratch_xfs_db
1234
1235         $dbprog -f -c 'help timelimit' | grep -v -q 'not found' && use_db=1
1236         if [ $use_db -eq 0 ]; then
1237                 # The "timelimit" command was added to xfs_db at the same time
1238                 # that bigtime was added to xfsprogs.  Therefore, we can assume
1239                 # the old timestamp range if the command isn't present.
1240                 echo "-$((1<<31)) $(((1<<31)-1))"
1241         else
1242                 $dbprog -f -c 'timelimit --compact' | \
1243                         awk '{printf("%s %s", $1, $2);}'
1244         fi
1245 }
1246
1247 # Require that the scratch device exists, that mkfs can format with bigtime
1248 # enabled, that the kernel can mount such a filesystem, and that xfs_info
1249 # advertises the presence of that feature.
1250 _require_scratch_xfs_bigtime()
1251 {
1252         _require_scratch
1253
1254         _scratch_mkfs -m bigtime=1 &>/dev/null || \
1255                 _notrun "mkfs.xfs doesn't support bigtime feature"
1256         _try_scratch_mount || \
1257                 _notrun "kernel doesn't support xfs bigtime feature"
1258         $XFS_INFO_PROG "$SCRATCH_MNT" | grep -q -w "bigtime=1" || \
1259                 _notrun "bigtime feature not advertised on mount?"
1260         _scratch_unmount
1261 }