common: filter aiodio dmesg after fs/iomap.c to fs/iomap/ move
[xfstests-dev.git] / common / filter
index 441ee1a6e490d708076db3e24f5f3eda417e2889..26fc21322d1cac349acfc2ffc40c4c8c7e0bf589 100644 (file)
@@ -1,23 +1,8 @@
 ##/bin/bash
-#
+# SPDX-License-Identifier: GPL-2.0
 # Copyright (c) 2000-2001 Silicon Graphics, Inc.  All Rights Reserved.
 #
-# This program is free software; you can redistribute it and/or
-# modify it under the terms of the GNU General Public License as
-# published by the Free Software Foundation.
-#
-# This program is distributed in the hope that it would be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-# GNU General Public License for more details.
-#
-# You should have received a copy of the GNU General Public License
-# along with this program; if not, write the Free Software Foundation,
-# Inc.,  51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
-#
-#
 # standard filters
-#
 
 # Checks that given_value is in range of correct_value +/- tolerance.
 # Tolerance can be an absolute value or a percentage of the correct value
@@ -226,6 +211,15 @@ _filter_xfs_io()
     sed -e "s/[0-9/.]* [GMKiBbytes]*, [0-9]* ops\; [0-9/:. sec]* ([infa0-9/.]* [EPGMKiBbytes]*\/sec and [infa0-9/.]* ops\/sec)/XXX Bytes, X ops\; XX:XX:XX.X (XXX YYY\/sec and XXX ops\/sec)/"
 }
 
+# Also filter out the offset part of xfs_io output
+# Some test cases may be affected by underlaying extent/chunk layout change,
+# so wipe out this part to avoid golden output difference
+_filter_xfs_io_offset()
+{
+    # filter out " at offset XXX" and offset of "pread -v"
+    _filter_xfs_io | sed -e "s/ at offset [0-9]*$//" -e "s/^[0-9a-f]\+:/XXXXXXXX:/"
+}
+
 # stderr filter for xfs_io to handle change of error output format (e.g.
 # pwrite64 -> pwrite).
 _filter_xfs_io_error()
@@ -277,6 +271,10 @@ _filter_xfs_io_pages_modified()
        _filter_xfs_io_units_modified "Page" $PAGE_SIZE
 }
 
+_filter_xfs_io_numbers()
+{
+        _filter_xfs_io | sed -E 's/[0-9]+/XXXX/g'
+}
 
 _filter_test_dir()
 {
@@ -390,11 +388,100 @@ _filter_fstrim()
        egrep -o "[0-9]+ bytes" | $AWK_PROG '{print $1}'
 }
 
-# Older mount output referred to "block device" when mounting RO devices
-# It's gone in newer versions
+# Remove the ending dot appended to mount error message, util-linux 2.30
+# starts to do so.
+_filter_ending_dot()
+{
+       sed -e "s/\.$//"
+}
+
+# Older mount output referred to "block device" when mounting RO devices. It's
+# gone in newer versions. v2.30 changed the output again. This filter is to
+# unify all read-only mount messages across all util-linux versions.
+#
+# for a successful ro mount:
+# ancient:        mount: block device <device> is write-protected, mounting read-only
+# prior to v2.30:  mount: <device> is write-protected, mounting read-only
+# v2.30 and later: mount: <mountpoint>: WARNING: device write-protected, mounted read-only.
+#
+# a failed ro mount:
+# ancient (two-line message):
+# mount: block device <device> is write-protected, mounting read-only
+# mount: cannot mount block device <device> read-only
+# prior to v2.30 (two-line message):
+# mount: <device> is write-protected, mounting read-only
+# mount: cannot mount <device> read-only
+# v2.30 and later (single-line message):
+# mount: <mountpoint>: cannot mount <device> read-only.
+#
+# a failed rw remount:
+# ancient:        mount: cannot remount block device <device> read-write, is write-protected
+# prior to v2.30:  mount: cannot remount <device> read-write, is write-protected
+# v2.30 and later: mount: <mountpoint>: cannot remount <device> read-write, is write-protected.
+#
+# Now use _filter_ro_mount to unify all these differences across old & new
+# util-linux versions. So the filtered format would be:
+#
+# successful ro mount:
+# mount: device write-protected, mounting read-only
+#
+# failed ro mount:
+# mount: device write-protected, mounting read-only
+# mount: cannot mount device read-only
+#
+# failed rw remount:
+# mount: cannot remount device read-write, is write-protected
 _filter_ro_mount() {
-       sed -e "s/mount: block device/mount:/g" \
-           -e "s/mount: cannot mount block device/mount: cannot mount/g"
+       perl -ne '
+       if (/write-protected, mount.*read-only/) {
+               # filter successful ro mount, and first line of prior to v2.30
+               # format failed ro mount
+               print "mount: device write-protected, mounting read-only\n";
+       } elsif (/mount: .*: cannot mount.*read-only/) {
+               # filter v2.30 format failed ro mount, convert single-line
+               # message to two-line message
+               print "mount: device write-protected, mounting read-only\n";
+               print "mount: cannot mount device read-only\n";
+       } elsif (/^mount: cannot mount .* read-only$/) {
+               # filter prior to v2.30 format failed ro mount
+               print "mount: cannot mount device read-only\n";
+       } elsif (/mount:.* cannot remount .* read-write.*/) {
+               # filter failed rw remount
+               print "mount: cannot remount device read-write, is write-protected\n";
+       } else {
+               print "$_";
+       }' | _filter_ending_dot
+}
+
+# Filter a failed mount output due to EUCLEAN and USTALE, util-linux changed
+# the message several times.
+#
+# prior to v2.21:
+# mount: Structure needs cleaning
+# v2.21 to v2.29:
+# mount: mount <device> on <mountpoint> failed: Structure needs cleaning
+# v2.30 and later:
+# mount: <mountpoint>: mount(2) system call failed: Structure needs cleaning.
+#
+# This is also true for ESTALE error. So let's remove all the changing parts
+# and keep the 'prior to v2.21' format:
+# mount: Structure needs cleaning
+# mount: Stale file handle
+_filter_error_mount()
+{
+       sed -e "s/mount:\(.*failed:\)/mount:/" | _filter_ending_dot
+}
+
+# Similar to _filter_error_mount, filter a busy mount output.
+# Turn both old (prior to util-linux v2.30) and new (v2.30 and later) format to
+# a simple one. e.g.
+# old: mount: <device> is already mounted or <mountpoint> busy
+# new: mount: <mountpoint>: <device> already mounted or mount point busy.
+# filtered: mount: device already mounted or mount point busy
+_filter_busy_mount()
+{
+       sed -e "s/.*: .* already mounted or .* busy/mount: device already mounted or mount point busy/" | \
+               _filter_ending_dot
 }
 
 _filter_od()
