2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (c) 2021 Red Hat, Inc., Lukas Czerner <lczerner@redhat.com>.
7 # Sanity check of ext4 mount options
10 _begin_fstest auto mount
13 seqres=$RESULT_DIR/$seq
17 status=1 # failure is the default!
18 trap "_cleanup; exit \$status" 0 1 2 3 15
23 $UMOUNT_PROG $SCRATCH_MNT > /dev/null 2>&1
24 if [ -n "$LOOP_LOGDEV" ];then
25 _destroy_loop_device $LOOP_LOGDEV 2>/dev/null
30 # get standard environment, filters and checks
34 # remove previous $seqres.full before test
37 echo "Silence is golden."
39 SIZE=$((1024 * 1024)) # 1GB in KB
40 LOGSIZE=$((10 *1024)) # 10MB in KB
42 _supported_fs ext2 ext3 ext4
43 _require_scratch_size $SIZE
46 _require_command "$TUNE2FS_PROG" tune2fs
47 MKE2FS_PROG=$(type -P mke2fs)
48 _require_command "$MKE2FS_PROG" mke2fs
49 _require_kernel_config CONFIG_QFMT_V2
56 KERNEL_VERSION=`uname -r | cut -d'.' -f1,2`
57 KERNEL_MAJ=${KERNEL_VERSION%.*}
58 KERNEL_MIN=${KERNEL_VERSION#*.}
64 if [ $KERNEL_MAJ -gt $major ]; then
66 elif [[ $KERNEL_MAJ -eq $major && $KERNEL_MIN -ge $minor ]]; then
73 # The aim here is to keep the mount options behaviour stable going forward
74 # so there is not much point in testing older kernels.
75 kernel_gte 5.12 || _notrun "This test is only relevant for kernel versions 5.12 and higher"
77 IGNORED="remount,defaults,ignored,removed"
78 CHECK_MINFO="lazytime,noatime,nodiratime,noexec,nosuid,ro"
80 # List of options that can't be used for remount even if the argument
82 CANT_REMOUNT="defaults,remount,abort,journal_path,journal_dev,usrjquota,grpjquota,jqfmt"
86 findmnt -n $SCRATCH_DEV > /dev/null 2>&1
87 [ $? -ne 0 ] && return $?
91 elif [ $# -eq 2 ]; then
97 print_log "checking \"$OPTS\" "
98 # test options in /proc/fs/ext4/dev/options
102 for option in $OPTS; do
103 if echo $IGNORED | grep -w $option; then
107 [ $option = "noload" ] && option="norecovery"
109 if [[ $option = ^* ]]; then
116 if echo $CHECK_MINFO | grep -w $option; then
117 findmnt -n -o OPTIONS $SCRATCH_DEV | grep $option
120 grep $option /proc/fs/ext4/$(_short_dev $SCRATCH_DEV)/options
124 if [ $ret -ne $expected ]; then
135 echo $LOG | tee -a $seqres.full
141 echo $LOG >> $seqres.full
146 _mount $* >> $seqres.full 2>&1
149 # $1 - can hold -n option, if it does argumetns are shifted
150 # $1 - options to test
151 # $2 - if provided it's the option string to check for
154 # If -n argument is provided do not specify $SCRATCH_DEV
155 # usefull for remount
156 if [ "$1" == "-n" ]; then
162 simple_mount $device $SCRATCH_MNT
165 simple_mount -o $1 $device $SCRATCH_MNT
168 if [ $ret -eq 0 ]; then
171 [ $ret -ne 0 ] && print_log "(not found)"
173 print_log "(failed mount)"
176 if [ $ret -ne 0 ] || [ -z "$1" ]; then
180 # Skip options that can't be remounted even if the argument
186 if echo $CANT_REMOUNT | grep -w $opt; then
189 # Skip the remount if we have data=journal on ext3 because
190 # it will set nodioread_nolock which is not supported on ext3
191 # hence remount will fail. Yes it is broken.
192 if [[ $fstype == "ext3" ]] && [[ $option == "data=journal" ]]; then
197 [ $? -eq 1 ] && return 0
198 print_log "(going to remount options $1)"
200 # Just remount with original mnt options, don't add anything at all
201 simple_mount -o remount,$1 $SCRATCH_MNT
203 if [ $ret -eq 0 ]; then
206 [ $ret -ne 0 ] && print_log "(not found after remount)"
208 print_log "(failed remount)"
211 [ $ret -ne 0 ] && return $ret
213 # Plain remount without specifying any mount options
214 simple_mount -o remount $SCRATCH_MNT
216 if [ $ret -eq 0 ]; then
219 [ $ret -ne 0 ] && print_log "(not found after plain remount)"
221 print_log "(failed plain remount)"
227 # Test that mounting or remounting with the specified mount option(s) fails
228 # (meaning that the mount or remount fails, as opposed to the mount option(s)
229 # just being ignored).
231 # We don't need -t not not_ variant
232 if [ "$1" == "-t" ]; then
236 print_log "SHOULD FAIL mounting $fstype \"$1\" "
237 if simple_mount -o $1 $SCRATCH_DEV $SCRATCH_MNT; then
238 print_log "(mount unexpectedly succeeded)"
240 $UMOUNT_PROG $SCRATCH_MNT
245 if ! simple_mount $SCRATCH_DEV $SCRATCH_MNT; then
246 print_log "(normal mount unexpectedly failed)"
251 $UMOUNT_PROG $SCRATCH_MNT
255 print_log "mounting $fstype \"$1\" "
257 if [ $? -ne 0 ]; then
265 # Do we need to run the tune2fs mount option test ?
267 if [ "$1" == "-t" ]; then
273 $UMOUNT_PROG $SCRATCH_MNT 2> /dev/null
275 [ "$t2fs" -eq 0 ] && return
278 if [ $# -eq 1 ]; then
280 elif [ $# -eq 2 ]; then
286 # some options need translation for tune2fs
287 op_set=$(echo $op_set | sed -e 's/data=journal/journal_data/' \
288 -e 's/data=ordered/journal_data_ordered/' \
289 -e 's/data=writeback/journal_data_writeback/')
290 $TUNE2FS_PROG -o $op_set $SCRATCH_DEV > /dev/null 2>&1
291 mnt_only "defaults" $check
292 $UMOUNT_PROG $SCRATCH_MNT 2> /dev/null
293 if [ "$op_set" = ^* ]; then
298 $TUNE2FS_PROG -o $op_set $SCRATCH_DEV > /dev/null 2>&1
301 # $1 - options to mount with
302 # $2 - options to remount with
304 # First do this specifying both dev and mnt
305 print_log "mounting $fstype \"$1\" "
307 [ $? -ne 0 ] && fail && return
308 print_log "remounting \"$2\" "
310 if [ $? -ne 0 ]; then
312 $UMOUNT_PROG $SCRATCH_MNT 2> /dev/null
317 $UMOUNT_PROG $SCRATCH_MNT 2> /dev/null
319 # Now just specify mnt
320 print_log "mounting $fstype \"$1\" "
322 [ $? -ne 0 ] && fail && return
323 print_log "remounting (MNT ONLY) \"$2\" "
324 do_mnt -n remount,$2 $3
325 if [ $? -ne 0 ]; then
331 $UMOUNT_PROG $SCRATCH_MNT 2> /dev/null
334 # Test that the filesystem cannot be remounted with option(s) $1 (meaning that
335 # the remount fails, as opposed to the mount option(s) just being ignored). The
336 # filesystem must already be mounted, and it is not unmounted afterwards.
338 print_log "SHOULD FAIL remounting $fstype \"$1\" "
339 # Try specifying both dev and mnt.
340 if simple_mount -o remount,$1 $SCRATCH_DEV $SCRATCH_MNT; then
341 print_log "(remount unexpectedly succeeded)"
347 # Try specifying mnt only.
348 print_log "SHOULD FAIL remounting $fstype (MNT ONLY) \"$1\" "
349 if simple_mount -o remount,$1 $SCRATCH_MNT; then
350 print_log "(remount unexpectedly succeeded)"
357 # Mount the filesystem with option(s) $1, then test that it cannot be remounted
358 # with option(s) $2 (meaning that the remount fails, as opposed to the mount
359 # option(s) just being ignored).
360 mnt_then_not_remount() {
361 print_log "mounting $fstype \"$1\" "
367 $UMOUNT_PROG $SCRATCH_MNT
372 $MKE2FS_PROG -T $fstype -Fq $* >> $seqres.full 2>&1 ||
373 _fail "mkfs failed - $MKFS_EXT4_PROG -Fq $* $SCRATCH_DEV"
377 if [[ $fstype == "ext2" ]]; then
385 if [[ $fstype == "ext4" ]]; then
392 # Create logdev for external journal
394 truncate -s ${LOGSIZE}k $LOOP_IMG
395 LOOP_LOGDEV=`_create_loop_device $LOOP_IMG`
396 majmin=`stat -c "%t:%T" $LOOP_LOGDEV`
397 LOGDEV_DEVNUM=`echo "${majmin%:*}*2^8 + ${majmin#*:}" | bc`
399 # Test all the extN file system supported by ext4 driver
401 for fstype in ext2 ext3 ext4; do
403 $UMOUNT_PROG $SCRATCH_MNT 2> /dev/null
404 $UMOUNT_PROG $SCRATCH_DEV 2> /dev/null
406 do_mkfs $SCRATCH_DEV ${SIZE}k
408 # do we have fstype support ?
410 if [ $? -ne 0 ]; then
411 print_log "$fstype not supported. Skipping..."
415 if [ ! -f /proc/fs/ext4/$(_short_dev $SCRATCH_DEV)/options ]; then
416 print_log "$fstype not supported. Skipping..."
421 $UMOUNT_PROG $SCRATCH_MNT 2> /dev/null
428 mnt -t bsdgroups grpid
430 mnt sysvgroups nogrpid
436 mnt errors=remount-ro
444 if _has_kernel_config CONFIG_EXT4_FS_POSIX_ACL; then
450 not_ext2 mnt noload norecovery
453 not_ext2 mnt commit=7
454 mnt min_batch_time=200
455 mnt max_batch_time=10000
456 only_ext4 mnt journal_checksum
457 only_ext4 mnt nojournal_checksum
458 only_ext4 mnt journal_async_commit,data=writeback
460 not_ext2 mnt -t data=journal
461 not_ext2 mnt -t data=ordered
462 not_ext2 mnt -t data=writeback
463 not_ext2 mnt data_err=abort
464 not_ext2 mnt data_err=ignore ignored
465 mnt usrjquota=aquota.user,jqfmt=vfsv0
466 not_mnt usrjquota=aquota.user
467 mnt usrjquota= ignored
468 mnt grpjquota=aquota.group,jqfmt=vfsv0
469 not_mnt grpjquota=aquota.group
470 mnt grpjquota= ignored
480 mnt barrier=0 nobarrier
481 mnt barrier=1 barrier
482 mnt barrier=99 barrier
486 only_ext4 mnt delalloc
487 only_ext4 mnt -t nodelalloc
490 not_mnt debug_want_extra_isize=512
491 mnt debug_want_extra_isize=32 ignored
492 mnt mblk_io_submit removed
493 mnt nomblk_io_submit removed
494 mnt -t block_validity
496 mnt inode_readahead_blks=16
497 not_ext2 mnt journal_ioprio=6 ignored
498 mnt auto_da_alloc=0 noauto_da_alloc
499 mnt auto_da_alloc=1 auto_da_alloc
500 mnt auto_da_alloc=95 auto_da_alloc
503 only_ext4 mnt dioread_nolock
504 only_ext4 mnt nodioread_nolock
505 only_ext4 mnt dioread_lock nodioread_nolock
512 mnt max_dir_size_kb=4096
514 if _has_kernel_config CONFIG_FS_ENCRYPTION; then
515 mnt test_dummy_encryption
516 mnt test_dummy_encryption=v1
517 mnt test_dummy_encryption=v2
518 not_mnt test_dummy_encryption=v3
519 not_mnt test_dummy_encryption=
521 mnt test_dummy_encryption ^test_dummy_encryption
522 mnt test_dummy_encryption=v1 ^test_dummy_encryption=v1
523 mnt test_dummy_encryption=v2 ^test_dummy_encryption=v2
524 mnt test_dummy_encryption=v3 ^test_dummy_encryption=v3
525 not_mnt test_dummy_encryption=
528 if _has_kernel_config CONFIG_FS_ENCRYPTION_INLINE_CRYPT; then
531 mnt inlinecrypt ^inlinecrypt
534 mnt prefetch_block_bitmaps removed
535 mnt no_prefetch_block_bitmaps
536 # We don't currently have a way to know that the option has been
537 # applied, so comment it out for now. This should be fixed in the
539 #mnt mb_optimize_scan=0
540 #mnt mb_optimize_scan=1
541 #not_mnt mb_optimize_scan=9
542 #not_mnt mb_optimize_scan=
544 mnt no_mbcache nombcache
545 mnt check=none removed
547 mnt reservation removed
548 mnt noreservation removed
549 mnt journal=20 ignored
550 not_mnt nonsenseoption
551 not_mnt nonsenseoption=value
553 # generic mount options
555 mnt nolazytime ^lazytime
562 # generic remount check
563 remount barrier nobarrier
564 remount nobarrier barrier
565 remount discard nodiscard
566 remount nodiscard discard
569 simple_mount -o dax=always $SCRATCH_DEV $SCRATCH_MNT > /dev/null 2>&1
570 if [ $? -eq 0 ]; then
571 $UMOUNT_PROG $SCRATCH_MNT 2> /dev/null
577 mnt_then_not_remount lazytime dax
578 mnt_then_not_remount dax=always dax=never
580 if [[ $fstype != "ext2" ]]; then
581 mnt_then_not_remount data=journal dax
582 mnt_then_not_remount data=journal dax=always
583 mnt_then_not_remount data=journal dax=never
584 mnt_then_not_remount data=journal dax=inode
588 # Quota remount check
589 remount grpquota usrquota
590 remount usrquota quota
591 remount usrquota usrjquota=q.u,jqfmt=vfsv0
592 remount grpquota grpjquota=q.g,jqfmt=vfsv0
594 mnt_then_not_remount usrquota grpjquota=q.g,jqfmt=vfsv0
595 mnt_then_not_remount grpquota usrjquota=q.u,jqfmt=vfsv0
597 remount quota usrjquota=q.u,jqfmt=vfsv0
598 mnt_then_not_remount quota grpjquota=q.g,jqfmt=vfsv0
600 remount usrjquota=q.u,jqfmt=vfsv0 grpjquota=q.g
601 mnt_then_not_remount usrjquota=q.u,jqfmt=vfsv0 usrjquota=q.ua
602 mnt_then_not_remount grpjquota=q.g,jqfmt=vfsv0 grpjquota=q.ga
604 remount usrjquota=q.u,jqfmt=vfsv0 usrquota usrjquota=q.u,jqfmt=vfsv0
605 remount grpjquota=q.g,jqfmt=vfsv0 grpquota grpjquota=q.g,jqfmt=vfsv0
606 mnt_then_not_remount usrjquota=q.u,jqfmt=vfsv0 grpquota
607 mnt_then_not_remount grpjquota=q.g,jqfmt=vfsv0 usrquota
609 remount grpjquota=q.g,jqfmt=vfsv0 grpjquota= ^grpjquota=
610 remount usrjquota=q.u,jqfmt=vfsv0 usrjquota= ^usrjquota=
611 remount grpjquota=q.g,usrjquota=q.u,jqfmt=vfsv0 grpjquota=,usrjquota= ^grpjquota=,^usrjquota=
613 remount jqfmt=vfsv0 grpjquota=q.g
614 remount jqfmt=vfsv0 usrjquota=q.u
616 if [[ $fstype != "ext2" ]]; then
617 remount noload data=journal norecovery
618 mnt_then_not_remount data=journal data=ordered
619 mnt_then_not_remount data=journal data=writeback
620 mnt_then_not_remount data=ordered data=journal
621 mnt_then_not_remount data=ordered data=writeback
622 mnt_then_not_remount data=writeback data=journal
623 mnt_then_not_remount data=writeback data=ordered
626 do_mkfs -O journal_dev $LOOP_LOGDEV ${LOGSIZE}k
627 do_mkfs -J device=$LOOP_LOGDEV $SCRATCH_DEV ${SIZE}k
629 mnt journal_path=$LOOP_LOGDEV ignored
630 mnt journal_dev=$LOGDEV_DEVNUM ignored
631 not_mnt journal_path=${LOOP_LOGDEV}_nonexistent
632 not_mnt journal_dev=123456
633 not_mnt journal_dev=999999999999999
635 do_mkfs -E quotatype=prjquota $SCRATCH_DEV ${SIZE}k
638 # test clearing/changing journalled quota when enabled
639 echo "== Testing active journalled quota" >> $seqres.full
640 mnt_only prjquota,grpjquota=aquota.group,usrjquota=aquota.user,jqfmt=vfsv0
642 # Prepare and enable quota
643 quotacheck -vugm $SCRATCH_MNT >> $seqres.full 2>&1
644 quotaon -vug $SCRATCH_MNT >> $seqres.full 2>&1
646 not_remount grpjquota=
647 not_remount usrjquota=aaquota.user
648 not_remount grpjquota=aaquota.group
649 not_remount jqfmt=vfsv1
651 mnt_only remount,usrquota,grpquota ^usrquota,^grpquota
652 $UMOUNT_PROG $SCRATCH_MNT > /dev/null 2>&1
654 # test clearing/changing quota when enabled
655 do_mkfs -E quotatype=^prjquota $SCRATCH_DEV ${SIZE}k
657 echo "== Testing active non-journalled quota" >> $seqres.full
658 mnt_only grpquota,usrquota
660 # Prepare and enable quota
661 quotacheck -vugm $SCRATCH_MNT >> $seqres.full 2>&1
662 quotaon -vug $SCRATCH_MNT >> $seqres.full 2>&1
665 not_remount usrjquota=aquota.user
666 not_remount grpjquota=aquota.group
667 not_remount jqfmt=vfsv1
668 mnt_only remount,grpjquota= grpquota,^grpjquota
669 mnt_only remount,usrjquota= usrquota,^usrjquota
670 mnt_only remount,usrquota,grpquota usrquota,grpquota
671 quotaoff -f $SCRATCH_MNT >> $seqres.full 2>&1
672 mnt_only remount,noquota ^usrquota,^grpquota,quota
673 $UMOUNT_PROG $SCRATCH_MNT > /dev/null 2>&1
676 echo "== Testing quota feature " >> $seqres.full
677 do_mkfs -O quota -E quotatype=prjquota $SCRATCH_DEV ${SIZE}k
678 mnt usrjquota=aquota.user,jqfmt=vfsv0 ^usrjquota=
679 mnt grpjquota=aquota.user,jqfmt=vfsv0 ^grpjquota=
680 mnt jqfmt=vfsv1 ^jqfmt=
684 mnt_then_not_remount defaults usrjquota=aquota.user
685 mnt_then_not_remount defaults grpjquota=aquota.user
686 mnt_then_not_remount defaults jqfmt=vfsv1
687 remount defaults grpjquota=,usrjquota= ignored
689 done #for fstype in ext2 ext3 ext4; do
691 $UMOUNT_PROG $SCRATCH_MNT > /dev/null 2>&1
692 echo "$ERR errors encountered" >> $seqres.full