]> git.ipfire.org Git - thirdparty/xfsprogs-dev.git/commitdiff
xfs_scrub_all: fail fast on masked units
authorDarrick J. Wong <djwong@kernel.org>
Mon, 29 Jul 2024 23:23:18 +0000 (16:23 -0700)
committerDarrick J. Wong <djwong@kernel.org>
Tue, 30 Jul 2024 00:01:10 +0000 (17:01 -0700)
If xfs_scrub_all tries to start a masked xfs_scrub@ unit, that's a sign
that the system administrator really didn't want us to scrub that
filesystem.  Instead of retrying pointlessly, just make a note of the
failure and move on.

Signed-off-by: Darrick J. Wong <djwong@kernel.org>
Reviewed-by: Christoph Hellwig <hch@lst.de>
scrub/xfs_scrub_all.in

index 5440e51c0791fa3110f6c6e109670f4a4d6e3704..5e2e0446a99f89d903bb0839680acd907dfcf88a 100644 (file)
@@ -181,6 +181,10 @@ def fibonacci(max_ret):
                y = z
                z = x + y
 
+def was_unit_masked(ex):
+       '''Decide if this dbus exception occurred because we tried to start a masked unit.'''
+       return ex.get_dbus_name() == "org.freedesktop.systemd1.UnitMasked"
+
 class scrub_service(scrub_control):
        '''Control object for xfs_scrub systemd service.'''
        def __init__(self, mnt, scrub_media):
@@ -219,6 +223,12 @@ class scrub_service(scrub_control):
                                if debug:
                                        print(e)
                                fatal_ex = e
+
+                               # If the unit is masked, there's no point in
+                               # retrying any operations on it.
+                               if was_unit_masked(e):
+                                       break
+
                                time.sleep(i)
                                self.bind()
                raise fatal_ex
@@ -270,6 +280,13 @@ class scrub_service(scrub_control):
                try:
                        self.__dbusrun(lambda: self.unit.Start('replace'))
                        return self.wait()
+               except dbus.exceptions.DBusException as e:
+                       # If the unit was masked, the sysadmin doesn't want us
+                       # running it.  Pretend that we finished it.
+                       if was_unit_masked(e):
+                               return 32
+                       print(e, file = sys.stderr)
+                       return -1
                except Exception as e:
                        print(e, file = sys.stderr)
                        return -1
@@ -317,6 +334,10 @@ def run_scrub(mnt, cond, running_devs, mntdevs, killfuncs):
                # are running as a systemd service.
                if 'SERVICE_MODE' in os.environ:
                        ret = run_service(mnt, scrub_media, killfuncs)
+                       if ret == 32:
+                               print("Scrubbing %s disabled by administrator, (err=%d)" % (mnt, ret))
+                               sys.stdout.flush()
+                               return
                        if ret == 0 or ret == 1:
                                print("Scrubbing %s done, (err=%d)" % (mnt, ret))
                                sys.stdout.flush()