From patchwork Sun Dec 21 18:07:18 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Goffredo Baroncelli X-Patchwork-Id: 5524571 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 B2708BEEA8 for ; Sun, 21 Dec 2014 18:05:51 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id B9CAF20117 for ; Sun, 21 Dec 2014 18:05:50 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 785A9200FE for ; Sun, 21 Dec 2014 18:05:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753204AbaLUSFp (ORCPT ); Sun, 21 Dec 2014 13:05:45 -0500 Received: from mail-wi0-f169.google.com ([209.85.212.169]:38933 "EHLO mail-wi0-f169.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752939AbaLUSFo (ORCPT ); Sun, 21 Dec 2014 13:05:44 -0500 Received: by mail-wi0-f169.google.com with SMTP id r20so8776917wiv.2 for ; Sun, 21 Dec 2014 10:05:43 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=ZaJ/nd8jRUOzZdgaAw05sPiF9CFgmpLF9JNR4qmaQUM=; b=Hcxz2hg8Bk0qXBgc+aEshwmaRyJTWPXJ8+US2zuY8XpsAdJwD5M+9HkWcB35cBlxrP EKt9b2iwG4dHUJ9ECdLqjXlDpjeSRLyw/bltJvHmhWikxQg3f2NHuv30XzkFJD/mCuwJ iIG90j5c6C5bum2pfVeYhnyQxfXZnmD78ypFbY9V36WH+9jaCcEIVVqyBZZu/iRN+8wI xRnYethiAGovEIqS+8b8F9GnQH7BLlrqsXnpRzRALY78wYyKY6Jnf2YMgLiOCiWqubvb va80/yor08NzauC56uvr7ZkC3htblfuru5qOSXRFxmMuxcLs5rC92gbNRrU7A2Vz0zhU LInQ== X-Received: by 10.194.81.38 with SMTP id w6mr34165751wjx.17.1419185143199; Sun, 21 Dec 2014 10:05:43 -0800 (PST) Received: from venice.bhome (ppp-212-98.24-151.libero.it. [151.24.98.212]) by mx.google.com with ESMTPSA id kn7sm13738620wjc.45.2014.12.21.10.05.42 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sun, 21 Dec 2014 10:05:42 -0800 (PST) From: Goffredo Baroncelli X-Google-Original-From: Goffredo Baroncelli To: linux-btrfs@vger.kernel.org Cc: Goffredo Baroncelli Subject: [PATCH][BTRFS-PROGS][CLEANUP] Remove gotos Date: Sun, 21 Dec 2014 19:07:18 +0100 Message-Id: <1419185238-4254-2-git-send-email-kreijack@inwind.it> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1419185238-4254-1-git-send-email-kreijack@inwind.it> References: <1419185238-4254-1-git-send-email-kreijack@inwind.it> 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.8 required=5.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, T_DKIM_INVALID, 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 Change a spagetti-style code (there are some "interlaced" gotos) to a more modern style... This patch removes also some #define from utils.h, which define constants used only in cmds-filesystems.c . Instead an enum is used locally in cmds-filesystems.c . --- cmds-filesystem.c | 106 ++++++++++++++++++++++++++++-------------------------- utils.h | 3 -- 2 files changed, 55 insertions(+), 54 deletions(-) diff --git a/cmds-filesystem.c b/cmds-filesystem.c index 7eaccb9..08ddb5d 100644 --- a/cmds-filesystem.c +++ b/cmds-filesystem.c @@ -40,6 +40,11 @@ #include "list_sort.h" #include "disk-io.h" +enum filesystem_show_scan_method { + BTRFS_SCAN_ANY, + BTRFS_SCAN_MOUNTED, + BTRFS_SCAN_LBLKID +}; /* * for btrfs fi show, we maintain a hash of fsids we've already printed. @@ -853,7 +858,7 @@ static int cmd_show(int argc, char **argv) char *search = NULL; int ret; /* default, search both kernel and udev */ - int where = -1; + int where = BTRFS_SCAN_ANY; int type = 0; char mp[BTRFS_PATH_NAME_MAX + 1]; char path[PATH_MAX]; @@ -930,61 +935,60 @@ static int cmd_show(int argc, char **argv) uuid_unparse(fsid, uuid_buf); search = uuid_buf; type = BTRFS_ARG_UUID; - goto devs_only; + where = BTRFS_SCAN_LBLKID; } } } - if (where == BTRFS_SCAN_LBLKID) - goto devs_only; - - /* show mounted btrfs */ - ret = btrfs_scan_kernel(search); - if (search && !ret) { - /* since search is found we are done */ - goto out; - } - - /* shows mounted only */ - if (where == BTRFS_SCAN_MOUNTED) - goto out; - -devs_only: - ret = btrfs_scan_lblkid(); - - if (ret) { - fprintf(stderr, "ERROR: %d while scanning\n", ret); - 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; - } - - /* - * The seed/sprout mapping are not detected yet, - * do mapping build for all umounted fs - */ - ret = map_seed_devices(&all_uuids); - if (ret) { - fprintf(stderr, - "ERROR: %d while mapping seed devices\n", ret); - return 1; + if (where == BTRFS_SCAN_MOUNTED || where == BTRFS_SCAN_ANY) { + + /* show mounted btrfs */ + ret = btrfs_scan_kernel(search); + if (search && !ret) { + /* since search is found we are done */ + goto out; + } + } - - list_for_each_entry(fs_devices, &all_uuids, list) - print_one_uuid(fs_devices); - - if (search && !found) - ret = 1; - - while (!list_empty(&all_uuids)) { - fs_devices = list_entry(all_uuids.next, - struct btrfs_fs_devices, list); - free_fs_devices(fs_devices); + + if (where == BTRFS_SCAN_LBLKID || where == BTRFS_SCAN_ANY) { + + ret = btrfs_scan_lblkid(); + + if (ret) { + fprintf(stderr, "ERROR: %d while scanning\n", ret); + 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; + } + + /* + * The seed/sprout mapping are not detected yet, + * do mapping build for all umounted fs + */ + ret = map_seed_devices(&all_uuids); + if (ret) { + fprintf(stderr, + "ERROR: %d while mapping seed devices\n", ret); + return 1; + } + + list_for_each_entry(fs_devices, &all_uuids, list) + print_one_uuid(fs_devices); + + if (search && !found) + ret = 1; + + while (!list_empty(&all_uuids)) { + fs_devices = list_entry(all_uuids.next, + struct btrfs_fs_devices, list); + free_fs_devices(fs_devices); + } } out: printf("%s\n", BTRFS_BUILD_VERSION); diff --git a/utils.h b/utils.h index 0464c2d..603cdfb 100644 --- a/utils.h +++ b/utils.h @@ -26,9 +26,6 @@ #define BTRFS_MKFS_SYSTEM_GROUP_SIZE (4 * 1024 * 1024) #define BTRFS_MKFS_SMALL_VOLUME_SIZE (1024 * 1024 * 1024) -#define BTRFS_SCAN_MOUNTED (1ULL << 0) -#define BTRFS_SCAN_LBLKID (1ULL << 1) - #define BTRFS_UPDATE_KERNEL 1 #define BTRFS_ARG_UNKNOWN 0