summaryrefslogtreecommitdiff
path: root/sys-fs/zfs/files/2.1.2-scrub-timers.patch
blob: f1c5b5699f6247bfa72dd6e13d0550ba1102fd2a (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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
From 2c9844d159024d4c742d24639a218213fb53d537 Mon Sep 17 00:00:00 2001
From: Georgy Yakovlev <gyakovlev@gentoo.org>
Date: Sat, 22 May 2021 22:27:39 -0700
Subject: [PATCH 1/2] systemd: add weekly and monthly scrub timers

timers can be enabled as follows:

systemctl enable zfs-scrub-weekly@rpool.timer --now
systemctl enable zfs-scrub-monthly@datapool.timer --now

Each timer will pull in zfs-scrub@${poolname}.service, which is not
schedule-specific.

Signed-off-by: Georgy Yakovlev <gyakovlev@gentoo.org>
---
 etc/systemd/system/.gitignore                  |  1 +
 etc/systemd/system/Makefile.am                 |  5 ++++-
 etc/systemd/system/zfs-scrub-monthly@.timer.in | 12 ++++++++++++
 etc/systemd/system/zfs-scrub-weekly@.timer.in  | 12 ++++++++++++
 etc/systemd/system/zfs-scrub@.service.in       | 14 ++++++++++++++
 5 files changed, 43 insertions(+), 1 deletion(-)
 create mode 100644 etc/systemd/system/zfs-scrub-monthly@.timer.in
 create mode 100644 etc/systemd/system/zfs-scrub-weekly@.timer.in
 create mode 100644 etc/systemd/system/zfs-scrub@.service.in

diff --git a/etc/systemd/system/Makefile.am b/etc/systemd/system/Makefile.am
index c374a52ac..5e65e1db4 100644
--- a/etc/systemd/system/Makefile.am
+++ b/etc/systemd/system/Makefile.am
@@ -12,7 +12,10 @@ systemdunit_DATA = \
 	zfs-volume-wait.service \
 	zfs-import.target \
 	zfs-volumes.target \
-	zfs.target
+	zfs.target \
+	zfs-scrub-monthly@.timer \
+	zfs-scrub-weekly@.timer \
+	zfs-scrub@.service
 
 SUBSTFILES += $(systemdpreset_DATA) $(systemdunit_DATA)
 
diff --git a/etc/systemd/system/zfs-scrub-monthly@.timer.in b/etc/systemd/system/zfs-scrub-monthly@.timer.in
new file mode 100644
index 000000000..903068468
--- /dev/null
+++ b/etc/systemd/system/zfs-scrub-monthly@.timer.in
@@ -0,0 +1,12 @@
+[Unit]
+Description=Monthly zpool scrub timer for %i
+Documentation=man:zpool-scrub(8)
+
+[Timer]
+OnCalendar=monthly
+Persistent=true
+RandomizedDelaySec=1h
+Unit=zfs-scrub@%i.service
+
+[Install]
+WantedBy=timers.target
diff --git a/etc/systemd/system/zfs-scrub-weekly@.timer.in b/etc/systemd/system/zfs-scrub-weekly@.timer.in
new file mode 100644
index 000000000..ede699500
--- /dev/null
+++ b/etc/systemd/system/zfs-scrub-weekly@.timer.in
@@ -0,0 +1,12 @@
+[Unit]
+Description=Weekly zpool scrub timer for %i
+Documentation=man:zpool-scrub(8)
+
+[Timer]
+OnCalendar=weekly
+Persistent=true
+RandomizedDelaySec=1h
+Unit=zfs-scrub@%i.service
+
+[Install]
+WantedBy=timers.target
diff --git a/etc/systemd/system/zfs-scrub@.service.in b/etc/systemd/system/zfs-scrub@.service.in
new file mode 100644
index 000000000..c04ac292a
--- /dev/null
+++ b/etc/systemd/system/zfs-scrub@.service.in
@@ -0,0 +1,14 @@
+[Unit]
+Description=zpool scrub on %i
+Documentation=man:zpool-scrub(8)
+Requires=zfs.target
+After=zfs.target
+ConditionACPower=true
+ConditionPathIsDirectory=/sys/module/zfs
+
+[Service]
+ExecStart=/bin/sh -c '\
+if @sbindir@/zpool status %i | grep "scrub in progress"; then\
+exec @sbindir@/zpool wait -t scrub %i;\
+else exec @sbindir@/zpool scrub -w %i; fi'
+ExecStop=-/bin/sh -c '@sbindir@/zpool scrub -p %i 2>/dev/null || true'
-- 
2.34.1

From 4bac4eae0345fb322337b66a9b4923e9f3f52b0f Mon Sep 17 00:00:00 2001
From: Georgy Yakovlev <gyakovlev@gentoo.org>
Date: Fri, 29 Oct 2021 21:40:50 -0700
Subject: [PATCH 2/2] zpool-scrub.8: add PERIODIC SCRUB section

Signed-off-by: Georgy Yakovlev <gyakovlev@gentoo.org>
---
 man/man8/zpool-scrub.8 | 21 +++++++++++++++++++++
 1 file changed, 21 insertions(+)

diff --git a/man/man8/zpool-scrub.8 b/man/man8/zpool-scrub.8
index 768f71539..69ae825b6 100644
--- a/man/man8/zpool-scrub.8
+++ b/man/man8/zpool-scrub.8
@@ -116,8 +116,29 @@ scanned at 100M/s, and 68.4M of that file data has been
 scrubbed sequentially at 10.0M/s.
 .El
 .El
+.Sh PERIODIC SCRUB
+On machines using systemd, scrub timers can be enabled on per-pool basis.
+.Nm weekly
+and
+.Nm monthly
+timer units are provided.
+.Bl -tag -width Ds
+.It Xo
+.Xc
+.Nm systemctl
+.Cm enable
+.Cm zfs-scrub-\fIweekly\fB@\fIrpool\fB.timer
+.Cm --now
+.It Xo
+.Xc
+.Nm systemctl
+.Cm enable
+.Cm zfs-scrub-\fImonthly\fB@\fIotherpool\fB.timer
+.Cm --now
+.El
 .
 .Sh SEE ALSO
+.Xr systemd.timer 5 ,
 .Xr zpool-iostat 8 ,
 .Xr zpool-resilver 8 ,
 .Xr zpool-status 8
-- 
2.34.1