1 From: Joel Becker <joel.becker@oracle.com>
2 Subject: ocfs2: Make 'private' into 'object' on ocfs2_extent_tree.
3 Patch-mainline: 2.6.28?
6 The 'private' pointer was a way to store off xattr values, which don't
7 live at a set place in the bh. But the concept of "the object
8 containing the extent tree" is much more generic. For an inode it's the
9 struct ocfs2_dinode, for an xattr value its the value. Let's save off
10 the 'object' at all times. If NULL is passed to
11 ocfs2_get_extent_tree(), 'object' is set to bh->b_data;
13 Signed-off-by: Joel Becker <joel.becker@oracle.com>
14 Acked-by: Mark Fasheh <mark.fasheh@suse.com>
16 fs/ocfs2/alloc.c | 62 +++++++++++++++++++++++++----------------------------
17 1 files changed, 29 insertions(+), 33 deletions(-)
19 diff --git a/fs/ocfs2/alloc.c b/fs/ocfs2/alloc.c
20 index 0abf11e..93f44f4 100644
21 --- a/fs/ocfs2/alloc.c
22 +++ b/fs/ocfs2/alloc.c
23 @@ -79,15 +79,14 @@ struct ocfs2_extent_tree {
24 struct ocfs2_extent_tree_operations *et_ops;
25 struct buffer_head *et_root_bh;
26 struct ocfs2_extent_list *et_root_el;
29 unsigned int et_max_leaf_clusters;
32 static void ocfs2_dinode_set_last_eb_blk(struct ocfs2_extent_tree *et,
35 - struct ocfs2_dinode *di =
36 - (struct ocfs2_dinode *)et->et_root_bh->b_data;
37 + struct ocfs2_dinode *di = et->et_object;
39 BUG_ON(et->et_type != OCFS2_DINODE_EXTENT);
40 di->i_last_eb_blk = cpu_to_le64(blkno);
41 @@ -95,8 +94,7 @@ static void ocfs2_dinode_set_last_eb_blk(struct ocfs2_extent_tree *et,
43 static u64 ocfs2_dinode_get_last_eb_blk(struct ocfs2_extent_tree *et)
45 - struct ocfs2_dinode *di =
46 - (struct ocfs2_dinode *)et->et_root_bh->b_data;
47 + struct ocfs2_dinode *di = et->et_object;
49 BUG_ON(et->et_type != OCFS2_DINODE_EXTENT);
50 return le64_to_cpu(di->i_last_eb_blk);
51 @@ -106,8 +104,7 @@ static void ocfs2_dinode_update_clusters(struct inode *inode,
52 struct ocfs2_extent_tree *et,
55 - struct ocfs2_dinode *di =
56 - (struct ocfs2_dinode *)et->et_root_bh->b_data;
57 + struct ocfs2_dinode *di = et->et_object;
59 le32_add_cpu(&di->i_clusters, clusters);
60 spin_lock(&OCFS2_I(inode)->ip_lock);
61 @@ -123,7 +120,7 @@ static int ocfs2_dinode_sanity_check(struct inode *inode,
63 BUG_ON(et->et_type != OCFS2_DINODE_EXTENT);
65 - di = (struct ocfs2_dinode *)et->et_root_bh->b_data;
67 if (!OCFS2_IS_VALID_DINODE(di)) {
69 ocfs2_error(inode->i_sb,
70 @@ -145,7 +142,7 @@ static void ocfs2_xattr_value_set_last_eb_blk(struct ocfs2_extent_tree *et,
73 struct ocfs2_xattr_value_root *xv =
74 - (struct ocfs2_xattr_value_root *)et->et_private;
75 + (struct ocfs2_xattr_value_root *)et->et_object;
77 xv->xr_last_eb_blk = cpu_to_le64(blkno);
79 @@ -153,7 +150,7 @@ static void ocfs2_xattr_value_set_last_eb_blk(struct ocfs2_extent_tree *et,
80 static u64 ocfs2_xattr_value_get_last_eb_blk(struct ocfs2_extent_tree *et)
82 struct ocfs2_xattr_value_root *xv =
83 - (struct ocfs2_xattr_value_root *) et->et_private;
84 + (struct ocfs2_xattr_value_root *) et->et_object;
86 return le64_to_cpu(xv->xr_last_eb_blk);
88 @@ -163,7 +160,7 @@ static void ocfs2_xattr_value_update_clusters(struct inode *inode,
91 struct ocfs2_xattr_value_root *xv =
92 - (struct ocfs2_xattr_value_root *)et->et_private;
93 + (struct ocfs2_xattr_value_root *)et->et_object;
95 le32_add_cpu(&xv->xr_clusters, clusters);
97 @@ -184,8 +181,7 @@ static struct ocfs2_extent_tree_operations ocfs2_xattr_et_ops = {
98 static void ocfs2_xattr_tree_set_last_eb_blk(struct ocfs2_extent_tree *et,
101 - struct ocfs2_xattr_block *xb =
102 - (struct ocfs2_xattr_block *) et->et_root_bh->b_data;
103 + struct ocfs2_xattr_block *xb = et->et_object;
104 struct ocfs2_xattr_tree_root *xt = &xb->xb_attrs.xb_root;
106 xt->xt_last_eb_blk = cpu_to_le64(blkno);
107 @@ -193,8 +189,7 @@ static void ocfs2_xattr_tree_set_last_eb_blk(struct ocfs2_extent_tree *et,
109 static u64 ocfs2_xattr_tree_get_last_eb_blk(struct ocfs2_extent_tree *et)
111 - struct ocfs2_xattr_block *xb =
112 - (struct ocfs2_xattr_block *) et->et_root_bh->b_data;
113 + struct ocfs2_xattr_block *xb = et->et_object;
114 struct ocfs2_xattr_tree_root *xt = &xb->xb_attrs.xb_root;
116 return le64_to_cpu(xt->xt_last_eb_blk);
117 @@ -204,8 +199,7 @@ static void ocfs2_xattr_tree_update_clusters(struct inode *inode,
118 struct ocfs2_extent_tree *et,
121 - struct ocfs2_xattr_block *xb =
122 - (struct ocfs2_xattr_block *)et->et_root_bh->b_data;
123 + struct ocfs2_xattr_block *xb = et->et_object;
125 le32_add_cpu(&xb->xb_attrs.xb_root.xt_clusters, clusters);
127 @@ -227,26 +221,28 @@ static void ocfs2_get_extent_tree(struct ocfs2_extent_tree *et,
129 struct buffer_head *bh,
130 enum ocfs2_extent_tree_type et_type,
134 et->et_type = et_type;
137 - et->et_private = private;
138 et->et_max_leaf_clusters = 0;
140 + obj = (void *)bh->b_data;
141 + et->et_object = obj;
143 if (et_type == OCFS2_DINODE_EXTENT) {
145 - &((struct ocfs2_dinode *)bh->b_data)->id2.i_list;
146 + &((struct ocfs2_dinode *)obj)->id2.i_list;
147 et->et_ops = &ocfs2_dinode_et_ops;
148 } else if (et_type == OCFS2_XATTR_VALUE_EXTENT) {
149 struct ocfs2_xattr_value_root *xv =
150 - (struct ocfs2_xattr_value_root *) private;
151 + (struct ocfs2_xattr_value_root *)obj;
152 et->et_root_el = &xv->xr_list;
153 et->et_ops = &ocfs2_xattr_et_ops;
154 } else if (et_type == OCFS2_XATTR_TREE_EXTENT) {
155 struct ocfs2_xattr_block *xb =
156 - (struct ocfs2_xattr_block *)bh->b_data;
157 + (struct ocfs2_xattr_block *)obj;
158 et->et_root_el = &xb->xb_attrs.xb_root.xt_list;
159 et->et_ops = &ocfs2_xattr_tree_et_ops;
160 et->et_max_leaf_clusters = ocfs2_clusters_for_bytes(inode->i_sb,
161 @@ -593,7 +589,7 @@ int ocfs2_num_free_extents(struct ocfs2_super *osb,
163 struct buffer_head *root_bh,
164 enum ocfs2_extent_tree_type type,
169 struct ocfs2_extent_list *el = NULL;
170 @@ -617,7 +613,7 @@ int ocfs2_num_free_extents(struct ocfs2_super *osb,
171 el = &fe->id2.i_list;
172 } else if (type == OCFS2_XATTR_VALUE_EXTENT) {
173 struct ocfs2_xattr_value_root *xv =
174 - (struct ocfs2_xattr_value_root *) private;
175 + (struct ocfs2_xattr_value_root *) obj;
177 last_eb_blk = le64_to_cpu(xv->xr_last_eb_blk);
179 @@ -4450,13 +4446,13 @@ int ocfs2_xattr_value_insert_extent(struct ocfs2_super *osb,
182 struct ocfs2_alloc_context *meta_ac,
187 struct ocfs2_extent_tree et;
189 ocfs2_get_extent_tree(&et, inode, root_bh,
190 - OCFS2_XATTR_VALUE_EXTENT, private);
191 + OCFS2_XATTR_VALUE_EXTENT, obj);
192 status = ocfs2_insert_extent(osb, handle, inode, root_bh,
193 cpos, start_blk, new_clusters,
194 flags, meta_ac, &et);
195 @@ -4507,7 +4503,7 @@ int ocfs2_add_clusters_in_btree(struct ocfs2_super *osb,
196 struct ocfs2_alloc_context *meta_ac,
197 enum ocfs2_alloc_restarted *reason_ret,
198 enum ocfs2_extent_tree_type type,
204 @@ -4522,7 +4518,7 @@ int ocfs2_add_clusters_in_btree(struct ocfs2_super *osb,
205 flags = OCFS2_EXT_UNWRITTEN;
207 free_extents = ocfs2_num_free_extents(osb, inode, root_bh, type,
210 if (free_extents < 0) {
211 status = free_extents;
213 @@ -4584,7 +4580,7 @@ int ocfs2_add_clusters_in_btree(struct ocfs2_super *osb,
216 block, num_bits, flags,
222 @@ -4866,7 +4862,7 @@ int ocfs2_mark_extent_written(struct inode *inode, struct buffer_head *root_bh,
223 struct ocfs2_alloc_context *meta_ac,
224 struct ocfs2_cached_dealloc_ctxt *dealloc,
225 enum ocfs2_extent_tree_type et_type,
230 u64 start_blkno = ocfs2_clusters_to_blocks(inode->i_sb, phys);
231 @@ -4878,7 +4874,7 @@ int ocfs2_mark_extent_written(struct inode *inode, struct buffer_head *root_bh,
232 mlog(0, "Inode %lu cpos %u, len %u, phys %u (%llu)\n",
233 inode->i_ino, cpos, len, phys, (unsigned long long)start_blkno);
235 - ocfs2_get_extent_tree(&et, inode, root_bh, et_type, private);
236 + ocfs2_get_extent_tree(&et, inode, root_bh, et_type, obj);
238 if (!ocfs2_writes_unwritten_extents(OCFS2_SB(inode->i_sb))) {
239 ocfs2_error(inode->i_sb, "Inode %llu has unwritten extents "
240 @@ -5170,7 +5166,7 @@ int ocfs2_remove_extent(struct inode *inode, struct buffer_head *root_bh,
241 struct ocfs2_alloc_context *meta_ac,
242 struct ocfs2_cached_dealloc_ctxt *dealloc,
243 enum ocfs2_extent_tree_type et_type,
248 u32 rec_range, trunc_range;
249 @@ -5179,7 +5175,7 @@ int ocfs2_remove_extent(struct inode *inode, struct buffer_head *root_bh,
250 struct ocfs2_path *path = NULL;
251 struct ocfs2_extent_tree et;
253 - ocfs2_get_extent_tree(&et, inode, root_bh, et_type, private);
254 + ocfs2_get_extent_tree(&et, inode, root_bh, et_type, obj);
256 ocfs2_extent_map_trunc(inode, 0);