Initialize for btrfsmaintenance

This commit is contained in:
zyppe 2024-02-05 15:42:11 +08:00
commit fd1c5c4d91
11 changed files with 610 additions and 0 deletions

View file

@ -0,0 +1 @@
a696cb16cc1e3167de8d329e98b977f9ff6ad3a4daf6bf2ddd1bec7ed0666504 btrfsmaintenance-0.4.2.tar.bz2

1
.gitignore vendored Normal file
View file

@ -0,0 +1 @@
btrfsmaintenance-0.4.2.tar.bz2

View file

@ -0,0 +1,37 @@
From 3e8ae32c961f0a3a6ba32881e88a49d5cbf656cd Mon Sep 17 00:00:00 2001
From: Jeff Mahoney <jeffm@suse.com>
Date: Fri, 11 Jan 2019 09:57:48 -0500
Subject: README: document impact of balance + quota groups
References: fate#325529 jsc#SLE-3188
The combination of balance and quota groups as the number of references
to extents rises (either via snapshots, dedupe, or reflink copies) can
be extreme.
The file system performs quota group accounting for every extent relocated
and the result can be the appearance of stalled system as the
transaction commit can take a very long time.
Signed-off-by: Jeff Mahoney <jeffm@suse.com>
---
README.md | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/README.md b/README.md
index 07a8104..d59f3d6 100644
--- a/README.md
+++ b/README.md
@@ -66,6 +66,10 @@ the same set of blocks is affected.
The balance command uses filters to do the work in smaller batches.
+The impact with quota groups enabled can be extreme. The balance operation
+performs quota group accounting for every extent being relocated, which can
+have the impact of stalling the file system for an extended period of time.
+
__Expected result:__ If possible all the underused chunks are removed, the
value of `total` in output of `btrfs fi df /path` should be lower than before.
Check the logs.
--
2.16.4

View file

@ -0,0 +1,56 @@
From 194fd3a02f686737ae7d266d72d35a3418a5903b Mon Sep 17 00:00:00 2001
From: Jeff Mahoney <jeffm@suse.com>
Date: Fri, 25 Jan 2019 13:29:20 -0500
Subject: sysconfig: reduce default balance usage thresholds
References: fate#325529 jsc#SLE-3188
In the early days of btrfs, the only way to clean up empty block groups
was to perform a balance operation to coalesce block groups that were
mostly free and release the newly empty block groups.
Since then, btrfs cleans up empty block groups automatically so the need
for regular aggressive balancing has been reduced substantially. Since
workload shifts could still produce ENOSPC issues, we still want to
perform a periodic balance but we can do it much less aggressively.
---
sysconfig.btrfsmaintenance | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/sysconfig.btrfsmaintenance b/sysconfig.btrfsmaintenance
index 4088254..5a34c83 100644
--- a/sysconfig.btrfsmaintenance
+++ b/sysconfig.btrfsmaintenance
@@ -52,18 +52,18 @@ BTRFS_BALANCE_PERIOD="weekly"
## Path: System/File systems/btrfs
## Type: string
-## Default: "1 5 10 20 30 40 50"
+## Default: "5 10"
#
# The usage percent for balancing data block groups.
#
# Note: default values should not disturb normal work but may not reclaim
# enough block groups. If you observe that, add higher values but beware that
# this will increase IO load on the system.
-BTRFS_BALANCE_DUSAGE="1 5 10 20 30 40 50"
+BTRFS_BALANCE_DUSAGE="5 10"
## Path: System/File systems/btrfs
## Type: string
-## Default: "1 5 10 20 30"
+## Default: "3"
#
# The usage percent for balancing metadata block groups. The values are also
# used in case the filesystem has mixed blockgroups.
@@ -71,7 +71,7 @@ BTRFS_BALANCE_DUSAGE="1 5 10 20 30 40 50"
# Note: default values should not disturb normal work but may not reclaim
# enough block groups. If you observe that, add higher values but beware that
# this will increase IO load on the system.
-BTRFS_BALANCE_MUSAGE="1 5 10 20 30"
+BTRFS_BALANCE_MUSAGE="3"
## Path: System/File systems/btrfs
## Type: string
--
2.16.4

