From patchwork Thu Oct 30 02:44:49 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gui Hecheng X-Patchwork-Id: 5193161 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.19.201]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 5FCA99F349 for ; Thu, 30 Oct 2014 02:46:25 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id B565C20260 for ; Thu, 30 Oct 2014 02:46:20 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id AA0D420219 for ; Thu, 30 Oct 2014 02:46:18 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756627AbaJ3CqN (ORCPT ); Wed, 29 Oct 2014 22:46:13 -0400 Received: from cn.fujitsu.com ([59.151.112.132]:51131 "EHLO heian.cn.fujitsu.com" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S1756510AbaJ3CqN (ORCPT ); Wed, 29 Oct 2014 22:46:13 -0400 X-IronPort-AV: E=Sophos;i="5.04,815,1406563200"; d="scan'208";a="42577898" Received: from unknown (HELO edo.cn.fujitsu.com) ([10.167.33.5]) by heian.cn.fujitsu.com with ESMTP; 30 Oct 2014 10:43:03 +0800 Received: from G08CNEXCHPEKD01.g08.fujitsu.local (localhost.localdomain [127.0.0.1]) by edo.cn.fujitsu.com (8.14.3/8.13.1) with ESMTP id s9U2k3Ax032455 for ; Thu, 30 Oct 2014 10:46:03 +0800 Received: from localhost.localdomain (10.167.226.111) by G08CNEXCHPEKD01.g08.fujitsu.local (10.167.33.89) with Microsoft SMTP Server (TLS) id 14.3.181.6; Thu, 30 Oct 2014 10:46:22 +0800 From: Gui Hecheng To: CC: Gui Hecheng Subject: [PATCH 1/2] btrfs-progs: make the search target device routine more clear for fi show Date: Thu, 30 Oct 2014 10:44:49 +0800 Message-ID: <1414637090-4476-1-git-send-email-guihc.fnst@cn.fujitsu.com> X-Mailer: git-send-email 1.8.1.4 MIME-Version: 1.0 X-Originating-IP: [10.167.226.111] 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.5 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 Extract the procedure of searching for a target device for fi show from the @map_seed_devices() function to make it more clear. Signed-off-by: Gui Hecheng --- cmds-filesystem.c | 37 ++++++++++++++++++++++++++++--------- 1 file changed, 28 insertions(+), 9 deletions(-) diff --git a/cmds-filesystem.c b/cmds-filesystem.c index bb5881e..6437e57 100644 --- a/cmds-filesystem.c +++ b/cmds-filesystem.c @@ -742,14 +742,10 @@ static int find_and_copy_seed(struct btrfs_fs_devices *seed, return 1; } -static int map_seed_devices(struct list_head *all_uuids, - char *search, int *found) +static int search_umounted_fs_uuids(struct list_head *all_uuids, + char *search) { - struct btrfs_fs_devices *cur_fs, *cur_seed; - struct btrfs_fs_devices *fs_copy, *seed_copy; - struct btrfs_fs_devices *opened_fs; - struct btrfs_device *device; - struct btrfs_fs_info *fs_info; + struct btrfs_fs_devices *cur_fs, *fs_copy; struct list_head *fs_uuids; int ret = 0; @@ -764,7 +760,7 @@ static int map_seed_devices(struct list_head *all_uuids, if (search) { if (uuid_search(cur_fs, search) == 0) continue; - *found = 1; + ret = 1; } fs_copy = malloc(sizeof(*fs_copy)); @@ -782,6 +778,22 @@ static int map_seed_devices(struct list_head *all_uuids, list_add(&fs_copy->list, all_uuids); } +out: + return ret; +} + +static int map_seed_devices(struct list_head *all_uuids) +{ + struct btrfs_fs_devices *cur_fs, *cur_seed; + struct btrfs_fs_devices *seed_copy; + struct btrfs_fs_devices *opened_fs; + struct btrfs_device *device; + struct btrfs_fs_info *fs_info; + struct list_head *fs_uuids; + int ret = 0; + + fs_uuids = btrfs_scanned_uuids(); + list_for_each_entry(cur_fs, all_uuids, list) { device = list_first_entry(&cur_fs->devices, struct btrfs_device, dev_list); @@ -943,11 +955,18 @@ devs_only: return 1; } + found = search_umounted_fs_uuids(&all_uuids, search); + if (found < 0) { + fprintf(stderr, + "ERROR: %d while searching target device\n", ret); + return 1; + } + /* * scan_for_btrfs() don't build seed/sprout mapping, * do mapping build for each scanned fs here */ - ret = map_seed_devices(&all_uuids, search, &found); + ret = map_seed_devices(&all_uuids); if (ret) { fprintf(stderr, "ERROR: %d while mapping seed devices\n", ret);