linux-ext4.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] tune2fs: Update overhead when toggling journal feature
@ 2021-06-14 21:28 Jan Kara
  2021-06-14 21:38 ` Andreas Dilger
  2021-07-07  2:28 ` Theodore Ts'o
  0 siblings, 2 replies; 4+ messages in thread
From: Jan Kara @ 2021-06-14 21:28 UTC (permalink / raw)
  To: Ted Tso; +Cc: linux-ext4, Jan Kara

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


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH] tune2fs: Update overhead when toggling journal feature
  2021-06-14 21:28 [PATCH] tune2fs: Update overhead when toggling journal feature Jan Kara
@ 2021-06-14 21:38 ` Andreas Dilger
  2021-06-15  7:52   ` Jan Kara
  2021-07-07  2:28 ` Theodore Ts'o
  1 sibling, 1 reply; 4+ messages in thread
From: Andreas Dilger @ 2021-06-14 21:38 UTC (permalink / raw)
  To: Jan Kara; +Cc: Ted Tso, Ext4 Developers List

[-- Attachment #1: Type: text/plain, Size: 1942 bytes --]


> On Jun 14, 2021, at 3:28 PM, Jan Kara <jack@suse.cz> wrote:
> 
> 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>

You could add:

Fixes: 9046b4dfd0ce ("mke2fs: set overhead in super block")

and

Reviewed-by: Andreas Dilger <adilger@dilger.ca>

That also makes me wonder if resize2fs also needs to recalculate or
invalidate the s_overhead_clusters field when adding new block groups.
It *looks* like that is done correctly in adjust_fs_info() already?

Cheers, Andreas

> ---
> 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
> 


Cheers, Andreas






[-- Attachment #2: Message signed with OpenPGP --]
[-- Type: application/pgp-signature, Size: 873 bytes --]

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] tune2fs: Update overhead when toggling journal feature
  2021-06-14 21:38 ` Andreas Dilger
@ 2021-06-15  7:52   ` Jan Kara
  0 siblings, 0 replies; 4+ messages in thread
From: Jan Kara @ 2021-06-15  7:52 UTC (permalink / raw)
  To: Andreas Dilger; +Cc: Jan Kara, Ted Tso, Ext4 Developers List

On Mon 14-06-21 15:38:57, Andreas Dilger wrote:
> 
> > On Jun 14, 2021, at 3:28 PM, Jan Kara <jack@suse.cz> wrote:
> > 
> > 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>
> 
> You could add:
> 
> Fixes: 9046b4dfd0ce ("mke2fs: set overhead in super block")
> 
> and
> 
> Reviewed-by: Andreas Dilger <adilger@dilger.ca>

Thanks!

> That also makes me wonder if resize2fs also needs to recalculate or
> invalidate the s_overhead_clusters field when adding new block groups.
> It *looks* like that is done correctly in adjust_fs_info() already?

Yes. From a quick look I had when doing this tune2fs patch I've noticed
that adjust_fs_info() just zeros s_overhead_clusters which makes the kernel
compute the overhead instead...

								Honza

-- 
Jan Kara <jack@suse.com>
SUSE Labs, CR

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] tune2fs: Update overhead when toggling journal feature
  2021-06-14 21:28 [PATCH] tune2fs: Update overhead when toggling journal feature Jan Kara
  2021-06-14 21:38 ` Andreas Dilger
@ 2021-07-07  2:28 ` Theodore Ts'o
  1 sibling, 0 replies; 4+ messages in thread
From: Theodore Ts'o @ 2021-07-07  2:28 UTC (permalink / raw)
  To: Jan Kara; +Cc: linux-ext4

On Mon, Jun 14, 2021 at 11:28:30PM +0200, Jan Kara wrote:
> 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>

Applied thanks.

					- Ted

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2021-07-07  2:28 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2021-06-14 21:28 [PATCH] tune2fs: Update overhead when toggling journal feature Jan Kara
2021-06-14 21:38 ` Andreas Dilger
2021-06-15  7:52   ` Jan Kara
2021-07-07  2:28 ` Theodore Ts'o

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).