]> www.infradead.org Git - users/hch/xfsprogs.git/commitdiff
xfs_scrub_all: only use the xfs_scrub@ systemd services in service mode
authorDarrick J. Wong <djwong@kernel.org>
Wed, 3 Jul 2024 21:21:16 +0000 (14:21 -0700)
committerDarrick J. Wong <djwong@kernel.org>
Tue, 9 Jul 2024 22:36:59 +0000 (15:36 -0700)
Since the per-mount xfs_scrub@.service definition includes a bunch of
resource usage constraints, we no longer want to use those services if
xfs_scrub_all is being run directly by the sysadmin (aka not in service
mode) on the presumption that sysadmins want answers as quickly as
possible.

Therefore, only try to call the systemd service from xfs_scrub_all if
SERVICE_MODE is set in the environment.  If reaching out to systemd
fails and we're in service mode, we still want to run xfs_scrub
directly.  Split the makefile variables as necessary so that we only
pass -b to xfs_scrub in service mode.

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

index 2a257e0805cd9744b17e54f91f9f467eea500523..2050fe28fc759a6d392e07b3e135a9cf8339a257 100644 (file)
@@ -15,7 +15,8 @@ LTCOMMAND = xfs_scrub
 INSTALL_SCRUB = install-scrub
 XFS_SCRUB_ALL_PROG = xfs_scrub_all
 XFS_SCRUB_FAIL_PROG = xfs_scrub_fail
-XFS_SCRUB_ARGS = -b -n
+XFS_SCRUB_ARGS = -n
+XFS_SCRUB_SERVICE_ARGS = -b
 ifeq ($(HAVE_SYSTEMD),yes)
 INSTALL_SCRUB += install-systemd
 SYSTEMD_SERVICES=\
@@ -113,6 +114,7 @@ xfs_scrub_all: xfs_scrub_all.in $(builddefs)
        $(Q)$(SED) -e "s|@sbindir@|$(PKG_SBIN_DIR)|g" \
                   -e "s|@scrub_svcname@|$(scrub_svcname)|g" \
                   -e "s|@pkg_version@|$(PKG_VERSION)|g" \
+                  -e "s|@scrub_service_args@|$(XFS_SCRUB_SERVICE_ARGS)|g" \
                   -e "s|@scrub_args@|$(XFS_SCRUB_ARGS)|g" < $< > $@
        $(Q)chmod a+x $@
 
@@ -132,6 +134,7 @@ install: $(INSTALL_SCRUB)
 %.service: %.service.in $(builddefs)
        @echo "    [SED]    $@"
        $(Q)$(SED) -e "s|@sbindir@|$(PKG_SBIN_DIR)|g" \
+                  -e "s|@scrub_service_args@|$(XFS_SCRUB_SERVICE_ARGS)|g" \
                   -e "s|@scrub_args@|$(XFS_SCRUB_ARGS)|g" \
                   -e "s|@pkg_libexec_dir@|$(PKG_LIBEXEC_DIR)|g" \
                   < $< > $@
index a8dd9052f0e086a2186fa1fa9217080dbf72d7e1..5fa5f328200e115df5fda53a709ddb67718980af 100644 (file)
@@ -22,7 +22,7 @@ RequiresMountsFor=%f
 [Service]
 Type=oneshot
 Environment=SERVICE_MODE=1
-ExecStart=@sbindir@/xfs_scrub @scrub_args@ -M /tmp/scrub/ %f
+ExecStart=@sbindir@/xfs_scrub @scrub_service_args@ @scrub_args@ -M /tmp/scrub/ %f
 SyslogIdentifier=%N
 
 # Run scrub with minimal CPU and IO priority so that nothing else will starve.
index d0ab27fd30602735c385f2493a511dc3ef67ea5b..f27251fa54397af89664dfc36d47c30b158e2989 100644 (file)
@@ -162,9 +162,10 @@ def run_scrub(mnt, cond, running_devs, mntdevs, killfuncs):
                if terminate:
                        return
 
-               # Try it the systemd way
+               # Run per-mount systemd xfs_scrub service only if we ourselves
+               # are running as a systemd service.
                unitname = path_to_serviceunit(path)
-               if unitname is not None:
+               if unitname is not None and 'SERVICE_MODE' in os.environ:
                        ret = systemctl_start(unitname, killfuncs)
                        if ret == 0 or ret == 1:
                                print("Scrubbing %s done, (err=%d)" % (mnt, ret))
@@ -175,8 +176,12 @@ def run_scrub(mnt, cond, running_devs, mntdevs, killfuncs):
                        if terminate:
                                return
 
-               # Invoke xfs_scrub manually
+               # Invoke xfs_scrub manually if we're running in the foreground.
+               # We also permit this if we're running as a cronjob where
+               # systemd services are unavailable.
                cmd = ['@sbindir@/xfs_scrub']
+               if 'SERVICE_MODE' in os.environ:
+                       cmd += '@scrub_service_args@'.split()
                cmd += '@scrub_args@'.split()
                cmd += [mnt]
                ret = run_killable(cmd, None, killfuncs)