View file

@ -0,0 +1,53 @@
From 0302324b7a824741a39e3928dc7a8617485e03ce Mon Sep 17 00:00:00 2001
From: Jeff Mahoney <jeffm@suse.com>
Date: Fri, 25 Jan 2019 13:35:54 -0500
Subject: sysconfig: document using systemd.time(7) for frequency of operations
References: fate#325529 jsc#SLE-3188
On systems using systemd timers, the calendar event format documented in
systemd.time(7) may be used to specify when to run balance, defrag,
scrub, or trim events. This commit documents that validity.
---
sysconfig.btrfsmaintenance | 12 ++++++++++++
1 file changed, 12 insertions(+)
diff --git a/sysconfig.btrfsmaintenance b/sysconfig.btrfsmaintenance
index 5a34c83..b35e2cf 100644
--- a/sysconfig.btrfsmaintenance
+++ b/sysconfig.btrfsmaintenance
@@ -48,6 +48,10 @@ BTRFS_BALANCE_MOUNTPOINTS="/"
## ServiceRestart: btrfsmaintenance-refresh
#
# Frequency of periodic balance.
+#
+# The frequency may be specified using one of the listed values or
+# in the format documented in the "Calendar Events" section of systemd.time(7),
+# if available.
BTRFS_BALANCE_PERIOD="weekly"
## Path: System/File systems/btrfs
@@ -89,6 +93,10 @@ BTRFS_SCRUB_MOUNTPOINTS="/"
## ServiceRestart: btrfsmaintenance-refresh
#
# Frequency of periodic scrub.
+#
+# The frequency may be specified using one of the listed values or
+# in the format documented in the "Calendar Events" section of systemd.time(7),
+# if available.
BTRFS_SCRUB_PERIOD="monthly"
## Path: System/File systems/btrfs
@@ -115,6 +123,10 @@ BTRFS_SCRUB_READ_ONLY="false"
# Frequency of periodic trim. Off by default so it does not collide with
# fstrim.timer . If you do not use the timer, turn it on here. The recommended
# period is 'weekly'.
+#
+# The frequency may be specified using one of the listed values or
+# in the format documented in the "Calendar Events" section of systemd.time(7),
+# if available.
BTRFS_TRIM_PERIOD="none"
## Path: System/File systems/btrfs
--
2.16.4

View file

