@@ -341,15 +341,17 @@ static void ocfs2_bg_discontig_add_extent(struct ocfs2_super *osb,
341341 struct ocfs2_extent_list * el = & bg -> bg_list ;
342342 struct ocfs2_extent_rec * rec ;
343343
344- BUG_ON (!ocfs2_supports_discontig_bh (osb ));
344+ BUG_ON (!ocfs2_supports_discontig_bg (osb ));
345345 if (!el -> l_next_free_rec )
346346 el -> l_count = cpu_to_le16 (ocfs2_extent_recs_per_gd (osb -> sb ));
347347 rec = & el -> l_recs [le16_to_cpu (el -> l_next_free_rec )];
348- rec -> e_blkno = p_blkno ;
348+ rec -> e_blkno = cpu_to_le64 ( p_blkno ) ;
349349 rec -> e_cpos = cpu_to_le32 (le16_to_cpu (bg -> bg_bits ) /
350350 le16_to_cpu (cl -> cl_bpc ));
351351 rec -> e_leaf_clusters = cpu_to_le32 (clusters );
352352 le16_add_cpu (& bg -> bg_bits , clusters * le16_to_cpu (cl -> cl_bpc ));
353+ le16_add_cpu (& bg -> bg_free_bits_count ,
354+ clusters * le16_to_cpu (cl -> cl_bpc ));
353355 le16_add_cpu (& el -> l_next_free_rec , 1 );
354356}
355357
@@ -397,7 +399,7 @@ static int ocfs2_block_group_fill(handle_t *handle,
397399 if (group_clusters == le16_to_cpu (cl -> cl_cpg ))
398400 bg -> bg_bits = cpu_to_le16 (ocfs2_bits_per_group (cl ));
399401 else
400- ocfs2_bg_discontig_add_extent (osb , bg , cl , bg -> bg_blkno ,
402+ ocfs2_bg_discontig_add_extent (osb , bg , cl , group_blkno ,
401403 group_clusters );
402404
403405 /* set the 1st bit in the bitmap to account for the descriptor block */
@@ -506,8 +508,8 @@ static int ocfs2_block_group_grow_discontig(handle_t *handle,
506508 struct ocfs2_super * osb = OCFS2_SB (alloc_inode -> i_sb );
507509 struct ocfs2_group_desc * bg =
508510 (struct ocfs2_group_desc * )bg_bh -> b_data ;
509- unsigned int needed =
510- ocfs2_bits_per_group ( cl ) - le16_to_cpu (bg -> bg_bits );
511+ unsigned int needed = le16_to_cpu ( cl -> cl_cpg ) -
512+ le16_to_cpu ( bg -> bg_bits ) / le16_to_cpu (cl -> cl_bpc );
511513 u32 p_cpos , clusters ;
512514 u64 p_blkno ;
513515 struct ocfs2_extent_list * el = & bg -> bg_list ;
@@ -538,10 +540,17 @@ static int ocfs2_block_group_grow_discontig(handle_t *handle,
538540 clusters );
539541
540542 min_bits = clusters ;
541- needed = ocfs2_bits_per_group (cl ) - le16_to_cpu (bg -> bg_bits );
543+ needed = le16_to_cpu (cl -> cl_cpg ) -
544+ le16_to_cpu (bg -> bg_bits ) / le16_to_cpu (cl -> cl_bpc );
542545 }
543546
544547 if (needed > 0 ) {
548+ /*
549+ * We have used up all the extent rec but can't fill up
550+ * the cpg. So bail out.
551+ */
552+ status = - ENOSPC ;
553+ goto bail ;
545554 }
546555
547556 ocfs2_journal_dirty (handle , bg_bh );
@@ -594,7 +603,7 @@ ocfs2_block_group_alloc_discontig(handle_t *handle,
594603 unsigned int alloc_rec = ocfs2_find_smallest_chain (cl );
595604 struct ocfs2_super * osb = OCFS2_SB (alloc_inode -> i_sb );
596605
597- if (!ocfs2_supports_discontig_bh (osb )) {
606+ if (!ocfs2_supports_discontig_bg (osb )) {
598607 status = - ENOSPC ;
599608 goto bail ;
600609 }
@@ -670,7 +679,7 @@ static int ocfs2_block_group_alloc(struct ocfs2_super *osb,
670679 struct ocfs2_chain_list * cl ;
671680 struct ocfs2_alloc_context * ac = NULL ;
672681 handle_t * handle = NULL ;
673- u64 bg_blkno ;
682+ u16 alloc_rec ;
674683 struct buffer_head * bg_bh = NULL ;
675684 struct ocfs2_group_desc * bg ;
676685
@@ -726,11 +735,12 @@ static int ocfs2_block_group_alloc(struct ocfs2_super *osb,
726735 goto bail ;
727736 }
728737
729- le32_add_cpu (& cl -> cl_recs [bg -> bg_chain ].c_free ,
738+ alloc_rec = le16_to_cpu (bg -> bg_chain );
739+ le32_add_cpu (& cl -> cl_recs [alloc_rec ].c_free ,
730740 le16_to_cpu (bg -> bg_free_bits_count ));
731- le32_add_cpu (& cl -> cl_recs [bg -> bg_chain ].c_total ,
741+ le32_add_cpu (& cl -> cl_recs [alloc_rec ].c_total ,
732742 le16_to_cpu (bg -> bg_bits ));
733- cl -> cl_recs [bg -> bg_chain ].c_blkno = cpu_to_le64 (bg_blkno );
743+ cl -> cl_recs [alloc_rec ].c_blkno = cpu_to_le64 (bg -> bg_blkno );
734744 if (le16_to_cpu (cl -> cl_next_free_rec ) < le16_to_cpu (cl -> cl_count ))
735745 le16_add_cpu (& cl -> cl_next_free_rec , 1 );
736746
@@ -1622,7 +1632,7 @@ static void ocfs2_bg_discontig_fix_result(struct ocfs2_alloc_context *ac,
16221632
16231633 res -> sr_blkno = res -> sr_bg_blkno + res -> sr_bit_offset ;
16241634 res -> sr_bg_blkno = 0 ; /* Clear it for contig block groups */
1625- if (!ocfs2_supports_discontig_bh (OCFS2_SB (ac -> ac_inode -> i_sb )) ||
1635+ if (!ocfs2_supports_discontig_bg (OCFS2_SB (ac -> ac_inode -> i_sb )) ||
16261636 !bg -> bg_list .l_next_free_rec )
16271637 return ;
16281638
@@ -2162,6 +2172,7 @@ int __ocfs2_claim_clusters(handle_t *handle,
21622172 res .sr_bg_blkno ,
21632173 res .sr_bit_offset );
21642174 atomic_inc (& osb -> alloc_stats .bitmap_data );
2175+ * num_clusters = res .sr_bits ;
21652176 }
21662177 }
21672178 if (status < 0 ) {
@@ -2170,8 +2181,7 @@ int __ocfs2_claim_clusters(handle_t *handle,
21702181 goto bail ;
21712182 }
21722183
2173- ac -> ac_bits_given += res .sr_bits ;
2174- * num_clusters = res .sr_bits ;
2184+ ac -> ac_bits_given += * num_clusters ;
21752185
21762186bail :
21772187 mlog_exit (status );
0 commit comments