From: Darrick J. Wong <djwong@xxxxxxxxxx> 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@xxxxxxxxxx> --- scrub/Makefile | 5 ++++- scrub/xfs_scrub@xxxxxxxxxxx | 2 +- scrub/xfs_scrub_all.in | 11 ++++++++--- 3 files changed, 13 insertions(+), 5 deletions(-) diff --git a/scrub/Makefile b/scrub/Makefile index db2b94feb12..f631fd6d70f 100644 --- a/scrub/Makefile +++ b/scrub/Makefile @@ -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=\ @@ -120,6 +121,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 $@ @@ -139,6 +141,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_lib_dir@|$(PKG_LIB_SCRIPT_DIR)|g" \ -e "s|@pkg_name@|$(PKG_NAME)|g" \ diff --git a/scrub/xfs_scrub@xxxxxxxxxxx b/scrub/xfs_scrub@xxxxxxxxxxx index e306216bb91..ef869379789 100644 --- a/scrub/xfs_scrub@xxxxxxxxxxx +++ b/scrub/xfs_scrub@xxxxxxxxxxx @@ -17,7 +17,7 @@ ConditionCapability=CAP_SYS_RAWIO Type=oneshot Environment=SERVICE_MODE=1 Environment=SERVICE_MOUNTPOINT=/tmp/scrub -ExecStart=@sbindir@/xfs_scrub @scrub_args@ %f +ExecStart=@sbindir@/xfs_scrub @scrub_service_args@ @scrub_args@ %f SyslogIdentifier=%N # Run scrub with minimal CPU and IO priority so that nothing else will starve. diff --git a/scrub/xfs_scrub_all.in b/scrub/xfs_scrub_all.in index 11189c3ee10..f2b06fb8f7d 100644 --- a/scrub/xfs_scrub_all.in +++ b/scrub/xfs_scrub_all.in @@ -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)