2024-01-18 04:30:33

by yangerkun

[permalink] [raw]
Subject: [PATCH v2 1/2] ext4: remove unused buddy_loaded in ext4_mb_seq_groups_show

We can just first call ext4_mb_unload_buddy, then copy information from
ext4_group_info. So remove this unused value.

Signed-off-by: yangerkun <[email protected]>
Reviewed-by: Jan Kara <[email protected]>
---
fs/ext4/mballoc.c | 13 ++++++-------
1 file changed, 6 insertions(+), 7 deletions(-)

v1->v2:
Add comments before memcpy, add review tag.

diff --git a/fs/ext4/mballoc.c b/fs/ext4/mballoc.c
index f44f668e407f..866f8f0922f1 100644
--- a/fs/ext4/mballoc.c
+++ b/fs/ext4/mballoc.c
@@ -2990,8 +2990,7 @@ static int ext4_mb_seq_groups_show(struct seq_file *seq, void *v)
{
struct super_block *sb = pde_data(file_inode(seq->file));
ext4_group_t group = (ext4_group_t) ((unsigned long) v);
- int i;
- int err, buddy_loaded = 0;
+ int i, err;
struct ext4_buddy e4b;
struct ext4_group_info *grinfo;
unsigned char blocksize_bits = min_t(unsigned char,
@@ -3021,14 +3020,14 @@ static int ext4_mb_seq_groups_show(struct seq_file *seq, void *v)
seq_printf(seq, "#%-5u: I/O error\n", group);
return 0;
}
- buddy_loaded = 1;
+ ext4_mb_unload_buddy(&e4b);
}

+ /*
+ * We care only about free space counters in the group info and
+ * these are safe to access even after the buddy has been unloaded
+ */
memcpy(&sg, grinfo, i);
-
- if (buddy_loaded)
- ext4_mb_unload_buddy(&e4b);
-
seq_printf(seq, "#%-5u: %-5u %-5u %-5u [", group, sg.info.bb_free,
sg.info.bb_fragments, sg.info.bb_first_free);
for (i = 0; i <= 13; i++)
--
2.39.2



2024-01-18 04:30:40

by yangerkun

[permalink] [raw]
Subject: [PATCH v2 2/2] ext4: improve error msg for ext4_mb_seq_groups_show

While cat mb_groups for a mounted ext4 image which has some corrupted
group, the string return to userspace was just "I/O error" which confuse
me a lot. Improve it with ext4_decode_error.

Signed-off-by: yangerkun <[email protected]>
Reviewed-by: Jan Kara <[email protected]>
---
fs/ext4/mballoc.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)

v1-v2:
improve the commit msg, add review tag.

diff --git a/fs/ext4/mballoc.c b/fs/ext4/mballoc.c
index 866f8f0922f1..f0c79c9d35e1 100644
--- a/fs/ext4/mballoc.c
+++ b/fs/ext4/mballoc.c
@@ -2991,6 +2991,7 @@ static int ext4_mb_seq_groups_show(struct seq_file *seq, void *v)
struct super_block *sb = pde_data(file_inode(seq->file));
ext4_group_t group = (ext4_group_t) ((unsigned long) v);
int i, err;
+ char nbuf[16];
struct ext4_buddy e4b;
struct ext4_group_info *grinfo;
unsigned char blocksize_bits = min_t(unsigned char,
@@ -3017,7 +3018,7 @@ static int ext4_mb_seq_groups_show(struct seq_file *seq, void *v)
if (unlikely(EXT4_MB_GRP_NEED_INIT(grinfo))) {
err = ext4_mb_load_buddy(sb, group, &e4b);
if (err) {
- seq_printf(seq, "#%-5u: I/O error\n", group);
+ seq_printf(seq, "#%-5u: %s\n", group, ext4_decode_error(NULL, err, nbuf));
return 0;
}
ext4_mb_unload_buddy(&e4b);
--
2.39.2


2024-02-15 16:04:59

by Theodore Ts'o

[permalink] [raw]
Subject: Re: [PATCH v2 1/2] ext4: remove unused buddy_loaded in ext4_mb_seq_groups_show


On Thu, 18 Jan 2024 12:25:56 +0800, yangerkun wrote:
> We can just first call ext4_mb_unload_buddy, then copy information from
> ext4_group_info. So remove this unused value.
>
>

Applied, thanks!

[1/2] ext4: remove unused buddy_loaded in ext4_mb_seq_groups_show
(no commit info)
[2/2] ext4: improve error msg for ext4_mb_seq_groups_show
(no commit info)

Best regards,
--
Theodore Ts'o <[email protected]>