From patchwork Tue Oct 13 12:52:17 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhaolei X-Patchwork-Id: 7384941 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 CAE609F302 for ; Tue, 13 Oct 2015 12:54:08 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id E31CF205F4 for ; Tue, 13 Oct 2015 12:54:06 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id B667720787 for ; Tue, 13 Oct 2015 12:54:05 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752933AbbJMMyD (ORCPT ); Tue, 13 Oct 2015 08:54:03 -0400 Received: from cn.fujitsu.com ([59.151.112.132]:61924 "EHLO heian.cn.fujitsu.com" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S1752383AbbJMMyB (ORCPT ); Tue, 13 Oct 2015 08:54:01 -0400 X-IronPort-AV: E=Sophos;i="5.15,520,1432569600"; d="scan'208";a="101785227" Received: from unknown (HELO edo.cn.fujitsu.com) ([10.167.33.5]) by heian.cn.fujitsu.com with ESMTP; 13 Oct 2015 20:56:24 +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 t9DCrUV3019605 for ; Tue, 13 Oct 2015 20:53:30 +0800 Received: from localhost.localdomain (10.167.226.114) by G08CNEXCHPEKD01.g08.fujitsu.local (10.167.33.89) with Microsoft SMTP Server id 14.3.181.6; Tue, 13 Oct 2015 20:53:57 +0800 From: Zhao Lei To: CC: Zhao Lei Subject: [PATCH 1/3] btrfs-progs: mkfs: Remove saved_optind in mkfs.btrfs Date: Tue, 13 Oct 2015 20:52:17 +0800 Message-ID: <681908a6a06b67212a4be5868a682a793585e7e7.1444740703.git.zhaolei@cn.fujitsu.com> X-Mailer: git-send-email 1.8.5.1 In-Reply-To: References: MIME-Version: 1.0 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 No need to use complex logic for iter devs in mkfs.c, as backup optind, increase/decrease optind and reset dev_cnt. A simple for() loop is enough for above request. Signed-off-by: Zhao Lei --- mkfs.c | 25 +++++++------------------ 1 file changed, 7 insertions(+), 18 deletions(-) diff --git a/mkfs.c b/mkfs.c index 7fa7cfc..cdae94d 100644 --- a/mkfs.c +++ b/mkfs.c @@ -1354,7 +1354,6 @@ int main(int ac, char **av) u64 size_of_data = 0; u64 source_dir_size = 0; int dev_cnt = 0; - int saved_optind; char fs_uuid[BTRFS_UUID_UNPARSED_SIZE] = { 0 }; u64 features = BTRFS_MKFS_DEFAULT_FEATURES; struct mkfs_allocation allocation = { 0 }; @@ -1467,7 +1466,6 @@ int main(int ac, char **av) } sectorsize = max(sectorsize, (u32)sysconf(_SC_PAGESIZE)); - saved_optind = optind; dev_cnt = ac - optind; if (dev_cnt == 0) print_usage(1); @@ -1490,18 +1488,15 @@ int main(int ac, char **av) exit(1); } } - - while (dev_cnt-- > 0) { - file = av[optind++]; + + for (i = optind; i < optind + dev_cnt; i++) { + file = av[i]; if (is_block_device(file) == 1) if (test_dev_for_mkfs(file, force_overwrite)) exit(1); } - optind = saved_optind; - dev_cnt = ac - optind; - - file = av[optind++]; + file = av[optind]; ssd = is_ssd(file); if (is_vol_small(file) || mixed) { @@ -1557,7 +1552,7 @@ int main(int ac, char **av) btrfs_min_dev_size(nodesize)); exit(1); } - for (i = saved_optind; i < saved_optind + dev_cnt; i++) { + for (i = optind; i < optind + dev_cnt; i++) { char *path; path = av[i]; @@ -1588,8 +1583,6 @@ int main(int ac, char **av) printf("See %s for more information.\n\n", PACKAGE_URL); } - dev_cnt--; - if (!source_dir_set) { /* * open without O_EXCL so that the problem should not @@ -1720,13 +1713,10 @@ int main(int ac, char **av) if (is_block_device(file) == 1) btrfs_register_one_device(file); - if (dev_cnt == 0) - goto raid_groups; - - while (dev_cnt-- > 0) { + for (i = optind + 1; i < optind + dev_cnt; i++) { int old_mixed = mixed; - file = av[optind++]; + file = av[i]; /* * open without O_EXCL so that the problem should not @@ -1771,7 +1761,6 @@ int main(int ac, char **av) btrfs_register_one_device(file); } -raid_groups: if (!source_dir_set) { ret = create_raid_groups(trans, root, data_profile, metadata_profile, mixed, &allocation);