aboutsummaryrefslogtreecommitdiffstats
path: root/fs/ocfs2
diff options
context:
space:
mode:
authorTao Ma <tao.ma@oracle.com>2010-04-22 02:09:15 -0400
committerTao Ma <tao.ma@oracle.com>2010-04-22 02:09:15 -0400
commit4711954eaa8d30f653fda238cecf919f1ae40d6f (patch)
treef150d49ce67d3982faa22a3a73c143cc901234ac /fs/ocfs2
parent95ec0adf0b56d6a3f0ca1ec87173311898486b2e (diff)
ocfs2: Some tiny bug fixes for discontiguous block allocation.
The fixes include: 1. some endian problems. 2. we should use bit/bpc in ocfs2_block_group_grow_discontig to allocate clusters. 3. set num_clusters properly in __ocfs2_claim_clusters. 4. change name from ocfs2_supports_discontig_bh to ocfs2_supports_discontig_bg. Signed-off-by: Tao Ma <tao.ma@oracle.com>
Diffstat (limited to 'fs/ocfs2')
-rw-r--r--fs/ocfs2/ocfs2.h2
-rw-r--r--fs/ocfs2/suballoc.c38
2 files changed, 25 insertions, 15 deletions
diff --git a/fs/ocfs2/ocfs2.h b/fs/ocfs2/ocfs2.h
index d389f2714c96..c67003b6b5a2 100644
--- a/fs/ocfs2/ocfs2.h
+++ b/fs/ocfs2/ocfs2.h
@@ -491,7 +491,7 @@ static inline int ocfs2_supports_indexed_dirs(struct ocfs2_super *osb)
491 return 0; 491 return 0;
492} 492}
493 493
494static inline int ocfs2_supports_discontig_bh(struct ocfs2_super *osb) 494static inline int ocfs2_supports_discontig_bg(struct ocfs2_super *osb)
495{ 495{
496 if (osb->s_feature_incompat & OCFS2_FEATURE_INCOMPAT_DISCONTIG_BG) 496 if (osb->s_feature_incompat & OCFS2_FEATURE_INCOMPAT_DISCONTIG_BG)
497 return 1; 497 return 1;
diff --git a/fs/ocfs2/suballoc.c b/fs/ocfs2/suballoc.c
index 5852a46647a2..b7491e2481ca 100644
--- a/fs/ocfs2/suballoc.c
+++ b/fs/ocfs2/suballoc.c
@@ -341,15 +341,17 @@ static void ocfs2_bg_discontig_add_extent(struct ocfs2_super *osb,
341 struct ocfs2_extent_list *el = &bg->bg_list; 341 struct ocfs2_extent_list *el = &bg->bg_list;
342 struct ocfs2_extent_rec *rec; 342 struct ocfs2_extent_rec *rec;
343 343
344 BUG_ON(!ocfs2_supports_discontig_bh(osb)); 344 BUG_ON(!ocfs2_supports_discontig_bg(osb));
345 if (!el->l_next_free_rec) 345 if (!el->l_next_free_rec)
346 el->l_count = cpu_to_le16(ocfs2_extent_recs_per_gd(osb->sb)); 346 el->l_count = cpu_to_le16(ocfs2_extent_recs_per_gd(osb->sb));
347 rec = &el->l_recs[le16_to_cpu(el->l_next_free_rec)]; 347 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);
349 rec->e_cpos = cpu_to_le32(le16_to_cpu(bg->bg_bits) / 349 rec->e_cpos = cpu_to_le32(le16_to_cpu(bg->bg_bits) /
350 le16_to_cpu(cl->cl_bpc)); 350 le16_to_cpu(cl->cl_bpc));
351 rec->e_leaf_clusters = cpu_to_le32(clusters); 351 rec->e_leaf_clusters = cpu_to_le32(clusters);
352 le16_add_cpu(&bg->bg_bits, clusters * le16_to_cpu(cl->cl_bpc)); 352 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));
353 le16_add_cpu(&el->l_next_free_rec, 1); 355 le16_add_cpu(&el->l_next_free_rec, 1);
354} 356}
355 357
@@ -397,7 +399,7 @@ static int ocfs2_block_group_fill(handle_t *handle,
397 if (group_clusters == le16_to_cpu(cl->cl_cpg)) 399 if (group_clusters == le16_to_cpu(cl->cl_cpg))
398 bg->bg_bits = cpu_to_le16(ocfs2_bits_per_group(cl)); 400 bg->bg_bits = cpu_to_le16(ocfs2_bits_per_group(cl));
399 else 401 else
400 ocfs2_bg_discontig_add_extent(osb, bg, cl, bg->bg_blkno, 402 ocfs2_bg_discontig_add_extent(osb, bg, cl, group_blkno,
401 group_clusters); 403 group_clusters);
402 404
403 /* set the 1st bit in the bitmap to account for the descriptor block */ 405 /* 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,
506 struct ocfs2_super *osb = OCFS2_SB(alloc_inode->i_sb); 508 struct ocfs2_super *osb = OCFS2_SB(alloc_inode->i_sb);
507 struct ocfs2_group_desc *bg = 509 struct ocfs2_group_desc *bg =
508 (struct ocfs2_group_desc *)bg_bh->b_data; 510 (struct ocfs2_group_desc *)bg_bh->b_data;
509 unsigned int needed = 511 unsigned int needed = le16_to_cpu(cl->cl_cpg) -
510 ocfs2_bits_per_group(cl) - le16_to_cpu(bg->bg_bits); 512 le16_to_cpu(bg->bg_bits) / le16_to_cpu(cl->cl_bpc);
511 u32 p_cpos, clusters; 513 u32 p_cpos, clusters;
512 u64 p_blkno; 514 u64 p_blkno;
513 struct ocfs2_extent_list *el = &bg->bg_list; 515 struct ocfs2_extent_list *el = &bg->bg_list;
@@ -538,10 +540,17 @@ static int ocfs2_block_group_grow_discontig(handle_t *handle,
538 clusters); 540 clusters);
539 541
540 min_bits = clusters; 542 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);
542 } 545 }
543 546
544 if (needed > 0) { 547 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;
545 } 554 }
546 555
547 ocfs2_journal_dirty(handle, bg_bh); 556 ocfs2_journal_dirty(handle, bg_bh);
@@ -594,7 +603,7 @@ ocfs2_block_group_alloc_discontig(handle_t *handle,
594 unsigned int alloc_rec = ocfs2_find_smallest_chain(cl); 603 unsigned int alloc_rec = ocfs2_find_smallest_chain(cl);
595 struct ocfs2_super *osb = OCFS2_SB(alloc_inode->i_sb); 604 struct ocfs2_super *osb = OCFS2_SB(alloc_inode->i_sb);
596 605
597 if (!ocfs2_supports_discontig_bh(osb)) { 606 if (!ocfs2_supports_discontig_bg(osb)) {
598 status = -ENOSPC; 607 status = -ENOSPC;
599 goto bail; 608 goto bail;
600 } 609 }
@@ -670,7 +679,7 @@ static int ocfs2_block_group_alloc(struct ocfs2_super *osb,
670 struct ocfs2_chain_list *cl; 679 struct ocfs2_chain_list *cl;
671 struct ocfs2_alloc_context *ac = NULL; 680 struct ocfs2_alloc_context *ac = NULL;
672 handle_t *handle = NULL; 681 handle_t *handle = NULL;
673 u64 bg_blkno; 682 u16 alloc_rec;
674 struct buffer_head *bg_bh = NULL; 683 struct buffer_head *bg_bh = NULL;
675 struct ocfs2_group_desc *bg; 684 struct ocfs2_group_desc *bg;
676 685
@@ -726,11 +735,12 @@ static int ocfs2_block_group_alloc(struct ocfs2_super *osb,
726 goto bail; 735 goto bail;
727 } 736 }
728 737
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,
730 le16_to_cpu(bg->bg_free_bits_count)); 740 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,
732 le16_to_cpu(bg->bg_bits)); 742 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);
734 if (le16_to_cpu(cl->cl_next_free_rec) < le16_to_cpu(cl->cl_count)) 744 if (le16_to_cpu(cl->cl_next_free_rec) < le16_to_cpu(cl->cl_count))
735 le16_add_cpu(&cl->cl_next_free_rec, 1); 745 le16_add_cpu(&cl->cl_next_free_rec, 1);
736 746
@@ -1622,7 +1632,7 @@ static void ocfs2_bg_discontig_fix_result(struct ocfs2_alloc_context *ac,
1622 1632
1623 res->sr_blkno = res->sr_bg_blkno + res->sr_bit_offset; 1633 res->sr_blkno = res->sr_bg_blkno + res->sr_bit_offset;
1624 res->sr_bg_blkno = 0; /* Clear it for contig block groups */ 1634 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)) ||
1626 !bg->bg_list.l_next_free_rec) 1636 !bg->bg_list.l_next_free_rec)
1627 return; 1637 return;
1628 1638
@@ -2162,6 +2172,7 @@ int __ocfs2_claim_clusters(handle_t *handle,
2162 res.sr_bg_blkno, 2172 res.sr_bg_blkno,
2163 res.sr_bit_offset); 2173 res.sr_bit_offset);
2164 atomic_inc(&osb->alloc_stats.bitmap_data); 2174 atomic_inc(&osb->alloc_stats.bitmap_data);
2175 *num_clusters = res.sr_bits;
2165 } 2176 }
2166 } 2177 }
2167 if (status < 0) { 2178 if (status < 0) {
@@ -2170,8 +2181,7 @@ int __ocfs2_claim_clusters(handle_t *handle,
2170 goto bail; 2181 goto bail;
2171 } 2182 }
2172 2183
2173 ac->ac_bits_given += res.sr_bits; 2184 ac->ac_bits_given += *num_clusters;
2174 *num_clusters = res.sr_bits;
2175 2185
2176bail: 2186bail:
2177 mlog_exit(status); 2187 mlog_exit(status);