49700386d0
- Document and adjust balance thresholds and periods (FATE#325529 jsc#SLE-3188). * README: document impact of balance + quota groups * sysconfig: reduce default balance usage thresholds * sysconfig: document using systemd.time(7) for frequency of operations * btrfsmaintenance-refresh-cron.sh: validate periods for cron-based systems - Remove python dependency (FATE#326736 jsc#SLE-4130). * btrfs-defrag-plugin: remove dependency on zypp-plugin-python - Added patches: * 0001-README-document-impact-of-balance-quota-groups.patch * 0002-sysconfig-reduce-default-balance-usage-thresholds-fa.patch * 0003-sysconfig-document-using-systemd.time-7-for-frequenc.patch * 0004-btrfsmaintenance-refresh-cron.sh-validate-periods-fo.patch * 0005-btrfs-defrag-plugin-remove-dependency-on-zypp-plugin.patch - Added source: * btrfs-defrag-plugin.sh - Removed patch: * python3-support-bsc1070322.diff OBS-URL: https://build.opensuse.org/request/show/684484 OBS-URL: https://build.opensuse.org/package/show/filesystems/btrfsmaintenance?expand=0&rev=44
152 lines
3.7 KiB
Bash
152 lines
3.7 KiB
Bash
#!/bin/bash
|
||
#
|
||
# This plugin defragments rpm files after update.
|
||
#
|
||
# If the filesystem is btrfs, run defrag command in /var/lib/rpm, set the
|
||
# desired extent size to 32MiB, but this may change in the result depending
|
||
# on the fragmentation of the free space
|
||
#
|
||
## Why 32MiB:
|
||
# - the worst fragmentation has been observed on /var/lib/rpm/Packages
|
||
# - this can grow up to several hundred of megabytes
|
||
# - the file gets updated at random places
|
||
# - although the file will be composed of many extents, it's faster to
|
||
# merge only the extents that affect some portions of the file, instead
|
||
# of the whole file; the difference is negligible
|
||
# - due to the free space fragmentation over time, it's hard to find
|
||
# contiguous space, the bigger the extent is, the worse and the extent
|
||
# size hint is not reached anyway
|
||
|
||
DEBUG="false"
|
||
EXTENT_SIZE="32M"
|
||
|
||
RPMDIR=$(rpm --eval "%_dbpath")
|
||
SCRIPTNAME="$(basename "$0")"
|
||
|
||
cleanup() {
|
||
test -n "$tmpdir" -a -d "$tmpdir" && execute rm -rf "$tmpdir"
|
||
}
|
||
|
||
trap cleanup EXIT
|
||
|
||
tmpdir=$(mktemp -d /tmp/btrfs-defrag-plugin.XXXXXX)
|
||
|
||
log() {
|
||
logger -p info -t $SCRIPTNAME --id=$$ "$@"
|
||
}
|
||
|
||
debug() {
|
||
$DEBUG && log "$@"
|
||
}
|
||
|
||
respond() {
|
||
debug "<< [$1]"
|
||
echo -ne "$1\n\n\x00"
|
||
}
|
||
|
||
execute() {
|
||
debug -- "Executing: $@"
|
||
|
||
$@ 2> $tmpdir/cmd-output
|
||
ret=$?
|
||
|
||
if $DEBUG; then
|
||
if test $ret -ne 0; then
|
||
log -- "Command failed, output follows:"
|
||
log -f $tmpdir/cmd-output
|
||
log -- "End output"
|
||
else
|
||
log -- "Command succeeded"
|
||
fi
|
||
fi
|
||
return $ret
|
||
}
|
||
|
||
btrfs_defrag() {
|
||
# defrag options:
|
||
# - verbose
|
||
# - recursive
|
||
# - flush each file before going to the next one
|
||
# - set the extent target hint
|
||
execute btrfs filesystem defragment -v -f -r -t "$EXTENT_SIZE" "$RPMDIR"
|
||
}
|
||
|
||
debug_fragmentation() {
|
||
if $DEBUG; then
|
||
log -- "Fragmentation $1"
|
||
execute filefrag $RPMDIR/* > $tmpdir/filefrag-output
|
||
if test $? -eq 0; then
|
||
log -f $tmpdir/filefrag-output
|
||
log -- "End output"
|
||
else
|
||
log "Non-fatal error ignored."
|
||
fi
|
||
fi
|
||
}
|
||
|
||
ret=0
|
||
|
||
# The frames are terminated with NUL. Use that as the delimeter and get
|
||
# the whole frame in one go.
|
||
while read -d ' |