From patchwork Tue Dec 15 10:02:00 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chandan Rajendra X-Patchwork-Id: 7853031 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 E310F9F349 for ; Tue, 15 Dec 2015 10:03:41 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id DC1BA202C8 for ; Tue, 15 Dec 2015 10:03:37 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id B6F0B202A1 for ; Tue, 15 Dec 2015 10:03:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S964829AbbLOKD2 (ORCPT ); Tue, 15 Dec 2015 05:03:28 -0500 Received: from e28smtp04.in.ibm.com ([125.16.236.4]:37529 "EHLO e28smtp04.in.ibm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S964814AbbLOKD1 (ORCPT ); Tue, 15 Dec 2015 05:03:27 -0500 Received: from localhost by e28smtp04.in.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Tue, 15 Dec 2015 15:33:23 +0530 Received: from d28dlp03.in.ibm.com (9.184.220.128) by e28smtp04.in.ibm.com (192.168.1.134) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Tue, 15 Dec 2015 15:33:21 +0530 X-IBM-Helo: d28dlp03.in.ibm.com X-IBM-MailFrom: chandan@linux.vnet.ibm.com X-IBM-RcptTo: linux-btrfs@vger.kernel.org Received: from d28relay03.in.ibm.com (d28relay03.in.ibm.com [9.184.220.60]) by d28dlp03.in.ibm.com (Postfix) with ESMTP id 17F651258059 for ; Tue, 15 Dec 2015 15:33:48 +0530 (IST) Received: from d28av01.in.ibm.com (d28av01.in.ibm.com [9.184.220.63]) by d28relay03.in.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id tBFA3ILY7340446 for ; Tue, 15 Dec 2015 15:33:19 +0530 Received: from d28av01.in.ibm.com (localhost [127.0.0.1]) by d28av01.in.ibm.com (8.14.4/8.14.4/NCO v10.0 AVout) with ESMTP id tBFA22bM026248 for ; Tue, 15 Dec 2015 15:32:03 +0530 Received: from localhost.in.ibm.com ([9.124.35.197]) by d28av01.in.ibm.com (8.14.4/8.14.4/NCO v10.0 AVin) with ESMTP id tBFA22Ed026242; Tue, 15 Dec 2015 15:32:02 +0530 From: Chandan Rajendra To: linux-btrfs@vger.kernel.org Cc: Chandan Rajendra , dsterba@suse.cz, chandan@mykolab.com Subject: [PATCH] Btrfs-progs: ftw_add_entry_size: Round up file size to sectorsize Date: Tue, 15 Dec 2015 15:32:00 +0530 Message-Id: <1450173720-25543-1-git-send-email-chandan@linux.vnet.ibm.com> X-Mailer: git-send-email 2.1.0 X-TM-AS-MML: disable X-Content-Scanned: Fidelis XPS MAILER x-cbid: 15121510-0013-0000-0000-00000912C7EE 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 ftw_add_entry_size() assumes 4k as the block size of the underlying filesystem and hence the file sizes computed is incorrect for non-4k sectorsized filesystems. Fix this by rounding up file sizes to sectorsize. Signed-off-by: Chandan Rajendra --- mkfs.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/mkfs.c b/mkfs.c index c58ab2f..88c2289 100644 --- a/mkfs.c +++ b/mkfs.c @@ -1031,16 +1031,15 @@ out: * This ignores symlinks with unreadable targets and subdirs that can't * be read. It's a best-effort to give a rough estimate of the size of * a subdir. It doesn't guarantee that prepopulating btrfs from this - * tree won't still run out of space. - * - * The rounding up to 4096 is questionable. Previous code used du -B 4096. + * tree won't still run out of space. */ static u64 global_total_size; +static u64 fs_block_size; static int ftw_add_entry_size(const char *fpath, const struct stat *st, int type) { if (type == FTW_F || type == FTW_D) - global_total_size += round_up(st->st_size, 4096); + global_total_size += round_up(st->st_size, fs_block_size); return 0; } @@ -1060,6 +1059,7 @@ static u64 size_sourcedir(char *dir_name, u64 sectorsize, allocated_meta_size / default_chunk_size; global_total_size = 0; + fs_block_size = sectorsize; ret = ftw(dir_name, ftw_add_entry_size, 10); dir_size = global_total_size; if (ret < 0) {