From patchwork Sun Dec 31 22:52:36 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13507975 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A63CDC13B for ; Sun, 31 Dec 2023 22:52:36 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="S6nHlQkn" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 76D0AC433C8; Sun, 31 Dec 2023 22:52:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1704063156; bh=zQl7kPEcbI7gjJHNVl3r8oqkftrjhAY8yO3qo8elozo=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=S6nHlQknveRBLnheyf3LHOdsQcavWgBiUl1lNsUFHnaa1W+C+tBroSMUNiaFOh1rh RR/cXyEtbV1JAPgTs1BTjm4G+UQkwddGb8vbwGZOF8Wk6fM8PGeElvoiu3bGO6sCIT AfHpieOG7iw41CJYRlF5Bv1u3fPgUDs53XjlvM9o+j+7yZSEowUwBgSV20SOQv3vix aj3K8dX3CDR8FMbQALyeYKyF3iqFzNQO5VRu++i3u3JJbS4TCUHfeMUzFrzGExKFtz Y5p7LS8OdtzMJrtvE6jtfbO02d/PR2zIODeDh5ssPbRszgmNxQF0FL/lIpcX+WCB5D BJcm08uaFa4Pg== Date: Sun, 31 Dec 2023 14:52:36 -0800 Subject: [PATCH 1/9] debian: install scrub services with dh_installsystemd From: "Darrick J. Wong" To: djwong@kernel.org, cem@kernel.org Cc: Christoph Hellwig , linux-xfs@vger.kernel.org Message-ID: <170405001860.1800712.12681766556317697413.stgit@frogsfrogsfrogs> In-Reply-To: <170405001841.1800712.6745668619742020884.stgit@frogsfrogsfrogs> References: <170405001841.1800712.6745668619742020884.stgit@frogsfrogsfrogs> User-Agent: StGit/0.19 Precedence: bulk X-Mailing-List: linux-xfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Darrick J. Wong Use dh_installsystemd to handle the installation and activation of the scrub systemd services. This requires bumping the compat version to 11. Note that the services are /not/ activated on installation. Signed-off-by: Darrick J. Wong Reviewed-by: Christoph Hellwig --- debian/rules | 1 + 1 file changed, 1 insertion(+) diff --git a/debian/rules b/debian/rules index 95df4835b25..57baad625c5 100755 --- a/debian/rules +++ b/debian/rules @@ -108,6 +108,7 @@ binary-arch: checkroot built dh_compress dh_fixperms dh_makeshlibs + dh_installsystemd -p xfsprogs --no-enable --no-start --no-restart-after-upgrade --no-stop-on-upgrade dh_installdeb dh_shlibdeps dh_gencontrol From patchwork Sun Dec 31 22:52:51 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13507976 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 96185C13B for ; Sun, 31 Dec 2023 22:52:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="KRqkluKn" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 16D3DC433C8; Sun, 31 Dec 2023 22:52:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1704063172; bh=nh94gu9XwoEkJScPh67zgk6Llz9kW9aZQJkyKIj2za8=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=KRqkluKn9Flh/BNRoDTH4EzuyRfGdAKzdu/QtX87lTY9ghOj3lNfUdaVNHVwVcktv xZfFqAX17N17CMZIlNc6AhwlqSbpUJqnfIr8BLKliJtEQ1wX1CuSyelphKrP7zg4ie X+gFErTWTKRdUqdN6mogkfHPOcUN88ejDo5WEUh8da1EfOiFjYB2iH7J9xRUKb+R+A DPHxWwQaAZ82rhow6u5ai4g1KyWS7Ot8DGtciHd0WfYyv5oOk8/MB5xeBZEYxa6Ewy 1qFm8Q6xKYr1VFmzNQE+uW8yGW/pWUu+nbbs5tbp3F7wBgUe/tDcAzlfn38Bg18iBD jT6nuppLv1wVg== Date: Sun, 31 Dec 2023 14:52:51 -0800 Subject: [PATCH 2/9] xfs_scrub_all: escape service names consistently From: "Darrick J. Wong" To: djwong@kernel.org, cem@kernel.org Cc: Christoph Hellwig , linux-xfs@vger.kernel.org Message-ID: <170405001872.1800712.4585841935852644225.stgit@frogsfrogsfrogs> In-Reply-To: <170405001841.1800712.6745668619742020884.stgit@frogsfrogsfrogs> References: <170405001841.1800712.6745668619742020884.stgit@frogsfrogsfrogs> User-Agent: StGit/0.19 Precedence: bulk X-Mailing-List: linux-xfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Darrick J. Wong 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 Reviewed-by: Christoph Hellwig --- scrub/xfs_scrub_all.in | 30 ++++++++++++++++-------------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/scrub/xfs_scrub_all.in b/scrub/xfs_scrub_all.in index 5042321a738..85f95f135cc 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 + 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 + if terminate: + return # Invoke xfs_scrub manually cmd=['@sbindir@/xfs_scrub', '@scrub_args@', mnt] From patchwork Sun Dec 31 22:53:07 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13507977 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 42652C127 for ; Sun, 31 Dec 2023 22:53:07 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="hbE5Sq45" Received: by smtp.kernel.org (Postfix) with ESMTPSA id B3EE1C433C8; Sun, 31 Dec 2023 22:53:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1704063187; bh=WAPP0k6ISTdx0fyPXkGKCfnq9C7BijfZ3GTghj6ctCs=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=hbE5Sq45JvhD8lMeqhIS/wYu89zeoe9GU0mrRd19nFecIC5vm76pGIRBiX1U8c3/V q+REfy5jO0JhhHNQWXK3dJgaco2BWi+uXmxoX9PQT01MTNSsFUE4cM9WgUXVAQ9N1f jXu9GX9N7dBWgQ1ykDY3Q0n4LkrB2f9AOoo1LztiGd2xCszJ2gnMBOQU1liRsEJJUd 9kxSPj8zGZWd/CVKbVpsEssGADJLKW0bmmeOy7wBvkKwl4jZ1K2mmBVUCfT7WelExj nEFI2cMyAbDYGP2ASM2M+l72AEhu6l7hzPeoSHmkpYKWBCjzN8BBmGUf4KOVMcfHuK 8fKEKBTW9Nr5Q== Date: Sun, 31 Dec 2023 14:53:07 -0800 Subject: [PATCH 3/9] xfs_scrub: fix pathname escaping across all service definitions From: "Darrick J. Wong" To: djwong@kernel.org, cem@kernel.org Cc: Christoph Hellwig , linux-xfs@vger.kernel.org Message-ID: <170405001885.1800712.12823520124308059411.stgit@frogsfrogsfrogs> In-Reply-To: <170405001841.1800712.6745668619742020884.stgit@frogsfrogsfrogs> References: <170405001841.1800712.6745668619742020884.stgit@frogsfrogsfrogs> User-Agent: StGit/0.19 Precedence: bulk X-Mailing-List: linux-xfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Darrick J. Wong systemd services provide an "instance name" that can be associated with a particular invocation of a service. This allows service users to invoke multiple copies of a service, each with a unique string. For xfs_scrub, we pass the mountpoint of the filesystem as the instance name. However, systemd services aren't supposed to have slashes in them, so we're supposed to escape them. The canonical escaping scheme for pathnames is defined by the systemd-escape --path command. Unfortunately, we've been adding our own opinionated sauce for years, to work around the fact that --path didn't exist in systemd before January 2017. The special sauce is incorrect, and we no longer care about systemd of 7 years past. Clean up this mess by following the systemd escaping scheme throughout the service units. Now we can use the '%f' specifier in them, which makes things a lot less complicated. Signed-off-by: Darrick J. Wong Reviewed-by: Christoph Hellwig --- scrub/Makefile | 19 +++++++++++++++---- scrub/xfs_scrub@.service.in | 6 +++--- scrub/xfs_scrub_all.in | 33 +++++++++++---------------------- scrub/xfs_scrub_fail.in | 5 ++++- scrub/xfs_scrub_fail@.service.in | 4 ++-- 5 files changed, 35 insertions(+), 32 deletions(-) rename scrub/{xfs_scrub_fail => xfs_scrub_fail.in} (75%) diff --git a/scrub/Makefile b/scrub/Makefile index af94cf0d684..fd47b893956 100644 --- a/scrub/Makefile +++ b/scrub/Makefile @@ -8,14 +8,17 @@ include $(builddefs) SCRUB_PREREQS=$(HAVE_OPENAT)$(HAVE_FSTATAT)$(HAVE_GETFSMAP) +scrub_svcname=xfs_scrub@.service + ifeq ($(SCRUB_PREREQS),yesyesyes) 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 ifeq ($(HAVE_SYSTEMD),yes) INSTALL_SCRUB += install-systemd -SYSTEMD_SERVICES = xfs_scrub@.service xfs_scrub_all.service xfs_scrub_all.timer xfs_scrub_fail@.service +SYSTEMD_SERVICES = $(scrub_svcname) xfs_scrub_all.service xfs_scrub_all.timer xfs_scrub_fail@.service OPTIONAL_TARGETS += $(SYSTEMD_SERVICES) endif ifeq ($(HAVE_CROND),yes) @@ -108,17 +111,25 @@ ifeq ($(HAVE_HDIO_GETGEO),yes) LCFLAGS += -DHAVE_HDIO_GETGEO endif -LDIRT = $(XFS_SCRUB_ALL_PROG) *.service *.cron +LDIRT = $(XFS_SCRUB_ALL_PROG) $(XFS_SCRUB_FAIL_PROG) *.service *.cron -default: depend $(LTCOMMAND) $(XFS_SCRUB_ALL_PROG) $(OPTIONAL_TARGETS) +default: depend $(LTCOMMAND) $(XFS_SCRUB_ALL_PROG) $(XFS_SCRUB_FAIL_PROG) $(OPTIONAL_TARGETS) xfs_scrub_all: xfs_scrub_all.in $(builddefs) @echo " [SED] $@" $(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_args@|$(XFS_SCRUB_ARGS)|g" < $< > $@ $(Q)chmod a+x $@ +xfs_scrub_fail: xfs_scrub_fail.in $(builddefs) + @echo " [SED] $@" + $(Q)$(SED) -e "s|@sbindir@|$(PKG_SBIN_DIR)|g" \ + -e "s|@scrub_svcname@|$(scrub_svcname)|g" \ + -e "s|@pkg_version@|$(PKG_VERSION)|g" < $< > $@ + $(Q)chmod a+x $@ + phase5.o unicrash.o xfs.o: $(builddefs) include $(BUILDRULES) @@ -141,7 +152,7 @@ install-systemd: default $(SYSTEMD_SERVICES) $(INSTALL) -m 755 -d $(SYSTEMD_SYSTEM_UNIT_DIR) $(INSTALL) -m 644 $(SYSTEMD_SERVICES) $(SYSTEMD_SYSTEM_UNIT_DIR) $(INSTALL) -m 755 -d $(PKG_LIB_SCRIPT_DIR)/$(PKG_NAME) - $(INSTALL) -m 755 xfs_scrub_fail $(PKG_LIB_SCRIPT_DIR)/$(PKG_NAME) + $(INSTALL) -m 755 $(XFS_SCRUB_FAIL_PROG) $(PKG_LIB_SCRIPT_DIR)/$(PKG_NAME) install-crond: default $(CRONTABS) $(INSTALL) -m 755 -d $(CROND_DIR) diff --git a/scrub/xfs_scrub@.service.in b/scrub/xfs_scrub@.service.in index d878eeda4fd..043aad12f20 100644 --- a/scrub/xfs_scrub@.service.in +++ b/scrub/xfs_scrub@.service.in @@ -4,7 +4,7 @@ # Author: Darrick J. Wong [Unit] -Description=Online XFS Metadata Check for %I +Description=Online XFS Metadata Check for %f OnFailure=xfs_scrub_fail@%i.service Documentation=man:xfs_scrub(8) @@ -13,7 +13,7 @@ Type=oneshot PrivateNetwork=true ProtectSystem=full ProtectHome=read-only -# Disable private /tmp just in case %i is a path under /tmp. +# Disable private /tmp just in case %f is a path under /tmp. PrivateTmp=no AmbientCapabilities=CAP_SYS_ADMIN CAP_FOWNER CAP_DAC_OVERRIDE CAP_DAC_READ_SEARCH CAP_SYS_RAWIO NoNewPrivileges=yes @@ -21,5 +21,5 @@ User=nobody IOSchedulingClass=idle CPUSchedulingPolicy=idle Environment=SERVICE_MODE=1 -ExecStart=@sbindir@/xfs_scrub @scrub_args@ %I +ExecStart=@sbindir@/xfs_scrub @scrub_args@ %f SyslogIdentifier=%N diff --git a/scrub/xfs_scrub_all.in b/scrub/xfs_scrub_all.in index 85f95f135cc..d7d36e1bdb0 100644 --- a/scrub/xfs_scrub_all.in +++ b/scrub/xfs_scrub_all.in @@ -81,29 +81,18 @@ def run_killable(cmd, stdout, killfuncs, kill_fn): return -1 # systemd doesn't like unit instance names with slashes in them, so it -# replaces them with dashes when it invokes the service. However, it's not -# smart enough to convert the dashes to something else, so when it unescapes -# the instance name to feed to xfs_scrub, it turns all dashes into slashes. -# "/moo-cow" becomes "-moo-cow" becomes "/moo/cow", which is wrong. systemd -# actually /can/ escape the dashes correctly if it is told that this is a path -# (and not a unit name), but it didn't do this prior to January 2017, so fix -# this for them. -# -# systemd path escaping also drops the initial slash so we add that back in so -# 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 path_to_service(path): - '''Escape a path to avoid mangled systemd mangling.''' +# replaces them with dashes when it invokes the service. Filesystem paths +# need a special --path argument so that dashes do not get mangled. +def path_to_serviceunit(path): + '''Convert a pathname into a systemd service unit name.''' - if path == '/': - return 'xfs_scrub@-' - cmd = ['systemd-escape', '--path', path] + cmd = ['systemd-escape', '--template', '@scrub_svcname@', + '--path', path] try: proc = subprocess.Popen(cmd, stdout = subprocess.PIPE) proc.wait() for line in proc.stdout: - return 'xfs_scrub@-%s' % line.decode(sys.stdout.encoding).strip() + return line.decode(sys.stdout.encoding).strip() except: return None @@ -119,11 +108,11 @@ def run_scrub(mnt, cond, running_devs, mntdevs, killfuncs): return # Try it the systemd way - svcname = path_to_service(path) - if svcname is not None: - cmd=['systemctl', 'start', svcname] + unitname = path_to_serviceunit(path) + if unitname is not None: + cmd=['systemctl', 'start', unitname] ret = run_killable(cmd, DEVNULL(), killfuncs, \ - lambda proc: kill_systemd(svcname, proc)) + lambda proc: kill_systemd(unitname, proc)) if ret == 0 or ret == 1: print("Scrubbing %s done, (err=%d)" % (mnt, ret)) sys.stdout.flush() diff --git a/scrub/xfs_scrub_fail b/scrub/xfs_scrub_fail.in similarity index 75% rename from scrub/xfs_scrub_fail rename to scrub/xfs_scrub_fail.in index 415efaa24d6..0bceda6403d 100755 --- a/scrub/xfs_scrub_fail +++ b/scrub/xfs_scrub_fail.in @@ -19,6 +19,9 @@ if [ ! -x "${mailer}" ]; then exit 1 fi +# Turn the mountpoint into a properly escaped systemd instance name +scrub_svc="$(systemd-escape --template "@scrub_svcname@" --path "${mntpoint}")" + (cat << ENDL To: $1 From: @@ -28,4 +31,4 @@ So sorry, the automatic xfs_scrub of ${mntpoint} on ${hostname} failed. A log of what happened follows: ENDL -systemctl status --full --lines 4294967295 "xfs_scrub@${mntpoint}") | "${mailer}" -t -i +systemctl status --full --lines 4294967295 "${scrub_svc}") | "${mailer}" -t -i diff --git a/scrub/xfs_scrub_fail@.service.in b/scrub/xfs_scrub_fail@.service.in index 187adc17f6d..048b5732459 100644 --- a/scrub/xfs_scrub_fail@.service.in +++ b/scrub/xfs_scrub_fail@.service.in @@ -4,13 +4,13 @@ # Author: Darrick J. Wong [Unit] -Description=Online XFS Metadata Check Failure Reporting for %I +Description=Online XFS Metadata Check Failure Reporting for %f Documentation=man:xfs_scrub(8) [Service] Type=oneshot Environment=EMAIL_ADDR=root -ExecStart=@pkg_lib_dir@/@pkg_name@/xfs_scrub_fail "${EMAIL_ADDR}" %I +ExecStart=@pkg_lib_dir@/@pkg_name@/xfs_scrub_fail "${EMAIL_ADDR}" %f User=mail Group=mail SupplementaryGroups=systemd-journal From patchwork Sun Dec 31 22:53:22 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13507978 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 80BD3C13B for ; Sun, 31 Dec 2023 22:53:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="Gz1fTgmp" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 55518C433C7; Sun, 31 Dec 2023 22:53:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1704063203; bh=y98u+KsOsj914TkccHMiJ4vGcXOaZPJrNAOA1jHAyQ8=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=Gz1fTgmpvE3+5OY5oKUoQT28aMdf/rjHOIPUwVSs8100gSS2lOzhQjEV3kbDaUYAA xs92bz51i40lC5DOhUM7IzelFXEHY9HyIxkWhO3BYSHaXH/7e1lmf1Tf0XoNNK0Cy/ xkKCqYVoJWn5z+7/1orzrideXQJJKKKW1cOo6hzW5bnrzLvztxH6uWWwGLD34YTvp2 /HKhebkbKdv46otgmDv92YmwHShEW5U/YiA982lJOLHJBrGo2RNFUoxudiHgeCTBaK OmPwPYHNImYxOwBhmq2xzjqYnFrYG22Oi/dnMotWwiT5osxxpuptBtcGep8gTo1uvd 2akZTtM3KDDrg== Date: Sun, 31 Dec 2023 14:53:22 -0800 Subject: [PATCH 4/9] xfs_scrub_fail: fix sendmail detection From: "Darrick J. Wong" To: djwong@kernel.org, cem@kernel.org Cc: Christoph Hellwig , linux-xfs@vger.kernel.org Message-ID: <170405001898.1800712.12623844675618759314.stgit@frogsfrogsfrogs> In-Reply-To: <170405001841.1800712.6745668619742020884.stgit@frogsfrogsfrogs> References: <170405001841.1800712.6745668619742020884.stgit@frogsfrogsfrogs> User-Agent: StGit/0.19 Precedence: bulk X-Mailing-List: linux-xfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Darrick J. Wong This script emails the results of failed scrub runs to root. We shouldn't be hardcoding the path to the mailer program because distros can change the path according to their whim. Modify this script to use command -v to find the program. Signed-off-by: Darrick J. Wong Reviewed-by: Christoph Hellwig --- scrub/xfs_scrub_fail.in | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/scrub/xfs_scrub_fail.in b/scrub/xfs_scrub_fail.in index 0bceda6403d..d6a3d92159b 100755 --- a/scrub/xfs_scrub_fail.in +++ b/scrub/xfs_scrub_fail.in @@ -7,13 +7,14 @@ # Email logs of failed xfs_scrub unit runs -mailer=/usr/sbin/sendmail recipient="$1" test -z "${recipient}" && exit 0 mntpoint="$2" test -z "${mntpoint}" && exit 0 hostname="$(hostname -f 2>/dev/null)" test -z "${hostname}" && hostname="${HOSTNAME}" + +mailer="$(command -v sendmail)" if [ ! -x "${mailer}" ]; then echo "${mailer}: Mailer program not found." exit 1 From patchwork Sun Dec 31 22:53:38 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13507979 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7A0A5C13B for ; Sun, 31 Dec 2023 22:53:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="SQS/iboK" Received: by smtp.kernel.org (Postfix) with ESMTPSA id E3CEFC433C8; Sun, 31 Dec 2023 22:53:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1704063219; bh=EzPoZV9/dsKmTzrH9rtXyDruww8MaA3YrKz9NvOpb0Y=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=SQS/iboKvHU74hsNBT29HmmUPjKioWuP1AsPf7wEKhA9uqnvhzxhUZpeqvkU9HwDU ArJ+0+3zxE4vSip7cL82meNMcdnfyzB8gGGJYXAqqXH8+VDgb84rMby7wQ4RcLKw0Y XoOgizgb074C5eDkxOMQ7Iulc0FBGRgNpx862fkG75dj6om6GTQqVLI3lVps87oPTd MPDc84povfZ2cNzwlXYQr/Pd7PoE2EfInx50t3yLSN991cillUCGxNzcKC6wL4yZh0 iIcNej/EQbS3cjN1iHY55PhlSQ50jLarnNdZ10aIgXgwCx1tvL/TbjnQjLn0leQq5D VhoZW8iUq5nnw== Date: Sun, 31 Dec 2023 14:53:38 -0800 Subject: [PATCH 5/9] xfs_scrub_fail: return the failure status of the mailer program From: "Darrick J. Wong" To: djwong@kernel.org, cem@kernel.org Cc: Christoph Hellwig , linux-xfs@vger.kernel.org Message-ID: <170405001911.1800712.1452013057147421398.stgit@frogsfrogsfrogs> In-Reply-To: <170405001841.1800712.6745668619742020884.stgit@frogsfrogsfrogs> References: <170405001841.1800712.6745668619742020884.stgit@frogsfrogsfrogs> User-Agent: StGit/0.19 Precedence: bulk X-Mailing-List: linux-xfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Darrick J. Wong We should return the exit code of the mailer program sending the scrub failure reports, since that's much more important to anyone watching the system. Signed-off-by: Darrick J. Wong Reviewed-by: Christoph Hellwig --- scrub/xfs_scrub_fail.in | 1 + 1 file changed, 1 insertion(+) diff --git a/scrub/xfs_scrub_fail.in b/scrub/xfs_scrub_fail.in index d6a3d92159b..d3275f9897c 100755 --- a/scrub/xfs_scrub_fail.in +++ b/scrub/xfs_scrub_fail.in @@ -33,3 +33,4 @@ So sorry, the automatic xfs_scrub of ${mntpoint} on ${hostname} failed. A log of what happened follows: ENDL systemctl status --full --lines 4294967295 "${scrub_svc}") | "${mailer}" -t -i +exit "${PIPESTATUS[1]}" From patchwork Sun Dec 31 22:53:54 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13507980 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D0357C127 for ; Sun, 31 Dec 2023 22:53:54 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="bbSTdDWL" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 9F545C433C8; Sun, 31 Dec 2023 22:53:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1704063234; bh=b+0C0e5XmYv1OCQ+CwwSoggYs1V3mFnPe6XJ5h5E7oY=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=bbSTdDWLy0n1jOU9+2wCDw8EFoNWvz0pNMPdLosq6ARx1ApxrekUtGrHsbkcM02id dKtcK4/sGJlbmiiY+AxJT6tvBUZZrqTHPt55DdiLxUPpE3GwG4XnBqgLJOy/v/JcCT NBW8TiNgQsJukRT3A0+pGVQQVcVMiyPifTBLsPc3vaCSQ3XOxDOZtFyj8mPcKu1KQw UOUNeRBZkEJjD4REMf4F16vV+CCfkGlKKDt1WIuYg1Q7TbvLQQQWmWRY+q3eP2Vx7J saU3x1whlc2HwljbSQIYASa2R68NI3xPcqcBp2HdTIAVtAGHla5AaS1sfwBXaFIjXq xKwco9EL1+CFg== Date: Sun, 31 Dec 2023 14:53:54 -0800 Subject: [PATCH 6/9] xfs_scrub_fail: add content type header to failure emails From: "Darrick J. Wong" To: djwong@kernel.org, cem@kernel.org Cc: linux-xfs@vger.kernel.org Message-ID: <170405001924.1800712.10812613070481678255.stgit@frogsfrogsfrogs> In-Reply-To: <170405001841.1800712.6745668619742020884.stgit@frogsfrogsfrogs> References: <170405001841.1800712.6745668619742020884.stgit@frogsfrogsfrogs> User-Agent: StGit/0.19 Precedence: bulk X-Mailing-List: linux-xfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Darrick J. Wong Add content type and encoding metadata so that these emails display correctly. Signed-off-by: Darrick J. Wong Reviewed-by: Christoph Hellwig --- scrub/xfs_scrub_fail.in | 2 ++ 1 file changed, 2 insertions(+) diff --git a/scrub/xfs_scrub_fail.in b/scrub/xfs_scrub_fail.in index d3275f9897c..baa9d32d94c 100755 --- a/scrub/xfs_scrub_fail.in +++ b/scrub/xfs_scrub_fail.in @@ -27,6 +27,8 @@ scrub_svc="$(systemd-escape --template "@scrub_svcname@" --path "${mntpoint}")" To: $1 From: Subject: xfs_scrub failure on ${mntpoint} +Content-Transfer-Encoding: 8bit +Content-Type: text/plain; charset=UTF-8 So sorry, the automatic xfs_scrub of ${mntpoint} on ${hostname} failed. From patchwork Sun Dec 31 22:54:09 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13507981 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6D955C147 for ; Sun, 31 Dec 2023 22:54:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="h87wRCk7" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 43BD0C433C8; Sun, 31 Dec 2023 22:54:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1704063250; bh=6v0ycd1HXesL1JaU4nwmBJrbzYmRgjWRJm5ZakbR1KE=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=h87wRCk7imsiRDO7FZYMVrHuYny75Pk2jR/R/xh80oc5Daao7tW5zJ2PcaQvLIzTs 9LFgu/jxbQvmROyzWxF9HndXw3SvbWf/wKd8p5UfD8F15iYdv8n7bALPDewuYaau3p 86BytIOADhiDt5LFWsViyWM6oXl+8dALwc/TLvuXdYUX6mJPRzbWxNBLE2babWKHCo 8k8Eg4Wp7yWtGPdzRul5SYkIqX4XIzLqwZQ3xqq3hfv/BA9/ScQdF9lQ4Pqo063QLx JGxOUuknWUAKc+cAqcDMMBJwwrLjcuPxzx9iOTdhcPAyGO4WBjisjVyfgWmboMI+H+ 99KD1mr5E9yCw== Date: Sun, 31 Dec 2023 14:54:09 -0800 Subject: [PATCH 7/9] xfs_scrub_fail: advise recipients not to reply From: "Darrick J. Wong" To: djwong@kernel.org, cem@kernel.org Cc: linux-xfs@vger.kernel.org Message-ID: <170405001937.1800712.9925405322044646768.stgit@frogsfrogsfrogs> In-Reply-To: <170405001841.1800712.6745668619742020884.stgit@frogsfrogsfrogs> References: <170405001841.1800712.6745668619742020884.stgit@frogsfrogsfrogs> User-Agent: StGit/0.19 Precedence: bulk X-Mailing-List: linux-xfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Darrick J. Wong Advise recipients of the service failure emails that they should not try to reply to the automated service message. Signed-off-by: Darrick J. Wong Reviewed-by: Christoph Hellwig --- scrub/xfs_scrub_fail.in | 1 + 1 file changed, 1 insertion(+) diff --git a/scrub/xfs_scrub_fail.in b/scrub/xfs_scrub_fail.in index baa9d32d94c..5dffb541798 100755 --- a/scrub/xfs_scrub_fail.in +++ b/scrub/xfs_scrub_fail.in @@ -31,6 +31,7 @@ Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset=UTF-8 So sorry, the automatic xfs_scrub of ${mntpoint} on ${hostname} failed. +Please do not reply to this mesage. A log of what happened follows: ENDL From patchwork Sun Dec 31 22:54:25 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13507982 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 196FFC127 for ; Sun, 31 Dec 2023 22:54:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="P6wwxLfg" Received: by smtp.kernel.org (Postfix) with ESMTPSA id DA4CAC433C7; Sun, 31 Dec 2023 22:54:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1704063265; bh=BYlDyDWtyBF/4VCIge67/+sEa7q8LySRbsjeOSOkB50=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=P6wwxLfgrz+oGRVAgSFcP6IZvn/DCtO1TlzhRe/ja4yWrzn9uw+bBWpT8HcHVx1QM oUhM9LTPT5zH4x9NVSfuE58+ZvY29KbWB+VC8gHWStGzx4j2lEkih9vRFFpXtYQwEj RrGkc2rUnnddxaugBIOxKpVo59sDk6NK9iyfy+KBDXx+5izJgEU7StlGDfEPiCkcCZ 8AYR+aVxBV8CcxuRE+aVROAT9+9u9G+ES+/xm6yr5eXUViDgmWFIBj25TRXkSrnRq/ X+OxReavlECk+5mE81kIeRR6on9JR2O0ErHebkxVwqfn6lmgPlVb6alIDjvO3t3r68 /BY3kCtBEjCow== Date: Sun, 31 Dec 2023 14:54:25 -0800 Subject: [PATCH 8/9] xfs_scrub_fail: move executable script to /usr/libexec From: "Darrick J. Wong" To: djwong@kernel.org, cem@kernel.org Cc: Neal Gompa , linux-xfs@vger.kernel.org Message-ID: <170405001950.1800712.15718005791386216226.stgit@frogsfrogsfrogs> In-Reply-To: <170405001841.1800712.6745668619742020884.stgit@frogsfrogsfrogs> References: <170405001841.1800712.6745668619742020884.stgit@frogsfrogsfrogs> User-Agent: StGit/0.19 Precedence: bulk X-Mailing-List: linux-xfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Darrick J. Wong Per FHS 3.0, non-PATH executable binaries are supposed to live under /usr/libexec, not /usr/lib. xfs_scrub_fail is an executable script, so move it to libexec in case some distro some day tries to mount /usr/lib as noexec or something. Cc: Neal Gompa Link: https://refspecs.linuxfoundation.org/FHS_3.0/fhs/ch04s07.html Signed-off-by: Darrick J. Wong Reviewed-by: Neal Gompa Reviewed-by: Christoph Hellwig --- include/builddefs.in | 1 + scrub/Makefile | 7 +++---- scrub/xfs_scrub_fail@.service.in | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/include/builddefs.in b/include/builddefs.in index eb7f6ba4f03..9d0f9c3bf7c 100644 --- a/include/builddefs.in +++ b/include/builddefs.in @@ -52,6 +52,7 @@ PKG_ROOT_SBIN_DIR = @root_sbindir@ PKG_ROOT_LIB_DIR= @root_libdir@@libdirsuffix@ PKG_LIB_DIR = @libdir@@libdirsuffix@ PKG_LIB_SCRIPT_DIR = @libdir@ +PKG_LIBEXEC_DIR = @libexecdir@/@pkg_name@ PKG_INC_DIR = @includedir@/xfs DK_INC_DIR = @includedir@/disk PKG_MAN_DIR = @mandir@ diff --git a/scrub/Makefile b/scrub/Makefile index fd47b893956..8fb366c922c 100644 --- a/scrub/Makefile +++ b/scrub/Makefile @@ -140,8 +140,7 @@ install: $(INSTALL_SCRUB) @echo " [SED] $@" $(Q)$(SED) -e "s|@sbindir@|$(PKG_SBIN_DIR)|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" \ + -e "s|@pkg_libexec_dir@|$(PKG_LIBEXEC_DIR)|g" \ < $< > $@ %.cron: %.cron.in $(builddefs) @@ -151,8 +150,8 @@ install: $(INSTALL_SCRUB) install-systemd: default $(SYSTEMD_SERVICES) $(INSTALL) -m 755 -d $(SYSTEMD_SYSTEM_UNIT_DIR) $(INSTALL) -m 644 $(SYSTEMD_SERVICES) $(SYSTEMD_SYSTEM_UNIT_DIR) - $(INSTALL) -m 755 -d $(PKG_LIB_SCRIPT_DIR)/$(PKG_NAME) - $(INSTALL) -m 755 $(XFS_SCRUB_FAIL_PROG) $(PKG_LIB_SCRIPT_DIR)/$(PKG_NAME) + $(INSTALL) -m 755 -d $(PKG_LIBEXEC_DIR) + $(INSTALL) -m 755 $(XFS_SCRUB_FAIL_PROG) $(PKG_LIBEXEC_DIR) install-crond: default $(CRONTABS) $(INSTALL) -m 755 -d $(CROND_DIR) diff --git a/scrub/xfs_scrub_fail@.service.in b/scrub/xfs_scrub_fail@.service.in index 048b5732459..48a0f25b5f1 100644 --- a/scrub/xfs_scrub_fail@.service.in +++ b/scrub/xfs_scrub_fail@.service.in @@ -10,7 +10,7 @@ Documentation=man:xfs_scrub(8) [Service] Type=oneshot Environment=EMAIL_ADDR=root -ExecStart=@pkg_lib_dir@/@pkg_name@/xfs_scrub_fail "${EMAIL_ADDR}" %f +ExecStart=@pkg_libexec_dir@/xfs_scrub_fail "${EMAIL_ADDR}" %f User=mail Group=mail SupplementaryGroups=systemd-journal From patchwork Sun Dec 31 22:54:41 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13507983 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 35F5AC127 for ; Sun, 31 Dec 2023 22:54:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="UahYe9PM" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 8FF57C433C8; Sun, 31 Dec 2023 22:54:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1704063281; bh=weZVtNuwuFW8FMAuVzTSxje6A8pHRgD6V4zIxuqzp+Y=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=UahYe9PMC1MFnCKaPZRVqA90qv2Cexzk+1l8BEAPZm262lUJrw+Ga0kxlg31P9v0v b+b+sKT4mmormyhD1Z5OkENmzaRIPlU35L5KH2DOMpLqwRencKmzxRDfjCzXflSPmR RBuEG5Lmyb6CoMIymNnmZvXhGcZH8q/RNXcZgi2jjx9S5LMTfS6ERgHrOR/GxWTpcw 5SGBj7XPv77VLUAfawR5LkULTrEVISE5p1SJ9RZ/Cosb8LZC6Bc0D5Wu/nITGef9j3 es9fR3TqvzgzS1GN7MwE8Hbah25kf3kuCeA9ZWO8/WKnGh+LnSOKu96JKN4mtS8pFO UZtVGAGLssgZA== Date: Sun, 31 Dec 2023 14:54:41 -0800 Subject: [PATCH 9/9] xfs_scrub_all.cron: move to package data directory From: "Darrick J. Wong" To: djwong@kernel.org, cem@kernel.org Cc: linux-xfs@vger.kernel.org Message-ID: <170405001964.1800712.10514067731814883862.stgit@frogsfrogsfrogs> In-Reply-To: <170405001841.1800712.6745668619742020884.stgit@frogsfrogsfrogs> References: <170405001841.1800712.6745668619742020884.stgit@frogsfrogsfrogs> User-Agent: StGit/0.19 Precedence: bulk X-Mailing-List: linux-xfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Darrick J. Wong cron jobs don't belong in /usr/lib. Since the cron job is also secondary to the systemd timer, it's really only provided as a courtesy for distributions that don't use systemd. Move it to @datadir@, aka /usr/share/xfsprogs. Signed-off-by: Darrick J. Wong Reviewed-by: Neal Gompa Reviewed-by: Christoph Hellwig --- include/builddefs.in | 1 - scrub/Makefile | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/include/builddefs.in b/include/builddefs.in index 9d0f9c3bf7c..f5138b5098f 100644 --- a/include/builddefs.in +++ b/include/builddefs.in @@ -51,7 +51,6 @@ PKG_SBIN_DIR = @sbindir@ PKG_ROOT_SBIN_DIR = @root_sbindir@ PKG_ROOT_LIB_DIR= @root_libdir@@libdirsuffix@ PKG_LIB_DIR = @libdir@@libdirsuffix@ -PKG_LIB_SCRIPT_DIR = @libdir@ PKG_LIBEXEC_DIR = @libexecdir@/@pkg_name@ PKG_INC_DIR = @includedir@/xfs DK_INC_DIR = @includedir@/disk diff --git a/scrub/Makefile b/scrub/Makefile index 8fb366c922c..472df48a720 100644 --- a/scrub/Makefile +++ b/scrub/Makefile @@ -26,7 +26,7 @@ INSTALL_SCRUB += install-crond CRONTABS = xfs_scrub_all.cron OPTIONAL_TARGETS += $(CRONTABS) # Don't enable the crontab by default for now -CROND_DIR = $(PKG_LIB_SCRIPT_DIR)/$(PKG_NAME) +CROND_DIR = $(PKG_DATA_DIR) endif endif # scrub_prereqs