@@ -417,6 +504,12 @@ _filter_mknod()
        sed -e "s/mknod: [\`']\(.*\)': File exists/mknod: \1: File exists/"
 }
 
+# Remove leading "rename" in "mv -v" output
+_filter_mv()
+{
+       sed -e "s/^renamed //"
+}
+
 _filter_lostfound()
 {
        sed -e '/^lost+found$/d'
@@ -448,10 +541,10 @@ _filter_filefrag()
              $flags, "\n"'
 }
 
-# xfs generates WARNINGs on purpose when applications mix buffered/mmap IO with
+# We generate WARNINGs on purpose when applications mix buffered/mmap IO with
 # direct IO on the same file. This is a helper for _check_dmesg() to filter out
 # such warnings.
-_filter_xfs_dmesg()
+_filter_aiodio_dmesg()
 {
        local warn1="WARNING:.*fs/xfs/xfs_file\.c:.*xfs_file_dio_aio_write.*"
        local warn2="WARNING:.*fs/xfs/xfs_file\.c:.*xfs_file_dio_aio_read.*"
@@ -461,6 +554,8 @@ _filter_xfs_dmesg()
        local warn6="WARNING:.*fs/xfs/xfs_aops\.c:.*__xfs_get_blocks.*"
        local warn7="WARNING:.*fs/iomap\.c:.*iomap_dio_actor.*"
        local warn8="WARNING:.*fs/iomap\.c:.*iomap_dio_complete.*"
+       local warn9="WARNING:.*fs/direct-io\.c:.*dio_complete.*"
+       local warn10="WARNING:.*fs/iomap/direct-io\.c:.*iomap_dio_actor.*"
        sed -e "s#$warn1#Intentional warnings in xfs_file_dio_aio_write#" \
            -e "s#$warn2#Intentional warnings in xfs_file_dio_aio_read#" \
            -e "s#$warn3#Intentional warnings in xfs_file_read_iter#" \
@@ -468,7 +563,20 @@ _filter_xfs_dmesg()
            -e "s#$warn5#Intentional warnings in iomap_dio_rw#" \
            -e "s#$warn6#Intentional warnings in __xfs_get_blocks#" \
            -e "s#$warn7#Intentional warnings in iomap_dio_actor#" \
-           -e "s#$warn8#Intentional warnings in iomap_dio_complete#"
+           -e "s#$warn8#Intentional warnings in iomap_dio_complete#" \
+           -e "s#$warn9#Intentional warnings in dio_complete#" \
+           -e "s#$warn10#Intentional warnings in iomap_dio_actor#"
+}
+
+# We generate assert related WARNINGs on purpose and make sure test doesn't fail
+# because of these warnings. This is a helper for _check_dmesg() to filter out
+# them.
+_filter_assert_dmesg()
+{
+       local warn1="WARNING:.*fs/xfs/xfs_message\.c:.*asswarn.*"
+       local warn2="WARNING:.*fs/xfs/xfs_message\.c:.*assfail.*"
+       sed -e "s#$warn1#Intentional warnings in asswarn#" \
+           -e "s#$warn2#Intentional warnings in assfail#"
 }
 
 # make sure this script returns success