[Ocfs2-tools-devel] [patch 02/11] Modify e_clusters used in the ocfs2-tools.

tao.ma at oracle.com tao.ma at oracle.com
Wed Aug 15 10:54:47 PDT 2007


ocfs2_extent_rec has been added a new flag and e_clusters has been modified.
So change it accordingly.
Index: test.ocfs2-tools/extras/find_dup_extents.c
===================================================================
--- test.ocfs2-tools.orig/extras/find_dup_extents.c	2007-08-16 00:27:42.000000000 -0400
+++ test.ocfs2-tools/extras/find_dup_extents.c	2007-08-16 00:36:28.000000000 -0400
@@ -68,7 +68,7 @@ static int extent_set_func(ocfs2_filesys
 		OCFS2_RAW_SB(fs->fs_super)->s_blocksize_bits;
 
 	cluster = (uint32_t)(rec->e_blkno >> b_to_c_bits);
-	for (i = 0; i < rec->e_clusters; i++) {
+	for (i = 0; i < ocfs2_rec_clusters(tree_depth, rec); i++) {
 		ret = ocfs2_bitmap_set(we->extent_map,
 				       cluster + i,
 				       &oldval);
@@ -112,7 +112,7 @@ static int extent_test_func(ocfs2_filesy
 		OCFS2_RAW_SB(fs->fs_super)->s_blocksize_bits;
 
 	cluster = (uint32_t)(rec->e_blkno >> b_to_c_bits);
-	for (i = 0; i < rec->e_clusters; i++) {
+	for (i = 0; i < ocfs2_rec_clusters(tree_depth, rec); i++) {
 		ret = ocfs2_bitmap_test(we->dup_map,
 					cluster + i,
 					&oldval);
Index: test.ocfs2-tools/fsck.ocfs2/extent.c
===================================================================
--- test.ocfs2-tools.orig/fsck.ocfs2/extent.c	2007-08-16 00:27:41.000000000 -0400
+++ test.ocfs2-tools/fsck.ocfs2/extent.c	2007-08-16 00:36:28.000000000 -0400
@@ -155,10 +155,11 @@ static errcode_t check_er(o2fsck_state *
 {
 	errcode_t ret = 0;
 	uint64_t first_block;
-	uint32_t last_cluster;
+	uint32_t last_cluster, clusters;
 
+	clusters = ocfs2_rec_clusters(el->l_tree_depth, er);
 	verbosef("cpos %u clusters %u blkno %"PRIu64"\n", er->e_cpos,
-		 er->e_clusters, er->e_blkno);
+		 clusters, er->e_blkno);
 
 	if (ocfs2_block_out_of_range(ost->ost_fs, er->e_blkno))
 		goto out;
@@ -204,7 +205,7 @@ static errcode_t check_er(o2fsck_state *
 	/* imagine blkno 0, 1 er_clusters.  last_cluster is 1 and 
 	 * fs_clusters is 1, which is ok.. */
 	last_cluster = ocfs2_blocks_to_clusters(ost->ost_fs, er->e_blkno) +
-		       er->e_clusters;
+		       clusters;
 
 	if (last_cluster > ost->ost_fs->fs_clusters &&
 	    prompt(ost, PY, PR_EXTENT_CLUSTERS_OVERRUN,
@@ -214,7 +215,8 @@ static errcode_t check_er(o2fsck_state *
 		   "clusters to fit it in the volume?", er->e_cpos, 
 		   di->i_blkno, last_cluster - ost->ost_fs->fs_clusters)) {
 
-		er->e_clusters -= last_cluster - ost->ost_fs->fs_clusters;
+		clusters -= last_cluster - ost->ost_fs->fs_clusters;
+		ocfs2_set_rec_clusters(el->l_tree_depth, er, clusters);
 		*changed = 1;
 	}
 	
@@ -236,6 +238,7 @@ static errcode_t check_el(o2fsck_state *
 	struct ocfs2_extent_rec *er;
 	uint64_t max_size;
 	uint16_t i;
+	uint32_t clusters;
 	size_t cpy;
 
 	verbosef("depth %u count %u next_free %u\n", el->l_tree_depth,
@@ -286,6 +289,13 @@ static errcode_t check_el(o2fsck_state *
 
 	for (i = 0; i < max_recs; i++) {
 		er = &el->l_recs[i];
+		clusters = ocfs2_rec_clusters(el->l_tree_depth, er);
+
+		/* For a sparse file, we may find an empty record
+		 * in the left most record. Just skip it.
+		 */
+		if (el->l_tree_depth && !i && !clusters)
+			continue;
 
 		/* returns immediately if blkno is out of range.
 		 * descends into eb.  checks that data er doesn't
@@ -328,11 +338,11 @@ static errcode_t check_el(o2fsck_state *
 		/* mark the data clusters as used */
 		o2fsck_mark_clusters_allocated(ost,
 			ocfs2_blocks_to_clusters(ost->ost_fs, er->e_blkno),
-			er->e_clusters);
+			clusters);
 
-		ei->ei_clusters += er->e_clusters;
+		ei->ei_clusters += clusters;
 
-		max_size = (er->e_cpos + er->e_clusters) <<
+		max_size = (er->e_cpos + clusters) <<
 			   OCFS2_RAW_SB(ost->ost_fs->fs_super)->s_clustersize_bits;
 		if (max_size > ei->ei_max_size)
 			ei->ei_max_size = max_size;
Index: test.ocfs2-tools/libocfs2/extents.c
===================================================================
--- test.ocfs2-tools.orig/libocfs2/extents.c	2007-08-16 00:27:42.000000000 -0400
+++ test.ocfs2-tools/libocfs2/extents.c	2007-08-16 00:36:28.000000000 -0400
@@ -49,7 +49,10 @@ static void ocfs2_swap_extent_list_secon
 		struct ocfs2_extent_rec *rec = &el->l_recs[i];
 
 		rec->e_cpos = bswap_32(rec->e_cpos);
-		rec->e_clusters = bswap_32(rec->e_clusters);
+		if (el->l_tree_depth)
+			rec->e_int_clusters = bswap_32(rec->e_int_clusters);
+		else
+			rec->e_leaf_clusters = bswap_16(rec->e_leaf_clusters);
 		rec->e_blkno = bswap_64(rec->e_blkno);
 	}
 }
@@ -248,7 +251,7 @@ static int extent_iterate_el(struct ocfs
 				iret |= update_eb_rec(ctxt, &before,
 						      &el->l_recs[i]);
 
-			if (el->l_recs[i].e_clusters &&
+			if (el->l_recs[i].e_int_clusters &&
 			   (el->l_recs[i].e_cpos >= ctxt->last_eb_cpos)) {
 				/*
 				 * Only set last_eb_blkno if current extent
@@ -261,6 +264,11 @@ static int extent_iterate_el(struct ocfs
 			}
 
 		} else {
+			/* For a sparse file, we may find an empty record
+			 * in the left most record. Just skip it.
+			 */
+			if (!i && !el->l_recs[i].e_leaf_clusters)
+				continue;
 			iret |= (*ctxt->func)(ctxt->fs, &el->l_recs[i],
 					      el->l_tree_depth,
 					      ctxt->ccount, ref_blkno,
@@ -268,7 +276,8 @@ static int extent_iterate_el(struct ocfs
 			if (iret & OCFS2_EXTENT_CHANGED)
 				iret |= update_leaf_rec(ctxt, &before,
 							&el->l_recs[i]);
-			ctxt->ccount += el->l_recs[i].e_clusters;
+			ctxt->ccount += ocfs2_rec_clusters(el->l_tree_depth,
+							   &el->l_recs[i]);
 		}
 		if (iret & (OCFS2_EXTENT_ABORT | OCFS2_EXTENT_ERROR))
 			break;
@@ -276,7 +285,8 @@ static int extent_iterate_el(struct ocfs
 
 	if (iret & OCFS2_EXTENT_CHANGED) {
 		for (i = 0; i < el->l_count; i++) {
-			if (el->l_recs[i].e_clusters)
+			if (ocfs2_rec_clusters(el->l_tree_depth,
+					       &el->l_recs[i]))
 				continue;
 			el->l_next_free_rec = i;
 			break;
@@ -334,9 +344,11 @@ static int extent_iterate_eb(struct ocfs
 	if (flags & (OCFS2_EXTENT_ABORT | OCFS2_EXTENT_ERROR))
 		iret |= flags & (OCFS2_EXTENT_ABORT | OCFS2_EXTENT_ERROR);
 
-	/* if the list was changed and we still have recs then we need
-	 * to write the changes to disk */
-	if (changed & OCFS2_EXTENT_CHANGED && el->l_next_free_rec) {
+	/* If the list was changed, we should write the changes to disk.
+	 * Note:
+	 * For a sparse file, we may have an empty extent block.
+	 */
+	if (changed & OCFS2_EXTENT_CHANGED) {
 		ctxt->errcode = ocfs2_write_extent_block(ctxt->fs,
 							 eb_rec->e_blkno,
 						ctxt->eb_bufs[tree_depth]);
@@ -508,8 +520,9 @@ static int block_iterate_func(ocfs2_file
 	uint64_t blkno, bcount, bend;
 	int iret = 0;
 
-	bcount = ocfs2_clusters_to_blocks(fs, ccount);
-	bend = bcount + ocfs2_clusters_to_blocks(fs, rec->e_clusters);
+	bcount = ocfs2_clusters_to_blocks(fs, rec->e_cpos);
+	bend = bcount + ocfs2_clusters_to_blocks(fs,
+					ocfs2_rec_clusters(tree_depth, rec));
 
 	for (blkno = rec->e_blkno; bcount < bend; blkno++, bcount++) {
 		if (((bcount * fs->fs_blocksize) >= ctxt->inode->i_size) &&
@@ -627,12 +640,14 @@ static int walk_extents_func(ocfs2_files
 		fprintf(stdout, " ");
 	fprintf(stdout, "(%08"PRIu32", %08"PRIu32", %08"PRIu64") |"
 			" + %08"PRIu32" = %08"PRIu32" / %08"PRIu32"\n",
-		rec->e_cpos, rec->e_clusters,
-		rec->e_blkno, ccount, ccount + rec->e_clusters,
+		rec->e_cpos, ocfs2_rec_clustes(tree_depth, rec),
+		rec->e_blkno, ccount,
+		ccount + ocfs2_rec_clusters(tree_depth, rec),
 		wi->di->i_clusters);
 
 	if (!tree_depth &&
-	    ((ccount + rec->e_clusters) == wi->di->i_clusters))
+	    ((ccount + ocfs2_rec_clusters(tree_depth, rec)) ==
+							 wi->di->i_clusters))
 		fprintf(stdout, "TOTAL: %u\n", wi->di->i_clusters);
 
 	return 0;
Index: test.ocfs2-tools/libocfs2/heartbeat.c
===================================================================
--- test.ocfs2-tools.orig/libocfs2/heartbeat.c	2007-08-16 00:27:42.000000000 -0400
+++ test.ocfs2-tools/libocfs2/heartbeat.c	2007-08-16 00:36:28.000000000 -0400
@@ -89,7 +89,7 @@ errcode_t ocfs2_fill_heartbeat_desc(ocfs
 		goto leave;
 	}
 
-	blocks = rec->e_clusters << cluster_bits;
+	blocks = ocfs2_rec_clusters(0, rec) << cluster_bits;
 	blocks >>= block_bits;
 
 	if (blocks > O2NM_MAX_NODES)

-- 



More information about the Ocfs2-tools-devel mailing list