Skip to contentSkip to conversation

fsck.gfs2: Repair rindex entries that were destroyed

PATCH New Bob Peterson 1 participant 1 message Jan 13, 2017 1 message not in the archive

lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): [email protected]

#1 lore raw

PATCH 1/1 fsck.gfs2: Repair rindex entries that were destroyed

Hi,

If an rindex entry was destroyed, the rindex was skipped, which means its rgrp never gets inserted into the rgrp tree. The trouble is, that causes a off-by-one-entry problem with all subsequent rindex entries. So if rindex entry R is destroyed, then rebuilt, originally good entry R+1 is checked against new entry for R.

Function rg_repair already had the capability to insert new rindex entries, but only at the end. This would be typical for a gfs2_grow that failed and left a bunch of rgrps on the device, but the rindex was never synced properly.

This patch allows the function to insert catch-up entries in the middle, which re-syncs the actual versus expected rgrp trees.

---

gfs2/fsck/rgrepair.c +8 -3
index 49bbad6..f397db1 100644
@@ -1137,10 +1137,14 @@ int rg_repair(struct gfs2_sbd *sdp, int trust_lvl, int *rg_count, int *sane)
 			next = osi_next(n);
 		enext = osi_next(e);
 		expected = (struct rgrp_tree *)e;
+		actual = (struct rgrp_tree *)n;
 
-		/* If we ran out of actual rindex entries due to rindex
+		/* If the next "actual" rgrp in memory is too far away,
+		   fill in a new one with the expected value. -or-
+		   If we ran out of actual rindex entries due to rindex
 		   damage, fill in a new one with the expected values. */
-		if (!n) { /* end of actual rindex */
+		if (!n || /* end of actual rindex */
+		    expected->ri.ri_addr < actual->ri.ri_addr) {
 			log_err( _("Entry missing from rindex: 0x%llx\n"),
 				 (unsigned long long)expected->ri.ri_addr);
 			actual = rgrp_insert(&sdp->rgtree,
@@ -1150,8 +1154,9 @@ int rg_repair(struct gfs2_sbd *sdp, int trust_lvl, int *rg_count, int *sane)
 				break;
 			}
 			rindex_modified = 1;
+			next = n; /* Ensure that the old actual gets checked
+				     against a new expected, since we added */
 		} else {
-			actual = (struct rgrp_tree *)n;
 			ri_compare(rg, actual->ri, expected->ri, ri_addr,
 				   "llx", unsigned long long);
 			ri_compare(rg, actual->ri, expected->ri, ri_length,