Skip to contentSkip to conversation

ext4: remove unused buddy_loaded in ext4_mb_seq_groups_show

PATCH Superseded yangerkun 3 participants 5 messages Jan 17, 2024 – Jan 18, 2024 ext4 file system

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

yangerkun

author
#0 lore raw

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

---
 fs/ext4/mballoc.c | 9 ++-------
 1 file changed, 2 insertions(+), 7 deletions(-)
fs/ext4/mballoc.c +2 -7
index f44f668e407f..139f232bdbb5 100644
@@ -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,10 @@ 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);
 	}
 
 	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++)
Signature · 1 line
2.39.2
author
#1 lore raw

PATCH 2/2 ext4: distinguish different error in 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. Use ext4_decode_error to help distinguish different error.

---
 fs/ext4/mballoc.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
fs/ext4/mballoc.c +2 -1
index 139f232bdbb5..77d6113e2822 100644
@@ -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);
Signature · 1 line
2.39.2
reviewer Reviewed-by on v1 2/2
#2 lore raw

Re: [PATCH 2/2] ext4: distinguish different error in ext4_mb_seq_groups_show

Quoted 5 lines · yangerkun

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. Use ext4_decode_error to help distinguish different error.

I guess this is an improvement :). Feel free to add:

Honza

Quoted 28 lines
---
 fs/ext4/mballoc.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
fs/ext4/mballoc.c +2 -1
index 139f232bdbb5..77d6113e2822 100644
@@ -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);
Signature · 1 line
2.39.2
Signature · 2 lines
Jan Kara <[email protected]>
SUSE Labs, CR
reviewer Reviewed-by on v1 1/2
#3 lore raw
In reply to yangerkun
Quoted 4 lines · yangerkun

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

Looks good. Feel free to add:

Although I'd prefer if you add a comment before memcpy() like:

	/*
	 * We care only about free space counters in the group info and
	 * these are safe to access even after the buddy has been unloaded
	 */

								Honza
Quoted 37 lines
---
 fs/ext4/mballoc.c | 9 ++-------
 1 file changed, 2 insertions(+), 7 deletions(-)
fs/ext4/mballoc.c +2 -7
index f44f668e407f..139f232bdbb5 100644
@@ -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,10 @@ 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);
 	}
 
 	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++)
Signature · 1 line
2.39.2
Signature · 2 lines
Jan Kara <[email protected]>
SUSE Labs, CR
#4 lore raw
Quoted 10 lines · Jan Kara
Quoted 4 lines · yangerkun

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

Looks good. Feel free to add:

Quoted 9 lines

Although I'd prefer if you add a comment before memcpy() like:

	/*
	 * We care only about free space counters in the group info and
	 * these are safe to access even after the buddy has been unloaded
	 */

								Honza

Thanks a lot for your review! I will do it next version!

Quoted 37 lines
Quoted 37 lines
---
  fs/ext4/mballoc.c | 9 ++-------
  1 file changed, 2 insertions(+), 7 deletions(-)
fs/ext4/mballoc.c +2 -7
index f44f668e407f..139f232bdbb5 100644
@@ -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,10 @@ 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);
  	}
 
  	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++)
Signature · 1 line
2.39.2