extents.c (b855192c08fcb14adbc5d3a7cab182022d433cca) extents.c (55ad63bf3a30936aced50f13452735c2f58b234c)
1/*
2 * Copyright (c) 2003-2006, Cluster File Systems, Inc, info@clusterfs.com
3 * Written by Alex Tomas <alex@clusterfs.com>
4 *
5 * Architecture independence:
6 * Copyright (c) 2005, Bull S.A.
7 * Written by Pierre Peiffer <pierre.peiffer@bull.net>
8 *

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

88 * breaking it into parts
89 */
90static void ext4_idx_store_pblock(struct ext4_extent_idx *ix, ext4_fsblk_t pb)
91{
92 ix->ei_leaf_lo = cpu_to_le32((unsigned long) (pb & 0xffffffff));
93 ix->ei_leaf_hi = cpu_to_le16((unsigned long) ((pb >> 31) >> 1) & 0xffff);
94}
95
1/*
2 * Copyright (c) 2003-2006, Cluster File Systems, Inc, info@clusterfs.com
3 * Written by Alex Tomas <alex@clusterfs.com>
4 *
5 * Architecture independence:
6 * Copyright (c) 2005, Bull S.A.
7 * Written by Pierre Peiffer <pierre.peiffer@bull.net>
8 *

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

88 * breaking it into parts
89 */
90static void ext4_idx_store_pblock(struct ext4_extent_idx *ix, ext4_fsblk_t pb)
91{
92 ix->ei_leaf_lo = cpu_to_le32((unsigned long) (pb & 0xffffffff));
93 ix->ei_leaf_hi = cpu_to_le16((unsigned long) ((pb >> 31) >> 1) & 0xffff);
94}
95
96static int ext4_ext_journal_restart(handle_t *handle, int needed)
96static int ext4_ext_truncate_extend_restart(handle_t *handle,
97 struct inode *inode,
98 int needed)
97{
98 int err;
99
100 if (!ext4_handle_valid(handle))
101 return 0;
102 if (handle->h_buffer_credits > needed)
103 return 0;
104 err = ext4_journal_extend(handle, needed);
105 if (err <= 0)
106 return err;
99{
100 int err;
101
102 if (!ext4_handle_valid(handle))
103 return 0;
104 if (handle->h_buffer_credits > needed)
105 return 0;
106 err = ext4_journal_extend(handle, needed);
107 if (err <= 0)
108 return err;
107 return ext4_journal_restart(handle, needed);
109 err = ext4_truncate_restart_trans(handle, inode, needed);
110 /*
111 * We have dropped i_data_sem so someone might have cached again
112 * an extent we are going to truncate.
113 */
114 ext4_ext_invalidate_cache(inode);
115
116 return err;
108}
109
110/*
111 * could return:
112 * - EROFS
113 * - ENOMEM
114 */
115static int ext4_ext_get_access(handle_t *handle, struct inode *inode,

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

215{
216 ext4_fsblk_t goal, newblock;
217
218 goal = ext4_ext_find_goal(inode, path, le32_to_cpu(ex->ee_block));
219 newblock = ext4_new_meta_blocks(handle, inode, goal, NULL, err);
220 return newblock;
221}
222
117}
118
119/*
120 * could return:
121 * - EROFS
122 * - ENOMEM
123 */
124static int ext4_ext_get_access(handle_t *handle, struct inode *inode,

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

224{
225 ext4_fsblk_t goal, newblock;
226
227 goal = ext4_ext_find_goal(inode, path, le32_to_cpu(ex->ee_block));
228 newblock = ext4_new_meta_blocks(handle, inode, goal, NULL, err);
229 return newblock;
230}
231
223static int ext4_ext_space_block(struct inode *inode)
232static inline int ext4_ext_space_block(struct inode *inode, int check)
224{
225 int size;
226
227 size = (inode->i_sb->s_blocksize - sizeof(struct ext4_extent_header))
228 / sizeof(struct ext4_extent);
233{
234 int size;
235
236 size = (inode->i_sb->s_blocksize - sizeof(struct ext4_extent_header))
237 / sizeof(struct ext4_extent);
238 if (!check) {
229#ifdef AGGRESSIVE_TEST
239#ifdef AGGRESSIVE_TEST
230 if (size > 6)
231 size = 6;
240 if (size > 6)
241 size = 6;
232#endif
242#endif
243 }
233 return size;
234}
235
244 return size;
245}
246
236static int ext4_ext_space_block_idx(struct inode *inode)
247static inline int ext4_ext_space_block_idx(struct inode *inode, int check)
237{
238 int size;
239
240 size = (inode->i_sb->s_blocksize - sizeof(struct ext4_extent_header))
241 / sizeof(struct ext4_extent_idx);
248{
249 int size;
250
251 size = (inode->i_sb->s_blocksize - sizeof(struct ext4_extent_header))
252 / sizeof(struct ext4_extent_idx);
253 if (!check) {
242#ifdef AGGRESSIVE_TEST
254#ifdef AGGRESSIVE_TEST
243 if (size > 5)
244 size = 5;
255 if (size > 5)
256 size = 5;
245#endif
257#endif
258 }
246 return size;
247}
248
259 return size;
260}
261
249static int ext4_ext_space_root(struct inode *inode)
262static inline int ext4_ext_space_root(struct inode *inode, int check)
250{
251 int size;
252
253 size = sizeof(EXT4_I(inode)->i_data);
254 size -= sizeof(struct ext4_extent_header);
255 size /= sizeof(struct ext4_extent);
263{
264 int size;
265
266 size = sizeof(EXT4_I(inode)->i_data);
267 size -= sizeof(struct ext4_extent_header);
268 size /= sizeof(struct ext4_extent);
269 if (!check) {
256#ifdef AGGRESSIVE_TEST
270#ifdef AGGRESSIVE_TEST
257 if (size > 3)
258 size = 3;
271 if (size > 3)
272 size = 3;
259#endif
273#endif
274 }
260 return size;
261}
262
275 return size;
276}
277
263static int ext4_ext_space_root_idx(struct inode *inode)
278static inline int ext4_ext_space_root_idx(struct inode *inode, int check)
264{
265 int size;
266
267 size = sizeof(EXT4_I(inode)->i_data);
268 size -= sizeof(struct ext4_extent_header);
269 size /= sizeof(struct ext4_extent_idx);
279{
280 int size;
281
282 size = sizeof(EXT4_I(inode)->i_data);
283 size -= sizeof(struct ext4_extent_header);
284 size /= sizeof(struct ext4_extent_idx);
285 if (!check) {
270#ifdef AGGRESSIVE_TEST
286#ifdef AGGRESSIVE_TEST
271 if (size > 4)
272 size = 4;
287 if (size > 4)
288 size = 4;
273#endif
289#endif
290 }
274 return size;
275}
276
277/*
278 * Calculate the number of metadata blocks needed
279 * to allocate @blocks
280 * Worse case is one block per extent
281 */
282int ext4_ext_calc_metadata_amount(struct inode *inode, int blocks)
283{
284 int lcap, icap, rcap, leafs, idxs, num;
285 int newextents = blocks;
286
291 return size;
292}
293
294/*
295 * Calculate the number of metadata blocks needed
296 * to allocate @blocks
297 * Worse case is one block per extent
298 */
299int ext4_ext_calc_metadata_amount(struct inode *inode, int blocks)
300{
301 int lcap, icap, rcap, leafs, idxs, num;
302 int newextents = blocks;
303
287 rcap = ext4_ext_space_root_idx(inode);
288 lcap = ext4_ext_space_block(inode);
289 icap = ext4_ext_space_block_idx(inode);
304 rcap = ext4_ext_space_root_idx(inode, 0);
305 lcap = ext4_ext_space_block(inode, 0);
306 icap = ext4_ext_space_block_idx(inode, 0);
290
291 /* number of new leaf blocks needed */
292 num = leafs = (newextents + lcap - 1) / lcap;
293
294 /*
295 * Worse case, we need separate index block(s)
296 * to link all new leaf blocks
297 */

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

306
307static int
308ext4_ext_max_entries(struct inode *inode, int depth)
309{
310 int max;
311
312 if (depth == ext_depth(inode)) {
313 if (depth == 0)
307
308 /* number of new leaf blocks needed */
309 num = leafs = (newextents + lcap - 1) / lcap;
310
311 /*
312 * Worse case, we need separate index block(s)
313 * to link all new leaf blocks
314 */

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

323
324static int
325ext4_ext_max_entries(struct inode *inode, int depth)
326{
327 int max;
328
329 if (depth == ext_depth(inode)) {
330 if (depth == 0)
314 max = ext4_ext_space_root(inode);
331 max = ext4_ext_space_root(inode, 1);
315 else
332 else
316 max = ext4_ext_space_root_idx(inode);
333 max = ext4_ext_space_root_idx(inode, 1);
317 } else {
318 if (depth == 0)
334 } else {
335 if (depth == 0)
319 max = ext4_ext_space_block(inode);
336 max = ext4_ext_space_block(inode, 1);
320 else
337 else
321 max = ext4_ext_space_block_idx(inode);
338 max = ext4_ext_space_block_idx(inode, 1);
322 }
323
324 return max;
325}
326
327static int ext4_valid_extent(struct inode *inode, struct ext4_extent *ext)
328{
329 ext4_fsblk_t block = ext_pblock(ext);

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

432 int k, l = path->p_depth;
433
434 ext_debug("path:");
435 for (k = 0; k <= l; k++, path++) {
436 if (path->p_idx) {
437 ext_debug(" %d->%llu", le32_to_cpu(path->p_idx->ei_block),
438 idx_pblock(path->p_idx));
439 } else if (path->p_ext) {
339 }
340
341 return max;
342}
343
344static int ext4_valid_extent(struct inode *inode, struct ext4_extent *ext)
345{
346 ext4_fsblk_t block = ext_pblock(ext);

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

449 int k, l = path->p_depth;
450
451 ext_debug("path:");
452 for (k = 0; k <= l; k++, path++) {
453 if (path->p_idx) {
454 ext_debug(" %d->%llu", le32_to_cpu(path->p_idx->ei_block),
455 idx_pblock(path->p_idx));
456 } else if (path->p_ext) {
440 ext_debug(" %d:%d:%llu ",
457 ext_debug(" %d:[%d]%d:%llu ",
441 le32_to_cpu(path->p_ext->ee_block),
458 le32_to_cpu(path->p_ext->ee_block),
459 ext4_ext_is_uninitialized(path->p_ext),
442 ext4_ext_get_actual_len(path->p_ext),
443 ext_pblock(path->p_ext));
444 } else
445 ext_debug(" []");
446 }
447 ext_debug("\n");
448}
449

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

455 int i;
456
457 if (!path)
458 return;
459
460 eh = path[depth].p_hdr;
461 ex = EXT_FIRST_EXTENT(eh);
462
460 ext4_ext_get_actual_len(path->p_ext),
461 ext_pblock(path->p_ext));
462 } else
463 ext_debug(" []");
464 }
465 ext_debug("\n");
466}
467

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

473 int i;
474
475 if (!path)
476 return;
477
478 eh = path[depth].p_hdr;
479 ex = EXT_FIRST_EXTENT(eh);
480
481 ext_debug("Displaying leaf extents for inode %lu\n", inode->i_ino);
482
463 for (i = 0; i < le16_to_cpu(eh->eh_entries); i++, ex++) {
483 for (i = 0; i < le16_to_cpu(eh->eh_entries); i++, ex++) {
464 ext_debug("%d:%d:%llu ", le32_to_cpu(ex->ee_block),
484 ext_debug("%d:[%d]%d:%llu ", le32_to_cpu(ex->ee_block),
485 ext4_ext_is_uninitialized(ex),
465 ext4_ext_get_actual_len(ex), ext_pblock(ex));
466 }
467 ext_debug("\n");
468}
469#else
470#define ext4_ext_show_path(inode, path)
471#define ext4_ext_show_leaf(inode, path)
472#endif

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

575 else
576 l = m + 1;
577 ext_debug("%p(%u):%p(%u):%p(%u) ", l, le32_to_cpu(l->ee_block),
578 m, le32_to_cpu(m->ee_block),
579 r, le32_to_cpu(r->ee_block));
580 }
581
582 path->p_ext = l - 1;
486 ext4_ext_get_actual_len(ex), ext_pblock(ex));
487 }
488 ext_debug("\n");
489}
490#else
491#define ext4_ext_show_path(inode, path)
492#define ext4_ext_show_leaf(inode, path)
493#endif

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

596 else
597 l = m + 1;
598 ext_debug("%p(%u):%p(%u):%p(%u) ", l, le32_to_cpu(l->ee_block),
599 m, le32_to_cpu(m->ee_block),
600 r, le32_to_cpu(r->ee_block));
601 }
602
603 path->p_ext = l - 1;
583 ext_debug(" -> %d:%llu:%d ",
604 ext_debug(" -> %d:%llu:[%d]%d ",
584 le32_to_cpu(path->p_ext->ee_block),
585 ext_pblock(path->p_ext),
605 le32_to_cpu(path->p_ext->ee_block),
606 ext_pblock(path->p_ext),
607 ext4_ext_is_uninitialized(path->p_ext),
586 ext4_ext_get_actual_len(path->p_ext));
587
588#ifdef CHECK_BINSEARCH
589 {
590 struct ext4_extent *chex, *ex;
591 int k;
592
593 chex = ex = EXT_FIRST_EXTENT(eh);

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

607int ext4_ext_tree_init(handle_t *handle, struct inode *inode)
608{
609 struct ext4_extent_header *eh;
610
611 eh = ext_inode_hdr(inode);
612 eh->eh_depth = 0;
613 eh->eh_entries = 0;
614 eh->eh_magic = EXT4_EXT_MAGIC;
608 ext4_ext_get_actual_len(path->p_ext));
609
610#ifdef CHECK_BINSEARCH
611 {
612 struct ext4_extent *chex, *ex;
613 int k;
614
615 chex = ex = EXT_FIRST_EXTENT(eh);

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

629int ext4_ext_tree_init(handle_t *handle, struct inode *inode)
630{
631 struct ext4_extent_header *eh;
632
633 eh = ext_inode_hdr(inode);
634 eh->eh_depth = 0;
635 eh->eh_entries = 0;
636 eh->eh_magic = EXT4_EXT_MAGIC;
615 eh->eh_max = cpu_to_le16(ext4_ext_space_root(inode));
637 eh->eh_max = cpu_to_le16(ext4_ext_space_root(inode, 0));
616 ext4_mark_inode_dirty(handle, inode);
617 ext4_ext_invalidate_cache(inode);
618 return 0;
619}
620
621struct ext4_ext_path *
622ext4_ext_find_extent(struct inode *inode, ext4_lblk_t block,
623 struct ext4_ext_path *path)

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

832 lock_buffer(bh);
833
834 err = ext4_journal_get_create_access(handle, bh);
835 if (err)
836 goto cleanup;
837
838 neh = ext_block_hdr(bh);
839 neh->eh_entries = 0;
638 ext4_mark_inode_dirty(handle, inode);
639 ext4_ext_invalidate_cache(inode);
640 return 0;
641}
642
643struct ext4_ext_path *
644ext4_ext_find_extent(struct inode *inode, ext4_lblk_t block,
645 struct ext4_ext_path *path)

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

854 lock_buffer(bh);
855
856 err = ext4_journal_get_create_access(handle, bh);
857 if (err)
858 goto cleanup;
859
860 neh = ext_block_hdr(bh);
861 neh->eh_entries = 0;
840 neh->eh_max = cpu_to_le16(ext4_ext_space_block(inode));
862 neh->eh_max = cpu_to_le16(ext4_ext_space_block(inode, 0));
841 neh->eh_magic = EXT4_EXT_MAGIC;
842 neh->eh_depth = 0;
843 ex = EXT_FIRST_EXTENT(neh);
844
845 /* move remainder of path[depth] to the new leaf */
846 BUG_ON(path[depth].p_hdr->eh_entries != path[depth].p_hdr->eh_max);
847 /* start copy from next extent */
848 /* TODO: we could do it by single memmove */
849 m = 0;
850 path[depth].p_ext++;
851 while (path[depth].p_ext <=
852 EXT_MAX_EXTENT(path[depth].p_hdr)) {
863 neh->eh_magic = EXT4_EXT_MAGIC;
864 neh->eh_depth = 0;
865 ex = EXT_FIRST_EXTENT(neh);
866
867 /* move remainder of path[depth] to the new leaf */
868 BUG_ON(path[depth].p_hdr->eh_entries != path[depth].p_hdr->eh_max);
869 /* start copy from next extent */
870 /* TODO: we could do it by single memmove */
871 m = 0;
872 path[depth].p_ext++;
873 while (path[depth].p_ext <=
874 EXT_MAX_EXTENT(path[depth].p_hdr)) {
853 ext_debug("move %d:%llu:%d in new leaf %llu\n",
875 ext_debug("move %d:%llu:[%d]%d in new leaf %llu\n",
854 le32_to_cpu(path[depth].p_ext->ee_block),
855 ext_pblock(path[depth].p_ext),
876 le32_to_cpu(path[depth].p_ext->ee_block),
877 ext_pblock(path[depth].p_ext),
878 ext4_ext_is_uninitialized(path[depth].p_ext),
856 ext4_ext_get_actual_len(path[depth].p_ext),
857 newblock);
858 /*memmove(ex++, path[depth].p_ext++,
859 sizeof(struct ext4_extent));
860 neh->eh_entries++;*/
861 path[depth].p_ext++;
862 m++;
863 }

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

907
908 err = ext4_journal_get_create_access(handle, bh);
909 if (err)
910 goto cleanup;
911
912 neh = ext_block_hdr(bh);
913 neh->eh_entries = cpu_to_le16(1);
914 neh->eh_magic = EXT4_EXT_MAGIC;
879 ext4_ext_get_actual_len(path[depth].p_ext),
880 newblock);
881 /*memmove(ex++, path[depth].p_ext++,
882 sizeof(struct ext4_extent));
883 neh->eh_entries++;*/
884 path[depth].p_ext++;
885 m++;
886 }

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

930
931 err = ext4_journal_get_create_access(handle, bh);
932 if (err)
933 goto cleanup;
934
935 neh = ext_block_hdr(bh);
936 neh->eh_entries = cpu_to_le16(1);
937 neh->eh_magic = EXT4_EXT_MAGIC;
915 neh->eh_max = cpu_to_le16(ext4_ext_space_block_idx(inode));
938 neh->eh_max = cpu_to_le16(ext4_ext_space_block_idx(inode, 0));
916 neh->eh_depth = cpu_to_le16(depth - i);
917 fidx = EXT_FIRST_INDEX(neh);
918 fidx->ei_block = border;
919 ext4_idx_store_pblock(fidx, oldblock);
920
921 ext_debug("int.index at %d (block %llu): %u -> %llu\n",
922 i, newblock, le32_to_cpu(border), oldblock);
923 /* copy indexes */

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

1032 /* move top-level index/leaf into new block */
1033 memmove(bh->b_data, curp->p_hdr, sizeof(EXT4_I(inode)->i_data));
1034
1035 /* set size of new block */
1036 neh = ext_block_hdr(bh);
1037 /* old root could have indexes or leaves
1038 * so calculate e_max right way */
1039 if (ext_depth(inode))
939 neh->eh_depth = cpu_to_le16(depth - i);
940 fidx = EXT_FIRST_INDEX(neh);
941 fidx->ei_block = border;
942 ext4_idx_store_pblock(fidx, oldblock);
943
944 ext_debug("int.index at %d (block %llu): %u -> %llu\n",
945 i, newblock, le32_to_cpu(border), oldblock);
946 /* copy indexes */

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

1055 /* move top-level index/leaf into new block */
1056 memmove(bh->b_data, curp->p_hdr, sizeof(EXT4_I(inode)->i_data));
1057
1058 /* set size of new block */
1059 neh = ext_block_hdr(bh);
1060 /* old root could have indexes or leaves
1061 * so calculate e_max right way */
1062 if (ext_depth(inode))
1040 neh->eh_max = cpu_to_le16(ext4_ext_space_block_idx(inode));
1063 neh->eh_max = cpu_to_le16(ext4_ext_space_block_idx(inode, 0));
1041 else
1064 else
1042 neh->eh_max = cpu_to_le16(ext4_ext_space_block(inode));
1065 neh->eh_max = cpu_to_le16(ext4_ext_space_block(inode, 0));
1043 neh->eh_magic = EXT4_EXT_MAGIC;
1044 set_buffer_uptodate(bh);
1045 unlock_buffer(bh);
1046
1047 err = ext4_handle_dirty_metadata(handle, inode, bh);
1048 if (err)
1049 goto out;
1050
1051 /* create index in new top-level index: num,max,pointer */
1052 err = ext4_ext_get_access(handle, inode, curp);
1053 if (err)
1054 goto out;
1055
1056 curp->p_hdr->eh_magic = EXT4_EXT_MAGIC;
1066 neh->eh_magic = EXT4_EXT_MAGIC;
1067 set_buffer_uptodate(bh);
1068 unlock_buffer(bh);
1069
1070 err = ext4_handle_dirty_metadata(handle, inode, bh);
1071 if (err)
1072 goto out;
1073
1074 /* create index in new top-level index: num,max,pointer */
1075 err = ext4_ext_get_access(handle, inode, curp);
1076 if (err)
1077 goto out;
1078
1079 curp->p_hdr->eh_magic = EXT4_EXT_MAGIC;
1057 curp->p_hdr->eh_max = cpu_to_le16(ext4_ext_space_root_idx(inode));
1080 curp->p_hdr->eh_max = cpu_to_le16(ext4_ext_space_root_idx(inode, 0));
1058 curp->p_hdr->eh_entries = cpu_to_le16(1);
1059 curp->p_idx = EXT_FIRST_INDEX(curp->p_hdr);
1060
1061 if (path[0].p_hdr->eh_depth)
1062 curp->p_idx->ei_block =
1063 EXT_FIRST_INDEX(path[0].p_hdr)->ei_block;
1064 else
1065 curp->p_idx->ei_block =

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

1575
1576 BUG_ON(ext4_ext_get_actual_len(newext) == 0);
1577 depth = ext_depth(inode);
1578 ex = path[depth].p_ext;
1579 BUG_ON(path[depth].p_hdr == NULL);
1580
1581 /* try to insert block into found extent and return */
1582 if (ex && ext4_can_extents_be_merged(inode, ex, newext)) {
1081 curp->p_hdr->eh_entries = cpu_to_le16(1);
1082 curp->p_idx = EXT_FIRST_INDEX(curp->p_hdr);
1083
1084 if (path[0].p_hdr->eh_depth)
1085 curp->p_idx->ei_block =
1086 EXT_FIRST_INDEX(path[0].p_hdr)->ei_block;
1087 else
1088 curp->p_idx->ei_block =

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

1598
1599 BUG_ON(ext4_ext_get_actual_len(newext) == 0);
1600 depth = ext_depth(inode);
1601 ex = path[depth].p_ext;
1602 BUG_ON(path[depth].p_hdr == NULL);
1603
1604 /* try to insert block into found extent and return */
1605 if (ex && ext4_can_extents_be_merged(inode, ex, newext)) {
1583 ext_debug("append %d block to %d:%d (from %llu)\n",
1606 ext_debug("append [%d]%d block to %d:[%d]%d (from %llu)\n",
1607 ext4_ext_is_uninitialized(newext),
1584 ext4_ext_get_actual_len(newext),
1585 le32_to_cpu(ex->ee_block),
1608 ext4_ext_get_actual_len(newext),
1609 le32_to_cpu(ex->ee_block),
1610 ext4_ext_is_uninitialized(ex),
1586 ext4_ext_get_actual_len(ex), ext_pblock(ex));
1587 err = ext4_ext_get_access(handle, inode, path + depth);
1588 if (err)
1589 return err;
1590
1591 /*
1592 * ext4_can_extents_be_merged should have checked that either
1593 * both extents are uninitialized, or both aren't. Thus we

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

1646 nearex = path[depth].p_ext;
1647
1648 err = ext4_ext_get_access(handle, inode, path + depth);
1649 if (err)
1650 goto cleanup;
1651
1652 if (!nearex) {
1653 /* there is no extent in this leaf, create first one */
1611 ext4_ext_get_actual_len(ex), ext_pblock(ex));
1612 err = ext4_ext_get_access(handle, inode, path + depth);
1613 if (err)
1614 return err;
1615
1616 /*
1617 * ext4_can_extents_be_merged should have checked that either
1618 * both extents are uninitialized, or both aren't. Thus we

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

1671 nearex = path[depth].p_ext;
1672
1673 err = ext4_ext_get_access(handle, inode, path + depth);
1674 if (err)
1675 goto cleanup;
1676
1677 if (!nearex) {
1678 /* there is no extent in this leaf, create first one */
1654 ext_debug("first extent in the leaf: %d:%llu:%d\n",
1679 ext_debug("first extent in the leaf: %d:%llu:[%d]%d\n",
1655 le32_to_cpu(newext->ee_block),
1656 ext_pblock(newext),
1680 le32_to_cpu(newext->ee_block),
1681 ext_pblock(newext),
1682 ext4_ext_is_uninitialized(newext),
1657 ext4_ext_get_actual_len(newext));
1658 path[depth].p_ext = EXT_FIRST_EXTENT(eh);
1659 } else if (le32_to_cpu(newext->ee_block)
1660 > le32_to_cpu(nearex->ee_block)) {
1661/* BUG_ON(newext->ee_block == nearex->ee_block); */
1662 if (nearex != EXT_LAST_EXTENT(eh)) {
1663 len = EXT_MAX_EXTENT(eh) - nearex;
1664 len = (len - 1) * sizeof(struct ext4_extent);
1665 len = len < 0 ? 0 : len;
1683 ext4_ext_get_actual_len(newext));
1684 path[depth].p_ext = EXT_FIRST_EXTENT(eh);
1685 } else if (le32_to_cpu(newext->ee_block)
1686 > le32_to_cpu(nearex->ee_block)) {
1687/* BUG_ON(newext->ee_block == nearex->ee_block); */
1688 if (nearex != EXT_LAST_EXTENT(eh)) {
1689 len = EXT_MAX_EXTENT(eh) - nearex;
1690 len = (len - 1) * sizeof(struct ext4_extent);
1691 len = len < 0 ? 0 : len;
1666 ext_debug("insert %d:%llu:%d after: nearest 0x%p, "
1692 ext_debug("insert %d:%llu:[%d]%d after: nearest 0x%p, "
1667 "move %d from 0x%p to 0x%p\n",
1668 le32_to_cpu(newext->ee_block),
1669 ext_pblock(newext),
1693 "move %d from 0x%p to 0x%p\n",
1694 le32_to_cpu(newext->ee_block),
1695 ext_pblock(newext),
1696 ext4_ext_is_uninitialized(newext),
1670 ext4_ext_get_actual_len(newext),
1671 nearex, len, nearex + 1, nearex + 2);
1672 memmove(nearex + 2, nearex + 1, len);
1673 }
1674 path[depth].p_ext = nearex + 1;
1675 } else {
1676 BUG_ON(newext->ee_block == nearex->ee_block);
1677 len = (EXT_MAX_EXTENT(eh) - nearex) * sizeof(struct ext4_extent);
1678 len = len < 0 ? 0 : len;
1697 ext4_ext_get_actual_len(newext),
1698 nearex, len, nearex + 1, nearex + 2);
1699 memmove(nearex + 2, nearex + 1, len);
1700 }
1701 path[depth].p_ext = nearex + 1;
1702 } else {
1703 BUG_ON(newext->ee_block == nearex->ee_block);
1704 len = (EXT_MAX_EXTENT(eh) - nearex) * sizeof(struct ext4_extent);
1705 len = len < 0 ? 0 : len;
1679 ext_debug("insert %d:%llu:%d before: nearest 0x%p, "
1706 ext_debug("insert %d:%llu:[%d]%d before: nearest 0x%p, "
1680 "move %d from 0x%p to 0x%p\n",
1681 le32_to_cpu(newext->ee_block),
1682 ext_pblock(newext),
1707 "move %d from 0x%p to 0x%p\n",
1708 le32_to_cpu(newext->ee_block),
1709 ext_pblock(newext),
1710 ext4_ext_is_uninitialized(newext),
1683 ext4_ext_get_actual_len(newext),
1684 nearex, len, nearex + 1, nearex + 2);
1685 memmove(nearex + 1, nearex, len);
1686 path[depth].p_ext = nearex;
1687 }
1688
1689 le16_add_cpu(&eh->eh_entries, 1);
1690 nearex = path[depth].p_ext;

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

2089 while (ex >= EXT_FIRST_EXTENT(eh) &&
2090 ex_ee_block + ex_ee_len > start) {
2091
2092 if (ext4_ext_is_uninitialized(ex))
2093 uninitialized = 1;
2094 else
2095 uninitialized = 0;
2096
1711 ext4_ext_get_actual_len(newext),
1712 nearex, len, nearex + 1, nearex + 2);
1713 memmove(nearex + 1, nearex, len);
1714 path[depth].p_ext = nearex;
1715 }
1716
1717 le16_add_cpu(&eh->eh_entries, 1);
1718 nearex = path[depth].p_ext;

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

2117 while (ex >= EXT_FIRST_EXTENT(eh) &&
2118 ex_ee_block + ex_ee_len > start) {
2119
2120 if (ext4_ext_is_uninitialized(ex))
2121 uninitialized = 1;
2122 else
2123 uninitialized = 0;
2124
2097 ext_debug("remove ext %lu:%u\n", ex_ee_block, ex_ee_len);
2125 ext_debug("remove ext %u:[%d]%d\n", ex_ee_block,
2126 uninitialized, ex_ee_len);
2098 path[depth].p_ext = ex;
2099
2100 a = ex_ee_block > start ? ex_ee_block : start;
2101 b = ex_ee_block + ex_ee_len - 1 < EXT_MAX_BLOCK ?
2102 ex_ee_block + ex_ee_len - 1 : EXT_MAX_BLOCK;
2103
2104 ext_debug(" border %u:%u\n", a, b);
2105

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

2133 */
2134 credits = 7 + 2*(ex_ee_len/EXT4_BLOCKS_PER_GROUP(inode->i_sb));
2135 if (ex == EXT_FIRST_EXTENT(eh)) {
2136 correct_index = 1;
2137 credits += (ext_depth(inode)) + 1;
2138 }
2139 credits += 2 * EXT4_QUOTA_TRANS_BLOCKS(inode->i_sb);
2140
2127 path[depth].p_ext = ex;
2128
2129 a = ex_ee_block > start ? ex_ee_block : start;
2130 b = ex_ee_block + ex_ee_len - 1 < EXT_MAX_BLOCK ?
2131 ex_ee_block + ex_ee_len - 1 : EXT_MAX_BLOCK;
2132
2133 ext_debug(" border %u:%u\n", a, b);
2134

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

2162 */
2163 credits = 7 + 2*(ex_ee_len/EXT4_BLOCKS_PER_GROUP(inode->i_sb));
2164 if (ex == EXT_FIRST_EXTENT(eh)) {
2165 correct_index = 1;
2166 credits += (ext_depth(inode)) + 1;
2167 }
2168 credits += 2 * EXT4_QUOTA_TRANS_BLOCKS(inode->i_sb);
2169
2141 err = ext4_ext_journal_restart(handle, credits);
2170 err = ext4_ext_truncate_extend_restart(handle, inode, credits);
2142 if (err)
2143 goto out;
2144
2145 err = ext4_ext_get_access(handle, inode, path + depth);
2146 if (err)
2147 goto out;
2148
2149 err = ext4_remove_blocks(handle, inode, ex, a, b);

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

2322 /*
2323 * truncate to zero freed all the tree,
2324 * so we need to correct eh_depth
2325 */
2326 err = ext4_ext_get_access(handle, inode, path);
2327 if (err == 0) {
2328 ext_inode_hdr(inode)->eh_depth = 0;
2329 ext_inode_hdr(inode)->eh_max =
2171 if (err)
2172 goto out;
2173
2174 err = ext4_ext_get_access(handle, inode, path + depth);
2175 if (err)
2176 goto out;
2177
2178 err = ext4_remove_blocks(handle, inode, ex, a, b);

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

2351 /*
2352 * truncate to zero freed all the tree,
2353 * so we need to correct eh_depth
2354 */
2355 err = ext4_ext_get_access(handle, inode, path);
2356 if (err == 0) {
2357 ext_inode_hdr(inode)->eh_depth = 0;
2358 ext_inode_hdr(inode)->eh_max =
2330 cpu_to_le16(ext4_ext_space_root(inode));
2359 cpu_to_le16(ext4_ext_space_root(inode, 0));
2331 err = ext4_ext_dirty(handle, inode, path);
2332 }
2333 }
2334out:
2335 ext4_ext_drop_refs(path);
2336 kfree(path);
2337 ext4_journal_stop(handle);
2338

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

2738 ex->ee_len = orig_ex.ee_len;
2739 ext4_ext_store_pblock(ex, ext_pblock(&orig_ex));
2740 ext4_ext_dirty(handle, inode, path + depth);
2741 /* zero out the first half */
2742 return allocated;
2743 } else if (err)
2744 goto fix_extent_len;
2745out:
2360 err = ext4_ext_dirty(handle, inode, path);
2361 }
2362 }
2363out:
2364 ext4_ext_drop_refs(path);
2365 kfree(path);
2366 ext4_journal_stop(handle);
2367

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

2767 ex->ee_len = orig_ex.ee_len;
2768 ext4_ext_store_pblock(ex, ext_pblock(&orig_ex));
2769 ext4_ext_dirty(handle, inode, path + depth);
2770 /* zero out the first half */
2771 return allocated;
2772 } else if (err)
2773 goto fix_extent_len;
2774out:
2775 ext4_ext_show_leaf(inode, path);
2746 return err ? err : allocated;
2747
2748fix_extent_len:
2749 ex->ee_block = orig_ex.ee_block;
2750 ex->ee_len = orig_ex.ee_len;
2751 ext4_ext_store_pblock(ex, ext_pblock(&orig_ex));
2752 ext4_ext_mark_uninitialized(ex);
2753 ext4_ext_dirty(handle, inode, path + depth);

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

