From patchwork Fri Aug 30 08:50:37 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anand Jain X-Patchwork-Id: 2851831 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 5B9B4C0AB5 for ; Fri, 30 Aug 2013 08:44:16 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 07FBB202FF for ; Fri, 30 Aug 2013 08:44:15 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id B4C02202EC for ; Fri, 30 Aug 2013 08:44:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755250Ab3H3IoI (ORCPT ); Fri, 30 Aug 2013 04:44:08 -0400 Received: from userp1040.oracle.com ([156.151.31.81]:50604 "EHLO userp1040.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755228Ab3H3IoE (ORCPT ); Fri, 30 Aug 2013 04:44:04 -0400 Received: from ucsinet22.oracle.com (ucsinet22.oracle.com [156.151.31.94]) by userp1040.oracle.com (Sentrion-MTA-4.3.1/Sentrion-MTA-4.3.1) with ESMTP id r7U8i0EQ004729 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Fri, 30 Aug 2013 08:44:01 GMT Received: from aserz7021.oracle.com (aserz7021.oracle.com [141.146.126.230]) by ucsinet22.oracle.com (8.14.4+Sun/8.14.4) with ESMTP id r7U8hxTk005290 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Fri, 30 Aug 2013 08:44:00 GMT Received: from abhmt120.oracle.com (abhmt120.oracle.com [141.146.116.72]) by aserz7021.oracle.com (8.14.4+Sun/8.14.4) with ESMTP id r7U8hxct012070; Fri, 30 Aug 2013 08:43:59 GMT Received: from wish.sg.oracle.com (/10.186.101.18) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Fri, 30 Aug 2013 01:43:59 -0700 From: Anand Jain To: linux-btrfs@vger.kernel.org, dsterba@suse.cz Subject: [PATCH v2] btrfs-progs: mkfs should check for small vol well before Date: Fri, 30 Aug 2013 16:50:37 +0800 Message-Id: <1377852637-4299-1-git-send-email-anand.jain@oracle.com> X-Mailer: git-send-email 1.8.1.164.g2d0029e In-Reply-To: <1376657550-15011-1-git-send-email-anand.jain@oracle.com> References: <1376657550-15011-1-git-send-email-anand.jain@oracle.com> X-Source-IP: ucsinet22.oracle.com [156.151.31.94] Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org X-Spam-Status: No, score=-9.0 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable 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 This fix the regression introduced by 830427d that it no more creates the FS if disk is small and if no mixed option is provided. This patch will bring it to the original design which will force mixed profile when disk is small and go ahead to create the FS. Which also means that before we open the device for the write we should also check if disk is small. v2: fixes the checkpatch.pl warnings Signed-off-by: Anand Jain --- mkfs.c | 20 +++++++++++--------- utils.c | 29 +++++++++++++++++++++++++++++ utils.h | 1 + 3 files changed, 41 insertions(+), 9 deletions(-) diff --git a/mkfs.c b/mkfs.c index 73f5425..5b3b245 100644 --- a/mkfs.c +++ b/mkfs.c @@ -1415,6 +1415,17 @@ int main(int ac, char **av) file = av[optind++]; ssd = is_ssd(file); + if (is_vol_small(file)) { + printf("SMALL VOLUME: forcing mixed metadata/data groups\n"); + mixed = 1; + if (metadata_profile != data_profile) { + if (metadata_profile_opt || data_profile_opt) { + fprintf(stderr, + "With mixed block groups data and metadata profiles must be the same\n"); + exit(1); + } + } + } /* * Set default profiles according to number of added devices. * For mixed groups defaults are single/single. @@ -1435,7 +1446,6 @@ int main(int ac, char **av) BTRFS_BLOCK_GROUP_RAID0 : 0; /* raid0 or single */ } } else { - /* this is not needed but just for completeness */ metadata_profile = 0; data_profile = 0; } @@ -1494,14 +1504,6 @@ int main(int ac, char **av) } - if (mixed) { - if (metadata_profile != data_profile) { - fprintf(stderr, "With mixed block groups data and metadata " - "profiles must be the same\n"); - exit(1); - } - } - blocks[0] = BTRFS_SUPER_INFO_OFFSET; for (i = 1; i < 7; i++) { blocks[i] = BTRFS_SUPER_INFO_OFFSET + 1024 * 1024 + diff --git a/utils.c b/utils.c index de182e0..b039a03 100644 --- a/utils.c +++ b/utils.c @@ -1964,3 +1964,32 @@ int scan_for_btrfs(int where, int update_kernel) } return ret; } + +int is_vol_small(char *file) +{ + int fd = -1; + int e; + struct stat st; + u64 size; + + fd = open(file, O_RDONLY); + if (fd < 0) + return -errno; + if (fstat(fd, &st) < 0) { + e = -errno; + close(fd); + return e; + } + size = btrfs_device_size(fd, &st); + if (size == 0) { + close(fd); + return -1; + } + if (size < 1024 * 1024 * 1024) { + close(fd); + return 1; + } else { + close(fd); + return 0; + } +} diff --git a/utils.h b/utils.h index 4b449b8..eb6fba3 100644 --- a/utils.h +++ b/utils.h @@ -82,4 +82,5 @@ int get_label_mounted(const char *mount_path, char *labelp); int test_num_disk_vs_raid(u64 metadata_profile, u64 data_profile, u64 dev_cnt, int mixed, char *estr); int get_btrfs_mount(const char *dev, char *mp, size_t mp_size); +int is_vol_small(char *file); #endif