Skip to content

Commit 3c816de

Browse files
Eric Whitneytytso
authored andcommitted
ext4: use journal inode to determine journal overhead
When a file system contains an internal journal that has not been loaded, use the journal inode's i_size field to determine its contribution to the file system's overhead. (The journal's j_maxlen field is normally used to determine its size, but it's unavailable when the journal has not been loaded.) Signed-off-by: Eric Whitney <enwlinux@gmail.com> Signed-off-by: Theodore Ts'o <tytso@mit.edu>
1 parent c6cb7e7 commit 3c816de

1 file changed

Lines changed: 17 additions & 2 deletions

File tree

‎fs/ext4/super.c‎

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3210,6 +3210,8 @@ int ext4_calculate_overhead(struct super_block *sb)
32103210
{
32113211
struct ext4_sb_info *sbi = EXT4_SB(sb);
32123212
struct ext4_super_block *es = sbi->s_es;
3213+
struct inode *j_inode;
3214+
unsigned int j_blocks, j_inum = le32_to_cpu(es->s_journal_inum);
32133215
ext4_group_t i, ngroups = ext4_get_groups_count(sb);
32143216
ext4_fsblk_t overhead = 0;
32153217
char *buf = (char *) get_zeroed_page(GFP_NOFS);
@@ -3240,10 +3242,23 @@ int ext4_calculate_overhead(struct super_block *sb)
32403242
memset(buf, 0, PAGE_SIZE);
32413243
cond_resched();
32423244
}
3243-
/* Add the internal journal blocks as well */
3245+
3246+
/*
3247+
* Add the internal journal blocks whether the journal has been
3248+
* loaded or not
3249+
*/
32443250
if (sbi->s_journal && !sbi->journal_bdev)
32453251
overhead += EXT4_NUM_B2C(sbi, sbi->s_journal->j_maxlen);
3246-
3252+
else if (ext4_has_feature_journal(sb) && !sbi->s_journal) {
3253+
j_inode = ext4_get_journal_inode(sb, j_inum);
3254+
if (j_inode) {
3255+
j_blocks = j_inode->i_size >> sb->s_blocksize_bits;
3256+
overhead += EXT4_NUM_B2C(sbi, j_blocks);
3257+
iput(j_inode);
3258+
} else {
3259+
ext4_msg(sb, KERN_ERR, "can't get journal size");
3260+
}
3261+
}
32473262
sbi->s_overhead = overhead;
32483263
smp_wmb();
32493264
free_page((unsigned long) buf);

0 commit comments

Comments
 (0)