2781 struct ext4_extent_header *eh;
2782 struct ext4_extent newex, *ex;
2783 ext4_fsblk_t newblock;
2784 int err = 0, depth, ret, cache_type;
2785 unsigned int allocated = 0;
2786 struct ext4_allocation_request ar;
2787
2788 __clear_bit(BH_New, &bh_result->b_state);
2776 return err ? err : allocated;
2777
2778fix_extent_len:
2779 ex->ee_block = orig_ex.ee_block;
2780 ex->ee_len = orig_ex.ee_len;
2781 ext4_ext_store_pblock(ex, ext_pblock(&orig_ex));
2782 ext4_ext_mark_uninitialized(ex);
2783 ext4_ext_dirty(handle, inode, path + depth);

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

2811 struct ext4_extent_header *eh;
2812 struct ext4_extent newex, *ex;
2813 ext4_fsblk_t newblock;
2814 int err = 0, depth, ret, cache_type;
2815 unsigned int allocated = 0;
2816 struct ext4_allocation_request ar;
2817
2818 __clear_bit(BH_New, &bh_result->b_state);
2789 ext_debug("blocks %u/%u requested for inode %u\n",
2819 ext_debug("blocks %u/%u requested for inode %lu\n",
2790 iblock, max_blocks, inode->i_ino);
2791
2792 /* check in cache */
2793 cache_type = ext4_ext_in_cache(inode, iblock, &newex);
2794 if (cache_type) {
2795 if (cache_type == EXT4_EXT_CACHE_GAP) {
2796 if ((flags & EXT4_GET_BLOCKS_CREATE) == 0) {
2797 /*

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

2844 * we split out initialized portions during a write.
2845 */
2846 ee_len = ext4_ext_get_actual_len(ex);
2847 /* if found extent covers block, simply return it */
2848 if (iblock >= ee_block && iblock < ee_block + ee_len) {
2849 newblock = iblock - ee_block + ee_start;
2850 /* number of remaining blocks in the extent */
2851 allocated = ee_len - (iblock - ee_block);
2820 iblock, max_blocks, inode->i_ino);
2821
2822 /* check in cache */
2823 cache_type = ext4_ext_in_cache(inode, iblock, &newex);
2824 if (cache_type) {
2825 if (cache_type == EXT4_EXT_CACHE_GAP) {
2826 if ((flags & EXT4_GET_BLOCKS_CREATE) == 0) {
2827 /*

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

2874 * we split out initialized portions during a write.
2875 */
2876 ee_len = ext4_ext_get_actual_len(ex);
2877 /* if found extent covers block, simply return it */
2878 if (iblock >= ee_block && iblock < ee_block + ee_len) {
2879 newblock = iblock - ee_block + ee_start;
2880 /* number of remaining blocks in the extent */
2881 allocated = ee_len - (iblock - ee_block);
2852 ext_debug("%u fit into %lu:%d -> %llu\n", iblock,
2882 ext_debug("%u fit into %u:%d -> %llu\n", iblock,
2853 ee_block, ee_len, newblock);
2854
2855 /* Do not put uninitialized extent in the cache */
2856 if (!ext4_ext_is_uninitialized(ex)) {
2857 ext4_ext_put_in_cache(inode, ee_block,
2858 ee_len, ee_start,
2859 EXT4_EXT_CACHE_EXTENT);
2860 goto out;

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

2945 if (S_ISREG(inode->i_mode))
2946 ar.flags = EXT4_MB_HINT_DATA;
2947 else
2948 /* disable in-core preallocation for non-regular files */
2949 ar.flags = 0;
2950 newblock = ext4_mb_new_blocks(handle, &ar, &err);
2951 if (!newblock)
2952 goto out2;
2883 ee_block, ee_len, newblock);
2884
2885 /* Do not put uninitialized extent in the cache */
2886 if (!ext4_ext_is_uninitialized(ex)) {
2887 ext4_ext_put_in_cache(inode, ee_block,
2888 ee_len, ee_start,
2889 EXT4_EXT_CACHE_EXTENT);
2890 goto out;

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

2975 if (S_ISREG(inode->i_mode))
2976 ar.flags = EXT4_MB_HINT_DATA;
2977 else
2978 /* disable in-core preallocation for non-regular files */
2979 ar.flags = 0;
2980 newblock = ext4_mb_new_blocks(handle, &ar, &err);
2981 if (!newblock)
2982 goto out2;
2953 ext_debug("allocate new block: goal %llu, found %llu/%lu\n",
2983 ext_debug("allocate new block: goal %llu, found %llu/%u\n",
2954 ar.goal, newblock, allocated);
2955
2956 /* try to insert new extent into found leaf and return */
2957 ext4_ext_store_pblock(&newex, newblock);
2958 newex.ee_len = cpu_to_le16(ar.len);
2959 if (flags & EXT4_GET_BLOCKS_UNINIT_EXT) /* Mark uninitialized */
2960 ext4_ext_mark_uninitialized(&newex);
2961 err = ext4_ext_insert_extent(handle, inode, path, &newex);

--- 358 unchanged lines hidden ---
2984 ar.goal, newblock, allocated);
2985
2986 /* try to insert new extent into found leaf and return */
2987 ext4_ext_store_pblock(&newex, newblock);
2988 newex.ee_len = cpu_to_le16(ar.len);
2989 if (flags & EXT4_GET_BLOCKS_UNINIT_EXT) /* Mark uninitialized */
2990 ext4_ext_mark_uninitialized(&newex);
2991 err = ext4_ext_insert_extent(handle, inode, path, &newex);

--- 358 unchanged lines hidden ---