Skip to contentSkip to conversation

gfs_fsck: Back-port some fixes from fsck.gfs2

PATCH New Bob Peterson 1 participant 1 message Aug 2, 2012

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 gfs_fsck: Back-port some fixes from fsck.gfs2

Hi,

This is kinda big, so I'm posting it here before I push it to the git repo.

This patch back-ports some patches from fsck.gfs2 to gfs_fsck to allow gfs_fsck to better detect and fix file systems that have invalid indirect metadata blocks.

Regards,

Bob Peterson
---

gfs/gfs_fsck/bio.c +0 -3
index cd6833c..bf743e7 100644
@@ -134,9 +134,6 @@ int write_buf(struct fsck_sb *sdp, osi_buf_t *bh, int flags){
 		return -1;
 	}
 
-	log_debug("Writing to %"PRIu64" - %"PRIu64" %u\n",
-		  (uint64)(BH_BLKNO(bh) * BH_SIZE(bh)),
-		  BH_BLKNO(bh), BH_SIZE(bh));
 	if(do_write(disk_fd, BH_DATA(bh), BH_SIZE(bh))) {
 		log_err("Unable to write %u bytes to position %"PRIu64"\n",
 			BH_SIZE(bh), (uint64)(BH_BLKNO(bh) * BH_SIZE(bh)));
gfs/gfs_fsck/metawalk.c +16 -10
index e14d4dc..e485428 100644
@@ -664,7 +664,7 @@ static int build_metalist(struct fsck_inode *ip, osi_list_t *mlp,
 	osi_list_t *prev_list, *cur_list, *tmp;
 	int i, head_size;
 	uint64 *ptr, block;
-	int err;
+	int error = 0, err;
 
 	if(get_and_read_buf(ip->i_sbd, ip->i_di.di_num.no_addr, &metabh)) {
 		stack;
@@ -708,13 +708,22 @@ static int build_metalist(struct fsck_inode *ip, osi_list_t *mlp,
 							   pass->private);
 				if(err < 0) {
 					stack;
+					error = err;
 					goto fail;
 				}
 				if(err > 0) {
+					if (!error)
+						error = err;
 					log_debug("Skipping block %"PRIu64
 						  "\n", block);
 					continue;
 				}
+				if (check_range(ip->i_sbd, block)) {
+					log_debug("Skipping invalid block "
+						  "%lld\n",
+						  (unsigned long long)block);
+					continue;
+				}
 				if(!nbh) {
 					if(get_and_read_buf(ip->i_sbd, block,
 							    &nbh)) {
@@ -726,7 +735,7 @@ static int build_metalist(struct fsck_inode *ip, osi_list_t *mlp,
 			}
 		}
 	}
-	return 0;
+	return error;
 
  fail:
 	for (i = 0; i < GFS_MAX_META_HEIGHT; i++) {
@@ -739,9 +748,8 @@ static int build_metalist(struct fsck_inode *ip, osi_list_t *mlp,
 			relse_buf(ip->i_sbd, bh);
 		}
 	}
-	/* This is an error path, so we need to release the buffer here: */
-	relse_buf(ip->i_sbd, metabh);
-	return -1;
+	/* No need to relse_buf on metabh because it's in the list */
+	return error;
 }
 
 /**
@@ -769,9 +777,10 @@ int check_metatree(struct fsck_inode *ip, struct metawalk_fxns *pass)
 		osi_list_init(&metalist[i]);
 
 	/* create metalist for each level */
-	if(build_metalist(ip, &metalist[0], pass)){
+	error = build_metalist(ip, &metalist[0], pass);
+	if (error) {
 		stack;
-		return -1;
+		return error;
 	}
 
 	/* We don't need to record directory blocks - they will be
@@ -1072,9 +1081,6 @@ int delete_blocks(struct fsck_inode *ip, uint64_t block, osi_buf_t **bh,
 		if (block_check(ip->i_sbd->bl, block, &q))
 			return 0;
 		if (!q.dup_block) {
-			log_info("Deleting %s block %lld as part "
-				 "of inode %lld \n",
-				 btype, block, ip->i_di.di_num.no_addr);
 			block_set(ip->i_sbd->bl, block, block_free);
 			free_block(ip->i_sbd, block);
 		}
gfs/gfs_fsck/pass1.c +126 -6

186 lines not on this page · raw message

gfs/gfs_fsck/util.c +2 -5
index bb53d8c..6d2a9a2 100644
@@ -107,11 +107,8 @@ int check_meta(osi_buf_t *bh, int type){
  
   check_magic = gfs32_to_cpu(check_magic);
   check_type = gfs32_to_cpu(check_type);
-  if((check_magic != GFS_MAGIC) || (type && (check_type != type))){
-	  log_debug("For %"PRIu64" Expected %X:%X - got %X:%X\n", BH_BLKNO(bh), GFS_MAGIC, type,
-		    check_magic, check_type);
-    return -1;
-  }
+  if((check_magic != GFS_MAGIC) || (type && (check_type != type)))
+	  return -1;
   return 0;
 }