Skip to contentSkip to conversation

ext3: Properly report backup blocks present in a group

PATCH Superseded Glauber de Oliveira Costa 2 participants 3 messages Jan 20, 2006 VFS

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 ext3: Properly report backup blocks present in a group

In filesystems with the meta block group flag on, ext3_bg_num_gdb() fails to report the correct number of blocks used to store the group descriptor backups in a given group. It happens because meta_bg follows a different logic from the original ext3 backup placement in groups multiples of 3, 5 and 7.

---

 fs/ext3/balloc.c |   33 +++++++++++++++++++++++++++++----
 1 files changed, 29 insertions(+), 4 deletions(-)

1164cfd9b1b413f6c4b86bac11006ba2b933ccb1

fs/ext3/balloc.c +29 -4
index 6250fcd..8bf87b0 100644
@@ -1499,6 +1499,25 @@ int ext3_bg_has_super(struct super_block
 	return 1;
 }
 
+static unsigned long ext3_bg_num_gdb_meta(struct super_block *sb, int group)
+{
+	unsigned long metagroup = group / EXT3_DESC_PER_BLOCK(sb);
+	unsigned long first = metagroup * EXT3_DESC_PER_BLOCK(sb);
+	unsigned long last = first + EXT3_DESC_PER_BLOCK(sb) - 1;
+
+	if (group == first || group == first + 1 || group == last)
+		return 1;
+	return 0;
+}
+
+static unsigned long ext3_bg_num_gdb_nometa(struct super_block *sb, int group)
+{
+	if (EXT3_HAS_RO_COMPAT_FEATURE(sb,EXT3_FEATURE_RO_COMPAT_SPARSE_SUPER)&&
+	    !ext3_group_sparse(group))
+		return 0;
+	return EXT3_SB(sb)->s_gdb_count;
+}
+
 /**
  *	ext3_bg_num_gdb - number of blocks used by the group table in group
  *	@sb: superblock for filesystem
@@ -1510,9 +1529,15 @@ int ext3_bg_has_super(struct super_block
  */
 unsigned long ext3_bg_num_gdb(struct super_block *sb, int group)
 {
-	if (EXT3_HAS_RO_COMPAT_FEATURE(sb,EXT3_FEATURE_RO_COMPAT_SPARSE_SUPER)&&
-	    !ext3_group_sparse(group))
-		return 0;
-	return EXT3_SB(sb)->s_gdb_count;
+	unsigned long first_meta_bg = 
+		cpu_to_le32(EXT3_SB(sb)->s_es->s_first_meta_bg);
+	unsigned long metagroup = group / EXT3_DESC_PER_BLOCK(sb);
+
+	if (!EXT3_HAS_INCOMPAT_FEATURE(sb,EXT3_FEATURE_INCOMPAT_META_BG)
+			|| metagroup < first_meta_bg)
+		return ext3_bg_num_gdb_nometa(sb,group);
+	
+	return ext3_bg_num_gdb_meta(sb,group);
+
 }
 
Signature · 1 line
1.0.4
#1 lore raw
Quoted 12 lines · Glauber de Oliveira Costa

In filesystems with the meta block group flag on, ext3_bg_num_gdb() fails to report the correct number of blocks used to store the group descriptor backups in a given group. It happens because meta_bg follows a different logic from the original ext3 backup placement in groups multiples of 3, 5 and 7.

fs/ext3/balloc.c +0 -0
@@ -1510,9 +1529,15 @@ int ext3_bg_has_super(struct super_block
  */
 unsigned long ext3_bg_num_gdb(struct super_block *sb, int group)
 {

fs/ext3/balloc.c int ext3_bg_has_super(struct super_block · line 1537

Quoted 10 lines
fs/ext3/balloc.c +6 -4
-	if (EXT3_HAS_RO_COMPAT_FEATURE(sb,EXT3_FEATURE_RO_COMPAT_SPARSE_SUPER)&&
-	    !ext3_group_sparse(group))
-		return 0;
-	return EXT3_SB(sb)->s_gdb_count;
+	unsigned long first_meta_bg =
+		cpu_to_le32(EXT3_SB(sb)->s_es->s_first_meta_bg);
+	unsigned long metagroup = group / EXT3_DESC_PER_BLOCK(sb);
+
+	if (!EXT3_HAS_INCOMPAT_FEATURE(sb,EXT3_FEATURE_INCOMPAT_META_BG)
+			|| metagroup < first_meta_bg)
			   ^^^^^^^^^^^^^^^^^^^^^^^^^

Comparison between little-endian and host-endian variables.

Quoted 3 lines
fs/ext3/balloc.c +3 -0
+		return ext3_bg_num_gdb_nometa(sb,group);
+
+	return ext3_bg_num_gdb_meta(sb,group);
#2 lore raw

Em Sexta 20 Janeiro 2006 18:01, você escreveu:

Quoted 27 lines · Glauber de Oliveira Costa
Quoted 15 lines

In filesystems with the meta block group flag on, ext3_bg_num_gdb() fails to report the correct number of blocks used to store the group descriptor backups in a given group. It happens because meta_bg follows a different logic from the original ext3 backup placement in groups multiples of 3, 5 and 7.

fs/ext3/balloc.c +0 -1
@@ -1510,9 +1529,15 @@ int ext3_bg_has_super(struct super_block
  */
 unsigned long ext3_bg_num_gdb(struct super_block *sb, int group)
 {
-	if

(EXT3_HAS_RO_COMPAT_FEATURE(sb,EXT3_FEATURE_RO_COMPAT_SPARSE_SUPER)&& -
!ext3_group_sparse(group))

fs/ext3/balloc.c int ext3_bg_has_super(struct super_block · line 1537

Quoted 8 lines
fs/ext3/balloc.c +6 -2
-		return 0;
-	return EXT3_SB(sb)->s_gdb_count;
+	unsigned long first_meta_bg =
+		cpu_to_le32(EXT3_SB(sb)->s_es->s_first_meta_bg);
+	unsigned long metagroup = group / EXT3_DESC_PER_BLOCK(sb);
+
+	if (!EXT3_HAS_INCOMPAT_FEATURE(sb,EXT3_FEATURE_INCOMPAT_META_BG)
+			|| metagroup < first_meta_bg)
			   ^^^^^^^^^^^^^^^^^^^^^^^^^
Quoted 1 line

Comparison between little-endian and host-endian variables.

I should have used le32_to_cpu() instead of cpu_to_le32() some lines above. It was a minor typo error. I Will resend.

Thank you.

Quoted 3 lines

fs/ext3/balloc.c int ext3_bg_has_super(struct super_block · line 1540

Quoted 3 lines
fs/ext3/balloc.c +3 -0
+		return ext3_bg_num_gdb_nometa(sb,group);
+
+	return ext3_bg_num_gdb_meta(sb,group);

-
To unsubscribe from this list: send the line "unsubscribe linux-fsdevel" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html