aboutsummaryrefslogtreecommitdiffstats
path: root/fs/ocfs2/suballoc.c
diff options
context:
space:
mode:
authorJoel Becker <joel.becker@oracle.com>2010-03-26 10:08:59 +0800
committerTao Ma <tao.ma@oracle.com>2010-03-26 10:08:59 +0800
commitba2066351b630f0205ebf725f5c81a2a07a77cd7 (patch)
tree033395fc2b1679cc17fa72751e7f1837d42aee69 /fs/ocfs2/suballoc.c
parent1ed9b777f77929ae961d6f9cdf828a07200ba71c (diff)
downloadkernel_samsung_smdk4412-ba2066351b630f0205ebf725f5c81a2a07a77cd7.zip
kernel_samsung_smdk4412-ba2066351b630f0205ebf725f5c81a2a07a77cd7.tar.gz
kernel_samsung_smdk4412-ba2066351b630f0205ebf725f5c81a2a07a77cd7.tar.bz2
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.c43
1 files changed, 24 insertions, 19 deletions
diff --git a/fs/ocfs2/suballoc.c b/fs/ocfs2/suballoc.c
index 3f62017..9c2e669 100644
--- a/fs/ocfs2/suballoc.c
+++ b/fs/ocfs2/suballoc.c
@@ -55,6 +55,7 @@
struct ocfs2_suballoc_result {
u64 sr_bg_blkno; /* The bg we allocated from */
+ u64 sr_blkno; /* The first allocated block */
unsigned int sr_bit_offset; /* The bit in the bg */
unsigned int sr_bits; /* How many bits we claimed */
};
@@ -1579,9 +1580,9 @@ out:
return ret;
}
-static int ocfs2_bg_discontig_trim_by_rec(struct ocfs2_suballoc_result *res,
- struct ocfs2_extent_rec *rec,
- struct ocfs2_chain_list *cl)
+static int ocfs2_bg_discontig_fix_by_rec(struct ocfs2_suballoc_result *res,
+ struct ocfs2_extent_rec *rec,
+ struct ocfs2_chain_list *cl)
{
unsigned int bpc = le16_to_cpu(cl->cl_bpc);
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,
return 0;
if (res->sr_bit_offset >= (bitoff + bitcount))
return 0;
+ res->sr_blkno = le64_to_cpu(rec->e_blkno) +
+ (res->sr_bit_offset - bitoff);
if ((res->sr_bit_offset + res->sr_bits) > (bitoff + bitcount))
res->sr_bits = (bitoff + bitcount) - res->sr_bit_offset;
return 1;
}
-static void ocfs2_bg_discontig_trim_result(struct ocfs2_alloc_context *ac,
- struct ocfs2_group_desc *bg,
- struct ocfs2_suballoc_result *res)
+static void ocfs2_bg_discontig_fix_result(struct ocfs2_alloc_context *ac,
+ struct ocfs2_group_desc *bg,
+ struct ocfs2_suballoc_result *res)
{
int i;
struct ocfs2_extent_rec *rec;
struct ocfs2_dinode *di = (struct ocfs2_dinode *)ac->ac_bh->b_data;
struct ocfs2_chain_list *cl = &di->id2.i_chain;
- if (!ocfs2_supports_discontig_bh(OCFS2_SB(ac->ac_inode->i_sb)))
- return;
-
- if (ocfs2_is_cluster_bitmap(ac->ac_inode))
+ if (ocfs2_is_cluster_bitmap(ac->ac_inode)) {
+ res->sr_blkno = 0;
return;
+ }
- if (!bg->bg_list.l_next_free_rec)
+ res->sr_blkno = res->sr_bg_blkno + res->sr_bit_offset;
+ if (!ocfs2_supports_discontig_bh(OCFS2_SB(ac->ac_inode->i_sb)) ||
+ !bg->bg_list.l_next_free_rec)
return;
for (i = 0; i < le16_to_cpu(bg->bg_list.l_next_free_rec); i++) {
rec = &bg->bg_list.l_recs[i];
- if (ocfs2_bg_discontig_trim_by_rec(res, rec, cl))
+ if (ocfs2_bg_discontig_fix_by_rec(res, rec, cl))
break;
}
}
@@ -1651,7 +1655,7 @@ static int ocfs2_search_one_group(struct ocfs2_alloc_context *ac,
}
if (!ret)
- ocfs2_bg_discontig_trim_result(ac, gd, res);
+ ocfs2_bg_discontig_fix_result(ac, gd, res);
ret = ocfs2_alloc_dinode_update_counts(alloc_inode, handle, ac->ac_bh,
res->sr_bits,
@@ -1743,7 +1747,7 @@ static int ocfs2_search_chain(struct ocfs2_alloc_context *ac,
BUG_ON(res->sr_bits == 0);
if (!status)
- ocfs2_bg_discontig_trim_result(ac, bg, res);
+ ocfs2_bg_discontig_fix_result(ac, bg, res);
/*
@@ -1927,7 +1931,7 @@ int ocfs2_claim_metadata(handle_t *handle,
u64 *blkno_start)
{
int status;
- struct ocfs2_suballoc_result res;
+ struct ocfs2_suballoc_result res = { .sr_blkno = 0, };
BUG_ON(!ac);
BUG_ON(ac->ac_bits_wanted < (ac->ac_bits_given + bits_wanted));
@@ -1945,7 +1949,7 @@ int ocfs2_claim_metadata(handle_t *handle,
atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
*suballoc_bit_start = res.sr_bit_offset;
- *blkno_start = res.sr_bg_blkno + (u64)(res.sr_bit_offset);
+ *blkno_start = res.sr_blkno;
ac->ac_bits_given += res.sr_bits;
*num_bits = res.sr_bits;
status = 0;
@@ -1993,7 +1997,7 @@ int ocfs2_claim_new_inode(handle_t *handle,
u64 *fe_blkno)
{
int status;
- struct ocfs2_suballoc_result res;
+ struct ocfs2_suballoc_result res = { .sr_blkno = 0, };
mlog_entry_void();
@@ -2018,7 +2022,7 @@ int ocfs2_claim_new_inode(handle_t *handle,
BUG_ON(res.sr_bits != 1);
*suballoc_bit = res.sr_bit_offset;
- *fe_blkno = res.sr_bg_blkno + (u64)(res.sr_bit_offset);
+ *fe_blkno = res.sr_blkno;
ac->ac_bits_given++;
ocfs2_save_inode_ac_group(dir, ac);
status = 0;
@@ -2097,7 +2101,7 @@ int __ocfs2_claim_clusters(handle_t *handle,
{
int status;
unsigned int bits_wanted = max_clusters;
- struct ocfs2_suballoc_result res;
+ struct ocfs2_suballoc_result res = { .sr_blkno = 0, };
struct ocfs2_super *osb = OCFS2_SB(ac->ac_inode->i_sb);
mlog_entry_void();
@@ -2138,6 +2142,7 @@ int __ocfs2_claim_clusters(handle_t *handle,
min_clusters,
&res);
if (!status) {
+ BUG_ON(res.sr_blkno); /* cluster alloc can't set */
*cluster_start =
ocfs2_desc_bitmap_to_cluster_off(ac->ac_inode,
res.sr_bg_blkno,