summaryrefslogtreecommitdiff
path: root/common/filter.btrfs
blob: ea047c55ea2e683b47515e4f52c2648f6ddf8779 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# Filters for btrfs command output

. ./common/filter

# Some, but not all, commands emit "Btrfs <version>"
_filter_btrfs_version()
{
	sed -e "s/^[Bb]trfs.*//g"
}

_filter_devid()
{
	sed -e "s/\(devid\)\s\+[0-9]\+/\1 <DEVID>/g"
}

# 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 | \
	_filter_zero_size | \
	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 | \
	sed -e "s/ *$NUMDEVS /<NUMDEVS> /g"
}

_filter_transcation_commit_default() {
	sed -e "/Transaction commit: none (default)/d"
}

_filter_btrfs_subvol_delete()
{
	_filter_scratch | _filter_transcation_commit_default

}

# make sure this script returns success
/bin/true