1 From: Tao Ma <tao.ma@oracle.com>
2 Subject: [PATCH 02/16] ocfs2: Use ocfs2_extent_list instead of ocfs2_dinode.
3 Patch-mainline: 2.6.28?
6 ocfs2_extend_meta_needed(), ocfs2_calc_extend_credits() and
7 ocfs2_reserve_new_metadata() are all useful for extent tree operations. But
8 they are all limited to an inode btree because they use a struct
9 ocfs2_dinode parameter. Change their parameter to struct ocfs2_extent_list
10 (the part of an ocfs2_dinode they actually use) so that the xattr btree code
11 can use these functions.
13 Signed-off-by: Tao Ma <tao.ma@oracle.com>
14 Signed-off-by: Mark Fasheh <mfasheh@suse.com>
16 fs/ocfs2/alloc.c | 3 ++-
17 fs/ocfs2/alloc.h | 12 +++++++++---
18 fs/ocfs2/aops.c | 3 ++-
19 fs/ocfs2/dir.c | 5 +++--
20 fs/ocfs2/file.c | 9 +++++----
21 fs/ocfs2/journal.h | 17 +++++++++++------
22 fs/ocfs2/suballoc.c | 4 ++--
23 fs/ocfs2/suballoc.h | 7 ++++++-
24 8 files changed, 40 insertions(+), 20 deletions(-)
26 --- a/fs/ocfs2/alloc.c
27 +++ b/fs/ocfs2/alloc.c
28 @@ -4536,7 +4536,8 @@ static int ocfs2_split_tree(struct inode
30 rightmost_el = path_leaf_el(path);
32 - credits += path->p_tree_depth + ocfs2_extend_meta_needed(di);
33 + credits += path->p_tree_depth +
34 + ocfs2_extend_meta_needed(&di->id2.i_list);
35 ret = ocfs2_extend_trans(handle, credits);
38 --- a/fs/ocfs2/alloc.h
39 +++ b/fs/ocfs2/alloc.h
40 @@ -48,8 +48,14 @@ int ocfs2_remove_extent(struct inode *in
41 int ocfs2_num_free_extents(struct ocfs2_super *osb,
43 struct buffer_head *bh);
44 -/* how many new metadata chunks would an allocation need at maximum? */
45 -static inline int ocfs2_extend_meta_needed(struct ocfs2_dinode *fe)
47 + * how many new metadata chunks would an allocation need at maximum?
49 + * Please note that the caller must make sure that root_el is the root
50 + * of extent tree. So for an inode, it should be &fe->id2.i_list. Otherwise
51 + * the result may be wrong.
53 +static inline int ocfs2_extend_meta_needed(struct ocfs2_extent_list *root_el)
56 * Rather than do all the work of determining how much we need
57 @@ -59,7 +65,7 @@ static inline int ocfs2_extend_meta_need
58 * new tree_depth==0 extent_block, and one block at the new
61 - return le16_to_cpu(fe->id2.i_list.l_tree_depth) + 2;
62 + return le16_to_cpu(root_el->l_tree_depth) + 2;
65 void ocfs2_dinode_new_extent_list(struct inode *inode, struct ocfs2_dinode *di);
68 @@ -1720,7 +1720,8 @@ int ocfs2_write_begin_nolock(struct addr
72 - credits = ocfs2_calc_extend_credits(inode->i_sb, di,
73 + credits = ocfs2_calc_extend_credits(inode->i_sb,
80 @@ -1430,6 +1430,7 @@ static int ocfs2_extend_dir(struct ocfs2
81 int credits, num_free_extents, drop_alloc_sem = 0;
83 struct ocfs2_dinode *fe = (struct ocfs2_dinode *) parent_fe_bh->b_data;
84 + struct ocfs2_extent_list *el = &fe->id2.i_list;
85 struct ocfs2_alloc_context *data_ac = NULL;
86 struct ocfs2_alloc_context *meta_ac = NULL;
87 handle_t *handle = NULL;
88 @@ -1488,7 +1489,7 @@ static int ocfs2_extend_dir(struct ocfs2
91 if (!num_free_extents) {
92 - status = ocfs2_reserve_new_metadata(osb, fe, &meta_ac);
93 + status = ocfs2_reserve_new_metadata(osb, el, &meta_ac);
95 if (status != -ENOSPC)
97 @@ -1503,7 +1504,7 @@ static int ocfs2_extend_dir(struct ocfs2
101 - credits = ocfs2_calc_extend_credits(sb, fe, 1);
102 + credits = ocfs2_calc_extend_credits(sb, el, 1);
104 spin_unlock(&OCFS2_I(dir)->ip_lock);
105 credits = OCFS2_SIMPLE_DIR_EXTEND_CREDITS;
106 --- a/fs/ocfs2/file.c
107 +++ b/fs/ocfs2/file.c
108 @@ -540,7 +540,7 @@ int ocfs2_do_extend_allocation(struct oc
110 } else if ((!free_extents)
111 && (ocfs2_alloc_context_bits_left(meta_ac)
112 - < ocfs2_extend_meta_needed(fe))) {
113 + < ocfs2_extend_meta_needed(&fe->id2.i_list))) {
114 mlog(0, "filesystem is really fragmented...\n");
116 reason = RESTART_META;
117 @@ -652,7 +652,7 @@ int ocfs2_lock_allocators(struct inode *
119 if (!num_free_extents ||
120 (ocfs2_sparse_alloc(osb) && num_free_extents < max_recs_needed)) {
121 - ret = ocfs2_reserve_new_metadata(osb, di, meta_ac);
122 + ret = ocfs2_reserve_new_metadata(osb, &di->id2.i_list, meta_ac);
126 @@ -732,7 +732,8 @@ restart_all:
130 - credits = ocfs2_calc_extend_credits(osb->sb, fe, clusters_to_add);
131 + credits = ocfs2_calc_extend_credits(osb->sb, &fe->id2.i_list,
133 handle = ocfs2_start_trans(osb, credits);
134 if (IS_ERR(handle)) {
135 status = PTR_ERR(handle);
136 @@ -790,7 +791,7 @@ restarted_transaction:
137 mlog(0, "restarting transaction.\n");
138 /* TODO: This can be more intelligent. */
139 credits = ocfs2_calc_extend_credits(osb->sb,
143 status = ocfs2_extend_trans(handle, credits);
145 --- a/fs/ocfs2/journal.h
146 +++ b/fs/ocfs2/journal.h
147 @@ -340,11 +340,16 @@ int ocfs2_journal_dirty
148 #define OCFS2_RENAME_CREDITS (3 * OCFS2_INODE_UPDATE_CREDITS + 3 \
149 + OCFS2_UNLINK_CREDITS)
152 + * Please note that the caller must make sure that root_el is the root
153 + * of extent tree. So for an inode, it should be &fe->id2.i_list. Otherwise
154 + * the result may be wrong.
156 static inline int ocfs2_calc_extend_credits(struct super_block *sb,
157 - struct ocfs2_dinode *fe,
158 + struct ocfs2_extent_list *root_el,
161 - int bitmap_blocks, sysfile_bitmap_blocks, dinode_blocks;
162 + int bitmap_blocks, sysfile_bitmap_blocks, extent_blocks;
164 /* bitmap dinode, group desc. + relinked group. */
165 bitmap_blocks = OCFS2_SUBALLOC_ALLOC;
166 @@ -355,16 +360,16 @@ static inline int ocfs2_calc_extend_cred
167 * however many metadata chunks needed * a remaining suballoc
169 sysfile_bitmap_blocks = 1 +
170 - (OCFS2_SUBALLOC_ALLOC - 1) * ocfs2_extend_meta_needed(fe);
171 + (OCFS2_SUBALLOC_ALLOC - 1) * ocfs2_extend_meta_needed(root_el);
173 /* this does not include *new* metadata blocks, which are
174 - * accounted for in sysfile_bitmap_blocks. fe +
175 + * accounted for in sysfile_bitmap_blocks. root_el +
176 * prev. last_eb_blk + blocks along edge of tree.
177 * calc_symlink_credits passes because we just need 1
178 * credit for the dinode there. */
179 - dinode_blocks = 1 + 1 + le16_to_cpu(fe->id2.i_list.l_tree_depth);
180 + extent_blocks = 1 + 1 + le16_to_cpu(root_el->l_tree_depth);
182 - return bitmap_blocks + sysfile_bitmap_blocks + dinode_blocks;
183 + return bitmap_blocks + sysfile_bitmap_blocks + extent_blocks;
186 static inline int ocfs2_calc_symlink_credits(struct super_block *sb)
187 --- a/fs/ocfs2/suballoc.c
188 +++ b/fs/ocfs2/suballoc.c
189 @@ -494,7 +494,7 @@ bail:
192 int ocfs2_reserve_new_metadata(struct ocfs2_super *osb,
193 - struct ocfs2_dinode *fe,
194 + struct ocfs2_extent_list *root_el,
195 struct ocfs2_alloc_context **ac)
198 @@ -507,7 +507,7 @@ int ocfs2_reserve_new_metadata(struct oc
202 - (*ac)->ac_bits_wanted = ocfs2_extend_meta_needed(fe);
203 + (*ac)->ac_bits_wanted = ocfs2_extend_meta_needed(root_el);
204 (*ac)->ac_which = OCFS2_AC_USE_META;
205 slot = osb->slot_num;
206 (*ac)->ac_group_search = ocfs2_block_group_search;
207 --- a/fs/ocfs2/suballoc.h
208 +++ b/fs/ocfs2/suballoc.h
209 @@ -59,8 +59,13 @@ static inline int ocfs2_alloc_context_bi
210 return ac->ac_bits_wanted - ac->ac_bits_given;
214 + * Please note that the caller must make sure that root_el is the root
215 + * of extent tree. So for an inode, it should be &fe->id2.i_list. Otherwise
216 + * the result may be wrong.
218 int ocfs2_reserve_new_metadata(struct ocfs2_super *osb,
219 - struct ocfs2_dinode *fe,
220 + struct ocfs2_extent_list *root_el,
221 struct ocfs2_alloc_context **ac);
222 int ocfs2_reserve_new_inode(struct ocfs2_super *osb,
223 struct ocfs2_alloc_context **ac);