diff options
author | Joel Becker <joel.becker@oracle.com> | 2010-03-25 22:08:59 -0400 |
---|---|---|
committer | Tao Ma <tao.ma@oracle.com> | 2010-03-25 22:08:59 -0400 |
commit | ba2066351b630f0205ebf725f5c81a2a07a77cd7 (patch) | |
tree | 033395fc2b1679cc17fa72751e7f1837d42aee69 /fs/ocfs2/suballoc.c | |
parent | 1ed9b777f77929ae961d6f9cdf828a07200ba71c (diff) |
ocfs2: Return allocated metadata blknos on the ocfs2_suballoc_result.
Rather than calculating the resulting block number, return it on the
ocfs2_suballoc_result structure. This way we can calculate block
numbers for discontiguous block groups.
Cluster groups keep doing it the old way.
Signed-off-by: Joel Becker <joel.becker@oracle.com>
Diffstat (limited to 'fs/ocfs2/suballoc.c')
-rw-r--r-- | fs/ocfs2/suballoc.c | 43 |
1 files changed, 24 insertions, 19 deletions
diff --git a/fs/ocfs2/suballoc.c b/fs/ocfs2/suballoc.c index 3f6201777784..9c2e669a74fa 100644 --- a/fs/ocfs2/suballoc.c +++ b/fs/ocfs2/suballoc.c | |||
@@ -55,6 +55,7 @@ | |||
55 | 55 | ||
56 | struct ocfs2_suballoc_result { | 56 | struct ocfs2_suballoc_result { |
57 | u64 sr_bg_blkno; /* The bg we allocated from */ | 57 | u64 sr_bg_blkno; /* The bg we allocated from */ |
58 | u64 sr_blkno; /* The first allocated block */ | ||
58 | unsigned int sr_bit_offset; /* The bit in the bg */ | 59 | unsigned int sr_bit_offset; /* The bit in the bg */ |
59 | unsigned int sr_bits; /* How many bits we claimed */ | 60 | unsigned int sr_bits; /* How many bits we claimed */ |
60 | }; | 61 | }; |
@@ -1579,9 +1580,9 @@ out: | |||
1579 | return ret; | 1580 | return ret; |
1580 | } | 1581 | } |
1581 | 1582 | ||
1582 | static int ocfs2_bg_discontig_trim_by_rec(struct ocfs2_suballoc_result *res, | 1583 | static int ocfs2_bg_discontig_fix_by_rec(struct ocfs2_suballoc_result *res, |
1583 | struct ocfs2_extent_rec *rec, | 1584 | struct ocfs2_extent_rec *rec, |
1584 | struct ocfs2_chain_list *cl) | 1585 | struct ocfs2_chain_list *cl) |
1585 | { | 1586 | { |
1586 | unsigned int bpc = le16_to_cpu(cl->cl_bpc); | 1587 | unsigned int bpc = le16_to_cpu(cl->cl_bpc); |
1587 | unsigned int bitoff = le32_to_cpu(rec->e_cpos) * bpc; | 1588 | unsigned int bitoff = le32_to_cpu(rec->e_cpos) * bpc; |
@@ -1591,32 +1592,35 @@ static int ocfs2_bg_discontig_trim_by_rec(struct ocfs2_suballoc_result *res, | |||
1591 | return 0; | 1592 | return 0; |
1592 | if (res->sr_bit_offset >= (bitoff + bitcount)) | 1593 | if (res->sr_bit_offset >= (bitoff + bitcount)) |
1593 | return 0; | 1594 | return 0; |
1595 | res->sr_blkno = le64_to_cpu(rec->e_blkno) + | ||
1596 | (res->sr_bit_offset - bitoff); | ||
1594 | if ((res->sr_bit_offset + res->sr_bits) > (bitoff + bitcount)) | 1597 | if ((res->sr_bit_offset + res->sr_bits) > (bitoff + bitcount)) |
1595 | res->sr_bits = (bitoff + bitcount) - res->sr_bit_offset; | 1598 | res->sr_bits = (bitoff + bitcount) - res->sr_bit_offset; |
1596 | return 1; | 1599 | return 1; |
1597 | } | 1600 | } |
1598 | 1601 | ||
1599 | static void ocfs2_bg_discontig_trim_result(struct ocfs2_alloc_context *ac, | 1602 | static void ocfs2_bg_discontig_fix_result(struct ocfs2_alloc_context *ac, |
1600 | struct ocfs2_group_desc *bg, | 1603 | struct ocfs2_group_desc *bg, |
1601 | struct ocfs2_suballoc_result *res) | 1604 | struct ocfs2_suballoc_result *res) |
1602 | { | 1605 | { |
1603 | int i; | 1606 | int i; |
1604 | struct ocfs2_extent_rec *rec; | 1607 | struct ocfs2_extent_rec *rec; |
1605 | struct ocfs2_dinode *di = (struct ocfs2_dinode *)ac->ac_bh->b_data; | 1608 | struct ocfs2_dinode *di = (struct ocfs2_dinode *)ac->ac_bh->b_data; |
1606 | struct ocfs2_chain_list *cl = &di->id2.i_chain; | 1609 | struct ocfs2_chain_list *cl = &di->id2.i_chain; |
1607 | 1610 | ||
1608 | if (!ocfs2_supports_discontig_bh(OCFS2_SB(ac->ac_inode->i_sb))) | 1611 | if (ocfs2_is_cluster_bitmap(ac->ac_inode)) { |
1609 | return; | 1612 | res->sr_blkno = 0; |
1610 | |||
1611 | if (ocfs2_is_cluster_bitmap(ac->ac_inode)) | ||
1612 | return; | 1613 | return; |
1614 | } | ||
1613 | 1615 | ||
1614 | if (!bg->bg_list.l_next_free_rec) | 1616 | res->sr_blkno = res->sr_bg_blkno + res->sr_bit_offset; |
1617 | if (!ocfs2_supports_discontig_bh(OCFS2_SB(ac->ac_inode->i_sb)) || | ||
1618 | !bg->bg_list.l_next_free_rec) | ||
1615 | return; | 1619 | return; |
1616 | 1620 | ||
1617 | for (i = 0; i < le16_to_cpu(bg->bg_list.l_next_free_rec); i++) { | 1621 | for (i = 0; i < le16_to_cpu(bg->bg_list.l_next_free_rec); i++) { |
1618 | rec = &bg->bg_list.l_recs[i]; | 1622 | rec = &bg->bg_list.l_recs[i]; |
1619 | if (ocfs2_bg_discontig_trim_by_rec(res, rec, cl)) | 1623 | if (ocfs2_bg_discontig_fix_by_rec(res, rec, cl)) |
1620 | break; | 1624 | break; |
1621 | } | 1625 | } |
1622 | } | 1626 | } |
@@ -1651,7 +1655,7 @@ static int ocfs2_search_one_group(struct ocfs2_alloc_context *ac, | |||
1651 | } | 1655 | } |
1652 | 1656 | ||
1653 | if (!ret) | 1657 | if (!ret) |
1654 | ocfs2_bg_discontig_trim_result(ac, gd, res); | 1658 | ocfs2_bg_discontig_fix_result(ac, gd, res); |
1655 | 1659 | ||
1656 | ret = ocfs2_alloc_dinode_update_counts(alloc_inode, handle, ac->ac_bh, | 1660 | ret = ocfs2_alloc_dinode_update_counts(alloc_inode, handle, ac->ac_bh, |
1657 | res->sr_bits, | 1661 | res->sr_bits, |
@@ -1743,7 +1747,7 @@ static int ocfs2_search_chain(struct ocfs2_alloc_context *ac, | |||
1743 | 1747 | ||
1744 | BUG_ON(res->sr_bits == 0); | 1748 | BUG_ON(res->sr_bits == 0); |
1745 | if (!status) | 1749 | if (!status) |
1746 | ocfs2_bg_discontig_trim_result(ac, bg, res); | 1750 | ocfs2_bg_discontig_fix_result(ac, bg, res); |
1747 | 1751 | ||
1748 | 1752 | ||
1749 | /* | 1753 | /* |
@@ -1927,7 +1931,7 @@ int ocfs2_claim_metadata(handle_t *handle, | |||
1927 | u64 *blkno_start) | 1931 | u64 *blkno_start) |
1928 | { | 1932 | { |
1929 | int status; | 1933 | int status; |
1930 | struct ocfs2_suballoc_result res; | 1934 | struct ocfs2_suballoc_result res = { .sr_blkno = 0, }; |
1931 | 1935 | ||
1932 | BUG_ON(!ac); | 1936 | BUG_ON(!ac); |
1933 | BUG_ON(ac->ac_bits_wanted < (ac->ac_bits_given + bits_wanted)); | 1937 | BUG_ON(ac->ac_bits_wanted < (ac->ac_bits_given + bits_wanted)); |
@@ -1945,7 +1949,7 @@ int ocfs2_claim_metadata(handle_t *handle, | |||
1945 | atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs); | 1949 | atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs); |
1946 | 1950 | ||
1947 | *suballoc_bit_start = res.sr_bit_offset; | 1951 | *suballoc_bit_start = res.sr_bit_offset; |
1948 | *blkno_start = res.sr_bg_blkno + (u64)(res.sr_bit_offset); | 1952 | *blkno_start = res.sr_blkno; |
1949 | ac->ac_bits_given += res.sr_bits; | 1953 | ac->ac_bits_given += res.sr_bits; |
1950 | *num_bits = res.sr_bits; | 1954 | *num_bits = res.sr_bits; |
1951 | status = 0; | 1955 | status = 0; |
@@ -1993,7 +1997,7 @@ int ocfs2_claim_new_inode(handle_t *handle, | |||
1993 | u64 *fe_blkno) | 1997 | u64 *fe_blkno) |
1994 | { | 1998 | { |
1995 | int status; | 1999 | int status; |
1996 | struct ocfs2_suballoc_result res; | 2000 | struct ocfs2_suballoc_result res = { .sr_blkno = 0, }; |
1997 | 2001 | ||
1998 | mlog_entry_void(); | 2002 | mlog_entry_void(); |
1999 | 2003 | ||
@@ -2018,7 +2022,7 @@ int ocfs2_claim_new_inode(handle_t *handle, | |||
2018 | BUG_ON(res.sr_bits != 1); | 2022 | BUG_ON(res.sr_bits != 1); |
2019 | 2023 | ||
2020 | *suballoc_bit = res.sr_bit_offset; | 2024 | *suballoc_bit = res.sr_bit_offset; |
2021 | *fe_blkno = res.sr_bg_blkno + (u64)(res.sr_bit_offset); | 2025 | *fe_blkno = res.sr_blkno; |
2022 | ac->ac_bits_given++; | 2026 | ac->ac_bits_given++; |
2023 | ocfs2_save_inode_ac_group(dir, ac); | 2027 | ocfs2_save_inode_ac_group(dir, ac); |
2024 | status = 0; | 2028 | status = 0; |
@@ -2097,7 +2101,7 @@ int __ocfs2_claim_clusters(handle_t *handle, | |||
2097 | { | 2101 | { |
2098 | int status; | 2102 | int status; |
2099 | unsigned int bits_wanted = max_clusters; | 2103 | unsigned int bits_wanted = max_clusters; |
2100 | struct ocfs2_suballoc_result res; | 2104 | struct ocfs2_suballoc_result res = { .sr_blkno = 0, }; |
2101 | struct ocfs2_super *osb = OCFS2_SB(ac->ac_inode->i_sb); | 2105 | struct ocfs2_super *osb = OCFS2_SB(ac->ac_inode->i_sb); |
2102 | 2106 | ||
2103 | mlog_entry_void(); | 2107 | mlog_entry_void(); |
@@ -2138,6 +2142,7 @@ int __ocfs2_claim_clusters(handle_t *handle, | |||
2138 | min_clusters, | 2142 | min_clusters, |
2139 | &res); | 2143 | &res); |
2140 | if (!status) { | 2144 | if (!status) { |
2145 | BUG_ON(res.sr_blkno); /* cluster alloc can't set */ | ||
2141 | *cluster_start = | 2146 | *cluster_start = |
2142 | ocfs2_desc_bitmap_to_cluster_off(ac->ac_inode, | 2147 | ocfs2_desc_bitmap_to_cluster_off(ac->ac_inode, |
2143 | res.sr_bg_blkno, | 2148 | res.sr_bg_blkno, |