]> bbs.cooldavid.org Git - net-next-2.6.git/commitdiff
ocfs2: Set suballoc_loc on allocated metadata.
authorJoel Becker <joel.becker@oracle.com>
Fri, 26 Mar 2010 02:09:15 +0000 (10:09 +0800)
committerTao Ma <tao.ma@oracle.com>
Fri, 26 Mar 2010 02:09:15 +0000 (10:09 +0800)
Get the suballoc_loc from ocfs2_claim_new_inode() or
ocfs2_claim_metadata().  Store it on the appropriate field of the block
we just allocated.

Signed-off-by: Joel Becker <joel.becker@oracle.com>
fs/ocfs2/alloc.c
fs/ocfs2/dir.c
fs/ocfs2/namei.c
fs/ocfs2/refcounttree.c
fs/ocfs2/suballoc.c
fs/ocfs2/suballoc.h
fs/ocfs2/xattr.c

index b6e2ba1f6a7b79db6d21c747c4700c2b51048521..479d2ecae340de69845f9ad77aeb59113e64e948 100644 (file)
@@ -1006,7 +1006,7 @@ static int ocfs2_create_new_meta_bhs(handle_t *handle,
        int count, status, i;
        u16 suballoc_bit_start;
        u32 num_got;
-       u64 first_blkno;
+       u64 suballoc_loc, first_blkno;
        struct ocfs2_super *osb =
                OCFS2_SB(ocfs2_metadata_cache_get_super(et->et_ci));
        struct ocfs2_extent_block *eb;
@@ -1018,6 +1018,7 @@ static int ocfs2_create_new_meta_bhs(handle_t *handle,
                status = ocfs2_claim_metadata(handle,
                                              meta_ac,
                                              wanted - count,
+                                             &suballoc_loc,
                                              &suballoc_bit_start,
                                              &num_got,
                                              &first_blkno);
@@ -1051,6 +1052,7 @@ static int ocfs2_create_new_meta_bhs(handle_t *handle,
                        eb->h_fs_generation = cpu_to_le32(osb->fs_generation);
                        eb->h_suballoc_slot =
                                cpu_to_le16(meta_ac->ac_alloc_slot);
+                       eb->h_suballoc_loc = cpu_to_le64(suballoc_loc);
                        eb->h_suballoc_bit = cpu_to_le16(suballoc_bit_start);
                        eb->h_list.l_count =
                                cpu_to_le16(ocfs2_extent_recs_per_eb(osb->sb));
index 02c3f2261550c747ec871a62c598cd3e3b536d54..341bb8f811e9d91927847daf341230bda1c0119a 100644 (file)
@@ -2395,15 +2395,15 @@ static int ocfs2_dx_dir_attach_index(struct ocfs2_super *osb,
        int ret;
        struct ocfs2_dinode *di = (struct ocfs2_dinode *) di_bh->b_data;
        u16 dr_suballoc_bit;
-       u64 dr_blkno;
+       u64 suballoc_loc, dr_blkno;
        unsigned int num_bits;
        struct buffer_head *dx_root_bh = NULL;
        struct ocfs2_dx_root_block *dx_root;
        struct ocfs2_dir_block_trailer *trailer =
                ocfs2_trailer_from_bh(dirdata_bh, dir->i_sb);
 
-       ret = ocfs2_claim_metadata(handle, meta_ac, 1, &dr_suballoc_bit,
-                                  &num_bits, &dr_blkno);
+       ret = ocfs2_claim_metadata(handle, meta_ac, 1, &suballoc_loc,
+                                  &dr_suballoc_bit, &num_bits, &dr_blkno);
        if (ret) {
                mlog_errno(ret);
                goto out;
@@ -2431,6 +2431,7 @@ static int ocfs2_dx_dir_attach_index(struct ocfs2_super *osb,
        memset(dx_root, 0, osb->sb->s_blocksize);
        strcpy(dx_root->dr_signature, OCFS2_DX_ROOT_SIGNATURE);
        dx_root->dr_suballoc_slot = cpu_to_le16(meta_ac->ac_alloc_slot);
+       dx_root->dr_suballoc_loc = cpu_to_le64(suballoc_loc);
        dx_root->dr_suballoc_bit = cpu_to_le16(dr_suballoc_bit);
        dx_root->dr_fs_generation = cpu_to_le32(osb->fs_generation);
        dx_root->dr_blkno = cpu_to_le64(dr_blkno);
index e5434a04b88a90bc2da71fce934318daee8f0bbf..bfe4571a4fa1e59e64f5f43142d7ae753a6f9386 100644 (file)
@@ -472,14 +472,15 @@ static int ocfs2_mknod_locked(struct ocfs2_super *osb,
        int status = 0;
        struct ocfs2_dinode *fe = NULL;
        struct ocfs2_extent_list *fel;
-       u64 fe_blkno = 0;
+       u64 suballoc_loc, fe_blkno = 0;
        u16 suballoc_bit;
        u16 feat;
 
        *new_fe_bh = NULL;
 
        status = ocfs2_claim_new_inode(handle, dir, parent_fe_bh,
-                                      inode_ac, &suballoc_bit, &fe_blkno);
+                                      inode_ac, &suballoc_loc,
+                                      &suballoc_bit, &fe_blkno);
        if (status < 0) {
                mlog_errno(status);
                goto leave;
@@ -516,6 +517,7 @@ static int ocfs2_mknod_locked(struct ocfs2_super *osb,
        fe->i_generation = cpu_to_le32(inode->i_generation);
        fe->i_fs_generation = cpu_to_le32(osb->fs_generation);
        fe->i_blkno = cpu_to_le64(fe_blkno);
+       fe->i_suballoc_loc = cpu_to_le64(suballoc_loc);
        fe->i_suballoc_bit = cpu_to_le16(suballoc_bit);
        fe->i_suballoc_slot = cpu_to_le16(inode_ac->ac_alloc_slot);
        fe->i_uid = cpu_to_le32(inode->i_uid);
index 2bd74766c4e0dad10caa1e435b2a0e7974f462e7..275920e8a40d3e5f4545174c02901bce88a84f9d 100644 (file)
@@ -571,7 +571,7 @@ static int ocfs2_create_refcount_tree(struct inode *inode,
        struct ocfs2_refcount_tree *new_tree = NULL, *tree = NULL;
        u16 suballoc_bit_start;
        u32 num_got;
-       u64 first_blkno;
+       u64 suballoc_loc, first_blkno;
 
        BUG_ON(oi->ip_dyn_features & OCFS2_HAS_REFCOUNT_FL);
 
@@ -597,7 +597,7 @@ static int ocfs2_create_refcount_tree(struct inode *inode,
                goto out_commit;
        }
 
-       ret = ocfs2_claim_metadata(handle, meta_ac, 1,
+       ret = ocfs2_claim_metadata(handle, meta_ac, 1, &suballoc_loc,
                                   &suballoc_bit_start, &num_got,
                                   &first_blkno);
        if (ret) {
@@ -627,6 +627,7 @@ static int ocfs2_create_refcount_tree(struct inode *inode,
        memset(rb, 0, inode->i_sb->s_blocksize);
        strcpy((void *)rb, OCFS2_REFCOUNT_BLOCK_SIGNATURE);
        rb->rf_suballoc_slot = cpu_to_le16(meta_ac->ac_alloc_slot);
+       rb->rf_suballoc_loc = cpu_to_le64(suballoc_loc);
        rb->rf_suballoc_bit = cpu_to_le16(suballoc_bit_start);
        rb->rf_fs_generation = cpu_to_le32(osb->fs_generation);
        rb->rf_blkno = cpu_to_le64(first_blkno);
@@ -1283,7 +1284,7 @@ static int ocfs2_expand_inline_ref_root(handle_t *handle,
        int ret;
        u16 suballoc_bit_start;
        u32 num_got;
-       u64 blkno;
+       u64 suballoc_loc, blkno;
        struct super_block *sb = ocfs2_metadata_cache_get_super(ci);
        struct buffer_head *new_bh = NULL;
        struct ocfs2_refcount_block *new_rb;
@@ -1297,7 +1298,7 @@ static int ocfs2_expand_inline_ref_root(handle_t *handle,
                goto out;
        }
 
-       ret = ocfs2_claim_metadata(handle, meta_ac, 1,
+       ret = ocfs2_claim_metadata(handle, meta_ac, 1, &suballoc_loc,
                                   &suballoc_bit_start, &num_got,
                                   &blkno);
        if (ret) {
@@ -1329,6 +1330,7 @@ static int ocfs2_expand_inline_ref_root(handle_t *handle,
 
        new_rb = (struct ocfs2_refcount_block *)new_bh->b_data;
        new_rb->rf_suballoc_slot = cpu_to_le16(meta_ac->ac_alloc_slot);
+       new_rb->rf_suballoc_loc = cpu_to_le64(suballoc_loc);
        new_rb->rf_suballoc_bit = cpu_to_le16(suballoc_bit_start);
        new_rb->rf_blkno = cpu_to_le64(blkno);
        new_rb->rf_cpos = cpu_to_le32(0);
@@ -1523,7 +1525,7 @@ static int ocfs2_new_leaf_refcount_block(handle_t *handle,
        int ret;
        u16 suballoc_bit_start;
        u32 num_got, new_cpos;
-       u64 blkno;
+       u64 suballoc_loc, blkno;
        struct super_block *sb = ocfs2_metadata_cache_get_super(ci);
        struct ocfs2_refcount_block *root_rb =
                        (struct ocfs2_refcount_block *)ref_root_bh->b_data;
@@ -1547,7 +1549,7 @@ static int ocfs2_new_leaf_refcount_block(handle_t *handle,
                goto out;
        }
 
-       ret = ocfs2_claim_metadata(handle, meta_ac, 1,
+       ret = ocfs2_claim_metadata(handle, meta_ac, 1, &suballoc_loc,
                                   &suballoc_bit_start, &num_got,
                                   &blkno);
        if (ret) {
@@ -1575,6 +1577,7 @@ static int ocfs2_new_leaf_refcount_block(handle_t *handle,
        memset(new_rb, 0, sb->s_blocksize);
        strcpy((void *)new_rb, OCFS2_REFCOUNT_BLOCK_SIGNATURE);
        new_rb->rf_suballoc_slot = cpu_to_le16(meta_ac->ac_alloc_slot);
+       new_rb->rf_suballoc_loc = cpu_to_le64(suballoc_loc);
        new_rb->rf_suballoc_bit = cpu_to_le16(suballoc_bit_start);
        new_rb->rf_fs_generation = cpu_to_le32(OCFS2_SB(sb)->fs_generation);
        new_rb->rf_blkno = cpu_to_le64(blkno);
index 9c2e669a74fad6bda50297cb24d83b63e7ab9f9f..7809f41bcbfc4eb5592f6797a5b10a75e8997093 100644 (file)
@@ -54,7 +54,9 @@
 #define OCFS2_MAX_TO_STEAL             1024
 
 struct ocfs2_suballoc_result {
-       u64             sr_bg_blkno;    /* The bg we allocated from */
+       u64             sr_bg_blkno;    /* The bg we allocated from.  Set
+                                          to 0 when a block group is
+                                          contiguous. */
        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 */
@@ -1604,6 +1606,7 @@ static void ocfs2_bg_discontig_fix_result(struct ocfs2_alloc_context *ac,
                                          struct ocfs2_suballoc_result *res)
 {
        int i;
+       u64 bg_blkno = res->sr_bg_blkno;  /* Save off */
        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;
@@ -1614,14 +1617,17 @@ static void ocfs2_bg_discontig_fix_result(struct ocfs2_alloc_context *ac,
        }
 
        res->sr_blkno = res->sr_bg_blkno + res->sr_bit_offset;
+       res->sr_bg_blkno = 0;  /* Clear it for contig block groups */
        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_fix_by_rec(res, rec, cl))
+               if (ocfs2_bg_discontig_fix_by_rec(res, rec, cl)) {
+                       res->sr_bg_blkno = bg_blkno;  /* Restore */
                        break;
+               }
        }
 }
 
@@ -1926,6 +1932,7 @@ bail:
 int ocfs2_claim_metadata(handle_t *handle,
                         struct ocfs2_alloc_context *ac,
                         u32 bits_wanted,
+                        u64 *suballoc_loc,
                         u16 *suballoc_bit_start,
                         unsigned int *num_bits,
                         u64 *blkno_start)
@@ -1948,6 +1955,7 @@ int ocfs2_claim_metadata(handle_t *handle,
        }
        atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
 
+       *suballoc_loc = res.sr_bg_blkno;
        *suballoc_bit_start = res.sr_bit_offset;
        *blkno_start = res.sr_blkno;
        ac->ac_bits_given += res.sr_bits;
@@ -1993,11 +2001,12 @@ int ocfs2_claim_new_inode(handle_t *handle,
                          struct inode *dir,
                          struct buffer_head *parent_fe_bh,
                          struct ocfs2_alloc_context *ac,
+                         u64 *suballoc_loc,
                          u16 *suballoc_bit,
                          u64 *fe_blkno)
 {
        int status;
-       struct ocfs2_suballoc_result res = { .sr_blkno = 0, };
+       struct ocfs2_suballoc_result res;
 
        mlog_entry_void();
 
@@ -2021,6 +2030,7 @@ int ocfs2_claim_new_inode(handle_t *handle,
 
        BUG_ON(res.sr_bits != 1);
 
+       *suballoc_loc = res.sr_bg_blkno;
        *suballoc_bit = res.sr_bit_offset;
        *fe_blkno = res.sr_blkno;
        ac->ac_bits_given++;
index 49b0b22d30cfbeaedd5136b7132de93000d74c22..a017dd3ee7d9ce2d6c0429d090b57ac077ed585a 100644 (file)
@@ -86,6 +86,7 @@ int ocfs2_reserve_clusters(struct ocfs2_super *osb,
 int ocfs2_claim_metadata(handle_t *handle,
                         struct ocfs2_alloc_context *ac,
                         u32 bits_wanted,
+                        u64 *suballoc_loc,
                         u16 *suballoc_bit_start,
                         u32 *num_bits,
                         u64 *blkno_start);
@@ -93,6 +94,7 @@ int ocfs2_claim_new_inode(handle_t *handle,
                          struct inode *dir,
                          struct buffer_head *parent_fe_bh,
                          struct ocfs2_alloc_context *ac,
+                         u64 *suballoc_loc,
                          u16 *suballoc_bit,
                          u64 *fe_blkno);
 int ocfs2_claim_clusters(handle_t *handle,
index 2f6fd48c0ba4d54e56af2de1d234498f18753710..805167e226c113788eb00f2abcebb8cd19330ff3 100644 (file)
@@ -2829,7 +2829,7 @@ static int ocfs2_create_xattr_block(struct inode *inode,
        int ret;
        u16 suballoc_bit_start;
        u32 num_got;
-       u64 first_blkno;
+       u64 suballoc_loc, first_blkno;
        struct ocfs2_dinode *di =  (struct ocfs2_dinode *)inode_bh->b_data;
        struct buffer_head *new_bh = NULL;
        struct ocfs2_xattr_block *xblk;
@@ -2842,8 +2842,8 @@ static int ocfs2_create_xattr_block(struct inode *inode,
        }
 
        ret = ocfs2_claim_metadata(ctxt->handle, ctxt->meta_ac, 1,
-                                  &suballoc_bit_start, &num_got,
-                                  &first_blkno);
+                                  &suballoc_loc, &suballoc_bit_start,
+                                  &num_got, &first_blkno);
        if (ret < 0) {
                mlog_errno(ret);
                goto end;
@@ -2865,6 +2865,7 @@ static int ocfs2_create_xattr_block(struct inode *inode,
        memset(xblk, 0, inode->i_sb->s_blocksize);
        strcpy((void *)xblk, OCFS2_XATTR_BLOCK_SIGNATURE);
        xblk->xb_suballoc_slot = cpu_to_le16(ctxt->meta_ac->ac_alloc_slot);
+       xblk->xb_suballoc_loc = cpu_to_le64(suballoc_loc);
        xblk->xb_suballoc_bit = cpu_to_le16(suballoc_bit_start);
        xblk->xb_fs_generation =
                cpu_to_le32(OCFS2_SB(inode->i_sb)->fs_generation);