diff options
author | Darrick J. Wong <djwong@kernel.org> | 2024-01-11 18:07:05 -0800 |
---|---|---|
committer | Darrick J. Wong <djwong@kernel.org> | 2024-01-11 18:08:46 -0800 |
commit | 7c4b91c5c119ea4b1e4d7640a64aac7671de36ff (patch) | |
tree | 6cb66d30953cdbdc7503867b8c4bdac1260cd903 | |
parent | dc0611945e7ee98f73b04f4b1b7a88b12d70a413 (diff) | |
download | xfsprogs-dev-7c4b91c5c119ea4b1e4d7640a64aac7671de36ff.tar.gz |
xfs_scrub_all: escape service names consistently
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>
-rw-r--r-- | scrub/xfs_scrub_all.in | 32 |
1 files changed, 17 insertions, 15 deletions
diff --git a/scrub/xfs_scrub_all.in b/scrub/xfs_scrub_all.in index 5042321a73..85f95f135c 100644 --- a/scrub/xfs_scrub_all.in +++ b/scrub/xfs_scrub_all.in @@ -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] |