extents.c (725d26d3f09ccb5bac4b4293096b985a312a0d67) | extents.c (bba907433b85ba2adae1bb3b6fd29b4e5f35c468) |
---|---|
1/* 2 * Copyright (c) 2003-2006, Cluster File Systems, Inc, info@clusterfs.com 3 * Written by Alex Tomas <alex@clusterfs.com> 4 * 5 * Architecture independence: 6 * Copyright (c) 2005, Bull S.A. 7 * Written by Pierre Peiffer <pierre.peiffer@bull.net> 8 * --- 360 unchanged lines hidden (view full) --- 369static void 370ext4_ext_binsearch_idx(struct inode *inode, 371 struct ext4_ext_path *path, ext4_lblk_t block) 372{ 373 struct ext4_extent_header *eh = path->p_hdr; 374 struct ext4_extent_idx *r, *l, *m; 375 376 | 1/* 2 * Copyright (c) 2003-2006, Cluster File Systems, Inc, info@clusterfs.com 3 * Written by Alex Tomas <alex@clusterfs.com> 4 * 5 * Architecture independence: 6 * Copyright (c) 2005, Bull S.A. 7 * Written by Pierre Peiffer <pierre.peiffer@bull.net> 8 * --- 360 unchanged lines hidden (view full) --- 369static void 370ext4_ext_binsearch_idx(struct inode *inode, 371 struct ext4_ext_path *path, ext4_lblk_t block) 372{ 373 struct ext4_extent_header *eh = path->p_hdr; 374 struct ext4_extent_idx *r, *l, *m; 375 376 |
377 ext_debug("binsearch for %lu(idx): ", (unsigned long)block); | 377 ext_debug("binsearch for %u(idx): ", block); |
378 379 l = EXT_FIRST_INDEX(eh) + 1; 380 r = EXT_LAST_INDEX(eh); 381 while (l <= r) { 382 m = l + (r - l) / 2; 383 if (block < le32_to_cpu(m->ei_block)) 384 r = m - 1; 385 else --- 49 unchanged lines hidden (view full) --- 435 if (eh->eh_entries == 0) { 436 /* 437 * this leaf is empty: 438 * we get such a leaf in split/add case 439 */ 440 return; 441 } 442 | 378 379 l = EXT_FIRST_INDEX(eh) + 1; 380 r = EXT_LAST_INDEX(eh); 381 while (l <= r) { 382 m = l + (r - l) / 2; 383 if (block < le32_to_cpu(m->ei_block)) 384 r = m - 1; 385 else --- 49 unchanged lines hidden (view full) --- 435 if (eh->eh_entries == 0) { 436 /* 437 * this leaf is empty: 438 * we get such a leaf in split/add case 439 */ 440 return; 441 } 442 |
443 ext_debug("binsearch for %lu: ", (unsigned long)block); | 443 ext_debug("binsearch for %u: ", block); |
444 445 l = EXT_FIRST_EXTENT(eh) + 1; 446 r = EXT_LAST_EXTENT(eh); 447 448 while (l <= r) { 449 m = l + (r - l) / 2; 450 if (block < le32_to_cpu(m->ee_block)) 451 r = m - 1; --- 309 unchanged lines hidden (view full) --- 761 if (k) 762 ext_debug("create %d intermediate indices\n", k); 763 /* insert new index into current index block */ 764 /* current depth stored in i var */ 765 i = depth - 1; 766 while (k--) { 767 oldblock = newblock; 768 newblock = ablocks[--a]; | 444 445 l = EXT_FIRST_EXTENT(eh) + 1; 446 r = EXT_LAST_EXTENT(eh); 447 448 while (l <= r) { 449 m = l + (r - l) / 2; 450 if (block < le32_to_cpu(m->ee_block)) 451 r = m - 1; --- 309 unchanged lines hidden (view full) --- 761 if (k) 762 ext_debug("create %d intermediate indices\n", k); 763 /* insert new index into current index block */ 764 /* current depth stored in i var */ 765 i = depth - 1; 766 while (k--) { 767 oldblock = newblock; 768 newblock = ablocks[--a]; |
769 bh = sb_getblk(inode->i_sb, (ext4_fsblk_t)newblock); | 769 bh = sb_getblk(inode->i_sb, newblock); |
770 if (!bh) { 771 err = -EIO; 772 goto cleanup; 773 } 774 lock_buffer(bh); 775 776 err = ext4_journal_get_create_access(handle, bh); 777 if (err) 778 goto cleanup; 779 780 neh = ext_block_hdr(bh); 781 neh->eh_entries = cpu_to_le16(1); 782 neh->eh_magic = EXT4_EXT_MAGIC; 783 neh->eh_max = cpu_to_le16(ext4_ext_space_block_idx(inode)); 784 neh->eh_depth = cpu_to_le16(depth - i); 785 fidx = EXT_FIRST_INDEX(neh); 786 fidx->ei_block = border; 787 ext4_idx_store_pblock(fidx, oldblock); 788 | 770 if (!bh) { 771 err = -EIO; 772 goto cleanup; 773 } 774 lock_buffer(bh); 775 776 err = ext4_journal_get_create_access(handle, bh); 777 if (err) 778 goto cleanup; 779 780 neh = ext_block_hdr(bh); 781 neh->eh_entries = cpu_to_le16(1); 782 neh->eh_magic = EXT4_EXT_MAGIC; 783 neh->eh_max = cpu_to_le16(ext4_ext_space_block_idx(inode)); 784 neh->eh_depth = cpu_to_le16(depth - i); 785 fidx = EXT_FIRST_INDEX(neh); 786 fidx->ei_block = border; 787 ext4_idx_store_pblock(fidx, oldblock); 788 |
789 ext_debug("int.index at %d (block %llu): %lu -> %llu\n", i, 790 newblock, (unsigned long) le32_to_cpu(border), 791 oldblock); | 789 ext_debug("int.index at %d (block %llu): %u -> %llu\n", 790 i, newblock, le32_to_cpu(border), oldblock); |
792 /* copy indexes */ 793 m = 0; 794 path[i].p_idx++; 795 796 ext_debug("cur 0x%p, last 0x%p\n", path[i].p_idx, 797 EXT_MAX_INDEX(path[i].p_hdr)); 798 BUG_ON(EXT_MAX_INDEX(path[i].p_hdr) != 799 EXT_LAST_INDEX(path[i].p_hdr)); --- 671 unchanged lines hidden (view full) --- 1471 if (ex == NULL) { 1472 /* there is no extent yet, so gap is [0;-] */ 1473 lblock = 0; 1474 len = EXT_MAX_BLOCK; 1475 ext_debug("cache gap(whole file):"); 1476 } else if (block < le32_to_cpu(ex->ee_block)) { 1477 lblock = block; 1478 len = le32_to_cpu(ex->ee_block) - block; | 791 /* copy indexes */ 792 m = 0; 793 path[i].p_idx++; 794 795 ext_debug("cur 0x%p, last 0x%p\n", path[i].p_idx, 796 EXT_MAX_INDEX(path[i].p_hdr)); 797 BUG_ON(EXT_MAX_INDEX(path[i].p_hdr) != 798 EXT_LAST_INDEX(path[i].p_hdr)); --- 671 unchanged lines hidden (view full) --- 1470 if (ex == NULL) { 1471 /* there is no extent yet, so gap is [0;-] */ 1472 lblock = 0; 1473 len = EXT_MAX_BLOCK; 1474 ext_debug("cache gap(whole file):"); 1475 } else if (block < le32_to_cpu(ex->ee_block)) { 1476 lblock = block; 1477 len = le32_to_cpu(ex->ee_block) - block; |
1479 ext_debug("cache gap(before): %lu [%lu:%lu]", 1480 (unsigned long) block, 1481 (unsigned long) le32_to_cpu(ex->ee_block), 1482 (unsigned long) ext4_ext_get_actual_len(ex)); | 1478 ext_debug("cache gap(before): %u [%u:%u]", 1479 block, 1480 le32_to_cpu(ex->ee_block), 1481 ext4_ext_get_actual_len(ex)); |
1483 } else if (block >= le32_to_cpu(ex->ee_block) 1484 + ext4_ext_get_actual_len(ex)) { 1485 ext4_lblk_t next; 1486 lblock = le32_to_cpu(ex->ee_block) 1487 + ext4_ext_get_actual_len(ex); 1488 1489 next = ext4_ext_next_allocated_block(path); | 1482 } else if (block >= le32_to_cpu(ex->ee_block) 1483 + ext4_ext_get_actual_len(ex)) { 1484 ext4_lblk_t next; 1485 lblock = le32_to_cpu(ex->ee_block) 1486 + ext4_ext_get_actual_len(ex); 1487 1488 next = ext4_ext_next_allocated_block(path); |
1490 ext_debug("cache gap(after): [%lu:%lu] %lu", 1491 (unsigned long) le32_to_cpu(ex->ee_block), 1492 (unsigned long) ext4_ext_get_actual_len(ex), 1493 (unsigned long) block); | 1489 ext_debug("cache gap(after): [%u:%u] %u", 1490 le32_to_cpu(ex->ee_block), 1491 ext4_ext_get_actual_len(ex), 1492 block); |
1494 BUG_ON(next == lblock); 1495 len = next - lblock; 1496 } else { 1497 lblock = len = 0; 1498 BUG(); 1499 } 1500 | 1493 BUG_ON(next == lblock); 1494 len = next - lblock; 1495 } else { 1496 lblock = len = 0; 1497 BUG(); 1498 } 1499 |
1501 ext_debug(" -> %lu:%lu\n", (unsigned long) lblock, len); | 1500 ext_debug(" -> %u:%lu\n", lblock, len); |
1502 ext4_ext_put_in_cache(inode, lblock, len, 0, EXT4_EXT_CACHE_GAP); 1503} 1504 1505static int 1506ext4_ext_in_cache(struct inode *inode, ext4_lblk_t block, 1507 struct ext4_extent *ex) 1508{ 1509 struct ext4_ext_cache *cex; --- 5 unchanged lines hidden (view full) --- 1515 return EXT4_EXT_CACHE_NO; 1516 1517 BUG_ON(cex->ec_type != EXT4_EXT_CACHE_GAP && 1518 cex->ec_type != EXT4_EXT_CACHE_EXTENT); 1519 if (block >= cex->ec_block && block < cex->ec_block + cex->ec_len) { 1520 ex->ee_block = cpu_to_le32(cex->ec_block); 1521 ext4_ext_store_pblock(ex, cex->ec_start); 1522 ex->ee_len = cpu_to_le16(cex->ec_len); | 1501 ext4_ext_put_in_cache(inode, lblock, len, 0, EXT4_EXT_CACHE_GAP); 1502} 1503 1504static int 1505ext4_ext_in_cache(struct inode *inode, ext4_lblk_t block, 1506 struct ext4_extent *ex) 1507{ 1508 struct ext4_ext_cache *cex; --- 5 unchanged lines hidden (view full) --- 1514 return EXT4_EXT_CACHE_NO; 1515 1516 BUG_ON(cex->ec_type != EXT4_EXT_CACHE_GAP && 1517 cex->ec_type != EXT4_EXT_CACHE_EXTENT); 1518 if (block >= cex->ec_block && block < cex->ec_block + cex->ec_len) { 1519 ex->ee_block = cpu_to_le32(cex->ec_block); 1520 ext4_ext_store_pblock(ex, cex->ec_start); 1521 ex->ee_len = cpu_to_le16(cex->ec_len); |
1523 ext_debug("%lu cached by %lu:%lu:%llu\n", 1524 (unsigned long) block, 1525 (unsigned long) cex->ec_block, 1526 (unsigned long) cex->ec_len, 1527 cex->ec_start); | 1522 ext_debug("%u cached by %u:%u:%llu\n", 1523 block, 1524 cex->ec_block, cex->ec_len, cex->ec_start); |
1528 return cex->ec_type; 1529 } 1530 1531 /* not in cache */ 1532 return EXT4_EXT_CACHE_NO; 1533} 1534 1535/* --- 604 unchanged lines hidden (view full) --- 2140 struct ext4_ext_path *path = NULL; 2141 struct ext4_extent_header *eh; 2142 struct ext4_extent newex, *ex; 2143 ext4_fsblk_t goal, newblock; 2144 int err = 0, depth, ret; 2145 unsigned long allocated = 0; 2146 2147 __clear_bit(BH_New, &bh_result->b_state); | 1525 return cex->ec_type; 1526 } 1527 1528 /* not in cache */ 1529 return EXT4_EXT_CACHE_NO; 1530} 1531 1532/* --- 604 unchanged lines hidden (view full) --- 2137 struct ext4_ext_path *path = NULL; 2138 struct ext4_extent_header *eh; 2139 struct ext4_extent newex, *ex; 2140 ext4_fsblk_t goal, newblock; 2141 int err = 0, depth, ret; 2142 unsigned long allocated = 0; 2143 2144 __clear_bit(BH_New, &bh_result->b_state); |
2148 ext_debug("blocks %lu/%lu requested for inode %u\n", 2149 (unsigned long) iblock, max_blocks, 2150 (unsigned) inode->i_ino); | 2145 ext_debug("blocks %u/%lu requested for inode %u\n", 2146 iblock, max_blocks, inode->i_ino); |
2151 mutex_lock(&EXT4_I(inode)->truncate_mutex); 2152 2153 /* check in cache */ 2154 goal = ext4_ext_in_cache(inode, iblock, &newex); 2155 if (goal) { 2156 if (goal == EXT4_EXT_CACHE_GAP) { 2157 if (!create) { 2158 /* --- 46 unchanged lines hidden (view full) --- 2205 * we split out initialized portions during a write. 2206 */ 2207 ee_len = ext4_ext_get_actual_len(ex); 2208 /* if found extent covers block, simply return it */ 2209 if (iblock >= ee_block && iblock < ee_block + ee_len) { 2210 newblock = iblock - ee_block + ee_start; 2211 /* number of remaining blocks in the extent */ 2212 allocated = ee_len - (iblock - ee_block); | 2147 mutex_lock(&EXT4_I(inode)->truncate_mutex); 2148 2149 /* check in cache */ 2150 goal = ext4_ext_in_cache(inode, iblock, &newex); 2151 if (goal) { 2152 if (goal == EXT4_EXT_CACHE_GAP) { 2153 if (!create) { 2154 /* --- 46 unchanged lines hidden (view full) --- 2201 * we split out initialized portions during a write. 2202 */ 2203 ee_len = ext4_ext_get_actual_len(ex); 2204 /* if found extent covers block, simply return it */ 2205 if (iblock >= ee_block && iblock < ee_block + ee_len) { 2206 newblock = iblock - ee_block + ee_start; 2207 /* number of remaining blocks in the extent */ 2208 allocated = ee_len - (iblock - ee_block); |
2213 ext_debug("%d fit into %lu:%d -> %llu\n", (int) iblock, | 2209 ext_debug("%u fit into %lu:%d -> %llu\n", iblock, |
2214 ee_block, ee_len, newblock); 2215 2216 /* Do not put uninitialized extent in the cache */ 2217 if (!ext4_ext_is_uninitialized(ex)) { 2218 ext4_ext_put_in_cache(inode, ee_block, 2219 ee_len, ee_start, 2220 EXT4_EXT_CACHE_EXTENT); 2221 goto out; --- 243 unchanged lines hidden (view full) --- 2465 2466 ret = ext4_ext_get_blocks(handle, inode, block, 2467 max_blocks, &map_bh, 2468 EXT4_CREATE_UNINITIALIZED_EXT, 0); 2469 WARN_ON(!ret); 2470 if (!ret) { 2471 ext4_error(inode->i_sb, "ext4_fallocate", 2472 "ext4_ext_get_blocks returned 0! inode#%lu" | 2210 ee_block, ee_len, newblock); 2211 2212 /* Do not put uninitialized extent in the cache */ 2213 if (!ext4_ext_is_uninitialized(ex)) { 2214 ext4_ext_put_in_cache(inode, ee_block, 2215 ee_len, ee_start, 2216 EXT4_EXT_CACHE_EXTENT); 2217 goto out; --- 243 unchanged lines hidden (view full) --- 2461 2462 ret = ext4_ext_get_blocks(handle, inode, block, 2463 max_blocks, &map_bh, 2464 EXT4_CREATE_UNINITIALIZED_EXT, 0); 2465 WARN_ON(!ret); 2466 if (!ret) { 2467 ext4_error(inode->i_sb, "ext4_fallocate", 2468 "ext4_ext_get_blocks returned 0! inode#%lu" |
2473 ", block=%lu, max_blocks=%lu", 2474 inode->i_ino, (unsigned long)block, 2475 (unsigned long)max_blocks); | 2469 ", block=%u, max_blocks=%lu", 2470 inode->i_ino, block, max_blocks); |
2476 ret = -EIO; 2477 ext4_mark_inode_dirty(handle, inode); 2478 ret2 = ext4_journal_stop(handle); 2479 break; 2480 } 2481 if (ret > 0) { 2482 /* check wrap through sign-bit/zero here */ 2483 if ((block + ret) < 0 || (block + ret) < block) { --- 58 unchanged lines hidden --- | 2471 ret = -EIO; 2472 ext4_mark_inode_dirty(handle, inode); 2473 ret2 = ext4_journal_stop(handle); 2474 break; 2475 } 2476 if (ret > 0) { 2477 /* check wrap through sign-bit/zero here */ 2478 if ((block + ret) < 0 || (block + ret) < block) { --- 58 unchanged lines hidden --- |