From patchwork Tue Jan 16 07:26:55 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xiao Yang X-Patchwork-Id: 10166099 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 2C3A7603B5 for ; Tue, 16 Jan 2018 07:30:55 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1CC5B280FC for ; Tue, 16 Jan 2018 07:30:55 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 1B25B28179; Tue, 16 Jan 2018 07:30:55 +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.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI 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 BB319280FC for ; Tue, 16 Jan 2018 07:30:53 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1750765AbeAPHaw (ORCPT ); Tue, 16 Jan 2018 02:30:52 -0500 Received: from mail.cn.fujitsu.com ([183.91.158.132]:6704 "EHLO heian.cn.fujitsu.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1750716AbeAPHaw (ORCPT ); Tue, 16 Jan 2018 02:30:52 -0500 X-IronPort-AV: E=Sophos;i="5.43,368,1503331200"; d="scan'208";a="35357421" Received: from bogon (HELO cn.fujitsu.com) ([10.167.33.5]) by heian.cn.fujitsu.com with ESMTP; 16 Jan 2018 15:30:50 +0800 Received: from G08CNEXCHPEKD01.g08.fujitsu.local (unknown [10.167.33.80]) by cn.fujitsu.com (Postfix) with ESMTP id 500C248AEA13; Tue, 16 Jan 2018 15:30:48 +0800 (CST) Received: from RHEL7.5Alpha (10.167.220.29) by G08CNEXCHPEKD01.g08.fujitsu.local (10.167.33.89) with Microsoft SMTP Server (TLS) id 14.3.361.1; Tue, 16 Jan 2018 15:30:50 +0800 From: xiao yang To: CC: , , , , xiao yang Subject: [PATCH v4 1/3] common/xfs: Check if write supports [-c|-d] option in xfs_db Date: Tue, 16 Jan 2018 15:26:55 +0800 Message-ID: <1516087617-2077-1-git-send-email-yangx.jy@cn.fujitsu.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <20180116040254.GE3102@eguan.usersys.redhat.com> References: <20180116040254.GE3102@eguan.usersys.redhat.com> MIME-Version: 1.0 X-Originating-IP: [10.167.220.29] X-yoursite-MailScanner-ID: 500C248AEA13.A94B8 X-yoursite-MailScanner: Found to be clean X-yoursite-MailScanner-From: yangx.jy@cn.fujitsu.com Sender: fstests-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: fstests@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Make sure _scratch_xfs_set_metadata_field() can be used on an old xfsprogs-dev(e.g. v3.1.1). The "-d" option was introduced since xfsprogs-dev v4.7.0 by commit 86769b3 ("xfs_db: allow recalculating CRCs on invalid metadata"). The special argument "--" is only used to end option-scanning in getopt(). getopt() was introduced since xfsprogs-dev v3.2.3 by commit c9f5e3d ("xfs_db: Allow writes of corrupted data")'. Signed-off-by: xiao yang --- common/xfs | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/common/xfs b/common/xfs index 45b84a0..ab58364 100644 --- a/common/xfs +++ b/common/xfs @@ -658,8 +658,11 @@ _scratch_xfs_set_metadata_field() for arg in "$@"; do cmds+=("-c" "${arg}") done - _scratch_xfs_db -x "${cmds[@]}" -c "write -d ${key} -- ${value}" - echo + + local wr_cmd="write" + _scratch_xfs_db -x -c "help write" | egrep -q "(-c|-d)" && value="-- ${value}" + _scratch_xfs_db -x -c "help write" | egrep -q "(-d)" && wr_cmd="${wr_cmd} -d" + _scratch_xfs_db -x "${cmds[@]}" -c "${wr_cmd} ${key} ${value}" } _scratch_xfs_get_sb_field()