2013-03-13 19:01:58 +00:00
|
|
|
# Filters for btrfs command output
|
|
|
|
|
|
2013-04-21 22:51:54 +00:00
|
|
|
. ./common/filter
|
2013-03-13 19:01:58 +00:00
|
|
|
|
|
|
|
|
# Some, but not all, commands emit "Btrfs <version>"
|
|
|
|
|
_filter_btrfs_version()
|
|
|
|
|
{
|
2015-04-01 11:33:17 +11:00
|
|
|
sed -e "s/^[Bb]trfs.*//g"
|
2013-03-13 19:01:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
_filter_devid()
|
|
|
|
|
{
|
2013-08-23 13:07:13 +00:00
|
|
|
sed -e "s/\(devid\)\s\+[0-9]\+/\1 <DEVID>/g"
|
2013-03-13 19:01:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
# If passed a number as first arg, filter that number of devices
|
|
|
|
|
# If passed a UUID as second arg, filter that exact UUID
|
|
|
|
|
_filter_btrfs_filesystem_show()
|
|
|
|
|
{
|
|
|
|
|
if [ ! -z $1 ]; then
|
|
|
|
|
NUMDEVS=$1
|
|
|
|
|
NUM_SUBST="<EXACTNUM>"
|
|
|
|
|
else
|
|
|
|
|
NUMDEVS="[0-9]\+"
|
|
|
|
|
NUM_SUBST="<NUM>"
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
UUID=""
|
|
|
|
|
if [ ! -z $2 ]; then
|
|
|
|
|
UUID=$2
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
# the uniq collapses all device lines into 1
|
|
|
|
|
_filter_uuid $UUID | _filter_scratch | _filter_scratch_pool | \
|
|
|
|
|
_filter_size | _filter_btrfs_version | _filter_devid | \
|
2014-01-20 13:28:38 +11:00
|
|
|
_filter_zero_size | \
|
2013-03-13 19:01:58 +00:00
|
|
|
sed -e "s/\(Total devices\) $NUMDEVS/\1 $NUM_SUBST/g" | \
|
|
|
|
|
uniq
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
# This eliminates all numbers, and shows only unique lines,
|
|
|
|
|
# to accomodate a varying nr. of devices.
|
|
|
|
|
# If given an argument, make sure we saw that many devices
|
|
|
|
|
# in total.
|
|
|
|
|
_filter_btrfs_device_stats()
|
|
|
|
|
{
|
|
|
|
|
if [ ! -z $1 ]; then
|
|
|
|
|
NUMDEVS=$1
|
|
|
|
|
UNIQ_OPT="-c"
|
|
|
|
|
else
|
|
|
|
|
NUMDEVS="thiswillnotmatch"
|
|
|
|
|
UNIQ_OPT=""
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
_filter_scratch | _filter_scratch_pool | \
|
|
|
|
|
sed -e "s/[0-9]\+$/<NUM>/g" | sort | uniq $UNIQ_OPT | \
|
2013-08-23 13:07:13 +00:00
|
|
|
sed -e "s/ *$NUMDEVS /<NUMDEVS> /g"
|
2013-03-13 19:01:58 +00:00
|
|
|
}
|
|
|
|
|
|
2015-04-01 11:34:45 +11:00
|
|
|
_filter_transaction_commit() {
|
|
|
|
|
sed -e "/Transaction commit: none (default)/d" | \
|
|
|
|
|
sed -e "s/Delete subvolume (.*commit):/Delete subvolume/g"
|
2014-01-20 13:28:38 +11:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
_filter_btrfs_subvol_delete()
|
|
|
|
|
{
|
2015-04-01 11:34:45 +11:00
|
|
|
_filter_scratch | _filter_transaction_commit
|
2016-03-23 17:39:11 +11:00
|
|
|
}
|
2014-01-20 13:28:38 +11:00
|
|
|
|
2016-03-23 17:39:11 +11:00
|
|
|
_filter_btrfs_compress_property()
|
|
|
|
|
{
|
2017-11-08 13:27:00 +09:00
|
|
|
sed -e "s/compression=\(lzo\|zlib\|zstd\)/COMPRESSION=XXX/g"
|
2014-01-20 13:28:38 +11:00
|
|
|
}
|
|
|
|
|
|
2016-06-27 16:14:11 -04:00
|
|
|
# filter error messages from btrfs prop, optionally verify against $1
|
2016-03-23 14:35:14 +11:00
|
|
|
# recognized message(s):
|
|
|
|
|
# "object is not compatible with property: label"
|
2016-06-27 16:14:11 -04:00
|
|
|
# "invalid value for property:{, value}"
|
|
|
|
|
# "failed to {get,set} compression for $PATH[.:]: Invalid argument"
|
2016-03-23 14:35:14 +11:00
|
|
|
_filter_btrfs_prop_error()
|
|
|
|
|
{
|
|
|
|
|
if ! [ -z "$1" ]; then
|
2016-06-27 16:14:11 -04:00
|
|
|
sed -e "s#\(compatible with property\): $1#\1#" \
|
|
|
|
|
-e "s#^\(.*failed to [sg]et compression for $1\)[:.] \(.*\)#\1: \2#"
|
2016-03-23 14:35:14 +11:00
|
|
|
else
|
2016-06-27 16:14:11 -04:00
|
|
|
sed -e "s#^\(.*compatible with property\).*#\1#" \
|
|
|
|
|
-e "s#^\(.*invalid value for property\)[:.].*#\1#"
|
2016-03-23 14:35:14 +11:00
|
|
|
fi
|
|
|
|
|
}
|
|
|
|
|
|
2018-08-13 13:22:05 +08:00
|
|
|
# filter warning messages caused by "btrfs quota assign/remove" command.
|
|
|
|
|
# Since qgroup relationship change could cause qgroup inconsistency, it would
|
|
|
|
|
# either trigger a qgroup rescan, or warning message.
|
|
|
|
|
_filter_btrfs_qgroup_assign_warnings()
|
|
|
|
|
{
|
|
|
|
|
sed -e "/Quota data changed, rescan scheduled/d" \
|
|
|
|
|
-e "/quotas may be inconsistent, rescan needed/d"
|
|
|
|
|
}
|
|
|
|
|
|
2018-11-05 11:15:24 +00:00
|
|
|
# Long ago we found that attempting to clone inline extents resulted in hitting
|
|
|
|
|
# a BUG_ON() and then decided to not support such use cases by returning errno
|
|
|
|
|
# -EOPNOTSUPP to user space. Later on, clone/reflink became a VFS API too, since
|
|
|
|
|
# other filesystems (such as XFS) implemented this feature. After that we found
|
|
|
|
|
# one scenario of data corruption due to allowing cloning an EOF block into the
|
|
|
|
|
# middle of a file, and started to reject such scenario by returning the errno
|
|
|
|
|
# -EINVAL to user space (this affected both Btrfs and XFS). Such scenario often
|
|
|
|
|
# overlaps the detection of attempts to clone inline extents, since it is done
|
|
|
|
|
# early on based only on the arguments passed to the clone system call (and
|
|
|
|
|
# btrfs' specific ioctl) before processing the source file extents.
|
|
|
|
|
# So replace error messages related to errno -EOPNOTSUPP to be the same as the
|
|
|
|
|
# one we get from a -EINVAL errno.
|
|
|
|
|
_filter_btrfs_cloner_error()
|
|
|
|
|
{
|
|
|
|
|
sed -e "s/\(clone failed:\) Operation not supported/\1 Invalid argument/g"
|
|
|
|
|
}
|
|
|
|
|
|
2013-03-13 19:01:58 +00:00
|
|
|
# make sure this script returns success
|
|
|
|
|
/bin/true
|