diff options
Diffstat (limited to 'fs/btrfs/inode.c')
| -rw-r--r-- | fs/btrfs/inode.c | 319 |
1 files changed, 141 insertions, 178 deletions
diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c index 61b16c641ce0..f6ab6f5e635a 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 | ||
| @@ -3756,7 +3800,7 @@ void btrfs_evict_inode(struct inode *inode) | |||
| 3756 | btrfs_end_transaction(trans, root); | 3800 | btrfs_end_transaction(trans, root); |
| 3757 | btrfs_btree_balance_dirty(root, nr); | 3801 | btrfs_btree_balance_dirty(root, nr); |
| 3758 | no_delete: | 3802 | no_delete: |
| 3759 | end_writeback(inode); | 3803 | clear_inode(inode); |
| 3760 | return; | 3804 | return; |
| 3761 | } | 3805 | } |
| 3762 | 3806 | ||
| @@ -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); |
| @@ -4431,46 +4475,18 @@ int btrfs_dirty_inode(struct inode *inode) | |||
| 4431 | * This is a copy of file_update_time. We need this so we can return error on | 4475 | * This is a copy of file_update_time. We need this so we can return error on |
| 4432 | * ENOSPC for updating the inode in the case of file write and mmap writes. | 4476 | * ENOSPC for updating the inode in the case of file write and mmap writes. |
| 4433 | */ | 4477 | */ |
| 4434 | int btrfs_update_time(struct file *file) | 4478 | static int btrfs_update_time(struct inode *inode, struct timespec *now, |
| 4479 | int flags) | ||
| 4435 | { | 4480 | { |
| 4436 | struct inode *inode = file->f_path.dentry->d_inode; | 4481 | if (flags & S_VERSION) |
| 4437 | struct timespec now; | ||
| 4438 | int ret; | ||
| 4439 | enum { S_MTIME = 1, S_CTIME = 2, S_VERSION = 4 } sync_it = 0; | ||
| 4440 | |||
| 4441 | /* First try to exhaust all avenues to not sync */ | ||
| 4442 | if (IS_NOCMTIME(inode)) | ||
| 4443 | return 0; | ||
| 4444 | |||
| 4445 | now = current_fs_time(inode->i_sb); | ||
| 4446 | if (!timespec_equal(&inode->i_mtime, &now)) | ||
| 4447 | sync_it = S_MTIME; | ||
| 4448 | |||
| 4449 | if (!timespec_equal(&inode->i_ctime, &now)) | ||
| 4450 | sync_it |= S_CTIME; | ||
| 4451 | |||
| 4452 | if (IS_I_VERSION(inode)) | ||
| 4453 | sync_it |= S_VERSION; | ||
| 4454 | |||
| 4455 | if (!sync_it) | ||
| 4456 | return 0; | ||
| 4457 | |||
| 4458 | /* Finally allowed to write? Takes lock. */ | ||
| 4459 | if (mnt_want_write_file(file)) | ||
| 4460 | return 0; | ||
| 4461 | |||
| 4462 | /* Only change inode inside the lock region */ | ||
| 4463 | if (sync_it & S_VERSION) | ||
| 4464 | inode_inc_iversion(inode); | 4482 | inode_inc_iversion(inode); |
| 4465 | if (sync_it & S_CTIME) | 4483 | if (flags & S_CTIME) |
| 4466 | inode->i_ctime = now; | 4484 | inode->i_ctime = *now; |
| 4467 | if (sync_it & S_MTIME) | 4485 | if (flags & S_MTIME) |
| 4468 | inode->i_mtime = now; | 4486 | inode->i_mtime = *now; |
| 4469 | ret = btrfs_dirty_inode(inode); | 4487 | if (flags & S_ATIME) |
| 4470 | if (!ret) | 4488 | inode->i_atime = *now; |
| 4471 | mark_inode_dirty_sync(inode); | 4489 | return btrfs_dirty_inode(inode); |
| 4472 | mnt_drop_write(file->f_path.mnt); | ||
| 4473 | return ret; | ||
| 4474 | } | 4490 | } |
| 4475 | 4491 | ||
| 4476 | /* | 4492 | /* |
| @@ -4730,6 +4746,7 @@ int btrfs_add_link(struct btrfs_trans_handle *trans, | |||
| 4730 | 4746 | ||
| 4731 | btrfs_i_size_write(parent_inode, parent_inode->i_size + | 4747 | btrfs_i_size_write(parent_inode, parent_inode->i_size + |
| 4732 | name_len * 2); | 4748 | name_len * 2); |
| 4749 | inode_inc_iversion(parent_inode); | ||
| 4733 | parent_inode->i_mtime = parent_inode->i_ctime = CURRENT_TIME; | 4750 | parent_inode->i_mtime = parent_inode->i_ctime = CURRENT_TIME; |
| 4734 | ret = btrfs_update_inode(trans, root, parent_inode); | 4751 | ret = btrfs_update_inode(trans, root, parent_inode); |
| 4735 | if (ret) | 4752 | if (ret) |
| @@ -4937,6 +4954,7 @@ static int btrfs_link(struct dentry *old_dentry, struct inode *dir, | |||
| 4937 | } | 4954 | } |
| 4938 | 4955 | ||
| 4939 | btrfs_inc_nlink(inode); | 4956 | btrfs_inc_nlink(inode); |
| 4957 | inode_inc_iversion(inode); | ||
| 4940 | inode->i_ctime = CURRENT_TIME; | 4958 | inode->i_ctime = CURRENT_TIME; |
| 4941 | ihold(inode); | 4959 | ihold(inode); |
| 4942 | 4960 | ||
| @@ -5903,9 +5921,7 @@ static void btrfs_endio_direct_write(struct bio *bio, int err) | |||
| 5903 | struct btrfs_dio_private *dip = bio->bi_private; | 5921 | struct btrfs_dio_private *dip = bio->bi_private; |
| 5904 | struct inode *inode = dip->inode; | 5922 | struct inode *inode = dip->inode; |
| 5905 | struct btrfs_root *root = BTRFS_I(inode)->root; | 5923 | struct btrfs_root *root = BTRFS_I(inode)->root; |
| 5906 | struct btrfs_trans_handle *trans; | ||
| 5907 | struct btrfs_ordered_extent *ordered = NULL; | 5924 | struct btrfs_ordered_extent *ordered = NULL; |
| 5908 | struct extent_state *cached_state = NULL; | ||
| 5909 | u64 ordered_offset = dip->logical_offset; | 5925 | u64 ordered_offset = dip->logical_offset; |
| 5910 | u64 ordered_bytes = dip->bytes; | 5926 | u64 ordered_bytes = dip->bytes; |
| 5911 | int ret; | 5927 | int ret; |
| @@ -5915,73 +5931,14 @@ static void btrfs_endio_direct_write(struct bio *bio, int err) | |||
| 5915 | again: | 5931 | again: |
| 5916 | ret = btrfs_dec_test_first_ordered_pending(inode, &ordered, | 5932 | ret = btrfs_dec_test_first_ordered_pending(inode, &ordered, |
| 5917 | &ordered_offset, | 5933 | &ordered_offset, |
| 5918 | ordered_bytes); | 5934 | ordered_bytes, !err); |
| 5919 | if (!ret) | 5935 | if (!ret) |
| 5920 | goto out_test; | 5936 | goto out_test; |
| 5921 | 5937 | ||
| 5922 | BUG_ON(!ordered); | 5938 | ordered->work.func = finish_ordered_fn; |
| 5923 | 5939 | ordered->work.flags = 0; | |
| 5924 | trans = btrfs_join_transaction(root); | 5940 | btrfs_queue_worker(&root->fs_info->endio_write_workers, |
| 5925 | if (IS_ERR(trans)) { | 5941 | &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: | 5942 | out_test: |
| 5986 | /* | 5943 | /* |
| 5987 | * our bio might span multiple ordered extents. If we haven't | 5944 | * our bio might span multiple ordered extents. If we haven't |
| @@ -5990,12 +5947,12 @@ out_test: | |||
| 5990 | if (ordered_offset < dip->logical_offset + dip->bytes) { | 5947 | if (ordered_offset < dip->logical_offset + dip->bytes) { |
| 5991 | ordered_bytes = dip->logical_offset + dip->bytes - | 5948 | ordered_bytes = dip->logical_offset + dip->bytes - |
| 5992 | ordered_offset; | 5949 | ordered_offset; |
| 5950 | ordered = NULL; | ||
| 5993 | goto again; | 5951 | goto again; |
| 5994 | } | 5952 | } |
| 5995 | out_done: | 5953 | out_done: |
| 5996 | bio->bi_private = dip->private; | 5954 | bio->bi_private = dip->private; |
| 5997 | 5955 | ||
| 5998 | kfree(dip->csums); | ||
| 5999 | kfree(dip); | 5956 | kfree(dip); |
| 6000 | 5957 | ||
| 6001 | /* If we had an error make sure to clear the uptodate flag */ | 5958 | /* If we had an error make sure to clear the uptodate flag */ |
| @@ -6063,9 +6020,12 @@ static inline int __btrfs_submit_dio_bio(struct bio *bio, struct inode *inode, | |||
| 6063 | int ret; | 6020 | int ret; |
| 6064 | 6021 | ||
| 6065 | bio_get(bio); | 6022 | bio_get(bio); |
| 6066 | ret = btrfs_bio_wq_end_io(root->fs_info, bio, 0); | 6023 | |
| 6067 | if (ret) | 6024 | if (!write) { |
| 6068 | goto err; | 6025 | ret = btrfs_bio_wq_end_io(root->fs_info, bio, 0); |
| 6026 | if (ret) | ||
| 6027 | goto err; | ||
| 6028 | } | ||
| 6069 | 6029 | ||
| 6070 | if (skip_sum) | 6030 | if (skip_sum) |
| 6071 | goto map; | 6031 | goto map; |
| @@ -6485,13 +6445,13 @@ static int btrfs_releasepage(struct page *page, gfp_t gfp_flags) | |||
| 6485 | 6445 | ||
| 6486 | static void btrfs_invalidatepage(struct page *page, unsigned long offset) | 6446 | static void btrfs_invalidatepage(struct page *page, unsigned long offset) |
| 6487 | { | 6447 | { |
| 6448 | struct inode *inode = page->mapping->host; | ||
| 6488 | struct extent_io_tree *tree; | 6449 | struct extent_io_tree *tree; |
| 6489 | struct btrfs_ordered_extent *ordered; | 6450 | struct btrfs_ordered_extent *ordered; |
| 6490 | struct extent_state *cached_state = NULL; | 6451 | struct extent_state *cached_state = NULL; |
| 6491 | u64 page_start = page_offset(page); | 6452 | u64 page_start = page_offset(page); |
| 6492 | u64 page_end = page_start + PAGE_CACHE_SIZE - 1; | 6453 | u64 page_end = page_start + PAGE_CACHE_SIZE - 1; |
| 6493 | 6454 | ||
| 6494 | |||
| 6495 | /* | 6455 | /* |
| 6496 | * we have the page locked, so new writeback can't start, | 6456 | * we have the page locked, so new writeback can't start, |
| 6497 | * and the dirty bit won't be cleared while we are here. | 6457 | * and the dirty bit won't be cleared while we are here. |
| @@ -6501,13 +6461,13 @@ static void btrfs_invalidatepage(struct page *page, unsigned long offset) | |||
| 6501 | */ | 6461 | */ |
| 6502 | wait_on_page_writeback(page); | 6462 | wait_on_page_writeback(page); |
| 6503 | 6463 | ||
| 6504 | tree = &BTRFS_I(page->mapping->host)->io_tree; | 6464 | tree = &BTRFS_I(inode)->io_tree; |
| 6505 | if (offset) { | 6465 | if (offset) { |
| 6506 | btrfs_releasepage(page, GFP_NOFS); | 6466 | btrfs_releasepage(page, GFP_NOFS); |
| 6507 | return; | 6467 | return; |
| 6508 | } | 6468 | } |
| 6509 | lock_extent_bits(tree, page_start, page_end, 0, &cached_state); | 6469 | lock_extent_bits(tree, page_start, page_end, 0, &cached_state); |
| 6510 | ordered = btrfs_lookup_ordered_extent(page->mapping->host, | 6470 | ordered = btrfs_lookup_ordered_extent(inode, |
| 6511 | page_offset(page)); | 6471 | page_offset(page)); |
| 6512 | if (ordered) { | 6472 | if (ordered) { |
| 6513 | /* | 6473 | /* |
| @@ -6522,9 +6482,10 @@ static void btrfs_invalidatepage(struct page *page, unsigned long offset) | |||
| 6522 | * whoever cleared the private bit is responsible | 6482 | * whoever cleared the private bit is responsible |
| 6523 | * for the finish_ordered_io | 6483 | * for the finish_ordered_io |
| 6524 | */ | 6484 | */ |
| 6525 | if (TestClearPagePrivate2(page)) { | 6485 | if (TestClearPagePrivate2(page) && |
| 6526 | btrfs_finish_ordered_io(page->mapping->host, | 6486 | btrfs_dec_test_ordered_pending(inode, &ordered, page_start, |
| 6527 | page_start, page_end); | 6487 | PAGE_CACHE_SIZE, 1)) { |
| 6488 | btrfs_finish_ordered_io(ordered); | ||
| 6528 | } | 6489 | } |
| 6529 | btrfs_put_ordered_extent(ordered); | 6490 | btrfs_put_ordered_extent(ordered); |
| 6530 | cached_state = NULL; | 6491 | cached_state = NULL; |
| @@ -6576,7 +6537,7 @@ int btrfs_page_mkwrite(struct vm_area_struct *vma, struct vm_fault *vmf) | |||
| 6576 | 6537 | ||
| 6577 | ret = btrfs_delalloc_reserve_space(inode, PAGE_CACHE_SIZE); | 6538 | ret = btrfs_delalloc_reserve_space(inode, PAGE_CACHE_SIZE); |
| 6578 | if (!ret) { | 6539 | if (!ret) { |
| 6579 | ret = btrfs_update_time(vma->vm_file); | 6540 | ret = file_update_time(vma->vm_file); |
| 6580 | reserved = 1; | 6541 | reserved = 1; |
| 6581 | } | 6542 | } |
| 6582 | if (ret) { | 6543 | if (ret) { |
| @@ -6771,7 +6732,8 @@ static int btrfs_truncate(struct inode *inode) | |||
| 6771 | * using truncate to replace the contents of the file will | 6732 | * using truncate to replace the contents of the file will |
| 6772 | * end up with a zero length file after a crash. | 6733 | * end up with a zero length file after a crash. |
| 6773 | */ | 6734 | */ |
| 6774 | if (inode->i_size == 0 && BTRFS_I(inode)->ordered_data_close) | 6735 | if (inode->i_size == 0 && test_bit(BTRFS_INODE_ORDERED_DATA_CLOSE, |
| 6736 | &BTRFS_I(inode)->runtime_flags)) | ||
| 6775 | btrfs_add_ordered_operation(trans, root, inode); | 6737 | btrfs_add_ordered_operation(trans, root, inode); |
| 6776 | 6738 | ||
| 6777 | while (1) { | 6739 | while (1) { |
| @@ -6894,7 +6856,6 @@ struct inode *btrfs_alloc_inode(struct super_block *sb) | |||
| 6894 | ei->root = NULL; | 6856 | ei->root = NULL; |
| 6895 | ei->space_info = NULL; | 6857 | ei->space_info = NULL; |
| 6896 | ei->generation = 0; | 6858 | ei->generation = 0; |
| 6897 | ei->sequence = 0; | ||
| 6898 | ei->last_trans = 0; | 6859 | ei->last_trans = 0; |
| 6899 | ei->last_sub_trans = 0; | 6860 | ei->last_sub_trans = 0; |
| 6900 | ei->logged_trans = 0; | 6861 | ei->logged_trans = 0; |
| @@ -6909,11 +6870,7 @@ struct inode *btrfs_alloc_inode(struct super_block *sb) | |||
| 6909 | ei->outstanding_extents = 0; | 6870 | ei->outstanding_extents = 0; |
| 6910 | ei->reserved_extents = 0; | 6871 | ei->reserved_extents = 0; |
| 6911 | 6872 | ||
| 6912 | ei->ordered_data_close = 0; | 6873 | 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; | 6874 | ei->force_compress = BTRFS_COMPRESS_NONE; |
| 6918 | 6875 | ||
| 6919 | ei->delayed_node = NULL; | 6876 | ei->delayed_node = NULL; |
| @@ -6927,7 +6884,6 @@ struct inode *btrfs_alloc_inode(struct super_block *sb) | |||
| 6927 | mutex_init(&ei->log_mutex); | 6884 | mutex_init(&ei->log_mutex); |
| 6928 | mutex_init(&ei->delalloc_mutex); | 6885 | mutex_init(&ei->delalloc_mutex); |
| 6929 | btrfs_ordered_inode_tree_init(&ei->ordered_tree); | 6886 | btrfs_ordered_inode_tree_init(&ei->ordered_tree); |
| 6930 | INIT_LIST_HEAD(&ei->i_orphan); | ||
| 6931 | INIT_LIST_HEAD(&ei->delalloc_inodes); | 6887 | INIT_LIST_HEAD(&ei->delalloc_inodes); |
| 6932 | INIT_LIST_HEAD(&ei->ordered_operations); | 6888 | INIT_LIST_HEAD(&ei->ordered_operations); |
| 6933 | RB_CLEAR_NODE(&ei->rb_node); | 6889 | RB_CLEAR_NODE(&ei->rb_node); |
| @@ -6972,13 +6928,12 @@ void btrfs_destroy_inode(struct inode *inode) | |||
| 6972 | spin_unlock(&root->fs_info->ordered_extent_lock); | 6928 | spin_unlock(&root->fs_info->ordered_extent_lock); |
| 6973 | } | 6929 | } |
| 6974 | 6930 | ||
| 6975 | spin_lock(&root->orphan_lock); | 6931 | if (test_bit(BTRFS_INODE_HAS_ORPHAN_ITEM, |
| 6976 | if (!list_empty(&BTRFS_I(inode)->i_orphan)) { | 6932 | &BTRFS_I(inode)->runtime_flags)) { |
| 6977 | printk(KERN_INFO "BTRFS: inode %llu still on the orphan list\n", | 6933 | printk(KERN_INFO "BTRFS: inode %llu still on the orphan list\n", |
| 6978 | (unsigned long long)btrfs_ino(inode)); | 6934 | (unsigned long long)btrfs_ino(inode)); |
| 6979 | list_del_init(&BTRFS_I(inode)->i_orphan); | 6935 | atomic_dec(&root->orphan_inodes); |
| 6980 | } | 6936 | } |
| 6981 | spin_unlock(&root->orphan_lock); | ||
| 6982 | 6937 | ||
| 6983 | while (1) { | 6938 | while (1) { |
| 6984 | ordered = btrfs_lookup_first_ordered_extent(inode, (u64)-1); | 6939 | ordered = btrfs_lookup_first_ordered_extent(inode, (u64)-1); |
| @@ -7193,6 +7148,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)) | 7148 | if (new_inode && new_inode->i_size && S_ISREG(old_inode->i_mode)) |
| 7194 | btrfs_add_ordered_operation(trans, root, old_inode); | 7149 | btrfs_add_ordered_operation(trans, root, old_inode); |
| 7195 | 7150 | ||
| 7151 | inode_inc_iversion(old_dir); | ||
| 7152 | inode_inc_iversion(new_dir); | ||
| 7153 | inode_inc_iversion(old_inode); | ||
| 7196 | old_dir->i_ctime = old_dir->i_mtime = ctime; | 7154 | old_dir->i_ctime = old_dir->i_mtime = ctime; |
| 7197 | new_dir->i_ctime = new_dir->i_mtime = ctime; | 7155 | new_dir->i_ctime = new_dir->i_mtime = ctime; |
| 7198 | old_inode->i_ctime = ctime; | 7156 | old_inode->i_ctime = ctime; |
| @@ -7219,6 +7177,7 @@ static int btrfs_rename(struct inode *old_dir, struct dentry *old_dentry, | |||
| 7219 | } | 7177 | } |
| 7220 | 7178 | ||
| 7221 | if (new_inode) { | 7179 | if (new_inode) { |
| 7180 | inode_inc_iversion(new_inode); | ||
| 7222 | new_inode->i_ctime = CURRENT_TIME; | 7181 | new_inode->i_ctime = CURRENT_TIME; |
| 7223 | if (unlikely(btrfs_ino(new_inode) == | 7182 | if (unlikely(btrfs_ino(new_inode) == |
| 7224 | BTRFS_EMPTY_SUBVOL_DIR_OBJECTID)) { | 7183 | BTRFS_EMPTY_SUBVOL_DIR_OBJECTID)) { |
| @@ -7490,6 +7449,7 @@ static int __btrfs_prealloc_file_range(struct inode *inode, int mode, | |||
| 7490 | cur_offset += ins.offset; | 7449 | cur_offset += ins.offset; |
| 7491 | *alloc_hint = ins.objectid + ins.offset; | 7450 | *alloc_hint = ins.objectid + ins.offset; |
| 7492 | 7451 | ||
| 7452 | inode_inc_iversion(inode); | ||
| 7493 | inode->i_ctime = CURRENT_TIME; | 7453 | inode->i_ctime = CURRENT_TIME; |
| 7494 | BTRFS_I(inode)->flags |= BTRFS_INODE_PREALLOC; | 7454 | BTRFS_I(inode)->flags |= BTRFS_INODE_PREALLOC; |
| 7495 | if (!(mode & FALLOC_FL_KEEP_SIZE) && | 7455 | if (!(mode & FALLOC_FL_KEEP_SIZE) && |
| @@ -7647,6 +7607,7 @@ static const struct inode_operations btrfs_file_inode_operations = { | |||
| 7647 | .permission = btrfs_permission, | 7607 | .permission = btrfs_permission, |
| 7648 | .fiemap = btrfs_fiemap, | 7608 | .fiemap = btrfs_fiemap, |
| 7649 | .get_acl = btrfs_get_acl, | 7609 | .get_acl = btrfs_get_acl, |
| 7610 | .update_time = btrfs_update_time, | ||
| 7650 | }; | 7611 | }; |
| 7651 | static const struct inode_operations btrfs_special_inode_operations = { | 7612 | static const struct inode_operations btrfs_special_inode_operations = { |
| 7652 | .getattr = btrfs_getattr, | 7613 | .getattr = btrfs_getattr, |
| @@ -7657,6 +7618,7 @@ static const struct inode_operations btrfs_special_inode_operations = { | |||
| 7657 | .listxattr = btrfs_listxattr, | 7618 | .listxattr = btrfs_listxattr, |
| 7658 | .removexattr = btrfs_removexattr, | 7619 | .removexattr = btrfs_removexattr, |
| 7659 | .get_acl = btrfs_get_acl, | 7620 | .get_acl = btrfs_get_acl, |
| 7621 | .update_time = btrfs_update_time, | ||
| 7660 | }; | 7622 | }; |
| 7661 | static const struct inode_operations btrfs_symlink_inode_operations = { | 7623 | static const struct inode_operations btrfs_symlink_inode_operations = { |
| 7662 | .readlink = generic_readlink, | 7624 | .readlink = generic_readlink, |
| @@ -7670,6 +7632,7 @@ static const struct inode_operations btrfs_symlink_inode_operations = { | |||
| 7670 | .listxattr = btrfs_listxattr, | 7632 | .listxattr = btrfs_listxattr, |
| 7671 | .removexattr = btrfs_removexattr, | 7633 | .removexattr = btrfs_removexattr, |
| 7672 | .get_acl = btrfs_get_acl, | 7634 | .get_acl = btrfs_get_acl, |
| 7635 | .update_time = btrfs_update_time, | ||
| 7673 | }; | 7636 | }; |
| 7674 | 7637 | ||
| 7675 | const struct dentry_operations btrfs_dentry_operations = { | 7638 | const struct dentry_operations btrfs_dentry_operations = { |
