Patchwork [RFC] mke2fs: set s_overhead_blocks

login
register
mail settings
Submitter Eric Sandeen
Date Feb. 11, 2013, 8:45 p.m.
Message ID <5119586E.8060400@redhat.com>
Download mbox | patch
Permalink /patch/219681/
State New
Headers show

Comments

Eric Sandeen - Feb. 11, 2013, 8:45 p.m.
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 <sandeen@redhat.com>
---

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

Patch

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: "));