diff options
Diffstat (limited to 'fs/ext4/extents.c')
-rw-r--r-- | fs/ext4/extents.c | 214 |
1 files changed, 133 insertions, 81 deletions
diff --git a/fs/ext4/extents.c b/fs/ext4/extents.c index bc0f1910b9cf..72ba4705d4fa 100644 --- a/fs/ext4/extents.c +++ b/fs/ext4/extents.c | |||
@@ -2125,7 +2125,8 @@ static int ext4_fill_fiemap_extents(struct inode *inode, | |||
2125 | next_del = ext4_find_delayed_extent(inode, &es); | 2125 | next_del = ext4_find_delayed_extent(inode, &es); |
2126 | if (!exists && next_del) { | 2126 | if (!exists && next_del) { |
2127 | exists = 1; | 2127 | exists = 1; |
2128 | flags |= FIEMAP_EXTENT_DELALLOC; | 2128 | flags |= (FIEMAP_EXTENT_DELALLOC | |
2129 | FIEMAP_EXTENT_UNKNOWN); | ||
2129 | } | 2130 | } |
2130 | up_read(&EXT4_I(inode)->i_data_sem); | 2131 | up_read(&EXT4_I(inode)->i_data_sem); |
2131 | 2132 | ||
@@ -2328,17 +2329,15 @@ int ext4_ext_calc_credits_for_single_extent(struct inode *inode, int nrblocks, | |||
2328 | } | 2329 | } |
2329 | 2330 | ||
2330 | /* | 2331 | /* |
2331 | * How many index/leaf blocks need to change/allocate to modify nrblocks? | 2332 | * How many index/leaf blocks need to change/allocate to add @extents extents? |
2332 | * | 2333 | * |
2333 | * if nrblocks are fit in a single extent (chunk flag is 1), then | 2334 | * If we add a single extent, then in the worse case, each tree level |
2334 | * in the worse case, each tree level index/leaf need to be changed | 2335 | * index/leaf need to be changed in case of the tree split. |
2335 | * if the tree split due to insert a new extent, then the old tree | ||
2336 | * index/leaf need to be updated too | ||
2337 | * | 2336 | * |
2338 | * If the nrblocks are discontiguous, they could cause | 2337 | * If more extents are inserted, they could cause the whole tree split more |
2339 | * the whole tree split more than once, but this is really rare. | 2338 | * than once, but this is really rare. |
2340 | */ | 2339 | */ |
2341 | int ext4_ext_index_trans_blocks(struct inode *inode, int nrblocks, int chunk) | 2340 | int ext4_ext_index_trans_blocks(struct inode *inode, int extents) |
2342 | { | 2341 | { |
2343 | int index; | 2342 | int index; |
2344 | int depth; | 2343 | int depth; |
@@ -2349,7 +2348,7 @@ int ext4_ext_index_trans_blocks(struct inode *inode, int nrblocks, int chunk) | |||
2349 | 2348 | ||
2350 | depth = ext_depth(inode); | 2349 | depth = ext_depth(inode); |
2351 | 2350 | ||
2352 | if (chunk) | 2351 | if (extents <= 1) |
2353 | index = depth * 2; | 2352 | index = depth * 2; |
2354 | else | 2353 | else |
2355 | index = depth * 3; | 2354 | index = depth * 3; |
@@ -2357,20 +2356,24 @@ int ext4_ext_index_trans_blocks(struct inode *inode, int nrblocks, int chunk) | |||
2357 | return index; | 2356 | return index; |
2358 | } | 2357 | } |
2359 | 2358 | ||
2359 | static inline int get_default_free_blocks_flags(struct inode *inode) | ||
2360 | { | ||
2361 | if (S_ISDIR(inode->i_mode) || S_ISLNK(inode->i_mode)) | ||
2362 | return EXT4_FREE_BLOCKS_METADATA | EXT4_FREE_BLOCKS_FORGET; | ||
2363 | else if (ext4_should_journal_data(inode)) | ||
2364 | return EXT4_FREE_BLOCKS_FORGET; | ||
2365 | return 0; | ||
2366 | } | ||
2367 | |||
2360 | static int ext4_remove_blocks(handle_t *handle, struct inode *inode, | 2368 | static int ext4_remove_blocks(handle_t *handle, struct inode *inode, |
2361 | struct ext4_extent *ex, | 2369 | struct ext4_extent *ex, |
2362 | ext4_fsblk_t *partial_cluster, | 2370 | long long *partial_cluster, |
2363 | ext4_lblk_t from, ext4_lblk_t to) | 2371 | ext4_lblk_t from, ext4_lblk_t to) |
2364 | { | 2372 | { |
2365 | struct ext4_sb_info *sbi = EXT4_SB(inode->i_sb); | 2373 | struct ext4_sb_info *sbi = EXT4_SB(inode->i_sb); |
2366 | unsigned short ee_len = ext4_ext_get_actual_len(ex); | 2374 | unsigned short ee_len = ext4_ext_get_actual_len(ex); |
2367 | ext4_fsblk_t pblk; | 2375 | ext4_fsblk_t pblk; |
2368 | int flags = 0; | 2376 | int flags = get_default_free_blocks_flags(inode); |
2369 | |||
2370 | if (S_ISDIR(inode->i_mode) || S_ISLNK(inode->i_mode)) | ||
2371 | flags |= EXT4_FREE_BLOCKS_METADATA | EXT4_FREE_BLOCKS_FORGET; | ||
2372 | else if (ext4_should_journal_data(inode)) | ||
2373 | flags |= EXT4_FREE_BLOCKS_FORGET; | ||
2374 | 2377 | ||
2375 | /* | 2378 | /* |
2376 | * For bigalloc file systems, we never free a partial cluster | 2379 | * For bigalloc file systems, we never free a partial cluster |
@@ -2388,7 +2391,8 @@ static int ext4_remove_blocks(handle_t *handle, struct inode *inode, | |||
2388 | * partial cluster here. | 2391 | * partial cluster here. |
2389 | */ | 2392 | */ |
2390 | pblk = ext4_ext_pblock(ex) + ee_len - 1; | 2393 | pblk = ext4_ext_pblock(ex) + ee_len - 1; |
2391 | if (*partial_cluster && (EXT4_B2C(sbi, pblk) != *partial_cluster)) { | 2394 | if ((*partial_cluster > 0) && |
2395 | (EXT4_B2C(sbi, pblk) != *partial_cluster)) { | ||
2392 | ext4_free_blocks(handle, inode, NULL, | 2396 | ext4_free_blocks(handle, inode, NULL, |
2393 | EXT4_C2B(sbi, *partial_cluster), | 2397 | EXT4_C2B(sbi, *partial_cluster), |
2394 | sbi->s_cluster_ratio, flags); | 2398 | sbi->s_cluster_ratio, flags); |
@@ -2414,41 +2418,46 @@ static int ext4_remove_blocks(handle_t *handle, struct inode *inode, | |||
2414 | && to == le32_to_cpu(ex->ee_block) + ee_len - 1) { | 2418 | && to == le32_to_cpu(ex->ee_block) + ee_len - 1) { |
2415 | /* tail removal */ | 2419 | /* tail removal */ |
2416 | ext4_lblk_t num; | 2420 | ext4_lblk_t num; |
2421 | unsigned int unaligned; | ||
2417 | 2422 | ||
2418 | num = le32_to_cpu(ex->ee_block) + ee_len - from; | 2423 | num = le32_to_cpu(ex->ee_block) + ee_len - from; |
2419 | pblk = ext4_ext_pblock(ex) + ee_len - num; | 2424 | pblk = ext4_ext_pblock(ex) + ee_len - num; |
2420 | ext_debug("free last %u blocks starting %llu\n", num, pblk); | 2425 | /* |
2426 | * Usually we want to free partial cluster at the end of the | ||
2427 | * extent, except for the situation when the cluster is still | ||
2428 | * used by any other extent (partial_cluster is negative). | ||
2429 | */ | ||
2430 | if (*partial_cluster < 0 && | ||
2431 | -(*partial_cluster) == EXT4_B2C(sbi, pblk + num - 1)) | ||
2432 | flags |= EXT4_FREE_BLOCKS_NOFREE_LAST_CLUSTER; | ||
2433 | |||
2434 | ext_debug("free last %u blocks starting %llu partial %lld\n", | ||
2435 | num, pblk, *partial_cluster); | ||
2421 | ext4_free_blocks(handle, inode, NULL, pblk, num, flags); | 2436 | ext4_free_blocks(handle, inode, NULL, pblk, num, flags); |
2422 | /* | 2437 | /* |
2423 | * If the block range to be freed didn't start at the | 2438 | * If the block range to be freed didn't start at the |
2424 | * beginning of a cluster, and we removed the entire | 2439 | * beginning of a cluster, and we removed the entire |
2425 | * extent, save the partial cluster here, since we | 2440 | * extent and the cluster is not used by any other extent, |
2426 | * might need to delete if we determine that the | 2441 | * save the partial cluster here, since we might need to |
2427 | * truncate operation has removed all of the blocks in | 2442 | * delete if we determine that the truncate operation has |
2428 | * the cluster. | 2443 | * removed all of the blocks in the cluster. |
2444 | * | ||
2445 | * On the other hand, if we did not manage to free the whole | ||
2446 | * extent, we have to mark the cluster as used (store negative | ||
2447 | * cluster number in partial_cluster). | ||
2429 | */ | 2448 | */ |
2430 | if (pblk & (sbi->s_cluster_ratio - 1) && | 2449 | unaligned = pblk & (sbi->s_cluster_ratio - 1); |
2431 | (ee_len == num)) | 2450 | if (unaligned && (ee_len == num) && |
2451 | (*partial_cluster != -((long long)EXT4_B2C(sbi, pblk)))) | ||
2432 | *partial_cluster = EXT4_B2C(sbi, pblk); | 2452 | *partial_cluster = EXT4_B2C(sbi, pblk); |
2433 | else | 2453 | else if (unaligned) |
2454 | *partial_cluster = -((long long)EXT4_B2C(sbi, pblk)); | ||
2455 | else if (*partial_cluster > 0) | ||
2434 | *partial_cluster = 0; | 2456 | *partial_cluster = 0; |
2435 | } else if (from == le32_to_cpu(ex->ee_block) | 2457 | } else |
2436 | && to <= le32_to_cpu(ex->ee_block) + ee_len - 1) { | 2458 | ext4_error(sbi->s_sb, "strange request: removal(2) " |
2437 | /* head removal */ | 2459 | "%u-%u from %u:%u\n", |
2438 | ext4_lblk_t num; | 2460 | from, to, le32_to_cpu(ex->ee_block), ee_len); |
2439 | ext4_fsblk_t start; | ||
2440 | |||
2441 | num = to - from; | ||
2442 | start = ext4_ext_pblock(ex); | ||
2443 | |||
2444 | ext_debug("free first %u blocks starting %llu\n", num, start); | ||
2445 | ext4_free_blocks(handle, inode, NULL, start, num, flags); | ||
2446 | |||
2447 | } else { | ||
2448 | printk(KERN_INFO "strange request: removal(2) " | ||
2449 | "%u-%u from %u:%u\n", | ||
2450 | from, to, le32_to_cpu(ex->ee_block), ee_len); | ||
2451 | } | ||
2452 | return 0; | 2461 | return 0; |
2453 | } | 2462 | } |
2454 | 2463 | ||
@@ -2461,12 +2470,16 @@ static int ext4_remove_blocks(handle_t *handle, struct inode *inode, | |||
2461 | * @handle: The journal handle | 2470 | * @handle: The journal handle |
2462 | * @inode: The files inode | 2471 | * @inode: The files inode |
2463 | * @path: The path to the leaf | 2472 | * @path: The path to the leaf |
2473 | * @partial_cluster: The cluster which we'll have to free if all extents | ||
2474 | * has been released from it. It gets negative in case | ||
2475 | * that the cluster is still used. | ||
2464 | * @start: The first block to remove | 2476 | * @start: The first block to remove |
2465 | * @end: The last block to remove | 2477 | * @end: The last block to remove |
2466 | */ | 2478 | */ |
2467 | static int | 2479 | static int |
2468 | ext4_ext_rm_leaf(handle_t *handle, struct inode *inode, | 2480 | ext4_ext_rm_leaf(handle_t *handle, struct inode *inode, |
2469 | struct ext4_ext_path *path, ext4_fsblk_t *partial_cluster, | 2481 | struct ext4_ext_path *path, |
2482 | long long *partial_cluster, | ||
2470 | ext4_lblk_t start, ext4_lblk_t end) | 2483 | ext4_lblk_t start, ext4_lblk_t end) |
2471 | { | 2484 | { |
2472 | struct ext4_sb_info *sbi = EXT4_SB(inode->i_sb); | 2485 | struct ext4_sb_info *sbi = EXT4_SB(inode->i_sb); |
@@ -2479,6 +2492,7 @@ ext4_ext_rm_leaf(handle_t *handle, struct inode *inode, | |||
2479 | unsigned short ex_ee_len; | 2492 | unsigned short ex_ee_len; |
2480 | unsigned uninitialized = 0; | 2493 | unsigned uninitialized = 0; |
2481 | struct ext4_extent *ex; | 2494 | struct ext4_extent *ex; |
2495 | ext4_fsblk_t pblk; | ||
2482 | 2496 | ||
2483 | /* the header must be checked already in ext4_ext_remove_space() */ | 2497 | /* the header must be checked already in ext4_ext_remove_space() */ |
2484 | ext_debug("truncate since %u in leaf to %u\n", start, end); | 2498 | ext_debug("truncate since %u in leaf to %u\n", start, end); |
@@ -2490,7 +2504,9 @@ ext4_ext_rm_leaf(handle_t *handle, struct inode *inode, | |||
2490 | return -EIO; | 2504 | return -EIO; |
2491 | } | 2505 | } |
2492 | /* find where to start removing */ | 2506 | /* find where to start removing */ |
2493 | ex = EXT_LAST_EXTENT(eh); | 2507 | ex = path[depth].p_ext; |
2508 | if (!ex) | ||
2509 | ex = EXT_LAST_EXTENT(eh); | ||
2494 | 2510 | ||
2495 | ex_ee_block = le32_to_cpu(ex->ee_block); | 2511 | ex_ee_block = le32_to_cpu(ex->ee_block); |
2496 | ex_ee_len = ext4_ext_get_actual_len(ex); | 2512 | ex_ee_len = ext4_ext_get_actual_len(ex); |
@@ -2517,6 +2533,16 @@ ext4_ext_rm_leaf(handle_t *handle, struct inode *inode, | |||
2517 | 2533 | ||
2518 | /* If this extent is beyond the end of the hole, skip it */ | 2534 | /* If this extent is beyond the end of the hole, skip it */ |
2519 | if (end < ex_ee_block) { | 2535 | if (end < ex_ee_block) { |
2536 | /* | ||
2537 | * We're going to skip this extent and move to another, | ||
2538 | * so if this extent is not cluster aligned we have | ||
2539 | * to mark the current cluster as used to avoid | ||
2540 | * accidentally freeing it later on | ||
2541 | */ | ||
2542 | pblk = ext4_ext_pblock(ex); | ||
2543 | if (pblk & (sbi->s_cluster_ratio - 1)) | ||
2544 | *partial_cluster = | ||
2545 | -((long long)EXT4_B2C(sbi, pblk)); | ||
2520 | ex--; | 2546 | ex--; |
2521 | ex_ee_block = le32_to_cpu(ex->ee_block); | 2547 | ex_ee_block = le32_to_cpu(ex->ee_block); |
2522 | ex_ee_len = ext4_ext_get_actual_len(ex); | 2548 | ex_ee_len = ext4_ext_get_actual_len(ex); |
@@ -2592,7 +2618,7 @@ ext4_ext_rm_leaf(handle_t *handle, struct inode *inode, | |||
2592 | sizeof(struct ext4_extent)); | 2618 | sizeof(struct ext4_extent)); |
2593 | } | 2619 | } |
2594 | le16_add_cpu(&eh->eh_entries, -1); | 2620 | le16_add_cpu(&eh->eh_entries, -1); |
2595 | } else | 2621 | } else if (*partial_cluster > 0) |
2596 | *partial_cluster = 0; | 2622 | *partial_cluster = 0; |
2597 | 2623 | ||
2598 | err = ext4_ext_dirty(handle, inode, path + depth); | 2624 | err = ext4_ext_dirty(handle, inode, path + depth); |
@@ -2610,17 +2636,13 @@ ext4_ext_rm_leaf(handle_t *handle, struct inode *inode, | |||
2610 | err = ext4_ext_correct_indexes(handle, inode, path); | 2636 | err = ext4_ext_correct_indexes(handle, inode, path); |
2611 | 2637 | ||
2612 | /* | 2638 | /* |
2613 | * If there is still a entry in the leaf node, check to see if | 2639 | * Free the partial cluster only if the current extent does not |
2614 | * it references the partial cluster. This is the only place | 2640 | * reference it. Otherwise we might free used cluster. |
2615 | * where it could; if it doesn't, we can free the cluster. | ||
2616 | */ | 2641 | */ |
2617 | if (*partial_cluster && ex >= EXT_FIRST_EXTENT(eh) && | 2642 | if (*partial_cluster > 0 && |
2618 | (EXT4_B2C(sbi, ext4_ext_pblock(ex) + ex_ee_len - 1) != | 2643 | (EXT4_B2C(sbi, ext4_ext_pblock(ex) + ex_ee_len - 1) != |
2619 | *partial_cluster)) { | 2644 | *partial_cluster)) { |
2620 | int flags = EXT4_FREE_BLOCKS_FORGET; | 2645 | int flags = get_default_free_blocks_flags(inode); |
2621 | |||
2622 | if (S_ISDIR(inode->i_mode) || S_ISLNK(inode->i_mode)) | ||
2623 | flags |= EXT4_FREE_BLOCKS_METADATA; | ||
2624 | 2646 | ||
2625 | ext4_free_blocks(handle, inode, NULL, | 2647 | ext4_free_blocks(handle, inode, NULL, |
2626 | EXT4_C2B(sbi, *partial_cluster), | 2648 | EXT4_C2B(sbi, *partial_cluster), |
@@ -2664,7 +2686,7 @@ int ext4_ext_remove_space(struct inode *inode, ext4_lblk_t start, | |||
2664 | struct super_block *sb = inode->i_sb; | 2686 | struct super_block *sb = inode->i_sb; |
2665 | int depth = ext_depth(inode); | 2687 | int depth = ext_depth(inode); |
2666 | struct ext4_ext_path *path = NULL; | 2688 | struct ext4_ext_path *path = NULL; |
2667 | ext4_fsblk_t partial_cluster = 0; | 2689 | long long partial_cluster = 0; |
2668 | handle_t *handle; | 2690 | handle_t *handle; |
2669 | int i = 0, err = 0; | 2691 | int i = 0, err = 0; |
2670 | 2692 | ||
@@ -2676,7 +2698,7 @@ int ext4_ext_remove_space(struct inode *inode, ext4_lblk_t start, | |||
2676 | return PTR_ERR(handle); | 2698 | return PTR_ERR(handle); |
2677 | 2699 | ||
2678 | again: | 2700 | again: |
2679 | trace_ext4_ext_remove_space(inode, start, depth); | 2701 | trace_ext4_ext_remove_space(inode, start, end, depth); |
2680 | 2702 | ||
2681 | /* | 2703 | /* |
2682 | * Check if we are removing extents inside the extent tree. If that | 2704 | * Check if we are removing extents inside the extent tree. If that |
@@ -2813,6 +2835,9 @@ again: | |||
2813 | err = -EIO; | 2835 | err = -EIO; |
2814 | break; | 2836 | break; |
2815 | } | 2837 | } |
2838 | /* Yield here to deal with large extent trees. | ||
2839 | * Should be a no-op if we did IO above. */ | ||
2840 | cond_resched(); | ||
2816 | if (WARN_ON(i + 1 > depth)) { | 2841 | if (WARN_ON(i + 1 > depth)) { |
2817 | err = -EIO; | 2842 | err = -EIO; |
2818 | break; | 2843 | break; |
@@ -2844,17 +2869,14 @@ again: | |||
2844 | } | 2869 | } |
2845 | } | 2870 | } |
2846 | 2871 | ||
2847 | trace_ext4_ext_remove_space_done(inode, start, depth, partial_cluster, | 2872 | trace_ext4_ext_remove_space_done(inode, start, end, depth, |
2848 | path->p_hdr->eh_entries); | 2873 | partial_cluster, path->p_hdr->eh_entries); |
2849 | 2874 | ||
2850 | /* If we still have something in the partial cluster and we have removed | 2875 | /* If we still have something in the partial cluster and we have removed |
2851 | * even the first extent, then we should free the blocks in the partial | 2876 | * even the first extent, then we should free the blocks in the partial |
2852 | * cluster as well. */ | 2877 | * cluster as well. */ |
2853 | if (partial_cluster && path->p_hdr->eh_entries == 0) { | 2878 | if (partial_cluster > 0 && path->p_hdr->eh_entries == 0) { |
2854 | int flags = EXT4_FREE_BLOCKS_FORGET; | 2879 | int flags = get_default_free_blocks_flags(inode); |
2855 | |||
2856 | if (S_ISDIR(inode->i_mode) || S_ISLNK(inode->i_mode)) | ||
2857 | flags |= EXT4_FREE_BLOCKS_METADATA; | ||
2858 | 2880 | ||
2859 | ext4_free_blocks(handle, inode, NULL, | 2881 | ext4_free_blocks(handle, inode, NULL, |
2860 | EXT4_C2B(EXT4_SB(sb), partial_cluster), | 2882 | EXT4_C2B(EXT4_SB(sb), partial_cluster), |
@@ -4242,8 +4264,8 @@ got_allocated_blocks: | |||
4242 | /* not a good idea to call discard here directly, | 4264 | /* not a good idea to call discard here directly, |
4243 | * but otherwise we'd need to call it every free() */ | 4265 | * but otherwise we'd need to call it every free() */ |
4244 | ext4_discard_preallocations(inode); | 4266 | ext4_discard_preallocations(inode); |
4245 | ext4_free_blocks(handle, inode, NULL, ext4_ext_pblock(&newex), | 4267 | ext4_free_blocks(handle, inode, NULL, newblock, |
4246 | ext4_ext_get_actual_len(&newex), fb_flags); | 4268 | EXT4_C2B(sbi, allocated_clusters), fb_flags); |
4247 | goto out2; | 4269 | goto out2; |
4248 | } | 4270 | } |
4249 | 4271 | ||
@@ -4363,8 +4385,9 @@ out2: | |||
4363 | } | 4385 | } |
4364 | 4386 | ||
4365 | out3: | 4387 | out3: |
4366 | trace_ext4_ext_map_blocks_exit(inode, map, err ? err : allocated); | 4388 | trace_ext4_ext_map_blocks_exit(inode, flags, map, |
4367 | 4389 | err ? err : allocated); | |
4390 | ext4_es_lru_add(inode); | ||
4368 | return err ? err : allocated; | 4391 | return err ? err : allocated; |
4369 | } | 4392 | } |
4370 | 4393 | ||
@@ -4386,9 +4409,20 @@ void ext4_ext_truncate(handle_t *handle, struct inode *inode) | |||
4386 | 4409 | ||
4387 | last_block = (inode->i_size + sb->s_blocksize - 1) | 4410 | last_block = (inode->i_size + sb->s_blocksize - 1) |
4388 | >> EXT4_BLOCK_SIZE_BITS(sb); | 4411 | >> EXT4_BLOCK_SIZE_BITS(sb); |
4412 | retry: | ||
4389 | err = ext4_es_remove_extent(inode, last_block, | 4413 | err = ext4_es_remove_extent(inode, last_block, |
4390 | EXT_MAX_BLOCKS - last_block); | 4414 | EXT_MAX_BLOCKS - last_block); |
4415 | if (err == -ENOMEM) { | ||
4416 | cond_resched(); | ||
4417 | congestion_wait(BLK_RW_ASYNC, HZ/50); | ||
4418 | goto retry; | ||
4419 | } | ||
4420 | if (err) { | ||
4421 | ext4_std_error(inode->i_sb, err); | ||
4422 | return; | ||
4423 | } | ||
4391 | err = ext4_ext_remove_space(inode, last_block, EXT_MAX_BLOCKS - 1); | 4424 | err = ext4_ext_remove_space(inode, last_block, EXT_MAX_BLOCKS - 1); |
4425 | ext4_std_error(inode->i_sb, err); | ||
4392 | } | 4426 | } |
4393 | 4427 | ||
4394 | static void ext4_falloc_update_inode(struct inode *inode, | 4428 | static void ext4_falloc_update_inode(struct inode *inode, |
@@ -4446,7 +4480,7 @@ long ext4_fallocate(struct file *file, int mode, loff_t offset, loff_t len) | |||
4446 | return -EOPNOTSUPP; | 4480 | return -EOPNOTSUPP; |
4447 | 4481 | ||
4448 | if (mode & FALLOC_FL_PUNCH_HOLE) | 4482 | if (mode & FALLOC_FL_PUNCH_HOLE) |
4449 | return ext4_punch_hole(file, offset, len); | 4483 | return ext4_punch_hole(inode, offset, len); |
4450 | 4484 | ||
4451 | ret = ext4_convert_inline_data(inode); | 4485 | ret = ext4_convert_inline_data(inode); |
4452 | if (ret) | 4486 | if (ret) |
@@ -4548,10 +4582,9 @@ retry: | |||
4548 | * function, to convert the fallocated extents after IO is completed. | 4582 | * function, to convert the fallocated extents after IO is completed. |
4549 | * Returns 0 on success. | 4583 | * Returns 0 on success. |
4550 | */ | 4584 | */ |
4551 | int ext4_convert_unwritten_extents(struct inode *inode, loff_t offset, | 4585 | int ext4_convert_unwritten_extents(handle_t *handle, struct inode *inode, |
4552 | ssize_t len) | 4586 | loff_t offset, ssize_t len) |
4553 | { | 4587 | { |
4554 | handle_t *handle; | ||
4555 | unsigned int max_blocks; | 4588 | unsigned int max_blocks; |
4556 | int ret = 0; | 4589 | int ret = 0; |
4557 | int ret2 = 0; | 4590 | int ret2 = 0; |
@@ -4566,16 +4599,32 @@ int ext4_convert_unwritten_extents(struct inode *inode, loff_t offset, | |||
4566 | max_blocks = ((EXT4_BLOCK_ALIGN(len + offset, blkbits) >> blkbits) - | 4599 | max_blocks = ((EXT4_BLOCK_ALIGN(len + offset, blkbits) >> blkbits) - |
4567 | map.m_lblk); | 4600 | map.m_lblk); |
4568 | /* | 4601 | /* |
4569 | * credits to insert 1 extent into extent tree | 4602 | * This is somewhat ugly but the idea is clear: When transaction is |
4603 | * reserved, everything goes into it. Otherwise we rather start several | ||
4604 | * smaller transactions for conversion of each extent separately. | ||
4570 | */ | 4605 | */ |
4571 | credits = ext4_chunk_trans_blocks(inode, max_blocks); | 4606 | if (handle) { |
4607 | handle = ext4_journal_start_reserved(handle, | ||
4608 | EXT4_HT_EXT_CONVERT); | ||
4609 | if (IS_ERR(handle)) | ||
4610 | return PTR_ERR(handle); | ||
4611 | credits = 0; | ||
4612 | } else { | ||
4613 | /* | ||
4614 | * credits to insert 1 extent into extent tree | ||
4615 | */ | ||
4616 | credits = ext4_chunk_trans_blocks(inode, max_blocks); | ||
4617 | } | ||
4572 | while (ret >= 0 && ret < max_blocks) { | 4618 | while (ret >= 0 && ret < max_blocks) { |
4573 | map.m_lblk += ret; | 4619 | map.m_lblk += ret; |
4574 | map.m_len = (max_blocks -= ret); | 4620 | map.m_len = (max_blocks -= ret); |
4575 | handle = ext4_journal_start(inode, EXT4_HT_MAP_BLOCKS, credits); | 4621 | if (credits) { |
4576 | if (IS_ERR(handle)) { | 4622 | handle = ext4_journal_start(inode, EXT4_HT_MAP_BLOCKS, |
4577 | ret = PTR_ERR(handle); | 4623 | credits); |
4578 | break; | 4624 | if (IS_ERR(handle)) { |
4625 | ret = PTR_ERR(handle); | ||
4626 | break; | ||
4627 | } | ||
4579 | } | 4628 | } |
4580 | ret = ext4_map_blocks(handle, inode, &map, | 4629 | ret = ext4_map_blocks(handle, inode, &map, |
4581 | EXT4_GET_BLOCKS_IO_CONVERT_EXT); | 4630 | EXT4_GET_BLOCKS_IO_CONVERT_EXT); |
@@ -4586,10 +4635,13 @@ int ext4_convert_unwritten_extents(struct inode *inode, loff_t offset, | |||
4586 | inode->i_ino, map.m_lblk, | 4635 | inode->i_ino, map.m_lblk, |
4587 | map.m_len, ret); | 4636 | map.m_len, ret); |
4588 | ext4_mark_inode_dirty(handle, inode); | 4637 | ext4_mark_inode_dirty(handle, inode); |
4589 | ret2 = ext4_journal_stop(handle); | 4638 | if (credits) |
4590 | if (ret <= 0 || ret2 ) | 4639 | ret2 = ext4_journal_stop(handle); |
4640 | if (ret <= 0 || ret2) | ||
4591 | break; | 4641 | break; |
4592 | } | 4642 | } |
4643 | if (!credits) | ||
4644 | ret2 = ext4_journal_stop(handle); | ||
4593 | return ret > 0 ? ret2 : ret; | 4645 | return ret > 0 ? ret2 : ret; |
4594 | } | 4646 | } |
4595 | 4647 | ||
@@ -4659,7 +4711,7 @@ static int ext4_xattr_fiemap(struct inode *inode, | |||
4659 | error = ext4_get_inode_loc(inode, &iloc); | 4711 | error = ext4_get_inode_loc(inode, &iloc); |
4660 | if (error) | 4712 | if (error) |
4661 | return error; | 4713 | return error; |
4662 | physical = iloc.bh->b_blocknr << blockbits; | 4714 | physical = (__u64)iloc.bh->b_blocknr << blockbits; |
4663 | offset = EXT4_GOOD_OLD_INODE_SIZE + | 4715 | offset = EXT4_GOOD_OLD_INODE_SIZE + |
4664 | EXT4_I(inode)->i_extra_isize; | 4716 | EXT4_I(inode)->i_extra_isize; |
4665 | physical += offset; | 4717 | physical += offset; |
@@ -4667,7 +4719,7 @@ static int ext4_xattr_fiemap(struct inode *inode, | |||
4667 | flags |= FIEMAP_EXTENT_DATA_INLINE; | 4719 | flags |= FIEMAP_EXTENT_DATA_INLINE; |
4668 | brelse(iloc.bh); | 4720 | brelse(iloc.bh); |
4669 | } else { /* external block */ | 4721 | } else { /* external block */ |
4670 | physical = EXT4_I(inode)->i_file_acl << blockbits; | 4722 | physical = (__u64)EXT4_I(inode)->i_file_acl << blockbits; |
4671 | length = inode->i_sb->s_blocksize; | 4723 | length = inode->i_sb->s_blocksize; |
4672 | } | 4724 | } |
4673 | 4725 | ||