]> git.ipfire.org Git - thirdparty/xfsprogs-dev.git/commitdiff
xfs_scrub_all: escape service names consistently
authorDarrick J. Wong <djwong@kernel.org>
Fri, 12 Jan 2024 02:07:05 +0000 (18:07 -0800)
committerDarrick J. Wong <djwong@kernel.org>
Fri, 12 Jan 2024 02:08:46 +0000 (18:08 -0800)
This program is not consistent as to whether or not it escapes the
pathname that is being used as the xfs_scrub service instance name.
Fix it to be consistent, and to fall back to direct invocation if
escaping doesn't work.  The escaping itself is also broken, but we'll
fix that in the next patch.

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

index 5042321a7389033ab8c02096259ad1b7cbfcba79..85f95f135cc233d7ba059bc5f11828cbe894c528 100644 (file)
@@ -93,19 +93,19 @@ def run_killable(cmd, stdout, killfuncs, kill_fn):
 # that log messages from the service units preserve the full path and users can
 # look up log messages using full paths.  However, for "/" the escaping rules
 # do /not/ drop the initial slash, so we have to special-case that here.
-def systemd_escape(path):
+def path_to_service(path):
        '''Escape a path to avoid mangled systemd mangling.'''
 
        if path == '/':
-               return '-'
+               return 'xfs_scrub@-'
        cmd = ['systemd-escape', '--path', path]
        try:
                proc = subprocess.Popen(cmd, stdout = subprocess.PIPE)
                proc.wait()
                for line in proc.stdout:
-                       return '-' + line.decode(sys.stdout.encoding).strip()
+                       return 'xfs_scrub@-%s' % line.decode(sys.stdout.encoding).strip()
        except:
-               return path
+               return None
 
 def run_scrub(mnt, cond, running_devs, mntdevs, killfuncs):
        '''Run a scrub process.'''
@@ -119,17 +119,19 @@ def run_scrub(mnt, cond, running_devs, mntdevs, killfuncs):
                        return
 
                # Try it the systemd way
-               cmd=['systemctl', 'start', 'xfs_scrub@%s' % systemd_escape(mnt)]
-               ret = run_killable(cmd, DEVNULL(), killfuncs, \
-                               lambda proc: kill_systemd('xfs_scrub@%s' % mnt, proc))
-               if ret == 0 or ret == 1:
-                       print("Scrubbing %s done, (err=%d)" % (mnt, ret))
-                       sys.stdout.flush()
-                       retcode |= ret
-                       return
-
-               if terminate:
-                       return
+               svcname = path_to_service(path)
+               if svcname is not None:
+                       cmd=['systemctl', 'start', svcname]
+                       ret = run_killable(cmd, DEVNULL(), killfuncs, \
+                                       lambda proc: kill_systemd(svcname, proc))
+                       if ret == 0 or ret == 1:
+                               print("Scrubbing %s done, (err=%d)" % (mnt, ret))
+                               sys.stdout.flush()
+                               retcode |= ret
+                               return
+
+                       if terminate:
+                               return
 
                # Invoke xfs_scrub manually
                cmd=['@sbindir@/xfs_scrub', '@scrub_args@', mnt]