forked from kdave/btrfsmaintenance
-
Notifications
You must be signed in to change notification settings - Fork 0
/
btrfs-balance.sh
executable file
·78 lines (69 loc) · 1.94 KB
/
btrfs-balance.sh
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
72
73
74
75
76
77
78
#!/bin/sh
#
# Copyright (c) 2014 SuSE Linux AG, Nuernberg, Germany.
#
# please send bugfixes or comments to http://www.suse.de/feedback.
#
# paranoia settings
#
umask 022
PATH=/sbin:/bin:/usr/sbin:/usr/bin
export PATH
if [ -f /etc/sysconfig/btrfsmaintenance ] ; then
. /etc/sysconfig/btrfsmaintenance
fi
if [ -f /etc/default/btrfsmaintenance ] ; then
. /etc/default/btrfsmaintenance
fi
LOGIDENTIFIER='btrfs-balance'
. $(dirname $(realpath $0))/btrfsmaintenance-functions
{
evaluate_auto_mountpoint BTRFS_BALANCE_MOUNTPOINTS
OIFS="$IFS"
IFS=:
exec 2>&1 # redirect stderr to stdout to catch all output to log destination
for MM in $BTRFS_BALANCE_MOUNTPOINTS; do
IFS="$OIFS"
if [ $(stat -f --format=%T "$MM") != "btrfs" ]; then
echo "Path $MM is not btrfs, skipping"
continue
fi
echo "Before balance of $MM"
btrfs filesystem df "$MM"
df -H "$MM"
if detect_mixed_bg "$MM"; then
btrfs balance start -musage=0 -dusage=0 "$MM"
# we use the MUSAGE values for both, supposedly less aggressive
# values, but as the data and metadata space is shared on
# mixed-bg this does not lead to the situations we want to
# prevent when the blockgroups are split (ie. underused
# blockgroups)
for BB in $BTRFS_BALANCE_MUSAGE; do
# quick round to clean up the unused block groups
btrfs balance start -v -musage=$BB -dusage=$BB "$MM"
done
else
btrfs balance start -dusage=0 "$MM"
for BB in $BTRFS_BALANCE_DUSAGE; do
# quick round to clean up the unused block groups
btrfs balance start -v -dusage=$BB "$MM"
done
btrfs balance start -musage=0 "$MM"
for BB in $BTRFS_BALANCE_MUSAGE; do
# quick round to clean up the unused block groups
btrfs balance start -v -musage="$BB" "$MM"
done
fi
echo "After balance of $MM"
btrfs filesystem df "$MM"
df -H "$MM"
done
} | \
case "$BTRFS_LOG_OUTPUT" in
stdout) cat;;
journal) systemd-cat -t "$LOGIDENTIFIER";;
syslog) logger -t "$LOGIDENTIFIER";;
none) cat >/dev/null;;
*) cat;;
esac
exit 0