From patchwork Wed Jan 14 06:50:40 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Qu Wenruo X-Patchwork-Id: 5626001 Return-Path: X-Original-To: patchwork-linux-btrfs@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 9D98A9F358 for ; Wed, 14 Jan 2015 07:00:48 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id BBE4E20397 for ; Wed, 14 Jan 2015 07:00:47 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 38A3C2038D for ; Wed, 14 Jan 2015 07:00:46 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751355AbbANHAj (ORCPT ); Wed, 14 Jan 2015 02:00:39 -0500 Received: from cn.fujitsu.com ([59.151.112.132]:54734 "EHLO heian.cn.fujitsu.com" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S1751112AbbANHAi (ORCPT ); Wed, 14 Jan 2015 02:00:38 -0500 X-IronPort-AV: E=Sophos;i="5.04,848,1406563200"; d="scan'208";a="56033498" Received: from unknown (HELO edo.cn.fujitsu.com) ([10.167.33.5]) by heian.cn.fujitsu.com with ESMTP; 14 Jan 2015 14:57:09 +0800 Received: from G08CNEXCHPEKD02.g08.fujitsu.local (localhost.localdomain [127.0.0.1]) by edo.cn.fujitsu.com (8.14.3/8.13.1) with ESMTP id t0E6q6M4015742 for ; Wed, 14 Jan 2015 14:52:26 +0800 Received: from localhost.localdomain (10.167.226.33) by G08CNEXCHPEKD02.g08.fujitsu.local (10.167.33.89) with Microsoft SMTP Server (TLS) id 14.3.181.6; Wed, 14 Jan 2015 14:52:47 +0800 From: Qu Wenruo To: Subject: [PATCH] btrfs-progs: Fix wrong return value when executing 'fi show' on umounted device. Date: Wed, 14 Jan 2015 14:50:40 +0800 Message-ID: <1421218240-13159-1-git-send-email-quwenruo@cn.fujitsu.com> X-Mailer: git-send-email 2.2.1 MIME-Version: 1.0 X-Originating-IP: [10.167.226.33] Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@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 When executing 'btrfs fi show' on unmounted device, even no problem happens, the return value is still 1 not 0. The problem lies in search_umounted_fs_uuids(), where when it finds the given uuid, it should return 1, but later uuid copy overwrites the return value, causing it always return 0 under that case. Fix it by pass found as pointer, and return value only indicates whether anything wrong happens, whether found or not is stored in the new parameter. Signed-off-by: Qu Wenruo --- cmds-filesystem.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/cmds-filesystem.c b/cmds-filesystem.c index a3cf114..30a7cc4 100644 --- a/cmds-filesystem.c +++ b/cmds-filesystem.c @@ -700,7 +700,7 @@ static int has_seed_devices(struct btrfs_fs_devices *fs_devices) } static int search_umounted_fs_uuids(struct list_head *all_uuids, - char *search) + char *search, int *found) { struct btrfs_fs_devices *cur_fs, *fs_copy; struct list_head *fs_uuids; @@ -717,7 +717,8 @@ static int search_umounted_fs_uuids(struct list_head *all_uuids, if (search) { if (uuid_search(cur_fs, search) == 0) continue; - ret = 1; + if (found) + *found = 1; } /* skip all fs already shown as mounted fs */ @@ -922,8 +923,8 @@ devs_only: return 1; } - found = search_umounted_fs_uuids(&all_uuids, search); - if (found < 0) { + ret = search_umounted_fs_uuids(&all_uuids, search, &found); + if (ret < 0) { fprintf(stderr, "ERROR: %d while searching target device\n", ret); return 1;