From: Jan Kara <jack@suse.cz>
To: Ted Tso <tytso@mit.edu>
Cc: <linux-ext4@vger.kernel.org>, Jan Kara <jack@suse.cz>
Subject: [PATCH] tune2fs: Update overhead when toggling journal feature
Date: Mon, 14 Jun 2021 23:28:30 +0200 [thread overview]
Message-ID: <20210614212830.20207-1-jack@suse.cz> (raw)
When adding or removing journal from a filesystem, we also need to add /
remove journal blocks from overhead stored in the superblock. Otherwise
total number of blocks in the filesystem as reported by statfs(2) need
not match reality and could lead to odd results like negative number of
used blocks reported by df(1).
Signed-off-by: Jan Kara <jack@suse.cz>
---
misc/tune2fs.c | 10 ++++++++--
1 file changed, 8 insertions(+), 2 deletions(-)
diff --git a/misc/tune2fs.c b/misc/tune2fs.c
index 4d4cf5a13384..2f6858abda32 100644
--- a/misc/tune2fs.c
+++ b/misc/tune2fs.c
@@ -396,6 +396,8 @@ static errcode_t remove_journal_inode(ext2_filsys fs)
_("while clearing journal inode"));
return retval;
}
+ fs->super->s_overhead_clusters -=
+ EXT2FS_NUM_B2C(fs, EXT2_I_SIZE(&inode) / fs->blocksize);
memset(&inode, 0, sizeof(inode));
ext2fs_mark_bb_dirty(fs);
fs->flags &= ~EXT2_FLAG_SUPER_ONLY;
@@ -1663,8 +1665,12 @@ static int add_journal(ext2_filsys fs)
com_err(program_name, retval, "%s",
_("\n\twhile trying to create journal file"));
return retval;
- } else
- fputs(_("done\n"), stdout);
+ }
+ fs->super->s_overhead_clusters += EXT2FS_NUM_B2C(fs,
+ jparams.num_journal_blocks + jparams.num_fc_blocks);
+ ext2fs_mark_super_dirty(fs);
+ fputs(_("done\n"), stdout);
+
/*
* If the filesystem wasn't mounted, we need to force
* the block group descriptors out.
--
2.26.2
next reply other threads:[~2021-06-14 21:28 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-06-14 21:28 Jan Kara [this message]
2021-06-14 21:38 ` [PATCH] tune2fs: Update overhead when toggling journal feature Andreas Dilger
2021-06-15 7:52 ` Jan Kara
2021-07-07 2:28 ` Theodore Ts'o
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=20210614212830.20207-1-jack@suse.cz \
--to=jack@suse.cz \
--cc=linux-ext4@vger.kernel.org \
--cc=tytso@mit.edu \
/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).