Lines Matching full:path
109 static void ext4_ext_drop_refs(struct ext4_ext_path *path) in ext4_ext_drop_refs() argument
113 if (!path) in ext4_ext_drop_refs()
115 depth = path->p_depth; in ext4_ext_drop_refs()
116 for (i = 0; i <= depth; i++, path++) { in ext4_ext_drop_refs()
117 brelse(path->p_bh); in ext4_ext_drop_refs()
118 path->p_bh = NULL; in ext4_ext_drop_refs()
122 void ext4_free_ext_path(struct ext4_ext_path *path) in ext4_free_ext_path() argument
124 ext4_ext_drop_refs(path); in ext4_free_ext_path()
125 kfree(path); in ext4_free_ext_path()
156 struct ext4_ext_path *path) in ext4_ext_get_access() argument
160 if (path->p_bh) { in ext4_ext_get_access()
161 /* path points to block */ in ext4_ext_get_access()
162 BUFFER_TRACE(path->p_bh, "get_write_access"); in ext4_ext_get_access()
164 path->p_bh, EXT4_JTR_NONE); in ext4_ext_get_access()
172 clear_buffer_verified(path->p_bh); in ext4_ext_get_access()
174 /* path points to leaf/index in inode body */ in ext4_ext_get_access()
187 struct ext4_ext_path *path) in __ext4_ext_dirty() argument
192 if (path->p_bh) { in __ext4_ext_dirty()
193 ext4_extent_block_csum_set(inode, ext_block_hdr(path->p_bh)); in __ext4_ext_dirty()
194 /* path points to block */ in __ext4_ext_dirty()
196 inode, path->p_bh); in __ext4_ext_dirty()
199 set_buffer_verified(path->p_bh); in __ext4_ext_dirty()
201 /* path points to leaf/index in inode body */ in __ext4_ext_dirty()
207 #define ext4_ext_dirty(handle, inode, path) \ argument
208 __ext4_ext_dirty(__func__, __LINE__, (handle), (inode), (path))
211 struct ext4_ext_path *path, in ext4_ext_find_goal() argument
214 if (path) { in ext4_ext_find_goal()
215 int depth = path->p_depth; in ext4_ext_find_goal()
235 ex = path[depth].p_ext; in ext4_ext_find_goal()
248 if (path[depth].p_bh) in ext4_ext_find_goal()
249 return path[depth].p_bh->b_blocknr; in ext4_ext_find_goal()
261 struct ext4_ext_path *path, in ext4_ext_new_meta_block() argument
266 goal = ext4_ext_find_goal(inode, path, le32_to_cpu(ex->ee_block)); in ext4_ext_new_meta_block()
331 struct ext4_ext_path *path = *ppath; in ext4_force_split_extent_at() local
332 int unwritten = ext4_ext_is_unwritten(path[path->p_depth].p_ext); in ext4_force_split_extent_at()
603 struct ext4_ext_path *path = NULL; in ext4_ext_precache() local
619 path = kcalloc(depth + 1, sizeof(struct ext4_ext_path), in ext4_ext_precache()
621 if (path == NULL) { in ext4_ext_precache()
626 path[0].p_hdr = ext_inode_hdr(inode); in ext4_ext_precache()
627 ret = ext4_ext_check(inode, path[0].p_hdr, depth, 0); in ext4_ext_precache()
630 path[0].p_idx = EXT_FIRST_INDEX(path[0].p_hdr); in ext4_ext_precache()
637 path[i].p_idx > EXT_LAST_INDEX(path[i].p_hdr)) { in ext4_ext_precache()
638 brelse(path[i].p_bh); in ext4_ext_precache()
639 path[i].p_bh = NULL; in ext4_ext_precache()
643 bh = read_extent_tree_block(inode, path[i].p_idx++, in ext4_ext_precache()
651 path[i].p_bh = bh; in ext4_ext_precache()
652 path[i].p_hdr = ext_block_hdr(bh); in ext4_ext_precache()
653 path[i].p_idx = EXT_FIRST_INDEX(path[i].p_hdr); in ext4_ext_precache()
658 ext4_free_ext_path(path); in ext4_ext_precache()
663 static void ext4_ext_show_path(struct inode *inode, struct ext4_ext_path *path) in ext4_ext_show_path() argument
665 int k, l = path->p_depth; in ext4_ext_show_path()
667 ext_debug(inode, "path:"); in ext4_ext_show_path()
668 for (k = 0; k <= l; k++, path++) { in ext4_ext_show_path()
669 if (path->p_idx) { in ext4_ext_show_path()
671 le32_to_cpu(path->p_idx->ei_block), in ext4_ext_show_path()
672 ext4_idx_pblock(path->p_idx)); in ext4_ext_show_path()
673 } else if (path->p_ext) { in ext4_ext_show_path()
675 le32_to_cpu(path->p_ext->ee_block), in ext4_ext_show_path()
676 ext4_ext_is_unwritten(path->p_ext), in ext4_ext_show_path()
677 ext4_ext_get_actual_len(path->p_ext), in ext4_ext_show_path()
678 ext4_ext_pblock(path->p_ext)); in ext4_ext_show_path()
685 static void ext4_ext_show_leaf(struct inode *inode, struct ext4_ext_path *path) in ext4_ext_show_leaf() argument
692 if (!path) in ext4_ext_show_leaf()
695 eh = path[depth].p_hdr; in ext4_ext_show_leaf()
708 static void ext4_ext_show_move(struct inode *inode, struct ext4_ext_path *path, in ext4_ext_show_move() argument
716 idx = path[level].p_idx; in ext4_ext_show_move()
717 while (idx <= EXT_MAX_INDEX(path[level].p_hdr)) { in ext4_ext_show_move()
727 ex = path[depth].p_ext; in ext4_ext_show_move()
728 while (ex <= EXT_MAX_EXTENT(path[depth].p_hdr)) { in ext4_ext_show_move()
740 #define ext4_ext_show_path(inode, path) argument
741 #define ext4_ext_show_leaf(inode, path) argument
742 #define ext4_ext_show_move(inode, path, newblock, level) argument
752 struct ext4_ext_path *path, ext4_lblk_t block) in ext4_ext_binsearch_idx() argument
754 struct ext4_extent_header *eh = path->p_hdr; in ext4_ext_binsearch_idx()
774 path->p_idx = l - 1; in ext4_ext_binsearch_idx()
775 ext_debug(inode, " -> %u->%lld ", le32_to_cpu(path->p_idx->ei_block), in ext4_ext_binsearch_idx()
776 ext4_idx_pblock(path->p_idx)); in ext4_ext_binsearch_idx()
800 BUG_ON(chix != path->p_idx); in ext4_ext_binsearch_idx()
813 struct ext4_ext_path *path, ext4_lblk_t block) in ext4_ext_binsearch() argument
815 struct ext4_extent_header *eh = path->p_hdr; in ext4_ext_binsearch()
843 path->p_ext = l - 1; in ext4_ext_binsearch()
845 le32_to_cpu(path->p_ext->ee_block), in ext4_ext_binsearch()
846 ext4_ext_pblock(path->p_ext), in ext4_ext_binsearch()
847 ext4_ext_is_unwritten(path->p_ext), in ext4_ext_binsearch()
848 ext4_ext_get_actual_len(path->p_ext)); in ext4_ext_binsearch()
863 BUG_ON(chex != path->p_ext); in ext4_ext_binsearch()
888 struct ext4_ext_path *path = orig_path ? *orig_path : NULL; in ext4_find_extent() local
905 if (path) { in ext4_find_extent()
906 ext4_ext_drop_refs(path); in ext4_find_extent()
907 if (depth > path[0].p_maxdepth) { in ext4_find_extent()
908 kfree(path); in ext4_find_extent()
909 *orig_path = path = NULL; in ext4_find_extent()
912 if (!path) { in ext4_find_extent()
914 path = kcalloc(depth + 2, sizeof(struct ext4_ext_path), in ext4_find_extent()
916 if (unlikely(!path)) in ext4_find_extent()
918 path[0].p_maxdepth = depth + 1; in ext4_find_extent()
920 path[0].p_hdr = eh; in ext4_find_extent()
921 path[0].p_bh = NULL; in ext4_find_extent()
931 ext4_ext_binsearch_idx(inode, path + ppos, block); in ext4_find_extent()
932 path[ppos].p_block = ext4_idx_pblock(path[ppos].p_idx); in ext4_find_extent()
933 path[ppos].p_depth = i; in ext4_find_extent()
934 path[ppos].p_ext = NULL; in ext4_find_extent()
936 bh = read_extent_tree_block(inode, path[ppos].p_idx, --i, flags); in ext4_find_extent()
944 path[ppos].p_bh = bh; in ext4_find_extent()
945 path[ppos].p_hdr = eh; in ext4_find_extent()
948 path[ppos].p_depth = i; in ext4_find_extent()
949 path[ppos].p_ext = NULL; in ext4_find_extent()
950 path[ppos].p_idx = NULL; in ext4_find_extent()
953 ext4_ext_binsearch(inode, path + ppos, block); in ext4_find_extent()
955 if (path[ppos].p_ext) in ext4_find_extent()
956 path[ppos].p_block = ext4_ext_pblock(path[ppos].p_ext); in ext4_find_extent()
958 ext4_ext_show_path(inode, path); in ext4_find_extent()
960 return path; in ext4_find_extent()
963 ext4_free_ext_path(path); in ext4_find_extent()
1044 * inserts new subtree into the path, using free index entry
1054 struct ext4_ext_path *path, in ext4_ext_split() argument
1077 if (unlikely(path[depth].p_ext > EXT_MAX_EXTENT(path[depth].p_hdr))) { in ext4_ext_split()
1081 if (path[depth].p_ext != EXT_MAX_EXTENT(path[depth].p_hdr)) { in ext4_ext_split()
1082 border = path[depth].p_ext[1].ee_block; in ext4_ext_split()
1112 newblock = ext4_ext_new_meta_block(handle, inode, path, in ext4_ext_split()
1145 /* move remainder of path[depth] to the new leaf */ in ext4_ext_split()
1146 if (unlikely(path[depth].p_hdr->eh_entries != in ext4_ext_split()
1147 path[depth].p_hdr->eh_max)) { in ext4_ext_split()
1149 path[depth].p_hdr->eh_entries, in ext4_ext_split()
1150 path[depth].p_hdr->eh_max); in ext4_ext_split()
1155 m = EXT_MAX_EXTENT(path[depth].p_hdr) - path[depth].p_ext++; in ext4_ext_split()
1156 ext4_ext_show_move(inode, path, newblock, depth); in ext4_ext_split()
1160 memmove(ex, path[depth].p_ext, sizeof(struct ext4_extent) * m); in ext4_ext_split()
1180 err = ext4_ext_get_access(handle, inode, path + depth); in ext4_ext_split()
1183 le16_add_cpu(&path[depth].p_hdr->eh_entries, -m); in ext4_ext_split()
1184 err = ext4_ext_dirty(handle, inode, path + depth); in ext4_ext_split()
1230 /* move remainder of path[i] to the new index block */ in ext4_ext_split()
1231 if (unlikely(EXT_MAX_INDEX(path[i].p_hdr) != in ext4_ext_split()
1232 EXT_LAST_INDEX(path[i].p_hdr))) { in ext4_ext_split()
1235 le32_to_cpu(path[i].p_ext->ee_block)); in ext4_ext_split()
1240 m = EXT_MAX_INDEX(path[i].p_hdr) - path[i].p_idx++; in ext4_ext_split()
1241 ext_debug(inode, "cur 0x%p, last 0x%p\n", path[i].p_idx, in ext4_ext_split()
1242 EXT_MAX_INDEX(path[i].p_hdr)); in ext4_ext_split()
1243 ext4_ext_show_move(inode, path, newblock, i); in ext4_ext_split()
1245 memmove(++fidx, path[i].p_idx, in ext4_ext_split()
1266 err = ext4_ext_get_access(handle, inode, path + i); in ext4_ext_split()
1269 le16_add_cpu(&path[i].p_hdr->eh_entries, -m); in ext4_ext_split()
1270 err = ext4_ext_dirty(handle, inode, path + i); in ext4_ext_split()
1279 err = ext4_ext_insert_index(handle, inode, path + at, in ext4_ext_split()
1404 struct ext4_ext_path *path = *ppath; in ext4_ext_create_new_leaf() local
1412 curp = path + depth; in ext4_ext_create_new_leaf()
1423 err = ext4_ext_split(handle, inode, mb_flags, path, newext, i); in ext4_ext_create_new_leaf()
1427 /* refill path */ in ext4_ext_create_new_leaf()
1428 path = ext4_find_extent(inode, in ext4_ext_create_new_leaf()
1431 if (IS_ERR(path)) in ext4_ext_create_new_leaf()
1432 err = PTR_ERR(path); in ext4_ext_create_new_leaf()
1439 /* refill path */ in ext4_ext_create_new_leaf()
1440 path = ext4_find_extent(inode, in ext4_ext_create_new_leaf()
1443 if (IS_ERR(path)) { in ext4_ext_create_new_leaf()
1444 err = PTR_ERR(path); in ext4_ext_create_new_leaf()
1453 if (path[depth].p_hdr->eh_entries == path[depth].p_hdr->eh_max) { in ext4_ext_create_new_leaf()
1471 struct ext4_ext_path *path, in ext4_ext_search_left() argument
1478 if (unlikely(path == NULL)) { in ext4_ext_search_left()
1479 EXT4_ERROR_INODE(inode, "path == NULL *logical %d!", *logical); in ext4_ext_search_left()
1482 depth = path->p_depth; in ext4_ext_search_left()
1485 if (depth == 0 && path->p_ext == NULL) in ext4_ext_search_left()
1488 /* usually extent in the path covers blocks smaller in ext4_ext_search_left()
1492 ex = path[depth].p_ext; in ext4_ext_search_left()
1495 if (unlikely(EXT_FIRST_EXTENT(path[depth].p_hdr) != ex)) { in ext4_ext_search_left()
1502 ix = path[depth].p_idx; in ext4_ext_search_left()
1503 if (unlikely(ix != EXT_FIRST_INDEX(path[depth].p_hdr))) { in ext4_ext_search_left()
1507 le32_to_cpu(EXT_FIRST_INDEX(path[depth].p_hdr)->ei_block), in ext4_ext_search_left()
1535 struct ext4_ext_path *path, in ext4_ext_search_right() argument
1546 if (unlikely(path == NULL)) { in ext4_ext_search_right()
1547 EXT4_ERROR_INODE(inode, "path == NULL *logical %d!", *logical); in ext4_ext_search_right()
1550 depth = path->p_depth; in ext4_ext_search_right()
1553 if (depth == 0 && path->p_ext == NULL) in ext4_ext_search_right()
1556 /* usually extent in the path covers blocks smaller in ext4_ext_search_right()
1560 ex = path[depth].p_ext; in ext4_ext_search_right()
1563 if (unlikely(EXT_FIRST_EXTENT(path[depth].p_hdr) != ex)) { in ext4_ext_search_right()
1565 "first_extent(path[%d].p_hdr) != ex", in ext4_ext_search_right()
1570 ix = path[depth].p_idx; in ext4_ext_search_right()
1571 if (unlikely(ix != EXT_FIRST_INDEX(path[depth].p_hdr))) { in ext4_ext_search_right()
1588 if (ex != EXT_LAST_EXTENT(path[depth].p_hdr)) { in ext4_ext_search_right()
1596 ix = path[depth].p_idx; in ext4_ext_search_right()
1597 if (ix != EXT_LAST_INDEX(path[depth].p_hdr)) in ext4_ext_search_right()
1609 while (++depth < path->p_depth) { in ext4_ext_search_right()
1611 bh = read_extent_tree_block(inode, ix, path->p_depth - depth, 0); in ext4_ext_search_right()
1619 bh = read_extent_tree_block(inode, ix, path->p_depth - depth, 0); in ext4_ext_search_right()
1642 ext4_ext_next_allocated_block(struct ext4_ext_path *path) in ext4_ext_next_allocated_block() argument
1646 BUG_ON(path == NULL); in ext4_ext_next_allocated_block()
1647 depth = path->p_depth; in ext4_ext_next_allocated_block()
1649 if (depth == 0 && path->p_ext == NULL) in ext4_ext_next_allocated_block()
1653 struct ext4_ext_path *p = &path[depth]; in ext4_ext_next_allocated_block()
1655 if (depth == path->p_depth) { in ext4_ext_next_allocated_block()
1674 static ext4_lblk_t ext4_ext_next_leaf_block(struct ext4_ext_path *path) in ext4_ext_next_leaf_block() argument
1678 BUG_ON(path == NULL); in ext4_ext_next_leaf_block()
1679 depth = path->p_depth; in ext4_ext_next_leaf_block()
1689 if (path[depth].p_idx != in ext4_ext_next_leaf_block()
1690 EXT_LAST_INDEX(path[depth].p_hdr)) in ext4_ext_next_leaf_block()
1692 le32_to_cpu(path[depth].p_idx[1].ei_block); in ext4_ext_next_leaf_block()
1706 struct ext4_ext_path *path) in ext4_ext_correct_indexes() argument
1714 eh = path[depth].p_hdr; in ext4_ext_correct_indexes()
1715 ex = path[depth].p_ext; in ext4_ext_correct_indexes()
1737 border = path[depth].p_ext->ee_block; in ext4_ext_correct_indexes()
1738 err = ext4_ext_get_access(handle, inode, path + k); in ext4_ext_correct_indexes()
1741 path[k].p_idx->ei_block = border; in ext4_ext_correct_indexes()
1742 err = ext4_ext_dirty(handle, inode, path + k); in ext4_ext_correct_indexes()
1748 if (path[k+1].p_idx != EXT_FIRST_INDEX(path[k+1].p_hdr)) in ext4_ext_correct_indexes()
1750 err = ext4_ext_get_access(handle, inode, path + k); in ext4_ext_correct_indexes()
1753 path[k].p_idx->ei_block = border; in ext4_ext_correct_indexes()
1754 err = ext4_ext_dirty(handle, inode, path + k); in ext4_ext_correct_indexes()
1802 struct ext4_ext_path *path, in ext4_ext_try_to_merge_right() argument
1810 BUG_ON(path[depth].p_hdr == NULL); in ext4_ext_try_to_merge_right()
1811 eh = path[depth].p_hdr; in ext4_ext_try_to_merge_right()
1844 struct ext4_ext_path *path) in ext4_ext_try_to_merge_up() argument
1850 if ((path[0].p_depth != 1) || in ext4_ext_try_to_merge_up()
1851 (le16_to_cpu(path[0].p_hdr->eh_entries) != 1) || in ext4_ext_try_to_merge_up()
1852 (le16_to_cpu(path[1].p_hdr->eh_entries) > max_root)) in ext4_ext_try_to_merge_up()
1867 blk = ext4_idx_pblock(path[0].p_idx); in ext4_ext_try_to_merge_up()
1868 s = le16_to_cpu(path[1].p_hdr->eh_entries) * in ext4_ext_try_to_merge_up()
1872 path[1].p_maxdepth = path[0].p_maxdepth; in ext4_ext_try_to_merge_up()
1873 memcpy(path[0].p_hdr, path[1].p_hdr, s); in ext4_ext_try_to_merge_up()
1874 path[0].p_depth = 0; in ext4_ext_try_to_merge_up()
1875 path[0].p_ext = EXT_FIRST_EXTENT(path[0].p_hdr) + in ext4_ext_try_to_merge_up()
1876 (path[1].p_ext - EXT_FIRST_EXTENT(path[1].p_hdr)); in ext4_ext_try_to_merge_up()
1877 path[0].p_hdr->eh_max = cpu_to_le16(max_root); in ext4_ext_try_to_merge_up()
1879 brelse(path[1].p_bh); in ext4_ext_try_to_merge_up()
1890 struct ext4_ext_path *path, in ext4_ext_try_to_merge() argument
1898 BUG_ON(path[depth].p_hdr == NULL); in ext4_ext_try_to_merge()
1899 eh = path[depth].p_hdr; in ext4_ext_try_to_merge()
1902 merge_done = ext4_ext_try_to_merge_right(inode, path, ex - 1); in ext4_ext_try_to_merge()
1905 (void) ext4_ext_try_to_merge_right(inode, path, ex); in ext4_ext_try_to_merge()
1907 ext4_ext_try_to_merge_up(handle, inode, path); in ext4_ext_try_to_merge()
1921 struct ext4_ext_path *path) in ext4_ext_check_overlap() argument
1930 if (!path[depth].p_ext) in ext4_ext_check_overlap()
1932 b2 = EXT4_LBLK_CMASK(sbi, le32_to_cpu(path[depth].p_ext->ee_block)); in ext4_ext_check_overlap()
1935 * get the next allocated block if the extent in the path in ext4_ext_check_overlap()
1939 b2 = ext4_ext_next_allocated_block(path); in ext4_ext_check_overlap()
1971 struct ext4_ext_path *path = *ppath; in ext4_ext_insert_extent() local
1987 ex = path[depth].p_ext; in ext4_ext_insert_extent()
1988 eh = path[depth].p_hdr; in ext4_ext_insert_extent()
1989 if (unlikely(path[depth].p_hdr == NULL)) { in ext4_ext_insert_extent()
1990 EXT4_ERROR_INODE(inode, "path[%d].p_hdr == NULL", depth); in ext4_ext_insert_extent()
2027 path + depth); in ext4_ext_insert_extent()
2052 path + depth); in ext4_ext_insert_extent()
2069 eh = path[depth].p_hdr; in ext4_ext_insert_extent()
2077 next = ext4_ext_next_leaf_block(path); in ext4_ext_insert_extent()
2084 BUG_ON(npath->p_depth != path->p_depth); in ext4_ext_insert_extent()
2089 path = npath; in ext4_ext_insert_extent()
2107 eh = path[depth].p_hdr; in ext4_ext_insert_extent()
2110 nearex = path[depth].p_ext; in ext4_ext_insert_extent()
2112 err = ext4_ext_get_access(handle, inode, path + depth); in ext4_ext_insert_extent()
2162 path[depth].p_ext = nearex; in ext4_ext_insert_extent()
2170 ext4_ext_try_to_merge(handle, inode, path, nearex); in ext4_ext_insert_extent()
2174 err = ext4_ext_correct_indexes(handle, inode, path); in ext4_ext_insert_extent()
2178 err = ext4_ext_dirty(handle, inode, path + path->p_depth); in ext4_ext_insert_extent()
2232 * ext4_ext_find_hole - find hole around given block according to the given path
2234 * @path: path in extent tree to @lblk
2238 * block. We don't try too hard to find the beginning of the hole but @path
2245 struct ext4_ext_path *path, in ext4_ext_find_hole() argument
2252 ex = path[depth].p_ext; in ext4_ext_find_hole()
2264 next = ext4_ext_next_allocated_block(path); in ext4_ext_find_hole()
2278 struct ext4_ext_path *path, int depth) in ext4_ext_rm_idx() argument
2285 path = path + depth; in ext4_ext_rm_idx()
2286 leaf = ext4_idx_pblock(path->p_idx); in ext4_ext_rm_idx()
2287 if (unlikely(path->p_hdr->eh_entries == 0)) { in ext4_ext_rm_idx()
2288 EXT4_ERROR_INODE(inode, "path->p_hdr->eh_entries == 0"); in ext4_ext_rm_idx()
2291 err = ext4_ext_get_access(handle, inode, path); in ext4_ext_rm_idx()
2295 if (path->p_idx != EXT_LAST_INDEX(path->p_hdr)) { in ext4_ext_rm_idx()
2296 int len = EXT_LAST_INDEX(path->p_hdr) - path->p_idx; in ext4_ext_rm_idx()
2298 memmove(path->p_idx, path->p_idx + 1, len); in ext4_ext_rm_idx()
2301 le16_add_cpu(&path->p_hdr->eh_entries, -1); in ext4_ext_rm_idx()
2302 err = ext4_ext_dirty(handle, inode, path); in ext4_ext_rm_idx()
2312 if (path->p_idx != EXT_FIRST_INDEX(path->p_hdr)) in ext4_ext_rm_idx()
2314 path--; in ext4_ext_rm_idx()
2315 err = ext4_ext_get_access(handle, inode, path); in ext4_ext_rm_idx()
2318 path->p_idx->ei_block = (path+1)->p_idx->ei_block; in ext4_ext_rm_idx()
2319 err = ext4_ext_dirty(handle, inode, path); in ext4_ext_rm_idx()
2330 * When pass the actual path, the caller should calculate credits
2334 struct ext4_ext_path *path) in ext4_ext_calc_credits_for_single_extent() argument
2336 if (path) { in ext4_ext_calc_credits_for_single_extent()
2341 if (le16_to_cpu(path[depth].p_hdr->eh_entries) in ext4_ext_calc_credits_for_single_extent()
2342 < le16_to_cpu(path[depth].p_hdr->eh_max)) { in ext4_ext_calc_credits_for_single_extent()
2557 * @path: The path to the leaf
2567 struct ext4_ext_path *path, in ext4_ext_rm_leaf() argument
2585 if (!path[depth].p_hdr) in ext4_ext_rm_leaf()
2586 path[depth].p_hdr = ext_block_hdr(path[depth].p_bh); in ext4_ext_rm_leaf()
2587 eh = path[depth].p_hdr; in ext4_ext_rm_leaf()
2588 if (unlikely(path[depth].p_hdr == NULL)) { in ext4_ext_rm_leaf()
2589 EXT4_ERROR_INODE(inode, "path[%d].p_hdr == NULL", depth); in ext4_ext_rm_leaf()
2593 ex = path[depth].p_ext; in ext4_ext_rm_leaf()
2612 path[depth].p_ext = ex; in ext4_ext_rm_leaf()
2682 err = ext4_ext_get_access(handle, inode, path + depth); in ext4_ext_rm_leaf()
2722 err = ext4_ext_dirty(handle, inode, path + depth); in ext4_ext_rm_leaf()
2734 err = ext4_ext_correct_indexes(handle, inode, path); in ext4_ext_rm_leaf()
2761 if (err == 0 && eh->eh_entries == 0 && path[depth].p_bh != NULL) in ext4_ext_rm_leaf()
2762 err = ext4_ext_rm_idx(handle, inode, path, depth); in ext4_ext_rm_leaf()
2773 ext4_ext_more_to_rm(struct ext4_ext_path *path) in ext4_ext_more_to_rm() argument
2775 BUG_ON(path->p_idx == NULL); in ext4_ext_more_to_rm()
2777 if (path->p_idx < EXT_FIRST_INDEX(path->p_hdr)) in ext4_ext_more_to_rm()
2784 if (le16_to_cpu(path->p_hdr->eh_entries) == path->p_block) in ext4_ext_more_to_rm()
2794 struct ext4_ext_path *path = NULL; in ext4_ext_remove_space() local
2828 path = ext4_find_extent(inode, end, NULL, in ext4_ext_remove_space()
2830 if (IS_ERR(path)) { in ext4_ext_remove_space()
2832 return PTR_ERR(path); in ext4_ext_remove_space()
2836 ex = path[depth].p_ext; in ext4_ext_remove_space()
2840 "path[%d].p_hdr == NULL", in ext4_ext_remove_space()
2875 err = ext4_force_split_extent_at(handle, inode, &path, in ext4_ext_remove_space()
2893 err = ext4_ext_search_right(inode, path, &lblk, &pblk, in ext4_ext_remove_space()
2908 if (path) { in ext4_ext_remove_space()
2911 path[k].p_block = in ext4_ext_remove_space()
2912 le16_to_cpu(path[k].p_hdr->eh_entries)+1; in ext4_ext_remove_space()
2914 path = kcalloc(depth + 1, sizeof(struct ext4_ext_path), in ext4_ext_remove_space()
2916 if (path == NULL) { in ext4_ext_remove_space()
2920 path[0].p_maxdepth = path[0].p_depth = depth; in ext4_ext_remove_space()
2921 path[0].p_hdr = ext_inode_hdr(inode); in ext4_ext_remove_space()
2924 if (ext4_ext_check(inode, path[0].p_hdr, depth, 0)) { in ext4_ext_remove_space()
2934 err = ext4_ext_rm_leaf(handle, inode, path, in ext4_ext_remove_space()
2937 brelse(path[i].p_bh); in ext4_ext_remove_space()
2938 path[i].p_bh = NULL; in ext4_ext_remove_space()
2944 if (!path[i].p_hdr) { in ext4_ext_remove_space()
2946 path[i].p_hdr = ext_block_hdr(path[i].p_bh); in ext4_ext_remove_space()
2949 if (!path[i].p_idx) { in ext4_ext_remove_space()
2951 path[i].p_idx = EXT_LAST_INDEX(path[i].p_hdr); in ext4_ext_remove_space()
2952 path[i].p_block = le16_to_cpu(path[i].p_hdr->eh_entries)+1; in ext4_ext_remove_space()
2954 path[i].p_hdr, in ext4_ext_remove_space()
2955 le16_to_cpu(path[i].p_hdr->eh_entries)); in ext4_ext_remove_space()
2958 path[i].p_idx--; in ext4_ext_remove_space()
2962 i, EXT_FIRST_INDEX(path[i].p_hdr), in ext4_ext_remove_space()
2963 path[i].p_idx); in ext4_ext_remove_space()
2964 if (ext4_ext_more_to_rm(path + i)) { in ext4_ext_remove_space()
2968 i + 1, ext4_idx_pblock(path[i].p_idx)); in ext4_ext_remove_space()
2969 memset(path + i + 1, 0, sizeof(*path)); in ext4_ext_remove_space()
2970 bh = read_extent_tree_block(inode, path[i].p_idx, in ext4_ext_remove_space()
2985 path[i + 1].p_bh = bh; in ext4_ext_remove_space()
2989 path[i].p_block = le16_to_cpu(path[i].p_hdr->eh_entries); in ext4_ext_remove_space()
2993 if (path[i].p_hdr->eh_entries == 0 && i > 0) { in ext4_ext_remove_space()
2997 err = ext4_ext_rm_idx(handle, inode, path, i); in ext4_ext_remove_space()
3000 brelse(path[i].p_bh); in ext4_ext_remove_space()
3001 path[i].p_bh = NULL; in ext4_ext_remove_space()
3008 path->p_hdr->eh_entries); in ext4_ext_remove_space()
3028 if (path->p_hdr->eh_entries == 0) { in ext4_ext_remove_space()
3033 err = ext4_ext_get_access(handle, inode, path); in ext4_ext_remove_space()
3038 err = ext4_ext_dirty(handle, inode, path); in ext4_ext_remove_space()
3042 ext4_free_ext_path(path); in ext4_ext_remove_space()
3043 path = NULL; in ext4_ext_remove_space()
3136 * @path: the path to the extent
3159 struct ext4_ext_path *path = *ppath; in ext4_split_extent_at() local
3172 ext4_ext_show_leaf(inode, path); in ext4_split_extent_at()
3175 ex = path[depth].p_ext; in ext4_split_extent_at()
3186 err = ext4_ext_get_access(handle, inode, path + depth); in ext4_split_extent_at()
3202 ext4_ext_try_to_merge(handle, inode, path, ex); in ext4_split_extent_at()
3204 err = ext4_ext_dirty(handle, inode, path + path->p_depth); in ext4_split_extent_at()
3215 * path may lead to new leaf, not to original leaf any more in ext4_split_extent_at()
3218 err = ext4_ext_dirty(handle, inode, path + depth); in ext4_split_extent_at()
3262 ext4_ext_try_to_merge(handle, inode, path, ex); in ext4_split_extent_at()
3263 err = ext4_ext_dirty(handle, inode, path + path->p_depth); in ext4_split_extent_at()
3279 * Ignore ext4_ext_dirty return value since we are already in error path in ext4_split_extent_at()
3282 ext4_ext_dirty(handle, inode, path + path->p_depth); in ext4_split_extent_at()
3285 ext4_ext_show_leaf(inode, path); in ext4_split_extent_at()
3307 struct ext4_ext_path *path = *ppath; in ext4_split_extent() local
3317 ex = path[depth].p_ext; in ext4_split_extent()
3338 * Update path is required because previous ext4_split_extent_at() may in ext4_split_extent()
3341 path = ext4_find_extent(inode, map->m_lblk, ppath, flags); in ext4_split_extent()
3342 if (IS_ERR(path)) in ext4_split_extent()
3343 return PTR_ERR(path); in ext4_split_extent()
3345 ex = path[depth].p_ext; in ext4_split_extent()
3366 ext4_ext_show_leaf(inode, path); in ext4_split_extent()
3382 * - The extent pointed to by 'path' is unwritten.
3383 * - The extent pointed to by 'path' contains a superset
3397 struct ext4_ext_path *path = *ppath; in ext4_ext_convert_to_initialized() local
3419 eh = path[depth].p_hdr; in ext4_ext_convert_to_initialized()
3420 ex = path[depth].p_ext; in ext4_ext_convert_to_initialized()
3474 err = ext4_ext_get_access(handle, inode, path + depth); in ext4_ext_convert_to_initialized()
3520 err = ext4_ext_get_access(handle, inode, path + depth); in ext4_ext_convert_to_initialized()
3542 err = ext4_ext_dirty(handle, inode, path + depth); in ext4_ext_convert_to_initialized()
3544 /* Update path to point to the right extent */ in ext4_ext_convert_to_initialized()
3545 path[depth].p_ext = abut_ex; in ext4_ext_convert_to_initialized()
3655 struct ext4_ext_path *path = *ppath; in ext4_split_convert_extents() local
3674 ex = path[depth].p_ext; in ext4_split_convert_extents()
3696 struct ext4_ext_path *path = *ppath; in ext4_convert_unwritten_extents_endio() local
3704 ex = path[depth].p_ext; in ext4_convert_unwritten_extents_endio()
3728 path = ext4_find_extent(inode, map->m_lblk, ppath, 0); in ext4_convert_unwritten_extents_endio()
3729 if (IS_ERR(path)) in ext4_convert_unwritten_extents_endio()
3730 return PTR_ERR(path); in ext4_convert_unwritten_extents_endio()
3732 ex = path[depth].p_ext; in ext4_convert_unwritten_extents_endio()
3735 err = ext4_ext_get_access(handle, inode, path + depth); in ext4_convert_unwritten_extents_endio()
3744 ext4_ext_try_to_merge(handle, inode, path, ex); in ext4_convert_unwritten_extents_endio()
3747 err = ext4_ext_dirty(handle, inode, path + path->p_depth); in ext4_convert_unwritten_extents_endio()
3749 ext4_ext_show_leaf(inode, path); in ext4_convert_unwritten_extents_endio()
3759 struct ext4_ext_path *path = *ppath; in convert_initialized_extent() local
3774 ex = path[depth].p_ext; in convert_initialized_extent()
3786 path = ext4_find_extent(inode, map->m_lblk, ppath, 0); in convert_initialized_extent()
3787 if (IS_ERR(path)) in convert_initialized_extent()
3788 return PTR_ERR(path); in convert_initialized_extent()
3790 ex = path[depth].p_ext; in convert_initialized_extent()
3798 err = ext4_ext_get_access(handle, inode, path + depth); in convert_initialized_extent()
3807 ext4_ext_try_to_merge(handle, inode, path, ex); in convert_initialized_extent()
3810 err = ext4_ext_dirty(handle, inode, path + path->p_depth); in convert_initialized_extent()
3813 ext4_ext_show_leaf(inode, path); in convert_initialized_extent()
3830 struct ext4_ext_path __maybe_unused *path = *ppath; in ext4_ext_handle_unwritten_extents() local
3837 ext4_ext_show_leaf(inode, path); in ext4_ext_handle_unwritten_extents()
3934 ext4_ext_show_leaf(inode, path); in ext4_ext_handle_unwritten_extents()
3983 struct ext4_ext_path *path) in get_implied_cluster_alloc() argument
4029 ext4_lblk_t next = ext4_ext_next_allocated_block(path); in get_implied_cluster_alloc()
4043 * locate and expand the hole from the given @path, and then adjust it
4049 struct ext4_ext_path *path, in ext4_ext_determine_insert_hole() argument
4056 len = ext4_ext_find_hole(inode, path, &hole_start); in ext4_ext_determine_insert_hole()
4129 struct ext4_ext_path *path = NULL; in ext4_ext_map_blocks() local
4143 path = ext4_find_extent(inode, map->m_lblk, NULL, 0); in ext4_ext_map_blocks()
4144 if (IS_ERR(path)) { in ext4_ext_map_blocks()
4145 err = PTR_ERR(path); in ext4_ext_map_blocks()
4146 path = NULL; in ext4_ext_map_blocks()
4157 if (unlikely(path[depth].p_ext == NULL && depth != 0)) { in ext4_ext_map_blocks()
4161 path[depth].p_block); in ext4_ext_map_blocks()
4166 ex = path[depth].p_ext; in ext4_ext_map_blocks()
4196 inode, map, &path, &allocated); in ext4_ext_map_blocks()
4204 ext4_ext_show_leaf(inode, path); in ext4_ext_map_blocks()
4209 handle, inode, map, &path, flags, in ext4_ext_map_blocks()
4226 len = ext4_ext_determine_insert_hole(inode, path, map->m_lblk); in ext4_ext_map_blocks()
4244 get_implied_cluster_alloc(inode->i_sb, map, ex, path)) { in ext4_ext_map_blocks()
4252 err = ext4_ext_search_left(inode, path, &ar.lleft, &ar.pleft); in ext4_ext_map_blocks()
4256 err = ext4_ext_search_right(inode, path, &ar.lright, &ar.pright, &ex2); in ext4_ext_map_blocks()
4263 get_implied_cluster_alloc(inode->i_sb, map, &ex2, path)) { in ext4_ext_map_blocks()
4284 err = ext4_ext_check_overlap(sbi, inode, &newex, path); in ext4_ext_map_blocks()
4292 ar.goal = ext4_ext_find_goal(inode, path, map->m_lblk); in ext4_ext_map_blocks()
4338 err = ext4_ext_insert_extent(handle, inode, &path, &newex, flags); in ext4_ext_map_blocks()
4408 ext4_ext_show_leaf(inode, path); in ext4_ext_map_blocks()
4410 ext4_free_ext_path(path); in ext4_ext_map_blocks()
5054 * Shift the extents of a path structure lying between path[depth].p_ext
5055 * and EXT_LAST_EXTENT(path[depth].p_hdr), by @shift blocks. @SHIFT tells
5059 ext4_ext_shift_path_extents(struct ext4_ext_path *path, ext4_lblk_t shift, in ext4_ext_shift_path_extents() argument
5067 depth = path->p_depth; in ext4_ext_shift_path_extents()
5070 if (depth == path->p_depth) { in ext4_ext_shift_path_extents()
5071 ex_start = path[depth].p_ext; in ext4_ext_shift_path_extents()
5075 ex_last = EXT_LAST_EXTENT(path[depth].p_hdr); in ext4_ext_shift_path_extents()
5078 if (ex_start == EXT_FIRST_EXTENT(path[depth].p_hdr)) { in ext4_ext_shift_path_extents()
5093 err = ext4_ext_get_access(handle, inode, path + depth); in ext4_ext_shift_path_extents()
5103 EXT_FIRST_EXTENT(path[depth].p_hdr)) in ext4_ext_shift_path_extents()
5106 path, ex_start - 1)) in ext4_ext_shift_path_extents()
5112 ext4_ext_try_to_merge_right(inode, path, in ext4_ext_shift_path_extents()
5117 err = ext4_ext_dirty(handle, inode, path + depth); in ext4_ext_shift_path_extents()
5126 err = ext4_ext_get_access(handle, inode, path + depth); in ext4_ext_shift_path_extents()
5131 le32_add_cpu(&path[depth].p_idx->ei_block, -shift); in ext4_ext_shift_path_extents()
5133 le32_add_cpu(&path[depth].p_idx->ei_block, shift); in ext4_ext_shift_path_extents()
5134 err = ext4_ext_dirty(handle, inode, path + depth); in ext4_ext_shift_path_extents()
5139 if (path[depth].p_idx != EXT_FIRST_INDEX(path[depth].p_hdr)) in ext4_ext_shift_path_extents()
5161 struct ext4_ext_path *path; in ext4_ext_shift_extents() local
5167 /* Let path point to the last extent */ in ext4_ext_shift_extents()
5168 path = ext4_find_extent(inode, EXT_MAX_BLOCKS - 1, NULL, in ext4_ext_shift_extents()
5170 if (IS_ERR(path)) in ext4_ext_shift_extents()
5171 return PTR_ERR(path); in ext4_ext_shift_extents()
5173 depth = path->p_depth; in ext4_ext_shift_extents()
5174 extent = path[depth].p_ext; in ext4_ext_shift_extents()
5186 path = ext4_find_extent(inode, start - 1, &path, in ext4_ext_shift_extents()
5188 if (IS_ERR(path)) in ext4_ext_shift_extents()
5189 return PTR_ERR(path); in ext4_ext_shift_extents()
5190 depth = path->p_depth; in ext4_ext_shift_extents()
5191 extent = path[depth].p_ext; in ext4_ext_shift_extents()
5235 path = ext4_find_extent(inode, *iterator, &path, in ext4_ext_shift_extents()
5237 if (IS_ERR(path)) in ext4_ext_shift_extents()
5238 return PTR_ERR(path); in ext4_ext_shift_extents()
5239 depth = path->p_depth; in ext4_ext_shift_extents()
5240 extent = path[depth].p_ext; in ext4_ext_shift_extents()
5249 if (extent < EXT_LAST_EXTENT(path[depth].p_hdr)) { in ext4_ext_shift_extents()
5250 path[depth].p_ext++; in ext4_ext_shift_extents()
5252 *iterator = ext4_ext_next_allocated_block(path); in ext4_ext_shift_extents()
5259 extent = EXT_LAST_EXTENT(path[depth].p_hdr); in ext4_ext_shift_extents()
5263 extent = EXT_FIRST_EXTENT(path[depth].p_hdr); in ext4_ext_shift_extents()
5269 extent = EXT_LAST_EXTENT(path[depth].p_hdr); in ext4_ext_shift_extents()
5273 if (extent == EXT_LAST_EXTENT(path[depth].p_hdr)) in ext4_ext_shift_extents()
5279 path[depth].p_ext = extent; in ext4_ext_shift_extents()
5281 ret = ext4_ext_shift_path_extents(path, shift, inode, in ext4_ext_shift_extents()
5290 ext4_free_ext_path(path); in ext4_ext_shift_extents()
5443 struct ext4_ext_path *path; in ext4_insert_range() local
5534 path = ext4_find_extent(inode, offset_lblk, NULL, 0); in ext4_insert_range()
5535 if (IS_ERR(path)) { in ext4_insert_range()
5541 extent = path[depth].p_ext; in ext4_insert_range()
5555 ret = ext4_split_extent_at(handle, inode, &path, in ext4_insert_range()
5562 ext4_free_ext_path(path); in ext4_insert_range()
5568 ext4_free_ext_path(path); in ext4_insert_range()
5707 * path must to be revalidated. */ in ext4_swap_extents()
5733 * path must to be revalidated. */ in ext4_swap_extents()
5800 struct ext4_ext_path *path; in ext4_clu_mapped() local
5815 path = ext4_find_extent(inode, EXT4_C2B(sbi, lclu), NULL, 0); in ext4_clu_mapped()
5816 if (IS_ERR(path)) { in ext4_clu_mapped()
5817 err = PTR_ERR(path); in ext4_clu_mapped()
5818 path = NULL; in ext4_clu_mapped()
5829 if (unlikely(path[depth].p_ext == NULL && depth != 0)) { in ext4_clu_mapped()
5833 depth, path[depth].p_block); in ext4_clu_mapped()
5838 extent = path[depth].p_ext; in ext4_clu_mapped()
5859 first_lblk = ext4_ext_next_allocated_block(path); in ext4_clu_mapped()
5867 ext4_free_ext_path(path); in ext4_clu_mapped()
5877 * replay path. Returns 0 on success and error on failure.
5882 struct ext4_ext_path *path = NULL, *ppath; in ext4_ext_replay_update_ex() local
5886 path = ext4_find_extent(inode, start, NULL, 0); in ext4_ext_replay_update_ex()
5887 if (IS_ERR(path)) in ext4_ext_replay_update_ex()
5888 return PTR_ERR(path); in ext4_ext_replay_update_ex()
5889 ex = path[path->p_depth].p_ext; in ext4_ext_replay_update_ex()
5898 ppath = path; in ext4_ext_replay_update_ex()
5904 kfree(path); in ext4_ext_replay_update_ex()
5905 path = ext4_find_extent(inode, start, NULL, 0); in ext4_ext_replay_update_ex()
5906 if (IS_ERR(path)) in ext4_ext_replay_update_ex()
5908 ppath = path; in ext4_ext_replay_update_ex()
5909 ex = path[path->p_depth].p_ext; in ext4_ext_replay_update_ex()
5918 kfree(path); in ext4_ext_replay_update_ex()
5919 path = ext4_find_extent(inode, start, NULL, 0); in ext4_ext_replay_update_ex()
5920 if (IS_ERR(path)) in ext4_ext_replay_update_ex()
5922 ex = path[path->p_depth].p_ext; in ext4_ext_replay_update_ex()
5931 ret = ext4_ext_dirty(NULL, inode, &path[path->p_depth]); in ext4_ext_replay_update_ex()
5934 ext4_free_ext_path(path); in ext4_ext_replay_update_ex()
5942 struct ext4_ext_path *path = NULL; in ext4_ext_replay_shrink_inode() local
5947 path = ext4_find_extent(inode, cur, NULL, 0); in ext4_ext_replay_shrink_inode()
5948 if (IS_ERR(path)) in ext4_ext_replay_shrink_inode()
5950 ex = path[path->p_depth].p_ext; in ext4_ext_replay_shrink_inode()
5952 ext4_free_ext_path(path); in ext4_ext_replay_shrink_inode()
5960 ext4_ext_try_to_merge(NULL, inode, path, ex); in ext4_ext_replay_shrink_inode()
5962 ext4_ext_dirty(NULL, inode, &path[path->p_depth]); in ext4_ext_replay_shrink_inode()
5965 ext4_free_ext_path(path); in ext4_ext_replay_shrink_inode()
5990 struct ext4_ext_path *path = NULL, *path2 = NULL; in ext4_ext_replay_set_iblocks() local
5998 path = ext4_find_extent(inode, EXT_MAX_BLOCKS - 1, NULL, in ext4_ext_replay_set_iblocks()
6000 if (IS_ERR(path)) in ext4_ext_replay_set_iblocks()
6001 return PTR_ERR(path); in ext4_ext_replay_set_iblocks()
6002 ex = path[path->p_depth].p_ext; in ext4_ext_replay_set_iblocks()
6004 ext4_free_ext_path(path); in ext4_ext_replay_set_iblocks()
6008 ext4_free_ext_path(path); in ext4_ext_replay_set_iblocks()
6026 * their paths. When path is different for 2 successive extents in ext4_ext_replay_set_iblocks()
6027 * we compare the blocks in the path at each level and increment in ext4_ext_replay_set_iblocks()
6034 path = ext4_find_extent(inode, cur, NULL, 0); in ext4_ext_replay_set_iblocks()
6035 if (IS_ERR(path)) in ext4_ext_replay_set_iblocks()
6037 numblks += path->p_depth; in ext4_ext_replay_set_iblocks()
6038 ext4_free_ext_path(path); in ext4_ext_replay_set_iblocks()
6040 path = ext4_find_extent(inode, cur, NULL, 0); in ext4_ext_replay_set_iblocks()
6041 if (IS_ERR(path)) in ext4_ext_replay_set_iblocks()
6043 ex = path[path->p_depth].p_ext; in ext4_ext_replay_set_iblocks()
6045 ext4_free_ext_path(path); in ext4_ext_replay_set_iblocks()
6052 ext4_free_ext_path(path); in ext4_ext_replay_set_iblocks()
6057 ext4_free_ext_path(path); in ext4_ext_replay_set_iblocks()
6060 for (i = 0; i <= max(path->p_depth, path2->p_depth); i++) { in ext4_ext_replay_set_iblocks()
6062 if (i <= path->p_depth) in ext4_ext_replay_set_iblocks()
6063 cmp1 = path[i].p_bh ? in ext4_ext_replay_set_iblocks()
6064 path[i].p_bh->b_blocknr : 0; in ext4_ext_replay_set_iblocks()
6071 ext4_free_ext_path(path); in ext4_ext_replay_set_iblocks()
6083 struct ext4_ext_path *path = NULL; in ext4_ext_clear_bb() local
6093 path = ext4_find_extent(inode, EXT_MAX_BLOCKS - 1, NULL, in ext4_ext_clear_bb()
6095 if (IS_ERR(path)) in ext4_ext_clear_bb()
6096 return PTR_ERR(path); in ext4_ext_clear_bb()
6097 ex = path[path->p_depth].p_ext; in ext4_ext_clear_bb()
6099 ext4_free_ext_path(path); in ext4_ext_clear_bb()
6103 ext4_free_ext_path(path); in ext4_ext_clear_bb()
6113 path = ext4_find_extent(inode, map.m_lblk, NULL, 0); in ext4_ext_clear_bb()
6114 if (!IS_ERR_OR_NULL(path)) { in ext4_ext_clear_bb()
6115 for (j = 0; j < path->p_depth; j++) { in ext4_ext_clear_bb()
6118 path[j].p_block, 1, false); in ext4_ext_clear_bb()
6120 0, path[j].p_block, 1, 1); in ext4_ext_clear_bb()
6122 ext4_free_ext_path(path); in ext4_ext_clear_bb()