From patchwork Fri Dec 30 22:18:31 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13085161 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 6D644C4332F for ; Sat, 31 Dec 2022 00:34:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235712AbiLaAeC (ORCPT ); Fri, 30 Dec 2022 19:34:02 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33766 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235655AbiLaAeC (ORCPT ); Fri, 30 Dec 2022 19:34:02 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 76B9A1DDE4 for ; Fri, 30 Dec 2022 16:34:01 -0800 (PST) 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 1314561C63 for ; Sat, 31 Dec 2022 00:34:01 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 70E03C433EF; Sat, 31 Dec 2022 00:34:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1672446840; bh=hpP4MJ9V6YvRymh4jocqoLMyOjhd22/YYU85ABgSC4M=; h=Subject:From:To:Cc:Date:In-Reply-To:References:From; b=aFsvZ97Da0kBK2QI4dWZ0ZqQr9+zlj1m4jBs9jlfmsuC+5vI7b8svqJ0no1NXQ/GF OKGXwJu0hdbKqIIakNdarSgEvjph6RZ5l9HbiCBy9HK9dHtst3P/3gE6nC5oxoNEwY E+FTOadWPwRhWdKjjQadlpBmGW/oM4Glalbv+XY5E1bbliELO7pOaRa1NLCs9yJHoc RfvSswqaKhYHfof/YC17+JBQHdYWdOoYafdAhMnOlCT+IPLljtHtN07mfALvdejYsY 9fhkQrCr002MFCQ7qG301XD0d1lKGKEMKI9/1H3Gi64JsHydC8NKIo0vMuRMUL46do WAnLss6/l3EqA== Subject: [PATCH 1/8] debian: install scrub services with dh_installsystemd From: "Darrick J. Wong" To: cem@kernel.org, djwong@kernel.org Cc: linux-xfs@vger.kernel.org Date: Fri, 30 Dec 2022 14:18:31 -0800 Message-ID: <167243871113.717702.9657625631265376492.stgit@magnolia> In-Reply-To: <167243871097.717702.15336500890922415647.stgit@magnolia> References: <167243871097.717702.15336500890922415647.stgit@magnolia> 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 --- 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 Dec 30 22:18:31 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13085162 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 04F83C3DA7C for ; Sat, 31 Dec 2022 00:34:22 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235655AbiLaAeV (ORCPT ); Fri, 30 Dec 2022 19:34:21 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33802 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235739AbiLaAeU (ORCPT ); Fri, 30 Dec 2022 19:34:20 -0500 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A665F1EAC0 for ; Fri, 30 Dec 2022 16:34:18 -0800 (PST) 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 ams.source.kernel.org (Postfix) with ESMTPS id 5D03EB81DCC for ; Sat, 31 Dec 2022 00:34:17 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 0845AC433D2; Sat, 31 Dec 2022 00:34:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1672446856; bh=gHkUpoL5ErM6WSK2LzdXFjgpnYxQD8zL3JsPsj1902k=; h=Subject:From:To:Cc:Date:In-Reply-To:References:From; b=rtLUYo4zmM9+0xMqZmqYVvYptnpgk+fmSf9LkAnbvApqVTOAe2JiP0i0LHehMaeXT SzDA/TsvPLgFGMGeG7iVaInMh8bI2ZQPk7lxOL/Cvc63EFTFfiOeL2oYqlvm8v5ZrJ 9wlLfncWlyNDVdP3LWxZOpzdkZNAIQcFXmQb53hBL7W9XnAsY+p4JCEak4FiTgxAAb 5C0NduU+h5RqvtqDHM+8ttILAl1Jc8ynhQDtFv5+NJ1BAfjEbEhRHgB/RZkHs1DdsJ DPECLE1OY2kW+NFTfD91Gmwt6pYsqYNcq1XLxmvJ8ZkL6pFEIobEUgxYLF/Z8PJYdd spKZv9kTE/uKw== Subject: [PATCH 2/8] xfs_scrub: add missing copyrights and spdx headers From: "Darrick J. Wong" To: cem@kernel.org, djwong@kernel.org Cc: linux-xfs@vger.kernel.org Date: Fri, 30 Dec 2022 14:18:31 -0800 Message-ID: <167243871124.717702.7783784861015870036.stgit@magnolia> In-Reply-To: <167243871097.717702.15336500890922415647.stgit@magnolia> References: <167243871097.717702.15336500890922415647.stgit@magnolia> 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 Add missing license and copyright information to the systemd control files in this directory. Signed-off-by: Darrick J. Wong --- scrub/xfs_scrub@.service.in | 5 +++++ scrub/xfs_scrub_all.cron.in | 5 +++++ scrub/xfs_scrub_all.service.in | 5 +++++ scrub/xfs_scrub_all.timer | 5 +++++ scrub/xfs_scrub_fail | 5 +++++ scrub/xfs_scrub_fail@.service.in | 5 +++++ 6 files changed, 30 insertions(+) diff --git a/scrub/xfs_scrub@.service.in b/scrub/xfs_scrub@.service.in index 6fb3f6ea2e9..c8662fc85a6 100644 --- a/scrub/xfs_scrub@.service.in +++ b/scrub/xfs_scrub@.service.in @@ -1,3 +1,8 @@ +# SPDX-License-Identifier: GPL-2.0 +# +# Copyright (C) 2018 Oracle. All Rights Reserved. +# Author: Darrick J. Wong + [Unit] Description=Online XFS Metadata Check for %I OnFailure=xfs_scrub_fail@%i.service diff --git a/scrub/xfs_scrub_all.cron.in b/scrub/xfs_scrub_all.cron.in index 3dea9296077..0ef97cc0ca8 100644 --- a/scrub/xfs_scrub_all.cron.in +++ b/scrub/xfs_scrub_all.cron.in @@ -1 +1,6 @@ +# SPDX-License-Identifier: GPL-2.0 +# +# Copyright (C) 2018 Oracle. All Rights Reserved. +# Author: Darrick J. Wong +# 10 3 * * 0 root test -e /run/systemd/system || @sbindir@/xfs_scrub_all diff --git a/scrub/xfs_scrub_all.service.in b/scrub/xfs_scrub_all.service.in index b1b80da40a3..b874eb6f757 100644 --- a/scrub/xfs_scrub_all.service.in +++ b/scrub/xfs_scrub_all.service.in @@ -1,3 +1,8 @@ +# SPDX-License-Identifier: GPL-2.0 +# +# Copyright (C) 2018 Oracle. All Rights Reserved. +# Author: Darrick J. Wong + [Unit] Description=Online XFS Metadata Check for All Filesystems ConditionACPower=true diff --git a/scrub/xfs_scrub_all.timer b/scrub/xfs_scrub_all.timer index 2e4a33b1666..1aef11e18f9 100644 --- a/scrub/xfs_scrub_all.timer +++ b/scrub/xfs_scrub_all.timer @@ -1,3 +1,8 @@ +# SPDX-License-Identifier: GPL-2.0 +# +# Copyright (C) 2018 Oracle. All Rights Reserved. +# Author: Darrick J. Wong + [Unit] Description=Periodic XFS Online Metadata Check for All Filesystems diff --git a/scrub/xfs_scrub_fail b/scrub/xfs_scrub_fail index 36dd50e9653..8ada5dbbe06 100755 --- a/scrub/xfs_scrub_fail +++ b/scrub/xfs_scrub_fail @@ -1,5 +1,10 @@ #!/bin/bash +# SPDX-License-Identifier: GPL-2.0 +# +# Copyright (C) 2018 Oracle. All Rights Reserved. +# Author: Darrick J. Wong + # Email logs of failed xfs_scrub unit runs mailer=/usr/sbin/sendmail diff --git a/scrub/xfs_scrub_fail@.service.in b/scrub/xfs_scrub_fail@.service.in index 8d106e9ba4b..ac0cb2e283b 100644 --- a/scrub/xfs_scrub_fail@.service.in +++ b/scrub/xfs_scrub_fail@.service.in @@ -1,3 +1,8 @@ +# SPDX-License-Identifier: GPL-2.0 +# +# Copyright (C) 2018 Oracle. All Rights Reserved. +# Author: Darrick J. Wong + [Unit] Description=Online XFS Metadata Check Failure Reporting for %I Documentation=man:xfs_scrub(8) From patchwork Fri Dec 30 22:18:31 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13085163 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 1A9E9C4332F for ; Sat, 31 Dec 2022 00:34:40 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235702AbiLaAei (ORCPT ); Fri, 30 Dec 2022 19:34:38 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33902 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235715AbiLaAef (ORCPT ); Fri, 30 Dec 2022 19:34:35 -0500 Received: from sin.source.kernel.org (sin.source.kernel.org [IPv6:2604:1380:40e1:4800::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2492F1EAC0 for ; Fri, 30 Dec 2022 16:34:35 -0800 (PST) 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 sin.source.kernel.org (Postfix) with ESMTPS id 73A7BCE19DF for ; Sat, 31 Dec 2022 00:34:33 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id B54A1C433D2; Sat, 31 Dec 2022 00:34:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1672446871; bh=hC8eHGeZ+n4lVRpOHeU/AA1l4ZjE8aISGHaoGAvlLxE=; h=Subject:From:To:Cc:Date:In-Reply-To:References:From; b=kwn1OLqh2+sEVcvWGLjDnbCTUT5XfkcJ1h/V8OASNRiyucfvGcbof1UxGIGbstEd6 eTCIrC3LkEeTnK6PmnIqZojDUEl3U5U3/oN/9fd5E+T1c5e5VHjUedSzH/Uen/hmST M1iGGwUGnnmP8lKo8p683GXBTnCGLmefIdSHPThp5SZ9YgBC+dz6IGaDGRdN5nRJn4 438LKkKunU/u6QZlcZwZAEzv7dzZU0mnVOEifVsr9GT7ipE4G4kaCdRMUiuXZ2Fv67 3e5ZtXsuNymrD8eGnIeNW1NEihDecLkHTzMgSIi+wYjudBQRsKkGHKdJIEFf3dbJ1X VkWrquEGUxg9Q== Subject: [PATCH 3/8] xfs_scrub_fail: fix sendmail detection From: "Darrick J. Wong" To: cem@kernel.org, djwong@kernel.org Cc: linux-xfs@vger.kernel.org Date: Fri, 30 Dec 2022 14:18:31 -0800 Message-ID: <167243871137.717702.7724582296047344762.stgit@magnolia> In-Reply-To: <167243871097.717702.15336500890922415647.stgit@magnolia> References: <167243871097.717702.15336500890922415647.stgit@magnolia> 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 --- scrub/xfs_scrub_fail | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/scrub/xfs_scrub_fail b/scrub/xfs_scrub_fail index 8ada5dbbe06..a46eb34ee29 100755 --- a/scrub/xfs_scrub_fail +++ b/scrub/xfs_scrub_fail @@ -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 Dec 30 22:18:31 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13085164 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 852E9C4332F for ; Sat, 31 Dec 2022 00:34:53 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235715AbiLaAew (ORCPT ); Fri, 30 Dec 2022 19:34:52 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34096 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235435AbiLaAev (ORCPT ); Fri, 30 Dec 2022 19:34:51 -0500 Received: from sin.source.kernel.org (sin.source.kernel.org [145.40.73.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E85E41DDE4 for ; Fri, 30 Dec 2022 16:34:50 -0800 (PST) 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 sin.source.kernel.org (Postfix) with ESMTPS id 3D9EFCE19BB for ; Sat, 31 Dec 2022 00:34:49 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 77076C433D2; Sat, 31 Dec 2022 00:34:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1672446887; bh=NpOtt+luzMwEzyMdzcmGAxqYzLtP5I0Ek93HIUJWdWk=; h=Subject:From:To:Cc:Date:In-Reply-To:References:From; b=gNkZebnY0JPFjkONUMwALl0u9NJY1fWt+FhtY0ep4+AtYTga4oEtKMita1H4MxpNZ 9KvzP+15BmUOgBMD0QfbZrNpWw82ufZ6js32e3ab8Md/muZ9WSUJOXWThOuLOezdPg y2Dn1euTA3LFkqQoem7OVs2SnO4smHOc6nfyuOig0hOdCkREWlFevqUEyPx2h9/3FO rL+EW8m6joCEl5d0huoEiFTid33Q3IGfod6xQpMk/Ni3nNRMO5WUjgl8DExyb1FGx6 3e/Jz8NhcFEM4h/ne5FVaDHorzkO7NT1Y6HUyFt5rkmP7c8XgVN6CoKhpwbTOAkjTc J12iqGCnMb3Ig== Subject: [PATCH 4/8] xfs_scrub_fail: escape paths correctly From: "Darrick J. Wong" To: cem@kernel.org, djwong@kernel.org Cc: linux-xfs@vger.kernel.org Date: Fri, 30 Dec 2022 14:18:31 -0800 Message-ID: <167243871150.717702.9536987936805993820.stgit@magnolia> In-Reply-To: <167243871097.717702.15336500890922415647.stgit@magnolia> References: <167243871097.717702.15336500890922415647.stgit@magnolia> 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 Always escape pathnames correctly so that systemd doesn't complain. Signed-off-by: Darrick J. Wong --- scrub/xfs_scrub_fail | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/scrub/xfs_scrub_fail b/scrub/xfs_scrub_fail index a46eb34ee29..4ec7e48836a 100755 --- a/scrub/xfs_scrub_fail +++ b/scrub/xfs_scrub_fail @@ -20,6 +20,32 @@ if [ ! -x "${mailer}" ]; then exit 1 fi +# 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. +escape_path() { + local arg="$1" + + if [ "${arg}" = "/" ]; then + echo "-" + exit 0 + fi + + echo "-$(systemd-escape --path "${mntpoint}")" +} + +mntpoint_esc="$(escape_path "${mntpoint}")" + (cat << ENDL To: $1 From: @@ -29,4 +55,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 "xfs_scrub@${mntpoint_esc}") | "${mailer}" -t -i From patchwork Fri Dec 30 22:18:31 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13085165 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 C859CC4332F for ; Sat, 31 Dec 2022 00:35:08 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235739AbiLaAfH (ORCPT ); Fri, 30 Dec 2022 19:35:07 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34112 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235435AbiLaAfG (ORCPT ); Fri, 30 Dec 2022 19:35:06 -0500 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B5A5A1DDE4 for ; Fri, 30 Dec 2022 16:35:05 -0800 (PST) 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 ams.source.kernel.org (Postfix) with ESMTPS id 78373B80883 for ; Sat, 31 Dec 2022 00:35:04 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 2C5D2C433EF; Sat, 31 Dec 2022 00:35:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1672446903; bh=b7ljo0En4q++GnEO7bOXZ/k2e/2L4zIqzdWIpmampXI=; h=Subject:From:To:Cc:Date:In-Reply-To:References:From; b=prnzzmCpuqZmTS0uC1QM5JG72ctqXwhrF9cDskGLPDBiSj7WHWbQjcaiE0LMwYctd BJnYvJydUcHdwdmyTni/0WJWw1POsVnN9fzuhKIU8XZCbD6aKIRHEvCNKeCIb3V5LK QoQe/gbGNduF/4wm+TUqXXb9GJBTBOEDI6BTIkVJNDEZ2R5VVigPZ+ANDJfu6tcArw WvQD8rqbkakBghJZlYQnKyG/wx0yCsKcqeZEoTqig17fLds9AtyEEGwJtOMycZArvK q6c0oVPmh7LsTjCUk+KI9nvpzJd/OwDZUtVrEdZ/xDtSQnmi5P1gs1uH6mAbZyDlYZ YOuk2haTdWj1Q== Subject: [PATCH 5/8] xfs_scrub_fail: return the failure status of the mailer program From: "Darrick J. Wong" To: cem@kernel.org, djwong@kernel.org Cc: linux-xfs@vger.kernel.org Date: Fri, 30 Dec 2022 14:18:31 -0800 Message-ID: <167243871164.717702.12178389387628868397.stgit@magnolia> In-Reply-To: <167243871097.717702.15336500890922415647.stgit@magnolia> References: <167243871097.717702.15336500890922415647.stgit@magnolia> 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 --- scrub/xfs_scrub_fail | 1 + 1 file changed, 1 insertion(+) diff --git a/scrub/xfs_scrub_fail b/scrub/xfs_scrub_fail index 4ec7e48836a..fbe30cbc4c6 100755 --- a/scrub/xfs_scrub_fail +++ b/scrub/xfs_scrub_fail @@ -56,3 +56,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_esc}") | "${mailer}" -t -i +exit "${PIPESTATUS[1]}" From patchwork Fri Dec 30 22:18:31 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13085166 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 4751CC4332F for ; Sat, 31 Dec 2022 00:35:23 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235745AbiLaAfV (ORCPT ); Fri, 30 Dec 2022 19:35:21 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34128 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235435AbiLaAfU (ORCPT ); Fri, 30 Dec 2022 19:35:20 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D779D1DDE4 for ; Fri, 30 Dec 2022 16:35:19 -0800 (PST) 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 7474061C63 for ; Sat, 31 Dec 2022 00:35:19 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id D1E0BC433D2; Sat, 31 Dec 2022 00:35:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1672446918; bh=Bodft67axSWtEbIInsJXd2K4KfRR/Y1t3ertYWCMpiU=; h=Subject:From:To:Cc:Date:In-Reply-To:References:From; b=l+tqnlzEz7Fod5xXdXd+qsH8XpH7NHLsn5lhjvUm/WTmKj9nXcIxyGIyQYPL3YuUN R6E+0ZTKlFOms2WUoZI7UVJtlZsxA/WQt63lBA4FeZlIphPTTscjaHka9eVMm16JK7 jZ8yFRCJnnh1NsOMDdE2nyLbbUz1lB22b1k1e0NShX3CzhpTiS9tAg7pI5QCg81N9W CX82AeznSOO3QRpryjAnIsvTnY9APqacdW0dgwdgcsbFb9rvuFrF+V3YS0eYnf7nvd x6Zf8FtH8y3rSLD3Un0iXmBOYqcsF9PW9YhPKsa9u2eHmLAtL4T5Qa5M0P/7YEbd8n ZJlGhOTcA8BPw== Subject: [PATCH 6/8] xfs_scrub_all: fix argument passing when invoking xfs_scrub manually From: "Darrick J. Wong" To: cem@kernel.org, djwong@kernel.org Cc: linux-xfs@vger.kernel.org Date: Fri, 30 Dec 2022 14:18:31 -0800 Message-ID: <167243871177.717702.7249068927476129957.stgit@magnolia> In-Reply-To: <167243871097.717702.15336500890922415647.stgit@magnolia> References: <167243871097.717702.15336500890922415647.stgit@magnolia> 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 Currently, xfs_scrub_all will try to invoke xfs_scrub with argv[1] being "-n -x". This of course is recognized by C getopt as a weird looking string, not two individual arguments, and causes the child process to exit with complaints about CLI usage. What we really want is to split the string into a proper array and then add them to the xfs_scrub command line. The code here isn't strictly correct, but as @scrub_args@ is controlled by us in the Makefile, it'll do for now. Signed-off-by: Darrick J. Wong --- scrub/xfs_scrub_all.in | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/scrub/xfs_scrub_all.in b/scrub/xfs_scrub_all.in index 5b76b49adab..32bcfb15f5a 100644 --- a/scrub/xfs_scrub_all.in +++ b/scrub/xfs_scrub_all.in @@ -132,7 +132,9 @@ def run_scrub(mnt, cond, running_devs, mntdevs, killfuncs): return # Invoke xfs_scrub manually - cmd=['@sbindir@/xfs_scrub', '@scrub_args@', mnt] + cmd = ['@sbindir@/xfs_scrub'] + cmd += '@scrub_args@'.split() + cmd += [mnt] ret = run_killable(cmd, None, killfuncs, \ lambda proc: proc.terminate()) if ret >= 0: From patchwork Fri Dec 30 22:18:31 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13085167 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 3CB05C4332F for ; Sat, 31 Dec 2022 00:35:40 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235435AbiLaAfj (ORCPT ); Fri, 30 Dec 2022 19:35:39 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34166 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235798AbiLaAfi (ORCPT ); Fri, 30 Dec 2022 19:35:38 -0500 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3B9081EAC0 for ; Fri, 30 Dec 2022 16:35:37 -0800 (PST) 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 ams.source.kernel.org (Postfix) with ESMTPS id E839CB81DC6 for ; Sat, 31 Dec 2022 00:35:35 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 9E20FC433EF; Sat, 31 Dec 2022 00:35:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1672446934; bh=3doS7mPzmxLI5OkHlaRQFbj7TN/gXQiD46AlCPwLjAM=; h=Subject:From:To:Cc:Date:In-Reply-To:References:From; b=cqbDhf4xdP2fol+ZTo2mNcD1qHpXcOTt1tYtWeHmmFACETapK4YjxUMPnB9SkEf+K eovrWfhbkDP16BeJ8w7uMjxFME/ecZy19z/rVu2w9KtF4r4SDHuafMKXg/9r2CX9DM D3whOH2HTgNltoMeJmB9YliW+6WKTVO2NSxpsB7wgRnqWrcYVWdc/k2GFvxOqb3ajx da75poUtZjbVdaWSGSemJ8TMLNkqBrV5wa6ov0b9ubfh6eXQMA+YZ3hZgN1lhTfU7w m8+wQqt3FhR4V1jIS7FOXMzHdWQ9fcfd4UaER3k0EjS1KfBtH/GibPja1BZwF1PtnT Bwh2ac1GZaKAA== Subject: [PATCH 7/8] xfs_scrub_all: escape service names consistently From: "Darrick J. Wong" To: cem@kernel.org, djwong@kernel.org Cc: linux-xfs@vger.kernel.org Date: Fri, 30 Dec 2022 14:18:31 -0800 Message-ID: <167243871191.717702.13948258598750867603.stgit@magnolia> In-Reply-To: <167243871097.717702.15336500890922415647.stgit@magnolia> References: <167243871097.717702.15336500890922415647.stgit@magnolia> 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 In commit 07c6fd59, I fixed this script so that it would escape pathnames correctly when passing them as unit instance variables to systemctl start. Unfortunately, I neglected to do this for systemctl stop, which leads to warnings if someone hit ^C while the program is running from a CLI. Fix that, and name the unit name variable consistently. Fixes: 07c6fd59 ("xfs_scrub_all: escape paths being passed to systemd service instances") Signed-off-by: Darrick J. Wong --- scrub/xfs_scrub_all.in | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/scrub/xfs_scrub_all.in b/scrub/xfs_scrub_all.in index 32bcfb15f5a..2bdbccffd9c 100644 --- a/scrub/xfs_scrub_all.in +++ b/scrub/xfs_scrub_all.in @@ -58,10 +58,10 @@ def find_mounts(): return fs -def kill_systemd(unit, proc): +def kill_systemd(unitname, proc): '''Kill systemd unit.''' proc.terminate() - cmd=['systemctl', 'stop', unit] + cmd = ['systemctl', 'stop', unitname] x = subprocess.Popen(cmd) x.wait() @@ -119,9 +119,10 @@ def run_scrub(mnt, cond, running_devs, mntdevs, killfuncs): return # Try it the systemd way - cmd=['systemctl', 'start', 'xfs_scrub@%s' % systemd_escape(mnt)] + unitname = 'xfs_scrub@%s' % systemd_escape(mnt) + cmd = ['systemctl', 'start', unitname] ret = run_killable(cmd, DEVNULL(), killfuncs, \ - lambda proc: kill_systemd('xfs_scrub@%s' % mnt, proc)) + lambda proc: kill_systemd(unitname, proc)) if ret == 0 or ret == 1: print("Scrubbing %s done, (err=%d)" % (mnt, ret)) sys.stdout.flush() From patchwork Fri Dec 30 22:18:32 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13085168 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 43FE5C4332F for ; Sat, 31 Dec 2022 00:35:57 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235777AbiLaAf4 (ORCPT ); Fri, 30 Dec 2022 19:35:56 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34470 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235750AbiLaAfz (ORCPT ); Fri, 30 Dec 2022 19:35:55 -0500 Received: from sin.source.kernel.org (sin.source.kernel.org [IPv6:2604:1380:40e1:4800::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C0AD712A9B for ; Fri, 30 Dec 2022 16:35:53 -0800 (PST) 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 sin.source.kernel.org (Postfix) with ESMTPS id 1A1B5CE1A94 for ; Sat, 31 Dec 2022 00:35:52 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 48597C433EF; Sat, 31 Dec 2022 00:35:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1672446950; bh=PoauaQzO0cPN8emQdPOl+YoqXrb5acYl7m8JTFZJbac=; h=Subject:From:To:Cc:Date:In-Reply-To:References:From; b=b3B+582uYI8Nl2hDoy603JJSI8kjGnUq682cZ0JM9tFXvdm4I7xLuxOC43UNv65HE agXeKBWukm1PveeoEDl2AAKf2sKR2EK28UB1ccOa09YALuFxxFFmSNdBJ/IlaqG2ZU bu26iDx1vm5aIbecDaGC6wM9BT0/Co4cKYb8q0e0worIEjknPxOEwssWpo7UR6CpiF qtqv0DsuEMl3smbySccP37WxFxY/BLrJH12b/h42OSdoQTRFvN8lvqWVIVAulxA6fD G7/CitH4OY9n2rOykFX4Z1yV1viia188tyXM3fI3NcjzfvoY0CbG0HNZQOr44c2lMa 2/UBPnmrZhgRQ== Subject: [PATCH 8/8] xfs_scrub_all: survive systemd restarts when waiting for services From: "Darrick J. Wong" To: cem@kernel.org, djwong@kernel.org Cc: linux-xfs@vger.kernel.org Date: Fri, 30 Dec 2022 14:18:32 -0800 Message-ID: <167243871205.717702.16197845816644006295.stgit@magnolia> In-Reply-To: <167243871097.717702.15336500890922415647.stgit@magnolia> References: <167243871097.717702.15336500890922415647.stgit@magnolia> 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 If xfs_scrub_all detects a running systemd, it will use it to invoke xfs_scrub subprocesses in a sandboxed and resource-controlled environment. Unfortunately, if you happen to restart dbus or systemd while it's running, you get this: systemd[1]: Reexecuting. xfs_scrub_all[9958]: Warning! D-Bus connection terminated. xfs_scrub_all[9956]: Warning! D-Bus connection terminated. xfs_scrub_all[9956]: Failed to wait for response: Connection reset by peer xfs_scrub_all[9958]: Failed to wait for response: Connection reset by peer xfs_scrub_all[9930]: Scrubbing / done, (err=1) xfs_scrub_all[9930]: Scrubbing /storage done, (err=1) The xfs_scrub units themselves are still running, it's just that the `systemctl start' command that xfs_scrub_all uses to start and wait for the unit lost its connection to dbus and hence is no longer monitoring sub-services. When this happens, we don't have great options -- systemctl doesn't have a command to wait on an activating (aka running) unit. Emulate the functionality we normally get by polling the failed/active statuses. Signed-off-by: Darrick J. Wong --- scrub/xfs_scrub_all.in | 78 ++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 65 insertions(+), 13 deletions(-) diff --git a/scrub/xfs_scrub_all.in b/scrub/xfs_scrub_all.in index 2bdbccffd9c..3e0c48acb39 100644 --- a/scrub/xfs_scrub_all.in +++ b/scrub/xfs_scrub_all.in @@ -14,6 +14,7 @@ import time import sys import os import argparse +from io import TextIOWrapper retcode = 0 terminate = False @@ -58,12 +59,18 @@ def find_mounts(): return fs -def kill_systemd(unitname, proc): - '''Kill systemd unit.''' - proc.terminate() - cmd = ['systemctl', 'stop', unitname] - x = subprocess.Popen(cmd) - x.wait() +def backtick(cmd): + '''Generator function that yields lines of a program's stdout.''' + p = subprocess.Popen(cmd, stdout = subprocess.PIPE) + for line in TextIOWrapper(p.stdout, encoding="utf-8"): + yield line.strip() + +def remove_killfunc(killfuncs, fn): + '''Ensure fn is not in killfuncs.''' + try: + killfuncs.remove(fn) + except: + pass def run_killable(cmd, stdout, killfuncs, kill_fn): '''Run a killable program. Returns program retcode or -1 if we can't start it.''' @@ -72,10 +79,7 @@ def run_killable(cmd, stdout, killfuncs, kill_fn): real_kill_fn = lambda: kill_fn(proc) killfuncs.add(real_kill_fn) proc.wait() - try: - killfuncs.remove(real_kill_fn) - except: - pass + remove_killfunc(killfuncs, real_kill_fn) return proc.returncode except: return -1 @@ -107,6 +111,56 @@ def systemd_escape(path): except: return path +def systemctl_stop(unitname): + '''Stop a systemd unit.''' + cmd = ['systemctl', 'stop', unitname] + x = subprocess.Popen(cmd) + x.wait() + +def systemctl_start(unitname, killfuncs): + '''Start a systemd unit and wait for it to complete.''' + stop_fn = None + cmd = ['systemctl', 'start', unitname] + try: + proc = subprocess.Popen(cmd, stdout = DEVNULL()) + stop_fn = lambda: systemctl_stop(unitname) + killfuncs.add(stop_fn) + proc.wait() + ret = proc.returncode + except: + if stop_fn is not None: + remove_killfunc(killfuncs, stop_fn) + return -1 + + if ret != 1: + remove_killfunc(killfuncs, stop_fn) + return ret + + # If systemctl-start returns 1, it's possible that the service failed + # or that dbus/systemd restarted and the client program lost its + # connection -- according to the systemctl man page, 1 means "unit not + # failed". + # + # Either way, we switch to polling the service status to try to wait + # for the service to end. As of systemd 249, the is-active command + # returns any of the following states: active, reloading, inactive, + # failed, activating, deactivating, or maintenance. Apparently these + # strings are not localized. + while True: + try: + for l in backtick(['systemctl', 'is-active', unitname]): + if l == 'failed': + remove_killfunc(killfuncs, stop_fn) + return 1 + if l == 'inactive': + remove_killfunc(killfuncs, stop_fn) + return 0 + except: + remove_killfunc(killfuncs, stop_fn) + return -1 + + time.sleep(1) + def run_scrub(mnt, cond, running_devs, mntdevs, killfuncs): '''Run a scrub process.''' global retcode, terminate @@ -120,9 +174,7 @@ def run_scrub(mnt, cond, running_devs, mntdevs, killfuncs): # Try it the systemd way unitname = 'xfs_scrub@%s' % systemd_escape(mnt) - cmd = ['systemctl', 'start', unitname] - ret = run_killable(cmd, DEVNULL(), killfuncs, \ - lambda proc: kill_systemd(unitname, proc)) + ret = systemctl_start(unitname, killfuncs) if ret == 0 or ret == 1: print("Scrubbing %s done, (err=%d)" % (mnt, ret)) sys.stdout.flush()