alloc.c (f056878332a91ed984a116bad4e7d49aefff9e6e) alloc.c (853a3a1439b18d5a70ada2cb3fcd468e70b7d095)
1/* -*- mode: c; c-basic-offset: 8; -*-
2 * vim: noexpandtab sw=8 ts=8 sts=0:
3 *
4 * alloc.c
5 *
6 * Extent allocs and frees
7 *
8 * Copyright (C) 2002, 2004 Oracle. All rights reserved.

--- 38 unchanged lines hidden (view full) ---

47#include "sysfile.h"
48#include "file.h"
49#include "super.h"
50#include "uptodate.h"
51#include "xattr.h"
52
53#include "buffer_head_io.h"
54
1/* -*- mode: c; c-basic-offset: 8; -*-
2 * vim: noexpandtab sw=8 ts=8 sts=0:
3 *
4 * alloc.c
5 *
6 * Extent allocs and frees
7 *
8 * Copyright (C) 2002, 2004 Oracle. All rights reserved.

--- 38 unchanged lines hidden (view full) ---

47#include "sysfile.h"
48#include "file.h"
49#include "super.h"
50#include "uptodate.h"
51#include "xattr.h"
52
53#include "buffer_head_io.h"
54
55enum ocfs2_contig_type {
56 CONTIG_NONE = 0,
57 CONTIG_LEFT,
58 CONTIG_RIGHT,
59 CONTIG_LEFTRIGHT,
60};
55
61
62static enum ocfs2_contig_type
63 ocfs2_extent_rec_contig(struct super_block *sb,
64 struct ocfs2_extent_rec *ext,
65 struct ocfs2_extent_rec *insert_rec);
56/*
57 * Operations for a specific extent tree type.
58 *
59 * To implement an on-disk btree (extent tree) type in ocfs2, add
60 * an ocfs2_extent_tree_operations structure and the matching
61 * ocfs2_init_<thingy>_extent_tree() function. That's pretty much it
62 * for the allocation portion of the extent tree.
63 */

--- 10 unchanged lines hidden (view full) ---

74 u64 (*eo_get_last_eb_blk)(struct ocfs2_extent_tree *et);
75
76 /*
77 * The on-disk structure usually keeps track of how many total
78 * clusters are stored in this extent tree. This function updates
79 * that value. new_clusters is the delta, and must be
80 * added to the total. Required.
81 */
66/*
67 * Operations for a specific extent tree type.
68 *
69 * To implement an on-disk btree (extent tree) type in ocfs2, add
70 * an ocfs2_extent_tree_operations structure and the matching
71 * ocfs2_init_<thingy>_extent_tree() function. That's pretty much it
72 * for the allocation portion of the extent tree.
73 */

--- 10 unchanged lines hidden (view full) ---