@ -0,0 +1,39 @@
From 7851de9a30610885f7fc2f8238128f1c4f2d3593 Mon Sep 17 00:00:00 2001
From: Jeff Mahoney <jeffm@suse.com>
Date: Fri, 25 Jan 2019 14:08:13 -0500
Subject: btrfsmaintenance-refresh-cron.sh: validate periods for cron-based systems
References: fate#325529 jsc#SLE-3188
Now that we accept systemd.time(7) calendar events, ensure that we don't
try to use them on cron-based systems. Instead of removing all existing
jobs silently, refuse to change the period and print an error.
---
btrfsmaintenance-refresh-cron.sh | 12 ++++++++++++
1 file changed, 12 insertions(+)
diff --git a/btrfsmaintenance-refresh-cron.sh b/btrfsmaintenance-refresh-cron.sh
index 2bf5f8e..10db054 100755
--- a/btrfsmaintenance-refresh-cron.sh
+++ b/btrfsmaintenance-refresh-cron.sh
@@ -35,6 +35,18 @@ refresh_cron() {
SCRIPT="$2"
echo "Refresh script $SCRIPT for $EXPECTED"
+ valid=false
+ for PERIOD in daily weekly monthly none uninstall; do
+ if [ "$PERIOD" = "$EXPECTED" ]; then
+ valid=true
+ fi
+ done
+
+ if ! $valid; then
+ echo "$EXPECTED is not a valid period for cron. Not changing."
+ return
+ fi
+
for PERIOD in daily weekly monthly; do
# NOTE: debian does not allow filenames with dots in /etc/cron.*
LINK="${SCRIPT%.*}"
--
2.16.4

View file

@ -0,0 +1,131 @@
From a1fdf5f2502ead429fe6ea6b44a63ad35aae7242 Mon Sep 17 00:00:00 2001
From: Jeff Mahoney <jeffm@suse.com>
Date: Tue, 12 Mar 2019 16:22:08 -0400
Subject: btrfs-defrag-plugin: remove dependency on zypp-plugin-python
References: FATE#326736 jsc#SLE-4130
Notes: The script is included separately since rpm can't use git binary diffs
Requiring zypp-plugin-python means that we need to pull in 150 MB of
python dependencies. It's present already on many systems but on
JeOS systems, it won't be by default. We still want to defrag
the RPM database on those systems.
This commit replaces the python script with a shell script that provides
the same functionality and drops the python dependency entirely.
Signed-off-by: Jeff Mahoney <jeffm@suse.com>
---
README.md | 4 +-
btrfs-defrag-plugin.py | 81 -------------------------------------------------
2 files changed, 2 insertions(+), 83 deletions(-)
diff --git a/README.md b/README.md
index d59f3d6..2202ebf 100644
--- a/README.md
+++ b/README.md
@@ -188,7 +188,7 @@ do manual installation of files as described below.
* `sysconfig.btrfsmaintenance` configuration template is put to:
* `/etc/sysconfig/btrfsmaintenance` on SUSE and RedHat based systems or derivatives
* `/etc/default/btrfsmaintenance` on Debian and derivatives
-* `/usr/lib/zypp/plugins/commit/btrfs-defrag-plugin.py` post-update script for
+* `/usr/lib/zypp/plugins/commit/btrfs-defrag-plugin.sh` post-update script for
zypper (the package manager), applies to SUSE-based distros for now
* cron refresh scripts are installed (see bellow)
@@ -212,7 +212,7 @@ configuration file in `/etc/sysconfig/btrfsmaintenance` by installing the
The package database files tend to be updated in a random way and get
fragmented, which particularly hurts on btrfs. For rpm-based distros this means files
in `/var/lib/rpm`. The script or plugin simpy runs a defragmentation on the affected files.
-See `btrfs-defrag-plugin.py` for more details.
+See `btrfs-defrag-plugin.sh` for more details.
At the moment the 'zypper' package manager plugin exists. As the package
managers differ significantly, there's no single plugin/script to do that.
diff --git a/btrfs-defrag-plugin.py b/btrfs-defrag-plugin.py
deleted file mode 100644
index dab9556..0000000
--- a/btrfs-defrag-plugin.py
+++ /dev/null
@@ -1,81 +0,0 @@
-#!/usr/bin/python
-
-# This plugin defragments rpm files after update.
-#
-# If the filesystem is btrfs, run defrag command in the RPM database
-# folder, 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 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
-
-import sys
-if sys.version_info[0] >= 3:
- from builtins import str
- popen_kwargs = { 'encoding': 'ascii' }
-else:
- popen_kwargs = { }
-from zypp_plugin import Plugin
-import subprocess
-
-DEBUG=False
-EXTENT_SIZE=32*1024*1024
-LOGFILE='/tmp/btrfs-defrag-plugin.log'
-PATH=subprocess.check_output(["rpm", "--eval", "%_dbpath"], **popen_kwargs).strip()
-
-def dbg(args):
- if not DEBUG: return
- f=open(LOGFILE, "a+")
- f.write(args)
- f.write("\n")
- f.close()
-
-def qx(args):
- out=subprocess.Popen(args, shell=True, stdout=subprocess.PIPE, **popen_kwargs).stdout
- outstr="".join(out.readlines())
- out.close()
- return outstr
-
-def fstype(path):
- ret=qx('stat -f --format=%T "'+path+'"')
- return ret.rstrip()
-
-class BtrfsDefragPlugin(Plugin):
- def PLUGINBEGIN(self, headers, body):
- self.actions = []
- self.commit_hook_supported = False
- dbg('--- Btrfs defrag plugin begin')
- self.ack()
-
- def PLUGINEND(self, headers, body):
- dbg('--- Btrfs defrag plugin end: %s %s\n' % (str(headers), str(body)))
- dbg('--- fstype(%s) = |%s|' % (PATH, fstype(PATH)))
- if fstype(PATH) != 'btrfs':
- self.ack()
- return
- if DEBUG:
- dbg('--- Fragmentation before')
- dbg(qx('filefrag %s/*' % (PATH)))
- # defrag options:
- # - verbose
- # - recursive
- # - flush each file before going to the next one
- # - set the extent target hint
- ret = qx('btrfs filesystem defragment -v -f -r -t %s "%s"' % \
- (str(EXTENT_SIZE), PATH))
- if DEBUG:
- dbg(ret)
- dbg('--- Fragmentation after')
- dbg(qx('filefrag %s/*' % (PATH)))
- self.ack()
-
-plugin = BtrfsDefragPlugin()
-plugin.main()

BIN
btrfs-defrag-plugin.sh Normal file

Binary file not shown.

142
btrfsmaintenance.changes Normal file
View file

@ -0,0 +1,142 @@
* Fri Nov 20 2020 rgoldwyn@suse.com
- btrfsmaintenance.service-delete-install-section.patch: Remove [Install]
section (bsc#1178874)
* Tue Mar 12 2019 jeffm@suse.com
- 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
* Mon Sep 24 2018 dsterba@suse.cz
- update to version 0.4.2
- CVE-2018-14722: expand auto mountpoints in a safe way
- btrfs-defrag: fix missing function to detect btrfs filesystems (#52)
- btrfs-trim: more verbose fstrim output (#60)
- dist-install: print information about timer unit installation (#58)
* Fri Apr 13 2018 lpechacek@suse.com
- In openSUSE the defrag plugin must explicitly refer to Python 3.
(bsc#1070322)
- Added patch: python3-support-bsc1070322.diff
* Wed Mar 14 2018 dsterba@suse.cz
- update to version 0.4.1
- defrag plugin: python2 and 3 compatibility
- defrag plugin: target extent size lowered to 32MiB (#43)
- shell compatibility fixes
- systemd unit type fixes
- Removed patch: python3-support-bsc1070322.diff (upstream)
* Mon Mar 12 2018 kukuk@suse.de
- Add missing btrfsmaintenance-refresh.path [bsc#1084871]
- Use %%license [bsc#1082318]
* Mon Feb 5 2018 lpechacek@suse.com
- Move the defrag plugin over to Python 3. (bsc#1070322)
- Added patch: python3-support-bsc1070322.diff
* Sun Jan 14 2018 dsterba@suse.cz
- update to version 0.4
- add support for systemd timers and use them by default; the alternative
cron scripts are still present (#29, #36)
- add automatic monitoring (via systemd.path) of the config file,
no manual updates by btrfsmaintenance-refresh.service needed (#38)
- fix RPM database path detection
- spec file cleanups
- documentation updates
- removed patches:
- btrfsmaintenance-0.3.1-fix-rpm-db-path.patch (upstream)
- btrfsmaintenance-switch-to-timer.patch (upstream)
- pull-request-36.patch (upstream)
* Fri Dec 22 2017 antoine.belvire@opensuse.org
- Fix systemd timers enabled even if period is set to none:
* Micro change in pull-request-36.patch (bsc#1075884)
- Clean spec file:
* Removed support for suse_version <= 1210.
* Removed call to btrfsmaintenance-refresh-cron.sh upon deletion
(not needed anymore since we use systemd timers which are
handled by macros).
* Ran spec-cleaner.
* Sun Dec 17 2017 kukuk@suse.de
- Switch default of btrfsmaintenance-refresh.service to systemd-timer,
too (btrfsmaintenance-switch-to-timer.patch) [bsc#1073204]
* Wed Dec 6 2017 kukuk@suse.de
- pull-request-36.patch: update patch
* Wed Dec 6 2017 kukuk@suse.de
- Don't call btrfsmaintenance-refresh-cron.sh in %%post, this is
done already by the systemd macros
* Tue Dec 5 2017 kukuk@suse.com
- Add patch to use systemd timer instead of cron (pull-request-36.patch)
* Thu Nov 23 2017 rbrown@suse.com
- Replace references to /var/adm/fillup-templates with new
%%_fillupdir macro (boo#1069468)
* Fri Nov 10 2017 antoine.belvire@opensuse.org
- Fix cron symlinks removal upon package upgrade (boo#904518):
* The problem was in the preun section (in the old RPM).
* This means the symlinks are removed by this update, but won't
be by the next ones.
* Please run 'systemctl start btrfsmaintenance-refresh' one more
time to fix your symlinks.
* Tue Nov 7 2017 antoine.belvire@opensuse.org
- Add btrfsmaintenance-0.3.1-fix-rpm-db-path.patch:
* Change RPM database path to /usr/lib/sysimage/rpm for
Tumbleweed.
* Wed Jul 5 2017 lnussel@suse.de
- Require btrfsprogs (bsc#1047226)
* Thu Apr 6 2017 dsterba@suse.cz
- version 0.3.1
- dist-install: fix installation paths, install functions
- functions: fix syntax to be compatible with dash
- spec: install functions file
* Mon Nov 14 2016 dsterba@suse.cz
- version 0.3
- add syslog to logging targets
- add none target (/dev/null)
- autodetect btrfs filesystems for balance, scrub and trim
- detect mixed blockgroups and use correct balance filters
- fix uninstall rules
- fix capturing entire output to the log
- fix when cron files are symlinks
- add generic installation script
- doc updates: retention policy tuning
* Thu Mar 3 2016 dsterba@suse.cz
- version 0.2
- updated documentation
- support debian-like configuration paths
- no hardcoded paths to external utilities
- fixed logger name typos for 'journal' target
- defrag fixes (sysconfig, find arguments)
* Wed Oct 7 2015 dsterba@suse.cz
- version 0.1.2
- change default config for trim: off
- journal loggin should work (fixed a typo)
* Sun Jul 12 2015 dsterba@suse.com
- version 0.1.1
- fix typo and make journal logging target work
* Tue Nov 18 2014 dsterba@suse.cz
- cron refresh: remove bashism
- cron refresh: remove debugging messages
- post installation must create the cron links (bsc#904518)
- Removed patches:
* btrfsmaintenance-0.1-fix-bashisms.patch
* Sat Nov 15 2014 ledest@gmail.com
- fix bashism in btrfsmaintenance-refresh-cron.sh script
- add patches:
* btrfsmaintenance-0.1-fix-bashisms.patch
* Tue Oct 28 2014 dsterba@suse.cz
- add COPYING, README.md
- add config option to specify log target (stdout, or journal)
* Thu Oct 9 2014 dsterba@suse.cz
- clean spec
- add Url tag
* Thu Oct 9 2014 dsterba@suse.cz
- fix sysconfig file Path: tags
* Wed Sep 24 2014 dsterba@suse.cz
- initial import 0.1

View file

@ -0,0 +1,27 @@
From 32a52adfc28ee2a756abb0c91405917a09b3484d Mon Sep 17 00:00:00 2001
From: karlmistelberger <62176982+karlmistelberger@users.noreply.github.com>
Date: Tue, 21 Apr 2020 12:41:03 +0200
Subject: [PATCH] btrfsmaintenance-refresh.service: delete install section
Install section causes the unit to execute during boot without
/etc/sysconfig/btrfsmaintenance being changed.
Link: https://bugzilla.suse.com/show_bug.cgi?id=1165780#c33
Pull-request: #81
Author: karlmistelberger
Signed-off-by: David Sterba <dsterba@suse.com>
---
btrfsmaintenance-refresh.service | 4 ----
1 file changed, 4 deletions(-)
--- a/btrfsmaintenance-refresh.service
+++ b/btrfsmaintenance-refresh.service
@@ -5,7 +5,3 @@
[Service]
ExecStart=/usr/share/btrfsmaintenance/btrfsmaintenance-refresh-cron.sh systemd-timer
Type=oneshot
-
-[Install]
-Also=btrfsmaintenance-refresh.path
-WantedBy=multi-user.target

123
btrfsmaintenance.spec Normal file
View file

@ -0,0 +1,123 @@
#
# spec file for package btrfsmaintenance
#
# Copyright (c) 2022-2023 ZhuningOS
#
#Compat macro for new _fillupdir macro introduced in Nov 2017
%if ! %{defined _fillupdir}
%define _fillupdir /var/adm/fillup-templates
%endif
Name: btrfsmaintenance
Version: 0.4.2
Release: 3.3.1
Summary: Scripts for btrfs periodic maintenance tasks
License: GPL-2.0-only
Group: System/Base
Url: https://github.com/kdave/btrfsmaintenance
Source0: %{name}-%{version}.tar.bz2
Source1: btrfs-defrag-plugin.sh
Patch1: 0001-README-document-impact-of-balance-quota-groups.patch
Patch2: 0002-sysconfig-reduce-default-balance-usage-thresholds-fa.patch
Patch3: 0003-sysconfig-document-using-systemd.time-7-for-frequenc.patch
Patch4: 0004-btrfsmaintenance-refresh-cron.sh-validate-periods-fo.patch
Patch5: 0005-btrfs-defrag-plugin-remove-dependency-on-zypp-plugin.patch
Patch6: btrfsmaintenance.service-delete-install-section.patch
BuildRequires: systemd
Requires: btrfsprogs
Requires: libzypp(plugin:commit)
Supplements: btrfsprogs
BuildArch: noarch
%{?systemd_requires}
%description
Scripts for btrfs maintenance tasks like periodic scrub, balance, trim or defrag
on selected mountpoints or directories. Hints for periodic snapshot tuning (eg.
for snapper).
%prep
%setup -q
%patch1 -p1
%patch2 -p1
%patch3 -p1
%patch4 -p1
%patch5 -p1
%patch6 -p1
cp %{SOURCE1} .
%build
%install
# scripts
install -m 755 -d %{buildroot}%{_datadir}/%{name}
install -m 755 btrfs-defrag.sh %{buildroot}%{_datadir}/%{name}
install -m 755 btrfs-balance.sh %{buildroot}%{_datadir}/%{name}
install -m 755 btrfs-scrub.sh %{buildroot}%{_datadir}/%{name}
install -m 755 btrfs-trim.sh %{buildroot}%{_datadir}/%{name}
install -m 755 btrfsmaintenance-refresh-cron.sh %{buildroot}%{_datadir}/%{name}
install -m 644 btrfsmaintenance-functions %{buildroot}%{_datadir}/%{name}
# systemd services and timers
install -m 755 -d %{buildroot}%{_unitdir}
install -m 644 -D btrfsmaintenance-refresh.service %{buildroot}%{_unitdir}
install -m 644 -D btrfsmaintenance-refresh.path %{buildroot}%{_unitdir}
install -m 644 -D btrfs-balance.service %{buildroot}%{_unitdir}
install -m 644 -D btrfs-defrag.service %{buildroot}%{_unitdir}
install -m 644 -D btrfs-scrub.service %{buildroot}%{_unitdir}
install -m 644 -D btrfs-trim.service %{buildroot}%{_unitdir}
install -m 644 -D btrfs-balance.timer %{buildroot}%{_unitdir}
install -m 644 -D btrfs-defrag.timer %{buildroot}%{_unitdir}
install -m 644 -D btrfs-scrub.timer %{buildroot}%{_unitdir}
install -m 644 -D btrfs-trim.timer %{buildroot}%{_unitdir}
install -m 755 -d %{buildroot}%{_sbindir}
ln -s %{_sbindir}/service %{buildroot}%{_sbindir}/rcbtrfsmaintenance-refresh
# zypp plugin
install -m 755 -d %{buildroot}%{_libexecdir}/zypp/plugins/commit
install -m 755 -D btrfs-defrag-plugin.sh %{buildroot}%{_libexecdir}/zypp/plugins/commit
# config
install -m 755 -d %{buildroot}%{_fillupdir}
install -m 644 -D sysconfig.btrfsmaintenance %{buildroot}%{_fillupdir}
%pre
# if the new service files don't exist, we migrate from
# old version with old script, remove cron symlinks
[ ! -f %{_unitdir}/btrfs-balance.timer -a -f %{_datadir}/%{name}/btrfsmaintenance-refresh-cron.sh ] && %{_datadir}/%{name}/btrfsmaintenance-refresh-cron.sh uninstall
%service_add_pre btrfsmaintenance-refresh.service btrfsmaintenance-refresh.path btrfs-balance.service btrfs-balance.timer btrfs-defrag.service btrfs-defrag.timer btrfs-scrub.service btrfs-scrub.timer btrfs-trim.service btrfs-trim.timer
%post
%service_add_post btrfsmaintenance-refresh.service btrfsmaintenance-refresh.path btrfs-balance.service btrfs-balance.timer btrfs-defrag.service btrfs-defrag.timer btrfs-scrub.service btrfs-scrub.timer btrfs-trim.service btrfs-trim.timer
%{fillup_only btrfsmaintenance}
%preun
%service_del_preun btrfsmaintenance-refresh.service btrfsmaintenance-refresh.path btrfs-balance.service btrfs-balance.timer btrfs-defrag.service btrfs-defrag.timer btrfs-scrub.service btrfs-scrub.timer btrfs-trim.service btrfs-trim.timer
%postun
%service_del_postun btrfsmaintenance-refresh.service btrfsmaintenance-refresh.path btrfs-balance.service btrfs-balance.timer btrfs-defrag.service btrfs-defrag.timer btrfs-scrub.service btrfs-scrub.timer btrfs-trim.service btrfs-trim.timer
%files
%license COPYING
%doc README.md
%{_fillupdir}/sysconfig.btrfsmaintenance
%dir %{_datadir}/%{name}
%{_datadir}/%{name}/*
%dir %{_libexecdir}/zypp/
%dir %{_libexecdir}/zypp/plugins
%dir %{_libexecdir}/zypp/plugins/commit
%{_libexecdir}/zypp/plugins/commit/btrfs-defrag-plugin.sh
%{_unitdir}/btrfsmaintenance-refresh.path
%{_unitdir}/btrfsmaintenance-refresh.service
%{_unitdir}/btrfs-balance.service
%{_unitdir}/btrfs-defrag.service
%{_unitdir}/btrfs-scrub.service
%{_unitdir}/btrfs-trim.service
%{_unitdir}/btrfs-balance.timer
%{_unitdir}/btrfs-defrag.timer
%{_unitdir}/btrfs-scrub.timer
%{_unitdir}/btrfs-trim.timer
%{_sbindir}/rcbtrfsmaintenance-refresh
%changelog