diff options
author | Joel Becker <joel.becker@oracle.com> | 2008-08-20 21:32:45 -0400 |
---|---|---|
committer | Mark Fasheh <mfasheh@suse.com> | 2008-10-13 19:57:05 -0400 |
commit | 1e61ee79e2a96f62c007486677319814ce621c3c (patch) | |
tree | 50e966441431ec036649dac3ebd17d1452937f26 /fs | |
parent | 1a09f556e5415a29cdddaf9a6ebf474194161cf3 (diff) |
ocfs2: Add an insertion check to ocfs2_extent_tree_operations.
A couple places check an extent_tree for a valid inode. We move that
out to add an eo_insert_check() operation. It can be called from
ocfs2_insert_extent() and elsewhere.
We also have the wrapper calls ocfs2_et_insert_check() and
ocfs2_et_sanity_check() ignore NULL ops. That way we don't have to
provide useless operations for xattr types.
Signed-off-by: Joel Becker <joel.becker@oracle.com>
Signed-off-by: Mark Fasheh <mfasheh@suse.com>
Diffstat (limited to 'fs')
-rw-r--r-- | fs/ocfs2/alloc.c | 69 |
1 files changed, 44 insertions, 25 deletions
diff --git a/fs/ocfs2/alloc.c b/fs/ocfs2/alloc.c index 7b08180a4c67..ce54730e18ff 100644 --- a/fs/ocfs2/alloc.c +++ b/fs/ocfs2/alloc.c | |||
@@ -71,6 +71,9 @@ struct ocfs2_extent_tree_operations { | |||
71 | void (*eo_update_clusters)(struct inode *inode, | 71 | void (*eo_update_clusters)(struct inode *inode, |
72 | struct ocfs2_extent_tree *et, | 72 | struct ocfs2_extent_tree *et, |
73 | u32 new_clusters); | 73 | u32 new_clusters); |
74 | int (*eo_insert_check)(struct inode *inode, | ||
75 | struct ocfs2_extent_tree *et, | ||
76 | struct ocfs2_extent_rec *rec); | ||
74 | int (*eo_sanity_check)(struct inode *inode, struct ocfs2_extent_tree *et); | 77 | int (*eo_sanity_check)(struct inode *inode, struct ocfs2_extent_tree *et); |
75 | 78 | ||
76 | /* These are internal to ocfs2_extent_tree and don't have | 79 | /* These are internal to ocfs2_extent_tree and don't have |
@@ -125,6 +128,25 @@ static void ocfs2_dinode_update_clusters(struct inode *inode, | |||
125 | spin_unlock(&OCFS2_I(inode)->ip_lock); | 128 | spin_unlock(&OCFS2_I(inode)->ip_lock); |
126 | } | 129 | } |
127 | 130 | ||
131 | static int ocfs2_dinode_insert_check(struct inode *inode, | ||
132 | struct ocfs2_extent_tree *et, | ||
133 | struct ocfs2_extent_rec *rec) | ||
134 | { | ||
135 | struct ocfs2_super *osb = OCFS2_SB(inode->i_sb); | ||
136 | |||
137 | BUG_ON(OCFS2_I(inode)->ip_dyn_features & OCFS2_INLINE_DATA_FL); | ||
138 | mlog_bug_on_msg(!ocfs2_sparse_alloc(osb) && | ||
139 | (OCFS2_I(inode)->ip_clusters != rec->e_cpos), | ||
140 | "Device %s, asking for sparse allocation: inode %llu, " | ||
141 | "cpos %u, clusters %u\n", | ||
142 | osb->dev_str, | ||
143 | (unsigned long long)OCFS2_I(inode)->ip_blkno, | ||
144 | rec->e_cpos, | ||
145 | OCFS2_I(inode)->ip_clusters); | ||
146 | |||
147 | return 0; | ||
148 | } | ||
149 | |||
128 | static int ocfs2_dinode_sanity_check(struct inode *inode, | 150 | static int ocfs2_dinode_sanity_check(struct inode *inode, |
129 | struct ocfs2_extent_tree *et) | 151 | struct ocfs2_extent_tree *et) |
130 | { | 152 | { |
@@ -148,6 +170,7 @@ static struct ocfs2_extent_tree_operations ocfs2_dinode_et_ops = { | |||
148 | .eo_set_last_eb_blk = ocfs2_dinode_set_last_eb_blk, | 170 | .eo_set_last_eb_blk = ocfs2_dinode_set_last_eb_blk, |
149 | .eo_get_last_eb_blk = ocfs2_dinode_get_last_eb_blk, | 171 | .eo_get_last_eb_blk = ocfs2_dinode_get_last_eb_blk, |
150 | .eo_update_clusters = ocfs2_dinode_update_clusters, | 172 | .eo_update_clusters = ocfs2_dinode_update_clusters, |
173 | .eo_insert_check = ocfs2_dinode_insert_check, | ||
151 | .eo_sanity_check = ocfs2_dinode_sanity_check, | 174 | .eo_sanity_check = ocfs2_dinode_sanity_check, |
152 | .eo_fill_root_el = ocfs2_dinode_fill_root_el, | 175 | .eo_fill_root_el = ocfs2_dinode_fill_root_el, |
153 | }; | 176 | }; |
@@ -186,17 +209,10 @@ static void ocfs2_xattr_value_update_clusters(struct inode *inode, | |||
186 | le32_add_cpu(&xv->xr_clusters, clusters); | 209 | le32_add_cpu(&xv->xr_clusters, clusters); |
187 | } | 210 | } |
188 | 211 | ||
189 | static int ocfs2_xattr_value_sanity_check(struct inode *inode, | ||
190 | struct ocfs2_extent_tree *et) | ||
191 | { | ||
192 | return 0; | ||
193 | } | ||
194 | |||
195 | static struct ocfs2_extent_tree_operations ocfs2_xattr_value_et_ops = { | 212 | static struct ocfs2_extent_tree_operations ocfs2_xattr_value_et_ops = { |
196 | .eo_set_last_eb_blk = ocfs2_xattr_value_set_last_eb_blk, | 213 | .eo_set_last_eb_blk = ocfs2_xattr_value_set_last_eb_blk, |
197 | .eo_get_last_eb_blk = ocfs2_xattr_value_get_last_eb_blk, | 214 | .eo_get_last_eb_blk = ocfs2_xattr_value_get_last_eb_blk, |
198 | .eo_update_clusters = ocfs2_xattr_value_update_clusters, | 215 | .eo_update_clusters = ocfs2_xattr_value_update_clusters, |
199 | .eo_sanity_check = ocfs2_xattr_value_sanity_check, | ||
200 | .eo_fill_root_el = ocfs2_xattr_value_fill_root_el, | 216 | .eo_fill_root_el = ocfs2_xattr_value_fill_root_el, |
201 | }; | 217 | }; |
202 | 218 | ||
@@ -241,17 +257,10 @@ static void ocfs2_xattr_tree_update_clusters(struct inode *inode, | |||
241 | le32_add_cpu(&xb->xb_attrs.xb_root.xt_clusters, clusters); | 257 | le32_add_cpu(&xb->xb_attrs.xb_root.xt_clusters, clusters); |
242 | } | 258 | } |
243 | 259 | ||
244 | static int ocfs2_xattr_tree_sanity_check(struct inode *inode, | ||
245 | struct ocfs2_extent_tree *et) | ||
246 | { | ||
247 | return 0; | ||
248 | } | ||
249 | |||
250 | static struct ocfs2_extent_tree_operations ocfs2_xattr_tree_et_ops = { | 260 | static struct ocfs2_extent_tree_operations ocfs2_xattr_tree_et_ops = { |
251 | .eo_set_last_eb_blk = ocfs2_xattr_tree_set_last_eb_blk, | 261 | .eo_set_last_eb_blk = ocfs2_xattr_tree_set_last_eb_blk, |
252 | .eo_get_last_eb_blk = ocfs2_xattr_tree_get_last_eb_blk, | 262 | .eo_get_last_eb_blk = ocfs2_xattr_tree_get_last_eb_blk, |
253 | .eo_update_clusters = ocfs2_xattr_tree_update_clusters, | 263 | .eo_update_clusters = ocfs2_xattr_tree_update_clusters, |
254 | .eo_sanity_check = ocfs2_xattr_tree_sanity_check, | ||
255 | .eo_fill_root_el = ocfs2_xattr_tree_fill_root_el, | 264 | .eo_fill_root_el = ocfs2_xattr_tree_fill_root_el, |
256 | .eo_fill_max_leaf_clusters = ocfs2_xattr_tree_fill_max_leaf_clusters, | 265 | .eo_fill_max_leaf_clusters = ocfs2_xattr_tree_fill_max_leaf_clusters, |
257 | }; | 266 | }; |
@@ -344,10 +353,25 @@ static inline void ocfs2_et_update_clusters(struct inode *inode, | |||
344 | et->et_ops->eo_update_clusters(inode, et, clusters); | 353 | et->et_ops->eo_update_clusters(inode, et, clusters); |
345 | } | 354 | } |
346 | 355 | ||
356 | static inline int ocfs2_et_insert_check(struct inode *inode, | ||
357 | struct ocfs2_extent_tree *et, | ||
358 | struct ocfs2_extent_rec *rec) | ||
359 | { | ||
360 | int ret = 0; | ||
361 | |||
362 | if (et->et_ops->eo_insert_check) | ||
363 | ret = et->et_ops->eo_insert_check(inode, et, rec); | ||
364 | return ret; | ||
365 | } | ||
366 | |||
347 | static inline int ocfs2_et_sanity_check(struct inode *inode, | 367 | static inline int ocfs2_et_sanity_check(struct inode *inode, |
348 | struct ocfs2_extent_tree *et) | 368 | struct ocfs2_extent_tree *et) |
349 | { | 369 | { |
350 | return et->et_ops->eo_sanity_check(inode, et); | 370 | int ret = 0; |
371 | |||
372 | if (et->et_ops->eo_sanity_check) | ||
373 | ret = et->et_ops->eo_sanity_check(inode, et); | ||
374 | return ret; | ||
351 | } | 375 | } |
352 | 376 | ||
353 | static void ocfs2_free_truncate_context(struct ocfs2_truncate_context *tc); | 377 | static void ocfs2_free_truncate_context(struct ocfs2_truncate_context *tc); |
@@ -4399,24 +4423,19 @@ static int ocfs2_insert_extent(struct ocfs2_super *osb, | |||
4399 | struct ocfs2_insert_type insert = {0, }; | 4423 | struct ocfs2_insert_type insert = {0, }; |
4400 | struct ocfs2_extent_rec rec; | 4424 | struct ocfs2_extent_rec rec; |
4401 | 4425 | ||
4402 | BUG_ON(OCFS2_I(inode)->ip_dyn_features & OCFS2_INLINE_DATA_FL); | ||
4403 | |||
4404 | mlog(0, "add %u clusters at position %u to inode %llu\n", | 4426 | mlog(0, "add %u clusters at position %u to inode %llu\n", |
4405 | new_clusters, cpos, (unsigned long long)OCFS2_I(inode)->ip_blkno); | 4427 | new_clusters, cpos, (unsigned long long)OCFS2_I(inode)->ip_blkno); |
4406 | 4428 | ||
4407 | mlog_bug_on_msg(!ocfs2_sparse_alloc(osb) && | ||
4408 | (OCFS2_I(inode)->ip_clusters != cpos), | ||
4409 | "Device %s, asking for sparse allocation: inode %llu, " | ||
4410 | "cpos %u, clusters %u\n", | ||
4411 | osb->dev_str, | ||
4412 | (unsigned long long)OCFS2_I(inode)->ip_blkno, cpos, | ||
4413 | OCFS2_I(inode)->ip_clusters); | ||
4414 | |||
4415 | memset(&rec, 0, sizeof(rec)); | 4429 | memset(&rec, 0, sizeof(rec)); |
4416 | rec.e_cpos = cpu_to_le32(cpos); | 4430 | rec.e_cpos = cpu_to_le32(cpos); |
4417 | rec.e_blkno = cpu_to_le64(start_blk); | 4431 | rec.e_blkno = cpu_to_le64(start_blk); |
4418 | rec.e_leaf_clusters = cpu_to_le16(new_clusters); | 4432 | rec.e_leaf_clusters = cpu_to_le16(new_clusters); |
4419 | rec.e_flags = flags; | 4433 | rec.e_flags = flags; |
4434 | status = ocfs2_et_insert_check(inode, et, &rec); | ||
4435 | if (status) { | ||
4436 | mlog_errno(status); | ||
4437 | goto bail; | ||
4438 | } | ||
4420 | 4439 | ||
4421 | status = ocfs2_figure_insert_type(inode, et, &last_eb_bh, &rec, | 4440 | status = ocfs2_figure_insert_type(inode, et, &last_eb_bh, &rec, |
4422 | &free_records, &insert); | 4441 | &free_records, &insert); |