84 u64 (*eo_get_last_eb_blk)(struct ocfs2_extent_tree *et);
85
86 /*
87 * The on-disk structure usually keeps track of how many total
88 * clusters are stored in this extent tree. This function updates
89 * that value. new_clusters is the delta, and must be
90 * added to the total. Required.
91 */
82 void (*eo_update_clusters)(struct inode *inode,
83 struct ocfs2_extent_tree *et,
92 void (*eo_update_clusters)(struct ocfs2_extent_tree *et,
84 u32 new_clusters);
85
86 /*
93 u32 new_clusters);
94
95 /*
96 * If this extent tree is supported by an extent map, insert
97 * a record into the map.
98 */
99 void (*eo_extent_map_insert)(struct ocfs2_extent_tree *et,
100 struct ocfs2_extent_rec *rec);
101
102 /*
103 * If this extent tree is supported by an extent map, truncate the
104 * map to clusters,
105 */
106 void (*eo_extent_map_truncate)(struct ocfs2_extent_tree *et,
107 u32 clusters);
108
109 /*
87 * If ->eo_insert_check() exists, it is called before rec is
88 * inserted into the extent tree. It is optional.
89 */
110 * If ->eo_insert_check() exists, it is called before rec is
111 * inserted into the extent tree. It is optional.
112 */
90 int (*eo_insert_check)(struct inode *inode,
91 struct ocfs2_extent_tree *et,
113 int (*eo_insert_check)(struct ocfs2_extent_tree *et,
92 struct ocfs2_extent_rec *rec);
114 struct ocfs2_extent_rec *rec);
93 int (*eo_sanity_check)(struct inode *inode, struct ocfs2_extent_tree *et);
115 int (*eo_sanity_check)(struct ocfs2_extent_tree *et);
94
95 /*
96 * --------------------------------------------------------------
97 * The remaining are internal to ocfs2_extent_tree and don't have
98 * accessor functions
99 */
100
101 /*
102 * ->eo_fill_root_el() takes et->et_object and sets et->et_root_el.
103 * It is required.
104 */
105 void (*eo_fill_root_el)(struct ocfs2_extent_tree *et);
106
107 /*
108 * ->eo_fill_max_leaf_clusters sets et->et_max_leaf_clusters if
109 * it exists. If it does not, et->et_max_leaf_clusters is set
110 * to 0 (unlimited). Optional.
111 */
116
117 /*
118 * --------------------------------------------------------------
119 * The remaining are internal to ocfs2_extent_tree and don't have
120 * accessor functions
121 */
122
123 /*
124 * ->eo_fill_root_el() takes et->et_object and sets et->et_root_el.
125 * It is required.
126 */
127 void (*eo_fill_root_el)(struct ocfs2_extent_tree *et);
128
129 /*
130 * ->eo_fill_max_leaf_clusters sets et->et_max_leaf_clusters if
131 * it exists. If it does not, et->et_max_leaf_clusters is set
132 * to 0 (unlimited). Optional.
133 */
112 void (*eo_fill_max_leaf_clusters)(struct inode *inode,
113 struct ocfs2_extent_tree *et);
134 void (*eo_fill_max_leaf_clusters)(struct ocfs2_extent_tree *et);
135
136 /*
137 * ->eo_extent_contig test whether the 2 ocfs2_extent_rec
138 * are contiguous or not. Optional. Don't need to set it if use
139 * ocfs2_extent_rec as the tree leaf.
140 */
141 enum ocfs2_contig_type
142 (*eo_extent_contig)(struct ocfs2_extent_tree *et,
143 struct ocfs2_extent_rec *ext,
144 struct ocfs2_extent_rec *insert_rec);
114};
115
116
117/*
118 * Pre-declare ocfs2_dinode_et_ops so we can use it as a sanity check
119 * in the methods.
120 */
121static u64 ocfs2_dinode_get_last_eb_blk(struct ocfs2_extent_tree *et);
122static void ocfs2_dinode_set_last_eb_blk(struct ocfs2_extent_tree *et,
123 u64 blkno);
145};
146
147
148/*
149 * Pre-declare ocfs2_dinode_et_ops so we can use it as a sanity check
150 * in the methods.
151 */
152static u64 ocfs2_dinode_get_last_eb_blk(struct ocfs2_extent_tree *et);
153static void ocfs2_dinode_set_last_eb_blk(struct ocfs2_extent_tree *et,
154 u64 blkno);
124static void ocfs2_dinode_update_clusters(struct inode *inode,
125 struct ocfs2_extent_tree *et,
155static void ocfs2_dinode_update_clusters(struct ocfs2_extent_tree *et,
126 u32 clusters);
156 u32 clusters);
127static int ocfs2_dinode_insert_check(struct inode *inode,
128 struct ocfs2_extent_tree *et,
157static void ocfs2_dinode_extent_map_insert(struct ocfs2_extent_tree *et,
158 struct ocfs2_extent_rec *rec);
159static void ocfs2_dinode_extent_map_truncate(struct ocfs2_extent_tree *et,
160 u32 clusters);
161static int ocfs2_dinode_insert_check(struct ocfs2_extent_tree *et,
129 struct ocfs2_extent_rec *rec);
162 struct ocfs2_extent_rec *rec);
130static int ocfs2_dinode_sanity_check(struct inode *inode,
131 struct ocfs2_extent_tree *et);
163static int ocfs2_dinode_sanity_check(struct ocfs2_extent_tree *et);
132static void ocfs2_dinode_fill_root_el(struct ocfs2_extent_tree *et);
133static struct ocfs2_extent_tree_operations ocfs2_dinode_et_ops = {
134 .eo_set_last_eb_blk = ocfs2_dinode_set_last_eb_blk,
135 .eo_get_last_eb_blk = ocfs2_dinode_get_last_eb_blk,
136 .eo_update_clusters = ocfs2_dinode_update_clusters,
164static void ocfs2_dinode_fill_root_el(struct ocfs2_extent_tree *et);
165static struct ocfs2_extent_tree_operations ocfs2_dinode_et_ops = {
166 .eo_set_last_eb_blk = ocfs2_dinode_set_last_eb_blk,
167 .eo_get_last_eb_blk = ocfs2_dinode_get_last_eb_blk,
168 .eo_update_clusters = ocfs2_dinode_update_clusters,
169 .eo_extent_map_insert = ocfs2_dinode_extent_map_insert,
170 .eo_extent_map_truncate = ocfs2_dinode_extent_map_truncate,
137 .eo_insert_check = ocfs2_dinode_insert_check,
138 .eo_sanity_check = ocfs2_dinode_sanity_check,
139 .eo_fill_root_el = ocfs2_dinode_fill_root_el,
140};
141
142static void ocfs2_dinode_set_last_eb_blk(struct ocfs2_extent_tree *et,
143 u64 blkno)
144{

--- 6 unchanged lines hidden (view full) ---

151static u64 ocfs2_dinode_get_last_eb_blk(struct ocfs2_extent_tree *et)
152{
153 struct ocfs2_dinode *di = et->et_object;
154
155 BUG_ON(et->et_ops != &ocfs2_dinode_et_ops);
156 return le64_to_cpu(di->i_last_eb_blk);
157}
158
171 .eo_insert_check = ocfs2_dinode_insert_check,
172 .eo_sanity_check = ocfs2_dinode_sanity_check,
173 .eo_fill_root_el = ocfs2_dinode_fill_root_el,
174};
175
176static void ocfs2_dinode_set_last_eb_blk(struct ocfs2_extent_tree *et,
177 u64 blkno)
178{

--- 6 unchanged lines hidden (view full) ---

185static u64 ocfs2_dinode_get_last_eb_blk(struct ocfs2_extent_tree *et)
186{
187 struct ocfs2_dinode *di = et->et_object;
188
189 BUG_ON(et->et_ops != &ocfs2_dinode_et_ops);
190 return le64_to_cpu(di->i_last_eb_blk);
191}
192
159static void ocfs2_dinode_update_clusters(struct inode *inode,
160 struct ocfs2_extent_tree *et,
193static void ocfs2_dinode_update_clusters(struct ocfs2_extent_tree *et,
161 u32 clusters)
162{
194 u32 clusters)
195{
196 struct ocfs2_inode_info *oi = cache_info_to_inode(et->et_ci);
163 struct ocfs2_dinode *di = et->et_object;
164
165 le32_add_cpu(&di->i_clusters, clusters);
197 struct ocfs2_dinode *di = et->et_object;
198
199 le32_add_cpu(&di->i_clusters, clusters);
166 spin_lock(&OCFS2_I(inode)->ip_lock);
167 OCFS2_I(inode)->ip_clusters = le32_to_cpu(di->i_clusters);
168 spin_unlock(&OCFS2_I(inode)->ip_lock);
200 spin_lock(&oi->ip_lock);
201 oi->ip_clusters = le32_to_cpu(di->i_clusters);
202 spin_unlock(&oi->ip_lock);
169}
170
203}
204
171static int ocfs2_dinode_insert_check(struct inode *inode,
172 struct ocfs2_extent_tree *et,
205static void ocfs2_dinode_extent_map_insert(struct ocfs2_extent_tree *et,
206 struct ocfs2_extent_rec *rec)
207{
208 struct inode *inode = &cache_info_to_inode(et->et_ci)->vfs_inode;
209
210 ocfs2_extent_map_insert_rec(inode, rec);
211}
212
213static void ocfs2_dinode_extent_map_truncate(struct ocfs2_extent_tree *et,
214 u32 clusters)
215{
216 struct inode *inode = &cache_info_to_inode(et->et_ci)->vfs_inode;
217
218 ocfs2_extent_map_trunc(inode, clusters);
219}
220
221static int ocfs2_dinode_insert_check(struct ocfs2_extent_tree *et,
173 struct ocfs2_extent_rec *rec)
174{
222 struct ocfs2_extent_rec *rec)
223{
175 struct ocfs2_super *osb = OCFS2_SB(inode->i_sb);
224 struct ocfs2_inode_info *oi = cache_info_to_inode(et->et_ci);
225 struct ocfs2_super *osb = OCFS2_SB(oi->vfs_inode.i_sb);
176
226
177 BUG_ON(OCFS2_I(inode)->ip_dyn_features & OCFS2_INLINE_DATA_FL);
227 BUG_ON(oi->ip_dyn_features & OCFS2_INLINE_DATA_FL);
178 mlog_bug_on_msg(!ocfs2_sparse_alloc(osb) &&
228 mlog_bug_on_msg(!ocfs2_sparse_alloc(osb) &&
179 (OCFS2_I(inode)->ip_clusters !=
180 le32_to_cpu(rec->e_cpos)),
229 (oi->ip_clusters != le32_to_cpu(rec->e_cpos)),
181 "Device %s, asking for sparse allocation: inode %llu, "
182 "cpos %u, clusters %u\n",
183 osb->dev_str,
230 "Device %s, asking for sparse allocation: inode %llu, "
231 "cpos %u, clusters %u\n",
232 osb->dev_str,
184 (unsigned long long)OCFS2_I(inode)->ip_blkno,
185 rec->e_cpos,
186 OCFS2_I(inode)->ip_clusters);
233 (unsigned long long)oi->ip_blkno,
234 rec->e_cpos, oi->ip_clusters);
187
188 return 0;
189}
190
235
236 return 0;
237}
238
191static int ocfs2_dinode_sanity_check(struct inode *inode,
192 struct ocfs2_extent_tree *et)
239static int ocfs2_dinode_sanity_check(struct ocfs2_extent_tree *et)
193{
194 struct ocfs2_dinode *di = et->et_object;
195
196 BUG_ON(et->et_ops != &ocfs2_dinode_et_ops);
197 BUG_ON(!OCFS2_IS_VALID_DINODE(di));
198
199 return 0;
200}

--- 23 unchanged lines hidden (view full) ---

224
225static u64 ocfs2_xattr_value_get_last_eb_blk(struct ocfs2_extent_tree *et)
226{
227 struct ocfs2_xattr_value_buf *vb = et->et_object;
228
229 return le64_to_cpu(vb->vb_xv->xr_last_eb_blk);
230}
231
240{
241 struct ocfs2_dinode *di = et->et_object;
242
243 BUG_ON(et->et_ops != &ocfs2_dinode_et_ops);
244 BUG_ON(!OCFS2_IS_VALID_DINODE(di));
245
246 return 0;
247}

--- 23 unchanged lines hidden (view full) ---

271
272static u64 ocfs2_xattr_value_get_last_eb_blk(struct ocfs2_extent_tree *et)
273{
274 struct ocfs2_xattr_value_buf *vb = et->et_object;
275
276 return le64_to_cpu(vb->vb_xv->xr_last_eb_blk);
277}
278
232static void ocfs2_xattr_value_update_clusters(struct inode *inode,
233 struct ocfs2_extent_tree *et,
279static void ocfs2_xattr_value_update_clusters(struct ocfs2_extent_tree *et,
234 u32 clusters)
235{
236 struct ocfs2_xattr_value_buf *vb = et->et_object;
237
238 le32_add_cpu(&vb->vb_xv->xr_clusters, clusters);
239}
240
241static struct ocfs2_extent_tree_operations ocfs2_xattr_value_et_ops = {

--- 5 unchanged lines hidden (view full) ---

247
248static void ocfs2_xattr_tree_fill_root_el(struct ocfs2_extent_tree *et)
249{
250 struct ocfs2_xattr_block *xb = et->et_object;
251
252 et->et_root_el = &xb->xb_attrs.xb_root.xt_list;
253}
254
280 u32 clusters)
281{
282 struct ocfs2_xattr_value_buf *vb = et->et_object;
283
284 le32_add_cpu(&vb->vb_xv->xr_clusters, clusters);
285}
286
287static struct ocfs2_extent_tree_operations ocfs2_xattr_value_et_ops = {

--- 5 unchanged lines hidden (view full) ---

293
294static void ocfs2_xattr_tree_fill_root_el(struct ocfs2_extent_tree *et)
295{
296 struct ocfs2_xattr_block *xb = et->et_object;
297
298 et->et_root_el = &xb->xb_attrs.xb_root.xt_list;
299}
300
255static void ocfs2_xattr_tree_fill_max_leaf_clusters(struct inode *inode,
256 struct ocfs2_extent_tree *et)
301static void ocfs2_xattr_tree_fill_max_leaf_clusters(struct ocfs2_extent_tree *et)
257{
302{
303 struct super_block *sb = ocfs2_metadata_cache_get_super(et->et_ci);
258 et->et_max_leaf_clusters =
304 et->et_max_leaf_clusters =
259 ocfs2_clusters_for_bytes(inode->i_sb,
260 OCFS2_MAX_XATTR_TREE_LEAF_SIZE);
305 ocfs2_clusters_for_bytes(sb, OCFS2_MAX_XATTR_TREE_LEAF_SIZE);
261}
262
263static void ocfs2_xattr_tree_set_last_eb_blk(struct ocfs2_extent_tree *et,
264 u64 blkno)
265{
266 struct ocfs2_xattr_block *xb = et->et_object;
267 struct ocfs2_xattr_tree_root *xt = &xb->xb_attrs.xb_root;
268
269 xt->xt_last_eb_blk = cpu_to_le64(blkno);
270}
271
272static u64 ocfs2_xattr_tree_get_last_eb_blk(struct ocfs2_extent_tree *et)
273{
274 struct ocfs2_xattr_block *xb = et->et_object;
275 struct ocfs2_xattr_tree_root *xt = &xb->xb_attrs.xb_root;
276
277 return le64_to_cpu(xt->xt_last_eb_blk);
278}
279
306}
307
308static void ocfs2_xattr_tree_set_last_eb_blk(struct ocfs2_extent_tree *et,
309 u64 blkno)
310{
311 struct ocfs2_xattr_block *xb = et->et_object;
312 struct ocfs2_xattr_tree_root *xt = &xb->xb_attrs.xb_root;
313
314 xt->xt_last_eb_blk = cpu_to_le64(blkno);
315}
316
317static u64 ocfs2_xattr_tree_get_last_eb_blk(struct ocfs2_extent_tree *et)
318{
319 struct ocfs2_xattr_block *xb = et->et_object;
320 struct ocfs2_xattr_tree_root *xt = &xb->xb_attrs.xb_root;
321
322 return le64_to_cpu(xt->xt_last_eb_blk);
323}
324
280static void ocfs2_xattr_tree_update_clusters(struct inode *inode,
281 struct ocfs2_extent_tree *et,
325static void ocfs2_xattr_tree_update_clusters(struct ocfs2_extent_tree *et,
282 u32 clusters)
283{
284 struct ocfs2_xattr_block *xb = et->et_object;
285
286 le32_add_cpu(&xb->xb_attrs.xb_root.xt_clusters, clusters);
287}
288
289static struct ocfs2_extent_tree_operations ocfs2_xattr_tree_et_ops = {

--- 14 unchanged lines hidden (view full) ---

304
305static u64 ocfs2_dx_root_get_last_eb_blk(struct ocfs2_extent_tree *et)
306{
307 struct ocfs2_dx_root_block *dx_root = et->et_object;
308
309 return le64_to_cpu(dx_root->dr_last_eb_blk);
310}
311
326 u32 clusters)
327{
328 struct ocfs2_xattr_block *xb = et->et_object;
329
330 le32_add_cpu(&xb->xb_attrs.xb_root.xt_clusters, clusters);
331}
332
333static struct ocfs2_extent_tree_operations ocfs2_xattr_tree_et_ops = {

--- 14 unchanged lines hidden (view full) ---

348
349static u64 ocfs2_dx_root_get_last_eb_blk(struct ocfs2_extent_tree *et)
350{
351 struct ocfs2_dx_root_block *dx_root = et->et_object;
352
353 return le64_to_cpu(dx_root->dr_last_eb_blk);
354}
355
312static void ocfs2_dx_root_update_clusters(struct inode *inode,
313 struct ocfs2_extent_tree *et,
356static void ocfs2_dx_root_update_clusters(struct ocfs2_extent_tree *et,
314 u32 clusters)
315{
316 struct ocfs2_dx_root_block *dx_root = et->et_object;
317
318 le32_add_cpu(&dx_root->dr_clusters, clusters);
319}
320
357 u32 clusters)
358{
359 struct ocfs2_dx_root_block *dx_root = et->et_object;
360
361 le32_add_cpu(&dx_root->dr_clusters, clusters);
362}
363
321static int ocfs2_dx_root_sanity_check(struct inode *inode,
322 struct ocfs2_extent_tree *et)
364static int ocfs2_dx_root_sanity_check(struct ocfs2_extent_tree *et)
323{
324 struct ocfs2_dx_root_block *dx_root = et->et_object;
325
326 BUG_ON(!OCFS2_IS_VALID_DX_ROOT(dx_root));
327
328 return 0;
329}
330

--- 8 unchanged lines hidden (view full) ---

339 .eo_set_last_eb_blk = ocfs2_dx_root_set_last_eb_blk,
340 .eo_get_last_eb_blk = ocfs2_dx_root_get_last_eb_blk,
341 .eo_update_clusters = ocfs2_dx_root_update_clusters,
342 .eo_sanity_check = ocfs2_dx_root_sanity_check,
343 .eo_fill_root_el = ocfs2_dx_root_fill_root_el,
344};
345
346static void __ocfs2_init_extent_tree(struct ocfs2_extent_tree *et,
365{
366 struct ocfs2_dx_root_block *dx_root = et->et_object;
367
368 BUG_ON(!OCFS2_IS_VALID_DX_ROOT(dx_root));
369
370 return 0;
371}
372

--- 8 unchanged lines hidden (view full) ---

381 .eo_set_last_eb_blk = ocfs2_dx_root_set_last_eb_blk,
382 .eo_get_last_eb_blk = ocfs2_dx_root_get_last_eb_blk,
383 .eo_update_clusters = ocfs2_dx_root_update_clusters,
384 .eo_sanity_check = ocfs2_dx_root_sanity_check,
385 .eo_fill_root_el = ocfs2_dx_root_fill_root_el,
386};
387
388static void __ocfs2_init_extent_tree(struct ocfs2_extent_tree *et,
347 struct inode *inode,
389 struct ocfs2_caching_info *ci,
348 struct buffer_head *bh,
349 ocfs2_journal_access_func access,
350 void *obj,
351 struct ocfs2_extent_tree_operations *ops)
352{
353 et->et_ops = ops;
354 et->et_root_bh = bh;
390 struct buffer_head *bh,
391 ocfs2_journal_access_func access,
392 void *obj,
393 struct ocfs2_extent_tree_operations *ops)
394{
395 et->et_ops = ops;
396 et->et_root_bh = bh;
397 et->et_ci = ci;
355 et->et_root_journal_access = access;
356 if (!obj)
357 obj = (void *)bh->b_data;
358 et->et_object = obj;
359
360 et->et_ops->eo_fill_root_el(et);
361 if (!et->et_ops->eo_fill_max_leaf_clusters)
362 et->et_max_leaf_clusters = 0;
363 else
398 et->et_root_journal_access = access;
399 if (!obj)
400 obj = (void *)bh->b_data;
401 et->et_object = obj;
402
403 et->et_ops->eo_fill_root_el(et);
404 if (!et->et_ops->eo_fill_max_leaf_clusters)
405 et->et_max_leaf_clusters = 0;
406 else
364 et->et_ops->eo_fill_max_leaf_clusters(inode, et);
407 et->et_ops->eo_fill_max_leaf_clusters(et);
365}
366
367void ocfs2_init_dinode_extent_tree(struct ocfs2_extent_tree *et,
408}
409
410void ocfs2_init_dinode_extent_tree(struct ocfs2_extent_tree *et,
368 struct inode *inode,
411 struct ocfs2_caching_info *ci,
369 struct buffer_head *bh)
370{
412 struct buffer_head *bh)
413{
371 __ocfs2_init_extent_tree(et, inode, bh, ocfs2_journal_access_di,
414 __ocfs2_init_extent_tree(et, ci, bh, ocfs2_journal_access_di,
372 NULL, &ocfs2_dinode_et_ops);
373}
374
375void ocfs2_init_xattr_tree_extent_tree(struct ocfs2_extent_tree *et,
415 NULL, &ocfs2_dinode_et_ops);
416}
417
418void ocfs2_init_xattr_tree_extent_tree(struct ocfs2_extent_tree *et,
376 struct inode *inode,
419 struct ocfs2_caching_info *ci,
377 struct buffer_head *bh)
378{
420 struct buffer_head *bh)
421{
379 __ocfs2_init_extent_tree(et, inode, bh, ocfs2_journal_access_xb,
422 __ocfs2_init_extent_tree(et, ci, bh, ocfs2_journal_access_xb,
380 NULL, &ocfs2_xattr_tree_et_ops);
381}
382
383void ocfs2_init_xattr_value_extent_tree(struct ocfs2_extent_tree *et,
423 NULL, &ocfs2_xattr_tree_et_ops);
424}
425
426void ocfs2_init_xattr_value_extent_tree(struct ocfs2_extent_tree *et,
384 struct inode *inode,
427 struct ocfs2_caching_info *ci,
385 struct ocfs2_xattr_value_buf *vb)
386{
428 struct ocfs2_xattr_value_buf *vb)
429{
387 __ocfs2_init_extent_tree(et, inode, vb->vb_bh, vb->vb_access, vb,
430 __ocfs2_init_extent_tree(et, ci, vb->vb_bh, vb->vb_access, vb,
388 &ocfs2_xattr_value_et_ops);
389}
390
391void ocfs2_init_dx_root_extent_tree(struct ocfs2_extent_tree *et,
431 &ocfs2_xattr_value_et_ops);
432}
433
434void ocfs2_init_dx_root_extent_tree(struct ocfs2_extent_tree *et,
392 struct inode *inode,
435 struct ocfs2_caching_info *ci,
393 struct buffer_head *bh)
394{
436 struct buffer_head *bh)
437{
395 __ocfs2_init_extent_tree(et, inode, bh, ocfs2_journal_access_dr,
438 __ocfs2_init_extent_tree(et, ci, bh, ocfs2_journal_access_dr,
396 NULL, &ocfs2_dx_root_et_ops);
397}
398
399static inline void ocfs2_et_set_last_eb_blk(struct ocfs2_extent_tree *et,
400 u64 new_last_eb_blk)
401{
402 et->et_ops->eo_set_last_eb_blk(et, new_last_eb_blk);
403}
404
405static inline u64 ocfs2_et_get_last_eb_blk(struct ocfs2_extent_tree *et)
406{
407 return et->et_ops->eo_get_last_eb_blk(et);
408}
409
439 NULL, &ocfs2_dx_root_et_ops);
440}
441
442static inline void ocfs2_et_set_last_eb_blk(struct ocfs2_extent_tree *et,
443 u64 new_last_eb_blk)
444{
445 et->et_ops->eo_set_last_eb_blk(et, new_last_eb_blk);
446}
447
448static inline u64 ocfs2_et_get_last_eb_blk(struct ocfs2_extent_tree *et)
449{
450 return et->et_ops->eo_get_last_eb_blk(et);
451}
452
410static inline void ocfs2_et_update_clusters(struct inode *inode,
411 struct ocfs2_extent_tree *et,
453static inline void ocfs2_et_update_clusters(struct ocfs2_extent_tree *et,
412 u32 clusters)
413{
454 u32 clusters)
455{
414 et->et_ops->eo_update_clusters(inode, et, clusters);
456 et->et_ops->eo_update_clusters(et, clusters);
415}
416
457}
458
459static inline void ocfs2_et_extent_map_insert(struct ocfs2_extent_tree *et,
460 struct ocfs2_extent_rec *rec)
461{
462 if (et->et_ops->eo_extent_map_insert)
463 et->et_ops->eo_extent_map_insert(et, rec);
464}
465
466static inline void ocfs2_et_extent_map_truncate(struct ocfs2_extent_tree *et,
467 u32 clusters)
468{
469 if (et->et_ops->eo_extent_map_truncate)
470 et->et_ops->eo_extent_map_truncate(et, clusters);
471}
472
417static inline int ocfs2_et_root_journal_access(handle_t *handle,
473static inline int ocfs2_et_root_journal_access(handle_t *handle,
418 struct inode *inode,
419 struct ocfs2_extent_tree *et,
420 int type)
421{
474 struct ocfs2_extent_tree *et,
475 int type)
476{
422 return et->et_root_journal_access(handle, inode, et->et_root_bh,
477 return et->et_root_journal_access(handle, et->et_ci, et->et_root_bh,
423 type);
424}
425
478 type);
479}
480
426static inline int ocfs2_et_insert_check(struct inode *inode,
427 struct ocfs2_extent_tree *et,
481static inline enum ocfs2_contig_type
482 ocfs2_et_extent_contig(struct ocfs2_extent_tree *et,
483 struct ocfs2_extent_rec *rec,
484 struct ocfs2_extent_rec *insert_rec)
485{
486 if (et->et_ops->eo_extent_contig)
487 return et->et_ops->eo_extent_contig(et, rec, insert_rec);
488
489 return ocfs2_extent_rec_contig(
490 ocfs2_metadata_cache_get_super(et->et_ci),
491 rec, insert_rec);
492}
493
494static inline int ocfs2_et_insert_check(struct ocfs2_extent_tree *et,
428 struct ocfs2_extent_rec *rec)
429{
430 int ret = 0;
431
432 if (et->et_ops->eo_insert_check)
495 struct ocfs2_extent_rec *rec)
496{
497 int ret = 0;
498
499 if (et->et_ops->eo_insert_check)
433 ret = et->et_ops->eo_insert_check(inode, et, rec);
500 ret = et->et_ops->eo_insert_check(et, rec);
434 return ret;
435}
436
501 return ret;
502}
503
437static inline int ocfs2_et_sanity_check(struct inode *inode,
438 struct ocfs2_extent_tree *et)
504static inline int ocfs2_et_sanity_check(struct ocfs2_extent_tree *et)
439{
440 int ret = 0;
441
442 if (et->et_ops->eo_sanity_check)
505{
506 int ret = 0;
507
508 if (et->et_ops->eo_sanity_check)
443 ret = et->et_ops->eo_sanity_check(inode, et);
509 ret = et->et_ops->eo_sanity_check(et);
444 return ret;
445}
446
447static void ocfs2_free_truncate_context(struct ocfs2_truncate_context *tc);
448static int ocfs2_cache_extent_block_free(struct ocfs2_cached_dealloc_ctxt *ctxt,
449 struct ocfs2_extent_block *eb);
450
451/*

--- 18 unchanged lines hidden (view full) ---

470
471#define path_root_bh(_path) ((_path)->p_node[0].bh)
472#define path_root_el(_path) ((_path)->p_node[0].el)
473#define path_root_access(_path)((_path)->p_root_access)
474#define path_leaf_bh(_path) ((_path)->p_node[(_path)->p_tree_depth].bh)
475#define path_leaf_el(_path) ((_path)->p_node[(_path)->p_tree_depth].el)
476#define path_num_items(_path) ((_path)->p_tree_depth + 1)
477
510 return ret;
511}
512
513static void ocfs2_free_truncate_context(struct ocfs2_truncate_context *tc);
514static int ocfs2_cache_extent_block_free(struct ocfs2_cached_dealloc_ctxt *ctxt,
515 struct ocfs2_extent_block *eb);
516
517/*

--- 18 unchanged lines hidden (view full) ---

536
537#define path_root_bh(_path) ((_path)->p_node[0].bh)
538#define path_root_el(_path) ((_path)->p_node[0].el)
539#define path_root_access(_path)((_path)->p_root_access)
540#define path_leaf_bh(_path) ((_path)->p_node[(_path)->p_tree_depth].bh)
541#define path_leaf_el(_path) ((_path)->p_node[(_path)->p_tree_depth].el)
542#define path_num_items(_path) ((_path)->p_tree_depth + 1)
543
478static int ocfs2_find_path(struct inode *inode, struct ocfs2_path *path,
479 u32 cpos);
480static void ocfs2_adjust_rightmost_records(struct inode *inode,
481 handle_t *handle,
544static int ocfs2_find_path(struct ocfs2_caching_info *ci,
545 struct ocfs2_path *path, u32 cpos);
546static void ocfs2_adjust_rightmost_records(handle_t *handle,
547 struct ocfs2_extent_tree *et,
482 struct ocfs2_path *path,
483 struct ocfs2_extent_rec *insert_rec);
484/*
485 * Reset the actual path elements so that we can re-use the structure
486 * to build another path. Generally, this involves freeing the buffer
487 * heads.
488 */
489static void ocfs2_reinit_path(struct ocfs2_path *path, int keep_root)

--- 138 unchanged lines hidden (view full) ---

628/*
629 * Journal the buffer at depth idx. All idx>0 are extent_blocks,
630 * otherwise it's the root_access function.
631 *
632 * I don't like the way this function's name looks next to
633 * ocfs2_journal_access_path(), but I don't have a better one.
634 */
635static int ocfs2_path_bh_journal_access(handle_t *handle,
548 struct ocfs2_path *path,
549 struct ocfs2_extent_rec *insert_rec);
550/*
551 * Reset the actual path elements so that we can re-use the structure
552 * to build another path. Generally, this involves freeing the buffer
553 * heads.
554 */
555static void ocfs2_reinit_path(struct ocfs2_path *path, int keep_root)

--- 138 unchanged lines hidden (view full) ---

694/*
695 * Journal the buffer at depth idx. All idx>0 are extent_blocks,
696 * otherwise it's the root_access function.
697 *
698 * I don't like the way this function's name looks next to
699 * ocfs2_journal_access_path(), but I don't have a better one.
700 */
701static int ocfs2_path_bh_journal_access(handle_t *handle,
636 struct inode *inode,
702 struct ocfs2_caching_info *ci,
637 struct ocfs2_path *path,
638 int idx)
639{
640 ocfs2_journal_access_func access = path_root_access(path);
641
642 if (!access)
643 access = ocfs2_journal_access;
644
645 if (idx)
646 access = ocfs2_journal_access_eb;
647
703 struct ocfs2_path *path,
704 int idx)
705{
706 ocfs2_journal_access_func access = path_root_access(path);
707
708 if (!access)
709 access = ocfs2_journal_access;
710
711 if (idx)
712 access = ocfs2_journal_access_eb;
713
648 return access(handle, inode, path->p_node[idx].bh,
714 return access(handle, ci, path->p_node[idx].bh,
649 OCFS2_JOURNAL_ACCESS_WRITE);
650}
651
652/*
653 * Convenience function to journal all components in a path.
654 */
715 OCFS2_JOURNAL_ACCESS_WRITE);
716}
717
718/*
719 * Convenience function to journal all components in a path.
720 */
655static int ocfs2_journal_access_path(struct inode *inode, handle_t *handle,
721static int ocfs2_journal_access_path(struct ocfs2_caching_info *ci,
722 handle_t *handle,
656 struct ocfs2_path *path)
657{
658 int i, ret = 0;
659
660 if (!path)
661 goto out;
662
663 for(i = 0; i < path_num_items(path); i++) {
723 struct ocfs2_path *path)
724{
725 int i, ret = 0;
726
727 if (!path)
728 goto out;
729
730 for(i = 0; i < path_num_items(path); i++) {
664 ret = ocfs2_path_bh_journal_access(handle, inode, path, i);
731 ret = ocfs2_path_bh_journal_access(handle, ci, path, i);
665 if (ret < 0) {
666 mlog_errno(ret);
667 goto out;
668 }
669 }
670
671out:
672 return ret;

--- 24 unchanged lines hidden (view full) ---

697 ret = i;
698 break;
699 }
700 }
701
702 return ret;
703}
704
732 if (ret < 0) {
733 mlog_errno(ret);
734 goto out;
735 }
736 }
737
738out:
739 return ret;

--- 24 unchanged lines hidden (view full) ---

764 ret = i;
765 break;
766 }
767 }
768
769 return ret;
770}
771
705enum ocfs2_contig_type {
706 CONTIG_NONE = 0,
707 CONTIG_LEFT,
708 CONTIG_RIGHT,
709 CONTIG_LEFTRIGHT,
710};
711
712
713/*
714 * NOTE: ocfs2_block_extent_contig(), ocfs2_extents_adjacent() and
772/*
773 * NOTE: ocfs2_block_extent_contig(), ocfs2_extents_adjacent() and
715 * ocfs2_extent_contig only work properly against leaf nodes!
774 * ocfs2_extent_rec_contig only work properly against leaf nodes!
716 */
717static int ocfs2_block_extent_contig(struct super_block *sb,
718 struct ocfs2_extent_rec *ext,
719 u64 blkno)
720{
721 u64 blk_end = le64_to_cpu(ext->e_blkno);
722
723 blk_end += ocfs2_clusters_to_blocks(sb,

--- 9 unchanged lines hidden (view full) ---

733
734 left_range = le32_to_cpu(left->e_cpos) +
735 le16_to_cpu(left->e_leaf_clusters);
736
737 return (left_range == le32_to_cpu(right->e_cpos));
738}
739
740static enum ocfs2_contig_type
775 */
776static int ocfs2_block_extent_contig(struct super_block *sb,
777 struct ocfs2_extent_rec *ext,
778 u64 blkno)
779{
780 u64 blk_end = le64_to_cpu(ext->e_blkno);
781
782 blk_end += ocfs2_clusters_to_blocks(sb,

--- 9 unchanged lines hidden (view full) ---

792
793 left_range = le32_to_cpu(left->e_cpos) +
794 le16_to_cpu(left->e_leaf_clusters);
795
796 return (left_range == le32_to_cpu(right->e_cpos));
797}
798
799static enum ocfs2_contig_type
741 ocfs2_extent_contig(struct inode *inode,
742 struct ocfs2_extent_rec *ext,
743 struct ocfs2_extent_rec *insert_rec)
800 ocfs2_extent_rec_contig(struct super_block *sb,
801 struct ocfs2_extent_rec *ext,
802 struct ocfs2_extent_rec *insert_rec)
744{
745 u64 blkno = le64_to_cpu(insert_rec->e_blkno);
746
747 /*
748 * Refuse to coalesce extent records with different flag
749 * fields - we don't want to mix unwritten extents with user
750 * data.
751 */
752 if (ext->e_flags != insert_rec->e_flags)
753 return CONTIG_NONE;
754
755 if (ocfs2_extents_adjacent(ext, insert_rec) &&
803{
804 u64 blkno = le64_to_cpu(insert_rec->e_blkno);
805
806 /*
807 * Refuse to coalesce extent records with different flag
808 * fields - we don't want to mix unwritten extents with user
809 * data.
810 */
811 if (ext->e_flags != insert_rec->e_flags)
812 return CONTIG_NONE;
813
814 if (ocfs2_extents_adjacent(ext, insert_rec) &&
756 ocfs2_block_extent_contig(inode->i_sb, ext, blkno))
815 ocfs2_block_extent_contig(sb, ext, blkno))
757 return CONTIG_RIGHT;
758
759 blkno = le64_to_cpu(ext->e_blkno);
760 if (ocfs2_extents_adjacent(insert_rec, ext) &&
816 return CONTIG_RIGHT;
817
818 blkno = le64_to_cpu(ext->e_blkno);
819 if (ocfs2_extents_adjacent(insert_rec, ext) &&
761 ocfs2_block_extent_contig(inode->i_sb, insert_rec, blkno))
820 ocfs2_block_extent_contig(sb, insert_rec, blkno))
762 return CONTIG_LEFT;
763
764 return CONTIG_NONE;
765}
766
767/*
768 * NOTE: We can have pretty much any combination of contiguousness and
769 * appending.

--- 78 unchanged lines hidden (view full) ---

848 (unsigned long long)bh->b_blocknr,
849 le32_to_cpu(eb->h_fs_generation));
850 return -EINVAL;
851 }
852
853 return 0;
854}
855
821 return CONTIG_LEFT;
822
823 return CONTIG_NONE;
824}
825
826/*
827 * NOTE: We can have pretty much any combination of contiguousness and
828 * appending.

--- 78 unchanged lines hidden (view full) ---

907 (unsigned long long)bh->b_blocknr,
908 le32_to_cpu(eb->h_fs_generation));
909 return -EINVAL;
910 }
911
912 return 0;
913}
914
856int ocfs2_read_extent_block(struct inode *inode, u64 eb_blkno,
915int ocfs2_read_extent_block(struct ocfs2_caching_info *ci, u64 eb_blkno,
857 struct buffer_head **bh)
858{
859 int rc;
860 struct buffer_head *tmp = *bh;
861
916 struct buffer_head **bh)
917{
918 int rc;
919 struct buffer_head *tmp = *bh;
920
862 rc = ocfs2_read_block(inode, eb_blkno, &tmp,
921 rc = ocfs2_read_block(ci, eb_blkno, &tmp,
863 ocfs2_validate_extent_block);
864
865 /* If ocfs2_read_block() got us a new bh, pass it up. */
866 if (!rc && !*bh)
867 *bh = tmp;
868
869 return rc;
870}
871
872
873/*
874 * How many free extents have we got before we need more meta data?
875 */
876int ocfs2_num_free_extents(struct ocfs2_super *osb,
922 ocfs2_validate_extent_block);
923
924 /* If ocfs2_read_block() got us a new bh, pass it up. */
925 if (!rc && !*bh)
926 *bh = tmp;
927
928 return rc;
929}
930
931
932/*
933 * How many free extents have we got before we need more meta data?
934 */
935int ocfs2_num_free_extents(struct ocfs2_super *osb,
877 struct inode *inode,
878 struct ocfs2_extent_tree *et)
879{
880 int retval;
881 struct ocfs2_extent_list *el = NULL;
882 struct ocfs2_extent_block *eb;
883 struct buffer_head *eb_bh = NULL;
884 u64 last_eb_blk = 0;
885
886 mlog_entry_void();
887
888 el = et->et_root_el;
889 last_eb_blk = ocfs2_et_get_last_eb_blk(et);
890
891 if (last_eb_blk) {
936 struct ocfs2_extent_tree *et)
937{
938 int retval;
939 struct ocfs2_extent_list *el = NULL;
940 struct ocfs2_extent_block *eb;
941 struct buffer_head *eb_bh = NULL;
942 u64 last_eb_blk = 0;
943
944 mlog_entry_void();
945
946 el = et->et_root_el;
947 last_eb_blk = ocfs2_et_get_last_eb_blk(et);
948
949 if (last_eb_blk) {
892 retval = ocfs2_read_extent_block(inode, last_eb_blk, &eb_bh);
950 retval = ocfs2_read_extent_block(et->et_ci, last_eb_blk,
951 &eb_bh);
893 if (retval < 0) {
894 mlog_errno(retval);
895 goto bail;
896 }
897 eb = (struct ocfs2_extent_block *) eb_bh->b_data;
898 el = &eb->h_list;
899 }
900

--- 7 unchanged lines hidden (view full) ---

908 return retval;
909}
910
911/* expects array to already be allocated
912 *
913 * sets h_signature, h_blkno, h_suballoc_bit, h_suballoc_slot, and
914 * l_count for you
915 */
952 if (retval < 0) {
953 mlog_errno(retval);
954 goto bail;
955 }
956 eb = (struct ocfs2_extent_block *) eb_bh->b_data;
957 el = &eb->h_list;
958 }
959

--- 7 unchanged lines hidden (view full) ---

967 return retval;
968}
969
970/* expects array to already be allocated
971 *
972 * sets h_signature, h_blkno, h_suballoc_bit, h_suballoc_slot, and
973 * l_count for you
974 */
916static int ocfs2_create_new_meta_bhs(struct ocfs2_super *osb,
917 handle_t *handle,
918 struct inode *inode,
975static int ocfs2_create_new_meta_bhs(handle_t *handle,
976 struct ocfs2_extent_tree *et,
919 int wanted,
920 struct ocfs2_alloc_context *meta_ac,
921 struct buffer_head *bhs[])
922{
923 int count, status, i;
924 u16 suballoc_bit_start;
925 u32 num_got;
926 u64 first_blkno;
977 int wanted,
978 struct ocfs2_alloc_context *meta_ac,
979 struct buffer_head *bhs[])
980{
981 int count, status, i;
982 u16 suballoc_bit_start;
983 u32 num_got;
984 u64 first_blkno;
985 struct ocfs2_super *osb =
986 OCFS2_SB(ocfs2_metadata_cache_get_super(et->et_ci));
927 struct ocfs2_extent_block *eb;
928
929 mlog_entry_void();
930
931 count = 0;
932 while (count < wanted) {
933 status = ocfs2_claim_metadata(osb,
934 handle,

--- 9 unchanged lines hidden (view full) ---

944
945 for(i = count; i < (num_got + count); i++) {
946 bhs[i] = sb_getblk(osb->sb, first_blkno);
947 if (bhs[i] == NULL) {
948 status = -EIO;
949 mlog_errno(status);
950 goto bail;
951 }
987 struct ocfs2_extent_block *eb;
988
989 mlog_entry_void();
990
991 count = 0;
992 while (count < wanted) {
993 status = ocfs2_claim_metadata(osb,
994 handle,

--- 9 unchanged lines hidden (view full) ---

1004
1005 for(i = count; i < (num_got + count); i++) {
1006 bhs[i] = sb_getblk(osb->sb, first_blkno);
1007 if (bhs[i] == NULL) {
1008 status = -EIO;
1009 mlog_errno(status);
1010 goto bail;
1011 }
952 ocfs2_set_new_buffer_uptodate(inode, bhs[i]);
1012 ocfs2_set_new_buffer_uptodate(et->et_ci, bhs[i]);
953
1013
954 status = ocfs2_journal_access_eb(handle, inode, bhs[i],
1014 status = ocfs2_journal_access_eb(handle, et->et_ci,
1015 bhs[i],
955 OCFS2_JOURNAL_ACCESS_CREATE);
956 if (status < 0) {
957 mlog_errno(status);
958 goto bail;
959 }
960
961 memset(bhs[i]->b_data, 0, osb->sb->s_blocksize);
962 eb = (struct ocfs2_extent_block *) bhs[i]->b_data;

--- 55 unchanged lines hidden (view full) ---

1018 ocfs2_rec_clusters(el, &el->l_recs[i]);
1019}
1020
1021/*
1022 * Change range of the branches in the right most path according to the leaf
1023 * extent block's rightmost record.
1024 */
1025static int ocfs2_adjust_rightmost_branch(handle_t *handle,
1016 OCFS2_JOURNAL_ACCESS_CREATE);
1017 if (status < 0) {
1018 mlog_errno(status);
1019 goto bail;
1020 }
1021
1022 memset(bhs[i]->b_data, 0, osb->sb->s_blocksize);
1023 eb = (struct ocfs2_extent_block *) bhs[i]->b_data;

--- 55 unchanged lines hidden (view full) ---

1079 ocfs2_rec_clusters(el, &el->l_recs[i]);
1080}
1081
1082/*
1083 * Change range of the branches in the right most path according to the leaf
1084 * extent block's rightmost record.
1085 */
1086static int ocfs2_adjust_rightmost_branch(handle_t *handle,
1026 struct inode *inode,
1027 struct ocfs2_extent_tree *et)
1028{
1029 int status;
1030 struct ocfs2_path *path = NULL;
1031 struct ocfs2_extent_list *el;
1032 struct ocfs2_extent_rec *rec;
1033
1034 path = ocfs2_new_path_from_et(et);
1035 if (!path) {
1036 status = -ENOMEM;
1037 return status;
1038 }
1039
1087 struct ocfs2_extent_tree *et)
1088{
1089 int status;
1090 struct ocfs2_path *path = NULL;
1091 struct ocfs2_extent_list *el;
1092 struct ocfs2_extent_rec *rec;
1093
1094 path = ocfs2_new_path_from_et(et);
1095 if (!path) {
1096 status = -ENOMEM;
1097 return status;
1098 }
1099
1040 status = ocfs2_find_path(inode, path, UINT_MAX);
1100 status = ocfs2_find_path(et->et_ci, path, UINT_MAX);
1041 if (status < 0) {
1042 mlog_errno(status);
1043 goto out;
1044 }
1045
1046 status = ocfs2_extend_trans(handle, path_num_items(path) +
1047 handle->h_buffer_credits);
1048 if (status < 0) {
1049 mlog_errno(status);
1050 goto out;
1051 }
1052
1101 if (status < 0) {
1102 mlog_errno(status);
1103 goto out;
1104 }
1105
1106 status = ocfs2_extend_trans(handle, path_num_items(path) +
1107 handle->h_buffer_credits);
1108 if (status < 0) {
1109 mlog_errno(status);
1110 goto out;
1111 }
1112
1053 status = ocfs2_journal_access_path(inode, handle, path);
1113 status = ocfs2_journal_access_path(et->et_ci, handle, path);
1054 if (status < 0) {
1055 mlog_errno(status);
1056 goto out;
1057 }
1058
1059 el = path_leaf_el(path);
1060 rec = &el->l_recs[le32_to_cpu(el->l_next_free_rec) - 1];
1061
1114 if (status < 0) {
1115 mlog_errno(status);
1116 goto out;
1117 }
1118
1119 el = path_leaf_el(path);
1120 rec = &el->l_recs[le32_to_cpu(el->l_next_free_rec) - 1];
1121
1062 ocfs2_adjust_rightmost_records(inode, handle, path, rec);
1122 ocfs2_adjust_rightmost_records(handle, et, path, rec);
1063
1064out:
1065 ocfs2_free_path(path);
1066 return status;
1067}
1068
1069/*
1070 * Add an entire tree branch to our inode. eb_bh is the extent block
1123
1124out:
1125 ocfs2_free_path(path);
1126 return status;
1127}
1128
1129/*
1130 * Add an entire tree branch to our inode. eb_bh is the extent block
1071 * to start at, if we don't want to start the branch at the dinode
1131 * to start at, if we don't want to start the branch at the root
1072 * structure.
1073 *
1074 * last_eb_bh is required as we have to update it's next_leaf pointer
1075 * for the new last extent block.
1076 *
1077 * the new branch will be 'empty' in the sense that every block will
1078 * contain a single record with cluster count == 0.
1079 */
1132 * structure.
1133 *
1134 * last_eb_bh is required as we have to update it's next_leaf pointer
1135 * for the new last extent block.
1136 *
1137 * the new branch will be 'empty' in the sense that every block will
1138 * contain a single record with cluster count == 0.
1139 */
1080static int ocfs2_add_branch(struct ocfs2_super *osb,
1081 handle_t *handle,
1082 struct inode *inode,
1140static int ocfs2_add_branch(handle_t *handle,
1083 struct ocfs2_extent_tree *et,
1084 struct buffer_head *eb_bh,
1085 struct buffer_head **last_eb_bh,
1086 struct ocfs2_alloc_context *meta_ac)
1087{
1088 int status, new_blocks, i;
1089 u64 next_blkno, new_last_eb_blk;
1090 struct buffer_head *bh;

--- 27 unchanged lines hidden (view full) ---

1118 * of the righmost leaf block, we need to remove the gap
1119 * between new_cpos and root_end first so that the tree
1120 * is consistent after we add a new branch(it will start
1121 * from new_cpos).
1122 */
1123 if (root_end > new_cpos) {
1124 mlog(0, "adjust the cluster end from %u to %u\n",
1125 root_end, new_cpos);
1141 struct ocfs2_extent_tree *et,
1142 struct buffer_head *eb_bh,
1143 struct buffer_head **last_eb_bh,
1144 struct ocfs2_alloc_context *meta_ac)
1145{
1146 int status, new_blocks, i;
1147 u64 next_blkno, new_last_eb_blk;
1148 struct buffer_head *bh;

--- 27 unchanged lines hidden (view full) ---

1176 * of the righmost leaf block, we need to remove the gap
1177 * between new_cpos and root_end first so that the tree
1178 * is consistent after we add a new branch(it will start
1179 * from new_cpos).
1180 */
1181 if (root_end > new_cpos) {
1182 mlog(0, "adjust the cluster end from %u to %u\n",
1183 root_end, new_cpos);
1126 status = ocfs2_adjust_rightmost_branch(handle, inode, et);
1184 status = ocfs2_adjust_rightmost_branch(handle, et);
1127 if (status) {
1128 mlog_errno(status);
1129 goto bail;
1130 }
1131 }
1132
1133 /* allocate the number of new eb blocks we need */
1134 new_eb_bhs = kcalloc(new_blocks, sizeof(struct buffer_head *),
1135 GFP_KERNEL);
1136 if (!new_eb_bhs) {
1137 status = -ENOMEM;
1138 mlog_errno(status);
1139 goto bail;
1140 }
1141
1185 if (status) {
1186 mlog_errno(status);
1187 goto bail;
1188 }
1189 }
1190
1191 /* allocate the number of new eb blocks we need */
1192 new_eb_bhs = kcalloc(new_blocks, sizeof(struct buffer_head *),
1193 GFP_KERNEL);
1194 if (!new_eb_bhs) {
1195 status = -ENOMEM;
1196 mlog_errno(status);
1197 goto bail;
1198 }
1199
1142 status = ocfs2_create_new_meta_bhs(osb, handle, inode, new_blocks,
1200 status = ocfs2_create_new_meta_bhs(handle, et, new_blocks,
1143 meta_ac, new_eb_bhs);
1144 if (status < 0) {
1145 mlog_errno(status);
1146 goto bail;
1147 }
1148
1149 /* Note: new_eb_bhs[new_blocks - 1] is the guy which will be
1150 * linked with the rest of the tree.

--- 5 unchanged lines hidden (view full) ---

1156 next_blkno = new_last_eb_blk = 0;
1157 for(i = 0; i < new_blocks; i++) {
1158 bh = new_eb_bhs[i];
1159 eb = (struct ocfs2_extent_block *) bh->b_data;
1160 /* ocfs2_create_new_meta_bhs() should create it right! */
1161 BUG_ON(!OCFS2_IS_VALID_EXTENT_BLOCK(eb));
1162 eb_el = &eb->h_list;
1163
1201 meta_ac, new_eb_bhs);
1202 if (status < 0) {
1203 mlog_errno(status);
1204 goto bail;
1205 }
1206
1207 /* Note: new_eb_bhs[new_blocks - 1] is the guy which will be
1208 * linked with the rest of the tree.

--- 5 unchanged lines hidden (view full) ---

1214 next_blkno = new_last_eb_blk = 0;
1215 for(i = 0; i < new_blocks; i++) {
1216 bh = new_eb_bhs[i];
1217 eb = (struct ocfs2_extent_block *) bh->b_data;
1218 /* ocfs2_create_new_meta_bhs() should create it right! */
1219 BUG_ON(!OCFS2_IS_VALID_EXTENT_BLOCK(eb));
1220 eb_el = &eb->h_list;
1221
1164 status = ocfs2_journal_access_eb(handle, inode, bh,
1222 status = ocfs2_journal_access_eb(handle, et->et_ci, bh,
1165 OCFS2_JOURNAL_ACCESS_CREATE);
1166 if (status < 0) {
1167 mlog_errno(status);
1168 goto bail;
1169 }
1170
1171 eb->h_next_leaf_blk = 0;
1172 eb_el->l_tree_depth = cpu_to_le16(i);

--- 23 unchanged lines hidden (view full) ---

1196 }
1197
1198 /* This is a bit hairy. We want to update up to three blocks
1199 * here without leaving any of them in an inconsistent state
1200 * in case of error. We don't have to worry about
1201 * journal_dirty erroring as it won't unless we've aborted the
1202 * handle (in which case we would never be here) so reserving
1203 * the write with journal_access is all we need to do. */
1223 OCFS2_JOURNAL_ACCESS_CREATE);
1224 if (status < 0) {
1225 mlog_errno(status);
1226 goto bail;
1227 }
1228
1229 eb->h_next_leaf_blk = 0;
1230 eb_el->l_tree_depth = cpu_to_le16(i);

--- 23 unchanged lines hidden (view full) ---

1254 }
1255
1256 /* This is a bit hairy. We want to update up to three blocks
1257 * here without leaving any of them in an inconsistent state
1258 * in case of error. We don't have to worry about
1259 * journal_dirty erroring as it won't unless we've aborted the
1260 * handle (in which case we would never be here) so reserving
1261 * the write with journal_access is all we need to do. */
1204 status = ocfs2_journal_access_eb(handle, inode, *last_eb_bh,
1262 status = ocfs2_journal_access_eb(handle, et->et_ci, *last_eb_bh,
1205 OCFS2_JOURNAL_ACCESS_WRITE);
1206 if (status < 0) {
1207 mlog_errno(status);
1208 goto bail;
1209 }
1263 OCFS2_JOURNAL_ACCESS_WRITE);
1264 if (status < 0) {
1265 mlog_errno(status);
1266 goto bail;
1267 }
1210 status = ocfs2_et_root_journal_access(handle, inode, et,
1268 status = ocfs2_et_root_journal_access(handle, et,
1211 OCFS2_JOURNAL_ACCESS_WRITE);
1212 if (status < 0) {
1213 mlog_errno(status);
1214 goto bail;
1215 }
1216 if (eb_bh) {
1269 OCFS2_JOURNAL_ACCESS_WRITE);
1270 if (status < 0) {
1271 mlog_errno(status);
1272 goto bail;
1273 }
1274 if (eb_bh) {
1217 status = ocfs2_journal_access_eb(handle, inode, eb_bh,
1275 status = ocfs2_journal_access_eb(handle, et->et_ci, eb_bh,
1218 OCFS2_JOURNAL_ACCESS_WRITE);
1219 if (status < 0) {
1220 mlog_errno(status);
1221 goto bail;
1222 }
1223 }
1224
1225 /* Link the new branch into the rest of the tree (el will

--- 43 unchanged lines hidden (view full) ---

1269 return status;
1270}
1271
1272/*
1273 * adds another level to the allocation tree.
1274 * returns back the new extent block so you can add a branch to it
1275 * after this call.
1276 */
1276 OCFS2_JOURNAL_ACCESS_WRITE);
1277 if (status < 0) {
1278 mlog_errno(status);
1279 goto bail;
1280 }
1281 }
1282
1283 /* Link the new branch into the rest of the tree (el will

--- 43 unchanged lines hidden (view full) ---

1327 return status;
1328}
1329
1330/*
1331 * adds another level to the allocation tree.
1332 * returns back the new extent block so you can add a branch to it
1333 * after this call.
1334 */
1277static int ocfs2_shift_tree_depth(struct ocfs2_super *osb,
1278 handle_t *handle,
1279 struct inode *inode,
1335static int ocfs2_shift_tree_depth(handle_t *handle,
1280 struct ocfs2_extent_tree *et,
1281 struct ocfs2_alloc_context *meta_ac,
1282 struct buffer_head **ret_new_eb_bh)
1283{
1284 int status, i;
1285 u32 new_clusters;
1286 struct buffer_head *new_eb_bh = NULL;
1287 struct ocfs2_extent_block *eb;
1288 struct ocfs2_extent_list *root_el;
1289 struct ocfs2_extent_list *eb_el;
1290
1291 mlog_entry_void();
1292
1336 struct ocfs2_extent_tree *et,
1337 struct ocfs2_alloc_context *meta_ac,
1338 struct buffer_head **ret_new_eb_bh)
1339{
1340 int status, i;
1341 u32 new_clusters;
1342 struct buffer_head *new_eb_bh = NULL;
1343 struct ocfs2_extent_block *eb;
1344 struct ocfs2_extent_list *root_el;
1345 struct ocfs2_extent_list *eb_el;
1346
1347 mlog_entry_void();
1348
1293 status = ocfs2_create_new_meta_bhs(osb, handle, inode, 1, meta_ac,
1349 status = ocfs2_create_new_meta_bhs(handle, et, 1, meta_ac,
1294 &new_eb_bh);
1295 if (status < 0) {
1296 mlog_errno(status);
1297 goto bail;
1298 }
1299
1300 eb = (struct ocfs2_extent_block *) new_eb_bh->b_data;
1301 /* ocfs2_create_new_meta_bhs() should create it right! */
1302 BUG_ON(!OCFS2_IS_VALID_EXTENT_BLOCK(eb));
1303
1304 eb_el = &eb->h_list;
1305 root_el = et->et_root_el;
1306
1350 &new_eb_bh);
1351 if (status < 0) {
1352 mlog_errno(status);
1353 goto bail;
1354 }
1355
1356 eb = (struct ocfs2_extent_block *) new_eb_bh->b_data;
1357 /* ocfs2_create_new_meta_bhs() should create it right! */
1358 BUG_ON(!OCFS2_IS_VALID_EXTENT_BLOCK(eb));
1359
1360 eb_el = &eb->h_list;
1361 root_el = et->et_root_el;
1362
1307 status = ocfs2_journal_access_eb(handle, inode, new_eb_bh,
1363 status = ocfs2_journal_access_eb(handle, et->et_ci, new_eb_bh,
1308 OCFS2_JOURNAL_ACCESS_CREATE);
1309 if (status < 0) {
1310 mlog_errno(status);
1311 goto bail;
1312 }
1313
1314 /* copy the root extent list data into the new extent block */
1315 eb_el->l_tree_depth = root_el->l_tree_depth;
1316 eb_el->l_next_free_rec = root_el->l_next_free_rec;
1317 for (i = 0; i < le16_to_cpu(root_el->l_next_free_rec); i++)
1318 eb_el->l_recs[i] = root_el->l_recs[i];
1319
1320 status = ocfs2_journal_dirty(handle, new_eb_bh);
1321 if (status < 0) {
1322 mlog_errno(status);
1323 goto bail;
1324 }
1325
1364 OCFS2_JOURNAL_ACCESS_CREATE);
1365 if (status < 0) {
1366 mlog_errno(status);
1367 goto bail;
1368 }
1369
1370 /* copy the root extent list data into the new extent block */
1371 eb_el->l_tree_depth = root_el->l_tree_depth;
1372 eb_el->l_next_free_rec = root_el->l_next_free_rec;
1373 for (i = 0; i < le16_to_cpu(root_el->l_next_free_rec); i++)
1374 eb_el->l_recs[i] = root_el->l_recs[i];
1375
1376 status = ocfs2_journal_dirty(handle, new_eb_bh);
1377 if (status < 0) {
1378 mlog_errno(status);
1379 goto bail;
1380 }
1381
1326 status = ocfs2_et_root_journal_access(handle, inode, et,
1382 status = ocfs2_et_root_journal_access(handle, et,
1327 OCFS2_JOURNAL_ACCESS_WRITE);
1328 if (status < 0) {
1329 mlog_errno(status);
1330 goto bail;
1331 }
1332
1333 new_clusters = ocfs2_sum_rightmost_rec(eb_el);
1334

--- 39 unchanged lines hidden (view full) ---

1374 * 2) the search fails to find anything, but the root_el has room. We
1375 * pass NULL back in *lowest_eb_bh, but still return '0'
1376 *
1377 * 3) the search fails to find anything AND the root_el is full, in
1378 * which case we return > 0
1379 *
1380 * return status < 0 indicates an error.
1381 */
1383 OCFS2_JOURNAL_ACCESS_WRITE);
1384 if (status < 0) {
1385 mlog_errno(status);
1386 goto bail;
1387 }
1388
1389 new_clusters = ocfs2_sum_rightmost_rec(eb_el);
1390

--- 39 unchanged lines hidden (view full) ---

1430 * 2) the search fails to find anything, but the root_el has room. We
1431 * pass NULL back in *lowest_eb_bh, but still return '0'
1432 *
1433 * 3) the search fails to find anything AND the root_el is full, in
1434 * which case we return > 0
1435 *
1436 * return status < 0 indicates an error.
1437 */
1382static int ocfs2_find_branch_target(struct ocfs2_super *osb,
1383 struct inode *inode,
1384 struct ocfs2_extent_tree *et,
1438static int ocfs2_find_branch_target(struct ocfs2_extent_tree *et,
1385 struct buffer_head **target_bh)
1386{
1387 int status = 0, i;
1388 u64 blkno;
1389 struct ocfs2_extent_block *eb;
1390 struct ocfs2_extent_list *el;
1391 struct buffer_head *bh = NULL;
1392 struct buffer_head *lowest_bh = NULL;
1393
1394 mlog_entry_void();
1395
1396 *target_bh = NULL;
1397
1398 el = et->et_root_el;
1399
1400 while(le16_to_cpu(el->l_tree_depth) > 1) {
1401 if (le16_to_cpu(el->l_next_free_rec) == 0) {
1439 struct buffer_head **target_bh)
1440{
1441 int status = 0, i;
1442 u64 blkno;
1443 struct ocfs2_extent_block *eb;
1444 struct ocfs2_extent_list *el;
1445 struct buffer_head *bh = NULL;
1446 struct buffer_head *lowest_bh = NULL;
1447
1448 mlog_entry_void();
1449
1450 *target_bh = NULL;
1451
1452 el = et->et_root_el;
1453
1454 while(le16_to_cpu(el->l_tree_depth) > 1) {
1455 if (le16_to_cpu(el->l_next_free_rec) == 0) {
1402 ocfs2_error(inode->i_sb, "Dinode %llu has empty "
1456 ocfs2_error(ocfs2_metadata_cache_get_super(et->et_ci),
1457 "Owner %llu has empty "
1403 "extent list (next_free_rec == 0)",
1458 "extent list (next_free_rec == 0)",
1404 (unsigned long long)OCFS2_I(inode)->ip_blkno);
1459 (unsigned long long)ocfs2_metadata_cache_owner(et->et_ci));
1405 status = -EIO;
1406 goto bail;
1407 }
1408 i = le16_to_cpu(el->l_next_free_rec) - 1;
1409 blkno = le64_to_cpu(el->l_recs[i].e_blkno);
1410 if (!blkno) {
1460 status = -EIO;
1461 goto bail;
1462 }
1463 i = le16_to_cpu(el->l_next_free_rec) - 1;
1464 blkno = le64_to_cpu(el->l_recs[i].e_blkno);
1465 if (!blkno) {
1411 ocfs2_error(inode->i_sb, "Dinode %llu has extent "
1466 ocfs2_error(ocfs2_metadata_cache_get_super(et->et_ci),
1467 "Owner %llu has extent "
1412 "list where extent # %d has no physical "
1413 "block start",
1468 "list where extent # %d has no physical "
1469 "block start",
1414 (unsigned long long)OCFS2_I(inode)->ip_blkno, i);
1470 (unsigned long long)ocfs2_metadata_cache_owner(et->et_ci), i);
1415 status = -EIO;
1416 goto bail;
1417 }
1418
1419 brelse(bh);
1420 bh = NULL;
1421
1471 status = -EIO;
1472 goto bail;
1473 }
1474
1475 brelse(bh);
1476 bh = NULL;
1477
1422 status = ocfs2_read_extent_block(inode, blkno, &bh);
1478 status = ocfs2_read_extent_block(et->et_ci, blkno, &bh);
1423 if (status < 0) {
1424 mlog_errno(status);
1425 goto bail;
1426 }
1427
1428 eb = (struct ocfs2_extent_block *) bh->b_data;
1429 el = &eb->h_list;
1430

--- 24 unchanged lines hidden (view full) ---

1455 *
1456 * We might shift the tree depth in which case existing paths should
1457 * be considered invalid.
1458 *
1459 * Tree depth after the grow is returned via *final_depth.
1460 *
1461 * *last_eb_bh will be updated by ocfs2_add_branch().
1462 */
1479 if (status < 0) {
1480 mlog_errno(status);
1481 goto bail;
1482 }
1483
1484 eb = (struct ocfs2_extent_block *) bh->b_data;
1485 el = &eb->h_list;
1486

--- 24 unchanged lines hidden (view full) ---

1511 *
1512 * We might shift the tree depth in which case existing paths should
1513 * be considered invalid.
1514 *
1515 * Tree depth after the grow is returned via *final_depth.
1516 *
1517 * *last_eb_bh will be updated by ocfs2_add_branch().
1518 */
1463static int ocfs2_grow_tree(struct inode *inode, handle_t *handle,
1464 struct ocfs2_extent_tree *et, int *final_depth,
1465 struct buffer_head **last_eb_bh,
1519static int ocfs2_grow_tree(handle_t *handle, struct ocfs2_extent_tree *et,
1520 int *final_depth, struct buffer_head **last_eb_bh,
1466 struct ocfs2_alloc_context *meta_ac)
1467{
1468 int ret, shift;
1469 struct ocfs2_extent_list *el = et->et_root_el;
1470 int depth = le16_to_cpu(el->l_tree_depth);
1521 struct ocfs2_alloc_context *meta_ac)
1522{
1523 int ret, shift;
1524 struct ocfs2_extent_list *el = et->et_root_el;
1525 int depth = le16_to_cpu(el->l_tree_depth);
1471 struct ocfs2_super *osb = OCFS2_SB(inode->i_sb);
1472 struct buffer_head *bh = NULL;
1473
1474 BUG_ON(meta_ac == NULL);
1475
1526 struct buffer_head *bh = NULL;
1527
1528 BUG_ON(meta_ac == NULL);
1529
1476 shift = ocfs2_find_branch_target(osb, inode, et, &bh);
1530 shift = ocfs2_find_branch_target(et, &bh);
1477 if (shift < 0) {
1478 ret = shift;
1479 mlog_errno(ret);
1480 goto out;
1481 }
1482
1483 /* We traveled all the way to the bottom of the allocation tree
1484 * and didn't find room for any more extents - we need to add
1485 * another tree level */
1486 if (shift) {
1487 BUG_ON(bh);
1488 mlog(0, "need to shift tree depth (current = %d)\n", depth);
1489
1490 /* ocfs2_shift_tree_depth will return us a buffer with
1491 * the new extent block (so we can pass that to
1492 * ocfs2_add_branch). */
1531 if (shift < 0) {
1532 ret = shift;
1533 mlog_errno(ret);
1534 goto out;
1535 }
1536
1537 /* We traveled all the way to the bottom of the allocation tree
1538 * and didn't find room for any more extents - we need to add
1539 * another tree level */
1540 if (shift) {
1541 BUG_ON(bh);
1542 mlog(0, "need to shift tree depth (current = %d)\n", depth);
1543
1544 /* ocfs2_shift_tree_depth will return us a buffer with
1545 * the new extent block (so we can pass that to
1546 * ocfs2_add_branch). */
1493 ret = ocfs2_shift_tree_depth(osb, handle, inode, et,
1494 meta_ac, &bh);
1547 ret = ocfs2_shift_tree_depth(handle, et, meta_ac, &bh);
1495 if (ret < 0) {
1496 mlog_errno(ret);
1497 goto out;
1498 }
1499 depth++;
1500 if (depth == 1) {
1501 /*
1502 * Special case: we have room now if we shifted from

--- 9 unchanged lines hidden (view full) ---

1512 *last_eb_bh = bh;
1513 goto out;
1514 }
1515 }
1516
1517 /* call ocfs2_add_branch to add the final part of the tree with
1518 * the new data. */
1519 mlog(0, "add branch. bh = %p\n", bh);
1548 if (ret < 0) {
1549 mlog_errno(ret);
1550 goto out;
1551 }
1552 depth++;
1553 if (depth == 1) {
1554 /*
1555 * Special case: we have room now if we shifted from

--- 9 unchanged lines hidden (view full) ---

1565 *last_eb_bh = bh;
1566 goto out;
1567 }
1568 }
1569
1570 /* call ocfs2_add_branch to add the final part of the tree with
1571 * the new data. */
1572 mlog(0, "add branch. bh = %p\n", bh);
1520 ret = ocfs2_add_branch(osb, handle, inode, et, bh, last_eb_bh,
1573 ret = ocfs2_add_branch(handle, et, bh, last_eb_bh,
1521 meta_ac);
1522 if (ret < 0) {
1523 mlog_errno(ret);
1524 goto out;
1525 }
1526
1527out:
1528 if (final_depth)

--- 153 unchanged lines hidden (view full) ---

1682 *
1683 * This function is passed two full paths from the dinode down to a
1684 * pair of adjacent leaves. It's task is to figure out which path
1685 * index contains the subtree root - this can be the root index itself
1686 * in a worst-case rotation.
1687 *
1688 * The array index of the subtree root is passed back.
1689 */
1574 meta_ac);
1575 if (ret < 0) {
1576 mlog_errno(ret);
1577 goto out;
1578 }
1579
1580out:
1581 if (final_depth)

--- 153 unchanged lines hidden (view full) ---

1735 *
1736 * This function is passed two full paths from the dinode down to a
1737 * pair of adjacent leaves. It's task is to figure out which path
1738 * index contains the subtree root - this can be the root index itself
1739 * in a worst-case rotation.
1740 *
1741 * The array index of the subtree root is passed back.
1742 */
1690static int ocfs2_find_subtree_root(struct inode *inode,
1743static int ocfs2_find_subtree_root(struct ocfs2_extent_tree *et,
1691 struct ocfs2_path *left,
1692 struct ocfs2_path *right)
1693{
1694 int i = 0;
1695
1696 /*
1697 * Check that the caller passed in two paths from the same tree.
1698 */
1699 BUG_ON(path_root_bh(left) != path_root_bh(right));
1700
1701 do {
1702 i++;
1703
1704 /*
1705 * The caller didn't pass two adjacent paths.
1706 */
1707 mlog_bug_on_msg(i > left->p_tree_depth,
1744 struct ocfs2_path *left,
1745 struct ocfs2_path *right)
1746{
1747 int i = 0;
1748
1749 /*
1750 * Check that the caller passed in two paths from the same tree.
1751 */
1752 BUG_ON(path_root_bh(left) != path_root_bh(right));
1753
1754 do {
1755 i++;
1756
1757 /*
1758 * The caller didn't pass two adjacent paths.
1759 */
1760 mlog_bug_on_msg(i > left->p_tree_depth,
1708 "Inode %lu, left depth %u, right depth %u\n"
1761 "Owner %llu, left depth %u, right depth %u\n"
1709 "left leaf blk %llu, right leaf blk %llu\n",
1762 "left leaf blk %llu, right leaf blk %llu\n",
1710 inode->i_ino, left->p_tree_depth,
1711 right->p_tree_depth,
1763 (unsigned long long)ocfs2_metadata_cache_owner(et->et_ci),
1764 left->p_tree_depth, right->p_tree_depth,
1712 (unsigned long long)path_leaf_bh(left)->b_blocknr,
1713 (unsigned long long)path_leaf_bh(right)->b_blocknr);
1714 } while (left->p_node[i].bh->b_blocknr ==
1715 right->p_node[i].bh->b_blocknr);
1716
1717 return i - 1;
1718}
1719
1720typedef void (path_insert_t)(void *, struct buffer_head *);
1721
1722/*
1723 * Traverse a btree path in search of cpos, starting at root_el.
1724 *
1725 * This code can be called with a cpos larger than the tree, in which
1726 * case it will return the rightmost path.
1727 */
1765 (unsigned long long)path_leaf_bh(left)->b_blocknr,
1766 (unsigned long long)path_leaf_bh(right)->b_blocknr);
1767 } while (left->p_node[i].bh->b_blocknr ==
1768 right->p_node[i].bh->b_blocknr);
1769
1770 return i - 1;
1771}
1772
1773typedef void (path_insert_t)(void *, struct buffer_head *);
1774
1775/*
1776 * Traverse a btree path in search of cpos, starting at root_el.
1777 *
1778 * This code can be called with a cpos larger than the tree, in which
1779 * case it will return the rightmost path.
1780 */
1728static int __ocfs2_find_path(struct inode *inode,
1781static int __ocfs2_find_path(struct ocfs2_caching_info *ci,
1729 struct ocfs2_extent_list *root_el, u32 cpos,
1730 path_insert_t *func, void *data)
1731{
1732 int i, ret = 0;
1733 u32 range;
1734 u64 blkno;
1735 struct buffer_head *bh = NULL;
1736 struct ocfs2_extent_block *eb;
1737 struct ocfs2_extent_list *el;
1738 struct ocfs2_extent_rec *rec;
1782 struct ocfs2_extent_list *root_el, u32 cpos,
1783 path_insert_t *func, void *data)
1784{
1785 int i, ret = 0;
1786 u32 range;
1787 u64 blkno;
1788 struct buffer_head *bh = NULL;
1789 struct ocfs2_extent_block *eb;
1790 struct ocfs2_extent_list *el;
1791 struct ocfs2_extent_rec *rec;
1739 struct ocfs2_inode_info *oi = OCFS2_I(inode);
1740
1741 el = root_el;
1742 while (el->l_tree_depth) {
1743 if (le16_to_cpu(el->l_next_free_rec) == 0) {
1792
1793 el = root_el;
1794 while (el->l_tree_depth) {
1795 if (le16_to_cpu(el->l_next_free_rec) == 0) {
1744 ocfs2_error(inode->i_sb,
1745 "Inode %llu has empty extent list at "
1796 ocfs2_error(ocfs2_metadata_cache_get_super(ci),
1797 "Owner %llu has empty extent list at "
1746 "depth %u\n",
1798 "depth %u\n",
1747 (unsigned long long)oi->ip_blkno,
1799 (unsigned long long)ocfs2_metadata_cache_owner(ci),
1748 le16_to_cpu(el->l_tree_depth));
1749 ret = -EROFS;
1750 goto out;
1751
1752 }
1753
1754 for(i = 0; i < le16_to_cpu(el->l_next_free_rec) - 1; i++) {
1755 rec = &el->l_recs[i];

--- 6 unchanged lines hidden (view full) ---

1762 range = le32_to_cpu(rec->e_cpos) +
1763 ocfs2_rec_clusters(el, rec);
1764 if (cpos >= le32_to_cpu(rec->e_cpos) && cpos < range)
1765 break;
1766 }
1767
1768 blkno = le64_to_cpu(el->l_recs[i].e_blkno);
1769 if (blkno == 0) {
1800 le16_to_cpu(el->l_tree_depth));
1801 ret = -EROFS;
1802 goto out;
1803
1804 }
1805
1806 for(i = 0; i < le16_to_cpu(el->l_next_free_rec) - 1; i++) {
1807 rec = &el->l_recs[i];

--- 6 unchanged lines hidden (view full) ---

1814 range = le32_to_cpu(rec->e_cpos) +
1815 ocfs2_rec_clusters(el, rec);
1816 if (cpos >= le32_to_cpu(rec->e_cpos) && cpos < range)
1817 break;
1818 }
1819
1820 blkno = le64_to_cpu(el->l_recs[i].e_blkno);
1821 if (blkno == 0) {
1770 ocfs2_error(inode->i_sb,
1771 "Inode %llu has bad blkno in extent list "
1822 ocfs2_error(ocfs2_metadata_cache_get_super(ci),
1823 "Owner %llu has bad blkno in extent list "
1772 "at depth %u (index %d)\n",
1824 "at depth %u (index %d)\n",
1773 (unsigned long long)oi->ip_blkno,
1825 (unsigned long long)ocfs2_metadata_cache_owner(ci),
1774 le16_to_cpu(el->l_tree_depth), i);
1775 ret = -EROFS;
1776 goto out;
1777 }
1778
1779 brelse(bh);
1780 bh = NULL;
1826 le16_to_cpu(el->l_tree_depth), i);
1827 ret = -EROFS;
1828 goto out;
1829 }
1830
1831 brelse(bh);
1832 bh = NULL;
1781 ret = ocfs2_read_extent_block(inode, blkno, &bh);
1833 ret = ocfs2_read_extent_block(ci, blkno, &bh);
1782 if (ret) {
1783 mlog_errno(ret);
1784 goto out;
1785 }
1786
1787 eb = (struct ocfs2_extent_block *) bh->b_data;
1788 el = &eb->h_list;
1789
1790 if (le16_to_cpu(el->l_next_free_rec) >
1791 le16_to_cpu(el->l_count)) {
1834 if (ret) {
1835 mlog_errno(ret);
1836 goto out;
1837 }
1838
1839 eb = (struct ocfs2_extent_block *) bh->b_data;
1840 el = &eb->h_list;
1841
1842 if (le16_to_cpu(el->l_next_free_rec) >
1843 le16_to_cpu(el->l_count)) {
1792 ocfs2_error(inode->i_sb,
1793 "Inode %llu has bad count in extent list "
1844 ocfs2_error(ocfs2_metadata_cache_get_super(ci),
1845 "Owner %llu has bad count in extent list "
1794 "at block %llu (next free=%u, count=%u)\n",
1846 "at block %llu (next free=%u, count=%u)\n",
1795 (unsigned long long)oi->ip_blkno,
1847 (unsigned long long)ocfs2_metadata_cache_owner(ci),
1796 (unsigned long long)bh->b_blocknr,
1797 le16_to_cpu(el->l_next_free_rec),
1798 le16_to_cpu(el->l_count));
1799 ret = -EROFS;
1800 goto out;
1801 }
1802
1803 if (func)

--- 27 unchanged lines hidden (view full) ---

1831static void find_path_ins(void *data, struct buffer_head *bh)
1832{
1833 struct find_path_data *fp = data;
1834
1835 get_bh(bh);
1836 ocfs2_path_insert_eb(fp->path, fp->index, bh);
1837 fp->index++;
1838}
1848 (unsigned long long)bh->b_blocknr,
1849 le16_to_cpu(el->l_next_free_rec),
1850 le16_to_cpu(el->l_count));
1851 ret = -EROFS;
1852 goto out;
1853 }
1854
1855 if (func)

--- 27 unchanged lines hidden (view full) ---

1883static void find_path_ins(void *data, struct buffer_head *bh)
1884{
1885 struct find_path_data *fp = data;
1886
1887 get_bh(bh);
1888 ocfs2_path_insert_eb(fp->path, fp->index, bh);
1889 fp->index++;
1890}
1839static int ocfs2_find_path(struct inode *inode, struct ocfs2_path *path,
1840 u32 cpos)
1891static int ocfs2_find_path(struct ocfs2_caching_info *ci,
1892 struct ocfs2_path *path, u32 cpos)
1841{
1842 struct find_path_data data;
1843
1844 data.index = 1;
1845 data.path = path;
1893{
1894 struct find_path_data data;
1895
1896 data.index = 1;
1897 data.path = path;
1846 return __ocfs2_find_path(inode, path_root_el(path), cpos,
1898 return __ocfs2_find_path(ci, path_root_el(path), cpos,
1847 find_path_ins, &data);
1848}
1849
1850static void find_leaf_ins(void *data, struct buffer_head *bh)
1851{
1852 struct ocfs2_extent_block *eb =(struct ocfs2_extent_block *)bh->b_data;
1853 struct ocfs2_extent_list *el = &eb->h_list;
1854 struct buffer_head **ret = data;

--- 8 unchanged lines hidden (view full) ---

1863 * Find the leaf block in the tree which would contain cpos. No
1864 * checking of the actual leaf is done.
1865 *
1866 * Some paths want to call this instead of allocating a path structure
1867 * and calling ocfs2_find_path().
1868 *
1869 * This function doesn't handle non btree extent lists.
1870 */
1899 find_path_ins, &data);
1900}
1901
1902static void find_leaf_ins(void *data, struct buffer_head *bh)
1903{
1904 struct ocfs2_extent_block *eb =(struct ocfs2_extent_block *)bh->b_data;
1905 struct ocfs2_extent_list *el = &eb->h_list;
1906 struct buffer_head **ret = data;

--- 8 unchanged lines hidden (view full) ---

1915 * Find the leaf block in the tree which would contain cpos. No
1916 * checking of the actual leaf is done.
1917 *
1918 * Some paths want to call this instead of allocating a path structure
1919 * and calling ocfs2_find_path().
1920 *
1921 * This function doesn't handle non btree extent lists.
1922 */
1871int ocfs2_find_leaf(struct inode *inode, struct ocfs2_extent_list *root_el,
1872 u32 cpos, struct buffer_head **leaf_bh)
1923int ocfs2_find_leaf(struct ocfs2_caching_info *ci,
1924 struct ocfs2_extent_list *root_el, u32 cpos,
1925 struct buffer_head **leaf_bh)
1873{
1874 int ret;
1875 struct buffer_head *bh = NULL;
1876
1926{
1927 int ret;
1928 struct buffer_head *bh = NULL;
1929
1877 ret = __ocfs2_find_path(inode, root_el, cpos, find_leaf_ins, &bh);
1930 ret = __ocfs2_find_path(ci, root_el, cpos, find_leaf_ins, &bh);
1878 if (ret) {
1879 mlog_errno(ret);
1880 goto out;
1881 }
1882
1883 *leaf_bh = bh;
1884out:
1885 return ret;

--- 89 unchanged lines hidden (view full) ---

1975 * - When we've moved an extent record from the left path leaf to the right
1976 * path leaf to make room for an empty extent in the left path leaf.
1977 * - When our insert into the right path leaf is at the leftmost edge
1978 * and requires an update of the path immediately to it's left. This
1979 * can occur at the end of some types of rotation and appending inserts.
1980 * - When we've adjusted the last extent record in the left path leaf and the
1981 * 1st extent record in the right path leaf during cross extent block merge.
1982 */
1931 if (ret) {
1932 mlog_errno(ret);
1933 goto out;
1934 }
1935
1936 *leaf_bh = bh;
1937out:
1938 return ret;

--- 89 unchanged lines hidden (view full) ---

2028 * - When we've moved an extent record from the left path leaf to the right
2029 * path leaf to make room for an empty extent in the left path leaf.
2030 * - When our insert into the right path leaf is at the leftmost edge
2031 * and requires an update of the path immediately to it's left. This
2032 * can occur at the end of some types of rotation and appending inserts.
2033 * - When we've adjusted the last extent record in the left path leaf and the
2034 * 1st extent record in the right path leaf during cross extent block merge.
2035 */
1983static void ocfs2_complete_edge_insert(struct inode *inode, handle_t *handle,
2036static void ocfs2_complete_edge_insert(handle_t *handle,
1984 struct ocfs2_path *left_path,
1985 struct ocfs2_path *right_path,
1986 int subtree_index)
1987{
1988 int ret, i, idx;
1989 struct ocfs2_extent_list *el, *left_el, *right_el;
1990 struct ocfs2_extent_rec *left_rec, *right_rec;
1991 struct buffer_head *root_bh = left_path->p_node[subtree_index].bh;

--- 61 unchanged lines hidden (view full) ---

2053
2054 root_bh = left_path->p_node[subtree_index].bh;
2055
2056 ret = ocfs2_journal_dirty(handle, root_bh);
2057 if (ret)
2058 mlog_errno(ret);
2059}
2060
2037 struct ocfs2_path *left_path,
2038 struct ocfs2_path *right_path,
2039 int subtree_index)
2040{
2041 int ret, i, idx;
2042 struct ocfs2_extent_list *el, *left_el, *right_el;
2043 struct ocfs2_extent_rec *left_rec, *right_rec;
2044 struct buffer_head *root_bh = left_path->p_node[subtree_index].bh;

--- 61 unchanged lines hidden (view full) ---

2106
2107 root_bh = left_path->p_node[subtree_index].bh;
2108
2109 ret = ocfs2_journal_dirty(handle, root_bh);
2110 if (ret)
2111 mlog_errno(ret);
2112}
2113
2061static int ocfs2_rotate_subtree_right(struct inode *inode,
2062 handle_t *handle,
2114static int ocfs2_rotate_subtree_right(handle_t *handle,
2115 struct ocfs2_extent_tree *et,
2063 struct ocfs2_path *left_path,
2064 struct ocfs2_path *right_path,
2065 int subtree_index)
2066{
2067 int ret, i;
2068 struct buffer_head *right_leaf_bh;
2069 struct buffer_head *left_leaf_bh = NULL;
2070 struct buffer_head *root_bh;
2071 struct ocfs2_extent_list *right_el, *left_el;
2072 struct ocfs2_extent_rec move_rec;
2073
2074 left_leaf_bh = path_leaf_bh(left_path);
2075 left_el = path_leaf_el(left_path);
2076
2077 if (left_el->l_next_free_rec != left_el->l_count) {
2116 struct ocfs2_path *left_path,
2117 struct ocfs2_path *right_path,
2118 int subtree_index)
2119{
2120 int ret, i;
2121 struct buffer_head *right_leaf_bh;
2122 struct buffer_head *left_leaf_bh = NULL;
2123 struct buffer_head *root_bh;
2124 struct ocfs2_extent_list *right_el, *left_el;
2125 struct ocfs2_extent_rec move_rec;
2126
2127 left_leaf_bh = path_leaf_bh(left_path);
2128 left_el = path_leaf_el(left_path);
2129
2130 if (left_el->l_next_free_rec != left_el->l_count) {
2078 ocfs2_error(inode->i_sb,
2131 ocfs2_error(ocfs2_metadata_cache_get_super(et->et_ci),
2079 "Inode %llu has non-full interior leaf node %llu"
2080 "(next free = %u)",
2132 "Inode %llu has non-full interior leaf node %llu"
2133 "(next free = %u)",
2081 (unsigned long long)OCFS2_I(inode)->ip_blkno,
2134 (unsigned long long)ocfs2_metadata_cache_owner(et->et_ci),
2082 (unsigned long long)left_leaf_bh->b_blocknr,
2083 le16_to_cpu(left_el->l_next_free_rec));
2084 return -EROFS;
2085 }
2086
2087 /*
2088 * This extent block may already have an empty record, so we
2089 * return early if so.
2090 */
2091 if (ocfs2_is_empty_extent(&left_el->l_recs[0]))
2092 return 0;
2093
2094 root_bh = left_path->p_node[subtree_index].bh;
2095 BUG_ON(root_bh != right_path->p_node[subtree_index].bh);
2096
2135 (unsigned long long)left_leaf_bh->b_blocknr,
2136 le16_to_cpu(left_el->l_next_free_rec));
2137 return -EROFS;
2138 }
2139
2140 /*
2141 * This extent block may already have an empty record, so we
2142 * return early if so.
2143 */
2144 if (ocfs2_is_empty_extent(&left_el->l_recs[0]))
2145 return 0;
2146
2147 root_bh = left_path->p_node[subtree_index].bh;
2148 BUG_ON(root_bh != right_path->p_node[subtree_index].bh);
2149
2097 ret = ocfs2_path_bh_journal_access(handle, inode, right_path,
2150 ret = ocfs2_path_bh_journal_access(handle, et->et_ci, right_path,
2098 subtree_index);
2099 if (ret) {
2100 mlog_errno(ret);
2101 goto out;
2102 }
2103
2104 for(i = subtree_index + 1; i < path_num_items(right_path); i++) {
2151 subtree_index);
2152 if (ret) {
2153 mlog_errno(ret);
2154 goto out;
2155 }
2156
2157 for(i = subtree_index + 1; i < path_num_items(right_path); i++) {
2105 ret = ocfs2_path_bh_journal_access(handle, inode,
2158 ret = ocfs2_path_bh_journal_access(handle, et->et_ci,
2106 right_path, i);
2107 if (ret) {
2108 mlog_errno(ret);
2109 goto out;
2110 }
2111
2159 right_path, i);
2160 if (ret) {
2161 mlog_errno(ret);
2162 goto out;
2163 }
2164
2112 ret = ocfs2_path_bh_journal_access(handle, inode,
2165 ret = ocfs2_path_bh_journal_access(handle, et->et_ci,
2113 left_path, i);
2114 if (ret) {
2115 mlog_errno(ret);
2116 goto out;
2117 }
2118 }
2119
2120 right_leaf_bh = path_leaf_bh(right_path);
2121 right_el = path_leaf_el(right_path);
2122
2123 /* This is a code error, not a disk corruption. */
2124 mlog_bug_on_msg(!right_el->l_next_free_rec, "Inode %llu: Rotate fails "
2125 "because rightmost leaf block %llu is empty\n",
2166 left_path, i);
2167 if (ret) {
2168 mlog_errno(ret);
2169 goto out;
2170 }
2171 }
2172
2173 right_leaf_bh = path_leaf_bh(right_path);
2174 right_el = path_leaf_el(right_path);
2175
2176 /* This is a code error, not a disk corruption. */
2177 mlog_bug_on_msg(!right_el->l_next_free_rec, "Inode %llu: Rotate fails "
2178 "because rightmost leaf block %llu is empty\n",
2126 (unsigned long long)OCFS2_I(inode)->ip_blkno,
2179 (unsigned long long)ocfs2_metadata_cache_owner(et->et_ci),
2127 (unsigned long long)right_leaf_bh->b_blocknr);
2128
2129 ocfs2_create_empty_extent(right_el);
2130
2131 ret = ocfs2_journal_dirty(handle, right_leaf_bh);
2132 if (ret) {
2133 mlog_errno(ret);
2134 goto out;

--- 17 unchanged lines hidden (view full) ---

2152 le16_add_cpu(&left_el->l_next_free_rec, 1);
2153
2154 ret = ocfs2_journal_dirty(handle, left_leaf_bh);
2155 if (ret) {
2156 mlog_errno(ret);
2157 goto out;
2158 }
2159
2180 (unsigned long long)right_leaf_bh->b_blocknr);
2181
2182 ocfs2_create_empty_extent(right_el);
2183
2184 ret = ocfs2_journal_dirty(handle, right_leaf_bh);
2185 if (ret) {
2186 mlog_errno(ret);
2187 goto out;

--- 17 unchanged lines hidden (view full) ---

2205 le16_add_cpu(&left_el->l_next_free_rec, 1);
2206
2207 ret = ocfs2_journal_dirty(handle, left_leaf_bh);
2208 if (ret) {
2209 mlog_errno(ret);
2210 goto out;
2211 }
2212
2160 ocfs2_complete_edge_insert(inode, handle, left_path, right_path,
2161 subtree_index);
2213 ocfs2_complete_edge_insert(handle, left_path, right_path,
2214 subtree_index);
2162
2163out:
2164 return ret;
2165}
2166
2167/*
2168 * Given a full path, determine what cpos value would return us a path
2169 * containing the leaf immediately to the left of the current one.

--- 146 unchanged lines hidden (view full) ---

2316 *
2317 * - The 'right_path' array will contain a path to the leaf block
2318 * whose range contains e_cpos.
2319 * - That leaf block will have a single empty extent in list index 0.
2320 * - In the case that the rotation requires a post-insert update,
2321 * *ret_left_path will contain a valid path which can be passed to
2322 * ocfs2_insert_path().
2323 */
2215
2216out:
2217 return ret;
2218}
2219
2220/*
2221 * Given a full path, determine what cpos value would return us a path
2222 * containing the leaf immediately to the left of the current one.

--- 146 unchanged lines hidden (view full) ---

2369 *
2370 * - The 'right_path' array will contain a path to the leaf block
2371 * whose range contains e_cpos.
2372 * - That leaf block will have a single empty extent in list index 0.
2373 * - In the case that the rotation requires a post-insert update,
2374 * *ret_left_path will contain a valid path which can be passed to
2375 * ocfs2_insert_path().
2376 */
2324static int ocfs2_rotate_tree_right(struct inode *inode,
2325 handle_t *handle,
2377static int ocfs2_rotate_tree_right(handle_t *handle,
2378 struct ocfs2_extent_tree *et,
2326 enum ocfs2_split_type split,
2327 u32 insert_cpos,
2328 struct ocfs2_path *right_path,
2329 struct ocfs2_path **ret_left_path)
2330{
2331 int ret, start, orig_credits = handle->h_buffer_credits;
2332 u32 cpos;
2333 struct ocfs2_path *left_path = NULL;
2379 enum ocfs2_split_type split,
2380 u32 insert_cpos,
2381 struct ocfs2_path *right_path,
2382 struct ocfs2_path **ret_left_path)
2383{
2384 int ret, start, orig_credits = handle->h_buffer_credits;
2385 u32 cpos;
2386 struct ocfs2_path *left_path = NULL;
2387 struct super_block *sb = ocfs2_metadata_cache_get_super(et->et_ci);
2334
2335 *ret_left_path = NULL;
2336
2337 left_path = ocfs2_new_path_from_path(right_path);
2338 if (!left_path) {
2339 ret = -ENOMEM;
2340 mlog_errno(ret);
2341 goto out;
2342 }
2343
2388
2389 *ret_left_path = NULL;
2390
2391 left_path = ocfs2_new_path_from_path(right_path);
2392 if (!left_path) {
2393 ret = -ENOMEM;
2394 mlog_errno(ret);
2395 goto out;
2396 }
2397
2344 ret = ocfs2_find_cpos_for_left_leaf(inode->i_sb, right_path, &cpos);
2398 ret = ocfs2_find_cpos_for_left_leaf(sb, right_path, &cpos);
2345 if (ret) {
2346 mlog_errno(ret);
2347 goto out;
2348 }
2349
2350 mlog(0, "Insert: %u, first left path cpos: %u\n", insert_cpos, cpos);
2351
2352 /*

--- 21 unchanged lines hidden (view full) ---

2374 * leftmost branch (i.e., a tree with one branch and a
2375 * rotation inside of it), or we've gone as far as we can in
2376 * rotating subtrees.
2377 */
2378 while (cpos && insert_cpos <= cpos) {
2379 mlog(0, "Rotating a tree: ins. cpos: %u, left path cpos: %u\n",
2380 insert_cpos, cpos);
2381
2399 if (ret) {
2400 mlog_errno(ret);
2401 goto out;
2402 }
2403
2404 mlog(0, "Insert: %u, first left path cpos: %u\n", insert_cpos, cpos);
2405
2406 /*

--- 21 unchanged lines hidden (view full) ---

2428 * leftmost branch (i.e., a tree with one branch and a
2429 * rotation inside of it), or we've gone as far as we can in
2430 * rotating subtrees.
2431 */
2432 while (cpos && insert_cpos <= cpos) {
2433 mlog(0, "Rotating a tree: ins. cpos: %u, left path cpos: %u\n",
2434 insert_cpos, cpos);
2435
2382 ret = ocfs2_find_path(inode, left_path, cpos);
2436 ret = ocfs2_find_path(et->et_ci, left_path, cpos);
2383 if (ret) {
2384 mlog_errno(ret);
2385 goto out;
2386 }
2387
2388 mlog_bug_on_msg(path_leaf_bh(left_path) ==
2389 path_leaf_bh(right_path),
2437 if (ret) {
2438 mlog_errno(ret);
2439 goto out;
2440 }
2441
2442 mlog_bug_on_msg(path_leaf_bh(left_path) ==
2443 path_leaf_bh(right_path),
2390 "Inode %lu: error during insert of %u "
2444 "Owner %llu: error during insert of %u "
2391 "(left path cpos %u) results in two identical "
2392 "paths ending at %llu\n",
2445 "(left path cpos %u) results in two identical "
2446 "paths ending at %llu\n",
2393 inode->i_ino, insert_cpos, cpos,
2447 (unsigned long long)ocfs2_metadata_cache_owner(et->et_ci),
2448 insert_cpos, cpos,
2394 (unsigned long long)
2395 path_leaf_bh(left_path)->b_blocknr);
2396
2397 if (split == SPLIT_NONE &&
2398 ocfs2_rotate_requires_path_adjustment(left_path,
2399 insert_cpos)) {
2400
2401 /*

--- 9 unchanged lines hidden (view full) ---

2411 * record e_cpos will reflect the actual
2412 * e_cpos of the 1st nonempty record of the
2413 * child list.
2414 */
2415 *ret_left_path = left_path;
2416 goto out_ret_path;
2417 }
2418
2449 (unsigned long long)
2450 path_leaf_bh(left_path)->b_blocknr);
2451
2452 if (split == SPLIT_NONE &&
2453 ocfs2_rotate_requires_path_adjustment(left_path,
2454 insert_cpos)) {
2455
2456 /*

--- 9 unchanged lines hidden (view full) ---

2466 * record e_cpos will reflect the actual
2467 * e_cpos of the 1st nonempty record of the
2468 * child list.
2469 */
2470 *ret_left_path = left_path;
2471 goto out_ret_path;
2472 }
2473
2419 start = ocfs2_find_subtree_root(inode, left_path, right_path);
2474 start = ocfs2_find_subtree_root(et, left_path, right_path);
2420
2421 mlog(0, "Subtree root at index %d (blk %llu, depth %d)\n",
2422 start,
2423 (unsigned long long) right_path->p_node[start].bh->b_blocknr,
2424 right_path->p_tree_depth);
2425
2426 ret = ocfs2_extend_rotate_transaction(handle, start,
2427 orig_credits, right_path);
2428 if (ret) {
2429 mlog_errno(ret);
2430 goto out;
2431 }
2432
2475
2476 mlog(0, "Subtree root at index %d (blk %llu, depth %d)\n",
2477 start,
2478 (unsigned long long) right_path->p_node[start].bh->b_blocknr,
2479 right_path->p_tree_depth);
2480
2481 ret = ocfs2_extend_rotate_transaction(handle, start,
2482 orig_credits, right_path);
2483 if (ret) {
2484 mlog_errno(ret);
2485 goto out;
2486 }
2487
2433 ret = ocfs2_rotate_subtree_right(inode, handle, left_path,
2488 ret = ocfs2_rotate_subtree_right(handle, et, left_path,
2434 right_path, start);
2435 if (ret) {
2436 mlog_errno(ret);
2437 goto out;
2438 }
2439
2440 if (split != SPLIT_NONE &&
2441 ocfs2_leftmost_rec_contains(path_leaf_el(right_path),

--- 15 unchanged lines hidden (view full) ---

2457
2458 /*
2459 * There is no need to re-read the next right path
2460 * as we know that it'll be our current left
2461 * path. Optimize by copying values instead.
2462 */
2463 ocfs2_mv_path(right_path, left_path);
2464
2489 right_path, start);
2490 if (ret) {
2491 mlog_errno(ret);
2492 goto out;
2493 }
2494
2495 if (split != SPLIT_NONE &&
2496 ocfs2_leftmost_rec_contains(path_leaf_el(right_path),

--- 15 unchanged lines hidden (view full) ---

2512
2513 /*
2514 * There is no need to re-read the next right path
2515 * as we know that it'll be our current left
2516 * path. Optimize by copying values instead.
2517 */
2518 ocfs2_mv_path(right_path, left_path);
2519
2465 ret = ocfs2_find_cpos_for_left_leaf(inode->i_sb, right_path,
2466 &cpos);
2520 ret = ocfs2_find_cpos_for_left_leaf(sb, right_path, &cpos);
2467 if (ret) {
2468 mlog_errno(ret);
2469 goto out;
2470 }
2471 }
2472
2473out:
2474 ocfs2_free_path(left_path);
2475
2476out_ret_path:
2477 return ret;
2478}
2479
2521 if (ret) {
2522 mlog_errno(ret);
2523 goto out;
2524 }
2525 }
2526
2527out:
2528 ocfs2_free_path(left_path);
2529
2530out_ret_path:
2531 return ret;
2532}
2533
2480static int ocfs2_update_edge_lengths(struct inode *inode, handle_t *handle,
2534static int ocfs2_update_edge_lengths(handle_t *handle,
2535 struct ocfs2_extent_tree *et,
2481 int subtree_index, struct ocfs2_path *path)
2482{
2483 int i, idx, ret;
2484 struct ocfs2_extent_rec *rec;
2485 struct ocfs2_extent_list *el;
2486 struct ocfs2_extent_block *eb;
2487 u32 range;
2488

--- 8 unchanged lines hidden (view full) ---

2497 */
2498 ret = ocfs2_extend_trans(handle,
2499 handle->h_buffer_credits + subtree_index);
2500 if (ret) {
2501 mlog_errno(ret);
2502 goto out;
2503 }
2504
2536 int subtree_index, struct ocfs2_path *path)
2537{
2538 int i, idx, ret;
2539 struct ocfs2_extent_rec *rec;
2540 struct ocfs2_extent_list *el;
2541 struct ocfs2_extent_block *eb;
2542 u32 range;
2543

--- 8 unchanged lines hidden (view full) ---

2552 */
2553 ret = ocfs2_extend_trans(handle,
2554 handle->h_buffer_credits + subtree_index);
2555 if (ret) {
2556 mlog_errno(ret);
2557 goto out;
2558 }
2559
2505 ret = ocfs2_journal_access_path(inode, handle, path);
2560 ret = ocfs2_journal_access_path(et->et_ci, handle, path);
2506 if (ret) {
2507 mlog_errno(ret);
2508 goto out;
2509 }
2510
2511 /* Path should always be rightmost. */
2512 eb = (struct ocfs2_extent_block *)path_leaf_bh(path)->b_data;
2513 BUG_ON(eb->h_next_leaf_blk != 0ULL);

--- 13 unchanged lines hidden (view full) ---

2527 le32_add_cpu(&rec->e_int_clusters, -le32_to_cpu(rec->e_cpos));
2528
2529 ocfs2_journal_dirty(handle, path->p_node[i].bh);
2530 }
2531out:
2532 return ret;
2533}
2534
2561 if (ret) {
2562 mlog_errno(ret);
2563 goto out;
2564 }
2565
2566 /* Path should always be rightmost. */
2567 eb = (struct ocfs2_extent_block *)path_leaf_bh(path)->b_data;
2568 BUG_ON(eb->h_next_leaf_blk != 0ULL);

--- 13 unchanged lines hidden (view full) ---

2582 le32_add_cpu(&rec->e_int_clusters, -le32_to_cpu(rec->e_cpos));
2583
2584 ocfs2_journal_dirty(handle, path->p_node[i].bh);
2585 }
2586out:
2587 return ret;
2588}
2589
2535static void ocfs2_unlink_path(struct inode *inode, handle_t *handle,
2590static void ocfs2_unlink_path(handle_t *handle,
2591 struct ocfs2_extent_tree *et,
2536 struct ocfs2_cached_dealloc_ctxt *dealloc,
2537 struct ocfs2_path *path, int unlink_start)
2538{
2539 int ret, i;
2540 struct ocfs2_extent_block *eb;
2541 struct ocfs2_extent_list *el;
2542 struct buffer_head *bh;
2543

--- 5 unchanged lines hidden (view full) ---

2549 * Not all nodes might have had their final count
2550 * decremented by the caller - handle this here.
2551 */
2552 el = &eb->h_list;
2553 if (le16_to_cpu(el->l_next_free_rec) > 1) {
2554 mlog(ML_ERROR,
2555 "Inode %llu, attempted to remove extent block "
2556 "%llu with %u records\n",
2592 struct ocfs2_cached_dealloc_ctxt *dealloc,
2593 struct ocfs2_path *path, int unlink_start)
2594{
2595 int ret, i;
2596 struct ocfs2_extent_block *eb;
2597 struct ocfs2_extent_list *el;
2598 struct buffer_head *bh;
2599

--- 5 unchanged lines hidden (view full) ---

2605 * Not all nodes might have had their final count
2606 * decremented by the caller - handle this here.
2607 */
2608 el = &eb->h_list;
2609 if (le16_to_cpu(el->l_next_free_rec) > 1) {
2610 mlog(ML_ERROR,
2611 "Inode %llu, attempted to remove extent block "
2612 "%llu with %u records\n",
2557 (unsigned long long)OCFS2_I(inode)->ip_blkno,
2613 (unsigned long long)ocfs2_metadata_cache_owner(et->et_ci),
2558 (unsigned long long)le64_to_cpu(eb->h_blkno),
2559 le16_to_cpu(el->l_next_free_rec));
2560
2561 ocfs2_journal_dirty(handle, bh);
2614 (unsigned long long)le64_to_cpu(eb->h_blkno),
2615 le16_to_cpu(el->l_next_free_rec));
2616
2617 ocfs2_journal_dirty(handle, bh);
2562 ocfs2_remove_from_cache(inode, bh);
2618 ocfs2_remove_from_cache(et->et_ci, bh);
2563 continue;
2564 }
2565
2566 el->l_next_free_rec = 0;
2567 memset(&el->l_recs[0], 0, sizeof(struct ocfs2_extent_rec));
2568
2569 ocfs2_journal_dirty(handle, bh);
2570
2571 ret = ocfs2_cache_extent_block_free(dealloc, eb);
2572 if (ret)
2573 mlog_errno(ret);
2574
2619 continue;
2620 }
2621
2622 el->l_next_free_rec = 0;
2623 memset(&el->l_recs[0], 0, sizeof(struct ocfs2_extent_rec));
2624
2625 ocfs2_journal_dirty(handle, bh);
2626
2627 ret = ocfs2_cache_extent_block_free(dealloc, eb);
2628 if (ret)
2629 mlog_errno(ret);
2630
2575 ocfs2_remove_from_cache(inode, bh);
2631 ocfs2_remove_from_cache(et->et_ci, bh);
2576 }
2577}
2578
2632 }
2633}
2634
2579static void ocfs2_unlink_subtree(struct inode *inode, handle_t *handle,
2635static void ocfs2_unlink_subtree(handle_t *handle,
2636 struct ocfs2_extent_tree *et,
2580 struct ocfs2_path *left_path,
2581 struct ocfs2_path *right_path,
2582 int subtree_index,
2583 struct ocfs2_cached_dealloc_ctxt *dealloc)
2584{
2585 int i;
2586 struct buffer_head *root_bh = left_path->p_node[subtree_index].bh;
2587 struct ocfs2_extent_list *root_el = left_path->p_node[subtree_index].el;

--- 14 unchanged lines hidden (view full) ---

2602 le16_add_cpu(&root_el->l_next_free_rec, -1);
2603
2604 eb = (struct ocfs2_extent_block *)path_leaf_bh(left_path)->b_data;
2605 eb->h_next_leaf_blk = 0;
2606
2607 ocfs2_journal_dirty(handle, root_bh);
2608 ocfs2_journal_dirty(handle, path_leaf_bh(left_path));
2609
2637 struct ocfs2_path *left_path,
2638 struct ocfs2_path *right_path,
2639 int subtree_index,
2640 struct ocfs2_cached_dealloc_ctxt *dealloc)
2641{
2642 int i;
2643 struct buffer_head *root_bh = left_path->p_node[subtree_index].bh;
2644 struct ocfs2_extent_list *root_el = left_path->p_node[subtree_index].el;

--- 14 unchanged lines hidden (view full) ---

2659 le16_add_cpu(&root_el->l_next_free_rec, -1);
2660
2661 eb = (struct ocfs2_extent_block *)path_leaf_bh(left_path)->b_data;
2662 eb->h_next_leaf_blk = 0;
2663
2664 ocfs2_journal_dirty(handle, root_bh);
2665 ocfs2_journal_dirty(handle, path_leaf_bh(left_path));
2666
2610 ocfs2_unlink_path(inode, handle, dealloc, right_path,
2667 ocfs2_unlink_path(handle, et, dealloc, right_path,
2611 subtree_index + 1);
2612}
2613
2668 subtree_index + 1);
2669}
2670
2614static int ocfs2_rotate_subtree_left(struct inode *inode, handle_t *handle,
2671static int ocfs2_rotate_subtree_left(handle_t *handle,
2672 struct ocfs2_extent_tree *et,
2615 struct ocfs2_path *left_path,
2616 struct ocfs2_path *right_path,
2617 int subtree_index,
2618 struct ocfs2_cached_dealloc_ctxt *dealloc,
2673 struct ocfs2_path *left_path,
2674 struct ocfs2_path *right_path,
2675 int subtree_index,
2676 struct ocfs2_cached_dealloc_ctxt *dealloc,
2619 int *deleted,
2620 struct ocfs2_extent_tree *et)
2677 int *deleted)
2621{
2622 int ret, i, del_right_subtree = 0, right_has_empty = 0;
2623 struct buffer_head *root_bh, *et_root_bh = path_root_bh(right_path);
2624 struct ocfs2_extent_list *right_leaf_el, *left_leaf_el;
2625 struct ocfs2_extent_block *eb;
2626
2627 *deleted = 0;
2628

--- 19 unchanged lines hidden (view full) ---

2648 * Non rightmost leaves will throw -EAGAIN and the
2649 * caller can manually move the subtree and retry.
2650 */
2651
2652 if (eb->h_next_leaf_blk != 0ULL)
2653 return -EAGAIN;
2654
2655 if (le16_to_cpu(right_leaf_el->l_next_free_rec) > 1) {
2678{
2679 int ret, i, del_right_subtree = 0, right_has_empty = 0;
2680 struct buffer_head *root_bh, *et_root_bh = path_root_bh(right_path);
2681 struct ocfs2_extent_list *right_leaf_el, *left_leaf_el;
2682 struct ocfs2_extent_block *eb;
2683
2684 *deleted = 0;
2685

--- 19 unchanged lines hidden (view full) ---

2705 * Non rightmost leaves will throw -EAGAIN and the
2706 * caller can manually move the subtree and retry.
2707 */
2708
2709 if (eb->h_next_leaf_blk != 0ULL)
2710 return -EAGAIN;
2711
2712 if (le16_to_cpu(right_leaf_el->l_next_free_rec) > 1) {
2656 ret = ocfs2_journal_access_eb(handle, inode,
2713 ret = ocfs2_journal_access_eb(handle, et->et_ci,
2657 path_leaf_bh(right_path),
2658 OCFS2_JOURNAL_ACCESS_WRITE);
2659 if (ret) {
2660 mlog_errno(ret);
2661 goto out;
2662 }
2663
2664 ocfs2_remove_empty_extent(right_leaf_el);
2665 } else
2666 right_has_empty = 1;
2667 }
2668
2669 if (eb->h_next_leaf_blk == 0ULL &&
2670 le16_to_cpu(right_leaf_el->l_next_free_rec) == 1) {
2671 /*
2672 * We have to update i_last_eb_blk during the meta
2673 * data delete.
2674 */
2714 path_leaf_bh(right_path),
2715 OCFS2_JOURNAL_ACCESS_WRITE);
2716 if (ret) {
2717 mlog_errno(ret);
2718 goto out;
2719 }
2720
2721 ocfs2_remove_empty_extent(right_leaf_el);
2722 } else
2723 right_has_empty = 1;
2724 }
2725
2726 if (eb->h_next_leaf_blk == 0ULL &&
2727 le16_to_cpu(right_leaf_el->l_next_free_rec) == 1) {
2728 /*
2729 * We have to update i_last_eb_blk during the meta
2730 * data delete.
2731 */
2675 ret = ocfs2_et_root_journal_access(handle, inode, et,
2732 ret = ocfs2_et_root_journal_access(handle, et,
2676 OCFS2_JOURNAL_ACCESS_WRITE);
2677 if (ret) {
2678 mlog_errno(ret);
2679 goto out;
2680 }
2681
2682 del_right_subtree = 1;
2683 }
2684
2685 /*
2686 * Getting here with an empty extent in the right path implies
2687 * that it's the rightmost path and will be deleted.
2688 */
2689 BUG_ON(right_has_empty && !del_right_subtree);
2690
2733 OCFS2_JOURNAL_ACCESS_WRITE);
2734 if (ret) {
2735 mlog_errno(ret);
2736 goto out;
2737 }
2738
2739 del_right_subtree = 1;
2740 }
2741
2742 /*
2743 * Getting here with an empty extent in the right path implies
2744 * that it's the rightmost path and will be deleted.
2745 */
2746 BUG_ON(right_has_empty && !del_right_subtree);
2747
2691 ret = ocfs2_path_bh_journal_access(handle, inode, right_path,
2748 ret = ocfs2_path_bh_journal_access(handle, et->et_ci, right_path,
2692 subtree_index);
2693 if (ret) {
2694 mlog_errno(ret);
2695 goto out;
2696 }
2697
2698 for(i = subtree_index + 1; i < path_num_items(right_path); i++) {
2749 subtree_index);
2750 if (ret) {
2751 mlog_errno(ret);
2752 goto out;
2753 }
2754
2755 for(i = subtree_index + 1; i < path_num_items(right_path); i++) {
2699 ret = ocfs2_path_bh_journal_access(handle, inode,
2756 ret = ocfs2_path_bh_journal_access(handle, et->et_ci,
2700 right_path, i);
2701 if (ret) {
2702 mlog_errno(ret);
2703 goto out;
2704 }
2705
2757 right_path, i);
2758 if (ret) {
2759 mlog_errno(ret);
2760 goto out;
2761 }
2762
2706 ret = ocfs2_path_bh_journal_access(handle, inode,
2763 ret = ocfs2_path_bh_journal_access(handle, et->et_ci,
2707 left_path, i);
2708 if (ret) {
2709 mlog_errno(ret);
2710 goto out;
2711 }
2712 }
2713
2714 if (!right_has_empty) {

--- 20 unchanged lines hidden (view full) ---

2735 ret = ocfs2_journal_dirty(handle, path_leaf_bh(left_path));
2736 if (ret)
2737 mlog_errno(ret);
2738 ret = ocfs2_journal_dirty(handle, path_leaf_bh(right_path));
2739 if (ret)
2740 mlog_errno(ret);
2741
2742 if (del_right_subtree) {
2764 left_path, i);
2765 if (ret) {
2766 mlog_errno(ret);
2767 goto out;
2768 }
2769 }
2770
2771 if (!right_has_empty) {

--- 20 unchanged lines hidden (view full) ---

2792 ret = ocfs2_journal_dirty(handle, path_leaf_bh(left_path));
2793 if (ret)
2794 mlog_errno(ret);
2795 ret = ocfs2_journal_dirty(handle, path_leaf_bh(right_path));
2796 if (ret)
2797 mlog_errno(ret);
2798
2799 if (del_right_subtree) {
2743 ocfs2_unlink_subtree(inode, handle, left_path, right_path,
2800 ocfs2_unlink_subtree(handle, et, left_path, right_path,
2744 subtree_index, dealloc);
2801 subtree_index, dealloc);
2745 ret = ocfs2_update_edge_lengths(inode, handle, subtree_index,
2802 ret = ocfs2_update_edge_lengths(handle, et, subtree_index,
2746 left_path);
2747 if (ret) {
2748 mlog_errno(ret);
2749 goto out;
2750 }
2751
2752 eb = (struct ocfs2_extent_block *)path_leaf_bh(left_path)->b_data;
2753 ocfs2_et_set_last_eb_blk(et, le64_to_cpu(eb->h_blkno));

--- 7 unchanged lines hidden (view full) ---

2761 ocfs2_remove_empty_extent(left_leaf_el);
2762
2763 ret = ocfs2_journal_dirty(handle, et_root_bh);
2764 if (ret)
2765 mlog_errno(ret);
2766
2767 *deleted = 1;
2768 } else
2803 left_path);
2804 if (ret) {
2805 mlog_errno(ret);
2806 goto out;
2807 }
2808
2809 eb = (struct ocfs2_extent_block *)path_leaf_bh(left_path)->b_data;
2810 ocfs2_et_set_last_eb_blk(et, le64_to_cpu(eb->h_blkno));

--- 7 unchanged lines hidden (view full) ---

2818 ocfs2_remove_empty_extent(left_leaf_el);
2819
2820 ret = ocfs2_journal_dirty(handle, et_root_bh);
2821 if (ret)
2822 mlog_errno(ret);
2823
2824 *deleted = 1;
2825 } else
2769 ocfs2_complete_edge_insert(inode, handle, left_path, right_path,
2826 ocfs2_complete_edge_insert(handle, left_path, right_path,
2770 subtree_index);
2771
2772out:
2773 return ret;
2774}
2775
2776/*
2777 * Given a full path, determine what cpos value would return us a path

--- 69 unchanged lines hidden (view full) ---

2847 blkno = path->p_node[i].bh->b_blocknr;
2848 i--;
2849 }
2850
2851out:
2852 return ret;
2853}
2854
2827 subtree_index);
2828
2829out:
2830 return ret;
2831}
2832
2833/*
2834 * Given a full path, determine what cpos value would return us a path

--- 69 unchanged lines hidden (view full) ---

2904 blkno = path->p_node[i].bh->b_blocknr;
2905 i--;
2906 }
2907
2908out:
2909 return ret;
2910}
2911
2855static int ocfs2_rotate_rightmost_leaf_left(struct inode *inode,
2856 handle_t *handle,
2912static int ocfs2_rotate_rightmost_leaf_left(handle_t *handle,
2913 struct ocfs2_extent_tree *et,
2857 struct ocfs2_path *path)
2858{
2859 int ret;
2860 struct buffer_head *bh = path_leaf_bh(path);
2861 struct ocfs2_extent_list *el = path_leaf_el(path);
2862
2863 if (!ocfs2_is_empty_extent(&el->l_recs[0]))
2864 return 0;
2865
2914 struct ocfs2_path *path)
2915{
2916 int ret;
2917 struct buffer_head *bh = path_leaf_bh(path);
2918 struct ocfs2_extent_list *el = path_leaf_el(path);
2919
2920 if (!ocfs2_is_empty_extent(&el->l_recs[0]))
2921 return 0;
2922
2866 ret = ocfs2_path_bh_journal_access(handle, inode, path,
2923 ret = ocfs2_path_bh_journal_access(handle, et->et_ci, path,
2867 path_num_items(path) - 1);
2868 if (ret) {
2869 mlog_errno(ret);
2870 goto out;
2871 }
2872
2873 ocfs2_remove_empty_extent(el);
2874
2875 ret = ocfs2_journal_dirty(handle, bh);
2876 if (ret)
2877 mlog_errno(ret);
2878
2879out:
2880 return ret;
2881}
2882
2924 path_num_items(path) - 1);
2925 if (ret) {
2926 mlog_errno(ret);
2927 goto out;
2928 }
2929
2930 ocfs2_remove_empty_extent(el);
2931
2932 ret = ocfs2_journal_dirty(handle, bh);
2933 if (ret)
2934 mlog_errno(ret);
2935
2936out:
2937 return ret;
2938}
2939
2883static int __ocfs2_rotate_tree_left(struct inode *inode,
2884 handle_t *handle, int orig_credits,
2940static int __ocfs2_rotate_tree_left(handle_t *handle,
2941 struct ocfs2_extent_tree *et,
2942 int orig_credits,
2885 struct ocfs2_path *path,
2886 struct ocfs2_cached_dealloc_ctxt *dealloc,
2943 struct ocfs2_path *path,
2944 struct ocfs2_cached_dealloc_ctxt *dealloc,
2887 struct ocfs2_path **empty_extent_path,
2888 struct ocfs2_extent_tree *et)
2945 struct ocfs2_path **empty_extent_path)
2889{
2890 int ret, subtree_root, deleted;
2891 u32 right_cpos;
2892 struct ocfs2_path *left_path = NULL;
2893 struct ocfs2_path *right_path = NULL;
2946{
2947 int ret, subtree_root, deleted;
2948 u32 right_cpos;
2949 struct ocfs2_path *left_path = NULL;
2950 struct ocfs2_path *right_path = NULL;
2951 struct super_block *sb = ocfs2_metadata_cache_get_super(et->et_ci);
2894
2895 BUG_ON(!ocfs2_is_empty_extent(&(path_leaf_el(path)->l_recs[0])));
2896
2897 *empty_extent_path = NULL;
2898
2952
2953 BUG_ON(!ocfs2_is_empty_extent(&(path_leaf_el(path)->l_recs[0])));
2954
2955 *empty_extent_path = NULL;
2956
2899 ret = ocfs2_find_cpos_for_right_leaf(inode->i_sb, path,
2900 &right_cpos);
2957 ret = ocfs2_find_cpos_for_right_leaf(sb, path, &right_cpos);
2901 if (ret) {
2902 mlog_errno(ret);
2903 goto out;
2904 }
2905
2906 left_path = ocfs2_new_path_from_path(path);
2907 if (!left_path) {
2908 ret = -ENOMEM;

--- 6 unchanged lines hidden (view full) ---

2915 right_path = ocfs2_new_path_from_path(path);
2916 if (!right_path) {
2917 ret = -ENOMEM;
2918 mlog_errno(ret);
2919 goto out;
2920 }
2921
2922 while (right_cpos) {
2958 if (ret) {
2959 mlog_errno(ret);
2960 goto out;
2961 }
2962
2963 left_path = ocfs2_new_path_from_path(path);
2964 if (!left_path) {
2965 ret = -ENOMEM;

--- 6 unchanged lines hidden (view full) ---

2972 right_path = ocfs2_new_path_from_path(path);
2973 if (!right_path) {
2974 ret = -ENOMEM;
2975 mlog_errno(ret);
2976 goto out;
2977 }
2978
2979 while (right_cpos) {
2923 ret = ocfs2_find_path(inode, right_path, right_cpos);
2980 ret = ocfs2_find_path(et->et_ci, right_path, right_cpos);
2924 if (ret) {
2925 mlog_errno(ret);
2926 goto out;
2927 }
2928
2981 if (ret) {
2982 mlog_errno(ret);
2983 goto out;
2984 }
2985
2929 subtree_root = ocfs2_find_subtree_root(inode, left_path,
2986 subtree_root = ocfs2_find_subtree_root(et, left_path,
2930 right_path);
2931
2932 mlog(0, "Subtree root at index %d (blk %llu, depth %d)\n",
2933 subtree_root,
2934 (unsigned long long)
2935 right_path->p_node[subtree_root].bh->b_blocknr,
2936 right_path->p_tree_depth);
2937
2938 ret = ocfs2_extend_rotate_transaction(handle, subtree_root,
2939 orig_credits, left_path);
2940 if (ret) {
2941 mlog_errno(ret);
2942 goto out;
2943 }
2944
2945 /*
2946 * Caller might still want to make changes to the
2947 * tree root, so re-add it to the journal here.
2948 */
2987 right_path);
2988
2989 mlog(0, "Subtree root at index %d (blk %llu, depth %d)\n",
2990 subtree_root,
2991 (unsigned long long)
2992 right_path->p_node[subtree_root].bh->b_blocknr,
2993 right_path->p_tree_depth);
2994
2995 ret = ocfs2_extend_rotate_transaction(handle, subtree_root,
2996 orig_credits, left_path);
2997 if (ret) {
2998 mlog_errno(ret);
2999 goto out;
3000 }
3001
3002 /*
3003 * Caller might still want to make changes to the
3004 * tree root, so re-add it to the journal here.
3005 */
2949 ret = ocfs2_path_bh_journal_access(handle, inode,
3006 ret = ocfs2_path_bh_journal_access(handle, et->et_ci,
2950 left_path, 0);
2951 if (ret) {
2952 mlog_errno(ret);
2953 goto out;
2954 }
2955
3007 left_path, 0);
3008 if (ret) {
3009 mlog_errno(ret);
3010 goto out;
3011 }
3012
2956 ret = ocfs2_rotate_subtree_left(inode, handle, left_path,
3013 ret = ocfs2_rotate_subtree_left(handle, et, left_path,
2957 right_path, subtree_root,
3014 right_path, subtree_root,
2958 dealloc, &deleted, et);
3015 dealloc, &deleted);
2959 if (ret == -EAGAIN) {
2960 /*
2961 * The rotation has to temporarily stop due to
2962 * the right subtree having an empty
2963 * extent. Pass it back to the caller for a
2964 * fixup.
2965 */
2966 *empty_extent_path = right_path;

--- 10 unchanged lines hidden (view full) ---

2977 * the rightmost edge. If so, then rotation is
2978 * complete.
2979 */
2980 if (deleted)
2981 break;
2982
2983 ocfs2_mv_path(left_path, right_path);
2984
3016 if (ret == -EAGAIN) {
3017 /*
3018 * The rotation has to temporarily stop due to
3019 * the right subtree having an empty
3020 * extent. Pass it back to the caller for a
3021 * fixup.
3022 */
3023 *empty_extent_path = right_path;

--- 10 unchanged lines hidden (view full) ---

3034 * the rightmost edge. If so, then rotation is
3035 * complete.
3036 */
3037 if (deleted)
3038 break;
3039
3040 ocfs2_mv_path(left_path, right_path);
3041
2985 ret = ocfs2_find_cpos_for_right_leaf(inode->i_sb, left_path,
3042 ret = ocfs2_find_cpos_for_right_leaf(sb, left_path,
2986 &right_cpos);
2987 if (ret) {
2988 mlog_errno(ret);
2989 goto out;
2990 }
2991 }
2992
2993out:
2994 ocfs2_free_path(right_path);
2995 ocfs2_free_path(left_path);
2996
2997 return ret;
2998}
2999
3043 &right_cpos);
3044 if (ret) {
3045 mlog_errno(ret);
3046 goto out;
3047 }
3048 }
3049
3050out:
3051 ocfs2_free_path(right_path);
3052 ocfs2_free_path(left_path);
3053
3054 return ret;
3055}
3056
3000static int ocfs2_remove_rightmost_path(struct inode *inode, handle_t *handle,
3057static int ocfs2_remove_rightmost_path(handle_t *handle,
3058 struct ocfs2_extent_tree *et,
3001 struct ocfs2_path *path,
3059 struct ocfs2_path *path,
3002 struct ocfs2_cached_dealloc_ctxt *dealloc,
3003 struct ocfs2_extent_tree *et)
3060 struct ocfs2_cached_dealloc_ctxt *dealloc)
3004{
3005 int ret, subtree_index;
3006 u32 cpos;
3007 struct ocfs2_path *left_path = NULL;
3008 struct ocfs2_extent_block *eb;
3009 struct ocfs2_extent_list *el;
3010
3011
3061{
3062 int ret, subtree_index;
3063 u32 cpos;
3064 struct ocfs2_path *left_path = NULL;
3065 struct ocfs2_extent_block *eb;
3066 struct ocfs2_extent_list *el;
3067
3068
3012 ret = ocfs2_et_sanity_check(inode, et);
3069 ret = ocfs2_et_sanity_check(et);
3013 if (ret)
3014 goto out;
3015 /*
3016 * There's two ways we handle this depending on
3017 * whether path is the only existing one.
3018 */
3019 ret = ocfs2_extend_rotate_transaction(handle, 0,
3020 handle->h_buffer_credits,
3021 path);
3022 if (ret) {
3023 mlog_errno(ret);
3024 goto out;
3025 }
3026
3070 if (ret)
3071 goto out;
3072 /*
3073 * There's two ways we handle this depending on
3074 * whether path is the only existing one.
3075 */
3076 ret = ocfs2_extend_rotate_transaction(handle, 0,
3077 handle->h_buffer_credits,
3078 path);
3079 if (ret) {
3080 mlog_errno(ret);
3081 goto out;
3082 }
3083
3027 ret = ocfs2_journal_access_path(inode, handle, path);
3084 ret = ocfs2_journal_access_path(et->et_ci, handle, path);
3028 if (ret) {
3029 mlog_errno(ret);
3030 goto out;
3031 }
3032
3085 if (ret) {
3086 mlog_errno(ret);
3087 goto out;
3088 }
3089
3033 ret = ocfs2_find_cpos_for_left_leaf(inode->i_sb, path, &cpos);
3090 ret = ocfs2_find_cpos_for_left_leaf(ocfs2_metadata_cache_get_super(et->et_ci),
3091 path, &cpos);
3034 if (ret) {
3035 mlog_errno(ret);
3036 goto out;
3037 }
3038
3039 if (cpos) {
3040 /*
3041 * We have a path to the left of this one - it needs
3042 * an update too.
3043 */
3044 left_path = ocfs2_new_path_from_path(path);
3045 if (!left_path) {
3046 ret = -ENOMEM;
3047 mlog_errno(ret);
3048 goto out;
3049 }
3050
3092 if (ret) {
3093 mlog_errno(ret);
3094 goto out;
3095 }
3096
3097 if (cpos) {
3098 /*
3099 * We have a path to the left of this one - it needs
3100 * an update too.
3101 */
3102 left_path = ocfs2_new_path_from_path(path);
3103 if (!left_path) {
3104 ret = -ENOMEM;
3105 mlog_errno(ret);
3106 goto out;
3107 }
3108
3051 ret = ocfs2_find_path(inode, left_path, cpos);
3109 ret = ocfs2_find_path(et->et_ci, left_path, cpos);
3052 if (ret) {
3053 mlog_errno(ret);
3054 goto out;
3055 }
3056
3110 if (ret) {
3111 mlog_errno(ret);
3112 goto out;
3113 }
3114
3057 ret = ocfs2_journal_access_path(inode, handle, left_path);
3115 ret = ocfs2_journal_access_path(et->et_ci, handle, left_path);
3058 if (ret) {
3059 mlog_errno(ret);
3060 goto out;
3061 }
3062
3116 if (ret) {
3117 mlog_errno(ret);
3118 goto out;
3119 }
3120
3063 subtree_index = ocfs2_find_subtree_root(inode, left_path, path);
3121 subtree_index = ocfs2_find_subtree_root(et, left_path, path);
3064
3122
3065 ocfs2_unlink_subtree(inode, handle, left_path, path,
3123 ocfs2_unlink_subtree(handle, et, left_path, path,
3066 subtree_index, dealloc);
3124 subtree_index, dealloc);
3067 ret = ocfs2_update_edge_lengths(inode, handle, subtree_index,
3125 ret = ocfs2_update_edge_lengths(handle, et, subtree_index,
3068 left_path);
3069 if (ret) {
3070 mlog_errno(ret);
3071 goto out;
3072 }
3073
3074 eb = (struct ocfs2_extent_block *)path_leaf_bh(left_path)->b_data;
3075 ocfs2_et_set_last_eb_blk(et, le64_to_cpu(eb->h_blkno));
3076 } else {
3077 /*
3078 * 'path' is also the leftmost path which
3079 * means it must be the only one. This gets
3080 * handled differently because we want to
3126 left_path);
3127 if (ret) {
3128 mlog_errno(ret);
3129 goto out;
3130 }
3131
3132 eb = (struct ocfs2_extent_block *)path_leaf_bh(left_path)->b_data;
3133 ocfs2_et_set_last_eb_blk(et, le64_to_cpu(eb->h_blkno));
3134 } else {
3135 /*
3136 * 'path' is also the leftmost path which
3137 * means it must be the only one. This gets
3138 * handled differently because we want to
3081 * revert the inode back to having extents
3139 * revert the root back to having extents
3082 * in-line.
3083 */
3140 * in-line.
3141 */
3084 ocfs2_unlink_path(inode, handle, dealloc, path, 1);
3142 ocfs2_unlink_path(handle, et, dealloc, path, 1);
3085
3086 el = et->et_root_el;
3087 el->l_tree_depth = 0;
3088 el->l_next_free_rec = 0;
3089 memset(&el->l_recs[0], 0, sizeof(struct ocfs2_extent_rec));
3090
3091 ocfs2_et_set_last_eb_blk(et, 0);
3092 }

--- 16 unchanged lines hidden (view full) ---

3109 * This is used by any code which reduces the number of extent records
3110 * in a leaf. After removal, an empty record should be placed in the
3111 * leftmost list position.
3112 *
3113 * This won't handle a length update of the rightmost path records if
3114 * the rightmost tree leaf record is removed so the caller is
3115 * responsible for detecting and correcting that.
3116 */
3143
3144 el = et->et_root_el;
3145 el->l_tree_depth = 0;
3146 el->l_next_free_rec = 0;
3147 memset(&el->l_recs[0], 0, sizeof(struct ocfs2_extent_rec));
3148
3149 ocfs2_et_set_last_eb_blk(et, 0);
3150 }

--- 16 unchanged lines hidden (view full) ---

3167 * This is used by any code which reduces the number of extent records
3168 * in a leaf. After removal, an empty record should be placed in the
3169 * leftmost list position.
3170 *
3171 * This won't handle a length update of the rightmost path records if
3172 * the rightmost tree leaf record is removed so the caller is
3173 * responsible for detecting and correcting that.
3174 */
3117static int ocfs2_rotate_tree_left(struct inode *inode, handle_t *handle,
3175static int ocfs2_rotate_tree_left(handle_t *handle,
3176 struct ocfs2_extent_tree *et,
3118 struct ocfs2_path *path,
3177 struct ocfs2_path *path,
3119 struct ocfs2_cached_dealloc_ctxt *dealloc,
3120 struct ocfs2_extent_tree *et)
3178 struct ocfs2_cached_dealloc_ctxt *dealloc)
3121{
3122 int ret, orig_credits = handle->h_buffer_credits;
3123 struct ocfs2_path *tmp_path = NULL, *restart_path = NULL;
3124 struct ocfs2_extent_block *eb;
3125 struct ocfs2_extent_list *el;
3126
3127 el = path_leaf_el(path);
3128 if (!ocfs2_is_empty_extent(&el->l_recs[0]))
3129 return 0;
3130
3131 if (path->p_tree_depth == 0) {
3132rightmost_no_delete:
3133 /*
3134 * Inline extents. This is trivially handled, so do
3135 * it up front.
3136 */
3179{
3180 int ret, orig_credits = handle->h_buffer_credits;
3181 struct ocfs2_path *tmp_path = NULL, *restart_path = NULL;
3182 struct ocfs2_extent_block *eb;
3183 struct ocfs2_extent_list *el;
3184
3185 el = path_leaf_el(path);
3186 if (!ocfs2_is_empty_extent(&el->l_recs[0]))
3187 return 0;
3188
3189 if (path->p_tree_depth == 0) {
3190rightmost_no_delete:
3191 /*
3192 * Inline extents. This is trivially handled, so do
3193 * it up front.
3194 */
3137 ret = ocfs2_rotate_rightmost_leaf_left(inode, handle,
3138 path);
3195 ret = ocfs2_rotate_rightmost_leaf_left(handle, et, path);
3139 if (ret)
3140 mlog_errno(ret);
3141 goto out;
3142 }
3143
3144 /*
3145 * Handle rightmost branch now. There's several cases:
3146 * 1) simple rotation leaving records in there. That's trivial.
3147 * 2) rotation requiring a branch delete - there's no more
3148 * records left. Two cases of this:
3149 * a) There are branches to the left.
3150 * b) This is also the leftmost (the only) branch.
3151 *
3152 * 1) is handled via ocfs2_rotate_rightmost_leaf_left()
3153 * 2a) we need the left branch so that we can update it with the unlink
3196 if (ret)
3197 mlog_errno(ret);
3198 goto out;
3199 }
3200
3201 /*
3202 * Handle rightmost branch now. There's several cases:
3203 * 1) simple rotation leaving records in there. That's trivial.
3204 * 2) rotation requiring a branch delete - there's no more
3205 * records left. Two cases of this:
3206 * a) There are branches to the left.
3207 * b) This is also the leftmost (the only) branch.
3208 *
3209 * 1) is handled via ocfs2_rotate_rightmost_leaf_left()
3210 * 2a) we need the left branch so that we can update it with the unlink
3154 * 2b) we need to bring the inode back to inline extents.
3211 * 2b) we need to bring the root back to inline extents.
3155 */
3156
3157 eb = (struct ocfs2_extent_block *)path_leaf_bh(path)->b_data;
3158 el = &eb->h_list;
3159 if (eb->h_next_leaf_blk == 0) {
3160 /*
3161 * This gets a bit tricky if we're going to delete the
3162 * rightmost path. Get the other cases out of the way
3163 * 1st.
3164 */
3165 if (le16_to_cpu(el->l_next_free_rec) > 1)
3166 goto rightmost_no_delete;
3167
3168 if (le16_to_cpu(el->l_next_free_rec) == 0) {
3169 ret = -EIO;
3212 */
3213
3214 eb = (struct ocfs2_extent_block *)path_leaf_bh(path)->b_data;
3215 el = &eb->h_list;
3216 if (eb->h_next_leaf_blk == 0) {
3217 /*
3218 * This gets a bit tricky if we're going to delete the
3219 * rightmost path. Get the other cases out of the way
3220 * 1st.
3221 */
3222 if (le16_to_cpu(el->l_next_free_rec) > 1)
3223 goto rightmost_no_delete;
3224
3225 if (le16_to_cpu(el->l_next_free_rec) == 0) {
3226 ret = -EIO;
3170 ocfs2_error(inode->i_sb,
3171 "Inode %llu has empty extent block at %llu",
3172 (unsigned long long)OCFS2_I(inode)->ip_blkno,
3227 ocfs2_error(ocfs2_metadata_cache_get_super(et->et_ci),
3228 "Owner %llu has empty extent block at %llu",
3229 (unsigned long long)ocfs2_metadata_cache_owner(et->et_ci),
3173 (unsigned long long)le64_to_cpu(eb->h_blkno));
3174 goto out;
3175 }
3176
3177 /*
3178 * XXX: The caller can not trust "path" any more after
3179 * this as it will have been deleted. What do we do?
3180 *
3181 * In theory the rotate-for-merge code will never get
3182 * here because it'll always ask for a rotate in a
3183 * nonempty list.
3184 */
3185
3230 (unsigned long long)le64_to_cpu(eb->h_blkno));
3231 goto out;
3232 }
3233
3234 /*
3235 * XXX: The caller can not trust "path" any more after
3236 * this as it will have been deleted. What do we do?
3237 *
3238 * In theory the rotate-for-merge code will never get
3239 * here because it'll always ask for a rotate in a
3240 * nonempty list.
3241 */
3242
3186 ret = ocfs2_remove_rightmost_path(inode, handle, path,
3187 dealloc, et);
3243 ret = ocfs2_remove_rightmost_path(handle, et, path,
3244 dealloc);
3188 if (ret)
3189 mlog_errno(ret);
3190 goto out;
3191 }
3192
3193 /*
3194 * Now we can loop, remembering the path we get from -EAGAIN
3195 * and restarting from there.
3196 */
3197try_rotate:
3245 if (ret)
3246 mlog_errno(ret);
3247 goto out;
3248 }
3249
3250 /*
3251 * Now we can loop, remembering the path we get from -EAGAIN
3252 * and restarting from there.
3253 */
3254try_rotate:
3198 ret = __ocfs2_rotate_tree_left(inode, handle, orig_credits, path,
3199 dealloc, &restart_path, et);
3255 ret = __ocfs2_rotate_tree_left(handle, et, orig_credits, path,
3256 dealloc, &restart_path);
3200 if (ret && ret != -EAGAIN) {
3201 mlog_errno(ret);
3202 goto out;
3203 }
3204
3205 while (ret == -EAGAIN) {
3206 tmp_path = restart_path;
3207 restart_path = NULL;
3208
3257 if (ret && ret != -EAGAIN) {
3258 mlog_errno(ret);
3259 goto out;
3260 }
3261
3262 while (ret == -EAGAIN) {
3263 tmp_path = restart_path;
3264 restart_path = NULL;
3265
3209 ret = __ocfs2_rotate_tree_left(inode, handle, orig_credits,
3266 ret = __ocfs2_rotate_tree_left(handle, et, orig_credits,
3210 tmp_path, dealloc,
3267 tmp_path, dealloc,
3211 &restart_path, et);
3268 &restart_path);
3212 if (ret && ret != -EAGAIN) {
3213 mlog_errno(ret);
3214 goto out;
3215 }
3216
3217 ocfs2_free_path(tmp_path);
3218 tmp_path = NULL;
3219

--- 34 unchanged lines hidden (view full) ---

3254 * Always memset - the caller doesn't check whether it
3255 * created an empty extent, so there could be junk in
3256 * the other fields.
3257 */
3258 memset(&el->l_recs[0], 0, sizeof(struct ocfs2_extent_rec));
3259 }
3260}
3261
3269 if (ret && ret != -EAGAIN) {
3270 mlog_errno(ret);
3271 goto out;
3272 }
3273
3274 ocfs2_free_path(tmp_path);
3275 tmp_path = NULL;
3276

--- 34 unchanged lines hidden (view full) ---

3311 * Always memset - the caller doesn't check whether it
3312 * created an empty extent, so there could be junk in
3313 * the other fields.
3314 */
3315 memset(&el->l_recs[0], 0, sizeof(struct ocfs2_extent_rec));
3316 }
3317}
3318
3262static int ocfs2_get_right_path(struct inode *inode,
3319static int ocfs2_get_right_path(struct ocfs2_extent_tree *et,
3263 struct ocfs2_path *left_path,
3264 struct ocfs2_path **ret_right_path)
3265{
3266 int ret;
3267 u32 right_cpos;
3268 struct ocfs2_path *right_path = NULL;
3269 struct ocfs2_extent_list *left_el;
3270
3271 *ret_right_path = NULL;
3272
3273 /* This function shouldn't be called for non-trees. */
3274 BUG_ON(left_path->p_tree_depth == 0);
3275
3276 left_el = path_leaf_el(left_path);
3277 BUG_ON(left_el->l_next_free_rec != left_el->l_count);
3278
3320 struct ocfs2_path *left_path,
3321 struct ocfs2_path **ret_right_path)
3322{
3323 int ret;
3324 u32 right_cpos;
3325 struct ocfs2_path *right_path = NULL;
3326 struct ocfs2_extent_list *left_el;
3327
3328 *ret_right_path = NULL;
3329
3330 /* This function shouldn't be called for non-trees. */
3331 BUG_ON(left_path->p_tree_depth == 0);
3332
3333 left_el = path_leaf_el(left_path);
3334 BUG_ON(left_el->l_next_free_rec != left_el->l_count);
3335
3279 ret = ocfs2_find_cpos_for_right_leaf(inode->i_sb, left_path,
3280 &right_cpos);
3336 ret = ocfs2_find_cpos_for_right_leaf(ocfs2_metadata_cache_get_super(et->et_ci),
3337 left_path, &right_cpos);
3281 if (ret) {
3282 mlog_errno(ret);
3283 goto out;
3284 }
3285
3286 /* This function shouldn't be called for the rightmost leaf. */
3287 BUG_ON(right_cpos == 0);
3288
3289 right_path = ocfs2_new_path_from_path(left_path);
3290 if (!right_path) {
3291 ret = -ENOMEM;
3292 mlog_errno(ret);
3293 goto out;
3294 }
3295
3338 if (ret) {
3339 mlog_errno(ret);
3340 goto out;
3341 }
3342
3343 /* This function shouldn't be called for the rightmost leaf. */
3344 BUG_ON(right_cpos == 0);
3345
3346 right_path = ocfs2_new_path_from_path(left_path);
3347 if (!right_path) {
3348 ret = -ENOMEM;
3349 mlog_errno(ret);
3350 goto out;
3351 }
3352
3296 ret = ocfs2_find_path(inode, right_path, right_cpos);
3353 ret = ocfs2_find_path(et->et_ci, right_path, right_cpos);
3297 if (ret) {
3298 mlog_errno(ret);
3299 goto out;
3300 }
3301
3302 *ret_right_path = right_path;
3303out:
3304 if (ret)
3305 ocfs2_free_path(right_path);
3306 return ret;
3307}
3308
3309/*
3310 * Remove split_rec clusters from the record at index and merge them
3311 * onto the beginning of the record "next" to it.
3312 * For index < l_count - 1, the next means the extent rec at index + 1.
3313 * For index == l_count - 1, the "next" means the 1st extent rec of the
3314 * next extent block.
3315 */
3354 if (ret) {
3355 mlog_errno(ret);
3356 goto out;
3357 }
3358
3359 *ret_right_path = right_path;
3360out:
3361 if (ret)
3362 ocfs2_free_path(right_path);
3363 return ret;
3364}
3365
3366/*
3367 * Remove split_rec clusters from the record at index and merge them
3368 * onto the beginning of the record "next" to it.
3369 * For index < l_count - 1, the next means the extent rec at index + 1.
3370 * For index == l_count - 1, the "next" means the 1st extent rec of the
3371 * next extent block.
3372 */
3316static int ocfs2_merge_rec_right(struct inode *inode,
3317 struct ocfs2_path *left_path,
3373static int ocfs2_merge_rec_right(struct ocfs2_path *left_path,
3318 handle_t *handle,
3374 handle_t *handle,
3375 struct ocfs2_extent_tree *et,
3319 struct ocfs2_extent_rec *split_rec,
3320 int index)
3321{
3322 int ret, next_free, i;
3323 unsigned int split_clusters = le16_to_cpu(split_rec->e_leaf_clusters);
3324 struct ocfs2_extent_rec *left_rec;
3325 struct ocfs2_extent_rec *right_rec;
3326 struct ocfs2_extent_list *right_el;

--- 4 unchanged lines hidden (view full) ---

3331 struct buffer_head *root_bh = NULL;
3332
3333 BUG_ON(index >= le16_to_cpu(el->l_next_free_rec));
3334 left_rec = &el->l_recs[index];
3335
3336 if (index == le16_to_cpu(el->l_next_free_rec) - 1 &&
3337 le16_to_cpu(el->l_next_free_rec) == le16_to_cpu(el->l_count)) {
3338 /* we meet with a cross extent block merge. */
3376 struct ocfs2_extent_rec *split_rec,
3377 int index)
3378{
3379 int ret, next_free, i;
3380 unsigned int split_clusters = le16_to_cpu(split_rec->e_leaf_clusters);
3381 struct ocfs2_extent_rec *left_rec;
3382 struct ocfs2_extent_rec *right_rec;
3383 struct ocfs2_extent_list *right_el;

--- 4 unchanged lines hidden (view full) ---

3388 struct buffer_head *root_bh = NULL;
3389
3390 BUG_ON(index >= le16_to_cpu(el->l_next_free_rec));
3391 left_rec = &el->l_recs[index];
3392
3393 if (index == le16_to_cpu(el->l_next_free_rec) - 1 &&
3394 le16_to_cpu(el->l_next_free_rec) == le16_to_cpu(el->l_count)) {
3395 /* we meet with a cross extent block merge. */
3339 ret = ocfs2_get_right_path(inode, left_path, &right_path);
3396 ret = ocfs2_get_right_path(et, left_path, &right_path);
3340 if (ret) {
3341 mlog_errno(ret);
3342 goto out;
3343 }
3344
3345 right_el = path_leaf_el(right_path);
3346 next_free = le16_to_cpu(right_el->l_next_free_rec);
3347 BUG_ON(next_free <= 0);
3348 right_rec = &right_el->l_recs[0];
3349 if (ocfs2_is_empty_extent(right_rec)) {
3350 BUG_ON(next_free <= 1);
3351 right_rec = &right_el->l_recs[1];
3352 }
3353
3354 BUG_ON(le32_to_cpu(left_rec->e_cpos) +
3355 le16_to_cpu(left_rec->e_leaf_clusters) !=
3356 le32_to_cpu(right_rec->e_cpos));
3357
3397 if (ret) {
3398 mlog_errno(ret);
3399 goto out;
3400 }
3401
3402 right_el = path_leaf_el(right_path);
3403 next_free = le16_to_cpu(right_el->l_next_free_rec);
3404 BUG_ON(next_free <= 0);
3405 right_rec = &right_el->l_recs[0];
3406 if (ocfs2_is_empty_extent(right_rec)) {
3407 BUG_ON(next_free <= 1);
3408 right_rec = &right_el->l_recs[1];
3409 }
3410
3411 BUG_ON(le32_to_cpu(left_rec->e_cpos) +
3412 le16_to_cpu(left_rec->e_leaf_clusters) !=
3413 le32_to_cpu(right_rec->e_cpos));
3414
3358 subtree_index = ocfs2_find_subtree_root(inode,
3359 left_path, right_path);
3415 subtree_index = ocfs2_find_subtree_root(et, left_path,
3416 right_path);
3360
3361 ret = ocfs2_extend_rotate_transaction(handle, subtree_index,
3362 handle->h_buffer_credits,
3363 right_path);
3364 if (ret) {
3365 mlog_errno(ret);
3366 goto out;
3367 }
3368
3369 root_bh = left_path->p_node[subtree_index].bh;
3370 BUG_ON(root_bh != right_path->p_node[subtree_index].bh);
3371
3417
3418 ret = ocfs2_extend_rotate_transaction(handle, subtree_index,
3419 handle->h_buffer_credits,
3420 right_path);
3421 if (ret) {
3422 mlog_errno(ret);
3423 goto out;
3424 }
3425
3426 root_bh = left_path->p_node[subtree_index].bh;
3427 BUG_ON(root_bh != right_path->p_node[subtree_index].bh);
3428
3372 ret = ocfs2_path_bh_journal_access(handle, inode, right_path,
3429 ret = ocfs2_path_bh_journal_access(handle, et->et_ci, right_path,
3373 subtree_index);
3374 if (ret) {
3375 mlog_errno(ret);
3376 goto out;
3377 }
3378
3379 for (i = subtree_index + 1;
3380 i < path_num_items(right_path); i++) {
3430 subtree_index);
3431 if (ret) {
3432 mlog_errno(ret);
3433 goto out;
3434 }
3435
3436 for (i = subtree_index + 1;
3437 i < path_num_items(right_path); i++) {
3381 ret = ocfs2_path_bh_journal_access(handle, inode,
3438 ret = ocfs2_path_bh_journal_access(handle, et->et_ci,
3382 right_path, i);
3383 if (ret) {
3384 mlog_errno(ret);
3385 goto out;
3386 }
3387
3439 right_path, i);
3440 if (ret) {
3441 mlog_errno(ret);
3442 goto out;
3443 }
3444
3388 ret = ocfs2_path_bh_journal_access(handle, inode,
3445 ret = ocfs2_path_bh_journal_access(handle, et->et_ci,
3389 left_path, i);
3390 if (ret) {
3391 mlog_errno(ret);
3392 goto out;
3393 }
3394 }
3395
3396 } else {
3397 BUG_ON(index == le16_to_cpu(el->l_next_free_rec) - 1);
3398 right_rec = &el->l_recs[index + 1];
3399 }
3400
3446 left_path, i);
3447 if (ret) {
3448 mlog_errno(ret);
3449 goto out;
3450 }
3451 }
3452
3453 } else {
3454 BUG_ON(index == le16_to_cpu(el->l_next_free_rec) - 1);
3455 right_rec = &el->l_recs[index + 1];
3456 }
3457
3401 ret = ocfs2_path_bh_journal_access(handle, inode, left_path,
3458 ret = ocfs2_path_bh_journal_access(handle, et->et_ci, left_path,
3402 path_num_items(left_path) - 1);
3403 if (ret) {
3404 mlog_errno(ret);
3405 goto out;
3406 }
3407
3408 le16_add_cpu(&left_rec->e_leaf_clusters, -split_clusters);
3409
3410 le32_add_cpu(&right_rec->e_cpos, -split_clusters);
3411 le64_add_cpu(&right_rec->e_blkno,
3459 path_num_items(left_path) - 1);
3460 if (ret) {
3461 mlog_errno(ret);
3462 goto out;
3463 }
3464
3465 le16_add_cpu(&left_rec->e_leaf_clusters, -split_clusters);
3466
3467 le32_add_cpu(&right_rec->e_cpos, -split_clusters);
3468 le64_add_cpu(&right_rec->e_blkno,
3412 -ocfs2_clusters_to_blocks(inode->i_sb, split_clusters));
3469 -ocfs2_clusters_to_blocks(ocfs2_metadata_cache_get_super(et->et_ci),
3470 split_clusters));
3413 le16_add_cpu(&right_rec->e_leaf_clusters, split_clusters);
3414
3415 ocfs2_cleanup_merge(el, index);
3416
3417 ret = ocfs2_journal_dirty(handle, bh);
3418 if (ret)
3419 mlog_errno(ret);
3420
3421 if (right_path) {
3422 ret = ocfs2_journal_dirty(handle, path_leaf_bh(right_path));
3423 if (ret)
3424 mlog_errno(ret);
3425
3471 le16_add_cpu(&right_rec->e_leaf_clusters, split_clusters);
3472
3473 ocfs2_cleanup_merge(el, index);
3474
3475 ret = ocfs2_journal_dirty(handle, bh);
3476 if (ret)
3477 mlog_errno(ret);
3478
3479 if (right_path) {
3480 ret = ocfs2_journal_dirty(handle, path_leaf_bh(right_path));
3481 if (ret)
3482 mlog_errno(ret);
3483
3426 ocfs2_complete_edge_insert(inode, handle, left_path,
3427 right_path, subtree_index);
3484 ocfs2_complete_edge_insert(handle, left_path, right_path,
3485 subtree_index);
3428 }
3429out:
3430 if (right_path)
3431 ocfs2_free_path(right_path);
3432 return ret;
3433}
3434
3486 }
3487out:
3488 if (right_path)
3489 ocfs2_free_path(right_path);
3490 return ret;
3491}
3492
3435static int ocfs2_get_left_path(struct inode *inode,
3493static int ocfs2_get_left_path(struct ocfs2_extent_tree *et,
3436 struct ocfs2_path *right_path,
3437 struct ocfs2_path **ret_left_path)
3438{
3439 int ret;
3440 u32 left_cpos;
3441 struct ocfs2_path *left_path = NULL;
3442
3443 *ret_left_path = NULL;
3444
3445 /* This function shouldn't be called for non-trees. */
3446 BUG_ON(right_path->p_tree_depth == 0);
3447
3494 struct ocfs2_path *right_path,
3495 struct ocfs2_path **ret_left_path)
3496{
3497 int ret;
3498 u32 left_cpos;
3499 struct ocfs2_path *left_path = NULL;
3500
3501 *ret_left_path = NULL;
3502
3503 /* This function shouldn't be called for non-trees. */
3504 BUG_ON(right_path->p_tree_depth == 0);
3505
3448 ret = ocfs2_find_cpos_for_left_leaf(inode->i_sb,
3506 ret = ocfs2_find_cpos_for_left_leaf(ocfs2_metadata_cache_get_super(et->et_ci),
3449 right_path, &left_cpos);
3450 if (ret) {
3451 mlog_errno(ret);
3452 goto out;
3453 }
3454
3455 /* This function shouldn't be called for the leftmost leaf. */
3456 BUG_ON(left_cpos == 0);
3457
3458 left_path = ocfs2_new_path_from_path(right_path);
3459 if (!left_path) {
3460 ret = -ENOMEM;
3461 mlog_errno(ret);
3462 goto out;
3463 }
3464
3507 right_path, &left_cpos);
3508 if (ret) {
3509 mlog_errno(ret);
3510 goto out;
3511 }
3512
3513 /* This function shouldn't be called for the leftmost leaf. */
3514 BUG_ON(left_cpos == 0);
3515
3516 left_path = ocfs2_new_path_from_path(right_path);
3517 if (!left_path) {
3518 ret = -ENOMEM;
3519 mlog_errno(ret);
3520 goto out;
3521 }
3522
3465 ret = ocfs2_find_path(inode, left_path, left_cpos);
3523 ret = ocfs2_find_path(et->et_ci, left_path, left_cpos);
3466 if (ret) {
3467 mlog_errno(ret);
3468 goto out;
3469 }
3470
3471 *ret_left_path = left_path;
3472out:
3473 if (ret)

--- 6 unchanged lines hidden (view full) ---

3480 * onto the tail of the record "before" it.
3481 * For index > 0, the "before" means the extent rec at index - 1.
3482 *
3483 * For index == 0, the "before" means the last record of the previous
3484 * extent block. And there is also a situation that we may need to
3485 * remove the rightmost leaf extent block in the right_path and change
3486 * the right path to indicate the new rightmost path.
3487 */
3524 if (ret) {
3525 mlog_errno(ret);
3526 goto out;
3527 }
3528
3529 *ret_left_path = left_path;
3530out:
3531 if (ret)

--- 6 unchanged lines hidden (view full) ---

3538 * onto the tail of the record "before" it.
3539 * For index > 0, the "before" means the extent rec at index - 1.
3540 *
3541 * For index == 0, the "before" means the last record of the previous
3542 * extent block. And there is also a situation that we may need to
3543 * remove the rightmost leaf extent block in the right_path and change
3544 * the right path to indicate the new rightmost path.
3545 */
3488static int ocfs2_merge_rec_left(struct inode *inode,
3489 struct ocfs2_path *right_path,
3546static int ocfs2_merge_rec_left(struct ocfs2_path *right_path,
3490 handle_t *handle,
3547 handle_t *handle,
3548 struct ocfs2_extent_tree *et,
3491 struct ocfs2_extent_rec *split_rec,
3492 struct ocfs2_cached_dealloc_ctxt *dealloc,
3549 struct ocfs2_extent_rec *split_rec,
3550 struct ocfs2_cached_dealloc_ctxt *dealloc,
3493 struct ocfs2_extent_tree *et,
3494 int index)
3495{
3496 int ret, i, subtree_index = 0, has_empty_extent = 0;
3497 unsigned int split_clusters = le16_to_cpu(split_rec->e_leaf_clusters);
3498 struct ocfs2_extent_rec *left_rec;
3499 struct ocfs2_extent_rec *right_rec;
3500 struct ocfs2_extent_list *el = path_leaf_el(right_path);
3501 struct buffer_head *bh = path_leaf_bh(right_path);
3502 struct buffer_head *root_bh = NULL;
3503 struct ocfs2_path *left_path = NULL;
3504 struct ocfs2_extent_list *left_el;
3505
3506 BUG_ON(index < 0);
3507
3508 right_rec = &el->l_recs[index];
3509 if (index == 0) {
3510 /* we meet with a cross extent block merge. */
3551 int index)
3552{
3553 int ret, i, subtree_index = 0, has_empty_extent = 0;
3554 unsigned int split_clusters = le16_to_cpu(split_rec->e_leaf_clusters);
3555 struct ocfs2_extent_rec *left_rec;
3556 struct ocfs2_extent_rec *right_rec;
3557 struct ocfs2_extent_list *el = path_leaf_el(right_path);
3558 struct buffer_head *bh = path_leaf_bh(right_path);
3559 struct buffer_head *root_bh = NULL;
3560 struct ocfs2_path *left_path = NULL;
3561 struct ocfs2_extent_list *left_el;
3562
3563 BUG_ON(index < 0);
3564
3565 right_rec = &el->l_recs[index];
3566 if (index == 0) {
3567 /* we meet with a cross extent block merge. */
3511 ret = ocfs2_get_left_path(inode, right_path, &left_path);
3568 ret = ocfs2_get_left_path(et, right_path, &left_path);
3512 if (ret) {
3513 mlog_errno(ret);
3514 goto out;
3515 }
3516
3517 left_el = path_leaf_el(left_path);
3518 BUG_ON(le16_to_cpu(left_el->l_next_free_rec) !=
3519 le16_to_cpu(left_el->l_count));
3520
3521 left_rec = &left_el->l_recs[
3522 le16_to_cpu(left_el->l_next_free_rec) - 1];
3523 BUG_ON(le32_to_cpu(left_rec->e_cpos) +
3524 le16_to_cpu(left_rec->e_leaf_clusters) !=
3525 le32_to_cpu(split_rec->e_cpos));
3526
3569 if (ret) {
3570 mlog_errno(ret);
3571 goto out;
3572 }
3573
3574 left_el = path_leaf_el(left_path);
3575 BUG_ON(le16_to_cpu(left_el->l_next_free_rec) !=
3576 le16_to_cpu(left_el->l_count));
3577
3578 left_rec = &left_el->l_recs[
3579 le16_to_cpu(left_el->l_next_free_rec) - 1];
3580 BUG_ON(le32_to_cpu(left_rec->e_cpos) +
3581 le16_to_cpu(left_rec->e_leaf_clusters) !=
3582 le32_to_cpu(split_rec->e_cpos));
3583
3527 subtree_index = ocfs2_find_subtree_root(inode,
3528 left_path, right_path);
3584 subtree_index = ocfs2_find_subtree_root(et, left_path,
3585 right_path);
3529
3530 ret = ocfs2_extend_rotate_transaction(handle, subtree_index,
3531 handle->h_buffer_credits,
3532 left_path);
3533 if (ret) {
3534 mlog_errno(ret);
3535 goto out;
3536 }
3537
3538 root_bh = left_path->p_node[subtree_index].bh;
3539 BUG_ON(root_bh != right_path->p_node[subtree_index].bh);
3540
3586
3587 ret = ocfs2_extend_rotate_transaction(handle, subtree_index,
3588 handle->h_buffer_credits,
3589 left_path);
3590 if (ret) {
3591 mlog_errno(ret);
3592 goto out;
3593 }
3594
3595 root_bh = left_path->p_node[subtree_index].bh;
3596 BUG_ON(root_bh != right_path->p_node[subtree_index].bh);
3597
3541 ret = ocfs2_path_bh_journal_access(handle, inode, right_path,
3598 ret = ocfs2_path_bh_journal_access(handle, et->et_ci, right_path,
3542 subtree_index);
3543 if (ret) {
3544 mlog_errno(ret);
3545 goto out;
3546 }
3547
3548 for (i = subtree_index + 1;
3549 i < path_num_items(right_path); i++) {
3599 subtree_index);
3600 if (ret) {
3601 mlog_errno(ret);
3602 goto out;
3603 }
3604
3605 for (i = subtree_index + 1;
3606 i < path_num_items(right_path); i++) {
3550 ret = ocfs2_path_bh_journal_access(handle, inode,
3607 ret = ocfs2_path_bh_journal_access(handle, et->et_ci,
3551 right_path, i);
3552 if (ret) {
3553 mlog_errno(ret);
3554 goto out;
3555 }
3556
3608 right_path, i);
3609 if (ret) {
3610 mlog_errno(ret);
3611 goto out;
3612 }
3613
3557 ret = ocfs2_path_bh_journal_access(handle, inode,
3614 ret = ocfs2_path_bh_journal_access(handle, et->et_ci,
3558 left_path, i);
3559 if (ret) {
3560 mlog_errno(ret);
3561 goto out;
3562 }
3563 }
3564 } else {
3565 left_rec = &el->l_recs[index - 1];
3566 if (ocfs2_is_empty_extent(&el->l_recs[0]))
3567 has_empty_extent = 1;
3568 }
3569
3615 left_path, i);
3616 if (ret) {
3617 mlog_errno(ret);
3618 goto out;
3619 }
3620 }
3621 } else {
3622 left_rec = &el->l_recs[index - 1];
3623 if (ocfs2_is_empty_extent(&el->l_recs[0]))
3624 has_empty_extent = 1;
3625 }
3626
3570 ret = ocfs2_path_bh_journal_access(handle, inode, right_path,
3627 ret = ocfs2_path_bh_journal_access(handle, et->et_ci, right_path,
3571 path_num_items(right_path) - 1);
3572 if (ret) {
3573 mlog_errno(ret);
3574 goto out;
3575 }
3576
3577 if (has_empty_extent && index == 1) {
3578 /*
3579 * The easy case - we can just plop the record right in.
3580 */
3581 *left_rec = *split_rec;
3582
3583 has_empty_extent = 0;
3584 } else
3585 le16_add_cpu(&left_rec->e_leaf_clusters, split_clusters);
3586
3587 le32_add_cpu(&right_rec->e_cpos, split_clusters);
3588 le64_add_cpu(&right_rec->e_blkno,
3628 path_num_items(right_path) - 1);
3629 if (ret) {
3630 mlog_errno(ret);
3631 goto out;
3632 }
3633
3634 if (has_empty_extent && index == 1) {
3635 /*
3636 * The easy case - we can just plop the record right in.
3637 */
3638 *left_rec = *split_rec;
3639
3640 has_empty_extent = 0;
3641 } else
3642 le16_add_cpu(&left_rec->e_leaf_clusters, split_clusters);
3643
3644 le32_add_cpu(&right_rec->e_cpos, split_clusters);
3645 le64_add_cpu(&right_rec->e_blkno,
3589 ocfs2_clusters_to_blocks(inode->i_sb, split_clusters));
3646 ocfs2_clusters_to_blocks(ocfs2_metadata_cache_get_super(et->et_ci),
3647 split_clusters));
3590 le16_add_cpu(&right_rec->e_leaf_clusters, -split_clusters);
3591
3592 ocfs2_cleanup_merge(el, index);
3593
3594 ret = ocfs2_journal_dirty(handle, bh);
3595 if (ret)
3596 mlog_errno(ret);
3597

--- 5 unchanged lines hidden (view full) ---

3603 /*
3604 * In the situation that the right_rec is empty and the extent
3605 * block is empty also, ocfs2_complete_edge_insert can't handle
3606 * it and we need to delete the right extent block.
3607 */
3608 if (le16_to_cpu(right_rec->e_leaf_clusters) == 0 &&
3609 le16_to_cpu(el->l_next_free_rec) == 1) {
3610
3648 le16_add_cpu(&right_rec->e_leaf_clusters, -split_clusters);
3649
3650 ocfs2_cleanup_merge(el, index);
3651
3652 ret = ocfs2_journal_dirty(handle, bh);
3653 if (ret)
3654 mlog_errno(ret);
3655

--- 5 unchanged lines hidden (view full) ---

3661 /*
3662 * In the situation that the right_rec is empty and the extent
3663 * block is empty also, ocfs2_complete_edge_insert can't handle
3664 * it and we need to delete the right extent block.
3665 */
3666 if (le16_to_cpu(right_rec->e_leaf_clusters) == 0 &&
3667 le16_to_cpu(el->l_next_free_rec) == 1) {
3668
3611 ret = ocfs2_remove_rightmost_path(inode, handle,
3669 ret = ocfs2_remove_rightmost_path(handle, et,
3612 right_path,
3670 right_path,
3613 dealloc, et);
3671 dealloc);
3614 if (ret) {
3615 mlog_errno(ret);
3616 goto out;
3617 }
3618
3619 /* Now the rightmost extent block has been deleted.
3620 * So we use the new rightmost path.
3621 */
3622 ocfs2_mv_path(right_path, left_path);
3623 left_path = NULL;
3624 } else
3672 if (ret) {
3673 mlog_errno(ret);
3674 goto out;
3675 }
3676
3677 /* Now the rightmost extent block has been deleted.
3678 * So we use the new rightmost path.
3679 */
3680 ocfs2_mv_path(right_path, left_path);
3681 left_path = NULL;
3682 } else
3625 ocfs2_complete_edge_insert(inode, handle, left_path,
3683 ocfs2_complete_edge_insert(handle, left_path,
3626 right_path, subtree_index);
3627 }
3628out:
3629 if (left_path)
3630 ocfs2_free_path(left_path);
3631 return ret;
3632}
3633
3684 right_path, subtree_index);
3685 }
3686out:
3687 if (left_path)
3688 ocfs2_free_path(left_path);
3689 return ret;
3690}
3691
3634static int ocfs2_try_to_merge_extent(struct inode *inode,
3635 handle_t *handle,
3692static int ocfs2_try_to_merge_extent(handle_t *handle,
3693 struct ocfs2_extent_tree *et,
3636 struct ocfs2_path *path,
3637 int split_index,
3638 struct ocfs2_extent_rec *split_rec,
3639 struct ocfs2_cached_dealloc_ctxt *dealloc,
3694 struct ocfs2_path *path,
3695 int split_index,
3696 struct ocfs2_extent_rec *split_rec,
3697 struct ocfs2_cached_dealloc_ctxt *dealloc,
3640 struct ocfs2_merge_ctxt *ctxt,
3641 struct ocfs2_extent_tree *et)
3642
3698 struct ocfs2_merge_ctxt *ctxt)
3643{
3644 int ret = 0;
3645 struct ocfs2_extent_list *el = path_leaf_el(path);
3646 struct ocfs2_extent_rec *rec = &el->l_recs[split_index];
3647
3648 BUG_ON(ctxt->c_contig_type == CONTIG_NONE);
3649
3650 if (ctxt->c_split_covers_rec && ctxt->c_has_empty_extent) {
3651 /*
3652 * The merge code will need to create an empty
3653 * extent to take the place of the newly
3654 * emptied slot. Remove any pre-existing empty
3655 * extents - having more than one in a leaf is
3656 * illegal.
3657 */
3699{
3700 int ret = 0;
3701 struct ocfs2_extent_list *el = path_leaf_el(path);
3702 struct ocfs2_extent_rec *rec = &el->l_recs[split_index];
3703
3704 BUG_ON(ctxt->c_contig_type == CONTIG_NONE);
3705
3706 if (ctxt->c_split_covers_rec && ctxt->c_has_empty_extent) {
3707 /*
3708 * The merge code will need to create an empty
3709 * extent to take the place of the newly
3710 * emptied slot. Remove any pre-existing empty
3711 * extents - having more than one in a leaf is
3712 * illegal.
3713 */
3658 ret = ocfs2_rotate_tree_left(inode, handle, path,
3659 dealloc, et);
3714 ret = ocfs2_rotate_tree_left(handle, et, path, dealloc);
3660 if (ret) {
3661 mlog_errno(ret);
3662 goto out;
3663 }
3664 split_index--;
3665 rec = &el->l_recs[split_index];
3666 }
3667

--- 12 unchanged lines hidden (view full) ---

3680 * Since the adding of an empty extent shifts
3681 * everything back to the right, there's no need to
3682 * update split_index here.
3683 *
3684 * When the split_index is zero, we need to merge it to the
3685 * prevoius extent block. It is more efficient and easier
3686 * if we do merge_right first and merge_left later.
3687 */
3715 if (ret) {
3716 mlog_errno(ret);
3717 goto out;
3718 }
3719 split_index--;
3720 rec = &el->l_recs[split_index];
3721 }
3722

--- 12 unchanged lines hidden (view full) ---

3735 * Since the adding of an empty extent shifts
3736 * everything back to the right, there's no need to
3737 * update split_index here.
3738 *
3739 * When the split_index is zero, we need to merge it to the
3740 * prevoius extent block. It is more efficient and easier
3741 * if we do merge_right first and merge_left later.
3742 */
3688 ret = ocfs2_merge_rec_right(inode, path,
3689 handle, split_rec,
3743 ret = ocfs2_merge_rec_right(path, handle, et, split_rec,
3690 split_index);
3691 if (ret) {
3692 mlog_errno(ret);
3693 goto out;
3694 }
3695
3696 /*
3697 * We can only get this from logic error above.
3698 */
3699 BUG_ON(!ocfs2_is_empty_extent(&el->l_recs[0]));
3700
3701 /* The merge left us with an empty extent, remove it. */
3744 split_index);
3745 if (ret) {
3746 mlog_errno(ret);
3747 goto out;
3748 }
3749
3750 /*
3751 * We can only get this from logic error above.
3752 */
3753 BUG_ON(!ocfs2_is_empty_extent(&el->l_recs[0]));
3754
3755 /* The merge left us with an empty extent, remove it. */
3702 ret = ocfs2_rotate_tree_left(inode, handle, path,
3703 dealloc, et);
3756 ret = ocfs2_rotate_tree_left(handle, et, path, dealloc);
3704 if (ret) {
3705 mlog_errno(ret);
3706 goto out;
3707 }
3708
3709 rec = &el->l_recs[split_index];
3710
3711 /*
3712 * Note that we don't pass split_rec here on purpose -
3713 * we've merged it into the rec already.
3714 */
3757 if (ret) {
3758 mlog_errno(ret);
3759 goto out;
3760 }
3761
3762 rec = &el->l_recs[split_index];
3763
3764 /*
3765 * Note that we don't pass split_rec here on purpose -
3766 * we've merged it into the rec already.
3767 */
3715 ret = ocfs2_merge_rec_left(inode, path,
3716 handle, rec,
3717 dealloc, et,
3718 split_index);
3768 ret = ocfs2_merge_rec_left(path, handle, et, rec,
3769 dealloc, split_index);
3719
3720 if (ret) {
3721 mlog_errno(ret);
3722 goto out;
3723 }
3724
3770
3771 if (ret) {
3772 mlog_errno(ret);
3773 goto out;
3774 }
3775
3725 ret = ocfs2_rotate_tree_left(inode, handle, path,
3726 dealloc, et);
3776 ret = ocfs2_rotate_tree_left(handle, et, path, dealloc);
3727 /*
3728 * Error from this last rotate is not critical, so
3729 * print but don't bubble it up.
3730 */
3731 if (ret)
3732 mlog_errno(ret);
3733 ret = 0;
3734 } else {
3735 /*
3736 * Merge a record to the left or right.
3737 *
3738 * 'contig_type' is relative to the existing record,
3739 * so for example, if we're "right contig", it's to
3740 * the record on the left (hence the left merge).
3741 */
3742 if (ctxt->c_contig_type == CONTIG_RIGHT) {
3777 /*
3778 * Error from this last rotate is not critical, so
3779 * print but don't bubble it up.
3780 */
3781 if (ret)
3782 mlog_errno(ret);
3783 ret = 0;
3784 } else {
3785 /*
3786 * Merge a record to the left or right.
3787 *
3788 * 'contig_type' is relative to the existing record,
3789 * so for example, if we're "right contig", it's to
3790 * the record on the left (hence the left merge).
3791 */
3792 if (ctxt->c_contig_type == CONTIG_RIGHT) {
3743 ret = ocfs2_merge_rec_left(inode,
3744 path,
3745 handle, split_rec,
3746 dealloc, et,
3793 ret = ocfs2_merge_rec_left(path, handle, et,
3794 split_rec, dealloc,
3747 split_index);
3748 if (ret) {
3749 mlog_errno(ret);
3750 goto out;
3751 }
3752 } else {
3795 split_index);
3796 if (ret) {
3797 mlog_errno(ret);
3798 goto out;
3799 }
3800 } else {
3753 ret = ocfs2_merge_rec_right(inode,
3754 path,
3755 handle, split_rec,
3801 ret = ocfs2_merge_rec_right(path, handle,
3802 et, split_rec,
3756 split_index);
3757 if (ret) {
3758 mlog_errno(ret);
3759 goto out;
3760 }
3761 }
3762
3763 if (ctxt->c_split_covers_rec) {
3764 /*
3765 * The merge may have left an empty extent in
3766 * our leaf. Try to rotate it away.
3767 */
3803 split_index);
3804 if (ret) {
3805 mlog_errno(ret);
3806 goto out;
3807 }
3808 }
3809
3810 if (ctxt->c_split_covers_rec) {
3811 /*
3812 * The merge may have left an empty extent in
3813 * our leaf. Try to rotate it away.
3814 */
3768 ret = ocfs2_rotate_tree_left(inode, handle, path,
3769 dealloc, et);
3815 ret = ocfs2_rotate_tree_left(handle, et, path,
3816 dealloc);
3770 if (ret)
3771 mlog_errno(ret);
3772 ret = 0;
3773 }
3774 }
3775
3776out:
3777 return ret;

--- 29 unchanged lines hidden (view full) ---

3807 }
3808}
3809
3810/*
3811 * Do the final bits of extent record insertion at the target leaf
3812 * list. If this leaf is part of an allocation tree, it is assumed
3813 * that the tree above has been prepared.
3814 */
3817 if (ret)
3818 mlog_errno(ret);
3819 ret = 0;
3820 }
3821 }
3822
3823out:
3824 return ret;

--- 29 unchanged lines hidden (view full) ---

3854 }
3855}
3856
3857/*
3858 * Do the final bits of extent record insertion at the target leaf
3859 * list. If this leaf is part of an allocation tree, it is assumed
3860 * that the tree above has been prepared.
3861 */
3815static void ocfs2_insert_at_leaf(struct ocfs2_extent_rec *insert_rec,
3862static void ocfs2_insert_at_leaf(struct ocfs2_extent_tree *et,
3863 struct ocfs2_extent_rec *insert_rec,
3816 struct ocfs2_extent_list *el,
3864 struct ocfs2_extent_list *el,
3817 struct ocfs2_insert_type *insert,
3818 struct inode *inode)
3865 struct ocfs2_insert_type *insert)
3819{
3820 int i = insert->ins_contig_index;
3821 unsigned int range;
3822 struct ocfs2_extent_rec *rec;
3823
3824 BUG_ON(le16_to_cpu(el->l_tree_depth) != 0);
3825
3826 if (insert->ins_split != SPLIT_NONE) {
3827 i = ocfs2_search_extent_list(el, le32_to_cpu(insert_rec->e_cpos));
3828 BUG_ON(i == -1);
3829 rec = &el->l_recs[i];
3866{
3867 int i = insert->ins_contig_index;
3868 unsigned int range;
3869 struct ocfs2_extent_rec *rec;
3870
3871 BUG_ON(le16_to_cpu(el->l_tree_depth) != 0);
3872
3873 if (insert->ins_split != SPLIT_NONE) {
3874 i = ocfs2_search_extent_list(el, le32_to_cpu(insert_rec->e_cpos));
3875 BUG_ON(i == -1);
3876 rec = &el->l_recs[i];
3830 ocfs2_subtract_from_rec(inode->i_sb, insert->ins_split, rec,
3877 ocfs2_subtract_from_rec(ocfs2_metadata_cache_get_super(et->et_ci),
3878 insert->ins_split, rec,
3831 insert_rec);
3832 goto rotate;
3833 }
3834
3835 /*
3836 * Contiguous insert - either left or right.
3837 */
3838 if (insert->ins_contig != CONTIG_NONE) {

--- 25 unchanged lines hidden (view full) ---

3864 i = le16_to_cpu(el->l_next_free_rec) - 1;
3865 rec = &el->l_recs[i];
3866 range = le32_to_cpu(rec->e_cpos)
3867 + le16_to_cpu(rec->e_leaf_clusters);
3868 BUG_ON(le32_to_cpu(insert_rec->e_cpos) < range);
3869
3870 mlog_bug_on_msg(le16_to_cpu(el->l_next_free_rec) >=
3871 le16_to_cpu(el->l_count),
3879 insert_rec);
3880 goto rotate;
3881 }
3882
3883 /*
3884 * Contiguous insert - either left or right.
3885 */
3886 if (insert->ins_contig != CONTIG_NONE) {

--- 25 unchanged lines hidden (view full) ---

3912 i = le16_to_cpu(el->l_next_free_rec) - 1;
3913 rec = &el->l_recs[i];
3914 range = le32_to_cpu(rec->e_cpos)
3915 + le16_to_cpu(rec->e_leaf_clusters);
3916 BUG_ON(le32_to_cpu(insert_rec->e_cpos) < range);
3917
3918 mlog_bug_on_msg(le16_to_cpu(el->l_next_free_rec) >=
3919 le16_to_cpu(el->l_count),
3872 "inode %lu, depth %u, count %u, next free %u, "
3920 "owner %llu, depth %u, count %u, next free %u, "
3873 "rec.cpos %u, rec.clusters %u, "
3874 "insert.cpos %u, insert.clusters %u\n",
3921 "rec.cpos %u, rec.clusters %u, "
3922 "insert.cpos %u, insert.clusters %u\n",
3875 inode->i_ino,
3923 ocfs2_metadata_cache_owner(et->et_ci),
3876 le16_to_cpu(el->l_tree_depth),
3877 le16_to_cpu(el->l_count),
3878 le16_to_cpu(el->l_next_free_rec),
3879 le32_to_cpu(el->l_recs[i].e_cpos),
3880 le16_to_cpu(el->l_recs[i].e_leaf_clusters),
3881 le32_to_cpu(insert_rec->e_cpos),
3882 le16_to_cpu(insert_rec->e_leaf_clusters));
3883 i++;

--- 11 unchanged lines hidden (view full) ---

3895 * above.
3896 *
3897 * This leaf needs to have space, either by the empty 1st
3898 * extent record, or by virtue of an l_next_rec < l_count.
3899 */
3900 ocfs2_rotate_leaf(el, insert_rec);
3901}
3902
3924 le16_to_cpu(el->l_tree_depth),
3925 le16_to_cpu(el->l_count),
3926 le16_to_cpu(el->l_next_free_rec),
3927 le32_to_cpu(el->l_recs[i].e_cpos),
3928 le16_to_cpu(el->l_recs[i].e_leaf_clusters),
3929 le32_to_cpu(insert_rec->e_cpos),
3930 le16_to_cpu(insert_rec->e_leaf_clusters));
3931 i++;

--- 11 unchanged lines hidden (view full) ---

3943 * above.
3944 *
3945 * This leaf needs to have space, either by the empty 1st
3946 * extent record, or by virtue of an l_next_rec < l_count.
3947 */
3948 ocfs2_rotate_leaf(el, insert_rec);
3949}
3950
3903static void ocfs2_adjust_rightmost_records(struct inode *inode,
3904 handle_t *handle,
3951static void ocfs2_adjust_rightmost_records(handle_t *handle,
3952 struct ocfs2_extent_tree *et,
3905 struct ocfs2_path *path,
3906 struct ocfs2_extent_rec *insert_rec)
3907{
3908 int ret, i, next_free;
3909 struct buffer_head *bh;
3910 struct ocfs2_extent_list *el;
3911 struct ocfs2_extent_rec *rec;
3912
3913 /*
3914 * Update everything except the leaf block.
3915 */
3916 for (i = 0; i < path->p_tree_depth; i++) {
3917 bh = path->p_node[i].bh;
3918 el = path->p_node[i].el;
3919
3920 next_free = le16_to_cpu(el->l_next_free_rec);
3921 if (next_free == 0) {
3953 struct ocfs2_path *path,
3954 struct ocfs2_extent_rec *insert_rec)
3955{
3956 int ret, i, next_free;
3957 struct buffer_head *bh;
3958 struct ocfs2_extent_list *el;
3959 struct ocfs2_extent_rec *rec;
3960
3961 /*
3962 * Update everything except the leaf block.
3963 */
3964 for (i = 0; i < path->p_tree_depth; i++) {
3965 bh = path->p_node[i].bh;
3966 el = path->p_node[i].el;
3967
3968 next_free = le16_to_cpu(el->l_next_free_rec);
3969 if (next_free == 0) {
3922 ocfs2_error(inode->i_sb,
3923 "Dinode %llu has a bad extent list",
3924 (unsigned long long)OCFS2_I(inode)->ip_blkno);
3970 ocfs2_error(ocfs2_metadata_cache_get_super(et->et_ci),
3971 "Owner %llu has a bad extent list",
3972 (unsigned long long)ocfs2_metadata_cache_owner(et->et_ci));
3925 ret = -EIO;
3926 return;
3927 }
3928
3929 rec = &el->l_recs[next_free - 1];
3930
3931 rec->e_int_clusters = insert_rec->e_cpos;
3932 le32_add_cpu(&rec->e_int_clusters,
3933 le16_to_cpu(insert_rec->e_leaf_clusters));
3934 le32_add_cpu(&rec->e_int_clusters,
3935 -le32_to_cpu(rec->e_cpos));
3936
3937 ret = ocfs2_journal_dirty(handle, bh);
3938 if (ret)
3939 mlog_errno(ret);
3940
3941 }
3942}
3943
3973 ret = -EIO;
3974 return;
3975 }
3976
3977 rec = &el->l_recs[next_free - 1];
3978
3979 rec->e_int_clusters = insert_rec->e_cpos;
3980 le32_add_cpu(&rec->e_int_clusters,
3981 le16_to_cpu(insert_rec->e_leaf_clusters));
3982 le32_add_cpu(&rec->e_int_clusters,
3983 -le32_to_cpu(rec->e_cpos));
3984
3985 ret = ocfs2_journal_dirty(handle, bh);
3986 if (ret)
3987 mlog_errno(ret);
3988
3989 }
3990}
3991
3944static int ocfs2_append_rec_to_path(struct inode *inode, handle_t *handle,
3992static int ocfs2_append_rec_to_path(handle_t *handle,
3993 struct ocfs2_extent_tree *et,
3945 struct ocfs2_extent_rec *insert_rec,
3946 struct ocfs2_path *right_path,
3947 struct ocfs2_path **ret_left_path)
3948{
3949 int ret, next_free;
3950 struct ocfs2_extent_list *el;
3951 struct ocfs2_path *left_path = NULL;
3952

--- 11 unchanged lines hidden (view full) ---

3964 * neighboring path.
3965 */
3966 el = path_leaf_el(right_path);
3967 next_free = le16_to_cpu(el->l_next_free_rec);
3968 if (next_free == 0 ||
3969 (next_free == 1 && ocfs2_is_empty_extent(&el->l_recs[0]))) {
3970 u32 left_cpos;
3971
3994 struct ocfs2_extent_rec *insert_rec,
3995 struct ocfs2_path *right_path,
3996 struct ocfs2_path **ret_left_path)
3997{
3998 int ret, next_free;
3999 struct ocfs2_extent_list *el;
4000 struct ocfs2_path *left_path = NULL;
4001

--- 11 unchanged lines hidden (view full) ---

4013 * neighboring path.
4014 */
4015 el = path_leaf_el(right_path);
4016 next_free = le16_to_cpu(el->l_next_free_rec);
4017 if (next_free == 0 ||
4018 (next_free == 1 && ocfs2_is_empty_extent(&el->l_recs[0]))) {
4019 u32 left_cpos;
4020
3972 ret = ocfs2_find_cpos_for_left_leaf(inode->i_sb, right_path,
3973 &left_cpos);
4021 ret = ocfs2_find_cpos_for_left_leaf(ocfs2_metadata_cache_get_super(et->et_ci),
4022 right_path, &left_cpos);
3974 if (ret) {
3975 mlog_errno(ret);
3976 goto out;
3977 }
3978
3979 mlog(0, "Append may need a left path update. cpos: %u, "
3980 "left_cpos: %u\n", le32_to_cpu(insert_rec->e_cpos),
3981 left_cpos);

--- 5 unchanged lines hidden (view full) ---

3987 if (left_cpos) {
3988 left_path = ocfs2_new_path_from_path(right_path);
3989 if (!left_path) {
3990 ret = -ENOMEM;
3991 mlog_errno(ret);
3992 goto out;
3993 }
3994
4023 if (ret) {
4024 mlog_errno(ret);
4025 goto out;
4026 }
4027
4028 mlog(0, "Append may need a left path update. cpos: %u, "
4029 "left_cpos: %u\n", le32_to_cpu(insert_rec->e_cpos),
4030 left_cpos);

--- 5 unchanged lines hidden (view full) ---

4036 if (left_cpos) {
4037 left_path = ocfs2_new_path_from_path(right_path);
4038 if (!left_path) {
4039 ret = -ENOMEM;
4040 mlog_errno(ret);
4041 goto out;
4042 }
4043
3995 ret = ocfs2_find_path(inode, left_path, left_cpos);
4044 ret = ocfs2_find_path(et->et_ci, left_path,
4045 left_cpos);
3996 if (ret) {
3997 mlog_errno(ret);
3998 goto out;
3999 }
4000
4001 /*
4002 * ocfs2_insert_path() will pass the left_path to the
4003 * journal for us.
4004 */
4005 }
4006 }
4007
4046 if (ret) {
4047 mlog_errno(ret);
4048 goto out;
4049 }
4050
4051 /*
4052 * ocfs2_insert_path() will pass the left_path to the
4053 * journal for us.
4054 */
4055 }
4056 }
4057
4008 ret = ocfs2_journal_access_path(inode, handle, right_path);
4058 ret = ocfs2_journal_access_path(et->et_ci, handle, right_path);
4009 if (ret) {
4010 mlog_errno(ret);
4011 goto out;
4012 }
4013
4059 if (ret) {
4060 mlog_errno(ret);
4061 goto out;
4062 }
4063
4014 ocfs2_adjust_rightmost_records(inode, handle, right_path, insert_rec);
4064 ocfs2_adjust_rightmost_records(handle, et, right_path, insert_rec);
4015
4016 *ret_left_path = left_path;
4017 ret = 0;
4018out:
4019 if (ret != 0)
4020 ocfs2_free_path(left_path);
4021
4022 return ret;
4023}
4024
4065
4066 *ret_left_path = left_path;
4067 ret = 0;
4068out:
4069 if (ret != 0)
4070 ocfs2_free_path(left_path);
4071
4072 return ret;
4073}
4074
4025static void ocfs2_split_record(struct inode *inode,
4075static void ocfs2_split_record(struct ocfs2_extent_tree *et,
4026 struct ocfs2_path *left_path,
4027 struct ocfs2_path *right_path,
4028 struct ocfs2_extent_rec *split_rec,
4029 enum ocfs2_split_type split)
4030{
4031 int index;
4032 u32 cpos = le32_to_cpu(split_rec->e_cpos);
4033 struct ocfs2_extent_list *left_el = NULL, *right_el, *insert_el, *el;

--- 56 unchanged lines hidden (view full) ---

4090 */
4091 el = left_el;
4092 insert_el = left_el;
4093 index = ocfs2_search_extent_list(el, cpos);
4094 BUG_ON(index == -1);
4095 }
4096
4097 rec = &el->l_recs[index];
4076 struct ocfs2_path *left_path,
4077 struct ocfs2_path *right_path,
4078 struct ocfs2_extent_rec *split_rec,
4079 enum ocfs2_split_type split)
4080{
4081 int index;
4082 u32 cpos = le32_to_cpu(split_rec->e_cpos);
4083 struct ocfs2_extent_list *left_el = NULL, *right_el, *insert_el, *el;

--- 56 unchanged lines hidden (view full) ---

4140 */
4141 el = left_el;
4142 insert_el = left_el;
4143 index = ocfs2_search_extent_list(el, cpos);
4144 BUG_ON(index == -1);
4145 }
4146
4147 rec = &el->l_recs[index];
4098 ocfs2_subtract_from_rec(inode->i_sb, split, rec, split_rec);
4148 ocfs2_subtract_from_rec(ocfs2_metadata_cache_get_super(et->et_ci),
4149 split, rec, split_rec);
4099 ocfs2_rotate_leaf(insert_el, split_rec);
4100}
4101
4102/*
4103 * This function only does inserts on an allocation b-tree. For tree
4104 * depth = 0, ocfs2_insert_at_leaf() is called directly.
4105 *
4106 * right_path is the path we want to do the actual insert
4107 * in. left_path should only be passed in if we need to update that
4108 * portion of the tree after an edge insert.
4109 */
4150 ocfs2_rotate_leaf(insert_el, split_rec);
4151}
4152
4153/*
4154 * This function only does inserts on an allocation b-tree. For tree
4155 * depth = 0, ocfs2_insert_at_leaf() is called directly.
4156 *
4157 * right_path is the path we want to do the actual insert
4158 * in. left_path should only be passed in if we need to update that
4159 * portion of the tree after an edge insert.
4160 */
4110static int ocfs2_insert_path(struct inode *inode,
4111 handle_t *handle,
4161static int ocfs2_insert_path(handle_t *handle,
4162 struct ocfs2_extent_tree *et,
4112 struct ocfs2_path *left_path,
4113 struct ocfs2_path *right_path,
4114 struct ocfs2_extent_rec *insert_rec,
4115 struct ocfs2_insert_type *insert)
4116{
4117 int ret, subtree_index;
4118 struct buffer_head *leaf_bh = path_leaf_bh(right_path);
4119

--- 9 unchanged lines hidden (view full) ---

4129 credits += left_path->p_tree_depth;
4130
4131 ret = ocfs2_extend_trans(handle, credits);
4132 if (ret < 0) {
4133 mlog_errno(ret);
4134 goto out;
4135 }
4136
4163 struct ocfs2_path *left_path,
4164 struct ocfs2_path *right_path,
4165 struct ocfs2_extent_rec *insert_rec,
4166 struct ocfs2_insert_type *insert)
4167{
4168 int ret, subtree_index;
4169 struct buffer_head *leaf_bh = path_leaf_bh(right_path);
4170

--- 9 unchanged lines hidden (view full) ---

4180 credits += left_path->p_tree_depth;
4181
4182 ret = ocfs2_extend_trans(handle, credits);
4183 if (ret < 0) {
4184 mlog_errno(ret);
4185 goto out;
4186 }
4187
4137 ret = ocfs2_journal_access_path(inode, handle, left_path);
4188 ret = ocfs2_journal_access_path(et->et_ci, handle, left_path);
4138 if (ret < 0) {
4139 mlog_errno(ret);
4140 goto out;
4141 }
4142 }
4143
4144 /*
4145 * Pass both paths to the journal. The majority of inserts
4146 * will be touching all components anyway.
4147 */
4189 if (ret < 0) {
4190 mlog_errno(ret);
4191 goto out;
4192 }
4193 }
4194
4195 /*
4196 * Pass both paths to the journal. The majority of inserts
4197 * will be touching all components anyway.
4198 */
4148 ret = ocfs2_journal_access_path(inode, handle, right_path);
4199 ret = ocfs2_journal_access_path(et->et_ci, handle, right_path);
4149 if (ret < 0) {
4150 mlog_errno(ret);
4151 goto out;
4152 }
4153
4154 if (insert->ins_split != SPLIT_NONE) {
4155 /*
4156 * We could call ocfs2_insert_at_leaf() for some types
4157 * of splits, but it's easier to just let one separate
4158 * function sort it all out.
4159 */
4200 if (ret < 0) {
4201 mlog_errno(ret);
4202 goto out;
4203 }
4204
4205 if (insert->ins_split != SPLIT_NONE) {
4206 /*
4207 * We could call ocfs2_insert_at_leaf() for some types
4208 * of splits, but it's easier to just let one separate
4209 * function sort it all out.
4210 */
4160 ocfs2_split_record(inode, left_path, right_path,
4211 ocfs2_split_record(et, left_path, right_path,
4161 insert_rec, insert->ins_split);
4162
4163 /*
4164 * Split might have modified either leaf and we don't
4165 * have a guarantee that the later edge insert will
4166 * dirty this for us.
4167 */
4168 if (left_path)
4169 ret = ocfs2_journal_dirty(handle,
4170 path_leaf_bh(left_path));
4171 if (ret)
4172 mlog_errno(ret);
4173 } else
4212 insert_rec, insert->ins_split);
4213
4214 /*
4215 * Split might have modified either leaf and we don't
4216 * have a guarantee that the later edge insert will
4217 * dirty this for us.
4218 */
4219 if (left_path)
4220 ret = ocfs2_journal_dirty(handle,
4221 path_leaf_bh(left_path));
4222 if (ret)
4223 mlog_errno(ret);
4224 } else
4174 ocfs2_insert_at_leaf(insert_rec, path_leaf_el(right_path),
4175 insert, inode);
4225 ocfs2_insert_at_leaf(et, insert_rec, path_leaf_el(right_path),
4226 insert);
4176
4177 ret = ocfs2_journal_dirty(handle, leaf_bh);
4178 if (ret)
4179 mlog_errno(ret);
4180
4181 if (left_path) {
4182 /*
4183 * The rotate code has indicated that we need to fix
4184 * up portions of the tree after the insert.
4185 *
4186 * XXX: Should we extend the transaction here?
4187 */
4227
4228 ret = ocfs2_journal_dirty(handle, leaf_bh);
4229 if (ret)
4230 mlog_errno(ret);
4231
4232 if (left_path) {
4233 /*
4234 * The rotate code has indicated that we need to fix
4235 * up portions of the tree after the insert.
4236 *
4237 * XXX: Should we extend the transaction here?
4238 */
4188 subtree_index = ocfs2_find_subtree_root(inode, left_path,
4239 subtree_index = ocfs2_find_subtree_root(et, left_path,
4189 right_path);
4240 right_path);
4190 ocfs2_complete_edge_insert(inode, handle, left_path,
4191 right_path, subtree_index);
4241 ocfs2_complete_edge_insert(handle, left_path, right_path,
4242 subtree_index);
4192 }
4193
4194 ret = 0;
4195out:
4196 return ret;
4197}
4198
4243 }
4244
4245 ret = 0;
4246out:
4247 return ret;
4248}
4249
4199static int ocfs2_do_insert_extent(struct inode *inode,
4200 handle_t *handle,
4250static int ocfs2_do_insert_extent(handle_t *handle,
4201 struct ocfs2_extent_tree *et,
4202 struct ocfs2_extent_rec *insert_rec,
4203 struct ocfs2_insert_type *type)
4204{
4205 int ret, rotate = 0;
4206 u32 cpos;
4207 struct ocfs2_path *right_path = NULL;
4208 struct ocfs2_path *left_path = NULL;
4209 struct ocfs2_extent_list *el;
4210
4211 el = et->et_root_el;
4212
4251 struct ocfs2_extent_tree *et,
4252 struct ocfs2_extent_rec *insert_rec,
4253 struct ocfs2_insert_type *type)
4254{
4255 int ret, rotate = 0;
4256 u32 cpos;
4257 struct ocfs2_path *right_path = NULL;
4258 struct ocfs2_path *left_path = NULL;
4259 struct ocfs2_extent_list *el;
4260
4261 el = et->et_root_el;
4262
4213 ret = ocfs2_et_root_journal_access(handle, inode, et,
4263 ret = ocfs2_et_root_journal_access(handle, et,
4214 OCFS2_JOURNAL_ACCESS_WRITE);
4215 if (ret) {
4216 mlog_errno(ret);
4217 goto out;
4218 }
4219
4220 if (le16_to_cpu(el->l_tree_depth) == 0) {
4264 OCFS2_JOURNAL_ACCESS_WRITE);
4265 if (ret) {
4266 mlog_errno(ret);
4267 goto out;
4268 }
4269
4270 if (le16_to_cpu(el->l_tree_depth) == 0) {
4221 ocfs2_insert_at_leaf(insert_rec, el, type, inode);
4271 ocfs2_insert_at_leaf(et, insert_rec, el, type);
4222 goto out_update_clusters;
4223 }
4224
4225 right_path = ocfs2_new_path_from_et(et);
4226 if (!right_path) {
4227 ret = -ENOMEM;
4228 mlog_errno(ret);
4229 goto out;

--- 6 unchanged lines hidden (view full) ---

4236 */
4237 cpos = le32_to_cpu(insert_rec->e_cpos);
4238 if (type->ins_appending == APPEND_NONE &&
4239 type->ins_contig == CONTIG_NONE) {
4240 rotate = 1;
4241 cpos = UINT_MAX;
4242 }
4243
4272 goto out_update_clusters;
4273 }
4274
4275 right_path = ocfs2_new_path_from_et(et);
4276 if (!right_path) {
4277 ret = -ENOMEM;
4278 mlog_errno(ret);
4279 goto out;

--- 6 unchanged lines hidden (view full) ---

4286 */
4287 cpos = le32_to_cpu(insert_rec->e_cpos);
4288 if (type->ins_appending == APPEND_NONE &&
4289 type->ins_contig == CONTIG_NONE) {
4290 rotate = 1;
4291 cpos = UINT_MAX;
4292 }
4293
4244 ret = ocfs2_find_path(inode, right_path, cpos);
4294 ret = ocfs2_find_path(et->et_ci, right_path, cpos);
4245 if (ret) {
4246 mlog_errno(ret);
4247 goto out;
4248 }
4249
4250 /*
4251 * Rotations and appends need special treatment - they modify
4252 * parts of the tree's above them.
4253 *
4254 * Both might pass back a path immediate to the left of the
4255 * one being inserted to. This will be cause
4256 * ocfs2_insert_path() to modify the rightmost records of
4257 * left_path to account for an edge insert.
4258 *
4259 * XXX: When modifying this code, keep in mind that an insert
4260 * can wind up skipping both of these two special cases...
4261 */
4262 if (rotate) {
4295 if (ret) {
4296 mlog_errno(ret);
4297 goto out;
4298 }
4299
4300 /*
4301 * Rotations and appends need special treatment - they modify
4302 * parts of the tree's above them.
4303 *
4304 * Both might pass back a path immediate to the left of the
4305 * one being inserted to. This will be cause
4306 * ocfs2_insert_path() to modify the rightmost records of
4307 * left_path to account for an edge insert.
4308 *
4309 * XXX: When modifying this code, keep in mind that an insert
4310 * can wind up skipping both of these two special cases...
4311 */
4312 if (rotate) {
4263 ret = ocfs2_rotate_tree_right(inode, handle, type->ins_split,
4313 ret = ocfs2_rotate_tree_right(handle, et, type->ins_split,
4264 le32_to_cpu(insert_rec->e_cpos),
4265 right_path, &left_path);
4266 if (ret) {
4267 mlog_errno(ret);
4268 goto out;
4269 }
4270
4271 /*
4272 * ocfs2_rotate_tree_right() might have extended the
4273 * transaction without re-journaling our tree root.
4274 */
4314 le32_to_cpu(insert_rec->e_cpos),
4315 right_path, &left_path);
4316 if (ret) {
4317 mlog_errno(ret);
4318 goto out;
4319 }
4320
4321 /*
4322 * ocfs2_rotate_tree_right() might have extended the
4323 * transaction without re-journaling our tree root.
4324 */
4275 ret = ocfs2_et_root_journal_access(handle, inode, et,
4325 ret = ocfs2_et_root_journal_access(handle, et,
4276 OCFS2_JOURNAL_ACCESS_WRITE);
4277 if (ret) {
4278 mlog_errno(ret);
4279 goto out;
4280 }
4281 } else if (type->ins_appending == APPEND_TAIL
4282 && type->ins_contig != CONTIG_LEFT) {
4326 OCFS2_JOURNAL_ACCESS_WRITE);
4327 if (ret) {
4328 mlog_errno(ret);
4329 goto out;
4330 }
4331 } else if (type->ins_appending == APPEND_TAIL
4332 && type->ins_contig != CONTIG_LEFT) {
4283 ret = ocfs2_append_rec_to_path(inode, handle, insert_rec,
4333 ret = ocfs2_append_rec_to_path(handle, et, insert_rec,
4284 right_path, &left_path);
4285 if (ret) {
4286 mlog_errno(ret);
4287 goto out;
4288 }
4289 }
4290
4334 right_path, &left_path);
4335 if (ret) {
4336 mlog_errno(ret);
4337 goto out;
4338 }
4339 }
4340
4291 ret = ocfs2_insert_path(inode, handle, left_path, right_path,
4341 ret = ocfs2_insert_path(handle, et, left_path, right_path,
4292 insert_rec, type);
4293 if (ret) {
4294 mlog_errno(ret);
4295 goto out;
4296 }
4297
4298out_update_clusters:
4299 if (type->ins_split == SPLIT_NONE)
4342 insert_rec, type);
4343 if (ret) {
4344 mlog_errno(ret);
4345 goto out;
4346 }
4347
4348out_update_clusters:
4349 if (type->ins_split == SPLIT_NONE)
4300 ocfs2_et_update_clusters(inode, et,
4350 ocfs2_et_update_clusters(et,
4301 le16_to_cpu(insert_rec->e_leaf_clusters));
4302
4303 ret = ocfs2_journal_dirty(handle, et->et_root_bh);
4304 if (ret)
4305 mlog_errno(ret);
4306
4307out:
4308 ocfs2_free_path(left_path);
4309 ocfs2_free_path(right_path);
4310
4311 return ret;
4312}
4313
4314static enum ocfs2_contig_type
4351 le16_to_cpu(insert_rec->e_leaf_clusters));
4352
4353 ret = ocfs2_journal_dirty(handle, et->et_root_bh);
4354 if (ret)
4355 mlog_errno(ret);
4356
4357out:
4358 ocfs2_free_path(left_path);
4359 ocfs2_free_path(right_path);
4360
4361 return ret;
4362}
4363
4364static enum ocfs2_contig_type
4315ocfs2_figure_merge_contig_type(struct inode *inode, struct ocfs2_path *path,
4365ocfs2_figure_merge_contig_type(struct ocfs2_extent_tree *et,
4366 struct ocfs2_path *path,
4316 struct ocfs2_extent_list *el, int index,
4317 struct ocfs2_extent_rec *split_rec)
4318{
4319 int status;
4320 enum ocfs2_contig_type ret = CONTIG_NONE;
4321 u32 left_cpos, right_cpos;
4322 struct ocfs2_extent_rec *rec = NULL;
4323 struct ocfs2_extent_list *new_el;
4324 struct ocfs2_path *left_path = NULL, *right_path = NULL;
4325 struct buffer_head *bh;
4326 struct ocfs2_extent_block *eb;
4367 struct ocfs2_extent_list *el, int index,
4368 struct ocfs2_extent_rec *split_rec)
4369{
4370 int status;
4371 enum ocfs2_contig_type ret = CONTIG_NONE;
4372 u32 left_cpos, right_cpos;
4373 struct ocfs2_extent_rec *rec = NULL;
4374 struct ocfs2_extent_list *new_el;
4375 struct ocfs2_path *left_path = NULL, *right_path = NULL;
4376 struct buffer_head *bh;
4377 struct ocfs2_extent_block *eb;
4378 struct super_block *sb = ocfs2_metadata_cache_get_super(et->et_ci);
4327
4328 if (index > 0) {
4329 rec = &el->l_recs[index - 1];
4330 } else if (path->p_tree_depth > 0) {
4379
4380 if (index > 0) {
4381 rec = &el->l_recs[index - 1];
4382 } else if (path->p_tree_depth > 0) {
4331 status = ocfs2_find_cpos_for_left_leaf(inode->i_sb,
4332 path, &left_cpos);
4383 status = ocfs2_find_cpos_for_left_leaf(sb, path, &left_cpos);
4333 if (status)
4334 goto out;
4335
4336 if (left_cpos != 0) {
4337 left_path = ocfs2_new_path_from_path(path);
4338 if (!left_path)
4339 goto out;
4340
4384 if (status)
4385 goto out;
4386
4387 if (left_cpos != 0) {
4388 left_path = ocfs2_new_path_from_path(path);
4389 if (!left_path)
4390 goto out;
4391
4341 status = ocfs2_find_path(inode, left_path, left_cpos);
4392 status = ocfs2_find_path(et->et_ci, left_path,
4393 left_cpos);
4342 if (status)
4343 goto out;
4344
4345 new_el = path_leaf_el(left_path);
4346
4347 if (le16_to_cpu(new_el->l_next_free_rec) !=
4348 le16_to_cpu(new_el->l_count)) {
4349 bh = path_leaf_bh(left_path);
4350 eb = (struct ocfs2_extent_block *)bh->b_data;
4394 if (status)
4395 goto out;
4396
4397 new_el = path_leaf_el(left_path);
4398
4399 if (le16_to_cpu(new_el->l_next_free_rec) !=
4400 le16_to_cpu(new_el->l_count)) {
4401 bh = path_leaf_bh(left_path);
4402 eb = (struct ocfs2_extent_block *)bh->b_data;
4351 ocfs2_error(inode->i_sb,
4403 ocfs2_error(sb,
4352 "Extent block #%llu has an "
4353 "invalid l_next_free_rec of "
4354 "%d. It should have "
4355 "matched the l_count of %d",
4356 (unsigned long long)le64_to_cpu(eb->h_blkno),
4357 le16_to_cpu(new_el->l_next_free_rec),
4358 le16_to_cpu(new_el->l_count));
4359 status = -EINVAL;

--- 8 unchanged lines hidden (view full) ---

4368 * We're careful to check for an empty extent record here -
4369 * the merge code will know what to do if it sees one.
4370 */
4371 if (rec) {
4372 if (index == 1 && ocfs2_is_empty_extent(rec)) {
4373 if (split_rec->e_cpos == el->l_recs[index].e_cpos)
4374 ret = CONTIG_RIGHT;
4375 } else {
4404 "Extent block #%llu has an "
4405 "invalid l_next_free_rec of "
4406 "%d. It should have "
4407 "matched the l_count of %d",
4408 (unsigned long long)le64_to_cpu(eb->h_blkno),
4409 le16_to_cpu(new_el->l_next_free_rec),
4410 le16_to_cpu(new_el->l_count));
4411 status = -EINVAL;

--- 8 unchanged lines hidden (view full) ---

4420 * We're careful to check for an empty extent record here -
4421 * the merge code will know what to do if it sees one.
4422 */
4423 if (rec) {
4424 if (index == 1 && ocfs2_is_empty_extent(rec)) {
4425 if (split_rec->e_cpos == el->l_recs[index].e_cpos)
4426 ret = CONTIG_RIGHT;
4427 } else {
4376 ret = ocfs2_extent_contig(inode, rec, split_rec);
4428 ret = ocfs2_et_extent_contig(et, rec, split_rec);
4377 }
4378 }
4379
4380 rec = NULL;
4381 if (index < (le16_to_cpu(el->l_next_free_rec) - 1))
4382 rec = &el->l_recs[index + 1];
4383 else if (le16_to_cpu(el->l_next_free_rec) == le16_to_cpu(el->l_count) &&
4384 path->p_tree_depth > 0) {
4429 }
4430 }
4431
4432 rec = NULL;
4433 if (index < (le16_to_cpu(el->l_next_free_rec) - 1))
4434 rec = &el->l_recs[index + 1];
4435 else if (le16_to_cpu(el->l_next_free_rec) == le16_to_cpu(el->l_count) &&
4436 path->p_tree_depth > 0) {
4385 status = ocfs2_find_cpos_for_right_leaf(inode->i_sb,
4386 path, &right_cpos);
4437 status = ocfs2_find_cpos_for_right_leaf(sb, path, &right_cpos);
4387 if (status)
4388 goto out;
4389
4390 if (right_cpos == 0)
4391 goto out;
4392
4393 right_path = ocfs2_new_path_from_path(path);
4394 if (!right_path)
4395 goto out;
4396
4438 if (status)
4439 goto out;
4440
4441 if (right_cpos == 0)
4442 goto out;
4443
4444 right_path = ocfs2_new_path_from_path(path);
4445 if (!right_path)
4446 goto out;
4447
4397 status = ocfs2_find_path(inode, right_path, right_cpos);
4448 status = ocfs2_find_path(et->et_ci, right_path, right_cpos);
4398 if (status)
4399 goto out;
4400
4401 new_el = path_leaf_el(right_path);
4402 rec = &new_el->l_recs[0];
4403 if (ocfs2_is_empty_extent(rec)) {
4404 if (le16_to_cpu(new_el->l_next_free_rec) <= 1) {
4405 bh = path_leaf_bh(right_path);
4406 eb = (struct ocfs2_extent_block *)bh->b_data;
4449 if (status)
4450 goto out;
4451
4452 new_el = path_leaf_el(right_path);
4453 rec = &new_el->l_recs[0];
4454 if (ocfs2_is_empty_extent(rec)) {
4455 if (le16_to_cpu(new_el->l_next_free_rec) <= 1) {
4456 bh = path_leaf_bh(right_path);
4457 eb = (struct ocfs2_extent_block *)bh->b_data;
4407 ocfs2_error(inode->i_sb,
4458 ocfs2_error(sb,
4408 "Extent block #%llu has an "
4409 "invalid l_next_free_rec of %d",
4410 (unsigned long long)le64_to_cpu(eb->h_blkno),
4411 le16_to_cpu(new_el->l_next_free_rec));
4412 status = -EINVAL;
4413 goto out;
4414 }
4415 rec = &new_el->l_recs[1];
4416 }
4417 }
4418
4419 if (rec) {
4420 enum ocfs2_contig_type contig_type;
4421
4459 "Extent block #%llu has an "
4460 "invalid l_next_free_rec of %d",
4461 (unsigned long long)le64_to_cpu(eb->h_blkno),
4462 le16_to_cpu(new_el->l_next_free_rec));
4463 status = -EINVAL;
4464 goto out;
4465 }
4466 rec = &new_el->l_recs[1];
4467 }
4468 }
4469
4470 if (rec) {
4471 enum ocfs2_contig_type contig_type;
4472
4422 contig_type = ocfs2_extent_contig(inode, rec, split_rec);
4473 contig_type = ocfs2_et_extent_contig(et, rec, split_rec);
4423
4424 if (contig_type == CONTIG_LEFT && ret == CONTIG_RIGHT)
4425 ret = CONTIG_LEFTRIGHT;
4426 else if (ret == CONTIG_NONE)
4427 ret = contig_type;
4428 }
4429
4430out:
4431 if (left_path)
4432 ocfs2_free_path(left_path);
4433 if (right_path)
4434 ocfs2_free_path(right_path);
4435
4436 return ret;
4437}
4438
4474
4475 if (contig_type == CONTIG_LEFT && ret == CONTIG_RIGHT)
4476 ret = CONTIG_LEFTRIGHT;
4477 else if (ret == CONTIG_NONE)
4478 ret = contig_type;
4479 }
4480
4481out:
4482 if (left_path)
4483 ocfs2_free_path(left_path);
4484 if (right_path)
4485 ocfs2_free_path(right_path);
4486
4487 return ret;
4488}
4489
4439static void ocfs2_figure_contig_type(struct inode *inode,
4490static void ocfs2_figure_contig_type(struct ocfs2_extent_tree *et,
4440 struct ocfs2_insert_type *insert,
4441 struct ocfs2_extent_list *el,
4491 struct ocfs2_insert_type *insert,
4492 struct ocfs2_extent_list *el,
4442 struct ocfs2_extent_rec *insert_rec,
4443 struct ocfs2_extent_tree *et)
4493 struct ocfs2_extent_rec *insert_rec)
4444{
4445 int i;
4446 enum ocfs2_contig_type contig_type = CONTIG_NONE;
4447
4448 BUG_ON(le16_to_cpu(el->l_tree_depth) != 0);
4449
4450 for(i = 0; i < le16_to_cpu(el->l_next_free_rec); i++) {
4494{
4495 int i;
4496 enum ocfs2_contig_type contig_type = CONTIG_NONE;
4497
4498 BUG_ON(le16_to_cpu(el->l_tree_depth) != 0);
4499
4500 for(i = 0; i < le16_to_cpu(el->l_next_free_rec); i++) {
4451 contig_type = ocfs2_extent_contig(inode, &el->l_recs[i],
4452 insert_rec);
4501 contig_type = ocfs2_et_extent_contig(et, &el->l_recs[i],
4502 insert_rec);
4453 if (contig_type != CONTIG_NONE) {
4454 insert->ins_contig_index = i;
4455 break;
4456 }
4457 }
4458 insert->ins_contig = contig_type;
4459
4460 if (insert->ins_contig != CONTIG_NONE) {

--- 64 unchanged lines hidden (view full) ---

4525 * - Whether the new extent is contiguous with an existing one.
4526 * - The current tree depth.
4527 * - Whether the insert is an appending one.
4528 * - The total # of free records in the tree.
4529 *
4530 * All of the information is stored on the ocfs2_insert_type
4531 * structure.
4532 */
4503 if (contig_type != CONTIG_NONE) {
4504 insert->ins_contig_index = i;
4505 break;
4506 }
4507 }
4508 insert->ins_contig = contig_type;
4509
4510 if (insert->ins_contig != CONTIG_NONE) {

--- 64 unchanged lines hidden (view full) ---

4575 * - Whether the new extent is contiguous with an existing one.
4576 * - The current tree depth.
4577 * - Whether the insert is an appending one.
4578 * - The total # of free records in the tree.
4579 *
4580 * All of the information is stored on the ocfs2_insert_type
4581 * structure.
4582 */
4533static int ocfs2_figure_insert_type(struct inode *inode,
4534 struct ocfs2_extent_tree *et,
4583static int ocfs2_figure_insert_type(struct ocfs2_extent_tree *et,
4535 struct buffer_head **last_eb_bh,
4536 struct ocfs2_extent_rec *insert_rec,
4537 int *free_records,
4538 struct ocfs2_insert_type *insert)
4539{
4540 int ret;
4541 struct ocfs2_extent_block *eb;
4542 struct ocfs2_extent_list *el;

--- 7 unchanged lines hidden (view full) ---

4550
4551 if (el->l_tree_depth) {
4552 /*
4553 * If we have tree depth, we read in the
4554 * rightmost extent block ahead of time as
4555 * ocfs2_figure_insert_type() and ocfs2_add_branch()
4556 * may want it later.
4557 */
4584 struct buffer_head **last_eb_bh,
4585 struct ocfs2_extent_rec *insert_rec,
4586 int *free_records,
4587 struct ocfs2_insert_type *insert)
4588{
4589 int ret;
4590 struct ocfs2_extent_block *eb;
4591 struct ocfs2_extent_list *el;

--- 7 unchanged lines hidden (view full) ---

4599
4600 if (el->l_tree_depth) {
4601 /*
4602 * If we have tree depth, we read in the
4603 * rightmost extent block ahead of time as
4604 * ocfs2_figure_insert_type() and ocfs2_add_branch()
4605 * may want it later.
4606 */
4558 ret = ocfs2_read_extent_block(inode,
4607 ret = ocfs2_read_extent_block(et->et_ci,
4559 ocfs2_et_get_last_eb_blk(et),
4560 &bh);
4561 if (ret) {
4562 mlog_exit(ret);
4563 goto out;
4564 }
4565 eb = (struct ocfs2_extent_block *) bh->b_data;
4566 el = &eb->h_list;

--- 6 unchanged lines hidden (view full) ---

4573 *
4574 * XXX: This test is simplistic, we can search for empty
4575 * extent records too.
4576 */
4577 *free_records = le16_to_cpu(el->l_count) -
4578 le16_to_cpu(el->l_next_free_rec);
4579
4580 if (!insert->ins_tree_depth) {
4608 ocfs2_et_get_last_eb_blk(et),
4609 &bh);
4610 if (ret) {
4611 mlog_exit(ret);
4612 goto out;
4613 }
4614 eb = (struct ocfs2_extent_block *) bh->b_data;
4615 el = &eb->h_list;

--- 6 unchanged lines hidden (view full) ---

4622 *
4623 * XXX: This test is simplistic, we can search for empty
4624 * extent records too.
4625 */
4626 *free_records = le16_to_cpu(el->l_count) -
4627 le16_to_cpu(el->l_next_free_rec);
4628
4629 if (!insert->ins_tree_depth) {
4581 ocfs2_figure_contig_type(inode, insert, el, insert_rec, et);
4630 ocfs2_figure_contig_type(et, insert, el, insert_rec);
4582 ocfs2_figure_appending_type(insert, el, insert_rec);
4583 return 0;
4584 }
4585
4586 path = ocfs2_new_path_from_et(et);
4587 if (!path) {
4588 ret = -ENOMEM;
4589 mlog_errno(ret);
4590 goto out;
4591 }
4592
4593 /*
4594 * In the case that we're inserting past what the tree
4595 * currently accounts for, ocfs2_find_path() will return for
4596 * us the rightmost tree path. This is accounted for below in
4597 * the appending code.
4598 */
4631 ocfs2_figure_appending_type(insert, el, insert_rec);
4632 return 0;
4633 }
4634
4635 path = ocfs2_new_path_from_et(et);
4636 if (!path) {
4637 ret = -ENOMEM;
4638 mlog_errno(ret);
4639 goto out;
4640 }
4641
4642 /*
4643 * In the case that we're inserting past what the tree
4644 * currently accounts for, ocfs2_find_path() will return for
4645 * us the rightmost tree path. This is accounted for below in
4646 * the appending code.
4647 */
4599 ret = ocfs2_find_path(inode, path, le32_to_cpu(insert_rec->e_cpos));
4648 ret = ocfs2_find_path(et->et_ci, path, le32_to_cpu(insert_rec->e_cpos));
4600 if (ret) {
4601 mlog_errno(ret);
4602 goto out;
4603 }
4604
4605 el = path_leaf_el(path);
4606
4607 /*
4608 * Now that we have the path, there's two things we want to determine:
4609 * 1) Contiguousness (also set contig_index if this is so)
4610 *
4611 * 2) Are we doing an append? We can trivially break this up
4612 * into two types of appends: simple record append, or a
4613 * rotate inside the tail leaf.
4614 */
4649 if (ret) {
4650 mlog_errno(ret);
4651 goto out;
4652 }
4653
4654 el = path_leaf_el(path);
4655
4656 /*
4657 * Now that we have the path, there's two things we want to determine:
4658 * 1) Contiguousness (also set contig_index if this is so)
4659 *
4660 * 2) Are we doing an append? We can trivially break this up
4661 * into two types of appends: simple record append, or a
4662 * rotate inside the tail leaf.
4663 */
4615 ocfs2_figure_contig_type(inode, insert, el, insert_rec, et);
4664 ocfs2_figure_contig_type(et, insert, el, insert_rec);
4616
4617 /*
4618 * The insert code isn't quite ready to deal with all cases of
4619 * left contiguousness. Specifically, if it's an insert into
4620 * the 1st record in a leaf, it will require the adjustment of
4621 * cluster count on the last record of the path directly to it's
4622 * left. For now, just catch that case and fool the layers
4623 * above us. This works just fine for tree_depth == 0, which

--- 28 unchanged lines hidden (view full) ---

4652 if (ret == 0)
4653 *last_eb_bh = bh;
4654 else
4655 brelse(bh);
4656 return ret;
4657}
4658
4659/*
4665
4666 /*
4667 * The insert code isn't quite ready to deal with all cases of
4668 * left contiguousness. Specifically, if it's an insert into
4669 * the 1st record in a leaf, it will require the adjustment of
4670 * cluster count on the last record of the path directly to it's
4671 * left. For now, just catch that case and fool the layers
4672 * above us. This works just fine for tree_depth == 0, which

--- 28 unchanged lines hidden (view full) ---

4701 if (ret == 0)
4702 *last_eb_bh = bh;
4703 else
4704 brelse(bh);
4705 return ret;
4706}
4707
4708/*
4660 * Insert an extent into an inode btree.
4709 * Insert an extent into a btree.
4661 *
4710 *
4662 * The caller needs to update fe->i_clusters
4711 * The caller needs to update the owning btree's cluster count.
4663 */
4712 */
4664int ocfs2_insert_extent(struct ocfs2_super *osb,
4665 handle_t *handle,
4666 struct inode *inode,
4713int ocfs2_insert_extent(handle_t *handle,
4667 struct ocfs2_extent_tree *et,
4668 u32 cpos,
4669 u64 start_blk,
4670 u32 new_clusters,
4671 u8 flags,
4672 struct ocfs2_alloc_context *meta_ac)
4673{
4674 int status;
4675 int uninitialized_var(free_records);
4676 struct buffer_head *last_eb_bh = NULL;
4677 struct ocfs2_insert_type insert = {0, };
4678 struct ocfs2_extent_rec rec;
4679
4714 struct ocfs2_extent_tree *et,
4715 u32 cpos,
4716 u64 start_blk,
4717 u32 new_clusters,
4718 u8 flags,
4719 struct ocfs2_alloc_context *meta_ac)
4720{
4721 int status;
4722 int uninitialized_var(free_records);
4723 struct buffer_head *last_eb_bh = NULL;
4724 struct ocfs2_insert_type insert = {0, };
4725 struct ocfs2_extent_rec rec;
4726
4680 mlog(0, "add %u clusters at position %u to inode %llu\n",
4681 new_clusters, cpos, (unsigned long long)OCFS2_I(inode)->ip_blkno);
4727 mlog(0, "add %u clusters at position %u to owner %llu\n",
4728 new_clusters, cpos,
4729 (unsigned long long)ocfs2_metadata_cache_owner(et->et_ci));
4682
4683 memset(&rec, 0, sizeof(rec));
4684 rec.e_cpos = cpu_to_le32(cpos);
4685 rec.e_blkno = cpu_to_le64(start_blk);
4686 rec.e_leaf_clusters = cpu_to_le16(new_clusters);
4687 rec.e_flags = flags;
4730
4731 memset(&rec, 0, sizeof(rec));
4732 rec.e_cpos = cpu_to_le32(cpos);
4733 rec.e_blkno = cpu_to_le64(start_blk);
4734 rec.e_leaf_clusters = cpu_to_le16(new_clusters);
4735 rec.e_flags = flags;
4688 status = ocfs2_et_insert_check(inode, et, &rec);
4736 status = ocfs2_et_insert_check(et, &rec);
4689 if (status) {
4690 mlog_errno(status);
4691 goto bail;
4692 }
4693
4737 if (status) {
4738 mlog_errno(status);
4739 goto bail;
4740 }
4741
4694 status = ocfs2_figure_insert_type(inode, et, &last_eb_bh, &rec,
4742 status = ocfs2_figure_insert_type(et, &last_eb_bh, &rec,
4695 &free_records, &insert);
4696 if (status < 0) {
4697 mlog_errno(status);
4698 goto bail;
4699 }
4700
4701 mlog(0, "Insert.appending: %u, Insert.Contig: %u, "
4702 "Insert.contig_index: %d, Insert.free_records: %d, "
4703 "Insert.tree_depth: %d\n",
4704 insert.ins_appending, insert.ins_contig, insert.ins_contig_index,
4705 free_records, insert.ins_tree_depth);
4706
4707 if (insert.ins_contig == CONTIG_NONE && free_records == 0) {
4743 &free_records, &insert);
4744 if (status < 0) {
4745 mlog_errno(status);
4746 goto bail;
4747 }
4748
4749 mlog(0, "Insert.appending: %u, Insert.Contig: %u, "
4750 "Insert.contig_index: %d, Insert.free_records: %d, "
4751 "Insert.tree_depth: %d\n",
4752 insert.ins_appending, insert.ins_contig, insert.ins_contig_index,
4753 free_records, insert.ins_tree_depth);
4754
4755 if (insert.ins_contig == CONTIG_NONE && free_records == 0) {
4708 status = ocfs2_grow_tree(inode, handle, et,
4756 status = ocfs2_grow_tree(handle, et,
4709 &insert.ins_tree_depth, &last_eb_bh,
4710 meta_ac);
4711 if (status) {
4712 mlog_errno(status);
4713 goto bail;
4714 }
4715 }
4716
4717 /* Finally, we can add clusters. This might rotate the tree for us. */
4757 &insert.ins_tree_depth, &last_eb_bh,
4758 meta_ac);
4759 if (status) {
4760 mlog_errno(status);
4761 goto bail;
4762 }
4763 }
4764
4765 /* Finally, we can add clusters. This might rotate the tree for us. */
4718 status = ocfs2_do_insert_extent(inode, handle, et, &rec, &insert);
4766 status = ocfs2_do_insert_extent(handle, et, &rec, &insert);
4719 if (status < 0)
4720 mlog_errno(status);
4767 if (status < 0)
4768 mlog_errno(status);
4721 else if (et->et_ops == &ocfs2_dinode_et_ops)
4722 ocfs2_extent_map_insert_rec(inode, &rec);
4769 else
4770 ocfs2_et_extent_map_insert(et, &rec);
4723
4724bail:
4725 brelse(last_eb_bh);
4726
4727 mlog_exit(status);
4728 return status;
4729}
4730
4731/*
4732 * Allcate and add clusters into the extent b-tree.
4733 * The new clusters(clusters_to_add) will be inserted at logical_offset.
4734 * The extent b-tree's root is specified by et, and
4735 * it is not limited to the file storage. Any extent tree can use this
4736 * function if it implements the proper ocfs2_extent_tree.
4737 */
4771
4772bail:
4773 brelse(last_eb_bh);
4774
4775 mlog_exit(status);
4776 return status;
4777}
4778
4779/*
4780 * Allcate and add clusters into the extent b-tree.
4781 * The new clusters(clusters_to_add) will be inserted at logical_offset.
4782 * The extent b-tree's root is specified by et, and
4783 * it is not limited to the file storage. Any extent tree can use this
4784 * function if it implements the proper ocfs2_extent_tree.
4785 */
4738int ocfs2_add_clusters_in_btree(struct ocfs2_super *osb,
4739 struct inode *inode,
4786int ocfs2_add_clusters_in_btree(handle_t *handle,
4787 struct ocfs2_extent_tree *et,
4740 u32 *logical_offset,
4741 u32 clusters_to_add,
4742 int mark_unwritten,
4788 u32 *logical_offset,
4789 u32 clusters_to_add,
4790 int mark_unwritten,
4743 struct ocfs2_extent_tree *et,
4744 handle_t *handle,
4745 struct ocfs2_alloc_context *data_ac,
4746 struct ocfs2_alloc_context *meta_ac,
4747 enum ocfs2_alloc_restarted *reason_ret)
4748{
4749 int status = 0;
4750 int free_extents;
4751 enum ocfs2_alloc_restarted reason = RESTART_NONE;
4752 u32 bit_off, num_bits;
4753 u64 block;
4754 u8 flags = 0;
4791 struct ocfs2_alloc_context *data_ac,
4792 struct ocfs2_alloc_context *meta_ac,
4793 enum ocfs2_alloc_restarted *reason_ret)
4794{
4795 int status = 0;
4796 int free_extents;
4797 enum ocfs2_alloc_restarted reason = RESTART_NONE;
4798 u32 bit_off, num_bits;
4799 u64 block;
4800 u8 flags = 0;
4801 struct ocfs2_super *osb =
4802 OCFS2_SB(ocfs2_metadata_cache_get_super(et->et_ci));
4755
4756 BUG_ON(!clusters_to_add);
4757
4758 if (mark_unwritten)
4759 flags = OCFS2_EXT_UNWRITTEN;
4760
4803
4804 BUG_ON(!clusters_to_add);
4805
4806 if (mark_unwritten)
4807 flags = OCFS2_EXT_UNWRITTEN;
4808
4761 free_extents = ocfs2_num_free_extents(osb, inode, et);
4809 free_extents = ocfs2_num_free_extents(osb, et);
4762 if (free_extents < 0) {
4763 status = free_extents;
4764 mlog_errno(status);
4765 goto leave;
4766 }
4767
4768 /* there are two cases which could cause us to EAGAIN in the
4769 * we-need-more-metadata case:

--- 20 unchanged lines hidden (view full) ---

4790 if (status != -ENOSPC)
4791 mlog_errno(status);
4792 goto leave;
4793 }
4794
4795 BUG_ON(num_bits > clusters_to_add);
4796
4797 /* reserve our write early -- insert_extent may update the tree root */
4810 if (free_extents < 0) {
4811 status = free_extents;
4812 mlog_errno(status);
4813 goto leave;
4814 }
4815
4816 /* there are two cases which could cause us to EAGAIN in the
4817 * we-need-more-metadata case:

--- 20 unchanged lines hidden (view full) ---

4838 if (status != -ENOSPC)
4839 mlog_errno(status);
4840 goto leave;
4841 }
4842
4843 BUG_ON(num_bits > clusters_to_add);
4844
4845 /* reserve our write early -- insert_extent may update the tree root */
4798 status = ocfs2_et_root_journal_access(handle, inode, et,
4846 status = ocfs2_et_root_journal_access(handle, et,
4799 OCFS2_JOURNAL_ACCESS_WRITE);
4800 if (status < 0) {
4801 mlog_errno(status);
4802 goto leave;
4803 }
4804
4805 block = ocfs2_clusters_to_blocks(osb->sb, bit_off);
4847 OCFS2_JOURNAL_ACCESS_WRITE);
4848 if (status < 0) {
4849 mlog_errno(status);
4850 goto leave;
4851 }
4852
4853 block = ocfs2_clusters_to_blocks(osb->sb, bit_off);
4806 mlog(0, "Allocating %u clusters at block %u for inode %llu\n",
4807 num_bits, bit_off, (unsigned long long)OCFS2_I(inode)->ip_blkno);
4808 status = ocfs2_insert_extent(osb, handle, inode, et,
4809 *logical_offset, block,
4854 mlog(0, "Allocating %u clusters at block %u for owner %llu\n",
4855 num_bits, bit_off,
4856 (unsigned long long)ocfs2_metadata_cache_owner(et->et_ci));
4857 status = ocfs2_insert_extent(handle, et, *logical_offset, block,
4810 num_bits, flags, meta_ac);
4811 if (status < 0) {
4812 mlog_errno(status);
4813 goto leave;
4814 }
4815
4816 status = ocfs2_journal_dirty(handle, et->et_root_bh);
4817 if (status < 0) {

--- 33 unchanged lines hidden (view full) ---

4851
4852 split_rec->e_blkno = rec->e_blkno;
4853 le64_add_cpu(&split_rec->e_blkno,
4854 ocfs2_clusters_to_blocks(sb, cpos - rec_cpos));
4855
4856 split_rec->e_flags = rec->e_flags;
4857}
4858
4858 num_bits, flags, meta_ac);
4859 if (status < 0) {
4860 mlog_errno(status);
4861 goto leave;
4862 }
4863
4864 status = ocfs2_journal_dirty(handle, et->et_root_bh);
4865 if (status < 0) {

--- 33 unchanged lines hidden (view full) ---

4899
4900 split_rec->e_blkno = rec->e_blkno;
4901 le64_add_cpu(&split_rec->e_blkno,
4902 ocfs2_clusters_to_blocks(sb, cpos - rec_cpos));
4903
4904 split_rec->e_flags = rec->e_flags;
4905}
4906
4859static int ocfs2_split_and_insert(struct inode *inode,
4860 handle_t *handle,
4861 struct ocfs2_path *path,
4907static int ocfs2_split_and_insert(handle_t *handle,
4862 struct ocfs2_extent_tree *et,
4908 struct ocfs2_extent_tree *et,
4909 struct ocfs2_path *path,
4863 struct buffer_head **last_eb_bh,
4864 int split_index,
4865 struct ocfs2_extent_rec *orig_split_rec,
4866 struct ocfs2_alloc_context *meta_ac)
4867{
4868 int ret = 0, depth;
4869 unsigned int insert_range, rec_range, do_leftright = 0;
4870 struct ocfs2_extent_rec tmprec;

--- 16 unchanged lines hidden (view full) ---

4887 if (depth) {
4888 BUG_ON(!(*last_eb_bh));
4889 eb = (struct ocfs2_extent_block *) (*last_eb_bh)->b_data;
4890 rightmost_el = &eb->h_list;
4891 }
4892
4893 if (le16_to_cpu(rightmost_el->l_next_free_rec) ==
4894 le16_to_cpu(rightmost_el->l_count)) {
4910 struct buffer_head **last_eb_bh,
4911 int split_index,
4912 struct ocfs2_extent_rec *orig_split_rec,
4913 struct ocfs2_alloc_context *meta_ac)
4914{
4915 int ret = 0, depth;
4916 unsigned int insert_range, rec_range, do_leftright = 0;
4917 struct ocfs2_extent_rec tmprec;

--- 16 unchanged lines hidden (view full) ---

4934 if (depth) {
4935 BUG_ON(!(*last_eb_bh));
4936 eb = (struct ocfs2_extent_block *) (*last_eb_bh)->b_data;
4937 rightmost_el = &eb->h_list;
4938 }
4939
4940 if (le16_to_cpu(rightmost_el->l_next_free_rec) ==
4941 le16_to_cpu(rightmost_el->l_count)) {
4895 ret = ocfs2_grow_tree(inode, handle, et,
4942 ret = ocfs2_grow_tree(handle, et,
4896 &depth, last_eb_bh, meta_ac);
4897 if (ret) {
4898 mlog_errno(ret);
4899 goto out;
4900 }
4901 }
4902
4903 memset(&insert, 0, sizeof(struct ocfs2_insert_type));

--- 12 unchanged lines hidden (view full) ---

4916 insert.ins_split = SPLIT_RIGHT;
4917 } else {
4918 /*
4919 * Left/right split. We fake this as a right split
4920 * first and then make a second pass as a left split.
4921 */
4922 insert.ins_split = SPLIT_RIGHT;
4923
4943 &depth, last_eb_bh, meta_ac);
4944 if (ret) {
4945 mlog_errno(ret);
4946 goto out;
4947 }
4948 }
4949
4950 memset(&insert, 0, sizeof(struct ocfs2_insert_type));

--- 12 unchanged lines hidden (view full) ---

4963 insert.ins_split = SPLIT_RIGHT;
4964 } else {
4965 /*
4966 * Left/right split. We fake this as a right split
4967 * first and then make a second pass as a left split.
4968 */
4969 insert.ins_split = SPLIT_RIGHT;
4970
4924 ocfs2_make_right_split_rec(inode->i_sb, &tmprec, insert_range,
4925 &rec);
4971 ocfs2_make_right_split_rec(ocfs2_metadata_cache_get_super(et->et_ci),
4972 &tmprec, insert_range, &rec);
4926
4927 split_rec = tmprec;
4928
4929 BUG_ON(do_leftright);
4930 do_leftright = 1;
4931 }
4932
4973
4974 split_rec = tmprec;
4975
4976 BUG_ON(do_leftright);
4977 do_leftright = 1;
4978 }
4979
4933 ret = ocfs2_do_insert_extent(inode, handle, et, &split_rec, &insert);
4980 ret = ocfs2_do_insert_extent(handle, et, &split_rec, &insert);
4934 if (ret) {
4935 mlog_errno(ret);
4936 goto out;
4937 }
4938
4939 if (do_leftright == 1) {
4940 u32 cpos;
4941 struct ocfs2_extent_list *el;
4942
4943 do_leftright++;
4944 split_rec = *orig_split_rec;
4945
4946 ocfs2_reinit_path(path, 1);
4947
4948 cpos = le32_to_cpu(split_rec.e_cpos);
4981 if (ret) {
4982 mlog_errno(ret);
4983 goto out;
4984 }
4985
4986 if (do_leftright == 1) {
4987 u32 cpos;
4988 struct ocfs2_extent_list *el;
4989
4990 do_leftright++;
4991 split_rec = *orig_split_rec;
4992
4993 ocfs2_reinit_path(path, 1);
4994
4995 cpos = le32_to_cpu(split_rec.e_cpos);
4949 ret = ocfs2_find_path(inode, path, cpos);
4996 ret = ocfs2_find_path(et->et_ci, path, cpos);
4950 if (ret) {
4951 mlog_errno(ret);
4952 goto out;
4953 }
4954
4955 el = path_leaf_el(path);
4956 split_index = ocfs2_search_extent_list(el, cpos);
4957 goto leftright;
4958 }
4959out:
4960
4961 return ret;
4962}
4963
4997 if (ret) {
4998 mlog_errno(ret);
4999 goto out;
5000 }
5001
5002 el = path_leaf_el(path);
5003 split_index = ocfs2_search_extent_list(el, cpos);
5004 goto leftright;
5005 }
5006out:
5007
5008 return ret;
5009}
5010
4964static int ocfs2_replace_extent_rec(struct inode *inode,
4965 handle_t *handle,
5011static int ocfs2_replace_extent_rec(handle_t *handle,
5012 struct ocfs2_extent_tree *et,
4966 struct ocfs2_path *path,
4967 struct ocfs2_extent_list *el,
4968 int split_index,
4969 struct ocfs2_extent_rec *split_rec)
4970{
4971 int ret;
4972
5013 struct ocfs2_path *path,
5014 struct ocfs2_extent_list *el,
5015 int split_index,
5016 struct ocfs2_extent_rec *split_rec)
5017{
5018 int ret;
5019
4973 ret = ocfs2_path_bh_journal_access(handle, inode, path,
5020 ret = ocfs2_path_bh_journal_access(handle, et->et_ci, path,
4974 path_num_items(path) - 1);
4975 if (ret) {
4976 mlog_errno(ret);
4977 goto out;
4978 }
4979
4980 el->l_recs[split_index] = *split_rec;
4981

--- 17 unchanged lines hidden (view full) ---

4999 * btree. Since a split may grow the tree or a merge might shrink it,
5000 * the caller cannot trust the contents of that buffer after this call.
5001 *
5002 * This code is optimized for readability - several passes might be
5003 * made over certain portions of the tree. All of those blocks will
5004 * have been brought into cache (and pinned via the journal), so the
5005 * extra overhead is not expressed in terms of disk reads.
5006 */
5021 path_num_items(path) - 1);
5022 if (ret) {
5023 mlog_errno(ret);
5024 goto out;
5025 }
5026
5027 el->l_recs[split_index] = *split_rec;
5028

--- 17 unchanged lines hidden (view full) ---

5046 * btree. Since a split may grow the tree or a merge might shrink it,
5047 * the caller cannot trust the contents of that buffer after this call.
5048 *
5049 * This code is optimized for readability - several passes might be
5050 * made over certain portions of the tree. All of those blocks will
5051 * have been brought into cache (and pinned via the journal), so the
5052 * extra overhead is not expressed in terms of disk reads.
5053 */
5007static int __ocfs2_mark_extent_written(struct inode *inode,
5054static int __ocfs2_mark_extent_written(handle_t *handle,
5008 struct ocfs2_extent_tree *et,
5055 struct ocfs2_extent_tree *et,
5009 handle_t *handle,
5010 struct ocfs2_path *path,
5011 int split_index,
5012 struct ocfs2_extent_rec *split_rec,
5013 struct ocfs2_alloc_context *meta_ac,
5014 struct ocfs2_cached_dealloc_ctxt *dealloc)
5015{
5016 int ret = 0;
5017 struct ocfs2_extent_list *el = path_leaf_el(path);

--- 11 unchanged lines hidden (view full) ---

5029 if (le32_to_cpu(rec->e_cpos) > le32_to_cpu(split_rec->e_cpos) ||
5030 ((le32_to_cpu(rec->e_cpos) + le16_to_cpu(rec->e_leaf_clusters)) <
5031 (le32_to_cpu(split_rec->e_cpos) + le16_to_cpu(split_rec->e_leaf_clusters)))) {
5032 ret = -EIO;
5033 mlog_errno(ret);
5034 goto out;
5035 }
5036
5056 struct ocfs2_path *path,
5057 int split_index,
5058 struct ocfs2_extent_rec *split_rec,
5059 struct ocfs2_alloc_context *meta_ac,
5060 struct ocfs2_cached_dealloc_ctxt *dealloc)
5061{
5062 int ret = 0;
5063 struct ocfs2_extent_list *el = path_leaf_el(path);

--- 11 unchanged lines hidden (view full) ---

5075 if (le32_to_cpu(rec->e_cpos) > le32_to_cpu(split_rec->e_cpos) ||
5076 ((le32_to_cpu(rec->e_cpos) + le16_to_cpu(rec->e_leaf_clusters)) <
5077 (le32_to_cpu(split_rec->e_cpos) + le16_to_cpu(split_rec->e_leaf_clusters)))) {
5078 ret = -EIO;
5079 mlog_errno(ret);
5080 goto out;
5081 }
5082
5037 ctxt.c_contig_type = ocfs2_figure_merge_contig_type(inode, path, el,
5083 ctxt.c_contig_type = ocfs2_figure_merge_contig_type(et, path, el,
5038 split_index,
5039 split_rec);
5040
5041 /*
5042 * The core merge / split code wants to know how much room is
5084 split_index,
5085 split_rec);
5086
5087 /*
5088 * The core merge / split code wants to know how much room is
5043 * left in this inodes allocation tree, so we pass the
5089 * left in this allocation tree, so we pass the
5044 * rightmost extent list.
5045 */
5046 if (path->p_tree_depth) {
5047 struct ocfs2_extent_block *eb;
5048
5090 * rightmost extent list.
5091 */
5092 if (path->p_tree_depth) {
5093 struct ocfs2_extent_block *eb;
5094
5049 ret = ocfs2_read_extent_block(inode,
5095 ret = ocfs2_read_extent_block(et->et_ci,
5050 ocfs2_et_get_last_eb_blk(et),
5051 &last_eb_bh);
5052 if (ret) {
5053 mlog_exit(ret);
5054 goto out;
5055 }
5056
5057 eb = (struct ocfs2_extent_block *) last_eb_bh->b_data;

--- 10 unchanged lines hidden (view full) ---

5068 ctxt.c_has_empty_extent = ocfs2_is_empty_extent(&el->l_recs[0]);
5069
5070 mlog(0, "index: %d, contig: %u, has_empty: %u, split_covers: %u\n",
5071 split_index, ctxt.c_contig_type, ctxt.c_has_empty_extent,
5072 ctxt.c_split_covers_rec);
5073
5074 if (ctxt.c_contig_type == CONTIG_NONE) {
5075 if (ctxt.c_split_covers_rec)
5096 ocfs2_et_get_last_eb_blk(et),
5097 &last_eb_bh);
5098 if (ret) {
5099 mlog_exit(ret);
5100 goto out;
5101 }
5102
5103 eb = (struct ocfs2_extent_block *) last_eb_bh->b_data;

--- 10 unchanged lines hidden (view full) ---

5114 ctxt.c_has_empty_extent = ocfs2_is_empty_extent(&el->l_recs[0]);
5115
5116 mlog(0, "index: %d, contig: %u, has_empty: %u, split_covers: %u\n",
5117 split_index, ctxt.c_contig_type, ctxt.c_has_empty_extent,
5118 ctxt.c_split_covers_rec);
5119
5120 if (ctxt.c_contig_type == CONTIG_NONE) {
5121 if (ctxt.c_split_covers_rec)
5076 ret = ocfs2_replace_extent_rec(inode, handle,
5077 path, el,
5122 ret = ocfs2_replace_extent_rec(handle, et, path, el,
5078 split_index, split_rec);
5079 else
5123 split_index, split_rec);
5124 else
5080 ret = ocfs2_split_and_insert(inode, handle, path, et,
5125 ret = ocfs2_split_and_insert(handle, et, path,
5081 &last_eb_bh, split_index,
5082 split_rec, meta_ac);
5083 if (ret)
5084 mlog_errno(ret);
5085 } else {
5126 &last_eb_bh, split_index,
5127 split_rec, meta_ac);
5128 if (ret)
5129 mlog_errno(ret);
5130 } else {
5086 ret = ocfs2_try_to_merge_extent(inode, handle, path,
5131 ret = ocfs2_try_to_merge_extent(handle, et, path,
5087 split_index, split_rec,
5132 split_index, split_rec,
5088 dealloc, &ctxt, et);
5133 dealloc, &ctxt);
5089 if (ret)
5090 mlog_errno(ret);
5091 }
5092
5093out:
5094 brelse(last_eb_bh);
5095 return ret;
5096}

--- 28 unchanged lines hidden (view full) ---

5125 (unsigned long long)OCFS2_I(inode)->ip_blkno);
5126 ret = -EROFS;
5127 goto out;
5128 }
5129
5130 /*
5131 * XXX: This should be fixed up so that we just re-insert the
5132 * next extent records.
5134 if (ret)
5135 mlog_errno(ret);
5136 }
5137
5138out:
5139 brelse(last_eb_bh);
5140 return ret;
5141}

--- 28 unchanged lines hidden (view full) ---

5170 (unsigned long long)OCFS2_I(inode)->ip_blkno);
5171 ret = -EROFS;
5172 goto out;
5173 }
5174
5175 /*
5176 * XXX: This should be fixed up so that we just re-insert the
5177 * next extent records.
5133 *
5134 * XXX: This is a hack on the extent tree, maybe it should be
5135 * an op?
5136 */
5178 */
5137 if (et->et_ops == &ocfs2_dinode_et_ops)
5138 ocfs2_extent_map_trunc(inode, 0);
5179 ocfs2_et_extent_map_truncate(et, 0);
5139
5140 left_path = ocfs2_new_path_from_et(et);
5141 if (!left_path) {
5142 ret = -ENOMEM;
5143 mlog_errno(ret);
5144 goto out;
5145 }
5146
5180
5181 left_path = ocfs2_new_path_from_et(et);
5182 if (!left_path) {
5183 ret = -ENOMEM;
5184 mlog_errno(ret);
5185 goto out;
5186 }
5187
5147 ret = ocfs2_find_path(inode, left_path, cpos);
5188 ret = ocfs2_find_path(et->et_ci, left_path, cpos);
5148 if (ret) {
5149 mlog_errno(ret);
5150 goto out;
5151 }
5152 el = path_leaf_el(left_path);
5153
5154 index = ocfs2_search_extent_list(el, cpos);
5155 if (index == -1 || index >= le16_to_cpu(el->l_next_free_rec)) {

--- 7 unchanged lines hidden (view full) ---

5163
5164 memset(&split_rec, 0, sizeof(struct ocfs2_extent_rec));
5165 split_rec.e_cpos = cpu_to_le32(cpos);
5166 split_rec.e_leaf_clusters = cpu_to_le16(len);
5167 split_rec.e_blkno = cpu_to_le64(start_blkno);
5168 split_rec.e_flags = path_leaf_el(left_path)->l_recs[index].e_flags;
5169 split_rec.e_flags &= ~OCFS2_EXT_UNWRITTEN;
5170
5189 if (ret) {
5190 mlog_errno(ret);
5191 goto out;
5192 }
5193 el = path_leaf_el(left_path);
5194
5195 index = ocfs2_search_extent_list(el, cpos);
5196 if (index == -1 || index >= le16_to_cpu(el->l_next_free_rec)) {

--- 7 unchanged lines hidden (view full) ---

5204
5205 memset(&split_rec, 0, sizeof(struct ocfs2_extent_rec));
5206 split_rec.e_cpos = cpu_to_le32(cpos);
5207 split_rec.e_leaf_clusters = cpu_to_le16(len);
5208 split_rec.e_blkno = cpu_to_le64(start_blkno);
5209 split_rec.e_flags = path_leaf_el(left_path)->l_recs[index].e_flags;
5210 split_rec.e_flags &= ~OCFS2_EXT_UNWRITTEN;
5211
5171 ret = __ocfs2_mark_extent_written(inode, et, handle, left_path,
5212 ret = __ocfs2_mark_extent_written(handle, et, left_path,
5172 index, &split_rec, meta_ac,
5173 dealloc);
5174 if (ret)
5175 mlog_errno(ret);
5176
5177out:
5178 ocfs2_free_path(left_path);
5179 return ret;
5180}
5181
5213 index, &split_rec, meta_ac,
5214 dealloc);
5215 if (ret)
5216 mlog_errno(ret);
5217
5218out:
5219 ocfs2_free_path(left_path);
5220 return ret;
5221}
5222
5182static int ocfs2_split_tree(struct inode *inode, struct ocfs2_extent_tree *et,
5183 handle_t *handle, struct ocfs2_path *path,
5223static int ocfs2_split_tree(handle_t *handle, struct ocfs2_extent_tree *et,
5224 struct ocfs2_path *path,
5184 int index, u32 new_range,
5185 struct ocfs2_alloc_context *meta_ac)
5186{
5187 int ret, depth, credits = handle->h_buffer_credits;
5188 struct buffer_head *last_eb_bh = NULL;
5189 struct ocfs2_extent_block *eb;
5190 struct ocfs2_extent_list *rightmost_el, *el;
5191 struct ocfs2_extent_rec split_rec;
5192 struct ocfs2_extent_rec *rec;
5193 struct ocfs2_insert_type insert;
5194
5195 /*
5196 * Setup the record to split before we grow the tree.
5197 */
5198 el = path_leaf_el(path);
5199 rec = &el->l_recs[index];
5225 int index, u32 new_range,
5226 struct ocfs2_alloc_context *meta_ac)
5227{
5228 int ret, depth, credits = handle->h_buffer_credits;
5229 struct buffer_head *last_eb_bh = NULL;
5230 struct ocfs2_extent_block *eb;
5231 struct ocfs2_extent_list *rightmost_el, *el;
5232 struct ocfs2_extent_rec split_rec;
5233 struct ocfs2_extent_rec *rec;
5234 struct ocfs2_insert_type insert;
5235
5236 /*
5237 * Setup the record to split before we grow the tree.
5238 */
5239 el = path_leaf_el(path);
5240 rec = &el->l_recs[index];
5200 ocfs2_make_right_split_rec(inode->i_sb, &split_rec, new_range, rec);
5241 ocfs2_make_right_split_rec(ocfs2_metadata_cache_get_super(et->et_ci),
5242 &split_rec, new_range, rec);
5201
5202 depth = path->p_tree_depth;
5203 if (depth > 0) {
5243
5244 depth = path->p_tree_depth;
5245 if (depth > 0) {
5204 ret = ocfs2_read_extent_block(inode,
5246 ret = ocfs2_read_extent_block(et->et_ci,
5205 ocfs2_et_get_last_eb_blk(et),
5206 &last_eb_bh);
5207 if (ret < 0) {
5208 mlog_errno(ret);
5209 goto out;
5210 }
5211
5212 eb = (struct ocfs2_extent_block *) last_eb_bh->b_data;

--- 6 unchanged lines hidden (view full) ---

5219 ret = ocfs2_extend_trans(handle, credits);
5220 if (ret) {
5221 mlog_errno(ret);
5222 goto out;
5223 }
5224
5225 if (le16_to_cpu(rightmost_el->l_next_free_rec) ==
5226 le16_to_cpu(rightmost_el->l_count)) {
5247 ocfs2_et_get_last_eb_blk(et),
5248 &last_eb_bh);
5249 if (ret < 0) {
5250 mlog_errno(ret);
5251 goto out;
5252 }
5253
5254 eb = (struct ocfs2_extent_block *) last_eb_bh->b_data;

--- 6 unchanged lines hidden (view full) ---

5261 ret = ocfs2_extend_trans(handle, credits);
5262 if (ret) {
5263 mlog_errno(ret);
5264 goto out;
5265 }
5266
5267 if (le16_to_cpu(rightmost_el->l_next_free_rec) ==
5268 le16_to_cpu(rightmost_el->l_count)) {
5227 ret = ocfs2_grow_tree(inode, handle, et, &depth, &last_eb_bh,
5269 ret = ocfs2_grow_tree(handle, et, &depth, &last_eb_bh,
5228 meta_ac);
5229 if (ret) {
5230 mlog_errno(ret);
5231 goto out;
5232 }
5233 }
5234
5235 memset(&insert, 0, sizeof(struct ocfs2_insert_type));
5236 insert.ins_appending = APPEND_NONE;
5237 insert.ins_contig = CONTIG_NONE;
5238 insert.ins_split = SPLIT_RIGHT;
5239 insert.ins_tree_depth = depth;
5240
5270 meta_ac);
5271 if (ret) {
5272 mlog_errno(ret);
5273 goto out;
5274 }
5275 }
5276
5277 memset(&insert, 0, sizeof(struct ocfs2_insert_type));
5278 insert.ins_appending = APPEND_NONE;
5279 insert.ins_contig = CONTIG_NONE;
5280 insert.ins_split = SPLIT_RIGHT;
5281 insert.ins_tree_depth = depth;
5282
5241 ret = ocfs2_do_insert_extent(inode, handle, et, &split_rec, &insert);
5283 ret = ocfs2_do_insert_extent(handle, et, &split_rec, &insert);
5242 if (ret)
5243 mlog_errno(ret);
5244
5245out:
5246 brelse(last_eb_bh);
5247 return ret;
5248}
5249
5284 if (ret)
5285 mlog_errno(ret);
5286
5287out:
5288 brelse(last_eb_bh);
5289 return ret;
5290}
5291
5250static int ocfs2_truncate_rec(struct inode *inode, handle_t *handle,
5292static int ocfs2_truncate_rec(handle_t *handle,
5293 struct ocfs2_extent_tree *et,
5251 struct ocfs2_path *path, int index,
5252 struct ocfs2_cached_dealloc_ctxt *dealloc,
5294 struct ocfs2_path *path, int index,
5295 struct ocfs2_cached_dealloc_ctxt *dealloc,
5253 u32 cpos, u32 len,
5254 struct ocfs2_extent_tree *et)
5296 u32 cpos, u32 len)
5255{
5256 int ret;
5257 u32 left_cpos, rec_range, trunc_range;
5258 int wants_rotate = 0, is_rightmost_tree_rec = 0;
5297{
5298 int ret;
5299 u32 left_cpos, rec_range, trunc_range;
5300 int wants_rotate = 0, is_rightmost_tree_rec = 0;
5259 struct super_block *sb = inode->i_sb;
5301 struct super_block *sb = ocfs2_metadata_cache_get_super(et->et_ci);
5260 struct ocfs2_path *left_path = NULL;
5261 struct ocfs2_extent_list *el = path_leaf_el(path);
5262 struct ocfs2_extent_rec *rec;
5263 struct ocfs2_extent_block *eb;
5264
5265 if (ocfs2_is_empty_extent(&el->l_recs[0]) && index > 0) {
5302 struct ocfs2_path *left_path = NULL;
5303 struct ocfs2_extent_list *el = path_leaf_el(path);
5304 struct ocfs2_extent_rec *rec;
5305 struct ocfs2_extent_block *eb;
5306
5307 if (ocfs2_is_empty_extent(&el->l_recs[0]) && index > 0) {
5266 ret = ocfs2_rotate_tree_left(inode, handle, path, dealloc, et);
5308 ret = ocfs2_rotate_tree_left(handle, et, path, dealloc);
5267 if (ret) {
5268 mlog_errno(ret);
5269 goto out;
5270 }
5271
5272 index--;
5273 }
5274

--- 15 unchanged lines hidden (view full) ---

5290 le32_to_cpu(rec->e_cpos) == cpos) {
5291 /*
5292 * Changing the leftmost offset (via partial or whole
5293 * record truncate) of an interior (or rightmost) path
5294 * means we have to update the subtree that is formed
5295 * by this leaf and the one to it's left.
5296 *
5297 * There are two cases we can skip:
5309 if (ret) {
5310 mlog_errno(ret);
5311 goto out;
5312 }
5313
5314 index--;
5315 }
5316

--- 15 unchanged lines hidden (view full) ---

5332 le32_to_cpu(rec->e_cpos) == cpos) {
5333 /*
5334 * Changing the leftmost offset (via partial or whole
5335 * record truncate) of an interior (or rightmost) path
5336 * means we have to update the subtree that is formed
5337 * by this leaf and the one to it's left.
5338 *
5339 * There are two cases we can skip:
5298 * 1) Path is the leftmost one in our inode tree.
5340 * 1) Path is the leftmost one in our btree.
5299 * 2) The leaf is rightmost and will be empty after
5300 * we remove the extent record - the rotate code
5301 * knows how to update the newly formed edge.
5302 */
5303
5341 * 2) The leaf is rightmost and will be empty after
5342 * we remove the extent record - the rotate code
5343 * knows how to update the newly formed edge.
5344 */
5345
5304 ret = ocfs2_find_cpos_for_left_leaf(inode->i_sb, path,
5305 &left_cpos);
5346 ret = ocfs2_find_cpos_for_left_leaf(sb, path, &left_cpos);
5306 if (ret) {
5307 mlog_errno(ret);
5308 goto out;
5309 }
5310
5311 if (left_cpos && le16_to_cpu(el->l_next_free_rec) > 1) {
5312 left_path = ocfs2_new_path_from_path(path);
5313 if (!left_path) {
5314 ret = -ENOMEM;
5315 mlog_errno(ret);
5316 goto out;
5317 }
5318
5347 if (ret) {
5348 mlog_errno(ret);
5349 goto out;
5350 }
5351
5352 if (left_cpos && le16_to_cpu(el->l_next_free_rec) > 1) {
5353 left_path = ocfs2_new_path_from_path(path);
5354 if (!left_path) {
5355 ret = -ENOMEM;
5356 mlog_errno(ret);
5357 goto out;
5358 }
5359
5319 ret = ocfs2_find_path(inode, left_path, left_cpos);
5360 ret = ocfs2_find_path(et->et_ci, left_path,
5361 left_cpos);
5320 if (ret) {
5321 mlog_errno(ret);
5322 goto out;
5323 }
5324 }
5325 }
5326
5327 ret = ocfs2_extend_rotate_transaction(handle, 0,
5328 handle->h_buffer_credits,
5329 path);
5330 if (ret) {
5331 mlog_errno(ret);
5332 goto out;
5333 }
5334
5362 if (ret) {
5363 mlog_errno(ret);
5364 goto out;
5365 }
5366 }
5367 }
5368
5369 ret = ocfs2_extend_rotate_transaction(handle, 0,
5370 handle->h_buffer_credits,
5371 path);
5372 if (ret) {
5373 mlog_errno(ret);
5374 goto out;
5375 }
5376
5335 ret = ocfs2_journal_access_path(inode, handle, path);
5377 ret = ocfs2_journal_access_path(et->et_ci, handle, path);
5336 if (ret) {
5337 mlog_errno(ret);
5338 goto out;
5339 }
5340
5378 if (ret) {
5379 mlog_errno(ret);
5380 goto out;
5381 }
5382
5341 ret = ocfs2_journal_access_path(inode, handle, left_path);
5383 ret = ocfs2_journal_access_path(et->et_ci, handle, left_path);
5342 if (ret) {
5343 mlog_errno(ret);
5344 goto out;
5345 }
5346
5347 rec_range = le32_to_cpu(rec->e_cpos) + ocfs2_rec_clusters(el, rec);
5348 trunc_range = cpos + len;
5349

--- 6 unchanged lines hidden (view full) ---

5356
5357 next_free = le16_to_cpu(el->l_next_free_rec);
5358 if (is_rightmost_tree_rec && next_free > 1) {
5359 /*
5360 * We skip the edge update if this path will
5361 * be deleted by the rotate code.
5362 */
5363 rec = &el->l_recs[next_free - 1];
5384 if (ret) {
5385 mlog_errno(ret);
5386 goto out;
5387 }
5388
5389 rec_range = le32_to_cpu(rec->e_cpos) + ocfs2_rec_clusters(el, rec);
5390 trunc_range = cpos + len;
5391

--- 6 unchanged lines hidden (view full) ---

5398
5399 next_free = le16_to_cpu(el->l_next_free_rec);
5400 if (is_rightmost_tree_rec && next_free > 1) {
5401 /*
5402 * We skip the edge update if this path will
5403 * be deleted by the rotate code.
5404 */
5405 rec = &el->l_recs[next_free - 1];
5364 ocfs2_adjust_rightmost_records(inode, handle, path,
5406 ocfs2_adjust_rightmost_records(handle, et, path,
5365 rec);
5366 }
5367 } else if (le32_to_cpu(rec->e_cpos) == cpos) {
5368 /* Remove leftmost portion of the record. */
5369 le32_add_cpu(&rec->e_cpos, len);
5370 le64_add_cpu(&rec->e_blkno, ocfs2_clusters_to_blocks(sb, len));
5371 le16_add_cpu(&rec->e_leaf_clusters, -len);
5372 } else if (rec_range == trunc_range) {
5373 /* Remove rightmost portion of the record */
5374 le16_add_cpu(&rec->e_leaf_clusters, -len);
5375 if (is_rightmost_tree_rec)
5407 rec);
5408 }
5409 } else if (le32_to_cpu(rec->e_cpos) == cpos) {
5410 /* Remove leftmost portion of the record. */
5411 le32_add_cpu(&rec->e_cpos, len);
5412 le64_add_cpu(&rec->e_blkno, ocfs2_clusters_to_blocks(sb, len));
5413 le16_add_cpu(&rec->e_leaf_clusters, -len);
5414 } else if (rec_range == trunc_range) {
5415 /* Remove rightmost portion of the record */
5416 le16_add_cpu(&rec->e_leaf_clusters, -len);
5417 if (is_rightmost_tree_rec)
5376 ocfs2_adjust_rightmost_records(inode, handle, path, rec);
5418 ocfs2_adjust_rightmost_records(handle, et, path, rec);
5377 } else {
5378 /* Caller should have trapped this. */
5419 } else {
5420 /* Caller should have trapped this. */
5379 mlog(ML_ERROR, "Inode %llu: Invalid record truncate: (%u, %u) "
5380 "(%u, %u)\n", (unsigned long long)OCFS2_I(inode)->ip_blkno,
5421 mlog(ML_ERROR, "Owner %llu: Invalid record truncate: (%u, %u) "
5422 "(%u, %u)\n",
5423 (unsigned long long)ocfs2_metadata_cache_owner(et->et_ci),
5381 le32_to_cpu(rec->e_cpos),
5382 le16_to_cpu(rec->e_leaf_clusters), cpos, len);
5383 BUG();
5384 }
5385
5386 if (left_path) {
5387 int subtree_index;
5388
5424 le32_to_cpu(rec->e_cpos),
5425 le16_to_cpu(rec->e_leaf_clusters), cpos, len);
5426 BUG();
5427 }
5428
5429 if (left_path) {
5430 int subtree_index;
5431
5389 subtree_index = ocfs2_find_subtree_root(inode, left_path, path);
5390 ocfs2_complete_edge_insert(inode, handle, left_path, path,
5432 subtree_index = ocfs2_find_subtree_root(et, left_path, path);
5433 ocfs2_complete_edge_insert(handle, left_path, path,
5391 subtree_index);
5392 }
5393
5394 ocfs2_journal_dirty(handle, path_leaf_bh(path));
5395
5434 subtree_index);
5435 }
5436
5437 ocfs2_journal_dirty(handle, path_leaf_bh(path));
5438
5396 ret = ocfs2_rotate_tree_left(inode, handle, path, dealloc, et);
5439 ret = ocfs2_rotate_tree_left(handle, et, path, dealloc);
5397 if (ret) {
5398 mlog_errno(ret);
5399 goto out;
5400 }
5401
5402out:
5403 ocfs2_free_path(left_path);
5404 return ret;
5405}
5406
5440 if (ret) {
5441 mlog_errno(ret);
5442 goto out;
5443 }
5444
5445out:
5446 ocfs2_free_path(left_path);
5447 return ret;
5448}
5449
5407int ocfs2_remove_extent(struct inode *inode,
5450int ocfs2_remove_extent(handle_t *handle,
5408 struct ocfs2_extent_tree *et,
5451 struct ocfs2_extent_tree *et,
5409 u32 cpos, u32 len, handle_t *handle,
5452 u32 cpos, u32 len,
5410 struct ocfs2_alloc_context *meta_ac,
5411 struct ocfs2_cached_dealloc_ctxt *dealloc)
5412{
5413 int ret, index;
5414 u32 rec_range, trunc_range;
5415 struct ocfs2_extent_rec *rec;
5416 struct ocfs2_extent_list *el;
5417 struct ocfs2_path *path = NULL;
5418
5453 struct ocfs2_alloc_context *meta_ac,
5454 struct ocfs2_cached_dealloc_ctxt *dealloc)
5455{
5456 int ret, index;
5457 u32 rec_range, trunc_range;
5458 struct ocfs2_extent_rec *rec;
5459 struct ocfs2_extent_list *el;
5460 struct ocfs2_path *path = NULL;
5461
5419 ocfs2_extent_map_trunc(inode, 0);
5462 /*
5463 * XXX: Why are we truncating to 0 instead of wherever this
5464 * affects us?
5465 */
5466 ocfs2_et_extent_map_truncate(et, 0);
5420
5421 path = ocfs2_new_path_from_et(et);
5422 if (!path) {
5423 ret = -ENOMEM;
5424 mlog_errno(ret);
5425 goto out;
5426 }
5427
5467
5468 path = ocfs2_new_path_from_et(et);
5469 if (!path) {
5470 ret = -ENOMEM;
5471 mlog_errno(ret);
5472 goto out;
5473 }
5474
5428 ret = ocfs2_find_path(inode, path, cpos);
5475 ret = ocfs2_find_path(et->et_ci, path, cpos);
5429 if (ret) {
5430 mlog_errno(ret);
5431 goto out;
5432 }
5433
5434 el = path_leaf_el(path);
5435 index = ocfs2_search_extent_list(el, cpos);
5436 if (index == -1 || index >= le16_to_cpu(el->l_next_free_rec)) {
5476 if (ret) {
5477 mlog_errno(ret);
5478 goto out;
5479 }
5480
5481 el = path_leaf_el(path);
5482 index = ocfs2_search_extent_list(el, cpos);
5483 if (index == -1 || index >= le16_to_cpu(el->l_next_free_rec)) {
5437 ocfs2_error(inode->i_sb,
5438 "Inode %llu has an extent at cpos %u which can no "
5484 ocfs2_error(ocfs2_metadata_cache_get_super(et->et_ci),
5485 "Owner %llu has an extent at cpos %u which can no "
5439 "longer be found.\n",
5486 "longer be found.\n",
5440 (unsigned long long)OCFS2_I(inode)->ip_blkno, cpos);
5487 (unsigned long long)ocfs2_metadata_cache_owner(et->et_ci),
5488 cpos);
5441 ret = -EROFS;
5442 goto out;
5443 }
5444
5445 /*
5446 * We have 3 cases of extent removal:
5447 * 1) Range covers the entire extent rec
5448 * 2) Range begins or ends on one edge of the extent rec

--- 10 unchanged lines hidden (view full) ---

5459 * something case 2 can handle.
5460 */
5461 rec = &el->l_recs[index];
5462 rec_range = le32_to_cpu(rec->e_cpos) + ocfs2_rec_clusters(el, rec);
5463 trunc_range = cpos + len;
5464
5465 BUG_ON(cpos < le32_to_cpu(rec->e_cpos) || trunc_range > rec_range);
5466
5489 ret = -EROFS;
5490 goto out;
5491 }
5492
5493 /*
5494 * We have 3 cases of extent removal:
5495 * 1) Range covers the entire extent rec
5496 * 2) Range begins or ends on one edge of the extent rec

--- 10 unchanged lines hidden (view full) ---

5507 * something case 2 can handle.
5508 */
5509 rec = &el->l_recs[index];
5510 rec_range = le32_to_cpu(rec->e_cpos) + ocfs2_rec_clusters(el, rec);
5511 trunc_range = cpos + len;
5512
5513 BUG_ON(cpos < le32_to_cpu(rec->e_cpos) || trunc_range > rec_range);
5514
5467 mlog(0, "Inode %llu, remove (cpos %u, len %u). Existing index %d "
5515 mlog(0, "Owner %llu, remove (cpos %u, len %u). Existing index %d "
5468 "(cpos %u, len %u)\n",
5516 "(cpos %u, len %u)\n",
5469 (unsigned long long)OCFS2_I(inode)->ip_blkno, cpos, len, index,
5517 (unsigned long long)ocfs2_metadata_cache_owner(et->et_ci),
5518 cpos, len, index,
5470 le32_to_cpu(rec->e_cpos), ocfs2_rec_clusters(el, rec));
5471
5472 if (le32_to_cpu(rec->e_cpos) == cpos || rec_range == trunc_range) {
5519 le32_to_cpu(rec->e_cpos), ocfs2_rec_clusters(el, rec));
5520
5521 if (le32_to_cpu(rec->e_cpos) == cpos || rec_range == trunc_range) {
5473 ret = ocfs2_truncate_rec(inode, handle, path, index, dealloc,
5474 cpos, len, et);
5522 ret = ocfs2_truncate_rec(handle, et, path, index, dealloc,
5523 cpos, len);
5475 if (ret) {
5476 mlog_errno(ret);
5477 goto out;
5478 }
5479 } else {
5524 if (ret) {
5525 mlog_errno(ret);
5526 goto out;
5527 }
5528 } else {
5480 ret = ocfs2_split_tree(inode, et, handle, path, index,
5529 ret = ocfs2_split_tree(handle, et, path, index,
5481 trunc_range, meta_ac);
5482 if (ret) {
5483 mlog_errno(ret);
5484 goto out;
5485 }
5486
5487 /*
5488 * The split could have manipulated the tree enough to
5489 * move the record location, so we have to look for it again.
5490 */
5491 ocfs2_reinit_path(path, 1);
5492
5530 trunc_range, meta_ac);
5531 if (ret) {
5532 mlog_errno(ret);
5533 goto out;
5534 }
5535
5536 /*
5537 * The split could have manipulated the tree enough to
5538 * move the record location, so we have to look for it again.
5539 */
5540 ocfs2_reinit_path(path, 1);
5541
5493 ret = ocfs2_find_path(inode, path, cpos);
5542 ret = ocfs2_find_path(et->et_ci, path, cpos);
5494 if (ret) {
5495 mlog_errno(ret);
5496 goto out;
5497 }
5498
5499 el = path_leaf_el(path);
5500 index = ocfs2_search_extent_list(el, cpos);
5501 if (index == -1 || index >= le16_to_cpu(el->l_next_free_rec)) {
5543 if (ret) {
5544 mlog_errno(ret);
5545 goto out;
5546 }
5547
5548 el = path_leaf_el(path);
5549 index = ocfs2_search_extent_list(el, cpos);
5550 if (index == -1 || index >= le16_to_cpu(el->l_next_free_rec)) {
5502 ocfs2_error(inode->i_sb,
5503 "Inode %llu: split at cpos %u lost record.",
5504 (unsigned long long)OCFS2_I(inode)->ip_blkno,
5551 ocfs2_error(ocfs2_metadata_cache_get_super(et->et_ci),
5552 "Owner %llu: split at cpos %u lost record.",
5553 (unsigned long long)ocfs2_metadata_cache_owner(et->et_ci),
5505 cpos);
5506 ret = -EROFS;
5507 goto out;
5508 }
5509
5510 /*
5511 * Double check our values here. If anything is fishy,
5512 * it's easier to catch it at the top level.
5513 */
5514 rec = &el->l_recs[index];
5515 rec_range = le32_to_cpu(rec->e_cpos) +
5516 ocfs2_rec_clusters(el, rec);
5517 if (rec_range != trunc_range) {
5554 cpos);
5555 ret = -EROFS;
5556 goto out;
5557 }
5558
5559 /*
5560 * Double check our values here. If anything is fishy,
5561 * it's easier to catch it at the top level.
5562 */
5563 rec = &el->l_recs[index];
5564 rec_range = le32_to_cpu(rec->e_cpos) +
5565 ocfs2_rec_clusters(el, rec);
5566 if (rec_range != trunc_range) {
5518 ocfs2_error(inode->i_sb,
5519 "Inode %llu: error after split at cpos %u"
5567 ocfs2_error(ocfs2_metadata_cache_get_super(et->et_ci),
5568 "Owner %llu: error after split at cpos %u"
5520 "trunc len %u, existing record is (%u,%u)",
5569 "trunc len %u, existing record is (%u,%u)",
5521 (unsigned long long)OCFS2_I(inode)->ip_blkno,
5570 (unsigned long long)ocfs2_metadata_cache_owner(et->et_ci),
5522 cpos, len, le32_to_cpu(rec->e_cpos),
5523 ocfs2_rec_clusters(el, rec));
5524 ret = -EROFS;
5525 goto out;
5526 }
5527
5571 cpos, len, le32_to_cpu(rec->e_cpos),
5572 ocfs2_rec_clusters(el, rec));
5573 ret = -EROFS;
5574 goto out;
5575 }
5576
5528 ret = ocfs2_truncate_rec(inode, handle, path, index, dealloc,
5529 cpos, len, et);
5577 ret = ocfs2_truncate_rec(handle, et, path, index, dealloc,
5578 cpos, len);
5530 if (ret) {
5531 mlog_errno(ret);
5532 goto out;
5533 }
5534 }
5535
5536out:
5537 ocfs2_free_path(path);

--- 30 unchanged lines hidden (view full) ---

5568
5569 handle = ocfs2_start_trans(osb, ocfs2_remove_extent_credits(osb->sb));
5570 if (IS_ERR(handle)) {
5571 ret = PTR_ERR(handle);
5572 mlog_errno(ret);
5573 goto out;
5574 }
5575
5579 if (ret) {
5580 mlog_errno(ret);
5581 goto out;
5582 }
5583 }
5584
5585out:
5586 ocfs2_free_path(path);

--- 30 unchanged lines hidden (view full) ---

5617
5618 handle = ocfs2_start_trans(osb, ocfs2_remove_extent_credits(osb->sb));
5619 if (IS_ERR(handle)) {
5620 ret = PTR_ERR(handle);
5621 mlog_errno(ret);
5622 goto out;
5623 }
5624
5576 ret = ocfs2_et_root_journal_access(handle, inode, et,
5625 ret = ocfs2_et_root_journal_access(handle, et,
5577 OCFS2_JOURNAL_ACCESS_WRITE);
5578 if (ret) {
5579 mlog_errno(ret);
5580 goto out;
5581 }
5582
5583 vfs_dq_free_space_nodirty(inode,
5584 ocfs2_clusters_to_bytes(inode->i_sb, len));
5585
5626 OCFS2_JOURNAL_ACCESS_WRITE);
5627 if (ret) {
5628 mlog_errno(ret);
5629 goto out;
5630 }
5631
5632 vfs_dq_free_space_nodirty(inode,
5633 ocfs2_clusters_to_bytes(inode->i_sb, len));
5634
5586 ret = ocfs2_remove_extent(inode, et, cpos, len, handle, meta_ac,
5587 dealloc);
5635 ret = ocfs2_remove_extent(handle, et, cpos, len, meta_ac, dealloc);
5588 if (ret) {
5589 mlog_errno(ret);
5590 goto out_commit;
5591 }
5592
5636 if (ret) {
5637 mlog_errno(ret);
5638 goto out_commit;
5639 }
5640
5593 ocfs2_et_update_clusters(inode, et, -len);
5641 ocfs2_et_update_clusters(et, -len);
5594
5595 ret = ocfs2_journal_dirty(handle, et->et_root_bh);
5596 if (ret) {
5597 mlog_errno(ret);
5598 goto out_commit;
5599 }
5600
5601 ret = ocfs2_truncate_log_append(osb, handle, phys_blkno, len);

--- 83 unchanged lines hidden (view full) ---

5685 /* Caller should have known to flush before calling us. */
5686 index = le16_to_cpu(tl->tl_used);
5687 if (index >= tl_count) {
5688 status = -ENOSPC;
5689 mlog_errno(status);
5690 goto bail;
5691 }
5692
5642
5643 ret = ocfs2_journal_dirty(handle, et->et_root_bh);
5644 if (ret) {
5645 mlog_errno(ret);
5646 goto out_commit;
5647 }
5648
5649 ret = ocfs2_truncate_log_append(osb, handle, phys_blkno, len);

--- 83 unchanged lines hidden (view full) ---

5733 /* Caller should have known to flush before calling us. */
5734 index = le16_to_cpu(tl->tl_used);
5735 if (index >= tl_count) {
5736 status = -ENOSPC;
5737 mlog_errno(status);
5738 goto bail;
5739 }
5740
5693 status = ocfs2_journal_access_di(handle, tl_inode, tl_bh,
5741 status = ocfs2_journal_access_di(handle, INODE_CACHE(tl_inode), tl_bh,
5694 OCFS2_JOURNAL_ACCESS_WRITE);
5695 if (status < 0) {
5696 mlog_errno(status);
5697 goto bail;
5698 }
5699
5700 mlog(0, "Log truncate of %u clusters starting at cluster %u to "
5701 "%llu (index = %d)\n", num_clusters, start_cluster,

--- 45 unchanged lines hidden (view full) ---

5747 mlog_entry_void();
5748
5749 di = (struct ocfs2_dinode *) tl_bh->b_data;
5750 tl = &di->id2.i_dealloc;
5751 i = le16_to_cpu(tl->tl_used) - 1;
5752 while (i >= 0) {
5753 /* Caller has given us at least enough credits to
5754 * update the truncate log dinode */
5742 OCFS2_JOURNAL_ACCESS_WRITE);
5743 if (status < 0) {
5744 mlog_errno(status);
5745 goto bail;
5746 }
5747
5748 mlog(0, "Log truncate of %u clusters starting at cluster %u to "
5749 "%llu (index = %d)\n", num_clusters, start_cluster,

--- 45 unchanged lines hidden (view full) ---

5795 mlog_entry_void();
5796
5797 di = (struct ocfs2_dinode *) tl_bh->b_data;
5798 tl = &di->id2.i_dealloc;
5799 i = le16_to_cpu(tl->tl_used) - 1;
5800 while (i >= 0) {
5801 /* Caller has given us at least enough credits to
5802 * update the truncate log dinode */
5755 status = ocfs2_journal_access_di(handle, tl_inode, tl_bh,
5803 status = ocfs2_journal_access_di(handle, INODE_CACHE(tl_inode), tl_bh,
5756 OCFS2_JOURNAL_ACCESS_WRITE);
5757 if (status < 0) {
5758 mlog_errno(status);
5759 goto bail;
5760 }
5761
5762 tl->tl_used = cpu_to_le16(i);
5763

--- 241 unchanged lines hidden (view full) ---

6005 * will be passed back to recovery for processing. */
6006 memcpy(*tl_copy, tl_bh->b_data, tl_bh->b_size);
6007
6008 /* All we need to do to clear the truncate log is set
6009 * tl_used. */
6010 tl->tl_used = 0;
6011
6012 ocfs2_compute_meta_ecc(osb->sb, tl_bh->b_data, &di->i_check);
5804 OCFS2_JOURNAL_ACCESS_WRITE);
5805 if (status < 0) {
5806 mlog_errno(status);
5807 goto bail;
5808 }
5809
5810 tl->tl_used = cpu_to_le16(i);
5811

--- 241 unchanged lines hidden (view full) ---

6053 * will be passed back to recovery for processing. */
6054 memcpy(*tl_copy, tl_bh->b_data, tl_bh->b_size);
6055
6056 /* All we need to do to clear the truncate log is set
6057 * tl_used. */
6058 tl->tl_used = 0;
6059
6060 ocfs2_compute_meta_ecc(osb->sb, tl_bh->b_data, &di->i_check);
6013 status = ocfs2_write_block(osb, tl_bh, tl_inode);
6061 status = ocfs2_write_block(osb, tl_bh, INODE_CACHE(tl_inode));
6014 if (status < 0) {
6015 mlog_errno(status);
6016 goto bail;
6017 }
6018 }
6019
6020bail:
6021 if (tl_inode)

--- 491 unchanged lines hidden (view full) ---

6513 }
6514
6515 ret = ocfs2_find_cpos_for_left_leaf(inode->i_sb, path, &cpos);
6516 if (ret) {
6517 mlog_errno(ret);
6518 goto out;
6519 }
6520
6062 if (status < 0) {
6063 mlog_errno(status);
6064 goto bail;
6065 }
6066 }
6067
6068bail:
6069 if (tl_inode)

--- 491 unchanged lines hidden (view full) ---

6561 }
6562
6563 ret = ocfs2_find_cpos_for_left_leaf(inode->i_sb, path, &cpos);
6564 if (ret) {
6565 mlog_errno(ret);
6566 goto out;
6567 }
6568
6521 ret = ocfs2_find_leaf(inode, path_root_el(path), cpos, &bh);
6569 ret = ocfs2_find_leaf(INODE_CACHE(inode), path_root_el(path), cpos, &bh);
6522 if (ret) {
6523 mlog_errno(ret);
6524 goto out;
6525 }
6526
6527 eb = (struct ocfs2_extent_block *) bh->b_data;
6528 el = &eb->h_list;
6529

--- 184 unchanged lines hidden (view full) ---

6714 /*
6715 * Save this for use when processing the
6716 * parent block.
6717 */
6718 deleted_eb = le64_to_cpu(eb->h_blkno);
6719
6720 mlog(0, "deleting this extent block.\n");
6721
6570 if (ret) {
6571 mlog_errno(ret);
6572 goto out;
6573 }
6574
6575 eb = (struct ocfs2_extent_block *) bh->b_data;
6576 el = &eb->h_list;
6577

--- 184 unchanged lines hidden (view full) ---

6762 /*
6763 * Save this for use when processing the
6764 * parent block.
6765 */
6766 deleted_eb = le64_to_cpu(eb->h_blkno);
6767
6768 mlog(0, "deleting this extent block.\n");
6769
6722 ocfs2_remove_from_cache(inode, bh);
6770 ocfs2_remove_from_cache(INODE_CACHE(inode), bh);
6723
6724 BUG_ON(ocfs2_rec_clusters(el, &el->l_recs[0]));
6725 BUG_ON(le32_to_cpu(el->l_recs[0].e_cpos));
6726 BUG_ON(le64_to_cpu(el->l_recs[0].e_blkno));
6727
6728 ret = ocfs2_cache_extent_block_free(&tc->tc_dealloc, eb);
6729 /* An error here is not fatal. */
6730 if (ret < 0)

--- 33 unchanged lines hidden (view full) ---

6764 mlog_errno(status);
6765 goto bail;
6766 }
6767
6768 /*
6769 * Each component will be touched, so we might as well journal
6770 * here to avoid having to handle errors later.
6771 */
6771
6772 BUG_ON(ocfs2_rec_clusters(el, &el->l_recs[0]));
6773 BUG_ON(le32_to_cpu(el->l_recs[0].e_cpos));
6774 BUG_ON(le64_to_cpu(el->l_recs[0].e_blkno));
6775
6776 ret = ocfs2_cache_extent_block_free(&tc->tc_dealloc, eb);
6777 /* An error here is not fatal. */
6778 if (ret < 0)

--- 33 unchanged lines hidden (view full) ---

6812 mlog_errno(status);
6813 goto bail;
6814 }
6815
6816 /*
6817 * Each component will be touched, so we might as well journal
6818 * here to avoid having to handle errors later.
6819 */
6772 status = ocfs2_journal_access_path(inode, handle, path);
6820 status = ocfs2_journal_access_path(INODE_CACHE(inode), handle, path);
6773 if (status < 0) {
6774 mlog_errno(status);
6775 goto bail;
6776 }
6777
6778 if (last_eb_bh) {
6821 if (status < 0) {
6822 mlog_errno(status);
6823 goto bail;
6824 }
6825
6826 if (last_eb_bh) {
6779 status = ocfs2_journal_access_eb(handle, inode, last_eb_bh,
6827 status = ocfs2_journal_access_eb(handle, INODE_CACHE(inode), last_eb_bh,
6780 OCFS2_JOURNAL_ACCESS_WRITE);
6781 if (status < 0) {
6782 mlog_errno(status);
6783 goto bail;
6784 }
6785
6786 last_eb = (struct ocfs2_extent_block *) last_eb_bh->b_data;
6787 }

--- 345 unchanged lines hidden (view full) ---

7133 handle = ocfs2_start_trans(osb,
7134 ocfs2_inline_to_extents_credits(osb->sb));
7135 if (IS_ERR(handle)) {
7136 ret = PTR_ERR(handle);
7137 mlog_errno(ret);
7138 goto out_unlock;
7139 }
7140
6828 OCFS2_JOURNAL_ACCESS_WRITE);
6829 if (status < 0) {
6830 mlog_errno(status);
6831 goto bail;
6832 }
6833
6834 last_eb = (struct ocfs2_extent_block *) last_eb_bh->b_data;
6835 }

--- 345 unchanged lines hidden (view full) ---

7181 handle = ocfs2_start_trans(osb,
7182 ocfs2_inline_to_extents_credits(osb->sb));
7183 if (IS_ERR(handle)) {
7184 ret = PTR_ERR(handle);
7185 mlog_errno(ret);
7186 goto out_unlock;
7187 }
7188
7141 ret = ocfs2_journal_access_di(handle, inode, di_bh,
7189 ret = ocfs2_journal_access_di(handle, INODE_CACHE(inode), di_bh,
7142 OCFS2_JOURNAL_ACCESS_WRITE);
7143 if (ret) {
7144 mlog_errno(ret);
7145 goto out_commit;
7146 }
7147
7148 if (has_data) {
7149 u32 bit_off, num;

--- 63 unchanged lines hidden (view full) ---

7213 ocfs2_journal_dirty(handle, di_bh);
7214
7215 if (has_data) {
7216 /*
7217 * An error at this point should be extremely rare. If
7218 * this proves to be false, we could always re-build
7219 * the in-inode data from our pages.
7220 */
7190 OCFS2_JOURNAL_ACCESS_WRITE);
7191 if (ret) {
7192 mlog_errno(ret);
7193 goto out_commit;
7194 }
7195
7196 if (has_data) {
7197 u32 bit_off, num;

--- 63 unchanged lines hidden (view full) ---

7261 ocfs2_journal_dirty(handle, di_bh);
7262
7263 if (has_data) {
7264 /*
7265 * An error at this point should be extremely rare. If
7266 * this proves to be false, we could always re-build
7267 * the in-inode data from our pages.
7268 */
7221 ocfs2_init_dinode_extent_tree(&et, inode, di_bh);
7222 ret = ocfs2_insert_extent(osb, handle, inode, &et,
7223 0, block, 1, 0, NULL);
7269 ocfs2_init_dinode_extent_tree(&et, INODE_CACHE(inode), di_bh);
7270 ret = ocfs2_insert_extent(handle, &et, 0, block, 1, 0, NULL);
7224 if (ret) {
7225 mlog_errno(ret);
7226 goto out_commit;
7227 }
7228
7229 inode->i_blocks = ocfs2_inode_sector_count(inode);
7230 }
7231

--- 58 unchanged lines hidden (view full) ---

7290 if (OCFS2_I(inode)->ip_clusters == 0) {
7291 status = 0;
7292 goto bail;
7293 }
7294
7295 /*
7296 * Truncate always works against the rightmost tree branch.
7297 */
7271 if (ret) {
7272 mlog_errno(ret);
7273 goto out_commit;
7274 }
7275
7276 inode->i_blocks = ocfs2_inode_sector_count(inode);
7277 }
7278

--- 58 unchanged lines hidden (view full) ---

7337 if (OCFS2_I(inode)->ip_clusters == 0) {
7338 status = 0;
7339 goto bail;
7340 }
7341
7342 /*
7343 * Truncate always works against the rightmost tree branch.
7344 */
7298 status = ocfs2_find_path(inode, path, UINT_MAX);
7345 status = ocfs2_find_path(INODE_CACHE(inode), path, UINT_MAX);
7299 if (status) {
7300 mlog_errno(status);
7301 goto bail;
7302 }
7303
7304 mlog(0, "inode->ip_clusters = %u, tree_depth = %u\n",
7305 OCFS2_I(inode)->ip_clusters, path->p_tree_depth);
7306

--- 133 unchanged lines hidden (view full) ---

7440 if (!(*tc)) {
7441 status = -ENOMEM;
7442 mlog_errno(status);
7443 goto bail;
7444 }
7445 ocfs2_init_dealloc_ctxt(&(*tc)->tc_dealloc);
7446
7447 if (fe->id2.i_list.l_tree_depth) {
7346 if (status) {
7347 mlog_errno(status);
7348 goto bail;
7349 }
7350
7351 mlog(0, "inode->ip_clusters = %u, tree_depth = %u\n",
7352 OCFS2_I(inode)->ip_clusters, path->p_tree_depth);
7353

--- 133 unchanged lines hidden (view full) ---

7487 if (!(*tc)) {
7488 status = -ENOMEM;
7489 mlog_errno(status);
7490 goto bail;
7491 }
7492 ocfs2_init_dealloc_ctxt(&(*tc)->tc_dealloc);
7493
7494 if (fe->id2.i_list.l_tree_depth) {
7448 status = ocfs2_read_extent_block(inode,
7495 status = ocfs2_read_extent_block(INODE_CACHE(inode),
7449 le64_to_cpu(fe->i_last_eb_blk),
7450 &last_eb_bh);
7451 if (status < 0) {
7452 mlog_errno(status);
7453 goto bail;
7454 }
7455 eb = (struct ocfs2_extent_block *) last_eb_bh->b_data;
7456 }

--- 45 unchanged lines hidden (view full) ---

7502
7503 handle = ocfs2_start_trans(osb, OCFS2_INODE_UPDATE_CREDITS);
7504 if (IS_ERR(handle)) {
7505 ret = PTR_ERR(handle);
7506 mlog_errno(ret);
7507 goto out;
7508 }
7509
7496 le64_to_cpu(fe->i_last_eb_blk),
7497 &last_eb_bh);
7498 if (status < 0) {
7499 mlog_errno(status);
7500 goto bail;
7501 }
7502 eb = (struct ocfs2_extent_block *) last_eb_bh->b_data;
7503 }

--- 45 unchanged lines hidden (view full) ---

7549
7550 handle = ocfs2_start_trans(osb, OCFS2_INODE_UPDATE_CREDITS);
7551 if (IS_ERR(handle)) {
7552 ret = PTR_ERR(handle);
7553 mlog_errno(ret);
7554 goto out;
7555 }
7556
7510 ret = ocfs2_journal_access_di(handle, inode, di_bh,
7557 ret = ocfs2_journal_access_di(handle, INODE_CACHE(inode), di_bh,
7511 OCFS2_JOURNAL_ACCESS_WRITE);
7512 if (ret) {
7513 mlog_errno(ret);
7514 goto out_commit;
7515 }
7516
7517 numbytes = end - start;
7518 memset(idata->id_data + start, 0, numbytes);

--- 41 unchanged lines hidden ---
7558 OCFS2_JOURNAL_ACCESS_WRITE);
7559 if (ret) {
7560 mlog_errno(ret);
7561 goto out_commit;
7562 }
7563
7564 numbytes = end - start;
7565 memset(idata->id_data + start, 0, numbytes);

--- 41 unchanged lines hidden ---