extents.c (3d58f48ba05caed9118bce62b3047f8683438835) extents.c (5887e98b609e96ce61ee0528cf94a2bfdc809dd7)
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 *

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

44#include "ext4_jbd2.h"
45#include "ext4_extents.h"
46
47
48/*
49 * ext_pblock:
50 * combine low and high parts of physical block number into ext4_fsblk_t
51 */
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 *

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

44#include "ext4_jbd2.h"
45#include "ext4_extents.h"
46
47
48/*
49 * ext_pblock:
50 * combine low and high parts of physical block number into ext4_fsblk_t
51 */
52static ext4_fsblk_t ext_pblock(struct ext4_extent *ex)
52ext4_fsblk_t ext_pblock(struct ext4_extent *ex)
53{
54 ext4_fsblk_t block;
55
56 block = le32_to_cpu(ex->ee_start_lo);
57 block |= ((ext4_fsblk_t) le16_to_cpu(ex->ee_start_hi) << 31) << 1;
58 return block;
59}
60

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

321 max = ext4_ext_space_block_idx(inode);
322 }
323
324 return max;
325}
326
327static int ext4_valid_extent(struct inode *inode, struct ext4_extent *ext)
328{
53{
54 ext4_fsblk_t block;
55
56 block = le32_to_cpu(ex->ee_start_lo);
57 block |= ((ext4_fsblk_t) le16_to_cpu(ex->ee_start_hi) << 31) << 1;
58 return block;
59}
60

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

321 max = ext4_ext_space_block_idx(inode);
322 }
323
324 return max;
325}
326
327static int ext4_valid_extent(struct inode *inode, struct ext4_extent *ext)
328{
329 ext4_fsblk_t block = ext_pblock(ext), valid_block;
329 ext4_fsblk_t block = ext_pblock(ext);
330 int len = ext4_ext_get_actual_len(ext);
330 int len = ext4_ext_get_actual_len(ext);
331 struct ext4_super_block *es = EXT4_SB(inode->i_sb)->s_es;
332
331
333 valid_block = le32_to_cpu(es->s_first_data_block) +
334 EXT4_SB(inode->i_sb)->s_gdb_count;
335 if (unlikely(block <= valid_block ||
336 ((block + len) > ext4_blocks_count(es))))
337 return 0;
338 else
339 return 1;
332 return ext4_data_block_valid(EXT4_SB(inode->i_sb), block, len);
340}
341
342static int ext4_valid_extent_idx(struct inode *inode,
343 struct ext4_extent_idx *ext_idx)
344{
333}
334
335static int ext4_valid_extent_idx(struct inode *inode,
336 struct ext4_extent_idx *ext_idx)
337{
345 ext4_fsblk_t block = idx_pblock(ext_idx), valid_block;
346 struct ext4_super_block *es = EXT4_SB(inode->i_sb)->s_es;
338 ext4_fsblk_t block = idx_pblock(ext_idx);
347
339
348 valid_block = le32_to_cpu(es->s_first_data_block) +
349 EXT4_SB(inode->i_sb)->s_gdb_count;
350 if (unlikely(block <= valid_block ||
351 (block >= ext4_blocks_count(es))))
352 return 0;
353 else
354 return 1;
340 return ext4_data_block_valid(EXT4_SB(inode->i_sb), block, 1);
355}
356
357static int ext4_valid_extent_entries(struct inode *inode,
358 struct ext4_extent_header *eh,
359 int depth)
360{
361 struct ext4_extent *ext;
362 struct ext4_extent_idx *ext_idx;

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

1426 err = ext4_ext_dirty(handle, inode, path + k);
1427 if (err)
1428 break;
1429 }
1430
1431 return err;
1432}
1433
341}
342
343static int ext4_valid_extent_entries(struct inode *inode,
344 struct ext4_extent_header *eh,
345 int depth)
346{
347 struct ext4_extent *ext;
348 struct ext4_extent_idx *ext_idx;

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

1412 err = ext4_ext_dirty(handle, inode, path + k);
1413 if (err)
1414 break;
1415 }
1416
1417 return err;
1418}
1419
1434static int
1420int
1435ext4_can_extents_be_merged(struct inode *inode, struct ext4_extent *ex1,
1436 struct ext4_extent *ex2)
1437{
1438 unsigned short ext1_ee_len, ext2_ee_len, max_len;
1439
1440 /*
1441 * Make sure that either both extents are uninitialized, or
1442 * both are _not_.

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

1986 * need to account for leaf block credit
1987 *
1988 * bitmaps and block group descriptor blocks
1989 * and other metadat blocks still need to be
1990 * accounted.
1991 */
1992 /* 1 bitmap, 1 block group descriptor */
1993 ret = 2 + EXT4_META_TRANS_BLOCKS(inode->i_sb);
1421ext4_can_extents_be_merged(struct inode *inode, struct ext4_extent *ex1,
1422 struct ext4_extent *ex2)
1423{
1424 unsigned short ext1_ee_len, ext2_ee_len, max_len;
1425
1426 /*
1427 * Make sure that either both extents are uninitialized, or
1428 * both are _not_.

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

1972 * need to account for leaf block credit
1973 *
1974 * bitmaps and block group descriptor blocks
1975 * and other metadat blocks still need to be
1976 * accounted.
1977 */
1978 /* 1 bitmap, 1 block group descriptor */
1979 ret = 2 + EXT4_META_TRANS_BLOCKS(inode->i_sb);
1980 return ret;
1994 }
1995 }
1996
1997 return ext4_chunk_trans_blocks(inode, nrblocks);
1998}
1999
2000/*
2001 * How many index/leaf blocks need to change/allocate to modify nrblocks?

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

2092 path[depth].p_hdr = ext_block_hdr(path[depth].p_bh);
2093 eh = path[depth].p_hdr;
2094 BUG_ON(eh == NULL);
2095
2096 /* find where to start removing */
2097 ex = EXT_LAST_EXTENT(eh);
2098
2099 ex_ee_block = le32_to_cpu(ex->ee_block);
1981 }
1982 }
1983
1984 return ext4_chunk_trans_blocks(inode, nrblocks);
1985}
1986
1987/*
1988 * How many index/leaf blocks need to change/allocate to modify nrblocks?

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

2079 path[depth].p_hdr = ext_block_hdr(path[depth].p_bh);
2080 eh = path[depth].p_hdr;
2081 BUG_ON(eh == NULL);
2082
2083 /* find where to start removing */
2084 ex = EXT_LAST_EXTENT(eh);
2085
2086 ex_ee_block = le32_to_cpu(ex->ee_block);
2100 if (ext4_ext_is_uninitialized(ex))
2101 uninitialized = 1;
2102 ex_ee_len = ext4_ext_get_actual_len(ex);
2103
2104 while (ex >= EXT_FIRST_EXTENT(eh) &&
2105 ex_ee_block + ex_ee_len > start) {
2087 ex_ee_len = ext4_ext_get_actual_len(ex);
2088
2089 while (ex >= EXT_FIRST_EXTENT(eh) &&
2090 ex_ee_block + ex_ee_len > start) {
2091
2092 if (ext4_ext_is_uninitialized(ex))
2093 uninitialized = 1;
2094 else
2095 uninitialized = 0;
2096
2106 ext_debug("remove ext %lu:%u\n", ex_ee_block, ex_ee_len);
2107 path[depth].p_ext = ex;
2108
2109 a = ex_ee_block > start ? ex_ee_block : start;
2110 b = ex_ee_block + ex_ee_len - 1 < EXT_MAX_BLOCK ?
2111 ex_ee_block + ex_ee_len - 1 : EXT_MAX_BLOCK;
2112
2113 ext_debug(" border %u:%u\n", a, b);

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

2779 * return = 0, if plain look up failed (blocks have not been allocated)
2780 * buffer head is unmapped
2781 *
2782 * return < 0, error case.
2783 */
2784int ext4_ext_get_blocks(handle_t *handle, struct inode *inode,
2785 ext4_lblk_t iblock,
2786 unsigned int max_blocks, struct buffer_head *bh_result,
2097 ext_debug("remove ext %lu:%u\n", ex_ee_block, ex_ee_len);
2098 path[depth].p_ext = ex;
2099
2100 a = ex_ee_block > start ? ex_ee_block : start;
2101 b = ex_ee_block + ex_ee_len - 1 < EXT_MAX_BLOCK ?
2102 ex_ee_block + ex_ee_len - 1 : EXT_MAX_BLOCK;
2103
2104 ext_debug(" border %u:%u\n", a, b);

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

2770 * return = 0, if plain look up failed (blocks have not been allocated)
2771 * buffer head is unmapped
2772 *
2773 * return < 0, error case.
2774 */
2775int ext4_ext_get_blocks(handle_t *handle, struct inode *inode,
2776 ext4_lblk_t iblock,
2777 unsigned int max_blocks, struct buffer_head *bh_result,
2787 int create, int extend_disksize)
2778 int flags)
2788{
2789 struct ext4_ext_path *path = NULL;
2790 struct ext4_extent_header *eh;
2791 struct ext4_extent newex, *ex;
2792 ext4_fsblk_t newblock;
2793 int err = 0, depth, ret, cache_type;
2794 unsigned int allocated = 0;
2795 struct ext4_allocation_request ar;
2779{
2780 struct ext4_ext_path *path = NULL;
2781 struct ext4_extent_header *eh;
2782 struct ext4_extent newex, *ex;
2783 ext4_fsblk_t newblock;
2784 int err = 0, depth, ret, cache_type;
2785 unsigned int allocated = 0;
2786 struct ext4_allocation_request ar;
2796 loff_t disksize;
2797
2798 __clear_bit(BH_New, &bh_result->b_state);
2799 ext_debug("blocks %u/%u requested for inode %u\n",
2800 iblock, max_blocks, inode->i_ino);
2801
2802 /* check in cache */
2803 cache_type = ext4_ext_in_cache(inode, iblock, &newex);
2804 if (cache_type) {
2805 if (cache_type == EXT4_EXT_CACHE_GAP) {
2787
2788 __clear_bit(BH_New, &bh_result->b_state);
2789 ext_debug("blocks %u/%u requested for inode %u\n",
2790 iblock, max_blocks, inode->i_ino);
2791
2792 /* check in cache */
2793 cache_type = ext4_ext_in_cache(inode, iblock, &newex);
2794 if (cache_type) {
2795 if (cache_type == EXT4_EXT_CACHE_GAP) {
2806 if (!create) {
2796 if ((flags & EXT4_GET_BLOCKS_CREATE) == 0) {
2807 /*
2808 * block isn't allocated yet and
2809 * user doesn't want to allocate it
2810 */
2811 goto out2;
2812 }
2813 /* we should allocate requested block */
2814 } else if (cache_type == EXT4_EXT_CACHE_EXTENT) {

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

2864
2865 /* Do not put uninitialized extent in the cache */
2866 if (!ext4_ext_is_uninitialized(ex)) {
2867 ext4_ext_put_in_cache(inode, ee_block,
2868 ee_len, ee_start,
2869 EXT4_EXT_CACHE_EXTENT);
2870 goto out;
2871 }
2797 /*
2798 * block isn't allocated yet and
2799 * user doesn't want to allocate it
2800 */
2801 goto out2;
2802 }
2803 /* we should allocate requested block */
2804 } else if (cache_type == EXT4_EXT_CACHE_EXTENT) {

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

2854
2855 /* Do not put uninitialized extent in the cache */
2856 if (!ext4_ext_is_uninitialized(ex)) {
2857 ext4_ext_put_in_cache(inode, ee_block,
2858 ee_len, ee_start,
2859 EXT4_EXT_CACHE_EXTENT);
2860 goto out;
2861 }
2872 if (create == EXT4_CREATE_UNINITIALIZED_EXT)
2862 if (flags & EXT4_GET_BLOCKS_UNINIT_EXT)
2873 goto out;
2863 goto out;
2874 if (!create) {
2864 if ((flags & EXT4_GET_BLOCKS_CREATE) == 0) {
2865 if (allocated > max_blocks)
2866 allocated = max_blocks;
2875 /*
2876 * We have blocks reserved already. We
2877 * return allocated blocks so that delalloc
2878 * won't do block reservation for us. But
2879 * the buffer head will be unmapped so that
2880 * a read from the block returns 0s.
2881 */
2867 /*
2868 * We have blocks reserved already. We
2869 * return allocated blocks so that delalloc
2870 * won't do block reservation for us. But
2871 * the buffer head will be unmapped so that
2872 * a read from the block returns 0s.
2873 */
2882 if (allocated > max_blocks)
2883 allocated = max_blocks;
2884 set_buffer_unwritten(bh_result);
2885 bh_result->b_bdev = inode->i_sb->s_bdev;
2886 bh_result->b_blocknr = newblock;
2887 goto out2;
2888 }
2889
2890 ret = ext4_ext_convert_to_initialized(handle, inode,
2891 path, iblock,

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

2898 goto outnew;
2899 }
2900 }
2901
2902 /*
2903 * requested block isn't allocated yet;
2904 * we couldn't try to create block if create flag is zero
2905 */
2874 set_buffer_unwritten(bh_result);
2875 bh_result->b_bdev = inode->i_sb->s_bdev;
2876 bh_result->b_blocknr = newblock;
2877 goto out2;
2878 }
2879
2880 ret = ext4_ext_convert_to_initialized(handle, inode,
2881 path, iblock,

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

2888 goto outnew;
2889 }
2890 }
2891
2892 /*
2893 * requested block isn't allocated yet;
2894 * we couldn't try to create block if create flag is zero
2895 */
2906 if (!create) {
2896 if ((flags & EXT4_GET_BLOCKS_CREATE) == 0) {
2907 /*
2908 * put just found gap into cache to speed up
2909 * subsequent requests
2910 */
2911 ext4_ext_put_gap_in_cache(inode, path, iblock);
2912 goto out2;
2913 }
2914 /*

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

2927
2928 /*
2929 * See if request is beyond maximum number of blocks we can have in
2930 * a single extent. For an initialized extent this limit is
2931 * EXT_INIT_MAX_LEN and for an uninitialized extent this limit is
2932 * EXT_UNINIT_MAX_LEN.
2933 */
2934 if (max_blocks > EXT_INIT_MAX_LEN &&
2897 /*
2898 * put just found gap into cache to speed up
2899 * subsequent requests
2900 */
2901 ext4_ext_put_gap_in_cache(inode, path, iblock);
2902 goto out2;
2903 }
2904 /*

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

2917
2918 /*
2919 * See if request is beyond maximum number of blocks we can have in
2920 * a single extent. For an initialized extent this limit is
2921 * EXT_INIT_MAX_LEN and for an uninitialized extent this limit is
2922 * EXT_UNINIT_MAX_LEN.
2923 */
2924 if (max_blocks > EXT_INIT_MAX_LEN &&
2935 create != EXT4_CREATE_UNINITIALIZED_EXT)
2925 !(flags & EXT4_GET_BLOCKS_UNINIT_EXT))
2936 max_blocks = EXT_INIT_MAX_LEN;
2937 else if (max_blocks > EXT_UNINIT_MAX_LEN &&
2926 max_blocks = EXT_INIT_MAX_LEN;
2927 else if (max_blocks > EXT_UNINIT_MAX_LEN &&
2938 create == EXT4_CREATE_UNINITIALIZED_EXT)
2928 (flags & EXT4_GET_BLOCKS_UNINIT_EXT))
2939 max_blocks = EXT_UNINIT_MAX_LEN;
2940
2941 /* Check if we can really insert (iblock)::(iblock+max_blocks) extent */
2942 newex.ee_block = cpu_to_le32(iblock);
2943 newex.ee_len = cpu_to_le16(max_blocks);
2944 err = ext4_ext_check_overlap(inode, &newex, path);
2945 if (err)
2946 allocated = ext4_ext_get_actual_len(&newex);

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

2961 if (!newblock)
2962 goto out2;
2963 ext_debug("allocate new block: goal %llu, found %llu/%lu\n",
2964 ar.goal, newblock, allocated);
2965
2966 /* try to insert new extent into found leaf and return */
2967 ext4_ext_store_pblock(&newex, newblock);
2968 newex.ee_len = cpu_to_le16(ar.len);
2929 max_blocks = EXT_UNINIT_MAX_LEN;
2930
2931 /* Check if we can really insert (iblock)::(iblock+max_blocks) extent */
2932 newex.ee_block = cpu_to_le32(iblock);
2933 newex.ee_len = cpu_to_le16(max_blocks);
2934 err = ext4_ext_check_overlap(inode, &newex, path);
2935 if (err)
2936 allocated = ext4_ext_get_actual_len(&newex);

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

2951 if (!newblock)
2952 goto out2;
2953 ext_debug("allocate new block: goal %llu, found %llu/%lu\n",
2954 ar.goal, newblock, allocated);
2955
2956 /* try to insert new extent into found leaf and return */
2957 ext4_ext_store_pblock(&newex, newblock);
2958 newex.ee_len = cpu_to_le16(ar.len);
2969 if (create == EXT4_CREATE_UNINITIALIZED_EXT) /* Mark uninitialized */
2959 if (flags & EXT4_GET_BLOCKS_UNINIT_EXT) /* Mark uninitialized */
2970 ext4_ext_mark_uninitialized(&newex);
2971 err = ext4_ext_insert_extent(handle, inode, path, &newex);
2972 if (err) {
2973 /* free data blocks we just allocated */
2974 /* not a good idea to call discard here directly,
2975 * but otherwise we'd need to call it every free() */
2976 ext4_discard_preallocations(inode);
2977 ext4_free_blocks(handle, inode, ext_pblock(&newex),
2978 ext4_ext_get_actual_len(&newex), 0);
2979 goto out2;
2980 }
2981
2982 /* previous routine could use block we allocated */
2983 newblock = ext_pblock(&newex);
2984 allocated = ext4_ext_get_actual_len(&newex);
2985outnew:
2960 ext4_ext_mark_uninitialized(&newex);
2961 err = ext4_ext_insert_extent(handle, inode, path, &newex);
2962 if (err) {
2963 /* free data blocks we just allocated */
2964 /* not a good idea to call discard here directly,
2965 * but otherwise we'd need to call it every free() */
2966 ext4_discard_preallocations(inode);
2967 ext4_free_blocks(handle, inode, ext_pblock(&newex),
2968 ext4_ext_get_actual_len(&newex), 0);
2969 goto out2;
2970 }
2971
2972 /* previous routine could use block we allocated */
2973 newblock = ext_pblock(&newex);
2974 allocated = ext4_ext_get_actual_len(&newex);
2975outnew:
2986 if (extend_disksize) {
2987 disksize = ((loff_t) iblock + ar.len) << inode->i_blkbits;
2988 if (disksize > i_size_read(inode))
2989 disksize = i_size_read(inode);
2990 if (disksize > EXT4_I(inode)->i_disksize)
2991 EXT4_I(inode)->i_disksize = disksize;
2992 }
2993
2994 set_buffer_new(bh_result);
2995
2996 /* Cache only when it is _not_ an uninitialized extent */
2976 set_buffer_new(bh_result);
2977
2978 /* Cache only when it is _not_ an uninitialized extent */
2997 if (create != EXT4_CREATE_UNINITIALIZED_EXT)
2979 if ((flags & EXT4_GET_BLOCKS_UNINIT_EXT) == 0)
2998 ext4_ext_put_in_cache(inode, iblock, allocated, newblock,
2999 EXT4_EXT_CACHE_EXTENT);
3000out:
3001 if (allocated > max_blocks)
3002 allocated = max_blocks;
3003 ext4_ext_show_leaf(inode, path);
3004 set_buffer_mapped(bh_result);
3005 bh_result->b_bdev = inode->i_sb->s_bdev;

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

3145 while (ret >= 0 && ret < max_blocks) {
3146 block = block + ret;
3147 max_blocks = max_blocks - ret;
3148 handle = ext4_journal_start(inode, credits);
3149 if (IS_ERR(handle)) {
3150 ret = PTR_ERR(handle);
3151 break;
3152 }
2980 ext4_ext_put_in_cache(inode, iblock, allocated, newblock,
2981 EXT4_EXT_CACHE_EXTENT);
2982out:
2983 if (allocated > max_blocks)
2984 allocated = max_blocks;
2985 ext4_ext_show_leaf(inode, path);
2986 set_buffer_mapped(bh_result);
2987 bh_result->b_bdev = inode->i_sb->s_bdev;

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

3127 while (ret >= 0 && ret < max_blocks) {
3128 block = block + ret;
3129 max_blocks = max_blocks - ret;
3130 handle = ext4_journal_start(inode, credits);
3131 if (IS_ERR(handle)) {
3132 ret = PTR_ERR(handle);
3133 break;
3134 }
3153 ret = ext4_get_blocks_wrap(handle, inode, block,
3154 max_blocks, &map_bh,
3155 EXT4_CREATE_UNINITIALIZED_EXT, 0, 0);
3135 map_bh.b_state = 0;
3136 ret = ext4_get_blocks(handle, inode, block,
3137 max_blocks, &map_bh,
3138 EXT4_GET_BLOCKS_CREATE_UNINIT_EXT);
3156 if (ret <= 0) {
3157#ifdef EXT4FS_DEBUG
3158 WARN_ON(ret <= 0);
3159 printk(KERN_ERR "%s: ext4_ext_get_blocks "
3160 "returned error inode#%lu, block=%u, "
3161 "max_blocks=%u", __func__,
3162 inode->i_ino, block, max_blocks);
3163#endif

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

3190/*
3191 * Callback function called for each extent to gather FIEMAP information.
3192 */
3193static int ext4_ext_fiemap_cb(struct inode *inode, struct ext4_ext_path *path,
3194 struct ext4_ext_cache *newex, struct ext4_extent *ex,
3195 void *data)
3196{
3197 struct fiemap_extent_info *fieinfo = data;
3139 if (ret <= 0) {
3140#ifdef EXT4FS_DEBUG
3141 WARN_ON(ret <= 0);
3142 printk(KERN_ERR "%s: ext4_ext_get_blocks "
3143 "returned error inode#%lu, block=%u, "
3144 "max_blocks=%u", __func__,
3145 inode->i_ino, block, max_blocks);
3146#endif

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

3173/*
3174 * Callback function called for each extent to gather FIEMAP information.
3175 */
3176static int ext4_ext_fiemap_cb(struct inode *inode, struct ext4_ext_path *path,
3177 struct ext4_ext_cache *newex, struct ext4_extent *ex,
3178 void *data)
3179{
3180 struct fiemap_extent_info *fieinfo = data;
3198 unsigned long blksize_bits = inode->i_sb->s_blocksize_bits;
3181 unsigned char blksize_bits = inode->i_sb->s_blocksize_bits;
3199 __u64 logical;
3200 __u64 physical;
3201 __u64 length;
3202 __u32 flags = 0;
3203 int error;
3204
3205 logical = (__u64)newex->ec_block << blksize_bits;
3206

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

3237 /*
3238 * If this extent reaches EXT_MAX_BLOCK, it must be last.
3239 *
3240 * Or if ext4_ext_next_allocated_block is EXT_MAX_BLOCK,
3241 * this also indicates no more allocated blocks.
3242 *
3243 * XXX this might miss a single-block extent at EXT_MAX_BLOCK
3244 */
3182 __u64 logical;
3183 __u64 physical;
3184 __u64 length;
3185 __u32 flags = 0;
3186 int error;
3187
3188 logical = (__u64)newex->ec_block << blksize_bits;
3189

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

3220 /*
3221 * If this extent reaches EXT_MAX_BLOCK, it must be last.
3222 *
3223 * Or if ext4_ext_next_allocated_block is EXT_MAX_BLOCK,
3224 * this also indicates no more allocated blocks.
3225 *
3226 * XXX this might miss a single-block extent at EXT_MAX_BLOCK
3227 */
3245 if (logical + length - 1 == EXT_MAX_BLOCK ||
3246 ext4_ext_next_allocated_block(path) == EXT_MAX_BLOCK)
3228 if (ext4_ext_next_allocated_block(path) == EXT_MAX_BLOCK ||
3229 newex->ec_block + newex->ec_len - 1 == EXT_MAX_BLOCK) {
3230 loff_t size = i_size_read(inode);
3231 loff_t bs = EXT4_BLOCK_SIZE(inode->i_sb);
3232
3247 flags |= FIEMAP_EXTENT_LAST;
3233 flags |= FIEMAP_EXTENT_LAST;
3234 if ((flags & FIEMAP_EXTENT_DELALLOC) &&
3235 logical+length > size)
3236 length = (size - logical + bs - 1) & ~(bs-1);
3237 }
3248
3249 error = fiemap_fill_next_extent(fieinfo, logical, physical,
3250 length, flags);
3251 if (error < 0)
3252 return error;
3253 if (error == 1)
3254 return EXT_BREAK;
3255

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

3313 } else {
3314 start_blk = start >> inode->i_sb->s_blocksize_bits;
3315 len_blks = len >> inode->i_sb->s_blocksize_bits;
3316
3317 /*
3318 * Walk the extent tree gathering extent information.
3319 * ext4_ext_fiemap_cb will push extents back to user.
3320 */
3238
3239 error = fiemap_fill_next_extent(fieinfo, logical, physical,
3240 length, flags);
3241 if (error < 0)
3242 return error;
3243 if (error == 1)
3244 return EXT_BREAK;
3245

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

3303 } else {
3304 start_blk = start >> inode->i_sb->s_blocksize_bits;
3305 len_blks = len >> inode->i_sb->s_blocksize_bits;
3306
3307 /*
3308 * Walk the extent tree gathering extent information.
3309 * ext4_ext_fiemap_cb will push extents back to user.
3310 */
3321 down_write(&EXT4_I(inode)->i_data_sem);
3311 down_read(&EXT4_I(inode)->i_data_sem);
3322 error = ext4_ext_walk_space(inode, start_blk, len_blks,
3323 ext4_ext_fiemap_cb, fieinfo);
3312 error = ext4_ext_walk_space(inode, start_blk, len_blks,
3313 ext4_ext_fiemap_cb, fieinfo);
3324 up_write(&EXT4_I(inode)->i_data_sem);
3314 up_read(&EXT4_I(inode)->i_data_sem);
3325 }
3326
3327 return error;
3328}
3329
3315 }
3316
3317 return error;
3318}
3319