From: Eric Sandeen <sandeen@redhat.com>
To: ext4 development <linux-ext4@vger.kernel.org>
Subject: [PATCH e2fsprogs] properly calculate overhead in ext2fs_initialize()
Date: Fri, 20 Jul 2007 16:47:14 -0500 [thread overview]
Message-ID: <46A12D62.2010704@redhat.com> (raw)
For some odd geometries*, mkfs will try to allocate inode tables off
the end of the block group and fail, rather than warning that too
many inodes have been requested.
This is because when ext2fs_initialize calculates metadata overhead,
it is only adding in group descriptor blocks and the superblock
if the *last* bg contains them - but the first bg also has all of
the various metadata bits taking up space.
Unconditionally adding those counts into the overhead seems to fix
it properly.
*for example "mke2fs -b 1024 -m 0 -g 256 -N 3745 fsfile 1024"
(Note, the test here is a little funky; the expected output is
actually a mkfs failure - but a proper failure instead of the
allocator catching the problem at the last minute)
Signed-off-by: Eric Sandeen <sandeen@redhat.com>
Index: e2fsprogs-1.40.2/lib/ext2fs/initialize.c
===================================================================
--- e2fsprogs-1.40.2.orig/lib/ext2fs/initialize.c
+++ e2fsprogs-1.40.2/lib/ext2fs/initialize.c
@@ -299,15 +299,13 @@ ipg_retry:
/*
* Overhead is the number of bookkeeping blocks per group. It
- * includes the superblock backup, the group descriptor
- * backups, the inode bitmap, the block bitmap, and the inode
- * table.
+ * includes the superblock (or backup), the block bitmap, the
+ * inode bitmap, the inode table, the group descriptor (or
+ * backups), and the reserved gdt blocks.
*/
- overhead = (int) (2 + fs->inode_blocks_per_group);
-
- if (ext2fs_bg_has_super(fs, fs->group_desc_count - 1))
- overhead += 1 + fs->desc_blocks + super->s_reserved_gdt_blocks;
+ overhead = (int) (3 + fs->inode_blocks_per_group +
+ fs->desc_blocks + super->s_reserved_gdt_blocks);
/* This can only happen if the user requested too many inodes */
if (overhead > super->s_blocks_per_group)Index: e2fsprogs-1.40.2/tests/m_mkfs_overhead/expect.1
===================================================================
--- /dev/null
+++ e2fsprogs-1.40.2/tests/m_mkfs_overhead/expect.1
@@ -0,0 +1,10 @@
+./test.img: Cannot create filesystem with requested number of inodes while setting up superblock
+./test.img: Attempt to read block from filesystem resulted in short read while opening filesystem
+features: Filesystem not open
+
+../e2fsck/e2fsck: Attempt to read block from filesystem resulted in short read while trying to open ./test.img
+Could this be a zero-length partition?
+Exit status is 8
+
+../misc/dumpe2fs: Attempt to read block from filesystem resulted in short read while trying to open ./test.img
+Couldn't find valid filesystem superblock.
Index: e2fsprogs-1.40.2/tests/m_mkfs_overhead/script
===================================================================
--- /dev/null
+++ e2fsprogs-1.40.2/tests/m_mkfs_overhead/script
@@ -0,0 +1,5 @@
+DESCRIPTION="test bg overhead calculation"
+FS_SIZE=1024
+MKE2FS_OPTS="-b 1024 -m 0 -g 256 -N 3745"
+. $cmd_dir/run_mke2fs
+
next reply other threads:[~2007-07-20 21:52 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-07-20 21:47 Eric Sandeen [this message]
2007-07-22 19:31 ` [PATCH e2fsprogs] properly calculate overhead in ext2fs_initialize() Theodore Tso
2007-07-23 18:00 ` Eric Sandeen
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=46A12D62.2010704@redhat.com \
--to=sandeen@redhat.com \
--cc=linux-ext4@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).