Lines Matching +full:depth +full:-

1 // SPDX-License-Identifier: GPL-2.0
3 * Copyright (c) 2003-2006, Cluster File Systems, Inc, info@clusterfs.com
15 * - ext4*_error() should be used in some situations
16 * - analyze all BUG()/BUG_ON(), use -EIO where appropriate
17 * - smart tree reduction
53 struct ext4_sb_info *sbi = EXT4_SB(inode->i_sb); in ext4_extent_block_csum()
56 csum = ext4_chksum(sbi, ei->i_csum_seed, (__u8 *)eh, in ext4_extent_block_csum()
66 if (!ext4_has_metadata_csum(inode->i_sb)) in ext4_extent_block_csum_verify()
70 if (et->et_checksum != ext4_extent_block_csum(inode, eh)) in ext4_extent_block_csum_verify()
80 if (!ext4_has_metadata_csum(inode->i_sb)) in ext4_extent_block_csum_set()
84 et->et_checksum = ext4_extent_block_csum(inode, eh); in ext4_extent_block_csum_set()
104 up_write(&EXT4_I(inode)->i_data_sem); in ext4_ext_trunc_restart_fn()
111 int depth, i; in ext4_ext_drop_refs() local
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()
146 down_write(&EXT4_I(inode)->i_data_sem); in ext4_datasem_ensure_credits()
152 * - EROFS
153 * - ENOMEM
160 if (path->p_bh) { in ext4_ext_get_access()
162 BUFFER_TRACE(path->p_bh, "get_write_access"); in ext4_ext_get_access()
163 err = ext4_journal_get_write_access(handle, inode->i_sb, 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()
175 /* we use in-core data, no need to protect them */ in ext4_ext_get_access()
181 * - EROFS
182 * - ENOMEM
183 * - EIO
191 WARN_ON(!rwsem_is_locked(&EXT4_I(inode)->i_data_sem)); in __ext4_ext_dirty()
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()
196 inode, path->p_bh); in __ext4_ext_dirty()
197 /* Extents updating done, re-set verified flag */ in __ext4_ext_dirty()
199 set_buffer_verified(path->p_bh); in __ext4_ext_dirty()
215 int depth = path->p_depth; in ext4_ext_find_goal() local
221 * non-sparse --- i.e., in the case of libbfd writing in ext4_ext_find_goal()
222 * an ELF object sections out-of-order but in a way in ext4_ext_find_goal()
226 * non-ideal if we are writing a sparse file such as in ext4_ext_find_goal()
235 ex = path[depth].p_ext; in ext4_ext_find_goal()
238 ext4_lblk_t ext_block = le32_to_cpu(ex->ee_block); in ext4_ext_find_goal()
241 return ext_pblk + (block - ext_block); in ext4_ext_find_goal()
243 return ext_pblk - (ext_block - block); 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()
266 goal = ext4_ext_find_goal(inode, path, le32_to_cpu(ex->ee_block)); in ext4_ext_new_meta_block()
276 size = (inode->i_sb->s_blocksize - sizeof(struct ext4_extent_header)) in ext4_ext_space_block()
289 size = (inode->i_sb->s_blocksize - sizeof(struct ext4_extent_header)) in ext4_ext_space_block_idx()
302 size = sizeof(EXT4_I(inode)->i_data); in ext4_ext_space_root()
303 size -= sizeof(struct ext4_extent_header); in ext4_ext_space_root()
316 size = sizeof(EXT4_I(inode)->i_data); in ext4_ext_space_root_idx()
317 size -= sizeof(struct ext4_extent_header); in ext4_ext_space_root_idx()
332 int unwritten = ext4_ext_is_unwritten(path[path->p_depth].p_ext); in ext4_force_split_extent_at()
344 ext4_ext_max_entries(struct inode *inode, int depth) in ext4_ext_max_entries() argument
348 if (depth == ext_depth(inode)) { in ext4_ext_max_entries()
349 if (depth == 0) in ext4_ext_max_entries()
354 if (depth == 0) in ext4_ext_max_entries()
367 ext4_lblk_t lblock = le32_to_cpu(ext->ee_block); in ext4_valid_extent()
371 * - zero length in ext4_valid_extent()
372 * - overflow/wrap-around in ext4_valid_extent()
390 int depth) in ext4_valid_extent_entries() argument
396 if (eh->eh_entries == 0) in ext4_valid_extent_entries()
399 entries = le16_to_cpu(eh->eh_entries); in ext4_valid_extent_entries()
401 if (depth == 0) { in ext4_valid_extent_entries()
409 if (depth != ext_depth(inode) && in ext4_valid_extent_entries()
410 lblk != le32_to_cpu(ext->ee_block)) in ext4_valid_extent_entries()
417 lblock = le32_to_cpu(ext->ee_block); in ext4_valid_extent_entries()
424 entries--; in ext4_valid_extent_entries()
433 if (depth != ext_depth(inode) && in ext4_valid_extent_entries()
434 lblk != le32_to_cpu(ext_idx->ei_block)) in ext4_valid_extent_entries()
441 lblock = le32_to_cpu(ext_idx->ei_block); in ext4_valid_extent_entries()
447 entries--; in ext4_valid_extent_entries()
456 int depth, ext4_fsblk_t pblk, ext4_lblk_t lblk) in __ext4_ext_check() argument
459 int max = 0, err = -EFSCORRUPTED; in __ext4_ext_check()
461 if (unlikely(eh->eh_magic != EXT4_EXT_MAGIC)) { in __ext4_ext_check()
465 if (unlikely(le16_to_cpu(eh->eh_depth) != depth)) { in __ext4_ext_check()
469 if (unlikely(eh->eh_max == 0)) { in __ext4_ext_check()
473 max = ext4_ext_max_entries(inode, depth); in __ext4_ext_check()
474 if (unlikely(le16_to_cpu(eh->eh_max) > max)) { in __ext4_ext_check()
478 if (unlikely(le16_to_cpu(eh->eh_entries) > le16_to_cpu(eh->eh_max))) { in __ext4_ext_check()
482 if (unlikely((eh->eh_entries == 0) && (depth > 0))) { in __ext4_ext_check()
486 if (!ext4_valid_extent_entries(inode, eh, lblk, &pblk, depth)) { in __ext4_ext_check()
490 if (unlikely(depth > 32)) { in __ext4_ext_check()
494 /* Verify checksum on non-root extent tree nodes */ in __ext4_ext_check()
495 if (ext_depth(inode) != depth && in __ext4_ext_check()
498 err = -EFSBADCRC; in __ext4_ext_check()
504 ext4_error_inode_err(inode, function, line, 0, -err, in __ext4_ext_check()
505 "pblk %llu bad header/extent: %s - magic %x, " in __ext4_ext_check()
506 "entries %u, max %u(%u), depth %u(%u)", in __ext4_ext_check()
508 le16_to_cpu(eh->eh_magic), in __ext4_ext_check()
509 le16_to_cpu(eh->eh_entries), in __ext4_ext_check()
510 le16_to_cpu(eh->eh_max), in __ext4_ext_check()
511 max, le16_to_cpu(eh->eh_depth), depth); in __ext4_ext_check()
515 #define ext4_ext_check(inode, eh, depth, pblk) \ argument
516 __ext4_ext_check(__func__, __LINE__, (inode), (eh), (depth), (pblk), 0)
530 for (i = le16_to_cpu(eh->eh_entries); i > 0; i--, ex++) { in ext4_cache_extents()
532 ext4_lblk_t lblk = le32_to_cpu(ex->ee_block); in ext4_cache_extents()
536 ext4_es_cache_extent(inode, prev, lblk - prev, ~0, in ext4_cache_extents()
550 int depth, int flags) in __read_extent_tree_block() argument
561 bh = sb_getblk_gfp(inode->i_sb, pblk, gfp_flags); in __read_extent_tree_block()
563 return ERR_PTR(-ENOMEM); in __read_extent_tree_block()
574 depth, pblk, le32_to_cpu(idx->ei_block)); in __read_extent_tree_block()
581 if (!(flags & EXT4_EX_NOCACHE) && depth == 0) { in __read_extent_tree_block()
592 #define read_extent_tree_block(inode, idx, depth, flags) \ argument
594 (depth), (flags))
605 int i = 0, depth, ret = 0; in ext4_ext_precache() local
608 return 0; /* not an extent-mapped inode */ in ext4_ext_precache()
610 down_read(&ei->i_data_sem); in ext4_ext_precache()
611 depth = ext_depth(inode); in ext4_ext_precache()
614 if (!depth) { in ext4_ext_precache()
615 up_read(&ei->i_data_sem); in ext4_ext_precache()
619 path = kcalloc(depth + 1, sizeof(struct ext4_ext_path), in ext4_ext_precache()
622 up_read(&ei->i_data_sem); in ext4_ext_precache()
623 return -ENOMEM; in ext4_ext_precache()
627 ret = ext4_ext_check(inode, path[0].p_hdr, depth, 0); in ext4_ext_precache()
636 if ((i == depth) || in ext4_ext_precache()
640 i--; in ext4_ext_precache()
644 depth - i - 1, in ext4_ext_precache()
657 up_read(&ei->i_data_sem); in ext4_ext_precache()
665 int k, l = path->p_depth; in ext4_ext_show_path()
669 if (path->p_idx) { in ext4_ext_show_path()
670 ext_debug(inode, " %d->%llu", 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()
687 int depth = ext_depth(inode); in ext4_ext_show_leaf() local
695 eh = path[depth].p_hdr; in ext4_ext_show_leaf()
700 for (i = 0; i < le16_to_cpu(eh->eh_entries); i++, ex++) { in ext4_ext_show_leaf()
701 ext_debug(inode, "%d:[%d]%d:%llu ", le32_to_cpu(ex->ee_block), in ext4_ext_show_leaf()
711 int depth = ext_depth(inode); in ext4_ext_show_move() local
714 if (depth != level) { in ext4_ext_show_move()
719 level, le32_to_cpu(idx->ei_block), 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()
730 le32_to_cpu(ex->ee_block), in ext4_ext_show_move()
754 struct ext4_extent_header *eh = path->p_hdr; in ext4_ext_binsearch_idx()
763 m = l + (r - l) / 2; in ext4_ext_binsearch_idx()
765 le32_to_cpu(l->ei_block), m, le32_to_cpu(m->ei_block), in ext4_ext_binsearch_idx()
766 r, le32_to_cpu(r->ei_block)); in ext4_ext_binsearch_idx()
768 if (block < le32_to_cpu(m->ei_block)) in ext4_ext_binsearch_idx()
769 r = m - 1; 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()
784 for (k = 0; k < le16_to_cpu(eh->eh_entries); k++, ix++) { in ext4_ext_binsearch_idx()
785 if (k != 0 && le32_to_cpu(ix->ei_block) <= in ext4_ext_binsearch_idx()
786 le32_to_cpu(ix[-1].ei_block)) { in ext4_ext_binsearch_idx()
791 le32_to_cpu(ix->ei_block), in ext4_ext_binsearch_idx()
792 le32_to_cpu(ix[-1].ei_block)); in ext4_ext_binsearch_idx()
794 BUG_ON(k && le32_to_cpu(ix->ei_block) in ext4_ext_binsearch_idx()
795 <= le32_to_cpu(ix[-1].ei_block)); in ext4_ext_binsearch_idx()
796 if (block < le32_to_cpu(ix->ei_block)) in ext4_ext_binsearch_idx()
800 BUG_ON(chix != path->p_idx); in ext4_ext_binsearch_idx()
815 struct ext4_extent_header *eh = path->p_hdr; in ext4_ext_binsearch()
818 if (eh->eh_entries == 0) { in ext4_ext_binsearch()
832 m = l + (r - l) / 2; in ext4_ext_binsearch()
834 le32_to_cpu(l->ee_block), m, le32_to_cpu(m->ee_block), in ext4_ext_binsearch()
835 r, le32_to_cpu(r->ee_block)); in ext4_ext_binsearch()
837 if (block < le32_to_cpu(m->ee_block)) in ext4_ext_binsearch()
838 r = m - 1; in ext4_ext_binsearch()
843 path->p_ext = l - 1; in ext4_ext_binsearch()
844 ext_debug(inode, " -> %d:%llu:[%d]%d ", 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()
856 for (k = 0; k < le16_to_cpu(eh->eh_entries); k++, ex++) { in ext4_ext_binsearch()
857 BUG_ON(k && le32_to_cpu(ex->ee_block) in ext4_ext_binsearch()
858 <= le32_to_cpu(ex[-1].ee_block)); in ext4_ext_binsearch()
859 if (block < le32_to_cpu(ex->ee_block)) in ext4_ext_binsearch()
863 BUG_ON(chex != path->p_ext); in ext4_ext_binsearch()
874 eh->eh_depth = 0; in ext4_ext_tree_init()
875 eh->eh_entries = 0; in ext4_ext_tree_init()
876 eh->eh_magic = EXT4_EXT_MAGIC; in ext4_ext_tree_init()
877 eh->eh_max = cpu_to_le16(ext4_ext_space_root(inode, 0)); in ext4_ext_tree_init()
878 eh->eh_generation = 0; in ext4_ext_tree_init()
889 short int depth, i, ppos = 0; in ext4_find_extent() local
897 depth = ext_depth(inode); in ext4_find_extent()
898 if (depth < 0 || depth > EXT4_MAX_EXTENT_DEPTH) { in ext4_find_extent()
899 EXT4_ERROR_INODE(inode, "inode has invalid extent depth: %d", in ext4_find_extent()
900 depth); in ext4_find_extent()
901 ret = -EFSCORRUPTED; in ext4_find_extent()
907 if (depth > path[0].p_maxdepth) { in ext4_find_extent()
913 /* account possible depth increase */ in ext4_find_extent()
914 path = kcalloc(depth + 2, sizeof(struct ext4_ext_path), in ext4_find_extent()
917 return ERR_PTR(-ENOMEM); in ext4_find_extent()
918 path[0].p_maxdepth = depth + 1; in ext4_find_extent()
923 i = depth; in ext4_find_extent()
924 if (!(flags & EXT4_EX_NOCACHE) && depth == 0) in ext4_find_extent()
928 ext_debug(inode, "depth %d: num %d, max %d\n", in ext4_find_extent()
929 ppos, le16_to_cpu(eh->eh_entries), le16_to_cpu(eh->eh_max)); in ext4_find_extent()
936 bh = read_extent_tree_block(inode, path[ppos].p_idx, --i, flags); in ext4_find_extent()
985 if (unlikely(logical == le32_to_cpu(curp->p_idx->ei_block))) { in ext4_ext_insert_index()
988 logical, le32_to_cpu(curp->p_idx->ei_block)); in ext4_ext_insert_index()
989 return -EFSCORRUPTED; in ext4_ext_insert_index()
992 if (unlikely(le16_to_cpu(curp->p_hdr->eh_entries) in ext4_ext_insert_index()
993 >= le16_to_cpu(curp->p_hdr->eh_max))) { in ext4_ext_insert_index()
996 le16_to_cpu(curp->p_hdr->eh_entries), in ext4_ext_insert_index()
997 le16_to_cpu(curp->p_hdr->eh_max)); in ext4_ext_insert_index()
998 return -EFSCORRUPTED; in ext4_ext_insert_index()
1001 if (logical > le32_to_cpu(curp->p_idx->ei_block)) { in ext4_ext_insert_index()
1005 ix = curp->p_idx + 1; in ext4_ext_insert_index()
1010 ix = curp->p_idx; in ext4_ext_insert_index()
1013 len = EXT_LAST_INDEX(curp->p_hdr) - ix + 1; in ext4_ext_insert_index()
1022 if (unlikely(ix > EXT_MAX_INDEX(curp->p_hdr))) { in ext4_ext_insert_index()
1024 return -EFSCORRUPTED; in ext4_ext_insert_index()
1027 ix->ei_block = cpu_to_le32(logical); in ext4_ext_insert_index()
1029 le16_add_cpu(&curp->p_hdr->eh_entries, 1); in ext4_ext_insert_index()
1031 if (unlikely(ix > EXT_LAST_INDEX(curp->p_hdr))) { in ext4_ext_insert_index()
1033 return -EFSCORRUPTED; in ext4_ext_insert_index()
1037 ext4_std_error(inode->i_sb, err); in ext4_ext_insert_index()
1045 * at depth @at:
1046 * - allocates all needed blocks (new leaf and all intermediate index blocks)
1047 * - makes decision where to split
1048 * - moves remaining extents and index entries (right to the split point)
1050 * - initializes subtree
1058 int depth = ext_depth(inode); in ext4_ext_split() local
1077 if (unlikely(path[depth].p_ext > EXT_MAX_EXTENT(path[depth].p_hdr))) { in ext4_ext_split()
1079 return -EFSCORRUPTED; 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()
1087 border = newext->ee_block; in ext4_ext_split()
1095 * and mark filesystem read-only. index won't in ext4_ext_split()
1105 ablocks = kcalloc(depth, sizeof(ext4_fsblk_t), gfp_flags); in ext4_ext_split()
1107 return -ENOMEM; in ext4_ext_split()
1110 ext_debug(inode, "allocate %d blocks for indexes/leaf\n", depth - at); in ext4_ext_split()
1111 for (a = 0; a < depth - at; a++) { in ext4_ext_split()
1120 newblock = ablocks[--a]; in ext4_ext_split()
1123 err = -EFSCORRUPTED; in ext4_ext_split()
1126 bh = sb_getblk_gfp(inode->i_sb, newblock, __GFP_MOVABLE | GFP_NOFS); in ext4_ext_split()
1128 err = -ENOMEM; in ext4_ext_split()
1133 err = ext4_journal_get_create_access(handle, inode->i_sb, bh, in ext4_ext_split()
1139 neh->eh_entries = 0; in ext4_ext_split()
1140 neh->eh_max = cpu_to_le16(ext4_ext_space_block(inode, 0)); in ext4_ext_split()
1141 neh->eh_magic = EXT4_EXT_MAGIC; in ext4_ext_split()
1142 neh->eh_depth = 0; in ext4_ext_split()
1143 neh->eh_generation = 0; 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()
1151 err = -EFSCORRUPTED; 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()
1161 le16_add_cpu(&neh->eh_entries, m); in ext4_ext_split()
1166 sizeof(struct ext4_extent) * le16_to_cpu(neh->eh_entries); in ext4_ext_split()
1167 memset(bh->b_data + ext_size, 0, inode->i_sb->s_blocksize - ext_size); 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()
1191 k = depth - at - 1; in ext4_ext_split()
1194 err = -EFSCORRUPTED; in ext4_ext_split()
1200 /* current depth stored in i var */ in ext4_ext_split()
1201 i = depth - 1; in ext4_ext_split()
1202 while (k--) { in ext4_ext_split()
1204 newblock = ablocks[--a]; in ext4_ext_split()
1205 bh = sb_getblk(inode->i_sb, newblock); in ext4_ext_split()
1207 err = -ENOMEM; in ext4_ext_split()
1212 err = ext4_journal_get_create_access(handle, inode->i_sb, bh, in ext4_ext_split()
1218 neh->eh_entries = cpu_to_le16(1); in ext4_ext_split()
1219 neh->eh_magic = EXT4_EXT_MAGIC; in ext4_ext_split()
1220 neh->eh_max = cpu_to_le16(ext4_ext_space_block_idx(inode, 0)); in ext4_ext_split()
1221 neh->eh_depth = cpu_to_le16(depth - i); in ext4_ext_split()
1222 neh->eh_generation = 0; in ext4_ext_split()
1224 fidx->ei_block = border; in ext4_ext_split()
1227 ext_debug(inode, "int.index at %d (block %llu): %u -> %llu\n", in ext4_ext_split()
1235 le32_to_cpu(path[i].p_ext->ee_block)); in ext4_ext_split()
1236 err = -EFSCORRUPTED; in ext4_ext_split()
1240 m = EXT_MAX_INDEX(path[i].p_hdr) - path[i].p_idx++; in ext4_ext_split()
1247 le16_add_cpu(&neh->eh_entries, m); in ext4_ext_split()
1251 (sizeof(struct ext4_extent) * le16_to_cpu(neh->eh_entries)); in ext4_ext_split()
1252 memset(bh->b_data + ext_size, 0, in ext4_ext_split()
1253 inode->i_sb->s_blocksize - ext_size); in ext4_ext_split()
1269 le16_add_cpu(&path[i].p_hdr->eh_entries, -m); in ext4_ext_split()
1275 i--; in ext4_ext_split()
1291 for (i = 0; i < depth; i++) { in ext4_ext_split()
1306 * - allocates new block
1307 * - moves top-level data (index block or leaf) into the new block
1308 * - initializes new top-level, creating index that points to the
1317 struct ext4_super_block *es = EXT4_SB(inode->i_sb)->s_es; in ext4_ext_grow_indepth()
1324 if (goal > le32_to_cpu(es->s_first_data_block)) { in ext4_ext_grow_indepth()
1326 goal--; in ext4_ext_grow_indepth()
1334 bh = sb_getblk_gfp(inode->i_sb, newblock, __GFP_MOVABLE | GFP_NOFS); in ext4_ext_grow_indepth()
1336 return -ENOMEM; in ext4_ext_grow_indepth()
1339 err = ext4_journal_get_create_access(handle, inode->i_sb, bh, in ext4_ext_grow_indepth()
1346 ext_size = sizeof(EXT4_I(inode)->i_data); in ext4_ext_grow_indepth()
1347 /* move top-level index/leaf into new block */ in ext4_ext_grow_indepth()
1348 memmove(bh->b_data, EXT4_I(inode)->i_data, ext_size); in ext4_ext_grow_indepth()
1350 memset(bh->b_data + ext_size, 0, inode->i_sb->s_blocksize - ext_size); in ext4_ext_grow_indepth()
1357 neh->eh_max = cpu_to_le16(ext4_ext_space_block_idx(inode, 0)); in ext4_ext_grow_indepth()
1359 neh->eh_max = cpu_to_le16(ext4_ext_space_block(inode, 0)); in ext4_ext_grow_indepth()
1360 neh->eh_magic = EXT4_EXT_MAGIC; in ext4_ext_grow_indepth()
1370 /* Update top-level index: num,max,pointer */ in ext4_ext_grow_indepth()
1372 neh->eh_entries = cpu_to_le16(1); in ext4_ext_grow_indepth()
1374 if (neh->eh_depth == 0) { in ext4_ext_grow_indepth()
1376 neh->eh_max = cpu_to_le16(ext4_ext_space_root_idx(inode, 0)); in ext4_ext_grow_indepth()
1377 EXT_FIRST_INDEX(neh)->ei_block = in ext4_ext_grow_indepth()
1378 EXT_FIRST_EXTENT(neh)->ee_block; in ext4_ext_grow_indepth()
1381 le16_to_cpu(neh->eh_entries), le16_to_cpu(neh->eh_max), in ext4_ext_grow_indepth()
1382 le32_to_cpu(EXT_FIRST_INDEX(neh)->ei_block), in ext4_ext_grow_indepth()
1385 le16_add_cpu(&neh->eh_depth, 1); in ext4_ext_grow_indepth()
1396 * if no free index is found, then it requests in-depth growing.
1406 int depth, i, err = 0; in ext4_ext_create_new_leaf() local
1409 i = depth = ext_depth(inode); in ext4_ext_create_new_leaf()
1412 curp = path + depth; in ext4_ext_create_new_leaf()
1414 i--; in ext4_ext_create_new_leaf()
1415 curp--; in ext4_ext_create_new_leaf()
1429 (ext4_lblk_t)le32_to_cpu(newext->ee_block), in ext4_ext_create_new_leaf()
1434 /* tree is full, time to grow in depth */ in ext4_ext_create_new_leaf()
1441 (ext4_lblk_t)le32_to_cpu(newext->ee_block), in ext4_ext_create_new_leaf()
1449 * only first (depth 0 -> 1) produces free space; in ext4_ext_create_new_leaf()
1452 depth = ext_depth(inode); 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()
1476 int depth, ee_len; in ext4_ext_search_left() local
1480 return -EFSCORRUPTED; 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()
1492 ex = path[depth].p_ext; in ext4_ext_search_left()
1494 if (*logical < le32_to_cpu(ex->ee_block)) { in ext4_ext_search_left()
1495 if (unlikely(EXT_FIRST_EXTENT(path[depth].p_hdr) != ex)) { in ext4_ext_search_left()
1498 *logical, le32_to_cpu(ex->ee_block)); in ext4_ext_search_left()
1499 return -EFSCORRUPTED; in ext4_ext_search_left()
1501 while (--depth >= 0) { 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()
1505 "ix (%d) != EXT_FIRST_INDEX (%d) (depth %d)!", in ext4_ext_search_left()
1506 ix != NULL ? le32_to_cpu(ix->ei_block) : 0, in ext4_ext_search_left()
1507 le32_to_cpu(EXT_FIRST_INDEX(path[depth].p_hdr)->ei_block), in ext4_ext_search_left()
1508 depth); in ext4_ext_search_left()
1509 return -EFSCORRUPTED; in ext4_ext_search_left()
1515 if (unlikely(*logical < (le32_to_cpu(ex->ee_block) + ee_len))) { in ext4_ext_search_left()
1518 *logical, le32_to_cpu(ex->ee_block), ee_len); in ext4_ext_search_left()
1519 return -EFSCORRUPTED; in ext4_ext_search_left()
1522 *logical = le32_to_cpu(ex->ee_block) + ee_len - 1; in ext4_ext_search_left()
1523 *phys = ext4_ext_pblock(ex) + ee_len - 1; in ext4_ext_search_left()
1543 int depth; /* Note, NOT eh_depth; depth from top of tree */ in ext4_ext_search_right() local
1548 return -EFSCORRUPTED; 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()
1560 ex = path[depth].p_ext; in ext4_ext_search_right()
1562 if (*logical < le32_to_cpu(ex->ee_block)) { in ext4_ext_search_right()
1563 if (unlikely(EXT_FIRST_EXTENT(path[depth].p_hdr) != ex)) { in ext4_ext_search_right()
1566 depth); in ext4_ext_search_right()
1567 return -EFSCORRUPTED; in ext4_ext_search_right()
1569 while (--depth >= 0) { 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()
1575 return -EFSCORRUPTED; in ext4_ext_search_right()
1581 if (unlikely(*logical < (le32_to_cpu(ex->ee_block) + ee_len))) { in ext4_ext_search_right()
1584 *logical, le32_to_cpu(ex->ee_block), ee_len); in ext4_ext_search_right()
1585 return -EFSCORRUPTED; in ext4_ext_search_right()
1588 if (ex != EXT_LAST_EXTENT(path[depth].p_hdr)) { in ext4_ext_search_right()
1595 while (--depth >= 0) { 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()
1625 *logical = le32_to_cpu(ex->ee_block); in ext4_ext_search_right()
1644 int depth; in ext4_ext_next_allocated_block() local
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()
1652 while (depth >= 0) { 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()
1657 if (p->p_ext && p->p_ext != EXT_LAST_EXTENT(p->p_hdr)) in ext4_ext_next_allocated_block()
1658 return le32_to_cpu(p->p_ext[1].ee_block); in ext4_ext_next_allocated_block()
1661 if (p->p_idx != EXT_LAST_INDEX(p->p_hdr)) in ext4_ext_next_allocated_block()
1662 return le32_to_cpu(p->p_idx[1].ei_block); in ext4_ext_next_allocated_block()
1664 depth--; in ext4_ext_next_allocated_block()
1676 int depth; in ext4_ext_next_leaf_block() local
1679 depth = path->p_depth; in ext4_ext_next_leaf_block()
1681 /* zero-tree has no leaf blocks at all */ in ext4_ext_next_leaf_block()
1682 if (depth == 0) in ext4_ext_next_leaf_block()
1686 depth--; in ext4_ext_next_leaf_block()
1688 while (depth >= 0) { 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()
1693 depth--; in ext4_ext_next_leaf_block()
1709 int depth = ext_depth(inode); in ext4_ext_correct_indexes() local
1714 eh = path[depth].p_hdr; in ext4_ext_correct_indexes()
1715 ex = path[depth].p_ext; in ext4_ext_correct_indexes()
1720 return -EFSCORRUPTED; in ext4_ext_correct_indexes()
1723 if (depth == 0) { in ext4_ext_correct_indexes()
1736 k = depth - 1; in ext4_ext_correct_indexes()
1737 border = path[depth].p_ext->ee_block; in ext4_ext_correct_indexes()
1741 path[k].p_idx->ei_block = border; in ext4_ext_correct_indexes()
1746 while (k--) { in ext4_ext_correct_indexes()
1747 /* change all left-side indexes */ in ext4_ext_correct_indexes()
1753 path[k].p_idx->ei_block = border; in ext4_ext_correct_indexes()
1774 if (le32_to_cpu(ex1->ee_block) + ext1_ee_len != in ext4_can_extents_be_merged()
1775 le32_to_cpu(ex2->ee_block)) in ext4_can_extents_be_merged()
1797 * left, pass "ex - 1" as argument instead of "ex".
1806 unsigned int depth, len; in ext4_ext_try_to_merge_right() local
1809 depth = ext_depth(inode); in ext4_ext_try_to_merge_right()
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()
1818 ex->ee_len = cpu_to_le16(ext4_ext_get_actual_len(ex) in ext4_ext_try_to_merge_right()
1824 len = (EXT_LAST_EXTENT(eh) - ex - 1) in ext4_ext_try_to_merge_right()
1828 le16_add_cpu(&eh->eh_entries, -1); in ext4_ext_try_to_merge_right()
1830 WARN_ON(eh->eh_entries == 0); in ext4_ext_try_to_merge_right()
1831 if (!eh->eh_entries) in ext4_ext_try_to_merge_right()
1832 EXT4_ERROR_INODE(inode, "eh->eh_entries = 0!"); in ext4_ext_try_to_merge_right()
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()
1861 ext4_free_metadata_revoke_credits(inode->i_sb, 1))) 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()
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()
1894 unsigned int depth; in ext4_ext_try_to_merge() local
1897 depth = ext_depth(inode); in ext4_ext_try_to_merge()
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()
1924 unsigned int depth, len1; in ext4_ext_check_overlap() local
1927 b1 = le32_to_cpu(newext->ee_block); in ext4_ext_check_overlap()
1929 depth = ext_depth(inode); in ext4_ext_check_overlap()
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()
1947 len1 = EXT_MAX_BLOCKS - b1; in ext4_ext_check_overlap()
1948 newext->ee_len = cpu_to_le16(len1); in ext4_ext_check_overlap()
1954 newext->ee_len = cpu_to_le16(b2 - b1); in ext4_ext_check_overlap()
1965 * creating new leaf in the no-space case.
1976 int depth, len, err; in ext4_ext_insert_extent() local
1984 return -EFSCORRUPTED; in ext4_ext_insert_extent()
1986 depth = ext_depth(inode); in ext4_ext_insert_extent()
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()
1991 return -EFSCORRUPTED; in ext4_ext_insert_extent()
2005 (le32_to_cpu(ex->ee_block) + in ext4_ext_insert_extent()
2007 le32_to_cpu(newext->ee_block))) { in ext4_ext_insert_extent()
2011 (le32_to_cpu(newext->ee_block) + in ext4_ext_insert_extent()
2013 le32_to_cpu(ex->ee_block))) in ext4_ext_insert_extent()
2014 ex -= 1; in ext4_ext_insert_extent()
2022 le32_to_cpu(ex->ee_block), in ext4_ext_insert_extent()
2027 path + depth); in ext4_ext_insert_extent()
2031 ex->ee_len = cpu_to_le16(ext4_ext_get_actual_len(ex) in ext4_ext_insert_extent()
2044 le32_to_cpu(newext->ee_block), in ext4_ext_insert_extent()
2047 le32_to_cpu(ex->ee_block), in ext4_ext_insert_extent()
2052 path + depth); in ext4_ext_insert_extent()
2057 ex->ee_block = newext->ee_block; in ext4_ext_insert_extent()
2059 ex->ee_len = cpu_to_le16(ext4_ext_get_actual_len(ex) in ext4_ext_insert_extent()
2068 depth = ext_depth(inode); in ext4_ext_insert_extent()
2069 eh = path[depth].p_hdr; in ext4_ext_insert_extent()
2070 if (le16_to_cpu(eh->eh_entries) < le16_to_cpu(eh->eh_max)) in ext4_ext_insert_extent()
2076 if (le32_to_cpu(newext->ee_block) > le32_to_cpu(fex->ee_block)) in ext4_ext_insert_extent()
2079 ext_debug(inode, "next leaf block - %u\n", next); in ext4_ext_insert_extent()
2084 BUG_ON(npath->p_depth != path->p_depth); in ext4_ext_insert_extent()
2085 eh = npath[depth].p_hdr; in ext4_ext_insert_extent()
2086 if (le16_to_cpu(eh->eh_entries) < le16_to_cpu(eh->eh_max)) { in ext4_ext_insert_extent()
2088 le16_to_cpu(eh->eh_entries)); in ext4_ext_insert_extent()
2093 le16_to_cpu(eh->eh_entries), le16_to_cpu(eh->eh_max)); in ext4_ext_insert_extent()
2106 depth = ext_depth(inode); 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()
2119 le32_to_cpu(newext->ee_block), in ext4_ext_insert_extent()
2125 if (le32_to_cpu(newext->ee_block) in ext4_ext_insert_extent()
2126 > le32_to_cpu(nearex->ee_block)) { in ext4_ext_insert_extent()
2130 le32_to_cpu(newext->ee_block), in ext4_ext_insert_extent()
2138 BUG_ON(newext->ee_block == nearex->ee_block); in ext4_ext_insert_extent()
2141 le32_to_cpu(newext->ee_block), in ext4_ext_insert_extent()
2147 len = EXT_LAST_EXTENT(eh) - nearex + 1; in ext4_ext_insert_extent()
2151 le32_to_cpu(newext->ee_block), in ext4_ext_insert_extent()
2161 le16_add_cpu(&eh->eh_entries, 1); in ext4_ext_insert_extent()
2162 path[depth].p_ext = nearex; in ext4_ext_insert_extent()
2163 nearex->ee_block = newext->ee_block; in ext4_ext_insert_extent()
2165 nearex->ee_len = newext->ee_len; in ext4_ext_insert_extent()
2178 err = ext4_ext_dirty(handle, inode, path + path->p_depth); in ext4_ext_insert_extent()
2189 ext4_lblk_t next, end = block + num - 1; in ext4_fill_es_cache_info()
2191 unsigned char blksize_bits = inode->i_sb->s_blocksize_bits; in ext4_fill_es_cache_info()
2232 * ext4_ext_determine_hole - determine hole around given block
2248 int depth = ext_depth(inode); in ext4_ext_determine_hole() local
2252 ex = path[depth].p_ext; in ext4_ext_determine_hole()
2254 /* there is no extent yet, so gap is [0;-] */ in ext4_ext_determine_hole()
2257 } else if (*lblk < le32_to_cpu(ex->ee_block)) { in ext4_ext_determine_hole()
2258 len = le32_to_cpu(ex->ee_block) - *lblk; in ext4_ext_determine_hole()
2259 } else if (*lblk >= le32_to_cpu(ex->ee_block) in ext4_ext_determine_hole()
2263 *lblk = le32_to_cpu(ex->ee_block) + ext4_ext_get_actual_len(ex); in ext4_ext_determine_hole()
2266 len = next - *lblk; in ext4_ext_determine_hole()
2285 hole_start + hole_len - 1, &es); in ext4_ext_put_gap_in_cache()
2290 hole_len = min(es.es_lblk - hole_start, hole_len); in ext4_ext_put_gap_in_cache()
2292 ext_debug(inode, " -> %u:%u\n", hole_start, hole_len); in ext4_ext_put_gap_in_cache()
2302 struct ext4_ext_path *path, int depth) in ext4_ext_rm_idx() argument
2308 depth--; in ext4_ext_rm_idx()
2309 path = path + depth; in ext4_ext_rm_idx()
2310 leaf = ext4_idx_pblock(path->p_idx); in ext4_ext_rm_idx()
2311 if (unlikely(path->p_hdr->eh_entries == 0)) { in ext4_ext_rm_idx()
2312 EXT4_ERROR_INODE(inode, "path->p_hdr->eh_entries == 0"); in ext4_ext_rm_idx()
2313 return -EFSCORRUPTED; in ext4_ext_rm_idx()
2319 if (path->p_idx != EXT_LAST_INDEX(path->p_hdr)) { in ext4_ext_rm_idx()
2320 int len = EXT_LAST_INDEX(path->p_hdr) - path->p_idx; in ext4_ext_rm_idx()
2322 memmove(path->p_idx, path->p_idx + 1, len); in ext4_ext_rm_idx()
2325 le16_add_cpu(&path->p_hdr->eh_entries, -1); in ext4_ext_rm_idx()
2335 while (--depth >= 0) { in ext4_ext_rm_idx()
2336 if (path->p_idx != EXT_FIRST_INDEX(path->p_hdr)) in ext4_ext_rm_idx()
2338 path--; in ext4_ext_rm_idx()
2342 path->p_idx->ei_block = (path+1)->p_idx->ei_block; in ext4_ext_rm_idx()
2361 int depth = ext_depth(inode); in ext4_ext_calc_credits_for_single_extent() local
2365 if (le16_to_cpu(path[depth].p_hdr->eh_entries) in ext4_ext_calc_credits_for_single_extent()
2366 < le16_to_cpu(path[depth].p_hdr->eh_max)) { in ext4_ext_calc_credits_for_single_extent()
2377 ret = 2 + EXT4_META_TRANS_BLOCKS(inode->i_sb); in ext4_ext_calc_credits_for_single_extent()
2397 int depth; in ext4_ext_index_trans_blocks() local
2403 depth = ext_depth(inode); in ext4_ext_index_trans_blocks()
2406 index = depth * 2; in ext4_ext_index_trans_blocks()
2408 index = depth * 3; in ext4_ext_index_trans_blocks()
2415 if (S_ISDIR(inode->i_mode) || S_ISLNK(inode->i_mode) || in get_default_free_blocks_flags()
2424 * ext4_rereserve_cluster - increment the reserved cluster count when
2427 * @inode - file containing the cluster
2428 * @lblk - logical block in cluster to be reserved
2440 struct ext4_sb_info *sbi = EXT4_SB(inode->i_sb); in ext4_rereserve_cluster()
2445 spin_lock(&ei->i_block_reservation_lock); in ext4_rereserve_cluster()
2446 ei->i_reserved_data_blocks++; in ext4_rereserve_cluster()
2447 percpu_counter_add(&sbi->s_dirtyclusters_counter, 1); in ext4_rereserve_cluster()
2448 spin_unlock(&ei->i_block_reservation_lock); in ext4_rereserve_cluster()
2450 percpu_counter_add(&sbi->s_freeclusters_counter, 1); in ext4_rereserve_cluster()
2459 struct ext4_sb_info *sbi = EXT4_SB(inode->i_sb); in ext4_remove_blocks()
2466 if (from < le32_to_cpu(ex->ee_block) || in ext4_remove_blocks()
2467 to != le32_to_cpu(ex->ee_block) + ee_len - 1) { in ext4_remove_blocks()
2468 ext4_error(sbi->s_sb, in ext4_remove_blocks()
2469 "strange request: removal(2) %u-%u from %u:%u", in ext4_remove_blocks()
2470 from, to, le32_to_cpu(ex->ee_block), ee_len); in ext4_remove_blocks()
2475 spin_lock(&sbi->s_ext_stats_lock); in ext4_remove_blocks()
2476 sbi->s_ext_blocks += ee_len; in ext4_remove_blocks()
2477 sbi->s_ext_extents++; in ext4_remove_blocks()
2478 if (ee_len < sbi->s_ext_min) in ext4_remove_blocks()
2479 sbi->s_ext_min = ee_len; in ext4_remove_blocks()
2480 if (ee_len > sbi->s_ext_max) in ext4_remove_blocks()
2481 sbi->s_ext_max = ee_len; in ext4_remove_blocks()
2482 if (ext_depth(inode) > sbi->s_depth_max) in ext4_remove_blocks()
2483 sbi->s_depth_max = ext_depth(inode); in ext4_remove_blocks()
2484 spin_unlock(&sbi->s_ext_stats_lock); in ext4_remove_blocks()
2493 last_pblk = ext4_ext_pblock(ex) + ee_len - 1; in ext4_remove_blocks()
2495 if (partial->state != initial && in ext4_remove_blocks()
2496 partial->pclu != EXT4_B2C(sbi, last_pblk)) { in ext4_remove_blocks()
2497 if (partial->state == tofree) { in ext4_remove_blocks()
2499 if (ext4_is_pending(inode, partial->lblk)) in ext4_remove_blocks()
2502 EXT4_C2B(sbi, partial->pclu), in ext4_remove_blocks()
2503 sbi->s_cluster_ratio, flags); in ext4_remove_blocks()
2505 ext4_rereserve_cluster(inode, partial->lblk); in ext4_remove_blocks()
2507 partial->state = initial; in ext4_remove_blocks()
2510 num = le32_to_cpu(ex->ee_block) + ee_len - from; in ext4_remove_blocks()
2511 pblk = ext4_ext_pblock(ex) + ee_len - num; in ext4_remove_blocks()
2522 if ((EXT4_LBLK_COFF(sbi, to) != sbi->s_cluster_ratio - 1) && in ext4_remove_blocks()
2524 (partial->state != nofree)) { in ext4_remove_blocks()
2529 sbi->s_cluster_ratio, flags); in ext4_remove_blocks()
2532 partial->state = initial; in ext4_remove_blocks()
2548 if (partial->state != initial && partial->pclu != EXT4_B2C(sbi, pblk)) in ext4_remove_blocks()
2549 partial->state = initial; in ext4_remove_blocks()
2558 * cluster - we're either done freeing or the beginning of the in ext4_remove_blocks()
2562 if (partial->state == initial) { in ext4_remove_blocks()
2563 partial->pclu = EXT4_B2C(sbi, pblk); in ext4_remove_blocks()
2564 partial->lblk = from; in ext4_remove_blocks()
2565 partial->state = tofree; in ext4_remove_blocks()
2568 partial->state = initial; in ext4_remove_blocks()
2595 struct ext4_sb_info *sbi = EXT4_SB(inode->i_sb); in ext4_ext_rm_leaf()
2597 int depth = ext_depth(inode), credits, revoke_credits; in ext4_ext_rm_leaf() local
2609 if (!path[depth].p_hdr) in ext4_ext_rm_leaf()
2610 path[depth].p_hdr = ext_block_hdr(path[depth].p_bh); in ext4_ext_rm_leaf()
2611 eh = path[depth].p_hdr; in ext4_ext_rm_leaf()
2612 if (unlikely(path[depth].p_hdr == NULL)) { in ext4_ext_rm_leaf()
2613 EXT4_ERROR_INODE(inode, "path[%d].p_hdr == NULL", depth); in ext4_ext_rm_leaf()
2614 return -EFSCORRUPTED; in ext4_ext_rm_leaf()
2617 ex = path[depth].p_ext; in ext4_ext_rm_leaf()
2621 ex_ee_block = le32_to_cpu(ex->ee_block); in ext4_ext_rm_leaf()
2636 path[depth].p_ext = ex; in ext4_ext_rm_leaf()
2639 b = ex_ee_block+ex_ee_len - 1 < end ? in ext4_ext_rm_leaf()
2640 ex_ee_block+ex_ee_len - 1 : end; in ext4_ext_rm_leaf()
2653 if (sbi->s_cluster_ratio > 1) { in ext4_ext_rm_leaf()
2655 partial->pclu = EXT4_B2C(sbi, pblk); in ext4_ext_rm_leaf()
2656 partial->state = nofree; in ext4_ext_rm_leaf()
2658 ex--; in ext4_ext_rm_leaf()
2659 ex_ee_block = le32_to_cpu(ex->ee_block); in ext4_ext_rm_leaf()
2662 } else if (b != ex_ee_block + ex_ee_len - 1) { in ext4_ext_rm_leaf()
2667 ex_ee_block + ex_ee_len - 1); in ext4_ext_rm_leaf()
2668 err = -EFSCORRUPTED; in ext4_ext_rm_leaf()
2672 num = a - ex_ee_block; in ext4_ext_rm_leaf()
2683 credits = 7 + 2*(ex_ee_len/EXT4_BLOCKS_PER_GROUP(inode->i_sb)); in ext4_ext_rm_leaf()
2688 credits += EXT4_MAXQUOTAS_TRANS_BLOCKS(inode->i_sb); in ext4_ext_rm_leaf()
2695 ext4_free_metadata_revoke_credits(inode->i_sb, in ext4_ext_rm_leaf()
2697 ext4_free_data_revoke_credits(inode, b - a + 1); in ext4_ext_rm_leaf()
2703 err = -EAGAIN; in ext4_ext_rm_leaf()
2707 err = ext4_ext_get_access(handle, inode, path + depth); in ext4_ext_rm_leaf()
2719 ex->ee_len = cpu_to_le16(num); in ext4_ext_rm_leaf()
2731 if (end != EXT_MAX_BLOCKS - 1) { in ext4_ext_rm_leaf()
2737 memmove(ex, ex+1, (EXT_LAST_EXTENT(eh) - ex) * in ext4_ext_rm_leaf()
2744 le16_add_cpu(&eh->eh_entries, -1); in ext4_ext_rm_leaf()
2747 err = ext4_ext_dirty(handle, inode, path + depth); in ext4_ext_rm_leaf()
2753 ex--; in ext4_ext_rm_leaf()
2754 ex_ee_block = le32_to_cpu(ex->ee_block); in ext4_ext_rm_leaf()
2758 if (correct_index && eh->eh_entries) in ext4_ext_rm_leaf()
2768 if (partial->state == tofree && ex >= EXT_FIRST_EXTENT(eh)) { in ext4_ext_rm_leaf()
2769 pblk = ext4_ext_pblock(ex) + ex_ee_len - 1; in ext4_ext_rm_leaf()
2770 if (partial->pclu != EXT4_B2C(sbi, pblk)) { in ext4_ext_rm_leaf()
2773 if (ext4_is_pending(inode, partial->lblk)) in ext4_ext_rm_leaf()
2776 EXT4_C2B(sbi, partial->pclu), in ext4_ext_rm_leaf()
2777 sbi->s_cluster_ratio, flags); in ext4_ext_rm_leaf()
2779 ext4_rereserve_cluster(inode, partial->lblk); in ext4_ext_rm_leaf()
2781 partial->state = initial; in ext4_ext_rm_leaf()
2786 if (err == 0 && eh->eh_entries == 0 && path[depth].p_bh != NULL) in ext4_ext_rm_leaf()
2787 err = ext4_ext_rm_idx(handle, inode, path, depth); in ext4_ext_rm_leaf()
2800 BUG_ON(path->p_idx == NULL); in ext4_ext_more_to_rm()
2802 if (path->p_idx < EXT_FIRST_INDEX(path->p_hdr)) in ext4_ext_more_to_rm()
2809 if (le16_to_cpu(path->p_hdr->eh_entries) == path->p_block) in ext4_ext_more_to_rm()
2817 struct ext4_sb_info *sbi = EXT4_SB(inode->i_sb); in ext4_ext_remove_space()
2818 int depth = ext_depth(inode); in ext4_ext_remove_space() local
2832 depth + 1, in ext4_ext_remove_space()
2833 ext4_free_metadata_revoke_credits(inode->i_sb, depth)); in ext4_ext_remove_space()
2838 trace_ext4_ext_remove_space(inode, start, end, depth); in ext4_ext_remove_space()
2847 if (end < EXT_MAX_BLOCKS - 1) { in ext4_ext_remove_space()
2859 depth = ext_depth(inode); in ext4_ext_remove_space()
2861 ex = path[depth].p_ext; in ext4_ext_remove_space()
2863 if (depth) { in ext4_ext_remove_space()
2866 depth); in ext4_ext_remove_space()
2867 err = -EFSCORRUPTED; in ext4_ext_remove_space()
2872 ee_block = le32_to_cpu(ex->ee_block); in ext4_ext_remove_space()
2873 ex_end = ee_block + ext4_ext_get_actual_len(ex) - 1; in ext4_ext_remove_space()
2888 if (sbi->s_cluster_ratio > 1) { in ext4_ext_remove_space()
2889 pblk = ext4_ext_pblock(ex) + end - ee_block + 1; in ext4_ext_remove_space()
2905 } else if (sbi->s_cluster_ratio > 1 && end >= ex_end && in ext4_ext_remove_space()
2930 * after i_size and walking into the tree depth-wise. in ext4_ext_remove_space()
2932 depth = ext_depth(inode); in ext4_ext_remove_space()
2934 int k = i = depth; in ext4_ext_remove_space()
2935 while (--k > 0) in ext4_ext_remove_space()
2937 le16_to_cpu(path[k].p_hdr->eh_entries)+1; in ext4_ext_remove_space()
2939 path = kcalloc(depth + 1, sizeof(struct ext4_ext_path), in ext4_ext_remove_space()
2943 return -ENOMEM; in ext4_ext_remove_space()
2945 path[0].p_maxdepth = path[0].p_depth = depth; in ext4_ext_remove_space()
2949 if (ext4_ext_check(inode, path[0].p_hdr, depth, 0)) { in ext4_ext_remove_space()
2950 err = -EFSCORRUPTED; in ext4_ext_remove_space()
2957 if (i == depth) { in ext4_ext_remove_space()
2964 i--; in ext4_ext_remove_space()
2977 path[i].p_block = le16_to_cpu(path[i].p_hdr->eh_entries)+1; in ext4_ext_remove_space()
2980 le16_to_cpu(path[i].p_hdr->eh_entries)); in ext4_ext_remove_space()
2983 path[i].p_idx--; in ext4_ext_remove_space()
2986 ext_debug(inode, "level %d - index, first 0x%p, cur 0x%p\n", in ext4_ext_remove_space()
2996 depth - i - 1, in ext4_ext_remove_space()
3004 * Should be a no-op if we did IO above. */ in ext4_ext_remove_space()
3006 if (WARN_ON(i + 1 > depth)) { in ext4_ext_remove_space()
3007 err = -EFSCORRUPTED; in ext4_ext_remove_space()
3014 path[i].p_block = le16_to_cpu(path[i].p_hdr->eh_entries); in ext4_ext_remove_space()
3018 if (path[i].p_hdr->eh_entries == 0 && i > 0) { in ext4_ext_remove_space()
3027 i--; in ext4_ext_remove_space()
3032 trace_ext4_ext_remove_space_done(inode, start, end, depth, &partial, in ext4_ext_remove_space()
3033 path->p_hdr->eh_entries); in ext4_ext_remove_space()
3046 sbi->s_cluster_ratio, flags); in ext4_ext_remove_space()
3053 if (path->p_hdr->eh_entries == 0) { in ext4_ext_remove_space()
3060 ext_inode_hdr(inode)->eh_depth = 0; in ext4_ext_remove_space()
3061 ext_inode_hdr(inode)->eh_max = in ext4_ext_remove_space()
3069 if (err == -EAGAIN) in ext4_ext_remove_space()
3087 printk(KERN_INFO "EXT4-fs: file extents enabled" in ext4_ext_init()
3100 spin_lock_init(&EXT4_SB(sb)->s_ext_stats_lock); in ext4_ext_init()
3101 EXT4_SB(sb)->s_ext_min = 1 << 30; in ext4_ext_init()
3102 EXT4_SB(sb)->s_ext_max = 0; in ext4_ext_init()
3116 if (EXT4_SB(sb)->s_ext_blocks && EXT4_SB(sb)->s_ext_extents) { in ext4_ext_release()
3118 printk(KERN_ERR "EXT4-fs: %lu blocks in %lu extents (%lu ave)\n", in ext4_ext_release()
3119 sbi->s_ext_blocks, sbi->s_ext_extents, in ext4_ext_release()
3120 sbi->s_ext_blocks / sbi->s_ext_extents); in ext4_ext_release()
3121 printk(KERN_ERR "EXT4-fs: extents: %lu min, %lu max, max depth %lu\n", in ext4_ext_release()
3122 sbi->s_ext_min, sbi->s_ext_max, sbi->s_depth_max); in ext4_ext_release()
3133 ee_block = le32_to_cpu(ex->ee_block); in ext4_zeroout_es()
3144 /* FIXME!! we need to try to merge to left or right after zero-out */
3152 return ext4_issue_zeroout(inode, le32_to_cpu(ex->ee_block), ee_pblock, in ext4_ext_zeroout()
3189 unsigned int ee_len, depth; in ext4_split_extent_at() local
3199 depth = ext_depth(inode); in ext4_split_extent_at()
3200 ex = path[depth].p_ext; in ext4_split_extent_at()
3201 ee_block = le32_to_cpu(ex->ee_block); in ext4_split_extent_at()
3203 newblock = split - ee_block + ext4_ext_pblock(ex); in ext4_split_extent_at()
3211 err = ext4_ext_get_access(handle, inode, path + depth); in ext4_split_extent_at()
3229 err = ext4_ext_dirty(handle, inode, path + path->p_depth); in ext4_split_extent_at()
3235 ex->ee_len = cpu_to_le16(split - ee_block); in ext4_split_extent_at()
3243 err = ext4_ext_dirty(handle, inode, path + depth); in ext4_split_extent_at()
3248 ex2->ee_block = cpu_to_le32(split); in ext4_split_extent_at()
3249 ex2->ee_len = cpu_to_le16(ee_len - (split - ee_block)); in ext4_split_extent_at()
3255 if (err != -ENOSPC && err != -EDQUOT) in ext4_split_extent_at()
3262 zero_ex.ee_block = ex2->ee_block; in ext4_split_extent_at()
3269 zero_ex.ee_block = ex->ee_block; in ext4_split_extent_at()
3286 ex->ee_len = cpu_to_le16(ee_len); in ext4_split_extent_at()
3288 err = ext4_ext_dirty(handle, inode, path + path->p_depth); in ext4_split_extent_at()
3302 ex->ee_len = orig_ex.ee_len; in ext4_split_extent_at()
3305 * and err is a non-zero error code. in ext4_split_extent_at()
3307 ext4_ext_dirty(handle, inode, path + path->p_depth); in ext4_split_extent_at()
3335 unsigned int ee_len, depth; in ext4_split_extent() local
3339 int allocated = map->m_len; in ext4_split_extent()
3341 depth = ext_depth(inode); in ext4_split_extent()
3342 ex = path[depth].p_ext; in ext4_split_extent()
3343 ee_block = le32_to_cpu(ex->ee_block); in ext4_split_extent()
3347 if (map->m_lblk + map->m_len < ee_block + ee_len) { in ext4_split_extent()
3356 map->m_lblk + map->m_len, split_flag1, flags1); in ext4_split_extent()
3360 allocated = ee_len - (map->m_lblk - ee_block); in ext4_split_extent()
3366 path = ext4_find_extent(inode, map->m_lblk, ppath, flags); in ext4_split_extent()
3369 depth = ext_depth(inode); in ext4_split_extent()
3370 ex = path[depth].p_ext; in ext4_split_extent()
3373 (unsigned long) map->m_lblk); in ext4_split_extent()
3374 return -EFSCORRUPTED; in ext4_split_extent()
3378 if (map->m_lblk >= ee_block) { in ext4_split_extent()
3386 map->m_lblk, split_flag1, flags); in ext4_split_extent()
3399 * extent into multiple extents (up to three - one initialized and two
3406 * Pre-conditions:
3407 * - The extent pointed to by 'path' is unwritten.
3408 * - The extent pointed to by 'path' contains a superset
3409 * of the logical span [map->m_lblk, map->m_lblk + map->m_len).
3411 * Post-conditions on success:
3412 * - the returned value is the number of blocks beyond map->l_lblk
3414 * It is guaranteed to be >= map->m_len.
3429 unsigned int ee_len, depth, map_len = map->m_len; in ext4_ext_convert_to_initialized() local
3435 (unsigned long long)map->m_lblk, map_len); in ext4_ext_convert_to_initialized()
3437 sbi = EXT4_SB(inode->i_sb); in ext4_ext_convert_to_initialized()
3438 eof_block = (EXT4_I(inode)->i_disksize + inode->i_sb->s_blocksize - 1) in ext4_ext_convert_to_initialized()
3439 >> inode->i_sb->s_blocksize_bits; in ext4_ext_convert_to_initialized()
3440 if (eof_block < map->m_lblk + map_len) in ext4_ext_convert_to_initialized()
3441 eof_block = map->m_lblk + map_len; in ext4_ext_convert_to_initialized()
3443 depth = ext_depth(inode); in ext4_ext_convert_to_initialized()
3444 eh = path[depth].p_hdr; in ext4_ext_convert_to_initialized()
3445 ex = path[depth].p_ext; in ext4_ext_convert_to_initialized()
3446 ee_block = le32_to_cpu(ex->ee_block); in ext4_ext_convert_to_initialized()
3453 /* Pre-conditions */ in ext4_ext_convert_to_initialized()
3455 BUG_ON(!in_range(map->m_lblk, ee_block, ee_len)); in ext4_ext_convert_to_initialized()
3466 * - L1: we do not deal with writes covering the whole extent. in ext4_ext_convert_to_initialized()
3469 * - L2: we only attempt to merge with an extent stored in the in ext4_ext_convert_to_initialized()
3472 if ((map->m_lblk == ee_block) && in ext4_ext_convert_to_initialized()
3480 abut_ex = ex - 1; in ext4_ext_convert_to_initialized()
3481 prev_lblk = le32_to_cpu(abut_ex->ee_block); in ext4_ext_convert_to_initialized()
3489 * - C1: abut_ex is initialized, in ext4_ext_convert_to_initialized()
3490 * - C2: abut_ex is logically abutting ex, in ext4_ext_convert_to_initialized()
3491 * - C3: abut_ex is physically abutting ex, in ext4_ext_convert_to_initialized()
3492 * - C4: abut_ex can receive the additional blocks without in ext4_ext_convert_to_initialized()
3498 (prev_len < (EXT_INIT_MAX_LEN - map_len))) { /*C4*/ in ext4_ext_convert_to_initialized()
3499 err = ext4_ext_get_access(handle, inode, path + depth); in ext4_ext_convert_to_initialized()
3507 ex->ee_block = cpu_to_le32(ee_block + map_len); in ext4_ext_convert_to_initialized()
3509 ex->ee_len = cpu_to_le16(ee_len - map_len); in ext4_ext_convert_to_initialized()
3513 abut_ex->ee_len = cpu_to_le16(prev_len + map_len); in ext4_ext_convert_to_initialized()
3518 } else if (((map->m_lblk + map_len) == (ee_block + ee_len)) && in ext4_ext_convert_to_initialized()
3527 next_lblk = le32_to_cpu(abut_ex->ee_block); in ext4_ext_convert_to_initialized()
3535 * - C1: abut_ex is initialized, in ext4_ext_convert_to_initialized()
3536 * - C2: abut_ex is logically abutting ex, in ext4_ext_convert_to_initialized()
3537 * - C3: abut_ex is physically abutting ex, in ext4_ext_convert_to_initialized()
3538 * - C4: abut_ex can receive the additional blocks without in ext4_ext_convert_to_initialized()
3542 ((map->m_lblk + map_len) == next_lblk) && /*C2*/ in ext4_ext_convert_to_initialized()
3544 (next_len < (EXT_INIT_MAX_LEN - map_len))) { /*C4*/ in ext4_ext_convert_to_initialized()
3545 err = ext4_ext_get_access(handle, inode, path + depth); in ext4_ext_convert_to_initialized()
3553 abut_ex->ee_block = cpu_to_le32(next_lblk - map_len); in ext4_ext_convert_to_initialized()
3554 ext4_ext_store_pblock(abut_ex, next_pblk - map_len); in ext4_ext_convert_to_initialized()
3555 ex->ee_len = cpu_to_le16(ee_len - map_len); in ext4_ext_convert_to_initialized()
3559 abut_ex->ee_len = cpu_to_le16(next_len + map_len); in ext4_ext_convert_to_initialized()
3567 err = ext4_ext_dirty(handle, inode, path + depth); in ext4_ext_convert_to_initialized()
3570 path[depth].p_ext = abut_ex; in ext4_ext_convert_to_initialized()
3573 allocated = ee_len - (map->m_lblk - ee_block); in ext4_ext_convert_to_initialized()
3575 WARN_ON(map->m_lblk < ee_block); in ext4_ext_convert_to_initialized()
3583 max_zeroout = sbi->s_extent_max_zeroout_kb >> in ext4_ext_convert_to_initialized()
3584 (inode->i_sb->s_blocksize_bits - 10); in ext4_ext_convert_to_initialized()
3597 split_map.m_lblk = map->m_lblk; in ext4_ext_convert_to_initialized()
3598 split_map.m_len = map->m_len; in ext4_ext_convert_to_initialized()
3607 cpu_to_le16(allocated - split_map.m_len); in ext4_ext_convert_to_initialized()
3610 split_map.m_len - ee_block); in ext4_ext_convert_to_initialized()
3616 if (split_map.m_lblk - ee_block + split_map.m_len < in ext4_ext_convert_to_initialized()
3620 zero_ex2.ee_block = ex->ee_block; in ext4_ext_convert_to_initialized()
3621 zero_ex2.ee_len = cpu_to_le16(split_map.m_lblk - in ext4_ext_convert_to_initialized()
3630 split_map.m_len += split_map.m_lblk - ee_block; in ext4_ext_convert_to_initialized()
3632 allocated = map->m_len; in ext4_ext_convert_to_initialized()
3663 * This works the same way in the case of initialized -> unwritten conversion.
3686 int split_flag = 0, depth; in ext4_split_convert_extents() local
3689 (unsigned long long)map->m_lblk, map->m_len); in ext4_split_convert_extents()
3691 eof_block = (EXT4_I(inode)->i_disksize + inode->i_sb->s_blocksize - 1) in ext4_split_convert_extents()
3692 >> inode->i_sb->s_blocksize_bits; in ext4_split_convert_extents()
3693 if (eof_block < map->m_lblk + map->m_len) in ext4_split_convert_extents()
3694 eof_block = map->m_lblk + map->m_len; in ext4_split_convert_extents()
3699 depth = ext_depth(inode); in ext4_split_convert_extents()
3700 ex = path[depth].p_ext; in ext4_split_convert_extents()
3701 ee_block = le32_to_cpu(ex->ee_block); in ext4_split_convert_extents()
3726 int depth; in ext4_convert_unwritten_extents_endio() local
3729 depth = ext_depth(inode); in ext4_convert_unwritten_extents_endio()
3730 ex = path[depth].p_ext; in ext4_convert_unwritten_extents_endio()
3731 ee_block = le32_to_cpu(ex->ee_block); in ext4_convert_unwritten_extents_endio()
3743 if (ee_block != map->m_lblk || ee_len > map->m_len) { in ext4_convert_unwritten_extents_endio()
3745 ext4_warning(inode->i_sb, "Inode (%ld) finished: extent logical block %llu," in ext4_convert_unwritten_extents_endio()
3747 inode->i_ino, (unsigned long long)ee_block, ee_len, in ext4_convert_unwritten_extents_endio()
3748 (unsigned long long)map->m_lblk, map->m_len); in ext4_convert_unwritten_extents_endio()
3754 path = ext4_find_extent(inode, map->m_lblk, ppath, 0); in ext4_convert_unwritten_extents_endio()
3757 depth = ext_depth(inode); in ext4_convert_unwritten_extents_endio()
3758 ex = path[depth].p_ext; in ext4_convert_unwritten_extents_endio()
3761 err = ext4_ext_get_access(handle, inode, path + depth); in ext4_convert_unwritten_extents_endio()
3773 err = ext4_ext_dirty(handle, inode, path + path->p_depth); in ext4_convert_unwritten_extents_endio()
3789 int depth; in convert_initialized_extent() local
3796 if (map->m_len > EXT_UNWRITTEN_MAX_LEN) in convert_initialized_extent()
3797 map->m_len = EXT_UNWRITTEN_MAX_LEN / 2; in convert_initialized_extent()
3799 depth = ext_depth(inode); in convert_initialized_extent()
3800 ex = path[depth].p_ext; in convert_initialized_extent()
3801 ee_block = le32_to_cpu(ex->ee_block); in convert_initialized_extent()
3807 if (ee_block != map->m_lblk || ee_len > map->m_len) { in convert_initialized_extent()
3812 path = ext4_find_extent(inode, map->m_lblk, ppath, 0); in convert_initialized_extent()
3815 depth = ext_depth(inode); in convert_initialized_extent()
3816 ex = path[depth].p_ext; in convert_initialized_extent()
3819 (unsigned long) map->m_lblk); in convert_initialized_extent()
3820 return -EFSCORRUPTED; in convert_initialized_extent()
3824 err = ext4_ext_get_access(handle, inode, path + depth); in convert_initialized_extent()
3836 err = ext4_ext_dirty(handle, inode, path + path->p_depth); in convert_initialized_extent()
3843 map->m_flags |= EXT4_MAP_UNWRITTEN; in convert_initialized_extent()
3844 if (*allocated > map->m_len) in convert_initialized_extent()
3845 *allocated = map->m_len; in convert_initialized_extent()
3846 map->m_len = *allocated; in convert_initialized_extent()
3861 (unsigned long long)map->m_lblk, map->m_len, flags, in ext4_ext_handle_unwritten_extents()
3889 map->m_len); in ext4_ext_handle_unwritten_extents()
3890 err = -EFSCORRUPTED; in ext4_ext_handle_unwritten_extents()
3893 map->m_flags |= EXT4_MAP_UNWRITTEN; in ext4_ext_handle_unwritten_extents()
3911 map->m_flags |= EXT4_MAP_UNWRITTEN; in ext4_ext_handle_unwritten_extents()
3924 map->m_flags |= EXT4_MAP_UNWRITTEN; in ext4_ext_handle_unwritten_extents()
3945 map->m_len); in ext4_ext_handle_unwritten_extents()
3946 err = -EFSCORRUPTED; in ext4_ext_handle_unwritten_extents()
3952 map->m_flags |= EXT4_MAP_NEW; in ext4_ext_handle_unwritten_extents()
3954 map->m_flags |= EXT4_MAP_MAPPED; in ext4_ext_handle_unwritten_extents()
3956 map->m_pblk = newblock; in ext4_ext_handle_unwritten_extents()
3957 if (allocated > map->m_len) in ext4_ext_handle_unwritten_extents()
3958 allocated = map->m_len; in ext4_ext_handle_unwritten_extents()
3959 map->m_len = allocated; in ext4_ext_handle_unwritten_extents()
3966 * get_implied_cluster_alloc - check to see if the requested
3970 * @map The requested lblk->pblk mapping
3980 * |--- cluster # N--|
3981 * |--- extent ---| |---- requested region ---|
3986 * |--------- cluster # N ----------------|
3987 * |--- requested region --| |------- extent ----|
3992 * |------------- cluster # N-------------|
3993 * |----- ex -----| |---- ex_right ----|
3994 * |------ requested region ------|
3997 * In each of the above cases, we need to set the map->m_pblk and
3998 * map->m_len so it corresponds to the return the extent labelled as
4000 * cluster EXT4_B2C(sbi, map->m_lblk). We will then return 1 to
4001 * signal to ext4_ext_map_blocks() that map->m_pblk should be treated
4012 ext4_lblk_t c_offset = EXT4_LBLK_COFF(sbi, map->m_lblk); in get_implied_cluster_alloc()
4015 ext4_lblk_t ee_block = le32_to_cpu(ex->ee_block); in get_implied_cluster_alloc()
4021 ex_cluster_end = EXT4_B2C(sbi, ee_block + ee_len - 1); in get_implied_cluster_alloc()
4024 rr_cluster_start = EXT4_B2C(sbi, map->m_lblk); in get_implied_cluster_alloc()
4029 ee_start += ee_len - 1; in get_implied_cluster_alloc()
4030 map->m_pblk = EXT4_PBLK_CMASK(sbi, ee_start) + c_offset; in get_implied_cluster_alloc()
4031 map->m_len = min(map->m_len, in get_implied_cluster_alloc()
4032 (unsigned) sbi->s_cluster_ratio - c_offset); in get_implied_cluster_alloc()
4036 * |--------- cluster # N-------------| in get_implied_cluster_alloc()
4037 * |------- extent ----| in get_implied_cluster_alloc()
4038 * |--- requested region ---| in get_implied_cluster_alloc()
4042 if (map->m_lblk < ee_block) in get_implied_cluster_alloc()
4043 map->m_len = min(map->m_len, ee_block - map->m_lblk); in get_implied_cluster_alloc()
4049 * |------------- cluster # N-------------| in get_implied_cluster_alloc()
4050 * |----- ex -----| |---- ex_right ----| in get_implied_cluster_alloc()
4051 * |------ requested region ------| in get_implied_cluster_alloc()
4054 if (map->m_lblk > ee_block) { in get_implied_cluster_alloc()
4056 map->m_len = min(map->m_len, next - map->m_lblk); in get_implied_cluster_alloc()
4073 * down_read(&EXT4_I(inode)->i_data_sem) if not allocating file system block
4074 * (ie, create is zero). Otherwise down_write(&EXT4_I(inode)->i_data_sem)
4077 * if create == 0 and these are pre-allocated blocks
4091 struct ext4_sb_info *sbi = EXT4_SB(inode->i_sb); in ext4_ext_map_blocks()
4093 int err = 0, depth, ret; in ext4_ext_map_blocks() local
4099 ext_debug(inode, "blocks %u/%u requested\n", map->m_lblk, map->m_len); in ext4_ext_map_blocks()
4100 trace_ext4_ext_map_blocks_enter(inode, map->m_lblk, map->m_len, flags); in ext4_ext_map_blocks()
4103 path = ext4_find_extent(inode, map->m_lblk, NULL, 0); in ext4_ext_map_blocks()
4110 depth = ext_depth(inode); in ext4_ext_map_blocks()
4117 if (unlikely(path[depth].p_ext == NULL && depth != 0)) { in ext4_ext_map_blocks()
4119 "lblock: %lu, depth: %d pblock %lld", in ext4_ext_map_blocks()
4120 (unsigned long) map->m_lblk, depth, in ext4_ext_map_blocks()
4121 path[depth].p_block); in ext4_ext_map_blocks()
4122 err = -EFSCORRUPTED; in ext4_ext_map_blocks()
4126 ex = path[depth].p_ext; in ext4_ext_map_blocks()
4128 ext4_lblk_t ee_block = le32_to_cpu(ex->ee_block); in ext4_ext_map_blocks()
4142 if (in_range(map->m_lblk, ee_block, ee_len)) { in ext4_ext_map_blocks()
4143 newblock = map->m_lblk - ee_block + ee_start; in ext4_ext_map_blocks()
4145 allocated = ee_len - (map->m_lblk - ee_block); in ext4_ext_map_blocks()
4146 ext_debug(inode, "%u fit into %u:%d -> %llu\n", in ext4_ext_map_blocks()
4147 map->m_lblk, ee_block, ee_len, newblock); in ext4_ext_map_blocks()
4159 map->m_flags |= EXT4_MAP_MAPPED; in ext4_ext_map_blocks()
4160 map->m_pblk = newblock; in ext4_ext_map_blocks()
4161 if (allocated > map->m_len) in ext4_ext_map_blocks()
4162 allocated = map->m_len; in ext4_ext_map_blocks()
4163 map->m_len = allocated; in ext4_ext_map_blocks()
4186 hole_start = map->m_lblk; in ext4_ext_map_blocks()
4194 /* Update hole_len to reflect hole size after map->m_lblk */ in ext4_ext_map_blocks()
4195 if (hole_start != map->m_lblk) in ext4_ext_map_blocks()
4196 hole_len -= map->m_lblk - hole_start; in ext4_ext_map_blocks()
4197 map->m_pblk = 0; in ext4_ext_map_blocks()
4198 map->m_len = min_t(unsigned int, map->m_len, hole_len); in ext4_ext_map_blocks()
4206 newex.ee_block = cpu_to_le32(map->m_lblk); in ext4_ext_map_blocks()
4207 cluster_offset = EXT4_LBLK_COFF(sbi, map->m_lblk); in ext4_ext_map_blocks()
4214 get_implied_cluster_alloc(inode->i_sb, map, ex, path)) { in ext4_ext_map_blocks()
4215 ar.len = allocated = map->m_len; in ext4_ext_map_blocks()
4216 newblock = map->m_pblk; in ext4_ext_map_blocks()
4221 ar.lleft = map->m_lblk; in ext4_ext_map_blocks()
4225 ar.lright = map->m_lblk; in ext4_ext_map_blocks()
4232 if ((sbi->s_cluster_ratio > 1) && err && in ext4_ext_map_blocks()
4233 get_implied_cluster_alloc(inode->i_sb, map, &ex2, path)) { in ext4_ext_map_blocks()
4234 ar.len = allocated = map->m_len; in ext4_ext_map_blocks()
4235 newblock = map->m_pblk; in ext4_ext_map_blocks()
4245 if (map->m_len > EXT_INIT_MAX_LEN && in ext4_ext_map_blocks()
4247 map->m_len = EXT_INIT_MAX_LEN; in ext4_ext_map_blocks()
4248 else if (map->m_len > EXT_UNWRITTEN_MAX_LEN && in ext4_ext_map_blocks()
4250 map->m_len = EXT_UNWRITTEN_MAX_LEN; in ext4_ext_map_blocks()
4253 newex.ee_len = cpu_to_le16(map->m_len); in ext4_ext_map_blocks()
4258 allocated = map->m_len; in ext4_ext_map_blocks()
4262 ar.goal = ext4_ext_find_goal(inode, path, map->m_lblk); in ext4_ext_map_blocks()
4263 ar.logical = map->m_lblk; in ext4_ext_map_blocks()
4272 offset = EXT4_LBLK_COFF(sbi, map->m_lblk); in ext4_ext_map_blocks()
4274 ar.goal -= offset; in ext4_ext_map_blocks()
4275 ar.logical -= offset; in ext4_ext_map_blocks()
4276 if (S_ISREG(inode->i_mode)) in ext4_ext_map_blocks()
4279 /* disable in-core preallocation for non-regular files */ in ext4_ext_map_blocks()
4291 ar.len = EXT4_C2B(sbi, ar.len) - offset; in ext4_ext_map_blocks()
4305 map->m_flags |= EXT4_MAP_UNWRITTEN; in ext4_ext_map_blocks()
4334 if (test_opt(inode->i_sb, DELALLOC) && allocated_clusters) { in ext4_ext_map_blocks()
4347 * When allocating non-delayed allocated clusters in ext4_ext_map_blocks()
4357 lblk = EXT4_LBLK_CMASK(sbi, map->m_lblk); in ext4_ext_map_blocks()
4358 len = allocated_clusters << sbi->s_cluster_bits; in ext4_ext_map_blocks()
4374 map->m_flags |= (EXT4_MAP_NEW | EXT4_MAP_MAPPED); in ext4_ext_map_blocks()
4375 map->m_pblk = pblk; in ext4_ext_map_blocks()
4376 map->m_len = ar.len; in ext4_ext_map_blocks()
4377 allocated = map->m_len; in ext4_ext_map_blocks()
4389 struct super_block *sb = inode->i_sb; in ext4_ext_truncate()
4400 EXT4_I(inode)->i_disksize = inode->i_size; in ext4_ext_truncate()
4405 last_block = (inode->i_size + sb->s_blocksize - 1) in ext4_ext_truncate()
4409 EXT_MAX_BLOCKS - last_block); in ext4_ext_truncate()
4410 if (err == -ENOMEM) { in ext4_ext_truncate()
4417 err = ext4_ext_remove_space(inode, last_block, EXT_MAX_BLOCKS - 1); in ext4_ext_truncate()
4418 if (err == -ENOMEM) { in ext4_ext_truncate()
4433 int depth = 0; in ext4_alloc_file_blocks() local
4453 depth = ext_depth(inode); in ext4_alloc_file_blocks()
4458 * Recalculate credits when extent tree depth changes. in ext4_alloc_file_blocks()
4460 if (depth != ext_depth(inode)) { in ext4_alloc_file_blocks()
4462 depth = ext_depth(inode); in ext4_alloc_file_blocks()
4475 inode->i_ino, map.m_lblk, in ext4_alloc_file_blocks()
4486 map.m_len = len = len - ret; in ext4_alloc_file_blocks()
4487 epos = (loff_t)map.m_lblk << inode->i_blkbits; in ext4_alloc_file_blocks()
4488 inode->i_ctime = current_time(inode); in ext4_alloc_file_blocks()
4493 inode->i_mtime = inode->i_ctime; in ext4_alloc_file_blocks()
4502 if (ret == -ENOSPC && ext4_should_retry_alloc(inode->i_sb, &retries)) in ext4_alloc_file_blocks()
4516 struct address_space *mapping = file->f_mapping; in ext4_zero_range()
4526 unsigned int blkbits = inode->i_blkbits; in ext4_zero_range()
4532 ret = ext4_force_commit(inode->i_sb); in ext4_zero_range()
4547 return -EINVAL; in ext4_zero_range()
4548 partial_begin = offset & ((1 << blkbits) - 1); in ext4_zero_range()
4549 partial_end = (offset + len) & ((1 << blkbits) - 1); in ext4_zero_range()
4556 max_blocks -= lblk; in ext4_zero_range()
4564 ret = -EOPNOTSUPP; in ext4_zero_range()
4569 (offset + len > inode->i_size || in ext4_zero_range()
4570 offset + len > EXT4_I(inode)->i_disksize)) { in ext4_zero_range()
4590 (round_up((offset + len), 1 << blkbits) - in ext4_zero_range()
4621 truncate_pagecache_range(inode, start, end - 1); in ext4_zero_range()
4622 inode->i_mtime = inode->i_ctime = current_time(inode); in ext4_zero_range()
4643 ext4_std_error(inode->i_sb, ret); in ext4_zero_range()
4647 inode->i_mtime = inode->i_ctime = current_time(inode); in ext4_zero_range()
4658 if (file->f_flags & O_SYNC) in ext4_zero_range()
4671 * For block-mapped files, posix_fallocate should fall back to the method
4683 unsigned int blkbits = inode->i_blkbits; in ext4_fallocate()
4687 * range since we would need to re-encrypt blocks with a in ext4_fallocate()
4693 return -EOPNOTSUPP; in ext4_fallocate()
4699 return -EOPNOTSUPP; in ext4_fallocate()
4735 * We only support preallocation for extent-based files only in ext4_fallocate()
4738 ret = -EOPNOTSUPP; in ext4_fallocate()
4743 (offset + len > inode->i_size || in ext4_fallocate()
4744 offset + len > EXT4_I(inode)->i_disksize)) { in ext4_fallocate()
4762 if (file->f_flags & O_SYNC && EXT4_SB(inode->i_sb)->s_journal) { in ext4_fallocate()
4763 ret = ext4_fc_commit(EXT4_SB(inode->i_sb)->s_journal, in ext4_fallocate()
4764 EXT4_I(inode)->i_sync_tid); in ext4_fallocate()
4789 unsigned int blkbits = inode->i_blkbits; in ext4_convert_unwritten_extents()
4803 map.m_len = (max_blocks -= ret); in ext4_convert_unwritten_extents()
4815 ext4_warning(inode->i_sb, in ext4_convert_unwritten_extents()
4818 inode->i_ino, map.m_lblk, in ext4_convert_unwritten_extents()
4850 list_for_each_entry(io_end_vec, &io_end->list_vec, list) { in ext4_convert_unwritten_io_end_vec()
4851 ret = ext4_convert_unwritten_extents(handle, io_end->inode, in ext4_convert_unwritten_io_end_vec()
4852 io_end_vec->offset, in ext4_convert_unwritten_io_end_vec()
4853 io_end_vec->size); in ext4_convert_unwritten_io_end_vec()
4868 int blockbits = inode->i_sb->s_blocksize_bits; in ext4_iomap_xattr_fiemap()
4872 /* in-inode? */ in ext4_iomap_xattr_fiemap()
4880 physical = (__u64)iloc.bh->b_blocknr << blockbits; in ext4_iomap_xattr_fiemap()
4882 EXT4_I(inode)->i_extra_isize; in ext4_iomap_xattr_fiemap()
4884 length = EXT4_SB(inode->i_sb)->s_inode_size - offset; in ext4_iomap_xattr_fiemap()
4887 } else if (EXT4_I(inode)->i_file_acl) { /* external block */ in ext4_iomap_xattr_fiemap()
4888 physical = (__u64)EXT4_I(inode)->i_file_acl << blockbits; in ext4_iomap_xattr_fiemap()
4889 length = inode->i_sb->s_blocksize; in ext4_iomap_xattr_fiemap()
4892 /* no in-inode or external block for xattr, so return -ENOENT */ in ext4_iomap_xattr_fiemap()
4893 error = -ENOENT; in ext4_iomap_xattr_fiemap()
4897 iomap->addr = physical; in ext4_iomap_xattr_fiemap()
4898 iomap->offset = 0; in ext4_iomap_xattr_fiemap()
4899 iomap->length = length; in ext4_iomap_xattr_fiemap()
4900 iomap->type = iomap_type; in ext4_iomap_xattr_fiemap()
4901 iomap->flags = 0; in ext4_iomap_xattr_fiemap()
4913 if (error == 0 && (offset >= iomap->length)) in ext4_iomap_xattr_begin()
4914 error = -ENOENT; in ext4_iomap_xattr_begin()
4927 maxbytes = inode->i_sb->s_maxbytes; in ext4_fiemap_check_ranges()
4929 maxbytes = EXT4_SB(inode->i_sb)->s_bitmap_maxbytes; in ext4_fiemap_check_ranges()
4932 return -EINVAL; in ext4_fiemap_check_ranges()
4934 return -EFBIG; in ext4_fiemap_check_ranges()
4939 if (*len > maxbytes || (maxbytes - *len) < start) in ext4_fiemap_check_ranges()
4940 *len = maxbytes - start; in ext4_fiemap_check_ranges()
4949 if (fieinfo->fi_flags & FIEMAP_FLAG_CACHE) { in ext4_fiemap()
4953 fieinfo->fi_flags &= ~FIEMAP_FLAG_CACHE; in ext4_fiemap()
4965 if (fieinfo->fi_flags & FIEMAP_FLAG_XATTR) { in ext4_fiemap()
4966 fieinfo->fi_flags &= ~FIEMAP_FLAG_XATTR; in ext4_fiemap()
4984 down_read(&EXT4_I(inode)->xattr_sem); in ext4_get_es_cache()
4986 up_read(&EXT4_I(inode)->xattr_sem); in ext4_get_es_cache()
4991 if (fieinfo->fi_flags & FIEMAP_FLAG_CACHE) { in ext4_get_es_cache()
4995 fieinfo->fi_flags &= ~FIEMAP_FLAG_CACHE; in ext4_get_es_cache()
5006 start_blk = start >> inode->i_sb->s_blocksize_bits; in ext4_get_es_cache()
5007 last_blk = (start + len - 1) >> inode->i_sb->s_blocksize_bits; in ext4_get_es_cache()
5009 last_blk = EXT_MAX_BLOCKS-1; in ext4_get_es_cache()
5010 len_blks = ((ext4_lblk_t) last_blk) - start_blk + 1; in ext4_get_es_cache()
5021 * Shift the extents of a path structure lying between path[depth].p_ext
5022 * and EXT_LAST_EXTENT(path[depth].p_hdr), by @shift blocks. @SHIFT tells
5030 int depth, err = 0; in ext4_ext_shift_path_extents() local
5034 depth = path->p_depth; in ext4_ext_shift_path_extents()
5036 while (depth >= 0) { in ext4_ext_shift_path_extents()
5037 if (depth == path->p_depth) { in ext4_ext_shift_path_extents()
5038 ex_start = path[depth].p_ext; in ext4_ext_shift_path_extents()
5040 return -EFSCORRUPTED; in ext4_ext_shift_path_extents()
5042 ex_last = EXT_LAST_EXTENT(path[depth].p_hdr); in ext4_ext_shift_path_extents()
5045 if (ex_start == EXT_FIRST_EXTENT(path[depth].p_hdr)) { in ext4_ext_shift_path_extents()
5048 credits = depth + 2; in ext4_ext_shift_path_extents()
5056 err = -EAGAIN; in ext4_ext_shift_path_extents()
5060 err = ext4_ext_get_access(handle, inode, path + depth); in ext4_ext_shift_path_extents()
5066 le32_add_cpu(&ex_start->ee_block, in ext4_ext_shift_path_extents()
5067 -shift); in ext4_ext_shift_path_extents()
5070 EXT_FIRST_EXTENT(path[depth].p_hdr)) in ext4_ext_shift_path_extents()
5073 path, ex_start - 1)) in ext4_ext_shift_path_extents()
5074 ex_last--; in ext4_ext_shift_path_extents()
5078 le32_add_cpu(&ex_last->ee_block, shift); in ext4_ext_shift_path_extents()
5081 ex_last--; in ext4_ext_shift_path_extents()
5084 err = ext4_ext_dirty(handle, inode, path + depth); in ext4_ext_shift_path_extents()
5088 if (--depth < 0 || !update) in ext4_ext_shift_path_extents()
5093 err = ext4_ext_get_access(handle, inode, path + depth); in ext4_ext_shift_path_extents()
5098 le32_add_cpu(&path[depth].p_idx->ei_block, -shift); in ext4_ext_shift_path_extents()
5100 le32_add_cpu(&path[depth].p_idx->ei_block, shift); in ext4_ext_shift_path_extents()
5101 err = ext4_ext_dirty(handle, inode, path + depth); in ext4_ext_shift_path_extents()
5106 if (path[depth].p_idx != EXT_FIRST_INDEX(path[depth].p_hdr)) in ext4_ext_shift_path_extents()
5109 depth--; in ext4_ext_shift_path_extents()
5129 int ret = 0, depth; in ext4_ext_shift_extents() local
5135 path = ext4_find_extent(inode, EXT_MAX_BLOCKS - 1, NULL, in ext4_ext_shift_extents()
5140 depth = path->p_depth; in ext4_ext_shift_extents()
5141 extent = path[depth].p_ext; in ext4_ext_shift_extents()
5145 stop = le32_to_cpu(extent->ee_block); in ext4_ext_shift_extents()
5153 path = ext4_find_extent(inode, start - 1, &path, in ext4_ext_shift_extents()
5157 depth = path->p_depth; in ext4_ext_shift_extents()
5158 extent = path[depth].p_ext; in ext4_ext_shift_extents()
5160 ex_start = le32_to_cpu(extent->ee_block); in ext4_ext_shift_extents()
5161 ex_end = le32_to_cpu(extent->ee_block) + in ext4_ext_shift_extents()
5169 (shift > start - ex_end)) { in ext4_ext_shift_extents()
5170 ret = -EINVAL; in ext4_ext_shift_extents()
5174 if (shift > EXT_MAX_BLOCKS - in ext4_ext_shift_extents()
5176 ret = -EINVAL; in ext4_ext_shift_extents()
5206 depth = path->p_depth; in ext4_ext_shift_extents()
5207 extent = path[depth].p_ext; in ext4_ext_shift_extents()
5211 return -EFSCORRUPTED; in ext4_ext_shift_extents()
5214 le32_to_cpu(extent->ee_block)) { in ext4_ext_shift_extents()
5216 if (extent < EXT_LAST_EXTENT(path[depth].p_hdr)) { in ext4_ext_shift_extents()
5217 path[depth].p_ext++; in ext4_ext_shift_extents()
5226 extent = EXT_LAST_EXTENT(path[depth].p_hdr); in ext4_ext_shift_extents()
5227 *iterator = le32_to_cpu(extent->ee_block) + in ext4_ext_shift_extents()
5230 extent = EXT_FIRST_EXTENT(path[depth].p_hdr); in ext4_ext_shift_extents()
5231 if (le32_to_cpu(extent->ee_block) > start) in ext4_ext_shift_extents()
5232 *iterator = le32_to_cpu(extent->ee_block) - 1; in ext4_ext_shift_extents()
5233 else if (le32_to_cpu(extent->ee_block) == start) in ext4_ext_shift_extents()
5236 extent = EXT_LAST_EXTENT(path[depth].p_hdr); in ext4_ext_shift_extents()
5237 while (le32_to_cpu(extent->ee_block) >= start) in ext4_ext_shift_extents()
5238 extent--; in ext4_ext_shift_extents()
5240 if (extent == EXT_LAST_EXTENT(path[depth].p_hdr)) in ext4_ext_shift_extents()
5246 path[depth].p_ext = extent; in ext4_ext_shift_extents()
5251 if (ret == -EAGAIN) in ext4_ext_shift_extents()
5264 * Returns: 0 and non-zero on error.
5269 struct super_block *sb = inode->i_sb; in ext4_collapse_range()
5270 struct address_space *mapping = inode->i_mapping; in ext4_collapse_range()
5283 return -EOPNOTSUPP; in ext4_collapse_range()
5287 return -EINVAL; in ext4_collapse_range()
5296 ret = ext4_force_commit(inode->i_sb); in ext4_collapse_range()
5306 if (offset + len >= inode->i_size) { in ext4_collapse_range()
5307 ret = -EINVAL; in ext4_collapse_range()
5313 ret = -EOPNOTSUPP; in ext4_collapse_range()
5365 down_write(&EXT4_I(inode)->i_data_sem); in ext4_collapse_range()
5369 EXT_MAX_BLOCKS - punch_start); in ext4_collapse_range()
5371 up_write(&EXT4_I(inode)->i_data_sem); in ext4_collapse_range()
5375 ret = ext4_ext_remove_space(inode, punch_start, punch_stop - 1); in ext4_collapse_range()
5377 up_write(&EXT4_I(inode)->i_data_sem); in ext4_collapse_range()
5383 punch_stop - punch_start, SHIFT_LEFT); in ext4_collapse_range()
5385 up_write(&EXT4_I(inode)->i_data_sem); in ext4_collapse_range()
5389 new_size = inode->i_size - len; in ext4_collapse_range()
5391 EXT4_I(inode)->i_disksize = new_size; in ext4_collapse_range()
5393 up_write(&EXT4_I(inode)->i_data_sem); in ext4_collapse_range()
5396 inode->i_mtime = inode->i_ctime = current_time(inode); in ext4_collapse_range()
5420 struct super_block *sb = inode->i_sb; in ext4_insert_range()
5421 struct address_space *mapping = inode->i_mapping; in ext4_insert_range()
5427 int ret = 0, depth, split_flag = 0; in ext4_insert_range() local
5436 return -EOPNOTSUPP; in ext4_insert_range()
5440 return -EINVAL; in ext4_insert_range()
5449 ret = ext4_force_commit(inode->i_sb); in ext4_insert_range()
5457 ret = -EOPNOTSUPP; in ext4_insert_range()
5462 if (len > inode->i_sb->s_maxbytes - inode->i_size) { in ext4_insert_range()
5463 ret = -EFBIG; in ext4_insert_range()
5468 if (offset >= inode->i_size) { in ext4_insert_range()
5469 ret = -EINVAL; in ext4_insert_range()
5496 ret = filemap_write_and_wait_range(inode->i_mapping, ioffset, in ext4_insert_range()
5511 inode->i_size += len; in ext4_insert_range()
5512 EXT4_I(inode)->i_disksize += len; in ext4_insert_range()
5513 inode->i_mtime = inode->i_ctime = current_time(inode); in ext4_insert_range()
5518 down_write(&EXT4_I(inode)->i_data_sem); in ext4_insert_range()
5523 up_write(&EXT4_I(inode)->i_data_sem); in ext4_insert_range()
5527 depth = ext_depth(inode); in ext4_insert_range()
5528 extent = path[depth].p_ext; in ext4_insert_range()
5530 ee_start_lblk = le32_to_cpu(extent->ee_block); in ext4_insert_range()
5551 up_write(&EXT4_I(inode)->i_data_sem); in ext4_insert_range()
5559 EXT_MAX_BLOCKS - offset_lblk); in ext4_insert_range()
5561 up_write(&EXT4_I(inode)->i_data_sem); in ext4_insert_range()
5573 up_write(&EXT4_I(inode)->i_data_sem); in ext4_insert_range()
5589 * ext4_swap_extents() - Swap extents between two inodes
5600 * stuff such as page-cache locking consistency, bh mapping consistency or
5617 BUG_ON(!rwsem_is_locked(&EXT4_I(inode1)->i_data_sem)); in ext4_swap_extents()
5618 BUG_ON(!rwsem_is_locked(&EXT4_I(inode2)->i_data_sem)); in ext4_swap_extents()
5649 ex1 = path1[path1->p_depth].p_ext; in ext4_swap_extents()
5650 ex2 = path2[path2->p_depth].p_ext; in ext4_swap_extents()
5655 e1_blk = le32_to_cpu(ex1->ee_block); in ext4_swap_extents()
5656 e2_blk = le32_to_cpu(ex2->ee_block); in ext4_swap_extents()
5677 len = next1 - lblk1; in ext4_swap_extents()
5678 if (len < next2 - lblk2) in ext4_swap_extents()
5679 len = next2 - lblk2; in ext4_swap_extents()
5684 count -= len; in ext4_swap_extents()
5710 if (len > e1_blk + e1_len - lblk1) in ext4_swap_extents()
5711 len = e1_blk + e1_len - lblk1; in ext4_swap_extents()
5712 if (len > e2_blk + e2_len - lblk2) in ext4_swap_extents()
5713 len = e2_blk + e2_len - lblk2; in ext4_swap_extents()
5735 *erp = ext4_ext_get_access(handle, inode1, path1 + path1->p_depth); in ext4_swap_extents()
5738 *erp = ext4_ext_get_access(handle, inode2, path2 + path2->p_depth); in ext4_swap_extents()
5746 ex1->ee_len = cpu_to_le16(e2_len); in ext4_swap_extents()
5747 ex2->ee_len = cpu_to_le16(e1_len); in ext4_swap_extents()
5756 path2->p_depth); in ext4_swap_extents()
5760 path1->p_depth); in ext4_swap_extents()
5772 count -= len; in ext4_swap_extents()
5783 * ext4_clu_mapped - determine whether any block in a logical cluster has
5786 * @inode - file containing the logical cluster
5787 * @lclu - logical cluster of interest
5796 struct ext4_sb_info *sbi = EXT4_SB(inode->i_sb); in ext4_clu_mapped()
5798 int depth, mapped = 0, err = 0; in ext4_clu_mapped() local
5810 depth = ext_depth(inode); in ext4_clu_mapped()
5817 if (unlikely(path[depth].p_ext == NULL && depth != 0)) { in ext4_clu_mapped()
5819 "bad extent address - lblock: %lu, depth: %d, pblock: %lld", in ext4_clu_mapped()
5821 depth, path[depth].p_block); in ext4_clu_mapped()
5822 err = -EFSCORRUPTED; in ext4_clu_mapped()
5826 extent = path[depth].p_ext; in ext4_clu_mapped()
5832 first_lblk = le32_to_cpu(extent->ee_block); in ext4_clu_mapped()
5836 * Three possible outcomes at this point - found extent spanning in ext4_clu_mapped()
5843 ext4_ext_get_actual_len(extent) - 1); in ext4_clu_mapped()
5877 ex = path[path->p_depth].p_ext; in ext4_ext_replay_update_ex()
5879 ret = -EFSCORRUPTED; in ext4_ext_replay_update_ex()
5883 if (le32_to_cpu(ex->ee_block) != start || in ext4_ext_replay_update_ex()
5887 down_write(&EXT4_I(inode)->i_data_sem); in ext4_ext_replay_update_ex()
5889 up_write(&EXT4_I(inode)->i_data_sem); in ext4_ext_replay_update_ex()
5895 return -1; in ext4_ext_replay_update_ex()
5897 ex = path[path->p_depth].p_ext; in ext4_ext_replay_update_ex()
5898 WARN_ON(le32_to_cpu(ex->ee_block) != start); in ext4_ext_replay_update_ex()
5900 down_write(&EXT4_I(inode)->i_data_sem); in ext4_ext_replay_update_ex()
5903 up_write(&EXT4_I(inode)->i_data_sem); in ext4_ext_replay_update_ex()
5909 return -EINVAL; in ext4_ext_replay_update_ex()
5910 ex = path[path->p_depth].p_ext; in ext4_ext_replay_update_ex()
5918 down_write(&EXT4_I(inode)->i_data_sem); in ext4_ext_replay_update_ex()
5919 ret = ext4_ext_dirty(NULL, inode, &path[path->p_depth]); in ext4_ext_replay_update_ex()
5920 up_write(&EXT4_I(inode)->i_data_sem); in ext4_ext_replay_update_ex()
5938 ex = path[path->p_depth].p_ext; in ext4_ext_replay_shrink_inode()
5945 cur = le32_to_cpu(ex->ee_block) + ext4_ext_get_actual_len(ex); in ext4_ext_replay_shrink_inode()
5949 down_write(&EXT4_I(inode)->i_data_sem); in ext4_ext_replay_shrink_inode()
5950 ext4_ext_dirty(NULL, inode, &path[path->p_depth]); in ext4_ext_replay_shrink_inode()
5951 up_write(&EXT4_I(inode)->i_data_sem); in ext4_ext_replay_shrink_inode()
5964 map.m_len = ((inode->i_size) >> inode->i_sb->s_blocksize_bits) - *cur; in skip_hole()
5986 path = ext4_find_extent(inode, EXT_MAX_BLOCKS - 1, NULL, in ext4_ext_replay_set_iblocks()
5990 ex = path[path->p_depth].p_ext; in ext4_ext_replay_set_iblocks()
5995 end = le32_to_cpu(ex->ee_block) + ext4_ext_get_actual_len(ex); in ext4_ext_replay_set_iblocks()
6002 map.m_len = end - cur; in ext4_ext_replay_set_iblocks()
6025 numblks += path->p_depth; in ext4_ext_replay_set_iblocks()
6031 ex = path[path->p_depth].p_ext; in ext4_ext_replay_set_iblocks()
6036 cur = max(cur + 1, le32_to_cpu(ex->ee_block) + in ext4_ext_replay_set_iblocks()
6048 for (i = 0; i <= max(path->p_depth, path2->p_depth); i++) { in ext4_ext_replay_set_iblocks()
6050 if (i <= path->p_depth) in ext4_ext_replay_set_iblocks()
6052 path[i].p_bh->b_blocknr : 0; in ext4_ext_replay_set_iblocks()
6053 if (i <= path2->p_depth) in ext4_ext_replay_set_iblocks()
6055 path2[i].p_bh->b_blocknr : 0; in ext4_ext_replay_set_iblocks()
6064 inode->i_blocks = numblks << (inode->i_sb->s_blocksize_bits - 9); in ext4_ext_replay_set_iblocks()
6081 path = ext4_find_extent(inode, EXT_MAX_BLOCKS - 1, NULL, in ext4_ext_clear_bb()
6085 ex = path[path->p_depth].p_ext; in ext4_ext_clear_bb()
6090 end = le32_to_cpu(ex->ee_block) + ext4_ext_get_actual_len(ex); in ext4_ext_clear_bb()
6096 map.m_len = end - cur; in ext4_ext_clear_bb()
6103 for (j = 0; j < path->p_depth; j++) { in ext4_ext_clear_bb()
6105 ext4_mb_mark_bb(inode->i_sb, in ext4_ext_clear_bb()
6107 ext4_fc_record_regions(inode->i_sb, inode->i_ino, in ext4_ext_clear_bb()
6112 ext4_mb_mark_bb(inode->i_sb, map.m_pblk, map.m_len, 0); in ext4_ext_clear_bb()
6113 ext4_fc_record_regions(inode->i_sb, inode->i_ino, in ext4_ext_clear_bb()