From patchwork Mon Feb 16 02:27:33 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhaolei X-Patchwork-Id: 5831071 Return-Path: X-Original-To: patchwork-fstests@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 7A232BF440 for ; Mon, 16 Feb 2015 02:28:58 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id A15E820219 for ; Mon, 16 Feb 2015 02:28:57 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 77B9C20154 for ; Mon, 16 Feb 2015 02:28:56 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752213AbbBPC24 (ORCPT ); Sun, 15 Feb 2015 21:28:56 -0500 Received: from cn.fujitsu.com ([59.151.112.132]:16955 "EHLO heian.cn.fujitsu.com" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S1752085AbbBPC2z convert rfc822-to-8bit (ORCPT ); Sun, 15 Feb 2015 21:28:55 -0500 X-IronPort-AV: E=Sophos;i="5.04,848,1406563200"; d="scan'208";a="57638445" Received: from unknown (HELO edo.cn.fujitsu.com) ([10.167.33.5]) by heian.cn.fujitsu.com with ESMTP; 16 Feb 2015 10:25:20 +0800 Received: from G08CNEXCHPEKD03.g08.fujitsu.local (localhost.localdomain [127.0.0.1]) by edo.cn.fujitsu.com (8.14.3/8.13.1) with ESMTP id t1G2S6Ei026726; Mon, 16 Feb 2015 10:28:06 +0800 Received: from G08FNSTD110808 (10.167.226.21) by G08CNEXCHPEKD03.g08.fujitsu.local (10.167.33.89) with Microsoft SMTP Server id 14.3.181.6; Mon, 16 Feb 2015 10:28:54 +0800 From: Zhao Lei To: "'Dave Chinner'" CC: References: <1423745294-20408-1-git-send-email-zhaolei@cn.fujitsu.com> <20150215230454.GF12722@dastard> In-Reply-To: <20150215230454.GF12722@dastard> Subject: RE: [PATCH] Fix warning of "Usage: _is_block_dev dev" Date: Mon, 16 Feb 2015 10:27:33 +0800 Message-ID: <000d01d04990$1eea6360$5cbf2a20$@cn.fujitsu.com> MIME-Version: 1.0 X-Mailer: Microsoft Outlook 15.0 Thread-Index: AQJM1xcCxJ6EMcndBmWQDBn8ZLy5hQKI3p1rm+UobrA= Content-Language: zh-cn Sender: fstests-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: fstests@vger.kernel.org X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, T_RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Hi, > -----Original Message----- > From: Dave Chinner [mailto:david@fromorbit.com] > Sent: Monday, February 16, 2015 7:05 AM > To: Zhaolei > Cc: fstests@vger.kernel.org > Subject: Re: [PATCH] Fix warning of "Usage: _is_block_dev dev" > > On Thu, Feb 12, 2015 at 08:48:14PM +0800, Zhaolei wrote: > > From: Zhao Lei > > > > _is_block_dev() will show above warning when "$dev" is not exist. > > It happened when user hadn't set $SCRATCH_DEV(optional) and check > > $TEST_DEV. > > _is_block_dev() is used in many places to check whether the block device exists. > i.e. I'd suggest that _is_block_dev() should return an empty string to indicate > it's not a block device rather than exit if a null. That means we don't have to > execute _is_block_dev() in a subshell (i.e. via `_is_block_dev ...`) to prevent it > from killing the script that runs it if the block device passed to it is null. > > That means we don't have to add checks everywhere it is called, and we can > simplify the calling convention at the same time.... > Thanks for your suggestion. Are you mean this? It is clean than before, but we still need call _is_block_dev() in a subshell to get its return string. If we want to avoid calling _is_block_dev in a subshell, we can do following change: _is_block_dev() { return 1 if "$1" is not block dev } _same_dev() { return 1 if "$1" and "$2" are not same dev } And caller code will be: if [ ! _is_block_dev "$SCRATCH_DEV" -o _same_dev "$SCRATCH_DEV" "$TEST_DEV" ] then _notrun "this test requires a valid \$SCRATCH_DEV" fi Thanks Zhaolei > Cheers, > > Dave. > -- > Dave Chinner > david@fromorbit.com --- To unsubscribe from this list: send the line "unsubscribe fstests" 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/common/rc b/common/rc index 7449a1d..12861b8 100644 --- a/common/rc +++ b/common/rc @@ -951,8 +951,7 @@ _is_block_dev() { if [ $# -ne 1 ] then - echo "Usage: _is_block_dev dev" 1>&2 - exit 1 + return fi _dev=$1 @@ -1095,7 +1094,7 @@ _require_scratch_nocheck() fi ;; *) - if [ -z "$SCRATCH_DEV" -o "`_is_block_dev $SCRATCH_DEV`" = "" ] + if [ "`_is_block_dev $SCRATCH_DEV`" = "" ] then _notrun "this test requires a valid \$SCRATCH_DEV" fi @@ -1167,7 +1166,7 @@ _require_test() fi ;; *) - if [ -z "$TEST_DEV" -o "`_is_block_dev $TEST_DEV`" = "" ] + if [ "`_is_block_dev $TEST_DEV`" = "" ] then _notrun "this test requires a valid \$TEST_DEV" Fi