From patchwork Tue Apr 8 09:16:02 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Qu Wenruo X-Patchwork-Id: 3948111 Return-Path: X-Original-To: patchwork-linux-btrfs@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 7EAE3BFF02 for ; Tue, 8 Apr 2014 09:15:12 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 53DE02037F for ; Tue, 8 Apr 2014 09:15:11 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 617A12037E for ; Tue, 8 Apr 2014 09:15:10 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754830AbaDHJPB (ORCPT ); Tue, 8 Apr 2014 05:15:01 -0400 Received: from cn.fujitsu.com ([59.151.112.132]:17365 "EHLO heian.cn.fujitsu.com" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S1750789AbaDHJPA (ORCPT ); Tue, 8 Apr 2014 05:15:00 -0400 X-IronPort-AV: E=Sophos;i="4.97,816,1389715200"; d="scan'208";a="28992638" Received: from unknown (HELO edo.cn.fujitsu.com) ([10.167.33.5]) by heian.cn.fujitsu.com with ESMTP; 08 Apr 2014 17:12:31 +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 s389EtQM024701; Tue, 8 Apr 2014 17:14:55 +0800 Received: from adam-work.lan (10.167.226.24) by G08CNEXCHPEKD03.g08.fujitsu.local (10.167.33.89) with Microsoft SMTP Server (TLS) id 14.3.146.2; Tue, 8 Apr 2014 17:15:01 +0800 From: Qu Wenruo To: CC: Anand Jain Subject: [PATCH] btrfs-progs: Fix the return value of btrfs_scan_kernel() Date: Tue, 8 Apr 2014 17:16:02 +0800 Message-ID: <1396948562-16653-1-git-send-email-quwenruo@cn.fujitsu.com> X-Mailer: git-send-email 1.9.1 MIME-Version: 1.0 X-Originating-IP: [10.167.226.24] Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org X-Spam-Status: No, score=-7.2 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, 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 btrfs_scan_kernel() is only used in 'btrfs fi show' but returns wrong return value. When search parameter is passed, it will never return 0 even the search can be matched. This patch will change the whatever strange logic to a more easy to understand one using 'found' var. Reported-by: Tsutomu Itoh Signed-off-by: Qu Wenruo Cc: Anand Jain --- cmds-filesystem.c | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/cmds-filesystem.c b/cmds-filesystem.c index b81768b..49d3aa7 100644 --- a/cmds-filesystem.c +++ b/cmds-filesystem.c @@ -430,6 +430,7 @@ static int btrfs_scan_kernel_v2(void *search) static int btrfs_scan_kernel(void *search) { int ret = 0, fd; + int found = 0; FILE *f; struct mntent *mnt; struct btrfs_ioctl_fs_info_args fs_info_arg; @@ -452,7 +453,6 @@ static int btrfs_scan_kernel(void *search) if (get_label_mounted(mnt->mnt_dir, label)) { kfree(dev_info_arg); - ret = 1; goto out; } if (search && !match_search_item_kernel(fs_info_arg.fsid, @@ -467,19 +467,16 @@ static int btrfs_scan_kernel(void *search) space_info_arg, label, mnt->mnt_dir); kfree(space_info_arg); memset(label, 0, sizeof(label)); + found = 1; } if (fd != -1) close(fd); kfree(dev_info_arg); - if (search) - ret = 0; } - if (search) - ret = 1; out: endmntent(f); - return ret; + return !found; } static int dev_to_fsid(char *dev, __u8 *fsid)