From patchwork Mon Feb 11 20:45:34 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Sandeen X-Patchwork-Id: 219681 Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 6D5062C02A4 for ; Tue, 12 Feb 2013 07:45:29 +1100 (EST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1759629Ab3BKUp2 (ORCPT ); Mon, 11 Feb 2013 15:45:28 -0500 Received: from mx1.redhat.com ([209.132.183.28]:48261 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1758813Ab3BKUp2 (ORCPT ); Mon, 11 Feb 2013 15:45:28 -0500 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id r1BKjRaE018482 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Mon, 11 Feb 2013 15:45:27 -0500 Received: from liberator.sandeen.net (ovpn01.gateway.prod.ext.phx2.redhat.com [10.5.9.1]) by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id r1BKjOA6002451 (version=TLSv1/SSLv3 cipher=DHE-RSA-CAMELLIA256-SHA bits=256 verify=NO) for ; Mon, 11 Feb 2013 15:45:25 -0500 Message-ID: <5119586E.8060400@redhat.com> Date: Mon, 11 Feb 2013 14:45:34 -0600 From: Eric Sandeen User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.8; rv:17.0) Gecko/20130107 Thunderbird/17.0.2 MIME-Version: 1.0 To: ext4 development Subject: [PATCH, RFC] mke2fs: set s_overhead_blocks X-Enigmail-Version: 1.5 X-Scanned-By: MIMEDefang 2.68 on 10.5.11.22 Sender: linux-ext4-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-ext4@vger.kernel.org The recent thread on the list about strange df behavior made me go look at how we were calculating s_overhead_blocks again, and I realized that mkfs still doesn't set it. It seems like a simple thing to do; just look at how many blocks are in use when mkfs is done. Signed-off-by: Eric Sandeen --- However, I realize that resize2fs breaks this. And by the time we have a populated fs, with bigalloc/meta/flex/whatnot, the calculation of overhead gets very tricky again. (at least for shrinking; growing is probably easier) Ted, did you have a better patch for this? You added the superblock field so maybe you had something in mind to keep it up to date as the filesystem size changes? -- To unsubscribe from this list: send the line "unsubscribe linux-ext4" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html diff --git a/misc/mke2fs.c b/misc/mke2fs.c index bbf477a..3413bb2 100644 --- a/misc/mke2fs.c +++ b/misc/mke2fs.c @@ -2346,6 +2346,38 @@ static int create_quota_inodes(ext2_filsys fs) return 0; } +/* + * Set the filesystem's metadata overhead - the number of blocks + * used for all mkfs-time metadata. We could carefully account + * for all blocks, or do it the easy way: See how many blocks + * have been used by mkfs, at the end of mkfs. Add the space used + * by the root dir and lost+found back in. + */ +void set_fs_overhead(ext2_filsys fs) { + unsigned int overhead; + struct ext2_inode inode; + ext2_ino_t inum; + blk64_t iblocks; + + /* overhead is everything mkfs has used ... */ + overhead = ext2fs_blocks_count(fs->super) - + ext2fs_free_blocks_count(fs->super); + + /* ... not counting / and /lost+found */ + if (!ext2fs_read_inode(fs, EXT2_ROOT_INO, &inode)) { + iblocks = ext2fs_inode_i_blocks(fs, &inode); + overhead -= (iblocks << 9) / fs->blocksize; + } + + if (!ext2fs_lookup(fs, EXT2_ROOT_INO, "lost+found", 10, 0, &inum) && + !ext2fs_read_inode(fs, inum, &inode)) { + iblocks = ext2fs_inode_i_blocks(fs, &inode); + overhead -= (iblocks << 9) / fs->blocksize; + } + + fs->super->s_overhead_blocks = overhead; +} + int main (int argc, char *argv[]) { errcode_t retval = 0; @@ -2733,6 +2764,8 @@ no_journal: EXT4_FEATURE_RO_COMPAT_QUOTA)) create_quota_inodes(fs); + set_fs_overhead(fs); + if (!quiet) printf(_("Writing superblocks and " "filesystem accounting information: "));