From f3da1f7afbcccd07daf9aec1310e69cb2619ae3f Mon Sep 17 00:00:00 2001 From: Christian Pointner Date: Fri, 18 Jun 2021 23:21:22 +0200 Subject: zfs/syncoid: inhibit autosuspend if scrubbing is in progress --- .../storage/zfs/syncoid/templates/autosuspend.py.j2 | 21 +++++++++++++++++++++ .../zfs/syncoid/templates/autosuspend.service.j2 | 1 - 2 files changed, 21 insertions(+), 1 deletion(-) (limited to 'roles/storage') 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 -- cgit v1.2.3