summaryrefslogtreecommitdiff
path: root/roles/storage
diff options
context:
space:
mode:
authorChristian Pointner <equinox@spreadspace.org>2021-06-18 23:21:22 +0200
committerChristian Pointner <equinox@spreadspace.org>2021-06-18 23:21:22 +0200
commitf3da1f7afbcccd07daf9aec1310e69cb2619ae3f (patch)
tree0078c527a7349eba12f4100b9c3ffb875e0d77d1 /roles/storage
parentch-jump: disable user fim (diff)
zfs/syncoid: inhibit autosuspend if scrubbing is in progress
Diffstat (limited to 'roles/storage')
-rw-r--r--roles/storage/zfs/syncoid/templates/autosuspend.py.j221
-rw-r--r--roles/storage/zfs/syncoid/templates/autosuspend.service.j21
2 files changed, 21 insertions, 1 deletions
diff --git a/roles/storage/zfs/syncoid/templates/autosuspend.py.j2 b/roles/storage/zfs/syncoid/templates/autosuspend.py.j2
index a9f3f646..22b27df4 100644
--- a/roles/storage/zfs/syncoid/templates/autosuspend.py.j2
+++ b/roles/storage/zfs/syncoid/templates/autosuspend.py.j2
@@ -4,6 +4,7 @@ import sys
import dbus
import re
import datetime
+import subprocess
# import pprint
@@ -12,6 +13,7 @@ class AutoSuspender(object):
def __init__(self):
self.__bus = dbus.SystemBus()
self.__timer_re = re.compile('^syncoid-pull-.*\.timer$')
+ self.__zpool_scrub_in_progress_re = re.compile('^\s*scan:.*scrub in progress.*$')
# self.__pp = pprint.PrettyPrinter(indent=2)
def _get_interface(self, dest, object, interface):
@@ -58,6 +60,17 @@ class AutoSuspender(object):
except ValueError:
return None
+ def _get_zpools(self):
+ pools = subprocess.run(["zpool", "list", "-H", "-o", "name"], check=True, stdout=subprocess.PIPE).stdout.splitlines()
+ return [pool.decode('utf-8') for pool in pools]
+
+ def _is_zpool_scrub_in_progress(self, pool):
+ lines = subprocess.run(["zpool", "status", pool], check=True, stdout=subprocess.PIPE).stdout.splitlines()
+ for line in lines:
+ if self.__zpool_scrub_in_progress_re.match(line.decode('utf-8')):
+ return True
+ return False
+
def check(self):
result = True
@@ -83,6 +96,14 @@ class AutoSuspender(object):
else:
print(" [ok] timer '%s' elapses in %s (%s)" % (timer[0], until, next))
+ zpools = self._get_zpools()
+ for pool in zpools:
+ if self._is_zpool_scrub_in_progress(pool):
+ print(" [NO] zpool scrubbing is in progress on pool '%s'" % (pool))
+ result = False
+ else:
+ print(" [ok] zpool '%s' is not scrubbing" % (pool))
+
return result
def suspend(self):
diff --git a/roles/storage/zfs/syncoid/templates/autosuspend.service.j2 b/roles/storage/zfs/syncoid/templates/autosuspend.service.j2
index f1e13b72..28cff913 100644
--- a/roles/storage/zfs/syncoid/templates/autosuspend.service.j2
+++ b/roles/storage/zfs/syncoid/templates/autosuspend.service.j2
@@ -6,7 +6,6 @@ Type=oneshot
ExecStart=/usr/local/bin/syncoid-autosuspend.py
NoNewPrivileges=yes
PrivateTmp=yes
-PrivateDevices=yes
ProtectSystem=strict
ProtectHome=yes
ProtectKernelTunables=yes