From patchwork Fri May 26 01:52:42 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: 13256166 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 86873C77B7E for ; Fri, 26 May 2023 01:52:47 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231495AbjEZBwq (ORCPT ); Thu, 25 May 2023 21:52:46 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41490 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229689AbjEZBwp (ORCPT ); Thu, 25 May 2023 21:52:45 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F37A8E7 for ; Thu, 25 May 2023 18:52:43 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 80C9C64C45 for ; Fri, 26 May 2023 01:52:43 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id E4B15C433D2; Fri, 26 May 2023 01:52:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1685065962; bh=hpP4MJ9V6YvRymh4jocqoLMyOjhd22/YYU85ABgSC4M=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=K7nJeDNFJdp7rPnHG6roVLT9TFl/XSogXwfrLpkX/1P/u3IyUIbpHaZ58c5s9qHm8 UfAZtiGMEwfUmuIfcEw3Dkij4oUqww80gQ4/Cbo7s2gIq8JaxLZSb6IfHUdZ99//B+ Q774fO/N9UYKAcVm6YtL2Yy6FmvmwMtNK5+XYzNUYw43+B9FDS0c64W389zzNVXDhT S5g3oEyCkt17A3wxVSpm3huwCgZ5H/IaPUl7anQXRRtCWkRkmqX0NmxcsLiv8sMzzV qwdu3SclYHOPkDHEl+A8/L0cd2dbX9Xq0M8j/7MDZuCb+lXo53kkDwp4P2TTEv0Dmm 7r6X0IkSU3aPQ== Date: Thu, 25 May 2023 18:52:42 -0700 Subject: [PATCH 1/5] debian: install scrub services with dh_installsystemd From: "Darrick J. Wong" To: djwong@kernel.org, cem@kernel.org Cc: linux-xfs@vger.kernel.org Message-ID: <168506073846.3745766.1338318814898903856.stgit@frogsfrogsfrogs> In-Reply-To: <168506073832.3745766.10929690168821459226.stgit@frogsfrogsfrogs> References: <168506073832.3745766.10929690168821459226.stgit@frogsfrogsfrogs> User-Agent: StGit/0.19 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-xfs@vger.kernel.org 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 Fri May 26 01:52:58 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: 13256167 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id A5377C7EE29 for ; Fri, 26 May 2023 01:53:02 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229689AbjEZBxB (ORCPT ); Thu, 25 May 2023 21:53:01 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41582 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229631AbjEZBxA (ORCPT ); Thu, 25 May 2023 21:53:00 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 96DD3E7 for ; Thu, 25 May 2023 18:52:59 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 3416963B77 for ; Fri, 26 May 2023 01:52:59 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 907C8C433D2; Fri, 26 May 2023 01:52:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1685065978; bh=Md+TWzSEeGGQTEiEVN5f2dIQ2HI7QO9lj9GspKoDH4o=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=f9we/6L9EC5EbVFJgZj+G6JEVAflk3F2WI/t2A8VSU2lpAz1/8cWehDy8ZCgXQ5KO dUe8kHus7A/77oEiG4ufXAD1cmPhCxt2XKa1UbXFfDxcjsVKnYN7v+5mqWa8h01z/w 17zG1Z6o+y4sxt1V/4+vYmdj+c5A68bnimAX85En/Qm1pKhQcF8Um7MSdAN1FoMqd/ x27BqZpwWGvYh5Uv6ENKwFy/HwmL0qnG9pA2cikjUAAUoP4NBTZe/wdnwowcwMcCK1 nvZKMseNtD2es8HJ75y7xpDpDBfVXEiMoJcS5HDhKqjClvLbOdCL6ovWs1Xox2ERVS M1Qd3VZ6kIchg== Date: Thu, 25 May 2023 18:52:58 -0700 Subject: [PATCH 2/5] xfs_scrub_all: escape service names consistently From: "Darrick J. Wong" To: djwong@kernel.org, cem@kernel.org Cc: linux-xfs@vger.kernel.org Message-ID: <168506073859.3745766.15701175812728914090.stgit@frogsfrogsfrogs> In-Reply-To: <168506073832.3745766.10929690168821459226.stgit@frogsfrogsfrogs> References: <168506073832.3745766.10929690168821459226.stgit@frogsfrogsfrogs> User-Agent: StGit/0.19 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-xfs@vger.kernel.org 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 d8264a3cb07..d4cb9bc7bb7 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 Fri May 26 01:53:13 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: 13256168 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id E1EC8C77B7E for ; Fri, 26 May 2023 01:53:18 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229631AbjEZBxR (ORCPT ); Thu, 25 May 2023 21:53:17 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41684 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229942AbjEZBxQ (ORCPT ); Thu, 25 May 2023 21:53:16 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3CA8318D for ; Thu, 25 May 2023 18:53:15 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id BFEF661B63 for ; Fri, 26 May 2023 01:53:14 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 2F576C433EF; Fri, 26 May 2023 01:53:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1685065994; bh=CKaqqFUa9VItpKU8fobegZDBfwpbBS5vwFYDuX41bkQ=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=r6U8YCbjXhw8bRvJ8vLfLyTa80h9sg4SxKTq/WgyVEObnDYDOQ3fpzUssJ3m6Jfty YaydVB6c/upd4aGR0R7D7gEerqZ5TpEAJmjjyk+TJMD1OmvkaG0Appvl1Sg7DPrFd7 cRjKdD1tBoTOhokqGYsGeFzY3AS4tx1pXQvGEU+3z/LlinUXKW5u9CKbcGvPxmANmz aKZzKuGGdpgvaJI9nPdTdmnno7c+kG6N1YG23cXZO/sFsHOy9drNipVZmrOIOPs8zR H+e0oUffxqP0n94ukicuchTOzriODzw+GTomIpVjoayQ+Vaem1hnwp/WULz1iY9m2J XnAdRaA9S/SIw== Date: Thu, 25 May 2023 18:53:13 -0700 Subject: [PATCH 3/5] xfs_scrub: fix pathname escaping across all service definitions From: "Darrick J. Wong" To: djwong@kernel.org, cem@kernel.org Cc: linux-xfs@vger.kernel.org Message-ID: <168506073873.3745766.7019908892401637437.stgit@frogsfrogsfrogs> In-Reply-To: <168506073832.3745766.10929690168821459226.stgit@frogsfrogsfrogs> References: <168506073832.3745766.10929690168821459226.stgit@frogsfrogsfrogs> User-Agent: StGit/0.19 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-xfs@vger.kernel.org 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 f6f8ebdc814..0cba97dcddc 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) @@ -103,17 +106,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) @@ -136,7 +147,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 2eb6be8fee2..81ca2043a82 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 d4cb9bc7bb7..060d8f66bfc 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 a1bc3b802ff..b154202815b 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 255d272e4cd..93e06a74410 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 Fri May 26 01:53:29 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: 13256169 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3C708C7EE29 for ; Fri, 26 May 2023 01:53:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229942AbjEZBxc (ORCPT ); Thu, 25 May 2023 21:53:32 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41736 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229890AbjEZBxb (ORCPT ); Thu, 25 May 2023 21:53:31 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B68A318D for ; Thu, 25 May 2023 18:53:30 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 522BB61295 for ; Fri, 26 May 2023 01:53:30 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id B24FAC433EF; Fri, 26 May 2023 01:53:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1685066009; bh=IJT8kuACDjUlGrRq3Si76H+zoOHiPJYCA88SuFREGmA=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=CQxhvf7ZZ2JnzsUjtqrRCQXCUpdckXloRw0S6lIGdptN2La4neygDQ1YdULlaXuLj XXnr0oGWH4NhbT3X0UPlP6JhbkYjXj3q+afsQ516+PEhSaz6FZhB2DY+hmGJU9w7Sh QytQu3Ud/YmUkvs4zu1kf1lbrIgfidAb5VPahiNQ2P0lA3FOS092092QlVsLR6rEKs 7RV19cCuTWQk3SIpfwfqXzDk4WeY1fZ1JvSCry2aVSaEd89Zt3JwSGs7vUHcjkSxt/ BBVmUrUgtLCNG/MFqa6NOjhy/a4Bk10Az7+suCqmOL0epJpOimJFHUG3YYJ34x8EtD FQyMfDsZ/JRAw== Date: Thu, 25 May 2023 18:53:29 -0700 Subject: [PATCH 4/5] xfs_scrub_fail: fix sendmail detection From: "Darrick J. Wong" To: djwong@kernel.org, cem@kernel.org Cc: linux-xfs@vger.kernel.org Message-ID: <168506073887.3745766.3554648508638613549.stgit@frogsfrogsfrogs> In-Reply-To: <168506073832.3745766.10929690168821459226.stgit@frogsfrogsfrogs> References: <168506073832.3745766.10929690168821459226.stgit@frogsfrogsfrogs> User-Agent: StGit/0.19 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-xfs@vger.kernel.org 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 b154202815b..a69be8a54cb 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 Fri May 26 01:53:44 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: 13256170 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5A601C77B7E for ; Fri, 26 May 2023 01:53:48 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229890AbjEZBxr (ORCPT ); Thu, 25 May 2023 21:53:47 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41760 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233496AbjEZBxq (ORCPT ); Thu, 25 May 2023 21:53:46 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4088F189 for ; Thu, 25 May 2023 18:53:46 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id D07B861298 for ; Fri, 26 May 2023 01:53:45 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 42CB9C433D2; Fri, 26 May 2023 01:53:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1685066025; bh=67n3qLMTUPziJjblmFHoAovqstmfXJeOAIJh23UhJsg=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=jeeK1JRn/mg9B2TZ6+pYlib55+O7/0vXjO1l+Pf2TzGfowszeLyBha/alEXs8cd8g DKtYefF/5o9gRVShAo23VjiKG6fqGpSE68U/7jbynD4wT25akr3kMLLoUchmhzQH5J Y69o7RtjU9IjLAsPx4DZJRQGnzGRrlSEvU7PiWm8s0KWzO1P4cKCbRlcDemRucFcxv w1Tvf3qLi6a2EdsGUWjmr4/emx+zK0E0yNHzPI0chUW1mgasxizPXgVFMh8pEVS0MF PKN14y2jtJuLh385UKfjGfZyRlamyY8v4qUlF7Ug3sevgOWAMxcgZCzJDyt5nDnLM9 /xm8/ui1qggLQ== Date: Thu, 25 May 2023 18:53:44 -0700 Subject: [PATCH 5/5] xfs_scrub_fail: return the failure status of the mailer program From: "Darrick J. Wong" To: djwong@kernel.org, cem@kernel.org Cc: linux-xfs@vger.kernel.org Message-ID: <168506073900.3745766.12097252494988640270.stgit@frogsfrogsfrogs> In-Reply-To: <168506073832.3745766.10929690168821459226.stgit@frogsfrogsfrogs> References: <168506073832.3745766.10929690168821459226.stgit@frogsfrogsfrogs> User-Agent: StGit/0.19 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-xfs@vger.kernel.org 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 a69be8a54cb..8f77e3d96cd 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]}"