]>
Commit | Line | Data |
---|---|---|
2cb7cef9 BS |
1 | From: Joel Becker <joel.becker@oracle.com> |
2 | Subject: ocfs2: Make ocfs2_extent_tree get/put instead of alloc. | |
3 | Patch-mainline: 2.6.28? | |
4 | References: FATE302067 | |
5 | ||
6 | Rather than allocating a struct ocfs2_extent_tree, just put it on the | |
7 | stack. Fill it with ocfs2_get_extent_tree() and drop it with | |
8 | ocfs2_put_extent_tree(). Now the callers don't have to ENOMEM, yet | |
9 | still safely ref the root_bh. | |
10 | ||
11 | Signed-off-by: Joel Becker <joel.becker@oracle.com> | |
12 | Acked-by: Mark Fasheh <mark.fasheh@suse.com> | |
13 | --- | |
14 | fs/ocfs2/alloc.c | 117 ++++++++++++++++------------------------------------- | |
15 | 1 files changed, 36 insertions(+), 81 deletions(-) | |
16 | ||
17 | diff --git a/fs/ocfs2/alloc.c b/fs/ocfs2/alloc.c | |
18 | index ab16b89..0abf11e 100644 | |
19 | --- a/fs/ocfs2/alloc.c | |
20 | +++ b/fs/ocfs2/alloc.c | |
21 | @@ -223,22 +223,17 @@ static struct ocfs2_extent_tree_operations ocfs2_xattr_tree_et_ops = { | |
22 | .eo_sanity_check = ocfs2_xattr_tree_sanity_check, | |
23 | }; | |
24 | ||
25 | -static struct ocfs2_extent_tree* | |
26 | - ocfs2_new_extent_tree(struct inode *inode, | |
27 | - struct buffer_head *bh, | |
28 | - enum ocfs2_extent_tree_type et_type, | |
29 | - void *private) | |
30 | +static void ocfs2_get_extent_tree(struct ocfs2_extent_tree *et, | |
31 | + struct inode *inode, | |
32 | + struct buffer_head *bh, | |
33 | + enum ocfs2_extent_tree_type et_type, | |
34 | + void *private) | |
35 | { | |
36 | - struct ocfs2_extent_tree *et; | |
37 | - | |
38 | - et = kzalloc(sizeof(*et), GFP_NOFS); | |
39 | - if (!et) | |
40 | - return NULL; | |
41 | - | |
42 | et->et_type = et_type; | |
43 | get_bh(bh); | |
44 | et->et_root_bh = bh; | |
45 | et->et_private = private; | |
46 | + et->et_max_leaf_clusters = 0; | |
47 | ||
48 | if (et_type == OCFS2_DINODE_EXTENT) { | |
49 | et->et_root_el = | |
50 | @@ -257,16 +252,11 @@ static struct ocfs2_extent_tree* | |
51 | et->et_max_leaf_clusters = ocfs2_clusters_for_bytes(inode->i_sb, | |
52 | OCFS2_MAX_XATTR_TREE_LEAF_SIZE); | |
53 | } | |
54 | - | |
55 | - return et; | |
56 | } | |
57 | ||
58 | -static void ocfs2_free_extent_tree(struct ocfs2_extent_tree *et) | |
59 | +static void ocfs2_put_extent_tree(struct ocfs2_extent_tree *et) | |
60 | { | |
61 | - if (et) { | |
62 | - brelse(et->et_root_bh); | |
63 | - kfree(et); | |
64 | - } | |
65 | + brelse(et->et_root_bh); | |
66 | } | |
67 | ||
68 | static inline void ocfs2_et_set_last_eb_blk(struct ocfs2_extent_tree *et, | |
69 | @@ -4439,22 +4429,15 @@ int ocfs2_dinode_insert_extent(struct ocfs2_super *osb, | |
70 | struct ocfs2_alloc_context *meta_ac) | |
71 | { | |
72 | int status; | |
73 | - struct ocfs2_extent_tree *et = NULL; | |
74 | - | |
75 | - et = ocfs2_new_extent_tree(inode, root_bh, OCFS2_DINODE_EXTENT, NULL); | |
76 | - if (!et) { | |
77 | - status = -ENOMEM; | |
78 | - mlog_errno(status); | |
79 | - goto bail; | |
80 | - } | |
81 | + struct ocfs2_extent_tree et; | |
82 | ||
83 | + ocfs2_get_extent_tree(&et, inode, root_bh, OCFS2_DINODE_EXTENT, | |
84 | + NULL); | |
85 | status = ocfs2_insert_extent(osb, handle, inode, root_bh, | |
86 | cpos, start_blk, new_clusters, | |
87 | - flags, meta_ac, et); | |
88 | + flags, meta_ac, &et); | |
89 | + ocfs2_put_extent_tree(&et); | |
90 | ||
91 | - if (et) | |
92 | - ocfs2_free_extent_tree(et); | |
93 | -bail: | |
94 | return status; | |
95 | } | |
96 | ||
97 | @@ -4470,23 +4453,15 @@ int ocfs2_xattr_value_insert_extent(struct ocfs2_super *osb, | |
98 | void *private) | |
99 | { | |
100 | int status; | |
101 | - struct ocfs2_extent_tree *et = NULL; | |
102 | - | |
103 | - et = ocfs2_new_extent_tree(inode, root_bh, | |
104 | - OCFS2_XATTR_VALUE_EXTENT, private); | |
105 | - if (!et) { | |
106 | - status = -ENOMEM; | |
107 | - mlog_errno(status); | |
108 | - goto bail; | |
109 | - } | |
110 | + struct ocfs2_extent_tree et; | |
111 | ||
112 | + ocfs2_get_extent_tree(&et, inode, root_bh, | |
113 | + OCFS2_XATTR_VALUE_EXTENT, private); | |
114 | status = ocfs2_insert_extent(osb, handle, inode, root_bh, | |
115 | cpos, start_blk, new_clusters, | |
116 | - flags, meta_ac, et); | |
117 | + flags, meta_ac, &et); | |
118 | + ocfs2_put_extent_tree(&et); | |
119 | ||
120 | - if (et) | |
121 | - ocfs2_free_extent_tree(et); | |
122 | -bail: | |
123 | return status; | |
124 | } | |
125 | ||
126 | @@ -4501,23 +4476,15 @@ int ocfs2_xattr_tree_insert_extent(struct ocfs2_super *osb, | |
127 | struct ocfs2_alloc_context *meta_ac) | |
128 | { | |
129 | int status; | |
130 | - struct ocfs2_extent_tree *et = NULL; | |
131 | - | |
132 | - et = ocfs2_new_extent_tree(inode, root_bh, OCFS2_XATTR_TREE_EXTENT, | |
133 | - NULL); | |
134 | - if (!et) { | |
135 | - status = -ENOMEM; | |
136 | - mlog_errno(status); | |
137 | - goto bail; | |
138 | - } | |
139 | + struct ocfs2_extent_tree et; | |
140 | ||
141 | + ocfs2_get_extent_tree(&et, inode, root_bh, OCFS2_XATTR_TREE_EXTENT, | |
142 | + NULL); | |
143 | status = ocfs2_insert_extent(osb, handle, inode, root_bh, | |
144 | cpos, start_blk, new_clusters, | |
145 | - flags, meta_ac, et); | |
146 | + flags, meta_ac, &et); | |
147 | + ocfs2_put_extent_tree(&et); | |
148 | ||
149 | - if (et) | |
150 | - ocfs2_free_extent_tree(et); | |
151 | -bail: | |
152 | return status; | |
153 | } | |
154 | ||
155 | @@ -4906,11 +4873,13 @@ int ocfs2_mark_extent_written(struct inode *inode, struct buffer_head *root_bh, | |
156 | struct ocfs2_extent_rec split_rec; | |
157 | struct ocfs2_path *left_path = NULL; | |
158 | struct ocfs2_extent_list *el; | |
159 | - struct ocfs2_extent_tree *et = NULL; | |
160 | + struct ocfs2_extent_tree et; | |
161 | ||
162 | mlog(0, "Inode %lu cpos %u, len %u, phys %u (%llu)\n", | |
163 | inode->i_ino, cpos, len, phys, (unsigned long long)start_blkno); | |
164 | ||
165 | + ocfs2_get_extent_tree(&et, inode, root_bh, et_type, private); | |
166 | + | |
167 | if (!ocfs2_writes_unwritten_extents(OCFS2_SB(inode->i_sb))) { | |
168 | ocfs2_error(inode->i_sb, "Inode %llu has unwritten extents " | |
169 | "that are being written to, but the feature bit " | |
170 | @@ -4920,13 +4889,6 @@ int ocfs2_mark_extent_written(struct inode *inode, struct buffer_head *root_bh, | |
171 | goto out; | |
172 | } | |
173 | ||
174 | - et = ocfs2_new_extent_tree(inode, root_bh, et_type, private); | |
175 | - if (!et) { | |
176 | - ret = -ENOMEM; | |
177 | - mlog_errno(ret); | |
178 | - goto out; | |
179 | - } | |
180 | - | |
181 | /* | |
182 | * XXX: This should be fixed up so that we just re-insert the | |
183 | * next extent records. | |
184 | @@ -4934,7 +4896,7 @@ int ocfs2_mark_extent_written(struct inode *inode, struct buffer_head *root_bh, | |
185 | if (et_type == OCFS2_DINODE_EXTENT) | |
186 | ocfs2_extent_map_trunc(inode, 0); | |
187 | ||
188 | - left_path = ocfs2_new_path(et->et_root_bh, et->et_root_el); | |
189 | + left_path = ocfs2_new_path(et.et_root_bh, et.et_root_el); | |
190 | if (!left_path) { | |
191 | ret = -ENOMEM; | |
192 | mlog_errno(ret); | |
193 | @@ -4965,7 +4927,7 @@ int ocfs2_mark_extent_written(struct inode *inode, struct buffer_head *root_bh, | |
194 | split_rec.e_flags = path_leaf_el(left_path)->l_recs[index].e_flags; | |
195 | split_rec.e_flags &= ~OCFS2_EXT_UNWRITTEN; | |
196 | ||
197 | - ret = __ocfs2_mark_extent_written(inode, et, handle, left_path, | |
198 | + ret = __ocfs2_mark_extent_written(inode, &et, handle, left_path, | |
199 | index, &split_rec, meta_ac, | |
200 | dealloc); | |
201 | if (ret) | |
202 | @@ -4973,8 +4935,7 @@ int ocfs2_mark_extent_written(struct inode *inode, struct buffer_head *root_bh, | |
203 | ||
204 | out: | |
205 | ocfs2_free_path(left_path); | |
206 | - if (et) | |
207 | - ocfs2_free_extent_tree(et); | |
208 | + ocfs2_put_extent_tree(&et); | |
209 | return ret; | |
210 | } | |
211 | ||
212 | @@ -5216,18 +5177,13 @@ int ocfs2_remove_extent(struct inode *inode, struct buffer_head *root_bh, | |
213 | struct ocfs2_extent_rec *rec; | |
214 | struct ocfs2_extent_list *el; | |
215 | struct ocfs2_path *path = NULL; | |
216 | - struct ocfs2_extent_tree *et = NULL; | |
217 | + struct ocfs2_extent_tree et; | |
218 | ||
219 | - et = ocfs2_new_extent_tree(inode, root_bh, et_type, private); | |
220 | - if (!et) { | |
221 | - ret = -ENOMEM; | |
222 | - mlog_errno(ret); | |
223 | - goto out; | |
224 | - } | |
225 | + ocfs2_get_extent_tree(&et, inode, root_bh, et_type, private); | |
226 | ||
227 | ocfs2_extent_map_trunc(inode, 0); | |
228 | ||
229 | - path = ocfs2_new_path(et->et_root_bh, et->et_root_el); | |
230 | + path = ocfs2_new_path(et.et_root_bh, et.et_root_el); | |
231 | if (!path) { | |
232 | ret = -ENOMEM; | |
233 | mlog_errno(ret); | |
234 | @@ -5280,13 +5236,13 @@ int ocfs2_remove_extent(struct inode *inode, struct buffer_head *root_bh, | |
235 | ||
236 | if (le32_to_cpu(rec->e_cpos) == cpos || rec_range == trunc_range) { | |
237 | ret = ocfs2_truncate_rec(inode, handle, path, index, dealloc, | |
238 | - cpos, len, et); | |
239 | + cpos, len, &et); | |
240 | if (ret) { | |
241 | mlog_errno(ret); | |
242 | goto out; | |
243 | } | |
244 | } else { | |
245 | - ret = ocfs2_split_tree(inode, et, handle, path, index, | |
246 | + ret = ocfs2_split_tree(inode, &et, handle, path, index, | |
247 | trunc_range, meta_ac); | |
248 | if (ret) { | |
249 | mlog_errno(ret); | |
250 | @@ -5335,7 +5291,7 @@ int ocfs2_remove_extent(struct inode *inode, struct buffer_head *root_bh, | |
251 | } | |
252 | ||
253 | ret = ocfs2_truncate_rec(inode, handle, path, index, dealloc, | |
254 | - cpos, len, et); | |
255 | + cpos, len, &et); | |
256 | if (ret) { | |
257 | mlog_errno(ret); | |
258 | goto out; | |
259 | @@ -5344,8 +5300,7 @@ int ocfs2_remove_extent(struct inode *inode, struct buffer_head *root_bh, | |
260 | ||
261 | out: | |
262 | ocfs2_free_path(path); | |
263 | - if (et) | |
264 | - ocfs2_free_extent_tree(et); | |
265 | + ocfs2_put_extent_tree(&et); | |
266 | return ret; | |
267 | } | |
268 | ||
269 | -- | |
270 | 1.5.4.5 | |
271 |