diff options
Diffstat (limited to 'fs/btrfs/inode.c')
-rw-r--r-- | fs/btrfs/inode.c | 264 |
1 files changed, 126 insertions, 138 deletions
diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c index 61b16c641ce0..92df0a5d1d94 100644 --- a/fs/btrfs/inode.c +++ b/fs/btrfs/inode.c | |||
@@ -89,7 +89,7 @@ static unsigned char btrfs_type_by_mode[S_IFMT >> S_SHIFT] = { | |||
89 | 89 | ||
90 | static int btrfs_setsize(struct inode *inode, loff_t newsize); | 90 | static int btrfs_setsize(struct inode *inode, loff_t newsize); |
91 | static int btrfs_truncate(struct inode *inode); | 91 | static int btrfs_truncate(struct inode *inode); |
92 | static int btrfs_finish_ordered_io(struct inode *inode, u64 start, u64 end); | 92 | static int btrfs_finish_ordered_io(struct btrfs_ordered_extent *ordered_extent); |
93 | static noinline int cow_file_range(struct inode *inode, | 93 | static noinline int cow_file_range(struct inode *inode, |
94 | struct page *locked_page, | 94 | struct page *locked_page, |
95 | u64 start, u64 end, int *page_started, | 95 | u64 start, u64 end, int *page_started, |
@@ -257,10 +257,13 @@ static noinline int cow_file_range_inline(struct btrfs_trans_handle *trans, | |||
257 | ret = insert_inline_extent(trans, root, inode, start, | 257 | ret = insert_inline_extent(trans, root, inode, start, |
258 | inline_len, compressed_size, | 258 | inline_len, compressed_size, |
259 | compress_type, compressed_pages); | 259 | compress_type, compressed_pages); |
260 | if (ret) { | 260 | if (ret && ret != -ENOSPC) { |
261 | btrfs_abort_transaction(trans, root, ret); | 261 | btrfs_abort_transaction(trans, root, ret); |
262 | return ret; | 262 | return ret; |
263 | } else if (ret == -ENOSPC) { | ||
264 | return 1; | ||
263 | } | 265 | } |
266 | |||
264 | btrfs_delalloc_release_metadata(inode, end + 1 - start); | 267 | btrfs_delalloc_release_metadata(inode, end + 1 - start); |
265 | btrfs_drop_extent_cache(inode, start, aligned_end - 1, 0); | 268 | btrfs_drop_extent_cache(inode, start, aligned_end - 1, 0); |
266 | return 0; | 269 | return 0; |
@@ -1572,11 +1575,11 @@ static int btrfs_submit_bio_hook(struct inode *inode, int rw, struct bio *bio, | |||
1572 | if (btrfs_is_free_space_inode(root, inode)) | 1575 | if (btrfs_is_free_space_inode(root, inode)) |
1573 | metadata = 2; | 1576 | metadata = 2; |
1574 | 1577 | ||
1575 | ret = btrfs_bio_wq_end_io(root->fs_info, bio, metadata); | ||
1576 | if (ret) | ||
1577 | return ret; | ||
1578 | |||
1579 | if (!(rw & REQ_WRITE)) { | 1578 | if (!(rw & REQ_WRITE)) { |
1579 | ret = btrfs_bio_wq_end_io(root->fs_info, bio, metadata); | ||
1580 | if (ret) | ||
1581 | return ret; | ||
1582 | |||
1580 | if (bio_flags & EXTENT_BIO_COMPRESSED) { | 1583 | if (bio_flags & EXTENT_BIO_COMPRESSED) { |
1581 | return btrfs_submit_compressed_read(inode, bio, | 1584 | return btrfs_submit_compressed_read(inode, bio, |
1582 | mirror_num, bio_flags); | 1585 | mirror_num, bio_flags); |
@@ -1815,25 +1818,24 @@ out: | |||
1815 | * an ordered extent if the range of bytes in the file it covers are | 1818 | * an ordered extent if the range of bytes in the file it covers are |
1816 | * fully written. | 1819 | * fully written. |
1817 | */ | 1820 | */ |
1818 | static int btrfs_finish_ordered_io(struct inode *inode, u64 start, u64 end) | 1821 | static int btrfs_finish_ordered_io(struct btrfs_ordered_extent *ordered_extent) |
1819 | { | 1822 | { |
1823 | struct inode *inode = ordered_extent->inode; | ||
1820 | struct btrfs_root *root = BTRFS_I(inode)->root; | 1824 | struct btrfs_root *root = BTRFS_I(inode)->root; |
1821 | struct btrfs_trans_handle *trans = NULL; | 1825 | struct btrfs_trans_handle *trans = NULL; |
1822 | struct btrfs_ordered_extent *ordered_extent = NULL; | ||
1823 | struct extent_io_tree *io_tree = &BTRFS_I(inode)->io_tree; | 1826 | struct extent_io_tree *io_tree = &BTRFS_I(inode)->io_tree; |
1824 | struct extent_state *cached_state = NULL; | 1827 | struct extent_state *cached_state = NULL; |
1825 | int compress_type = 0; | 1828 | int compress_type = 0; |
1826 | int ret; | 1829 | int ret; |
1827 | bool nolock; | 1830 | bool nolock; |
1828 | 1831 | ||
1829 | ret = btrfs_dec_test_ordered_pending(inode, &ordered_extent, start, | ||
1830 | end - start + 1); | ||
1831 | if (!ret) | ||
1832 | return 0; | ||
1833 | BUG_ON(!ordered_extent); /* Logic error */ | ||
1834 | |||
1835 | nolock = btrfs_is_free_space_inode(root, inode); | 1832 | nolock = btrfs_is_free_space_inode(root, inode); |
1836 | 1833 | ||
1834 | if (test_bit(BTRFS_ORDERED_IOERR, &ordered_extent->flags)) { | ||
1835 | ret = -EIO; | ||
1836 | goto out; | ||
1837 | } | ||
1838 | |||
1837 | if (test_bit(BTRFS_ORDERED_NOCOW, &ordered_extent->flags)) { | 1839 | if (test_bit(BTRFS_ORDERED_NOCOW, &ordered_extent->flags)) { |
1838 | BUG_ON(!list_empty(&ordered_extent->list)); /* Logic error */ | 1840 | BUG_ON(!list_empty(&ordered_extent->list)); /* Logic error */ |
1839 | ret = btrfs_ordered_update_i_size(inode, 0, ordered_extent); | 1841 | ret = btrfs_ordered_update_i_size(inode, 0, ordered_extent); |
@@ -1889,12 +1891,10 @@ static int btrfs_finish_ordered_io(struct inode *inode, u64 start, u64 end) | |||
1889 | ordered_extent->file_offset, | 1891 | ordered_extent->file_offset, |
1890 | ordered_extent->len); | 1892 | ordered_extent->len); |
1891 | } | 1893 | } |
1892 | unlock_extent_cached(io_tree, ordered_extent->file_offset, | 1894 | |
1893 | ordered_extent->file_offset + | ||
1894 | ordered_extent->len - 1, &cached_state, GFP_NOFS); | ||
1895 | if (ret < 0) { | 1895 | if (ret < 0) { |
1896 | btrfs_abort_transaction(trans, root, ret); | 1896 | btrfs_abort_transaction(trans, root, ret); |
1897 | goto out; | 1897 | goto out_unlock; |
1898 | } | 1898 | } |
1899 | 1899 | ||
1900 | add_pending_csums(trans, inode, ordered_extent->file_offset, | 1900 | add_pending_csums(trans, inode, ordered_extent->file_offset, |
@@ -1905,10 +1905,14 @@ static int btrfs_finish_ordered_io(struct inode *inode, u64 start, u64 end) | |||
1905 | ret = btrfs_update_inode_fallback(trans, root, inode); | 1905 | ret = btrfs_update_inode_fallback(trans, root, inode); |
1906 | if (ret) { /* -ENOMEM or corruption */ | 1906 | if (ret) { /* -ENOMEM or corruption */ |
1907 | btrfs_abort_transaction(trans, root, ret); | 1907 | btrfs_abort_transaction(trans, root, ret); |
1908 | goto out; | 1908 | goto out_unlock; |
1909 | } | 1909 | } |
1910 | } | 1910 | } |
1911 | ret = 0; | 1911 | ret = 0; |
1912 | out_unlock: | ||
1913 | unlock_extent_cached(io_tree, ordered_extent->file_offset, | ||
1914 | ordered_extent->file_offset + | ||
1915 | ordered_extent->len - 1, &cached_state, GFP_NOFS); | ||
1912 | out: | 1916 | out: |
1913 | if (root != root->fs_info->tree_root) | 1917 | if (root != root->fs_info->tree_root) |
1914 | btrfs_delalloc_release_metadata(inode, ordered_extent->len); | 1918 | btrfs_delalloc_release_metadata(inode, ordered_extent->len); |
@@ -1919,26 +1923,57 @@ out: | |||
1919 | btrfs_end_transaction(trans, root); | 1923 | btrfs_end_transaction(trans, root); |
1920 | } | 1924 | } |
1921 | 1925 | ||
1926 | if (ret) | ||
1927 | clear_extent_uptodate(io_tree, ordered_extent->file_offset, | ||
1928 | ordered_extent->file_offset + | ||
1929 | ordered_extent->len - 1, NULL, GFP_NOFS); | ||
1930 | |||
1931 | /* | ||
1932 | * This needs to be dont to make sure anybody waiting knows we are done | ||
1933 | * upating everything for this ordered extent. | ||
1934 | */ | ||
1935 | btrfs_remove_ordered_extent(inode, ordered_extent); | ||
1936 | |||
1922 | /* once for us */ | 1937 | /* once for us */ |
1923 | btrfs_put_ordered_extent(ordered_extent); | 1938 | btrfs_put_ordered_extent(ordered_extent); |
1924 | /* once for the tree */ | 1939 | /* once for the tree */ |
1925 | btrfs_put_ordered_extent(ordered_extent); | 1940 | btrfs_put_ordered_extent(ordered_extent); |
1926 | 1941 | ||
1927 | return 0; | 1942 | return ret; |
1928 | out_unlock: | 1943 | } |
1929 | unlock_extent_cached(io_tree, ordered_extent->file_offset, | 1944 | |
1930 | ordered_extent->file_offset + | 1945 | static void finish_ordered_fn(struct btrfs_work *work) |
1931 | ordered_extent->len - 1, &cached_state, GFP_NOFS); | 1946 | { |
1932 | goto out; | 1947 | struct btrfs_ordered_extent *ordered_extent; |
1948 | ordered_extent = container_of(work, struct btrfs_ordered_extent, work); | ||
1949 | btrfs_finish_ordered_io(ordered_extent); | ||
1933 | } | 1950 | } |
1934 | 1951 | ||
1935 | static int btrfs_writepage_end_io_hook(struct page *page, u64 start, u64 end, | 1952 | static int btrfs_writepage_end_io_hook(struct page *page, u64 start, u64 end, |
1936 | struct extent_state *state, int uptodate) | 1953 | struct extent_state *state, int uptodate) |
1937 | { | 1954 | { |
1955 | struct inode *inode = page->mapping->host; | ||
1956 | struct btrfs_root *root = BTRFS_I(inode)->root; | ||
1957 | struct btrfs_ordered_extent *ordered_extent = NULL; | ||
1958 | struct btrfs_workers *workers; | ||
1959 | |||
1938 | trace_btrfs_writepage_end_io_hook(page, start, end, uptodate); | 1960 | trace_btrfs_writepage_end_io_hook(page, start, end, uptodate); |
1939 | 1961 | ||
1940 | ClearPagePrivate2(page); | 1962 | ClearPagePrivate2(page); |
1941 | return btrfs_finish_ordered_io(page->mapping->host, start, end); | 1963 | if (!btrfs_dec_test_ordered_pending(inode, &ordered_extent, start, |
1964 | end - start + 1, uptodate)) | ||
1965 | return 0; | ||
1966 | |||
1967 | ordered_extent->work.func = finish_ordered_fn; | ||
1968 | ordered_extent->work.flags = 0; | ||
1969 | |||
1970 | if (btrfs_is_free_space_inode(root, inode)) | ||
1971 | workers = &root->fs_info->endio_freespace_worker; | ||
1972 | else | ||
1973 | workers = &root->fs_info->endio_write_workers; | ||
1974 | btrfs_queue_worker(workers, &ordered_extent->work); | ||
1975 | |||
1976 | return 0; | ||
1942 | } | 1977 | } |
1943 | 1978 | ||
1944 | /* | 1979 | /* |
@@ -2072,12 +2107,12 @@ void btrfs_orphan_commit_root(struct btrfs_trans_handle *trans, | |||
2072 | struct btrfs_block_rsv *block_rsv; | 2107 | struct btrfs_block_rsv *block_rsv; |
2073 | int ret; | 2108 | int ret; |
2074 | 2109 | ||
2075 | if (!list_empty(&root->orphan_list) || | 2110 | if (atomic_read(&root->orphan_inodes) || |
2076 | root->orphan_cleanup_state != ORPHAN_CLEANUP_DONE) | 2111 | root->orphan_cleanup_state != ORPHAN_CLEANUP_DONE) |
2077 | return; | 2112 | return; |
2078 | 2113 | ||
2079 | spin_lock(&root->orphan_lock); | 2114 | spin_lock(&root->orphan_lock); |
2080 | if (!list_empty(&root->orphan_list)) { | 2115 | if (atomic_read(&root->orphan_inodes)) { |
2081 | spin_unlock(&root->orphan_lock); | 2116 | spin_unlock(&root->orphan_lock); |
2082 | return; | 2117 | return; |
2083 | } | 2118 | } |
@@ -2134,8 +2169,8 @@ int btrfs_orphan_add(struct btrfs_trans_handle *trans, struct inode *inode) | |||
2134 | block_rsv = NULL; | 2169 | block_rsv = NULL; |
2135 | } | 2170 | } |
2136 | 2171 | ||
2137 | if (list_empty(&BTRFS_I(inode)->i_orphan)) { | 2172 | if (!test_and_set_bit(BTRFS_INODE_HAS_ORPHAN_ITEM, |
2138 | list_add(&BTRFS_I(inode)->i_orphan, &root->orphan_list); | 2173 | &BTRFS_I(inode)->runtime_flags)) { |
2139 | #if 0 | 2174 | #if 0 |
2140 | /* | 2175 | /* |
2141 | * For proper ENOSPC handling, we should do orphan | 2176 | * For proper ENOSPC handling, we should do orphan |
@@ -2148,12 +2183,12 @@ int btrfs_orphan_add(struct btrfs_trans_handle *trans, struct inode *inode) | |||
2148 | insert = 1; | 2183 | insert = 1; |
2149 | #endif | 2184 | #endif |
2150 | insert = 1; | 2185 | insert = 1; |
2186 | atomic_dec(&root->orphan_inodes); | ||
2151 | } | 2187 | } |
2152 | 2188 | ||
2153 | if (!BTRFS_I(inode)->orphan_meta_reserved) { | 2189 | if (!test_and_set_bit(BTRFS_INODE_ORPHAN_META_RESERVED, |
2154 | BTRFS_I(inode)->orphan_meta_reserved = 1; | 2190 | &BTRFS_I(inode)->runtime_flags)) |
2155 | reserve = 1; | 2191 | reserve = 1; |
2156 | } | ||
2157 | spin_unlock(&root->orphan_lock); | 2192 | spin_unlock(&root->orphan_lock); |
2158 | 2193 | ||
2159 | /* grab metadata reservation from transaction handle */ | 2194 | /* grab metadata reservation from transaction handle */ |
@@ -2166,6 +2201,8 @@ int btrfs_orphan_add(struct btrfs_trans_handle *trans, struct inode *inode) | |||
2166 | if (insert >= 1) { | 2201 | if (insert >= 1) { |
2167 | ret = btrfs_insert_orphan_item(trans, root, btrfs_ino(inode)); | 2202 | ret = btrfs_insert_orphan_item(trans, root, btrfs_ino(inode)); |
2168 | if (ret && ret != -EEXIST) { | 2203 | if (ret && ret != -EEXIST) { |
2204 | clear_bit(BTRFS_INODE_HAS_ORPHAN_ITEM, | ||
2205 | &BTRFS_I(inode)->runtime_flags); | ||
2169 | btrfs_abort_transaction(trans, root, ret); | 2206 | btrfs_abort_transaction(trans, root, ret); |
2170 | return ret; | 2207 | return ret; |
2171 | } | 2208 | } |
@@ -2196,15 +2233,13 @@ int btrfs_orphan_del(struct btrfs_trans_handle *trans, struct inode *inode) | |||
2196 | int ret = 0; | 2233 | int ret = 0; |
2197 | 2234 | ||
2198 | spin_lock(&root->orphan_lock); | 2235 | spin_lock(&root->orphan_lock); |
2199 | if (!list_empty(&BTRFS_I(inode)->i_orphan)) { | 2236 | if (test_and_clear_bit(BTRFS_INODE_HAS_ORPHAN_ITEM, |
2200 | list_del_init(&BTRFS_I(inode)->i_orphan); | 2237 | &BTRFS_I(inode)->runtime_flags)) |
2201 | delete_item = 1; | 2238 | delete_item = 1; |
2202 | } | ||
2203 | 2239 | ||
2204 | if (BTRFS_I(inode)->orphan_meta_reserved) { | 2240 | if (test_and_clear_bit(BTRFS_INODE_ORPHAN_META_RESERVED, |
2205 | BTRFS_I(inode)->orphan_meta_reserved = 0; | 2241 | &BTRFS_I(inode)->runtime_flags)) |
2206 | release_rsv = 1; | 2242 | release_rsv = 1; |
2207 | } | ||
2208 | spin_unlock(&root->orphan_lock); | 2243 | spin_unlock(&root->orphan_lock); |
2209 | 2244 | ||
2210 | if (trans && delete_item) { | 2245 | if (trans && delete_item) { |
@@ -2212,8 +2247,10 @@ int btrfs_orphan_del(struct btrfs_trans_handle *trans, struct inode *inode) | |||
2212 | BUG_ON(ret); /* -ENOMEM or corruption (JDM: Recheck) */ | 2247 | BUG_ON(ret); /* -ENOMEM or corruption (JDM: Recheck) */ |
2213 | } | 2248 | } |
2214 | 2249 | ||
2215 | if (release_rsv) | 2250 | if (release_rsv) { |
2216 | btrfs_orphan_release_metadata(inode); | 2251 | btrfs_orphan_release_metadata(inode); |
2252 | atomic_dec(&root->orphan_inodes); | ||
2253 | } | ||
2217 | 2254 | ||
2218 | return 0; | 2255 | return 0; |
2219 | } | 2256 | } |
@@ -2341,6 +2378,8 @@ int btrfs_orphan_cleanup(struct btrfs_root *root) | |||
2341 | ret = PTR_ERR(trans); | 2378 | ret = PTR_ERR(trans); |
2342 | goto out; | 2379 | goto out; |
2343 | } | 2380 | } |
2381 | printk(KERN_ERR "auto deleting %Lu\n", | ||
2382 | found_key.objectid); | ||
2344 | ret = btrfs_del_orphan_item(trans, root, | 2383 | ret = btrfs_del_orphan_item(trans, root, |
2345 | found_key.objectid); | 2384 | found_key.objectid); |
2346 | BUG_ON(ret); /* -ENOMEM or corruption (JDM: Recheck) */ | 2385 | BUG_ON(ret); /* -ENOMEM or corruption (JDM: Recheck) */ |
@@ -2352,9 +2391,8 @@ int btrfs_orphan_cleanup(struct btrfs_root *root) | |||
2352 | * add this inode to the orphan list so btrfs_orphan_del does | 2391 | * add this inode to the orphan list so btrfs_orphan_del does |
2353 | * the proper thing when we hit it | 2392 | * the proper thing when we hit it |
2354 | */ | 2393 | */ |
2355 | spin_lock(&root->orphan_lock); | 2394 | set_bit(BTRFS_INODE_HAS_ORPHAN_ITEM, |
2356 | list_add(&BTRFS_I(inode)->i_orphan, &root->orphan_list); | 2395 | &BTRFS_I(inode)->runtime_flags); |
2357 | spin_unlock(&root->orphan_lock); | ||
2358 | 2396 | ||
2359 | /* if we have links, this was a truncate, lets do that */ | 2397 | /* if we have links, this was a truncate, lets do that */ |
2360 | if (inode->i_nlink) { | 2398 | if (inode->i_nlink) { |
@@ -2510,7 +2548,7 @@ static void btrfs_read_locked_inode(struct inode *inode) | |||
2510 | 2548 | ||
2511 | inode_set_bytes(inode, btrfs_inode_nbytes(leaf, inode_item)); | 2549 | inode_set_bytes(inode, btrfs_inode_nbytes(leaf, inode_item)); |
2512 | BTRFS_I(inode)->generation = btrfs_inode_generation(leaf, inode_item); | 2550 | BTRFS_I(inode)->generation = btrfs_inode_generation(leaf, inode_item); |
2513 | BTRFS_I(inode)->sequence = btrfs_inode_sequence(leaf, inode_item); | 2551 | inode->i_version = btrfs_inode_sequence(leaf, inode_item); |
2514 | inode->i_generation = BTRFS_I(inode)->generation; | 2552 | inode->i_generation = BTRFS_I(inode)->generation; |
2515 | inode->i_rdev = 0; | 2553 | inode->i_rdev = 0; |
2516 | rdev = btrfs_inode_rdev(leaf, inode_item); | 2554 | rdev = btrfs_inode_rdev(leaf, inode_item); |
@@ -2594,7 +2632,7 @@ static void fill_inode_item(struct btrfs_trans_handle *trans, | |||
2594 | 2632 | ||
2595 | btrfs_set_inode_nbytes(leaf, item, inode_get_bytes(inode)); | 2633 | btrfs_set_inode_nbytes(leaf, item, inode_get_bytes(inode)); |
2596 | btrfs_set_inode_generation(leaf, item, BTRFS_I(inode)->generation); | 2634 | btrfs_set_inode_generation(leaf, item, BTRFS_I(inode)->generation); |
2597 | btrfs_set_inode_sequence(leaf, item, BTRFS_I(inode)->sequence); | 2635 | btrfs_set_inode_sequence(leaf, item, inode->i_version); |
2598 | btrfs_set_inode_transid(leaf, item, trans->transid); | 2636 | btrfs_set_inode_transid(leaf, item, trans->transid); |
2599 | btrfs_set_inode_rdev(leaf, item, inode->i_rdev); | 2637 | btrfs_set_inode_rdev(leaf, item, inode->i_rdev); |
2600 | btrfs_set_inode_flags(leaf, item, BTRFS_I(inode)->flags); | 2638 | btrfs_set_inode_flags(leaf, item, BTRFS_I(inode)->flags); |
@@ -2752,6 +2790,8 @@ err: | |||
2752 | goto out; | 2790 | goto out; |
2753 | 2791 | ||
2754 | btrfs_i_size_write(dir, dir->i_size - name_len * 2); | 2792 | btrfs_i_size_write(dir, dir->i_size - name_len * 2); |
2793 | inode_inc_iversion(inode); | ||
2794 | inode_inc_iversion(dir); | ||
2755 | inode->i_ctime = dir->i_mtime = dir->i_ctime = CURRENT_TIME; | 2795 | inode->i_ctime = dir->i_mtime = dir->i_ctime = CURRENT_TIME; |
2756 | btrfs_update_inode(trans, root, dir); | 2796 | btrfs_update_inode(trans, root, dir); |
2757 | out: | 2797 | out: |
@@ -3089,6 +3129,7 @@ int btrfs_unlink_subvol(struct btrfs_trans_handle *trans, | |||
3089 | } | 3129 | } |
3090 | 3130 | ||
3091 | btrfs_i_size_write(dir, dir->i_size - name_len * 2); | 3131 | btrfs_i_size_write(dir, dir->i_size - name_len * 2); |
3132 | inode_inc_iversion(dir); | ||
3092 | dir->i_mtime = dir->i_ctime = CURRENT_TIME; | 3133 | dir->i_mtime = dir->i_ctime = CURRENT_TIME; |
3093 | ret = btrfs_update_inode(trans, root, dir); | 3134 | ret = btrfs_update_inode(trans, root, dir); |
3094 | if (ret) | 3135 | if (ret) |
@@ -3607,7 +3648,8 @@ static int btrfs_setsize(struct inode *inode, loff_t newsize) | |||
3607 | * any new writes get down to disk quickly. | 3648 | * any new writes get down to disk quickly. |
3608 | */ | 3649 | */ |
3609 | if (newsize == 0) | 3650 | if (newsize == 0) |
3610 | BTRFS_I(inode)->ordered_data_close = 1; | 3651 | set_bit(BTRFS_INODE_ORDERED_DATA_CLOSE, |
3652 | &BTRFS_I(inode)->runtime_flags); | ||
3611 | 3653 | ||
3612 | /* we don't support swapfiles, so vmtruncate shouldn't fail */ | 3654 | /* we don't support swapfiles, so vmtruncate shouldn't fail */ |
3613 | truncate_setsize(inode, newsize); | 3655 | truncate_setsize(inode, newsize); |
@@ -3638,6 +3680,7 @@ static int btrfs_setattr(struct dentry *dentry, struct iattr *attr) | |||
3638 | 3680 | ||
3639 | if (attr->ia_valid) { | 3681 | if (attr->ia_valid) { |
3640 | setattr_copy(inode, attr); | 3682 | setattr_copy(inode, attr); |
3683 | inode_inc_iversion(inode); | ||
3641 | err = btrfs_dirty_inode(inode); | 3684 | err = btrfs_dirty_inode(inode); |
3642 | 3685 | ||
3643 | if (!err && attr->ia_valid & ATTR_MODE) | 3686 | if (!err && attr->ia_valid & ATTR_MODE) |
@@ -3671,7 +3714,8 @@ void btrfs_evict_inode(struct inode *inode) | |||
3671 | btrfs_wait_ordered_range(inode, 0, (u64)-1); | 3714 | btrfs_wait_ordered_range(inode, 0, (u64)-1); |
3672 | 3715 | ||
3673 | if (root->fs_info->log_root_recovering) { | 3716 | if (root->fs_info->log_root_recovering) { |
3674 | BUG_ON(!list_empty(&BTRFS_I(inode)->i_orphan)); | 3717 | BUG_ON(!test_bit(BTRFS_INODE_HAS_ORPHAN_ITEM, |
3718 | &BTRFS_I(inode)->runtime_flags)); | ||
3675 | goto no_delete; | 3719 | goto no_delete; |
3676 | } | 3720 | } |
3677 | 3721 | ||
@@ -4066,7 +4110,7 @@ static struct inode *new_simple_dir(struct super_block *s, | |||
4066 | 4110 | ||
4067 | BTRFS_I(inode)->root = root; | 4111 | BTRFS_I(inode)->root = root; |
4068 | memcpy(&BTRFS_I(inode)->location, key, sizeof(*key)); | 4112 | memcpy(&BTRFS_I(inode)->location, key, sizeof(*key)); |
4069 | BTRFS_I(inode)->dummy_inode = 1; | 4113 | set_bit(BTRFS_INODE_DUMMY, &BTRFS_I(inode)->runtime_flags); |
4070 | 4114 | ||
4071 | inode->i_ino = BTRFS_EMPTY_SUBVOL_DIR_OBJECTID; | 4115 | inode->i_ino = BTRFS_EMPTY_SUBVOL_DIR_OBJECTID; |
4072 | inode->i_op = &btrfs_dir_ro_inode_operations; | 4116 | inode->i_op = &btrfs_dir_ro_inode_operations; |
@@ -4370,7 +4414,7 @@ int btrfs_write_inode(struct inode *inode, struct writeback_control *wbc) | |||
4370 | int ret = 0; | 4414 | int ret = 0; |
4371 | bool nolock = false; | 4415 | bool nolock = false; |
4372 | 4416 | ||
4373 | if (BTRFS_I(inode)->dummy_inode) | 4417 | if (test_bit(BTRFS_INODE_DUMMY, &BTRFS_I(inode)->runtime_flags)) |
4374 | return 0; | 4418 | return 0; |
4375 | 4419 | ||
4376 | if (btrfs_fs_closing(root->fs_info) && btrfs_is_free_space_inode(root, inode)) | 4420 | if (btrfs_fs_closing(root->fs_info) && btrfs_is_free_space_inode(root, inode)) |
@@ -4403,7 +4447,7 @@ int btrfs_dirty_inode(struct inode *inode) | |||
4403 | struct btrfs_trans_handle *trans; | 4447 | struct btrfs_trans_handle *trans; |
4404 | int ret; | 4448 | int ret; |
4405 | 4449 | ||
4406 | if (BTRFS_I(inode)->dummy_inode) | 4450 | if (test_bit(BTRFS_INODE_DUMMY, &BTRFS_I(inode)->runtime_flags)) |
4407 | return 0; | 4451 | return 0; |
4408 | 4452 | ||
4409 | trans = btrfs_join_transaction(root); | 4453 | trans = btrfs_join_transaction(root); |
@@ -4730,6 +4774,7 @@ int btrfs_add_link(struct btrfs_trans_handle *trans, | |||
4730 | 4774 | ||
4731 | btrfs_i_size_write(parent_inode, parent_inode->i_size + | 4775 | btrfs_i_size_write(parent_inode, parent_inode->i_size + |
4732 | name_len * 2); | 4776 | name_len * 2); |
4777 | inode_inc_iversion(parent_inode); | ||
4733 | parent_inode->i_mtime = parent_inode->i_ctime = CURRENT_TIME; | 4778 | parent_inode->i_mtime = parent_inode->i_ctime = CURRENT_TIME; |
4734 | ret = btrfs_update_inode(trans, root, parent_inode); | 4779 | ret = btrfs_update_inode(trans, root, parent_inode); |
4735 | if (ret) | 4780 | if (ret) |
@@ -4937,6 +4982,7 @@ static int btrfs_link(struct dentry *old_dentry, struct inode *dir, | |||
4937 | } | 4982 | } |
4938 | 4983 | ||
4939 | btrfs_inc_nlink(inode); | 4984 | btrfs_inc_nlink(inode); |
4985 | inode_inc_iversion(inode); | ||
4940 | inode->i_ctime = CURRENT_TIME; | 4986 | inode->i_ctime = CURRENT_TIME; |
4941 | ihold(inode); | 4987 | ihold(inode); |
4942 | 4988 | ||
@@ -5903,9 +5949,7 @@ static void btrfs_endio_direct_write(struct bio *bio, int err) | |||
5903 | struct btrfs_dio_private *dip = bio->bi_private; | 5949 | struct btrfs_dio_private *dip = bio->bi_private; |
5904 | struct inode *inode = dip->inode; | 5950 | struct inode *inode = dip->inode; |
5905 | struct btrfs_root *root = BTRFS_I(inode)->root; | 5951 | struct btrfs_root *root = BTRFS_I(inode)->root; |
5906 | struct btrfs_trans_handle *trans; | ||
5907 | struct btrfs_ordered_extent *ordered = NULL; | 5952 | struct btrfs_ordered_extent *ordered = NULL; |
5908 | struct extent_state *cached_state = NULL; | ||
5909 | u64 ordered_offset = dip->logical_offset; | 5953 | u64 ordered_offset = dip->logical_offset; |
5910 | u64 ordered_bytes = dip->bytes; | 5954 | u64 ordered_bytes = dip->bytes; |
5911 | int ret; | 5955 | int ret; |
@@ -5915,73 +5959,14 @@ static void btrfs_endio_direct_write(struct bio *bio, int err) | |||
5915 | again: | 5959 | again: |
5916 | ret = btrfs_dec_test_first_ordered_pending(inode, &ordered, | 5960 | ret = btrfs_dec_test_first_ordered_pending(inode, &ordered, |
5917 | &ordered_offset, | 5961 | &ordered_offset, |
5918 | ordered_bytes); | 5962 | ordered_bytes, !err); |
5919 | if (!ret) | 5963 | if (!ret) |
5920 | goto out_test; | 5964 | goto out_test; |
5921 | 5965 | ||
5922 | BUG_ON(!ordered); | 5966 | ordered->work.func = finish_ordered_fn; |
5923 | 5967 | ordered->work.flags = 0; | |
5924 | trans = btrfs_join_transaction(root); | 5968 | btrfs_queue_worker(&root->fs_info->endio_write_workers, |
5925 | if (IS_ERR(trans)) { | 5969 | &ordered->work); |
5926 | err = -ENOMEM; | ||
5927 | goto out; | ||
5928 | } | ||
5929 | trans->block_rsv = &root->fs_info->delalloc_block_rsv; | ||
5930 | |||
5931 | if (test_bit(BTRFS_ORDERED_NOCOW, &ordered->flags)) { | ||
5932 | ret = btrfs_ordered_update_i_size(inode, 0, ordered); | ||
5933 | if (!ret) | ||
5934 | err = btrfs_update_inode_fallback(trans, root, inode); | ||
5935 | goto out; | ||
5936 | } | ||
5937 | |||
5938 | lock_extent_bits(&BTRFS_I(inode)->io_tree, ordered->file_offset, | ||
5939 | ordered->file_offset + ordered->len - 1, 0, | ||
5940 | &cached_state); | ||
5941 | |||
5942 | if (test_bit(BTRFS_ORDERED_PREALLOC, &ordered->flags)) { | ||
5943 | ret = btrfs_mark_extent_written(trans, inode, | ||
5944 | ordered->file_offset, | ||
5945 | ordered->file_offset + | ||
5946 | ordered->len); | ||
5947 | if (ret) { | ||
5948 | err = ret; | ||
5949 | goto out_unlock; | ||
5950 | } | ||
5951 | } else { | ||
5952 | ret = insert_reserved_file_extent(trans, inode, | ||
5953 | ordered->file_offset, | ||
5954 | ordered->start, | ||
5955 | ordered->disk_len, | ||
5956 | ordered->len, | ||
5957 | ordered->len, | ||
5958 | 0, 0, 0, | ||
5959 | BTRFS_FILE_EXTENT_REG); | ||
5960 | unpin_extent_cache(&BTRFS_I(inode)->extent_tree, | ||
5961 | ordered->file_offset, ordered->len); | ||
5962 | if (ret) { | ||
5963 | err = ret; | ||
5964 | WARN_ON(1); | ||
5965 | goto out_unlock; | ||
5966 | } | ||
5967 | } | ||
5968 | |||
5969 | add_pending_csums(trans, inode, ordered->file_offset, &ordered->list); | ||
5970 | ret = btrfs_ordered_update_i_size(inode, 0, ordered); | ||
5971 | if (!ret || !test_bit(BTRFS_ORDERED_PREALLOC, &ordered->flags)) | ||
5972 | btrfs_update_inode_fallback(trans, root, inode); | ||
5973 | ret = 0; | ||
5974 | out_unlock: | ||
5975 | unlock_extent_cached(&BTRFS_I(inode)->io_tree, ordered->file_offset, | ||
5976 | ordered->file_offset + ordered->len - 1, | ||
5977 | &cached_state, GFP_NOFS); | ||
5978 | out: | ||
5979 | btrfs_delalloc_release_metadata(inode, ordered->len); | ||
5980 | btrfs_end_transaction(trans, root); | ||
5981 | ordered_offset = ordered->file_offset + ordered->len; | ||
5982 | btrfs_put_ordered_extent(ordered); | ||
5983 | btrfs_put_ordered_extent(ordered); | ||
5984 | |||
5985 | out_test: | 5970 | out_test: |
5986 | /* | 5971 | /* |
5987 | * our bio might span multiple ordered extents. If we haven't | 5972 | * our bio might span multiple ordered extents. If we haven't |
@@ -5990,12 +5975,12 @@ out_test: | |||
5990 | if (ordered_offset < dip->logical_offset + dip->bytes) { | 5975 | if (ordered_offset < dip->logical_offset + dip->bytes) { |
5991 | ordered_bytes = dip->logical_offset + dip->bytes - | 5976 | ordered_bytes = dip->logical_offset + dip->bytes - |
5992 | ordered_offset; | 5977 | ordered_offset; |
5978 | ordered = NULL; | ||
5993 | goto again; | 5979 | goto again; |
5994 | } | 5980 | } |
5995 | out_done: | 5981 | out_done: |
5996 | bio->bi_private = dip->private; | 5982 | bio->bi_private = dip->private; |
5997 | 5983 | ||
5998 | kfree(dip->csums); | ||
5999 | kfree(dip); | 5984 | kfree(dip); |
6000 | 5985 | ||
6001 | /* If we had an error make sure to clear the uptodate flag */ | 5986 | /* If we had an error make sure to clear the uptodate flag */ |
@@ -6063,9 +6048,12 @@ static inline int __btrfs_submit_dio_bio(struct bio *bio, struct inode *inode, | |||
6063 | int ret; | 6048 | int ret; |
6064 | 6049 | ||
6065 | bio_get(bio); | 6050 | bio_get(bio); |
6066 | ret = btrfs_bio_wq_end_io(root->fs_info, bio, 0); | 6051 | |
6067 | if (ret) | 6052 | if (!write) { |
6068 | goto err; | 6053 | ret = btrfs_bio_wq_end_io(root->fs_info, bio, 0); |
6054 | if (ret) | ||
6055 | goto err; | ||
6056 | } | ||
6069 | 6057 | ||
6070 | if (skip_sum) | 6058 | if (skip_sum) |
6071 | goto map; | 6059 | goto map; |
@@ -6485,13 +6473,13 @@ static int btrfs_releasepage(struct page *page, gfp_t gfp_flags) | |||
6485 | 6473 | ||
6486 | static void btrfs_invalidatepage(struct page *page, unsigned long offset) | 6474 | static void btrfs_invalidatepage(struct page *page, unsigned long offset) |
6487 | { | 6475 | { |
6476 | struct inode *inode = page->mapping->host; | ||
6488 | struct extent_io_tree *tree; | 6477 | struct extent_io_tree *tree; |
6489 | struct btrfs_ordered_extent *ordered; | 6478 | struct btrfs_ordered_extent *ordered; |
6490 | struct extent_state *cached_state = NULL; | 6479 | struct extent_state *cached_state = NULL; |
6491 | u64 page_start = page_offset(page); | 6480 | u64 page_start = page_offset(page); |
6492 | u64 page_end = page_start + PAGE_CACHE_SIZE - 1; | 6481 | u64 page_end = page_start + PAGE_CACHE_SIZE - 1; |
6493 | 6482 | ||
6494 | |||
6495 | /* | 6483 | /* |
6496 | * we have the page locked, so new writeback can't start, | 6484 | * we have the page locked, so new writeback can't start, |
6497 | * and the dirty bit won't be cleared while we are here. | 6485 | * and the dirty bit won't be cleared while we are here. |
@@ -6501,13 +6489,13 @@ static void btrfs_invalidatepage(struct page *page, unsigned long offset) | |||
6501 | */ | 6489 | */ |
6502 | wait_on_page_writeback(page); | 6490 | wait_on_page_writeback(page); |
6503 | 6491 | ||
6504 | tree = &BTRFS_I(page->mapping->host)->io_tree; | 6492 | tree = &BTRFS_I(inode)->io_tree; |
6505 | if (offset) { | 6493 | if (offset) { |
6506 | btrfs_releasepage(page, GFP_NOFS); | 6494 | btrfs_releasepage(page, GFP_NOFS); |
6507 | return; | 6495 | return; |
6508 | } | 6496 | } |
6509 | lock_extent_bits(tree, page_start, page_end, 0, &cached_state); | 6497 | lock_extent_bits(tree, page_start, page_end, 0, &cached_state); |
6510 | ordered = btrfs_lookup_ordered_extent(page->mapping->host, | 6498 | ordered = btrfs_lookup_ordered_extent(inode, |
6511 | page_offset(page)); | 6499 | page_offset(page)); |
6512 | if (ordered) { | 6500 | if (ordered) { |
6513 | /* | 6501 | /* |
@@ -6522,9 +6510,10 @@ static void btrfs_invalidatepage(struct page *page, unsigned long offset) | |||
6522 | * whoever cleared the private bit is responsible | 6510 | * whoever cleared the private bit is responsible |
6523 | * for the finish_ordered_io | 6511 | * for the finish_ordered_io |
6524 | */ | 6512 | */ |
6525 | if (TestClearPagePrivate2(page)) { | 6513 | if (TestClearPagePrivate2(page) && |
6526 | btrfs_finish_ordered_io(page->mapping->host, | 6514 | btrfs_dec_test_ordered_pending(inode, &ordered, page_start, |
6527 | page_start, page_end); | 6515 | PAGE_CACHE_SIZE, 1)) { |
6516 | btrfs_finish_ordered_io(ordered); | ||
6528 | } | 6517 | } |
6529 | btrfs_put_ordered_extent(ordered); | 6518 | btrfs_put_ordered_extent(ordered); |
6530 | cached_state = NULL; | 6519 | cached_state = NULL; |
@@ -6771,7 +6760,8 @@ static int btrfs_truncate(struct inode *inode) | |||
6771 | * using truncate to replace the contents of the file will | 6760 | * using truncate to replace the contents of the file will |
6772 | * end up with a zero length file after a crash. | 6761 | * end up with a zero length file after a crash. |
6773 | */ | 6762 | */ |
6774 | if (inode->i_size == 0 && BTRFS_I(inode)->ordered_data_close) | 6763 | if (inode->i_size == 0 && test_bit(BTRFS_INODE_ORDERED_DATA_CLOSE, |
6764 | &BTRFS_I(inode)->runtime_flags)) | ||
6775 | btrfs_add_ordered_operation(trans, root, inode); | 6765 | btrfs_add_ordered_operation(trans, root, inode); |
6776 | 6766 | ||
6777 | while (1) { | 6767 | while (1) { |
@@ -6894,7 +6884,6 @@ struct inode *btrfs_alloc_inode(struct super_block *sb) | |||
6894 | ei->root = NULL; | 6884 | ei->root = NULL; |
6895 | ei->space_info = NULL; | 6885 | ei->space_info = NULL; |
6896 | ei->generation = 0; | 6886 | ei->generation = 0; |
6897 | ei->sequence = 0; | ||
6898 | ei->last_trans = 0; | 6887 | ei->last_trans = 0; |
6899 | ei->last_sub_trans = 0; | 6888 | ei->last_sub_trans = 0; |
6900 | ei->logged_trans = 0; | 6889 | ei->logged_trans = 0; |
@@ -6909,11 +6898,7 @@ struct inode *btrfs_alloc_inode(struct super_block *sb) | |||
6909 | ei->outstanding_extents = 0; | 6898 | ei->outstanding_extents = 0; |
6910 | ei->reserved_extents = 0; | 6899 | ei->reserved_extents = 0; |
6911 | 6900 | ||
6912 | ei->ordered_data_close = 0; | 6901 | ei->runtime_flags = 0; |
6913 | ei->orphan_meta_reserved = 0; | ||
6914 | ei->dummy_inode = 0; | ||
6915 | ei->in_defrag = 0; | ||
6916 | ei->delalloc_meta_reserved = 0; | ||
6917 | ei->force_compress = BTRFS_COMPRESS_NONE; | 6902 | ei->force_compress = BTRFS_COMPRESS_NONE; |
6918 | 6903 | ||
6919 | ei->delayed_node = NULL; | 6904 | ei->delayed_node = NULL; |
@@ -6927,7 +6912,6 @@ struct inode *btrfs_alloc_inode(struct super_block *sb) | |||
6927 | mutex_init(&ei->log_mutex); | 6912 | mutex_init(&ei->log_mutex); |
6928 | mutex_init(&ei->delalloc_mutex); | 6913 | mutex_init(&ei->delalloc_mutex); |
6929 | btrfs_ordered_inode_tree_init(&ei->ordered_tree); | 6914 | btrfs_ordered_inode_tree_init(&ei->ordered_tree); |
6930 | INIT_LIST_HEAD(&ei->i_orphan); | ||
6931 | INIT_LIST_HEAD(&ei->delalloc_inodes); | 6915 | INIT_LIST_HEAD(&ei->delalloc_inodes); |
6932 | INIT_LIST_HEAD(&ei->ordered_operations); | 6916 | INIT_LIST_HEAD(&ei->ordered_operations); |
6933 | RB_CLEAR_NODE(&ei->rb_node); | 6917 | RB_CLEAR_NODE(&ei->rb_node); |
@@ -6972,13 +6956,12 @@ void btrfs_destroy_inode(struct inode *inode) | |||
6972 | spin_unlock(&root->fs_info->ordered_extent_lock); | 6956 | spin_unlock(&root->fs_info->ordered_extent_lock); |
6973 | } | 6957 | } |
6974 | 6958 | ||
6975 | spin_lock(&root->orphan_lock); | 6959 | if (test_bit(BTRFS_INODE_HAS_ORPHAN_ITEM, |
6976 | if (!list_empty(&BTRFS_I(inode)->i_orphan)) { | 6960 | &BTRFS_I(inode)->runtime_flags)) { |
6977 | printk(KERN_INFO "BTRFS: inode %llu still on the orphan list\n", | 6961 | printk(KERN_INFO "BTRFS: inode %llu still on the orphan list\n", |
6978 | (unsigned long long)btrfs_ino(inode)); | 6962 | (unsigned long long)btrfs_ino(inode)); |
6979 | list_del_init(&BTRFS_I(inode)->i_orphan); | 6963 | atomic_dec(&root->orphan_inodes); |
6980 | } | 6964 | } |
6981 | spin_unlock(&root->orphan_lock); | ||
6982 | 6965 | ||
6983 | while (1) { | 6966 | while (1) { |
6984 | ordered = btrfs_lookup_first_ordered_extent(inode, (u64)-1); | 6967 | ordered = btrfs_lookup_first_ordered_extent(inode, (u64)-1); |
@@ -7193,6 +7176,9 @@ static int btrfs_rename(struct inode *old_dir, struct dentry *old_dentry, | |||
7193 | if (new_inode && new_inode->i_size && S_ISREG(old_inode->i_mode)) | 7176 | if (new_inode && new_inode->i_size && S_ISREG(old_inode->i_mode)) |
7194 | btrfs_add_ordered_operation(trans, root, old_inode); | 7177 | btrfs_add_ordered_operation(trans, root, old_inode); |
7195 | 7178 | ||
7179 | inode_inc_iversion(old_dir); | ||
7180 | inode_inc_iversion(new_dir); | ||
7181 | inode_inc_iversion(old_inode); | ||
7196 | old_dir->i_ctime = old_dir->i_mtime = ctime; | 7182 | old_dir->i_ctime = old_dir->i_mtime = ctime; |
7197 | new_dir->i_ctime = new_dir->i_mtime = ctime; | 7183 | new_dir->i_ctime = new_dir->i_mtime = ctime; |
7198 | old_inode->i_ctime = ctime; | 7184 | old_inode->i_ctime = ctime; |
@@ -7219,6 +7205,7 @@ static int btrfs_rename(struct inode *old_dir, struct dentry *old_dentry, | |||
7219 | } | 7205 | } |
7220 | 7206 | ||
7221 | if (new_inode) { | 7207 | if (new_inode) { |
7208 | inode_inc_iversion(new_inode); | ||
7222 | new_inode->i_ctime = CURRENT_TIME; | 7209 | new_inode->i_ctime = CURRENT_TIME; |
7223 | if (unlikely(btrfs_ino(new_inode) == | 7210 | if (unlikely(btrfs_ino(new_inode) == |
7224 | BTRFS_EMPTY_SUBVOL_DIR_OBJECTID)) { | 7211 | BTRFS_EMPTY_SUBVOL_DIR_OBJECTID)) { |
@@ -7490,6 +7477,7 @@ static int __btrfs_prealloc_file_range(struct inode *inode, int mode, | |||
7490 | cur_offset += ins.offset; | 7477 | cur_offset += ins.offset; |
7491 | *alloc_hint = ins.objectid + ins.offset; | 7478 | *alloc_hint = ins.objectid + ins.offset; |
7492 | 7479 | ||
7480 | inode_inc_iversion(inode); | ||
7493 | inode->i_ctime = CURRENT_TIME; | 7481 | inode->i_ctime = CURRENT_TIME; |
7494 | BTRFS_I(inode)->flags |= BTRFS_INODE_PREALLOC; | 7482 | BTRFS_I(inode)->flags |= BTRFS_INODE_PREALLOC; |
7495 | if (!(mode & FALLOC_FL_KEEP_SIZE) && | 7483 | if (!(mode & FALLOC_FL_KEEP_SIZE) && |