src/idmapped-mounts: Remove useless header file
[xfstests-dev.git] / common / filter.btrfs
1 # Filters for btrfs command output
2
3 . ./common/filter
4
5 # Some, but not all, commands emit "Btrfs <version>"
6 _filter_btrfs_version()
7 {
8         sed -e "s/^[Bb]trfs.*//g"
9 }
10
11 _filter_devid()
12 {
13         sed -e "s/\(devid\)\s\+[0-9]\+/\1 <DEVID>/g"
14 }
15
16 # If passed a number as first arg, filter that number of devices
17 # If passed a UUID as second arg, filter that exact UUID
18 _filter_btrfs_filesystem_show()
19 {
20         if [ ! -z $1 ]; then
21                 NUMDEVS=$1
22                 NUM_SUBST="<EXACTNUM>"
23         else
24                 NUMDEVS="[0-9]\+"
25                 NUM_SUBST="<NUM>"
26         fi
27
28         UUID=""
29         if [ ! -z $2 ]; then
30                 UUID=$2
31         fi
32
33         # the uniq collapses all device lines into 1
34         _filter_uuid $UUID | _filter_scratch | _filter_scratch_pool | \
35         _filter_size | _filter_btrfs_version | _filter_devid | \
36         _filter_zero_size | \
37         sed -e "s/\(Total devices\) $NUMDEVS/\1 $NUM_SUBST/g" | \
38         uniq
39 }
40
41 # This eliminates all numbers, and shows only unique lines,
42 # to accomodate a varying nr. of devices.
43 # If given an argument, make sure we saw that many devices
44 # in total.
45 _filter_btrfs_device_stats()
46 {
47         if [ ! -z $1 ]; then
48                 NUMDEVS=$1
49                 UNIQ_OPT="-c"
50         else
51                 NUMDEVS="thiswillnotmatch"
52                 UNIQ_OPT=""
53         fi
54
55         _filter_scratch | _filter_scratch_pool | \
56         sed -e "s/[0-9]\+$/<NUM>/g" | sort | uniq $UNIQ_OPT | \
57         sed -e "s/ *$NUMDEVS /<NUMDEVS> /g"
58 }
59
60 _filter_transaction_commit() {
61         sed -e "/Transaction commit: none (default)/d" | \
62         sed -e "s/Delete subvolume (.*commit):/Delete subvolume/g"
63 }
64
65 _filter_btrfs_subvol_delete()
66 {
67         _filter_scratch | _filter_transaction_commit
68 }
69
70 _filter_btrfs_compress_property()
71 {
72         sed -e "s/compression=\(lzo\|zlib\|zstd\)/COMPRESSION=XXX/g"
73 }
74
75 # filter error messages from btrfs prop, optionally verify against $1
76 # recognized message(s):
77 #  "object is not compatible with property: label"
78 #  "invalid value for property:{, value}"
79 #  "failed to {get,set} compression for $PATH[.:]: Invalid argument"
80 _filter_btrfs_prop_error()
81 {
82         if ! [ -z "$1" ]; then
83                 sed -e "s#\(compatible with property\): $1#\1#" \
84                     -e "s#^\(.*failed to [sg]et compression for $1\)[:.] \(.*\)#\1: \2#"
85         else
86                 sed -e "s#^\(.*compatible with property\).*#\1#" \
87                     -e "s#^\(.*invalid value for property\)[:.].*#\1#"
88         fi
89 }
90
91 # filter warning messages caused by "btrfs quota assign/remove" command.
92 # Since qgroup relationship change could cause qgroup inconsistency, it would
93 # either trigger a qgroup rescan, or warning message.
94 _filter_btrfs_qgroup_assign_warnings()
95 {
96         sed -e "/Quota data changed, rescan scheduled/d" \
97             -e "/quotas may be inconsistent, rescan needed/d"
98 }
99
100 # Long ago we found that attempting to clone inline extents resulted in hitting
101 # a BUG_ON() and then decided to not support such use cases by returning errno
102 # -EOPNOTSUPP to user space. Later on, clone/reflink became a VFS API too, since
103 # other filesystems (such as XFS) implemented this feature. After that we found
104 # one scenario of data corruption due to allowing cloning an EOF block into the
105 # middle of a file, and started to reject such scenario by returning the errno
106 # -EINVAL to user space (this affected both Btrfs and XFS). Such scenario often
107 # overlaps the detection of attempts to clone inline extents, since it is done
108 # early on based only on the arguments passed to the clone system call (and
109 # btrfs' specific ioctl) before processing the source file extents.
110 # So replace error messages related to errno -EOPNOTSUPP to be the same as the
111 # one we get from a -EINVAL errno.
112 _filter_btrfs_cloner_error()
113 {
114         sed -e "s/\(clone failed:\) Operation not supported/\1 Invalid argument/g"
115 }
116
117 # make sure this script returns success
118 /bin/true