@@ -79,6 +79,7 @@ struct ocfs2_extent_tree {
7979 struct buffer_head * root_bh ;
8080 struct ocfs2_extent_list * root_el ;
8181 void * private ;
82+ unsigned int max_leaf_clusters ;
8283};
8384
8485static void ocfs2_dinode_set_last_eb_blk (struct ocfs2_extent_tree * et ,
@@ -220,7 +221,8 @@ static struct ocfs2_extent_tree_operations ocfs2_xattr_tree_et_ops = {
220221};
221222
222223static struct ocfs2_extent_tree *
223- ocfs2_new_extent_tree (struct buffer_head * bh ,
224+ ocfs2_new_extent_tree (struct inode * inode ,
225+ struct buffer_head * bh ,
224226 enum ocfs2_extent_tree_type et_type ,
225227 void * private )
226228{
@@ -248,6 +250,8 @@ static struct ocfs2_extent_tree*
248250 (struct ocfs2_xattr_block * )bh -> b_data ;
249251 et -> root_el = & xb -> xb_attrs .xb_root .xt_list ;
250252 et -> eops = & ocfs2_xattr_tree_et_ops ;
253+ et -> max_leaf_clusters = ocfs2_clusters_for_bytes (inode -> i_sb ,
254+ OCFS2_MAX_XATTR_TREE_LEAF_SIZE );
251255 }
252256
253257 return et ;
@@ -4109,7 +4113,8 @@ ocfs2_figure_merge_contig_type(struct inode *inode, struct ocfs2_path *path,
41094113static void ocfs2_figure_contig_type (struct inode * inode ,
41104114 struct ocfs2_insert_type * insert ,
41114115 struct ocfs2_extent_list * el ,
4112- struct ocfs2_extent_rec * insert_rec )
4116+ struct ocfs2_extent_rec * insert_rec ,
4117+ struct ocfs2_extent_tree * et )
41134118{
41144119 int i ;
41154120 enum ocfs2_contig_type contig_type = CONTIG_NONE ;
@@ -4125,6 +4130,20 @@ static void ocfs2_figure_contig_type(struct inode *inode,
41254130 }
41264131 }
41274132 insert -> ins_contig = contig_type ;
4133+
4134+ if (insert -> ins_contig != CONTIG_NONE ) {
4135+ struct ocfs2_extent_rec * rec =
4136+ & el -> l_recs [insert -> ins_contig_index ];
4137+ unsigned int len = le16_to_cpu (rec -> e_leaf_clusters ) +
4138+ le16_to_cpu (insert_rec -> e_leaf_clusters );
4139+
4140+ /*
4141+ * Caller might want us to limit the size of extents, don't
4142+ * calculate contiguousness if we might exceed that limit.
4143+ */
4144+ if (et -> max_leaf_clusters && len > et -> max_leaf_clusters )
4145+ insert -> ins_contig = CONTIG_NONE ;
4146+ }
41284147}
41294148
41304149/*
@@ -4232,7 +4251,7 @@ static int ocfs2_figure_insert_type(struct inode *inode,
42324251 le16_to_cpu (el -> l_next_free_rec );
42334252
42344253 if (!insert -> ins_tree_depth ) {
4235- ocfs2_figure_contig_type (inode , insert , el , insert_rec );
4254+ ocfs2_figure_contig_type (inode , insert , el , insert_rec , et );
42364255 ocfs2_figure_appending_type (insert , el , insert_rec );
42374256 return 0 ;
42384257 }
@@ -4266,7 +4285,7 @@ static int ocfs2_figure_insert_type(struct inode *inode,
42664285 * into two types of appends: simple record append, or a
42674286 * rotate inside the tail leaf.
42684287 */
4269- ocfs2_figure_contig_type (inode , insert , el , insert_rec );
4288+ ocfs2_figure_contig_type (inode , insert , el , insert_rec , et );
42704289
42714290 /*
42724291 * The insert code isn't quite ready to deal with all cases of
@@ -4402,7 +4421,7 @@ int ocfs2_dinode_insert_extent(struct ocfs2_super *osb,
44024421 int status ;
44034422 struct ocfs2_extent_tree * et = NULL ;
44044423
4405- et = ocfs2_new_extent_tree (root_bh , OCFS2_DINODE_EXTENT , NULL );
4424+ et = ocfs2_new_extent_tree (inode , root_bh , OCFS2_DINODE_EXTENT , NULL );
44064425 if (!et ) {
44074426 status = - ENOMEM ;
44084427 mlog_errno (status );
@@ -4433,7 +4452,8 @@ int ocfs2_xattr_value_insert_extent(struct ocfs2_super *osb,
44334452 int status ;
44344453 struct ocfs2_extent_tree * et = NULL ;
44354454
4436- et = ocfs2_new_extent_tree (root_bh , OCFS2_XATTR_VALUE_EXTENT , private );
4455+ et = ocfs2_new_extent_tree (inode , root_bh ,
4456+ OCFS2_XATTR_VALUE_EXTENT , private );
44374457 if (!et ) {
44384458 status = - ENOMEM ;
44394459 mlog_errno (status );
@@ -4463,7 +4483,8 @@ int ocfs2_xattr_tree_insert_extent(struct ocfs2_super *osb,
44634483 int status ;
44644484 struct ocfs2_extent_tree * et = NULL ;
44654485
4466- et = ocfs2_new_extent_tree (root_bh , OCFS2_XATTR_TREE_EXTENT , NULL );
4486+ et = ocfs2_new_extent_tree (inode , root_bh , OCFS2_XATTR_TREE_EXTENT ,
4487+ NULL );
44674488 if (!et ) {
44684489 status = - ENOMEM ;
44694490 mlog_errno (status );
@@ -4879,7 +4900,7 @@ int ocfs2_mark_extent_written(struct inode *inode, struct buffer_head *root_bh,
48794900 goto out ;
48804901 }
48814902
4882- et = ocfs2_new_extent_tree (root_bh , et_type , private );
4903+ et = ocfs2_new_extent_tree (inode , root_bh , et_type , private );
48834904 if (!et ) {
48844905 ret = - ENOMEM ;
48854906 mlog_errno (ret );
@@ -5177,7 +5198,7 @@ int ocfs2_remove_extent(struct inode *inode, struct buffer_head *root_bh,
51775198 struct ocfs2_path * path = NULL ;
51785199 struct ocfs2_extent_tree * et = NULL ;
51795200
5180- et = ocfs2_new_extent_tree (root_bh , et_type , private );
5201+ et = ocfs2_new_extent_tree (inode , root_bh , et_type , private );
51815202 if (!et ) {
51825203 ret = - ENOMEM ;
51835204 mlog_errno (ret );
0 commit comments