All of lore.kernel.org
 help / color / mirror / Atom feed
* [Ocfs2-devel] [PATCH 1/2] ocfs2: Add wrapper for the check of extent tree type.
  2008-08-27  6:16 [Ocfs2-devel] [PATCH 0/2] ocfs2.git: Combine ocfs2_xattr_get_clusters to ocfs2_get_cluster Tao Ma
@ 2008-08-26 22:38 ` Tao Ma
  2008-08-26 22:44 ` Tao Ma
  2008-08-26 22:44 ` [Ocfs2-devel] [PATCH 2/2] ocfs2: Combine normal and xattr get extent clusters process together Tao Ma
  2 siblings, 0 replies; 4+ messages in thread
From: Tao Ma @ 2008-08-26 22:38 UTC (permalink / raw)
  To: ocfs2-devel

In some places we may need to check the ocfs2_extent_tree's type,
so add the checker for them.

Signed-off-by: Tao Ma <tao.ma@oracle.com>
---
 fs/ocfs2/alloc.c |   19 +++++++++++++++++--
 fs/ocfs2/alloc.h |    3 +++
 2 files changed, 20 insertions(+), 2 deletions(-)

diff --git a/fs/ocfs2/alloc.c b/fs/ocfs2/alloc.c
index 5f44ef8..80dbf2f 100644
--- a/fs/ocfs2/alloc.c
+++ b/fs/ocfs2/alloc.c
@@ -344,6 +344,21 @@ void ocfs2_init_xattr_value_extent_tree(struct ocfs2_extent_tree *et,
 				 &ocfs2_xattr_value_et_ops);
 }
 
+int ocfs2_is_dinode_extent_tree(struct ocfs2_extent_tree *et)
+{
+	return et->et_ops == &ocfs2_dinode_et_ops;
+}
+
+int ocfs2_is_xattr_value_extent_tree(struct ocfs2_extent_tree *et)
+{
+	return et->et_ops == &ocfs2_xattr_value_et_ops;
+}
+
+int ocfs2_is_xattr_tree_extent_tree(struct ocfs2_extent_tree *et)
+{
+	return et->et_ops == &ocfs2_xattr_tree_et_ops;
+}
+
 static inline void ocfs2_et_set_last_eb_blk(struct ocfs2_extent_tree *et,
 					    u64 new_last_eb_blk)
 {
@@ -4476,7 +4491,7 @@ int ocfs2_insert_extent(struct ocfs2_super *osb,
 	status = ocfs2_do_insert_extent(inode, handle, et, &rec, &insert);
 	if (status < 0)
 		mlog_errno(status);
-	else if (et->et_ops == &ocfs2_dinode_et_ops)
+	else if (ocfs2_is_dinode_extent_tree(et))
 		ocfs2_extent_map_insert_rec(inode, &rec);
 
 bail:
@@ -4874,7 +4889,7 @@ int ocfs2_mark_extent_written(struct inode *inode,
 	 * XXX: This is a hack on the extent tree, maybe it should be
 	 * an op?
 	 */
-	if (et->et_ops == &ocfs2_dinode_et_ops)
+	if (ocfs2_is_dinode_extent_tree(et))
 		ocfs2_extent_map_trunc(inode, 0);
 
 	left_path = ocfs2_new_path(et->et_root_bh, et->et_root_el);
diff --git a/fs/ocfs2/alloc.h b/fs/ocfs2/alloc.h
index a0ae6bd..8b98f40 100644
--- a/fs/ocfs2/alloc.h
+++ b/fs/ocfs2/alloc.h
@@ -72,6 +72,9 @@ void ocfs2_init_xattr_value_extent_tree(struct ocfs2_extent_tree *et,
 					struct inode *inode,
 					struct buffer_head *bh,
 					struct ocfs2_xattr_value_root *xv);
+int ocfs2_is_dinode_extent_tree(struct ocfs2_extent_tree *et);
+int ocfs2_is_xattr_value_extent_tree(struct ocfs2_extent_tree *et);
+int ocfs2_is_xattr_tree_extent_tree(struct ocfs2_extent_tree *et);
 
 struct ocfs2_alloc_context;
 int ocfs2_insert_extent(struct ocfs2_super *osb,
-- 
1.5.4.GIT

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [Ocfs2-devel] [PATCH 1/2] ocfs2: Add wrapper for the check of extent tree type.
  2008-08-27  6:16 [Ocfs2-devel] [PATCH 0/2] ocfs2.git: Combine ocfs2_xattr_get_clusters to ocfs2_get_cluster Tao Ma
  2008-08-26 22:38 ` [Ocfs2-devel] [PATCH 1/2] ocfs2: Add wrapper for the check of extent tree type Tao Ma
@ 2008-08-26 22:44 ` Tao Ma
  2008-08-26 22:44 ` [Ocfs2-devel] [PATCH 2/2] ocfs2: Combine normal and xattr get extent clusters process together Tao Ma
  2 siblings, 0 replies; 4+ messages in thread
From: Tao Ma @ 2008-08-26 22:44 UTC (permalink / raw)
  To: ocfs2-devel

In some places we may need to check the ocfs2_extent_tree's type,
so add the checker for them.

Signed-off-by: Tao Ma <tao.ma@oracle.com>
---
 fs/ocfs2/alloc.c |   19 +++++++++++++++++--
 fs/ocfs2/alloc.h |    3 +++
 2 files changed, 20 insertions(+), 2 deletions(-)

diff --git a/fs/ocfs2/alloc.c b/fs/ocfs2/alloc.c
index 5f44ef8..80dbf2f 100644
--- a/fs/ocfs2/alloc.c
+++ b/fs/ocfs2/alloc.c
@@ -344,6 +344,21 @@ void ocfs2_init_xattr_value_extent_tree(struct ocfs2_extent_tree *et,
 				 &ocfs2_xattr_value_et_ops);
 }
 
+int ocfs2_is_dinode_extent_tree(struct ocfs2_extent_tree *et)
+{
+	return et->et_ops == &ocfs2_dinode_et_ops;
+}
+
+int ocfs2_is_xattr_value_extent_tree(struct ocfs2_extent_tree *et)
+{
+	return et->et_ops == &ocfs2_xattr_value_et_ops;
+}
+
+int ocfs2_is_xattr_tree_extent_tree(struct ocfs2_extent_tree *et)
+{
+	return et->et_ops == &ocfs2_xattr_tree_et_ops;
+}
+
 static inline void ocfs2_et_set_last_eb_blk(struct ocfs2_extent_tree *et,
 					    u64 new_last_eb_blk)
 {
@@ -4476,7 +4491,7 @@ int ocfs2_insert_extent(struct ocfs2_super *osb,
 	status = ocfs2_do_insert_extent(inode, handle, et, &rec, &insert);
 	if (status < 0)
 		mlog_errno(status);
-	else if (et->et_ops == &ocfs2_dinode_et_ops)
+	else if (ocfs2_is_dinode_extent_tree(et))
 		ocfs2_extent_map_insert_rec(inode, &rec);
 
 bail:
@@ -4874,7 +4889,7 @@ int ocfs2_mark_extent_written(struct inode *inode,
 	 * XXX: This is a hack on the extent tree, maybe it should be
 	 * an op?
 	 */
-	if (et->et_ops == &ocfs2_dinode_et_ops)
+	if (ocfs2_is_dinode_extent_tree(et))
 		ocfs2_extent_map_trunc(inode, 0);
 
 	left_path = ocfs2_new_path(et->et_root_bh, et->et_root_el);
diff --git a/fs/ocfs2/alloc.h b/fs/ocfs2/alloc.h
index a0ae6bd..8b98f40 100644
--- a/fs/ocfs2/alloc.h
+++ b/fs/ocfs2/alloc.h
@@ -72,6 +72,9 @@ void ocfs2_init_xattr_value_extent_tree(struct ocfs2_extent_tree *et,
 					struct inode *inode,
 					struct buffer_head *bh,
 					struct ocfs2_xattr_value_root *xv);
+int ocfs2_is_dinode_extent_tree(struct ocfs2_extent_tree *et);
+int ocfs2_is_xattr_value_extent_tree(struct ocfs2_extent_tree *et);
+int ocfs2_is_xattr_tree_extent_tree(struct ocfs2_extent_tree *et);
 
 struct ocfs2_alloc_context;
 int ocfs2_insert_extent(struct ocfs2_super *osb,
-- 
1.5.4.GIT

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [Ocfs2-devel] [PATCH 2/2] ocfs2: Combine normal and xattr get extent clusters process together.
  2008-08-27  6:16 [Ocfs2-devel] [PATCH 0/2] ocfs2.git: Combine ocfs2_xattr_get_clusters to ocfs2_get_cluster Tao Ma
  2008-08-26 22:38 ` [Ocfs2-devel] [PATCH 1/2] ocfs2: Add wrapper for the check of extent tree type Tao Ma
  2008-08-26 22:44 ` Tao Ma
@ 2008-08-26 22:44 ` Tao Ma
  2 siblings, 0 replies; 4+ messages in thread
From: Tao Ma @ 2008-08-26 22:44 UTC (permalink / raw)
  To: ocfs2-devel

ocfs2_xattr_get_clusters was originally copied and modified from
ocfs2_get_clusters and some codes are almost common, so combine
them together with the help of new wrapper, ocfs2_extent_tree.

Signed-off-by: Tao Ma <tao.ma@oracle.com>
---
 fs/ocfs2/alloc.c      |    7 ++
 fs/ocfs2/extent_map.c |  146 +++++++++++++++++++------------------------------
 fs/ocfs2/extent_map.h |    2 +-
 fs/ocfs2/xattr.c      |    8 +--
 4 files changed, 68 insertions(+), 95 deletions(-)

diff --git a/fs/ocfs2/alloc.c b/fs/ocfs2/alloc.c
index 80dbf2f..da51f52 100644
--- a/fs/ocfs2/alloc.c
+++ b/fs/ocfs2/alloc.c
@@ -307,6 +307,13 @@ static void __ocfs2_init_extent_tree(struct ocfs2_extent_tree *et,
 				     void *obj,
 				     struct ocfs2_extent_tree_operations *ops)
 {
+	BUG_ON(!obj && !bh);
+	/*
+	 * We at least need one to get our et_root_el initialized.
+	 * And if no bh, No modification of the extent tree is allowed such
+	 * as inserting or removing extents.
+	 */
+
 	et->et_ops = ops;
 	et->et_root_bh = bh;
 	if (!obj)
diff --git a/fs/ocfs2/extent_map.c b/fs/ocfs2/extent_map.c
index 619b20a..623b189 100644
--- a/fs/ocfs2/extent_map.c
+++ b/fs/ocfs2/extent_map.c
@@ -373,12 +373,15 @@ out:
 	return ret;
 }
 
-int ocfs2_xattr_get_clusters(struct inode *inode, u32 v_cluster,
+int ocfs2_get_clusters_btree(struct inode *inode, u32 v_cluster,
 			     u32 *p_cluster, u32 *num_clusters,
-			     struct ocfs2_extent_list *el)
+			     struct ocfs2_extent_tree *et,
+			     unsigned int *extent_flags)
 {
 	int ret = 0, i;
+	unsigned int flags = 0;
 	struct buffer_head *eb_bh = NULL;
+	struct ocfs2_extent_list *el = et->et_root_el;
 	struct ocfs2_extent_block *eb;
 	struct ocfs2_extent_rec *rec;
 	u32 coff;
@@ -396,7 +399,7 @@ int ocfs2_xattr_get_clusters(struct inode *inode, u32 v_cluster,
 		if (el->l_tree_depth) {
 			ocfs2_error(inode->i_sb,
 				    "Inode %lu has non zero tree depth in "
-				    "xattr leaf block %llu\n", inode->i_ino,
+				    "leaf block %llu\n", inode->i_ino,
 				    (unsigned long long)eb_bh->b_blocknr);
 			ret = -EROFS;
 			goto out;
@@ -405,16 +408,36 @@ int ocfs2_xattr_get_clusters(struct inode *inode, u32 v_cluster,
 
 	i = ocfs2_search_extent_list(el, v_cluster);
 	if (i == -1) {
-		ret = -EROFS;
-		mlog_errno(ret);
-		goto out;
+		if (ocfs2_is_dinode_extent_tree(et)) {
+			/*
+			 * A hole was found. Return some canned values that
+			 * callers can key on. If asked for, num_clusters will
+			 * be populated with the size of the hole.
+			 */
+			*p_cluster = 0;
+			if (num_clusters) {
+				ret = ocfs2_figure_hole_clusters(inode, el,
+								 eb_bh,
+								 v_cluster,
+								 num_clusters);
+				if (ret) {
+					mlog_errno(ret);
+					goto out;
+				}
+			}
+		} else if (ocfs2_is_xattr_value_extent_tree(et)) {
+			ret = -EROFS;
+			mlog_errno(ret);
+			goto out;
+		} else
+			BUG();
 	} else {
 		rec = &el->l_recs[i];
 		BUG_ON(v_cluster < le32_to_cpu(rec->e_cpos));
 
 		if (!rec->e_blkno) {
 			ocfs2_error(inode->i_sb, "Inode %lu has bad extent "
-				    "record (%u, %u, 0) in xattr", inode->i_ino,
+				    "record (%u, %u, 0)", inode->i_ino,
 				    le32_to_cpu(rec->e_cpos),
 				    ocfs2_rec_clusters(el, rec));
 			ret = -EROFS;
@@ -426,26 +449,39 @@ int ocfs2_xattr_get_clusters(struct inode *inode, u32 v_cluster,
 		*p_cluster = *p_cluster + coff;
 		if (num_clusters)
 			*num_clusters = ocfs2_rec_clusters(el, rec) - coff;
+
+		flags = rec->e_flags;
+
+		if (ocfs2_is_dinode_extent_tree(et))
+			ocfs2_extent_map_insert_rec(inode, rec);
 	}
+
+	if (extent_flags)
+		*extent_flags = flags;
 out:
-	if (eb_bh)
-		brelse(eb_bh);
+	brelse(eb_bh);
 	return ret;
 }
 
+int ocfs2_xattr_get_clusters(struct inode *inode, u32 v_cluster,
+			     u32 *p_cluster, u32 *num_clusters,
+			     struct ocfs2_xattr_value_root *xv)
+{
+	struct ocfs2_extent_tree et;
+
+	ocfs2_init_xattr_value_extent_tree(&et, inode, NULL, xv);
+	return ocfs2_get_clusters_btree(inode, v_cluster,
+					p_cluster, num_clusters,
+					&et, NULL);
+}
+
 int ocfs2_get_clusters(struct inode *inode, u32 v_cluster,
 		       u32 *p_cluster, u32 *num_clusters,
 		       unsigned int *extent_flags)
 {
-	int ret, i;
-	unsigned int flags = 0;
+	int ret;
 	struct buffer_head *di_bh = NULL;
-	struct buffer_head *eb_bh = NULL;
-	struct ocfs2_dinode *di;
-	struct ocfs2_extent_block *eb;
-	struct ocfs2_extent_list *el;
-	struct ocfs2_extent_rec *rec;
-	u32 coff;
+	struct ocfs2_extent_tree et;
 
 	if (OCFS2_I(inode)->ip_dyn_features & OCFS2_INLINE_DATA_FL) {
 		ret = -ERANGE;
@@ -465,80 +501,12 @@ int ocfs2_get_clusters(struct inode *inode, u32 v_cluster,
 		goto out;
 	}
 
-	di = (struct ocfs2_dinode *) di_bh->b_data;
-	el = &di->id2.i_list;
-
-	if (el->l_tree_depth) {
-		ret = ocfs2_find_leaf(inode, el, v_cluster, &eb_bh);
-		if (ret) {
-			mlog_errno(ret);
-			goto out;
-		}
-
-		eb = (struct ocfs2_extent_block *) eb_bh->b_data;
-		el = &eb->h_list;
-
-		if (el->l_tree_depth) {
-			ocfs2_error(inode->i_sb,
-				    "Inode %lu has non zero tree depth in "
-				    "leaf block %llu\n", inode->i_ino,
-				    (unsigned long long)eb_bh->b_blocknr);
-			ret = -EROFS;
-			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. If asked for, num_clusters will
-		 * be populated with the size of the hole.
-		 */
-		*p_cluster = 0;
-		if (num_clusters) {
-			ret = ocfs2_figure_hole_clusters(inode, el, eb_bh,
-							 v_cluster,
-							 num_clusters);
-			if (ret) {
-				mlog_errno(ret);
-				goto out;
-			}
-		}
-	} else {
-		rec = &el->l_recs[i];
-
-		BUG_ON(v_cluster < le32_to_cpu(rec->e_cpos));
-
-		if (!rec->e_blkno) {
-			ocfs2_error(inode->i_sb, "Inode %lu has bad extent "
-				    "record (%u, %u, 0)", inode->i_ino,
-				    le32_to_cpu(rec->e_cpos),
-				    ocfs2_rec_clusters(el, rec));
-			ret = -EROFS;
-			goto out;
-		}
-
-		coff = v_cluster - le32_to_cpu(rec->e_cpos);
-
-		*p_cluster = ocfs2_blocks_to_clusters(inode->i_sb,
-						    le64_to_cpu(rec->e_blkno));
-		*p_cluster = *p_cluster + coff;
-
-		if (num_clusters)
-			*num_clusters = ocfs2_rec_clusters(el, rec) - coff;
-
-		flags = rec->e_flags;
-
-		ocfs2_extent_map_insert_rec(inode, rec);
-	}
-
-	if (extent_flags)
-		*extent_flags = flags;
-
+	ocfs2_init_dinode_extent_tree(&et, inode, di_bh);
+	ret = ocfs2_get_clusters_btree(inode, v_cluster,
+				       p_cluster, num_clusters,
+				       &et, extent_flags);
 out:
 	brelse(di_bh);
-	brelse(eb_bh);
 	return ret;
 }
 
diff --git a/fs/ocfs2/extent_map.h b/fs/ocfs2/extent_map.h
index d98444e..ac2d9d7 100644
--- a/fs/ocfs2/extent_map.h
+++ b/fs/ocfs2/extent_map.h
@@ -52,5 +52,5 @@ int ocfs2_extent_map_get_blocks(struct inode *inode, u64 v_blkno, u64 *p_blkno,
 
 int ocfs2_xattr_get_clusters(struct inode *inode, u32 v_cluster,
 			     u32 *p_cluster, u32 *num_clusters,
-			     struct ocfs2_extent_list *el);
+			     struct ocfs2_xattr_value_root *xv);
 #endif  /* _EXTENT_MAP_H */
diff --git a/fs/ocfs2/xattr.c b/fs/ocfs2/xattr.c
index 2ccffb1..2bc53b1 100644
--- a/fs/ocfs2/xattr.c
+++ b/fs/ocfs2/xattr.c
@@ -423,7 +423,7 @@ static int ocfs2_xattr_shrink_size(struct inode *inode,
 	trunc_len = old_clusters - new_clusters;
 	while (trunc_len) {
 		ret = ocfs2_xattr_get_clusters(inode, cpos, &phys_cpos,
-					       &alloc_size, &xv->xr_list);
+					       &alloc_size, xv);
 		if (ret) {
 			mlog_errno(ret);
 			goto out;
@@ -656,9 +656,7 @@ static int ocfs2_xattr_get_value_outside(struct inode *inode,
 	int i, ret = 0;
 	size_t cplen, blocksize;
 	struct buffer_head *bh = NULL;
-	struct ocfs2_extent_list *el;
 
-	el = &xv->xr_list;
 	clusters = le32_to_cpu(xv->xr_clusters);
 	bpc = ocfs2_clusters_to_blocks(inode->i_sb, 1);
 	blocksize = inode->i_sb->s_blocksize;
@@ -666,7 +664,7 @@ static int ocfs2_xattr_get_value_outside(struct inode *inode,
 	cpos = 0;
 	while (cpos < clusters) {
 		ret = ocfs2_xattr_get_clusters(inode, cpos, &p_cluster,
-					       &num_clusters, el);
+					       &num_clusters, xv);
 		if (ret) {
 			mlog_errno(ret);
 			goto out;
@@ -916,7 +914,7 @@ static int __ocfs2_xattr_set_value_outside(struct inode *inode,
 
 	while (cpos < clusters) {
 		ret = ocfs2_xattr_get_clusters(inode, cpos, &p_cluster,
-					       &num_clusters, &xv->xr_list);
+					       &num_clusters, xv);
 		if (ret) {
 			mlog_errno(ret);
 			goto out_commit;
-- 
1.5.4.GIT

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [Ocfs2-devel] [PATCH 0/2] ocfs2.git: Combine ocfs2_xattr_get_clusters to ocfs2_get_cluster.
@ 2008-08-27  6:16 Tao Ma
  2008-08-26 22:38 ` [Ocfs2-devel] [PATCH 1/2] ocfs2: Add wrapper for the check of extent tree type Tao Ma
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Tao Ma @ 2008-08-27  6:16 UTC (permalink / raw)
  To: ocfs2-devel

Hi,
	The ocfs2_xattr_get_clusters is originally copied from 
ocfs2_get_clusters, so most of the codes are common. This patch set 
merge them together.

Regards,
Tao

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2008-08-27  6:16 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-08-27  6:16 [Ocfs2-devel] [PATCH 0/2] ocfs2.git: Combine ocfs2_xattr_get_clusters to ocfs2_get_cluster Tao Ma
2008-08-26 22:38 ` [Ocfs2-devel] [PATCH 1/2] ocfs2: Add wrapper for the check of extent tree type Tao Ma
2008-08-26 22:44 ` Tao Ma
2008-08-26 22:44 ` [Ocfs2-devel] [PATCH 2/2] ocfs2: Combine normal and xattr get extent clusters process together Tao Ma

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.