diff options
Diffstat (limited to 'fs/ext4/extents.c')
-rw-r--r-- | fs/ext4/extents.c | 236 |
1 files changed, 120 insertions, 116 deletions
diff --git a/fs/ext4/extents.c b/fs/ext4/extents.c index 01b0c208f625..4da228a0e6d0 100644 --- a/fs/ext4/extents.c +++ b/fs/ext4/extents.c | |||
@@ -50,8 +50,8 @@ | |||
50 | */ | 50 | */ |
51 | #define EXT4_EXT_MAY_ZEROOUT 0x1 /* safe to zeroout if split fails \ | 51 | #define EXT4_EXT_MAY_ZEROOUT 0x1 /* safe to zeroout if split fails \ |
52 | due to ENOSPC */ | 52 | due to ENOSPC */ |
53 | #define EXT4_EXT_MARK_UNINIT1 0x2 /* mark first half uninitialized */ | 53 | #define EXT4_EXT_MARK_UNWRIT1 0x2 /* mark first half unwritten */ |
54 | #define EXT4_EXT_MARK_UNINIT2 0x4 /* mark second half uninitialized */ | 54 | #define EXT4_EXT_MARK_UNWRIT2 0x4 /* mark second half unwritten */ |
55 | 55 | ||
56 | #define EXT4_EXT_DATA_VALID1 0x8 /* first half contains valid data */ | 56 | #define EXT4_EXT_DATA_VALID1 0x8 /* first half contains valid data */ |
57 | #define EXT4_EXT_DATA_VALID2 0x10 /* second half contains valid data */ | 57 | #define EXT4_EXT_DATA_VALID2 0x10 /* second half contains valid data */ |
@@ -143,6 +143,7 @@ static int ext4_ext_get_access(handle_t *handle, struct inode *inode, | |||
143 | { | 143 | { |
144 | if (path->p_bh) { | 144 | if (path->p_bh) { |
145 | /* path points to block */ | 145 | /* path points to block */ |
146 | BUFFER_TRACE(path->p_bh, "get_write_access"); | ||
146 | return ext4_journal_get_write_access(handle, path->p_bh); | 147 | return ext4_journal_get_write_access(handle, path->p_bh); |
147 | } | 148 | } |
148 | /* path points to leaf/index in inode body */ | 149 | /* path points to leaf/index in inode body */ |
@@ -524,7 +525,7 @@ __read_extent_tree_block(const char *function, unsigned int line, | |||
524 | lblk - prev, ~0, | 525 | lblk - prev, ~0, |
525 | EXTENT_STATUS_HOLE); | 526 | EXTENT_STATUS_HOLE); |
526 | 527 | ||
527 | if (ext4_ext_is_uninitialized(ex)) | 528 | if (ext4_ext_is_unwritten(ex)) |
528 | status = EXTENT_STATUS_UNWRITTEN; | 529 | status = EXTENT_STATUS_UNWRITTEN; |
529 | ext4_es_cache_extent(inode, lblk, len, | 530 | ext4_es_cache_extent(inode, lblk, len, |
530 | ext4_ext_pblock(ex), status); | 531 | ext4_ext_pblock(ex), status); |
@@ -620,7 +621,7 @@ static void ext4_ext_show_path(struct inode *inode, struct ext4_ext_path *path) | |||
620 | } else if (path->p_ext) { | 621 | } else if (path->p_ext) { |
621 | ext_debug(" %d:[%d]%d:%llu ", | 622 | ext_debug(" %d:[%d]%d:%llu ", |
622 | le32_to_cpu(path->p_ext->ee_block), | 623 | le32_to_cpu(path->p_ext->ee_block), |
623 | ext4_ext_is_uninitialized(path->p_ext), | 624 | ext4_ext_is_unwritten(path->p_ext), |
624 | ext4_ext_get_actual_len(path->p_ext), | 625 | ext4_ext_get_actual_len(path->p_ext), |
625 | ext4_ext_pblock(path->p_ext)); | 626 | ext4_ext_pblock(path->p_ext)); |
626 | } else | 627 | } else |
@@ -646,7 +647,7 @@ static void ext4_ext_show_leaf(struct inode *inode, struct ext4_ext_path *path) | |||
646 | 647 | ||
647 | for (i = 0; i < le16_to_cpu(eh->eh_entries); i++, ex++) { | 648 | for (i = 0; i < le16_to_cpu(eh->eh_entries); i++, ex++) { |
648 | ext_debug("%d:[%d]%d:%llu ", le32_to_cpu(ex->ee_block), | 649 | ext_debug("%d:[%d]%d:%llu ", le32_to_cpu(ex->ee_block), |
649 | ext4_ext_is_uninitialized(ex), | 650 | ext4_ext_is_unwritten(ex), |
650 | ext4_ext_get_actual_len(ex), ext4_ext_pblock(ex)); | 651 | ext4_ext_get_actual_len(ex), ext4_ext_pblock(ex)); |
651 | } | 652 | } |
652 | ext_debug("\n"); | 653 | ext_debug("\n"); |
@@ -677,7 +678,7 @@ static void ext4_ext_show_move(struct inode *inode, struct ext4_ext_path *path, | |||
677 | ext_debug("move %d:%llu:[%d]%d in new leaf %llu\n", | 678 | ext_debug("move %d:%llu:[%d]%d in new leaf %llu\n", |
678 | le32_to_cpu(ex->ee_block), | 679 | le32_to_cpu(ex->ee_block), |
679 | ext4_ext_pblock(ex), | 680 | ext4_ext_pblock(ex), |
680 | ext4_ext_is_uninitialized(ex), | 681 | ext4_ext_is_unwritten(ex), |
681 | ext4_ext_get_actual_len(ex), | 682 | ext4_ext_get_actual_len(ex), |
682 | newblock); | 683 | newblock); |
683 | ex++; | 684 | ex++; |
@@ -802,7 +803,7 @@ ext4_ext_binsearch(struct inode *inode, | |||
802 | ext_debug(" -> %d:%llu:[%d]%d ", | 803 | ext_debug(" -> %d:%llu:[%d]%d ", |
803 | le32_to_cpu(path->p_ext->ee_block), | 804 | le32_to_cpu(path->p_ext->ee_block), |
804 | ext4_ext_pblock(path->p_ext), | 805 | ext4_ext_pblock(path->p_ext), |
805 | ext4_ext_is_uninitialized(path->p_ext), | 806 | ext4_ext_is_unwritten(path->p_ext), |
806 | ext4_ext_get_actual_len(path->p_ext)); | 807 | ext4_ext_get_actual_len(path->p_ext)); |
807 | 808 | ||
808 | #ifdef CHECK_BINSEARCH | 809 | #ifdef CHECK_BINSEARCH |
@@ -1686,11 +1687,11 @@ ext4_can_extents_be_merged(struct inode *inode, struct ext4_extent *ex1, | |||
1686 | 1687 | ||
1687 | /* | 1688 | /* |
1688 | * Make sure that both extents are initialized. We don't merge | 1689 | * Make sure that both extents are initialized. We don't merge |
1689 | * uninitialized extents so that we can be sure that end_io code has | 1690 | * unwritten extents so that we can be sure that end_io code has |
1690 | * the extent that was written properly split out and conversion to | 1691 | * the extent that was written properly split out and conversion to |
1691 | * initialized is trivial. | 1692 | * initialized is trivial. |
1692 | */ | 1693 | */ |
1693 | if (ext4_ext_is_uninitialized(ex1) != ext4_ext_is_uninitialized(ex2)) | 1694 | if (ext4_ext_is_unwritten(ex1) != ext4_ext_is_unwritten(ex2)) |
1694 | return 0; | 1695 | return 0; |
1695 | 1696 | ||
1696 | ext1_ee_len = ext4_ext_get_actual_len(ex1); | 1697 | ext1_ee_len = ext4_ext_get_actual_len(ex1); |
@@ -1707,10 +1708,10 @@ ext4_can_extents_be_merged(struct inode *inode, struct ext4_extent *ex1, | |||
1707 | */ | 1708 | */ |
1708 | if (ext1_ee_len + ext2_ee_len > EXT_INIT_MAX_LEN) | 1709 | if (ext1_ee_len + ext2_ee_len > EXT_INIT_MAX_LEN) |
1709 | return 0; | 1710 | return 0; |
1710 | if (ext4_ext_is_uninitialized(ex1) && | 1711 | if (ext4_ext_is_unwritten(ex1) && |
1711 | (ext4_test_inode_state(inode, EXT4_STATE_DIO_UNWRITTEN) || | 1712 | (ext4_test_inode_state(inode, EXT4_STATE_DIO_UNWRITTEN) || |
1712 | atomic_read(&EXT4_I(inode)->i_unwritten) || | 1713 | atomic_read(&EXT4_I(inode)->i_unwritten) || |
1713 | (ext1_ee_len + ext2_ee_len > EXT_UNINIT_MAX_LEN))) | 1714 | (ext1_ee_len + ext2_ee_len > EXT_UNWRITTEN_MAX_LEN))) |
1714 | return 0; | 1715 | return 0; |
1715 | #ifdef AGGRESSIVE_TEST | 1716 | #ifdef AGGRESSIVE_TEST |
1716 | if (ext1_ee_len >= 4) | 1717 | if (ext1_ee_len >= 4) |
@@ -1735,7 +1736,7 @@ static int ext4_ext_try_to_merge_right(struct inode *inode, | |||
1735 | { | 1736 | { |
1736 | struct ext4_extent_header *eh; | 1737 | struct ext4_extent_header *eh; |
1737 | unsigned int depth, len; | 1738 | unsigned int depth, len; |
1738 | int merge_done = 0, uninit; | 1739 | int merge_done = 0, unwritten; |
1739 | 1740 | ||
1740 | depth = ext_depth(inode); | 1741 | depth = ext_depth(inode); |
1741 | BUG_ON(path[depth].p_hdr == NULL); | 1742 | BUG_ON(path[depth].p_hdr == NULL); |
@@ -1745,11 +1746,11 @@ static int ext4_ext_try_to_merge_right(struct inode *inode, | |||
1745 | if (!ext4_can_extents_be_merged(inode, ex, ex + 1)) | 1746 | if (!ext4_can_extents_be_merged(inode, ex, ex + 1)) |
1746 | break; | 1747 | break; |
1747 | /* merge with next extent! */ | 1748 | /* merge with next extent! */ |
1748 | uninit = ext4_ext_is_uninitialized(ex); | 1749 | unwritten = ext4_ext_is_unwritten(ex); |
1749 | ex->ee_len = cpu_to_le16(ext4_ext_get_actual_len(ex) | 1750 | ex->ee_len = cpu_to_le16(ext4_ext_get_actual_len(ex) |
1750 | + ext4_ext_get_actual_len(ex + 1)); | 1751 | + ext4_ext_get_actual_len(ex + 1)); |
1751 | if (uninit) | 1752 | if (unwritten) |
1752 | ext4_ext_mark_uninitialized(ex); | 1753 | ext4_ext_mark_unwritten(ex); |
1753 | 1754 | ||
1754 | if (ex + 1 < EXT_LAST_EXTENT(eh)) { | 1755 | if (ex + 1 < EXT_LAST_EXTENT(eh)) { |
1755 | len = (EXT_LAST_EXTENT(eh) - ex - 1) | 1756 | len = (EXT_LAST_EXTENT(eh) - ex - 1) |
@@ -1903,7 +1904,7 @@ int ext4_ext_insert_extent(handle_t *handle, struct inode *inode, | |||
1903 | struct ext4_ext_path *npath = NULL; | 1904 | struct ext4_ext_path *npath = NULL; |
1904 | int depth, len, err; | 1905 | int depth, len, err; |
1905 | ext4_lblk_t next; | 1906 | ext4_lblk_t next; |
1906 | int mb_flags = 0, uninit; | 1907 | int mb_flags = 0, unwritten; |
1907 | 1908 | ||
1908 | if (unlikely(ext4_ext_get_actual_len(newext) == 0)) { | 1909 | if (unlikely(ext4_ext_get_actual_len(newext) == 0)) { |
1909 | EXT4_ERROR_INODE(inode, "ext4_ext_get_actual_len(newext) == 0"); | 1910 | EXT4_ERROR_INODE(inode, "ext4_ext_get_actual_len(newext) == 0"); |
@@ -1943,21 +1944,21 @@ int ext4_ext_insert_extent(handle_t *handle, struct inode *inode, | |||
1943 | if (ext4_can_extents_be_merged(inode, ex, newext)) { | 1944 | if (ext4_can_extents_be_merged(inode, ex, newext)) { |
1944 | ext_debug("append [%d]%d block to %u:[%d]%d" | 1945 | ext_debug("append [%d]%d block to %u:[%d]%d" |
1945 | "(from %llu)\n", | 1946 | "(from %llu)\n", |
1946 | ext4_ext_is_uninitialized(newext), | 1947 | ext4_ext_is_unwritten(newext), |
1947 | ext4_ext_get_actual_len(newext), | 1948 | ext4_ext_get_actual_len(newext), |
1948 | le32_to_cpu(ex->ee_block), | 1949 | le32_to_cpu(ex->ee_block), |
1949 | ext4_ext_is_uninitialized(ex), | 1950 | ext4_ext_is_unwritten(ex), |
1950 | ext4_ext_get_actual_len(ex), | 1951 | ext4_ext_get_actual_len(ex), |
1951 | ext4_ext_pblock(ex)); | 1952 | ext4_ext_pblock(ex)); |
1952 | err = ext4_ext_get_access(handle, inode, | 1953 | err = ext4_ext_get_access(handle, inode, |
1953 | path + depth); | 1954 | path + depth); |
1954 | if (err) | 1955 | if (err) |
1955 | return err; | 1956 | return err; |
1956 | uninit = ext4_ext_is_uninitialized(ex); | 1957 | unwritten = ext4_ext_is_unwritten(ex); |
1957 | ex->ee_len = cpu_to_le16(ext4_ext_get_actual_len(ex) | 1958 | ex->ee_len = cpu_to_le16(ext4_ext_get_actual_len(ex) |
1958 | + ext4_ext_get_actual_len(newext)); | 1959 | + ext4_ext_get_actual_len(newext)); |
1959 | if (uninit) | 1960 | if (unwritten) |
1960 | ext4_ext_mark_uninitialized(ex); | 1961 | ext4_ext_mark_unwritten(ex); |
1961 | eh = path[depth].p_hdr; | 1962 | eh = path[depth].p_hdr; |
1962 | nearex = ex; | 1963 | nearex = ex; |
1963 | goto merge; | 1964 | goto merge; |
@@ -1969,10 +1970,10 @@ prepend: | |||
1969 | ext_debug("prepend %u[%d]%d block to %u:[%d]%d" | 1970 | ext_debug("prepend %u[%d]%d block to %u:[%d]%d" |
1970 | "(from %llu)\n", | 1971 | "(from %llu)\n", |
1971 | le32_to_cpu(newext->ee_block), | 1972 | le32_to_cpu(newext->ee_block), |
1972 | ext4_ext_is_uninitialized(newext), | 1973 | ext4_ext_is_unwritten(newext), |
1973 | ext4_ext_get_actual_len(newext), | 1974 | ext4_ext_get_actual_len(newext), |
1974 | le32_to_cpu(ex->ee_block), | 1975 | le32_to_cpu(ex->ee_block), |
1975 | ext4_ext_is_uninitialized(ex), | 1976 | ext4_ext_is_unwritten(ex), |
1976 | ext4_ext_get_actual_len(ex), | 1977 | ext4_ext_get_actual_len(ex), |
1977 | ext4_ext_pblock(ex)); | 1978 | ext4_ext_pblock(ex)); |
1978 | err = ext4_ext_get_access(handle, inode, | 1979 | err = ext4_ext_get_access(handle, inode, |
@@ -1980,13 +1981,13 @@ prepend: | |||
1980 | if (err) | 1981 | if (err) |
1981 | return err; | 1982 | return err; |
1982 | 1983 | ||
1983 | uninit = ext4_ext_is_uninitialized(ex); | 1984 | unwritten = ext4_ext_is_unwritten(ex); |
1984 | ex->ee_block = newext->ee_block; | 1985 | ex->ee_block = newext->ee_block; |
1985 | ext4_ext_store_pblock(ex, ext4_ext_pblock(newext)); | 1986 | ext4_ext_store_pblock(ex, ext4_ext_pblock(newext)); |
1986 | ex->ee_len = cpu_to_le16(ext4_ext_get_actual_len(ex) | 1987 | ex->ee_len = cpu_to_le16(ext4_ext_get_actual_len(ex) |
1987 | + ext4_ext_get_actual_len(newext)); | 1988 | + ext4_ext_get_actual_len(newext)); |
1988 | if (uninit) | 1989 | if (unwritten) |
1989 | ext4_ext_mark_uninitialized(ex); | 1990 | ext4_ext_mark_unwritten(ex); |
1990 | eh = path[depth].p_hdr; | 1991 | eh = path[depth].p_hdr; |
1991 | nearex = ex; | 1992 | nearex = ex; |
1992 | goto merge; | 1993 | goto merge; |
@@ -2046,7 +2047,7 @@ has_space: | |||
2046 | ext_debug("first extent in the leaf: %u:%llu:[%d]%d\n", | 2047 | ext_debug("first extent in the leaf: %u:%llu:[%d]%d\n", |
2047 | le32_to_cpu(newext->ee_block), | 2048 | le32_to_cpu(newext->ee_block), |
2048 | ext4_ext_pblock(newext), | 2049 | ext4_ext_pblock(newext), |
2049 | ext4_ext_is_uninitialized(newext), | 2050 | ext4_ext_is_unwritten(newext), |
2050 | ext4_ext_get_actual_len(newext)); | 2051 | ext4_ext_get_actual_len(newext)); |
2051 | nearex = EXT_FIRST_EXTENT(eh); | 2052 | nearex = EXT_FIRST_EXTENT(eh); |
2052 | } else { | 2053 | } else { |
@@ -2057,7 +2058,7 @@ has_space: | |||
2057 | "nearest %p\n", | 2058 | "nearest %p\n", |
2058 | le32_to_cpu(newext->ee_block), | 2059 | le32_to_cpu(newext->ee_block), |
2059 | ext4_ext_pblock(newext), | 2060 | ext4_ext_pblock(newext), |
2060 | ext4_ext_is_uninitialized(newext), | 2061 | ext4_ext_is_unwritten(newext), |
2061 | ext4_ext_get_actual_len(newext), | 2062 | ext4_ext_get_actual_len(newext), |
2062 | nearex); | 2063 | nearex); |
2063 | nearex++; | 2064 | nearex++; |
@@ -2068,7 +2069,7 @@ has_space: | |||
2068 | "nearest %p\n", | 2069 | "nearest %p\n", |
2069 | le32_to_cpu(newext->ee_block), | 2070 | le32_to_cpu(newext->ee_block), |
2070 | ext4_ext_pblock(newext), | 2071 | ext4_ext_pblock(newext), |
2071 | ext4_ext_is_uninitialized(newext), | 2072 | ext4_ext_is_unwritten(newext), |
2072 | ext4_ext_get_actual_len(newext), | 2073 | ext4_ext_get_actual_len(newext), |
2073 | nearex); | 2074 | nearex); |
2074 | } | 2075 | } |
@@ -2078,7 +2079,7 @@ has_space: | |||
2078 | "move %d extents from 0x%p to 0x%p\n", | 2079 | "move %d extents from 0x%p to 0x%p\n", |
2079 | le32_to_cpu(newext->ee_block), | 2080 | le32_to_cpu(newext->ee_block), |
2080 | ext4_ext_pblock(newext), | 2081 | ext4_ext_pblock(newext), |
2081 | ext4_ext_is_uninitialized(newext), | 2082 | ext4_ext_is_unwritten(newext), |
2082 | ext4_ext_get_actual_len(newext), | 2083 | ext4_ext_get_actual_len(newext), |
2083 | len, nearex, nearex + 1); | 2084 | len, nearex, nearex + 1); |
2084 | memmove(nearex + 1, nearex, | 2085 | memmove(nearex + 1, nearex, |
@@ -2200,7 +2201,7 @@ static int ext4_fill_fiemap_extents(struct inode *inode, | |||
2200 | es.es_lblk = le32_to_cpu(ex->ee_block); | 2201 | es.es_lblk = le32_to_cpu(ex->ee_block); |
2201 | es.es_len = ext4_ext_get_actual_len(ex); | 2202 | es.es_len = ext4_ext_get_actual_len(ex); |
2202 | es.es_pblk = ext4_ext_pblock(ex); | 2203 | es.es_pblk = ext4_ext_pblock(ex); |
2203 | if (ext4_ext_is_uninitialized(ex)) | 2204 | if (ext4_ext_is_unwritten(ex)) |
2204 | flags |= FIEMAP_EXTENT_UNWRITTEN; | 2205 | flags |= FIEMAP_EXTENT_UNWRITTEN; |
2205 | } | 2206 | } |
2206 | 2207 | ||
@@ -2576,7 +2577,7 @@ ext4_ext_rm_leaf(handle_t *handle, struct inode *inode, | |||
2576 | unsigned num; | 2577 | unsigned num; |
2577 | ext4_lblk_t ex_ee_block; | 2578 | ext4_lblk_t ex_ee_block; |
2578 | unsigned short ex_ee_len; | 2579 | unsigned short ex_ee_len; |
2579 | unsigned uninitialized = 0; | 2580 | unsigned unwritten = 0; |
2580 | struct ext4_extent *ex; | 2581 | struct ext4_extent *ex; |
2581 | ext4_fsblk_t pblk; | 2582 | ext4_fsblk_t pblk; |
2582 | 2583 | ||
@@ -2623,13 +2624,13 @@ ext4_ext_rm_leaf(handle_t *handle, struct inode *inode, | |||
2623 | while (ex >= EXT_FIRST_EXTENT(eh) && | 2624 | while (ex >= EXT_FIRST_EXTENT(eh) && |
2624 | ex_ee_block + ex_ee_len > start) { | 2625 | ex_ee_block + ex_ee_len > start) { |
2625 | 2626 | ||
2626 | if (ext4_ext_is_uninitialized(ex)) | 2627 | if (ext4_ext_is_unwritten(ex)) |
2627 | uninitialized = 1; | 2628 | unwritten = 1; |
2628 | else | 2629 | else |
2629 | uninitialized = 0; | 2630 | unwritten = 0; |
2630 | 2631 | ||
2631 | ext_debug("remove ext %u:[%d]%d\n", ex_ee_block, | 2632 | ext_debug("remove ext %u:[%d]%d\n", ex_ee_block, |
2632 | uninitialized, ex_ee_len); | 2633 | unwritten, ex_ee_len); |
2633 | path[depth].p_ext = ex; | 2634 | path[depth].p_ext = ex; |
2634 | 2635 | ||
2635 | a = ex_ee_block > start ? ex_ee_block : start; | 2636 | a = ex_ee_block > start ? ex_ee_block : start; |
@@ -2701,11 +2702,11 @@ ext4_ext_rm_leaf(handle_t *handle, struct inode *inode, | |||
2701 | 2702 | ||
2702 | ex->ee_len = cpu_to_le16(num); | 2703 | ex->ee_len = cpu_to_le16(num); |
2703 | /* | 2704 | /* |
2704 | * Do not mark uninitialized if all the blocks in the | 2705 | * Do not mark unwritten if all the blocks in the |
2705 | * extent have been removed. | 2706 | * extent have been removed. |
2706 | */ | 2707 | */ |
2707 | if (uninitialized && num) | 2708 | if (unwritten && num) |
2708 | ext4_ext_mark_uninitialized(ex); | 2709 | ext4_ext_mark_unwritten(ex); |
2709 | /* | 2710 | /* |
2710 | * If the extent was completely released, | 2711 | * If the extent was completely released, |
2711 | * we need to remove it from the leaf | 2712 | * we need to remove it from the leaf |
@@ -2854,9 +2855,9 @@ again: | |||
2854 | end < ee_block + ext4_ext_get_actual_len(ex) - 1) { | 2855 | end < ee_block + ext4_ext_get_actual_len(ex) - 1) { |
2855 | int split_flag = 0; | 2856 | int split_flag = 0; |
2856 | 2857 | ||
2857 | if (ext4_ext_is_uninitialized(ex)) | 2858 | if (ext4_ext_is_unwritten(ex)) |
2858 | split_flag = EXT4_EXT_MARK_UNINIT1 | | 2859 | split_flag = EXT4_EXT_MARK_UNWRIT1 | |
2859 | EXT4_EXT_MARK_UNINIT2; | 2860 | EXT4_EXT_MARK_UNWRIT2; |
2860 | 2861 | ||
2861 | /* | 2862 | /* |
2862 | * Split the extent in two so that 'end' is the last | 2863 | * Split the extent in two so that 'end' is the last |
@@ -3113,7 +3114,7 @@ static int ext4_ext_zeroout(struct inode *inode, struct ext4_extent *ex) | |||
3113 | * @path: the path to the extent | 3114 | * @path: the path to the extent |
3114 | * @split: the logical block where the extent is splitted. | 3115 | * @split: the logical block where the extent is splitted. |
3115 | * @split_flags: indicates if the extent could be zeroout if split fails, and | 3116 | * @split_flags: indicates if the extent could be zeroout if split fails, and |
3116 | * the states(init or uninit) of new extents. | 3117 | * the states(init or unwritten) of new extents. |
3117 | * @flags: flags used to insert new extent to extent tree. | 3118 | * @flags: flags used to insert new extent to extent tree. |
3118 | * | 3119 | * |
3119 | * | 3120 | * |
@@ -3155,10 +3156,10 @@ static int ext4_split_extent_at(handle_t *handle, | |||
3155 | newblock = split - ee_block + ext4_ext_pblock(ex); | 3156 | newblock = split - ee_block + ext4_ext_pblock(ex); |
3156 | 3157 | ||
3157 | BUG_ON(split < ee_block || split >= (ee_block + ee_len)); | 3158 | BUG_ON(split < ee_block || split >= (ee_block + ee_len)); |
3158 | BUG_ON(!ext4_ext_is_uninitialized(ex) && | 3159 | BUG_ON(!ext4_ext_is_unwritten(ex) && |
3159 | split_flag & (EXT4_EXT_MAY_ZEROOUT | | 3160 | split_flag & (EXT4_EXT_MAY_ZEROOUT | |
3160 | EXT4_EXT_MARK_UNINIT1 | | 3161 | EXT4_EXT_MARK_UNWRIT1 | |
3161 | EXT4_EXT_MARK_UNINIT2)); | 3162 | EXT4_EXT_MARK_UNWRIT2)); |
3162 | 3163 | ||
3163 | err = ext4_ext_get_access(handle, inode, path + depth); | 3164 | err = ext4_ext_get_access(handle, inode, path + depth); |
3164 | if (err) | 3165 | if (err) |
@@ -3170,8 +3171,8 @@ static int ext4_split_extent_at(handle_t *handle, | |||
3170 | * then we just change the state of the extent, and splitting | 3171 | * then we just change the state of the extent, and splitting |
3171 | * is not needed. | 3172 | * is not needed. |
3172 | */ | 3173 | */ |
3173 | if (split_flag & EXT4_EXT_MARK_UNINIT2) | 3174 | if (split_flag & EXT4_EXT_MARK_UNWRIT2) |
3174 | ext4_ext_mark_uninitialized(ex); | 3175 | ext4_ext_mark_unwritten(ex); |
3175 | else | 3176 | else |
3176 | ext4_ext_mark_initialized(ex); | 3177 | ext4_ext_mark_initialized(ex); |
3177 | 3178 | ||
@@ -3185,8 +3186,8 @@ static int ext4_split_extent_at(handle_t *handle, | |||
3185 | /* case a */ | 3186 | /* case a */ |
3186 | memcpy(&orig_ex, ex, sizeof(orig_ex)); | 3187 | memcpy(&orig_ex, ex, sizeof(orig_ex)); |
3187 | ex->ee_len = cpu_to_le16(split - ee_block); | 3188 | ex->ee_len = cpu_to_le16(split - ee_block); |
3188 | if (split_flag & EXT4_EXT_MARK_UNINIT1) | 3189 | if (split_flag & EXT4_EXT_MARK_UNWRIT1) |
3189 | ext4_ext_mark_uninitialized(ex); | 3190 | ext4_ext_mark_unwritten(ex); |
3190 | 3191 | ||
3191 | /* | 3192 | /* |
3192 | * path may lead to new leaf, not to original leaf any more | 3193 | * path may lead to new leaf, not to original leaf any more |
@@ -3200,8 +3201,8 @@ static int ext4_split_extent_at(handle_t *handle, | |||
3200 | ex2->ee_block = cpu_to_le32(split); | 3201 | ex2->ee_block = cpu_to_le32(split); |
3201 | ex2->ee_len = cpu_to_le16(ee_len - (split - ee_block)); | 3202 | ex2->ee_len = cpu_to_le16(ee_len - (split - ee_block)); |
3202 | ext4_ext_store_pblock(ex2, newblock); | 3203 | ext4_ext_store_pblock(ex2, newblock); |
3203 | if (split_flag & EXT4_EXT_MARK_UNINIT2) | 3204 | if (split_flag & EXT4_EXT_MARK_UNWRIT2) |
3204 | ext4_ext_mark_uninitialized(ex2); | 3205 | ext4_ext_mark_unwritten(ex2); |
3205 | 3206 | ||
3206 | err = ext4_ext_insert_extent(handle, inode, path, &newex, flags); | 3207 | err = ext4_ext_insert_extent(handle, inode, path, &newex, flags); |
3207 | if (err == -ENOSPC && (EXT4_EXT_MAY_ZEROOUT & split_flag)) { | 3208 | if (err == -ENOSPC && (EXT4_EXT_MAY_ZEROOUT & split_flag)) { |
@@ -3278,7 +3279,7 @@ static int ext4_split_extent(handle_t *handle, | |||
3278 | struct ext4_extent *ex; | 3279 | struct ext4_extent *ex; |
3279 | unsigned int ee_len, depth; | 3280 | unsigned int ee_len, depth; |
3280 | int err = 0; | 3281 | int err = 0; |
3281 | int uninitialized; | 3282 | int unwritten; |
3282 | int split_flag1, flags1; | 3283 | int split_flag1, flags1; |
3283 | int allocated = map->m_len; | 3284 | int allocated = map->m_len; |
3284 | 3285 | ||
@@ -3286,14 +3287,14 @@ static int ext4_split_extent(handle_t *handle, | |||
3286 | ex = path[depth].p_ext; | 3287 | ex = path[depth].p_ext; |
3287 | ee_block = le32_to_cpu(ex->ee_block); | 3288 | ee_block = le32_to_cpu(ex->ee_block); |
3288 | ee_len = ext4_ext_get_actual_len(ex); | 3289 | ee_len = ext4_ext_get_actual_len(ex); |
3289 | uninitialized = ext4_ext_is_uninitialized(ex); | 3290 | unwritten = ext4_ext_is_unwritten(ex); |
3290 | 3291 | ||
3291 | if (map->m_lblk + map->m_len < ee_block + ee_len) { | 3292 | if (map->m_lblk + map->m_len < ee_block + ee_len) { |
3292 | split_flag1 = split_flag & EXT4_EXT_MAY_ZEROOUT; | 3293 | split_flag1 = split_flag & EXT4_EXT_MAY_ZEROOUT; |
3293 | flags1 = flags | EXT4_GET_BLOCKS_PRE_IO; | 3294 | flags1 = flags | EXT4_GET_BLOCKS_PRE_IO; |
3294 | if (uninitialized) | 3295 | if (unwritten) |
3295 | split_flag1 |= EXT4_EXT_MARK_UNINIT1 | | 3296 | split_flag1 |= EXT4_EXT_MARK_UNWRIT1 | |
3296 | EXT4_EXT_MARK_UNINIT2; | 3297 | EXT4_EXT_MARK_UNWRIT2; |
3297 | if (split_flag & EXT4_EXT_DATA_VALID2) | 3298 | if (split_flag & EXT4_EXT_DATA_VALID2) |
3298 | split_flag1 |= EXT4_EXT_DATA_VALID1; | 3299 | split_flag1 |= EXT4_EXT_DATA_VALID1; |
3299 | err = ext4_split_extent_at(handle, inode, path, | 3300 | err = ext4_split_extent_at(handle, inode, path, |
@@ -3318,15 +3319,15 @@ static int ext4_split_extent(handle_t *handle, | |||
3318 | (unsigned long) map->m_lblk); | 3319 | (unsigned long) map->m_lblk); |
3319 | return -EIO; | 3320 | return -EIO; |
3320 | } | 3321 | } |
3321 | uninitialized = ext4_ext_is_uninitialized(ex); | 3322 | unwritten = ext4_ext_is_unwritten(ex); |
3322 | split_flag1 = 0; | 3323 | split_flag1 = 0; |
3323 | 3324 | ||
3324 | if (map->m_lblk >= ee_block) { | 3325 | if (map->m_lblk >= ee_block) { |
3325 | split_flag1 = split_flag & EXT4_EXT_DATA_VALID2; | 3326 | split_flag1 = split_flag & EXT4_EXT_DATA_VALID2; |
3326 | if (uninitialized) { | 3327 | if (unwritten) { |
3327 | split_flag1 |= EXT4_EXT_MARK_UNINIT1; | 3328 | split_flag1 |= EXT4_EXT_MARK_UNWRIT1; |
3328 | split_flag1 |= split_flag & (EXT4_EXT_MAY_ZEROOUT | | 3329 | split_flag1 |= split_flag & (EXT4_EXT_MAY_ZEROOUT | |
3329 | EXT4_EXT_MARK_UNINIT2); | 3330 | EXT4_EXT_MARK_UNWRIT2); |
3330 | } | 3331 | } |
3331 | err = ext4_split_extent_at(handle, inode, path, | 3332 | err = ext4_split_extent_at(handle, inode, path, |
3332 | map->m_lblk, split_flag1, flags); | 3333 | map->m_lblk, split_flag1, flags); |
@@ -3341,16 +3342,16 @@ out: | |||
3341 | 3342 | ||
3342 | /* | 3343 | /* |
3343 | * This function is called by ext4_ext_map_blocks() if someone tries to write | 3344 | * This function is called by ext4_ext_map_blocks() if someone tries to write |
3344 | * to an uninitialized extent. It may result in splitting the uninitialized | 3345 | * to an unwritten extent. It may result in splitting the unwritten |
3345 | * extent into multiple extents (up to three - one initialized and two | 3346 | * extent into multiple extents (up to three - one initialized and two |
3346 | * uninitialized). | 3347 | * unwritten). |
3347 | * There are three possibilities: | 3348 | * There are three possibilities: |
3348 | * a> There is no split required: Entire extent should be initialized | 3349 | * a> There is no split required: Entire extent should be initialized |
3349 | * b> Splits in two extents: Write is happening at either end of the extent | 3350 | * b> Splits in two extents: Write is happening at either end of the extent |
3350 | * c> Splits in three extents: Somone is writing in middle of the extent | 3351 | * c> Splits in three extents: Somone is writing in middle of the extent |
3351 | * | 3352 | * |
3352 | * Pre-conditions: | 3353 | * Pre-conditions: |
3353 | * - The extent pointed to by 'path' is uninitialized. | 3354 | * - The extent pointed to by 'path' is unwritten. |
3354 | * - The extent pointed to by 'path' contains a superset | 3355 | * - The extent pointed to by 'path' contains a superset |
3355 | * of the logical span [map->m_lblk, map->m_lblk + map->m_len). | 3356 | * of the logical span [map->m_lblk, map->m_lblk + map->m_len). |
3356 | * | 3357 | * |
@@ -3396,12 +3397,12 @@ static int ext4_ext_convert_to_initialized(handle_t *handle, | |||
3396 | trace_ext4_ext_convert_to_initialized_enter(inode, map, ex); | 3397 | trace_ext4_ext_convert_to_initialized_enter(inode, map, ex); |
3397 | 3398 | ||
3398 | /* Pre-conditions */ | 3399 | /* Pre-conditions */ |
3399 | BUG_ON(!ext4_ext_is_uninitialized(ex)); | 3400 | BUG_ON(!ext4_ext_is_unwritten(ex)); |
3400 | BUG_ON(!in_range(map->m_lblk, ee_block, ee_len)); | 3401 | BUG_ON(!in_range(map->m_lblk, ee_block, ee_len)); |
3401 | 3402 | ||
3402 | /* | 3403 | /* |
3403 | * Attempt to transfer newly initialized blocks from the currently | 3404 | * Attempt to transfer newly initialized blocks from the currently |
3404 | * uninitialized extent to its neighbor. This is much cheaper | 3405 | * unwritten extent to its neighbor. This is much cheaper |
3405 | * than an insertion followed by a merge as those involve costly | 3406 | * than an insertion followed by a merge as those involve costly |
3406 | * memmove() calls. Transferring to the left is the common case in | 3407 | * memmove() calls. Transferring to the left is the common case in |
3407 | * steady state for workloads doing fallocate(FALLOC_FL_KEEP_SIZE) | 3408 | * steady state for workloads doing fallocate(FALLOC_FL_KEEP_SIZE) |
@@ -3437,7 +3438,7 @@ static int ext4_ext_convert_to_initialized(handle_t *handle, | |||
3437 | * - C4: abut_ex can receive the additional blocks without | 3438 | * - C4: abut_ex can receive the additional blocks without |
3438 | * overflowing the (initialized) length limit. | 3439 | * overflowing the (initialized) length limit. |
3439 | */ | 3440 | */ |
3440 | if ((!ext4_ext_is_uninitialized(abut_ex)) && /*C1*/ | 3441 | if ((!ext4_ext_is_unwritten(abut_ex)) && /*C1*/ |
3441 | ((prev_lblk + prev_len) == ee_block) && /*C2*/ | 3442 | ((prev_lblk + prev_len) == ee_block) && /*C2*/ |
3442 | ((prev_pblk + prev_len) == ee_pblk) && /*C3*/ | 3443 | ((prev_pblk + prev_len) == ee_pblk) && /*C3*/ |
3443 | (prev_len < (EXT_INIT_MAX_LEN - map_len))) { /*C4*/ | 3444 | (prev_len < (EXT_INIT_MAX_LEN - map_len))) { /*C4*/ |
@@ -3452,7 +3453,7 @@ static int ext4_ext_convert_to_initialized(handle_t *handle, | |||
3452 | ex->ee_block = cpu_to_le32(ee_block + map_len); | 3453 | ex->ee_block = cpu_to_le32(ee_block + map_len); |
3453 | ext4_ext_store_pblock(ex, ee_pblk + map_len); | 3454 | ext4_ext_store_pblock(ex, ee_pblk + map_len); |
3454 | ex->ee_len = cpu_to_le16(ee_len - map_len); | 3455 | ex->ee_len = cpu_to_le16(ee_len - map_len); |
3455 | ext4_ext_mark_uninitialized(ex); /* Restore the flag */ | 3456 | ext4_ext_mark_unwritten(ex); /* Restore the flag */ |
3456 | 3457 | ||
3457 | /* Extend abut_ex by 'map_len' blocks */ | 3458 | /* Extend abut_ex by 'map_len' blocks */ |
3458 | abut_ex->ee_len = cpu_to_le16(prev_len + map_len); | 3459 | abut_ex->ee_len = cpu_to_le16(prev_len + map_len); |
@@ -3483,7 +3484,7 @@ static int ext4_ext_convert_to_initialized(handle_t *handle, | |||
3483 | * - C4: abut_ex can receive the additional blocks without | 3484 | * - C4: abut_ex can receive the additional blocks without |
3484 | * overflowing the (initialized) length limit. | 3485 | * overflowing the (initialized) length limit. |
3485 | */ | 3486 | */ |
3486 | if ((!ext4_ext_is_uninitialized(abut_ex)) && /*C1*/ | 3487 | if ((!ext4_ext_is_unwritten(abut_ex)) && /*C1*/ |
3487 | ((map->m_lblk + map_len) == next_lblk) && /*C2*/ | 3488 | ((map->m_lblk + map_len) == next_lblk) && /*C2*/ |
3488 | ((ee_pblk + ee_len) == next_pblk) && /*C3*/ | 3489 | ((ee_pblk + ee_len) == next_pblk) && /*C3*/ |
3489 | (next_len < (EXT_INIT_MAX_LEN - map_len))) { /*C4*/ | 3490 | (next_len < (EXT_INIT_MAX_LEN - map_len))) { /*C4*/ |
@@ -3498,7 +3499,7 @@ static int ext4_ext_convert_to_initialized(handle_t *handle, | |||
3498 | abut_ex->ee_block = cpu_to_le32(next_lblk - map_len); | 3499 | abut_ex->ee_block = cpu_to_le32(next_lblk - map_len); |
3499 | ext4_ext_store_pblock(abut_ex, next_pblk - map_len); | 3500 | ext4_ext_store_pblock(abut_ex, next_pblk - map_len); |
3500 | ex->ee_len = cpu_to_le16(ee_len - map_len); | 3501 | ex->ee_len = cpu_to_le16(ee_len - map_len); |
3501 | ext4_ext_mark_uninitialized(ex); /* Restore the flag */ | 3502 | ext4_ext_mark_unwritten(ex); /* Restore the flag */ |
3502 | 3503 | ||
3503 | /* Extend abut_ex by 'map_len' blocks */ | 3504 | /* Extend abut_ex by 'map_len' blocks */ |
3504 | abut_ex->ee_len = cpu_to_le16(next_len + map_len); | 3505 | abut_ex->ee_len = cpu_to_le16(next_len + map_len); |
@@ -3603,26 +3604,26 @@ out: | |||
3603 | /* | 3604 | /* |
3604 | * This function is called by ext4_ext_map_blocks() from | 3605 | * This function is called by ext4_ext_map_blocks() from |
3605 | * ext4_get_blocks_dio_write() when DIO to write | 3606 | * ext4_get_blocks_dio_write() when DIO to write |
3606 | * to an uninitialized extent. | 3607 | * to an unwritten extent. |
3607 | * | 3608 | * |
3608 | * Writing to an uninitialized extent may result in splitting the uninitialized | 3609 | * Writing to an unwritten extent may result in splitting the unwritten |
3609 | * extent into multiple initialized/uninitialized extents (up to three) | 3610 | * extent into multiple initialized/unwritten extents (up to three) |
3610 | * There are three possibilities: | 3611 | * There are three possibilities: |
3611 | * a> There is no split required: Entire extent should be uninitialized | 3612 | * a> There is no split required: Entire extent should be unwritten |
3612 | * b> Splits in two extents: Write is happening at either end of the extent | 3613 | * b> Splits in two extents: Write is happening at either end of the extent |
3613 | * c> Splits in three extents: Somone is writing in middle of the extent | 3614 | * c> Splits in three extents: Somone is writing in middle of the extent |
3614 | * | 3615 | * |
3615 | * This works the same way in the case of initialized -> unwritten conversion. | 3616 | * This works the same way in the case of initialized -> unwritten conversion. |
3616 | * | 3617 | * |
3617 | * One of more index blocks maybe needed if the extent tree grow after | 3618 | * One of more index blocks maybe needed if the extent tree grow after |
3618 | * the uninitialized extent split. To prevent ENOSPC occur at the IO | 3619 | * the unwritten extent split. To prevent ENOSPC occur at the IO |
3619 | * complete, we need to split the uninitialized extent before DIO submit | 3620 | * complete, we need to split the unwritten extent before DIO submit |
3620 | * the IO. The uninitialized extent called at this time will be split | 3621 | * the IO. The unwritten extent called at this time will be split |
3621 | * into three uninitialized extent(at most). After IO complete, the part | 3622 | * into three unwritten extent(at most). After IO complete, the part |
3622 | * being filled will be convert to initialized by the end_io callback function | 3623 | * being filled will be convert to initialized by the end_io callback function |
3623 | * via ext4_convert_unwritten_extents(). | 3624 | * via ext4_convert_unwritten_extents(). |
3624 | * | 3625 | * |
3625 | * Returns the size of uninitialized extent to be written on success. | 3626 | * Returns the size of unwritten extent to be written on success. |
3626 | */ | 3627 | */ |
3627 | static int ext4_split_convert_extents(handle_t *handle, | 3628 | static int ext4_split_convert_extents(handle_t *handle, |
3628 | struct inode *inode, | 3629 | struct inode *inode, |
@@ -3660,7 +3661,7 @@ static int ext4_split_convert_extents(handle_t *handle, | |||
3660 | } else if (flags & EXT4_GET_BLOCKS_CONVERT) { | 3661 | } else if (flags & EXT4_GET_BLOCKS_CONVERT) { |
3661 | split_flag |= ee_block + ee_len <= eof_block ? | 3662 | split_flag |= ee_block + ee_len <= eof_block ? |
3662 | EXT4_EXT_MAY_ZEROOUT : 0; | 3663 | EXT4_EXT_MAY_ZEROOUT : 0; |
3663 | split_flag |= (EXT4_EXT_MARK_UNINIT2 | EXT4_EXT_DATA_VALID2); | 3664 | split_flag |= (EXT4_EXT_MARK_UNWRIT2 | EXT4_EXT_DATA_VALID2); |
3664 | } | 3665 | } |
3665 | flags |= EXT4_GET_BLOCKS_PRE_IO; | 3666 | flags |= EXT4_GET_BLOCKS_PRE_IO; |
3666 | return ext4_split_extent(handle, inode, path, map, split_flag, flags); | 3667 | return ext4_split_extent(handle, inode, path, map, split_flag, flags); |
@@ -3710,8 +3711,8 @@ static int ext4_convert_initialized_extents(handle_t *handle, | |||
3710 | err = ext4_ext_get_access(handle, inode, path + depth); | 3711 | err = ext4_ext_get_access(handle, inode, path + depth); |
3711 | if (err) | 3712 | if (err) |
3712 | goto out; | 3713 | goto out; |
3713 | /* first mark the extent as uninitialized */ | 3714 | /* first mark the extent as unwritten */ |
3714 | ext4_ext_mark_uninitialized(ex); | 3715 | ext4_ext_mark_unwritten(ex); |
3715 | 3716 | ||
3716 | /* note: ext4_ext_correct_indexes() isn't needed here because | 3717 | /* note: ext4_ext_correct_indexes() isn't needed here because |
3717 | * borders are not changed | 3718 | * borders are not changed |
@@ -3971,10 +3972,10 @@ ext4_ext_convert_initialized_extent(handle_t *handle, struct inode *inode, | |||
3971 | 3972 | ||
3972 | /* | 3973 | /* |
3973 | * Make sure that the extent is no bigger than we support with | 3974 | * Make sure that the extent is no bigger than we support with |
3974 | * uninitialized extent | 3975 | * unwritten extent |
3975 | */ | 3976 | */ |
3976 | if (map->m_len > EXT_UNINIT_MAX_LEN) | 3977 | if (map->m_len > EXT_UNWRITTEN_MAX_LEN) |
3977 | map->m_len = EXT_UNINIT_MAX_LEN / 2; | 3978 | map->m_len = EXT_UNWRITTEN_MAX_LEN / 2; |
3978 | 3979 | ||
3979 | ret = ext4_convert_initialized_extents(handle, inode, map, | 3980 | ret = ext4_convert_initialized_extents(handle, inode, map, |
3980 | path); | 3981 | path); |
@@ -3993,7 +3994,7 @@ ext4_ext_convert_initialized_extent(handle_t *handle, struct inode *inode, | |||
3993 | } | 3994 | } |
3994 | 3995 | ||
3995 | static int | 3996 | static int |
3996 | ext4_ext_handle_uninitialized_extents(handle_t *handle, struct inode *inode, | 3997 | ext4_ext_handle_unwritten_extents(handle_t *handle, struct inode *inode, |
3997 | struct ext4_map_blocks *map, | 3998 | struct ext4_map_blocks *map, |
3998 | struct ext4_ext_path *path, int flags, | 3999 | struct ext4_ext_path *path, int flags, |
3999 | unsigned int allocated, ext4_fsblk_t newblock) | 4000 | unsigned int allocated, ext4_fsblk_t newblock) |
@@ -4002,23 +4003,23 @@ ext4_ext_handle_uninitialized_extents(handle_t *handle, struct inode *inode, | |||
4002 | int err = 0; | 4003 | int err = 0; |
4003 | ext4_io_end_t *io = ext4_inode_aio(inode); | 4004 | ext4_io_end_t *io = ext4_inode_aio(inode); |
4004 | 4005 | ||
4005 | ext_debug("ext4_ext_handle_uninitialized_extents: inode %lu, logical " | 4006 | ext_debug("ext4_ext_handle_unwritten_extents: inode %lu, logical " |
4006 | "block %llu, max_blocks %u, flags %x, allocated %u\n", | 4007 | "block %llu, max_blocks %u, flags %x, allocated %u\n", |
4007 | inode->i_ino, (unsigned long long)map->m_lblk, map->m_len, | 4008 | inode->i_ino, (unsigned long long)map->m_lblk, map->m_len, |
4008 | flags, allocated); | 4009 | flags, allocated); |
4009 | ext4_ext_show_leaf(inode, path); | 4010 | ext4_ext_show_leaf(inode, path); |
4010 | 4011 | ||
4011 | /* | 4012 | /* |
4012 | * When writing into uninitialized space, we should not fail to | 4013 | * When writing into unwritten space, we should not fail to |
4013 | * allocate metadata blocks for the new extent block if needed. | 4014 | * allocate metadata blocks for the new extent block if needed. |
4014 | */ | 4015 | */ |
4015 | flags |= EXT4_GET_BLOCKS_METADATA_NOFAIL; | 4016 | flags |= EXT4_GET_BLOCKS_METADATA_NOFAIL; |
4016 | 4017 | ||
4017 | trace_ext4_ext_handle_uninitialized_extents(inode, map, flags, | 4018 | trace_ext4_ext_handle_unwritten_extents(inode, map, flags, |
4018 | allocated, newblock); | 4019 | allocated, newblock); |
4019 | 4020 | ||
4020 | /* get_block() before submit the IO, split the extent */ | 4021 | /* get_block() before submit the IO, split the extent */ |
4021 | if ((flags & EXT4_GET_BLOCKS_PRE_IO)) { | 4022 | if (flags & EXT4_GET_BLOCKS_PRE_IO) { |
4022 | ret = ext4_split_convert_extents(handle, inode, map, | 4023 | ret = ext4_split_convert_extents(handle, inode, map, |
4023 | path, flags | EXT4_GET_BLOCKS_CONVERT); | 4024 | path, flags | EXT4_GET_BLOCKS_CONVERT); |
4024 | if (ret <= 0) | 4025 | if (ret <= 0) |
@@ -4033,12 +4034,10 @@ ext4_ext_handle_uninitialized_extents(handle_t *handle, struct inode *inode, | |||
4033 | else | 4034 | else |
4034 | ext4_set_inode_state(inode, EXT4_STATE_DIO_UNWRITTEN); | 4035 | ext4_set_inode_state(inode, EXT4_STATE_DIO_UNWRITTEN); |
4035 | map->m_flags |= EXT4_MAP_UNWRITTEN; | 4036 | map->m_flags |= EXT4_MAP_UNWRITTEN; |
4036 | if (ext4_should_dioread_nolock(inode)) | ||
4037 | map->m_flags |= EXT4_MAP_UNINIT; | ||
4038 | goto out; | 4037 | goto out; |
4039 | } | 4038 | } |
4040 | /* IO end_io complete, convert the filled extent to written */ | 4039 | /* IO end_io complete, convert the filled extent to written */ |
4041 | if ((flags & EXT4_GET_BLOCKS_CONVERT)) { | 4040 | if (flags & EXT4_GET_BLOCKS_CONVERT) { |
4042 | ret = ext4_convert_unwritten_extents_endio(handle, inode, map, | 4041 | ret = ext4_convert_unwritten_extents_endio(handle, inode, map, |
4043 | path); | 4042 | path); |
4044 | if (ret >= 0) { | 4043 | if (ret >= 0) { |
@@ -4059,7 +4058,7 @@ ext4_ext_handle_uninitialized_extents(handle_t *handle, struct inode *inode, | |||
4059 | * repeat fallocate creation request | 4058 | * repeat fallocate creation request |
4060 | * we already have an unwritten extent | 4059 | * we already have an unwritten extent |
4061 | */ | 4060 | */ |
4062 | if (flags & EXT4_GET_BLOCKS_UNINIT_EXT) { | 4061 | if (flags & EXT4_GET_BLOCKS_UNWRIT_EXT) { |
4063 | map->m_flags |= EXT4_MAP_UNWRITTEN; | 4062 | map->m_flags |= EXT4_MAP_UNWRITTEN; |
4064 | goto map_out; | 4063 | goto map_out; |
4065 | } | 4064 | } |
@@ -4310,7 +4309,7 @@ int ext4_ext_map_blocks(handle_t *handle, struct inode *inode, | |||
4310 | 4309 | ||
4311 | 4310 | ||
4312 | /* | 4311 | /* |
4313 | * Uninitialized extents are treated as holes, except that | 4312 | * unwritten extents are treated as holes, except that |
4314 | * we split out initialized portions during a write. | 4313 | * we split out initialized portions during a write. |
4315 | */ | 4314 | */ |
4316 | ee_len = ext4_ext_get_actual_len(ex); | 4315 | ee_len = ext4_ext_get_actual_len(ex); |
@@ -4329,16 +4328,16 @@ int ext4_ext_map_blocks(handle_t *handle, struct inode *inode, | |||
4329 | * If the extent is initialized check whether the | 4328 | * If the extent is initialized check whether the |
4330 | * caller wants to convert it to unwritten. | 4329 | * caller wants to convert it to unwritten. |
4331 | */ | 4330 | */ |
4332 | if ((!ext4_ext_is_uninitialized(ex)) && | 4331 | if ((!ext4_ext_is_unwritten(ex)) && |
4333 | (flags & EXT4_GET_BLOCKS_CONVERT_UNWRITTEN)) { | 4332 | (flags & EXT4_GET_BLOCKS_CONVERT_UNWRITTEN)) { |
4334 | allocated = ext4_ext_convert_initialized_extent( | 4333 | allocated = ext4_ext_convert_initialized_extent( |
4335 | handle, inode, map, path, flags, | 4334 | handle, inode, map, path, flags, |
4336 | allocated, newblock); | 4335 | allocated, newblock); |
4337 | goto out2; | 4336 | goto out2; |
4338 | } else if (!ext4_ext_is_uninitialized(ex)) | 4337 | } else if (!ext4_ext_is_unwritten(ex)) |
4339 | goto out; | 4338 | goto out; |
4340 | 4339 | ||
4341 | ret = ext4_ext_handle_uninitialized_extents( | 4340 | ret = ext4_ext_handle_unwritten_extents( |
4342 | handle, inode, map, path, flags, | 4341 | handle, inode, map, path, flags, |
4343 | allocated, newblock); | 4342 | allocated, newblock); |
4344 | if (ret < 0) | 4343 | if (ret < 0) |
@@ -4410,15 +4409,15 @@ int ext4_ext_map_blocks(handle_t *handle, struct inode *inode, | |||
4410 | /* | 4409 | /* |
4411 | * See if request is beyond maximum number of blocks we can have in | 4410 | * See if request is beyond maximum number of blocks we can have in |
4412 | * a single extent. For an initialized extent this limit is | 4411 | * a single extent. For an initialized extent this limit is |
4413 | * EXT_INIT_MAX_LEN and for an uninitialized extent this limit is | 4412 | * EXT_INIT_MAX_LEN and for an unwritten extent this limit is |
4414 | * EXT_UNINIT_MAX_LEN. | 4413 | * EXT_UNWRITTEN_MAX_LEN. |
4415 | */ | 4414 | */ |
4416 | if (map->m_len > EXT_INIT_MAX_LEN && | 4415 | if (map->m_len > EXT_INIT_MAX_LEN && |
4417 | !(flags & EXT4_GET_BLOCKS_UNINIT_EXT)) | 4416 | !(flags & EXT4_GET_BLOCKS_UNWRIT_EXT)) |
4418 | map->m_len = EXT_INIT_MAX_LEN; | 4417 | map->m_len = EXT_INIT_MAX_LEN; |
4419 | else if (map->m_len > EXT_UNINIT_MAX_LEN && | 4418 | else if (map->m_len > EXT_UNWRITTEN_MAX_LEN && |
4420 | (flags & EXT4_GET_BLOCKS_UNINIT_EXT)) | 4419 | (flags & EXT4_GET_BLOCKS_UNWRIT_EXT)) |
4421 | map->m_len = EXT_UNINIT_MAX_LEN; | 4420 | map->m_len = EXT_UNWRITTEN_MAX_LEN; |
4422 | 4421 | ||
4423 | /* Check if we can really insert (m_lblk)::(m_lblk + m_len) extent */ | 4422 | /* Check if we can really insert (m_lblk)::(m_lblk + m_len) extent */ |
4424 | newex.ee_len = cpu_to_le16(map->m_len); | 4423 | newex.ee_len = cpu_to_le16(map->m_len); |
@@ -4466,21 +4465,19 @@ got_allocated_blocks: | |||
4466 | /* try to insert new extent into found leaf and return */ | 4465 | /* try to insert new extent into found leaf and return */ |
4467 | ext4_ext_store_pblock(&newex, newblock + offset); | 4466 | ext4_ext_store_pblock(&newex, newblock + offset); |
4468 | newex.ee_len = cpu_to_le16(ar.len); | 4467 | newex.ee_len = cpu_to_le16(ar.len); |
4469 | /* Mark uninitialized */ | 4468 | /* Mark unwritten */ |
4470 | if (flags & EXT4_GET_BLOCKS_UNINIT_EXT){ | 4469 | if (flags & EXT4_GET_BLOCKS_UNWRIT_EXT){ |
4471 | ext4_ext_mark_uninitialized(&newex); | 4470 | ext4_ext_mark_unwritten(&newex); |
4472 | map->m_flags |= EXT4_MAP_UNWRITTEN; | 4471 | map->m_flags |= EXT4_MAP_UNWRITTEN; |
4473 | /* | 4472 | /* |
4474 | * io_end structure was created for every IO write to an | 4473 | * io_end structure was created for every IO write to an |
4475 | * uninitialized extent. To avoid unnecessary conversion, | 4474 | * unwritten extent. To avoid unnecessary conversion, |
4476 | * here we flag the IO that really needs the conversion. | 4475 | * here we flag the IO that really needs the conversion. |
4477 | * For non asycn direct IO case, flag the inode state | 4476 | * For non asycn direct IO case, flag the inode state |
4478 | * that we need to perform conversion when IO is done. | 4477 | * that we need to perform conversion when IO is done. |
4479 | */ | 4478 | */ |
4480 | if ((flags & EXT4_GET_BLOCKS_PRE_IO)) | 4479 | if (flags & EXT4_GET_BLOCKS_PRE_IO) |
4481 | set_unwritten = 1; | 4480 | set_unwritten = 1; |
4482 | if (ext4_should_dioread_nolock(inode)) | ||
4483 | map->m_flags |= EXT4_MAP_UNINIT; | ||
4484 | } | 4481 | } |
4485 | 4482 | ||
4486 | err = 0; | 4483 | err = 0; |
@@ -4607,9 +4604,9 @@ got_allocated_blocks: | |||
4607 | 4604 | ||
4608 | /* | 4605 | /* |
4609 | * Cache the extent and update transaction to commit on fdatasync only | 4606 | * Cache the extent and update transaction to commit on fdatasync only |
4610 | * when it is _not_ an uninitialized extent. | 4607 | * when it is _not_ an unwritten extent. |
4611 | */ | 4608 | */ |
4612 | if ((flags & EXT4_GET_BLOCKS_UNINIT_EXT) == 0) | 4609 | if ((flags & EXT4_GET_BLOCKS_UNWRIT_EXT) == 0) |
4613 | ext4_update_inode_fsync_trans(handle, inode, 1); | 4610 | ext4_update_inode_fsync_trans(handle, inode, 1); |
4614 | else | 4611 | else |
4615 | ext4_update_inode_fsync_trans(handle, inode, 0); | 4612 | ext4_update_inode_fsync_trans(handle, inode, 0); |
@@ -4683,7 +4680,7 @@ static int ext4_alloc_file_blocks(struct file *file, ext4_lblk_t offset, | |||
4683 | * that it doesn't get unnecessarily split into multiple | 4680 | * that it doesn't get unnecessarily split into multiple |
4684 | * extents. | 4681 | * extents. |
4685 | */ | 4682 | */ |
4686 | if (len <= EXT_UNINIT_MAX_LEN) | 4683 | if (len <= EXT_UNWRITTEN_MAX_LEN) |
4687 | flags |= EXT4_GET_BLOCKS_NO_NORMALIZE; | 4684 | flags |= EXT4_GET_BLOCKS_NO_NORMALIZE; |
4688 | 4685 | ||
4689 | /* | 4686 | /* |
@@ -4744,6 +4741,13 @@ static long ext4_zero_range(struct file *file, loff_t offset, | |||
4744 | if (!S_ISREG(inode->i_mode)) | 4741 | if (!S_ISREG(inode->i_mode)) |
4745 | return -EINVAL; | 4742 | return -EINVAL; |
4746 | 4743 | ||
4744 | /* Call ext4_force_commit to flush all data in case of data=journal. */ | ||
4745 | if (ext4_should_journal_data(inode)) { | ||
4746 | ret = ext4_force_commit(inode->i_sb); | ||
4747 | if (ret) | ||
4748 | return ret; | ||
4749 | } | ||
4750 | |||
4747 | /* | 4751 | /* |
4748 | * Write out all dirty pages to avoid race conditions | 4752 | * Write out all dirty pages to avoid race conditions |
4749 | * Then release them. | 4753 | * Then release them. |
@@ -4775,7 +4779,7 @@ static long ext4_zero_range(struct file *file, loff_t offset, | |||
4775 | else | 4779 | else |
4776 | max_blocks -= lblk; | 4780 | max_blocks -= lblk; |
4777 | 4781 | ||
4778 | flags = EXT4_GET_BLOCKS_CREATE_UNINIT_EXT | | 4782 | flags = EXT4_GET_BLOCKS_CREATE_UNWRIT_EXT | |
4779 | EXT4_GET_BLOCKS_CONVERT_UNWRITTEN; | 4783 | EXT4_GET_BLOCKS_CONVERT_UNWRITTEN; |
4780 | if (mode & FALLOC_FL_KEEP_SIZE) | 4784 | if (mode & FALLOC_FL_KEEP_SIZE) |
4781 | flags |= EXT4_GET_BLOCKS_KEEP_SIZE; | 4785 | flags |= EXT4_GET_BLOCKS_KEEP_SIZE; |
@@ -4918,7 +4922,7 @@ long ext4_fallocate(struct file *file, int mode, loff_t offset, loff_t len) | |||
4918 | max_blocks = (EXT4_BLOCK_ALIGN(len + offset, blkbits) >> blkbits) | 4922 | max_blocks = (EXT4_BLOCK_ALIGN(len + offset, blkbits) >> blkbits) |
4919 | - lblk; | 4923 | - lblk; |
4920 | 4924 | ||
4921 | flags = EXT4_GET_BLOCKS_CREATE_UNINIT_EXT; | 4925 | flags = EXT4_GET_BLOCKS_CREATE_UNWRIT_EXT; |
4922 | if (mode & FALLOC_FL_KEEP_SIZE) | 4926 | if (mode & FALLOC_FL_KEEP_SIZE) |
4923 | flags |= EXT4_GET_BLOCKS_KEEP_SIZE; | 4927 | flags |= EXT4_GET_BLOCKS_KEEP_SIZE; |
4924 | 4928 | ||