From patchwork Wed Mar 21 03:41:00 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 10298511 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 6F0BA600CC for ; Wed, 21 Mar 2018 03:41:07 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5E4EE295F9 for ; Wed, 21 Mar 2018 03:41:07 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 514872962D; Wed, 21 Mar 2018 03:41:07 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI, T_DKIM_INVALID, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D4830295F9 for ; Wed, 21 Mar 2018 03:41:06 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751832AbeCUDlG (ORCPT ); Tue, 20 Mar 2018 23:41:06 -0400 Received: from userp2130.oracle.com ([156.151.31.86]:55380 "EHLO userp2130.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751687AbeCUDlF (ORCPT ); Tue, 20 Mar 2018 23:41:05 -0400 Received: from pps.filterd (userp2130.oracle.com [127.0.0.1]) by userp2130.oracle.com (8.16.0.22/8.16.0.22) with SMTP id w2L3aQYR175659; Wed, 21 Mar 2018 03:41:03 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=subject : from : to : cc : date : message-id : in-reply-to : references : mime-version : content-type : content-transfer-encoding; s=corp-2017-10-26; bh=JmmM+RFAgTlBY0AZKQFdqZuUSLVtG1s0emsKXJgXl/o=; b=V9nfbk3cWM1U7K5tVa+87WRqMdrncP+0JFhWoP++ZRXV//noaQgrQRQrZO2KXFBjFvNl 2F7YtDOZdrtymn2scCJdEJN4YRxtBMTH4Q1FwUsb9UKsO3qFzWDRFWSYSMEmyiEvRxdf d4RIyH3/3h8LmSYvV7IVeA29V7EXdTc3F8ffQGcz8yB2mfXHzWJMvGQj4X/IyMWibAX+ qzQW5SNtIum9wtpPtvBqIVwbGD3vImsEwPgHhpF1UNaKFOFVu3jKxic9FQ2vAIhfFVy6 +11DG1Uo9aYwZR+RR0bBs0zZXUpp9GTwxqTxH6hJrNFqUnIW8ePt0cAHmZYFF1roPZSJ 8A== Received: from aserv0022.oracle.com (aserv0022.oracle.com [141.146.126.234]) by userp2130.oracle.com with ESMTP id 2gufmk00a8-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 21 Mar 2018 03:41:03 +0000 Received: from aserv0121.oracle.com (aserv0121.oracle.com [141.146.126.235]) by aserv0022.oracle.com (8.14.4/8.14.4) with ESMTP id w2L3f2WN008127 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 21 Mar 2018 03:41:02 GMT Received: from abhmp0018.oracle.com (abhmp0018.oracle.com [141.146.116.24]) by aserv0121.oracle.com (8.14.4/8.13.8) with ESMTP id w2L3f2xP018947; Wed, 21 Mar 2018 03:41:02 GMT Received: from localhost (/10.159.242.221) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Tue, 20 Mar 2018 20:41:02 -0700 Subject: [PATCH 13/14] xfs_scrub_all: escape paths being passed to systemd service instances From: "Darrick J. Wong" To: sandeen@redhat.com, darrick.wong@oracle.com Cc: linux-xfs@vger.kernel.org Date: Tue, 20 Mar 2018 20:41:00 -0700 Message-ID: <152160366039.8288.1390627066543987632.stgit@magnolia> In-Reply-To: <152160358015.8288.2700156777231657519.stgit@magnolia> References: <152160358015.8288.2700156777231657519.stgit@magnolia> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=nai engine=5900 definitions=8838 signatures=668695 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=9 malwarescore=0 phishscore=0 bulkscore=0 spamscore=0 mlxscore=0 mlxlogscore=656 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1711220000 definitions=main-1803200127 Sender: linux-xfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-xfs@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Darrick J. Wong 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. Signed-off-by: Darrick J. Wong Reviewed-by: Eric Sandeen --- scrub/xfs_scrub_all.in | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) -- To unsubscribe from this list: send the line "unsubscribe linux-xfs" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html diff --git a/scrub/xfs_scrub_all.in b/scrub/xfs_scrub_all.in index aed66a1..83c4e21 100644 --- a/scrub/xfs_scrub_all.in +++ b/scrub/xfs_scrub_all.in @@ -87,6 +87,28 @@ def run_killable(cmd, stdout, killfuncs, kill_fn): except: 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. +def systemd_escape(path): + '''Escape a path to avoid mangled systemd mangling.''' + + if '-' not in path: + return path + 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() + except: + return path + def run_scrub(mnt, cond, running_devs, mntdevs, killfuncs): '''Run a scrub process.''' global retcode, terminate @@ -99,7 +121,7 @@ def run_scrub(mnt, cond, running_devs, mntdevs, killfuncs): return # Try it the systemd way - cmd=['systemctl', 'start', 'xfs_scrub@%s' % mnt] + 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: