[Ocfs2-tools-commits] taoma commits r1329 - in branches/sparse-files: fsck.ocfs2 fswreck libocfs2 libocfs2/include

svn-commits at oss.oracle.com svn-commits at oss.oracle.com
Mon Mar 26 00:30:53 PDT 2007


Author: taoma
Date: 2007-03-26 00:30:47 -0700 (Mon, 26 Mar 2007)
New Revision: 1329

Modified:
   branches/sparse-files/fsck.ocfs2/journal.c
   branches/sparse-files/fswreck/dir.c
   branches/sparse-files/fswreck/symlink.c
   branches/sparse-files/libocfs2/dir_scan.c
   branches/sparse-files/libocfs2/expanddir.c
   branches/sparse-files/libocfs2/extent_map.c
   branches/sparse-files/libocfs2/fileio.c
   branches/sparse-files/libocfs2/include/ocfs2.h
Log:
Update the extent map searching mechanism with Mark's new kernel code for sparse file.

This new mechanism's corresponding ocfs2 kernel code is sparse file branch with
the last commit hash 8d7c92bebcd01b2a95c4c3b331cd2c9c86755e82.
The date is Mar 22 2007.
And since extent map can give us the size of a hole, the function
find_cluster_hole is removed from fileio.c.

Modified: branches/sparse-files/fsck.ocfs2/journal.c
===================================================================
--- branches/sparse-files/fsck.ocfs2/journal.c	2007-03-26 06:30:00 UTC (rev 1328)
+++ branches/sparse-files/fsck.ocfs2/journal.c	2007-03-26 07:30:47 UTC (rev 1329)
@@ -238,7 +238,7 @@
 				      int check_dup)
 {
 	errcode_t ret;
-	int contig;
+	uint64_t contig;
 	int was_set;
 
 	ret = ocfs2_extent_map_get_blocks(ji->ji_cinode, blkoff, 1, blkno,
@@ -529,7 +529,8 @@
 	uint64_t blkno;
 	errcode_t ret;
 	ocfs2_cached_inode *cinode = NULL;
-	int contig, is_dirty;
+	int is_dirty;
+	uint64_t contig;
 	journal_superblock_t *jsb;
 
 	*should = 0;

Modified: branches/sparse-files/fswreck/dir.c
===================================================================
--- branches/sparse-files/fswreck/dir.c	2007-03-26 06:30:00 UTC (rev 1328)
+++ branches/sparse-files/fswreck/dir.c	2007-03-26 07:30:47 UTC (rev 1329)
@@ -134,7 +134,7 @@
 	errcode_t ret;
 	char *buf = NULL;
 	uint64_t blkno, tmp_blkno;
-	int contig;
+	uint64_t contig;
 	ocfs2_cached_inode *cinode = NULL;
 	struct ocfs2_dir_entry *de = NULL, *newent = NULL;
 	char name[OCFS2_MAX_FILENAME_LEN];
@@ -336,7 +336,7 @@
 void mess_up_dir_parent_dup(ocfs2_filesys *fs, uint64_t blkno)
 {
 	errcode_t ret;
-	int contig;
+	uint64_t contig;
 	uint64_t parent1, parent2, tmp_blkno,extblk;
 	char *buf = NULL;
 	struct ocfs2_dir_entry *de = NULL, *newent = NULL;

Modified: branches/sparse-files/fswreck/symlink.c
===================================================================
--- branches/sparse-files/fswreck/symlink.c	2007-03-26 06:30:00 UTC (rev 1328)
+++ branches/sparse-files/fswreck/symlink.c	2007-03-26 07:30:47 UTC (rev 1329)
@@ -76,7 +76,7 @@
 	errcode_t ret = 0;
 	ocfs2_cached_inode *cinode = NULL;
 	uint64_t new_blk;
-	int contig;
+	uint64_t contig;
 	char *buf = NULL;
 
 	ret = ocfs2_read_cached_inode(fs, blkno, &cinode);

Modified: branches/sparse-files/libocfs2/dir_scan.c
===================================================================
--- branches/sparse-files/libocfs2/dir_scan.c	2007-03-26 06:30:00 UTC (rev 1328)
+++ branches/sparse-files/libocfs2/dir_scan.c	2007-03-26 07:30:47 UTC (rev 1329)
@@ -50,7 +50,7 @@
 {
 	errcode_t ret;
 	uint64_t blkno;
-	int cblocks;
+	uint64_t cblocks;
 
 	if (scan->blocks_read == scan->total_blocks)
 		return OCFS2_ET_ITERATION_COMPLETE;

Modified: branches/sparse-files/libocfs2/expanddir.c
===================================================================
--- branches/sparse-files/libocfs2/expanddir.c	2007-03-26 06:30:00 UTC (rev 1328)
+++ branches/sparse-files/libocfs2/expanddir.c	2007-03-26 07:30:47 UTC (rev 1329)
@@ -50,7 +50,7 @@
 	uint64_t used_blks;
 	uint64_t totl_blks;
 	uint64_t new_blk;
-	int contig;
+	uint64_t contig;
 	char *buf = NULL;
 
 	if (!(fs->fs_flags & OCFS2_FLAG_RW))

Modified: branches/sparse-files/libocfs2/extent_map.c
===================================================================
--- branches/sparse-files/libocfs2/extent_map.c	2007-03-26 06:30:00 UTC (rev 1328)
+++ branches/sparse-files/libocfs2/extent_map.c	2007-03-26 07:30:47 UTC (rev 1329)
@@ -480,6 +480,92 @@
 #endif
 
 /*
+ * Return the 1st index within el which contains an extent start
+ * larger than v_cluster.
+ */
+static int ocfs2_search_for_hole_index(struct ocfs2_extent_list *el,
+				       uint32_t v_cluster)
+{
+	int i;
+	struct ocfs2_extent_rec *rec;
+
+	for(i = 0; i < el->l_next_free_rec; i++) {
+		rec = &el->l_recs[i];
+
+		if (v_cluster < rec->e_cpos)
+			break;
+	}
+
+	return i;
+}
+
+/*
+ * Figure out the size of a hole which starts at v_cluster within the given
+ * extent list.
+ *
+ * If there is no more allocation past v_cluster, we return the maximum
+ * cluster size minus v_cluster.
+ *
+ * If we have in-inode extents, then el points to the dinode list and
+ * eb_buf is NULL. Otherwise, eb_buf should point to the extent block
+ * containing el.
+ */
+static int ocfs2_figure_hole_clusters(ocfs2_cached_inode *cinode,
+				      struct ocfs2_extent_list *el,
+				      char *eb_buf,
+				      uint32_t v_cluster,
+				      uint32_t *num_clusters)
+{
+	int ret, i;
+	char *next_eb_buf = NULL;
+	struct ocfs2_extent_block *eb, *next_eb;
+
+	i = ocfs2_search_for_hole_index(el, v_cluster);
+
+	if (i == le16_to_cpu(el->l_next_free_rec) && eb_buf) {
+		eb = (struct ocfs2_extent_block *)eb_buf;
+
+		/*
+		 * Check the next leaf for any extents.
+		 */
+		if (eb->h_next_leaf_blk == 0)
+			goto no_more_extents;
+
+		ret = ocfs2_malloc_block(cinode->ci_fs->fs_io, &next_eb_buf);
+		if (ret)
+			goto out;
+
+		ret = ocfs2_read_extent_block(cinode->ci_fs,
+					      eb->h_next_leaf_blk, eb_buf);
+		if (ret)
+			goto out;
+
+		next_eb = (struct ocfs2_extent_block *)next_eb_buf;
+
+		el = &next_eb->h_list;
+
+		i = ocfs2_search_for_hole_index(el, v_cluster);
+	}
+
+no_more_extents:
+	if (i == el->l_next_free_rec) {
+		/*
+		 * We're at the end of our existing allocation. Just
+		 * return the maximum number of clusters we could
+		 * possibly allocate.
+		 */
+		*num_clusters = UINT_MAX - v_cluster;
+	} else
+		*num_clusters = el->l_recs[i].e_cpos - v_cluster;
+
+	ret = 0;
+out:
+	if (next_eb_buf)
+		ocfs2_free(&next_eb_buf);
+	return ret;
+}
+
+/*
  * Return the index of the extent record which contains cluster #v_cluster.
  * -1 is returned if it was not found.
  *
@@ -491,13 +577,14 @@
 	int ret = -1;
 	int i;
 	struct ocfs2_extent_rec *rec;
-	uint32_t rec_end, rec_start;
+	uint32_t rec_end, rec_start, clusters;
 
 	for(i = 0; i < el->l_next_free_rec; i++) {
 		rec = &el->l_recs[i];
 
 		rec_start = rec->e_cpos;
-		rec_end = rec_start + ocfs2_rec_clusters(el->l_tree_depth,rec);
+		clusters = ocfs2_rec_clusters(el->l_tree_depth, rec);
+		rec_end = rec_start + clusters;
 
 		if (v_cluster >= rec_start && v_cluster < rec_end) {
 			ret = i;
@@ -508,8 +595,10 @@
 	return ret;
 }
 
-static int ocfs2_get_clusters(ocfs2_cached_inode *cinode, uint32_t v_cluster,
-			      uint32_t *p_cluster, uint32_t *num_clusters)
+static errcode_t ocfs2_get_clusters(ocfs2_cached_inode *cinode,
+				    uint32_t v_cluster,
+				    uint32_t *p_cluster,
+		 		    uint32_t *num_clusters)
 {
 	int i;
 	errcode_t ret =  0;
@@ -531,17 +620,33 @@
 
 		eb = (struct ocfs2_extent_block *) eb_buf;
 		el = &eb->h_list;
+
+		if (el->l_tree_depth) {
+			fprintf(stderr,
+				"Inode %"PRIu64" has non zero tree depth in "
+				"leaf block %"PRIu64"\n",
+				di->i_blkno, eb->h_blkno);
+			ret = OCFS2_ET_CORRUPT_EXTENT_BLOCK;
+			goto out;
+		}
 	}
 
 	i = ocfs2_search_extent_list(el, v_cluster);
 	if (i == -1) {
 		/*
 		 * A hole was found. Return some canned values that
-		 * callers can key on.
+		 * callers can key on. If asked for, num_clusters will
+		 * be populated with the size of the hole.
+
 		 */
 		*p_cluster = 0;
-		if (num_clusters)
-			*num_clusters = 1;
+		if (num_clusters) {
+			ret = ocfs2_figure_hole_clusters(cinode, el, eb_buf,
+							 v_cluster,
+							 num_clusters);
+			if (ret)
+				goto out;
+		}
 	} else {
 		rec = &el->l_recs[i];
 
@@ -574,7 +679,7 @@
 
 errcode_t ocfs2_extent_map_get_blocks(ocfs2_cached_inode *cinode,
 				      uint64_t v_blkno, int count,
-				      uint64_t *p_blkno, int *ret_count)
+				      uint64_t *p_blkno, uint64_t *ret_count)
 {
 	errcode_t ret;
 	int bpc;

Modified: branches/sparse-files/libocfs2/fileio.c
===================================================================
--- branches/sparse-files/libocfs2/fileio.c	2007-03-26 06:30:00 UTC (rev 1328)
+++ branches/sparse-files/libocfs2/fileio.c	2007-03-26 07:30:47 UTC (rev 1329)
@@ -128,7 +128,7 @@
 	errcode_t	ret = 0;
 	char		*ptr = (char *) buf;
 	uint32_t	wanted_blocks;
-	int		contig_blocks;
+	uint64_t	contig_blocks;
 	uint64_t	v_blkno;
 	uint64_t	p_blkno;
 	uint32_t	tmp;
@@ -190,31 +190,6 @@
 	return ret;
 }
 
-/*
- * Search the space [start_pos, start_pos + n_clusters), and find the
- * cluster num a hole poccesses starting from start_pos.
- */
-static uint32_t find_cluster_hole(ocfs2_cached_inode *ci, uint32_t start_pos,
-			       uint32_t n_clusters)
-{
-	errcode_t ret;
-	uint32_t cluster_hole, i;
-	uint64_t blkno = ocfs2_clusters_to_blocks(ci->ci_fs,start_pos);
-	uint32_t bpc = ci->ci_fs->fs_clustersize / ci->ci_fs->fs_blocksize;
-	uint64_t p_blkno;
-	int	 contig_blocks;
-
-	for (i = 0; i < n_clusters; i++, blkno += bpc) {
-		ret = ocfs2_extent_map_get_blocks(ci, blkno, 1,
-						  &p_blkno, &contig_blocks);
-		if (ret || p_blkno)
-			break;
-	}
-	cluster_hole = i;
-
-	return cluster_hole;
-}
-
 errcode_t ocfs2_file_write(ocfs2_cached_inode *ci, void *buf, uint32_t count,
 			   uint64_t offset, uint32_t *wrote)
 {
@@ -222,7 +197,7 @@
 	errcode_t	ret = 0;
 	char		*ptr = (char *) buf;
 	uint32_t	wanted_blocks;
-	int		contig_blocks;
+	uint64_t	contig_blocks;
 	uint64_t	v_blkno;
 	uint64_t	p_blkno;
 	uint32_t	tmp;
@@ -263,8 +238,6 @@
 			cluster_end = ocfs2_blocks_to_clusters(fs,
 						v_blkno + contig_blocks -1);
 			n_clusters = cluster_end - cluster_begin + 1;
-			n_clusters = find_cluster_hole(ci, cluster_begin,
-						       n_clusters);
 			ret = ocfs2_new_clusters(fs, 1, n_clusters, &p_blkno,
 						 &n_clusters);
 			if (ret)

Modified: branches/sparse-files/libocfs2/include/ocfs2.h
===================================================================
--- branches/sparse-files/libocfs2/include/ocfs2.h	2007-03-26 06:30:00 UTC (rev 1328)
+++ branches/sparse-files/libocfs2/include/ocfs2.h	2007-03-26 07:30:47 UTC (rev 1329)
@@ -298,7 +298,7 @@
 errcode_t ocfs2_extent_map_get_blocks(ocfs2_cached_inode *cinode,
 				      uint64_t v_blkno, int count,
 				      uint64_t *p_blkno,
-				      int *ret_count);
+				      uint64_t *ret_count);
 int ocfs2_find_leaf(ocfs2_filesys *fs, struct ocfs2_dinode *di,
 		    uint32_t cpos, char **leaf_buf);
 void ocfs2_swap_journal_superblock(journal_superblock_t *jsb);




More information about the Ocfs2-tools-commits mailing list