diff options
Diffstat (limited to 'fs/btrfs/inode.c')
-rw-r--r-- | fs/btrfs/inode.c | 94 |
1 files changed, 65 insertions, 29 deletions
diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c index 855935f6671a..e33dff356460 100644 --- a/fs/btrfs/inode.c +++ b/fs/btrfs/inode.c | |||
@@ -4209,7 +4209,7 @@ int btrfs_truncate_inode_items(struct btrfs_trans_handle *trans, | |||
4209 | u64 extent_num_bytes = 0; | 4209 | u64 extent_num_bytes = 0; |
4210 | u64 extent_offset = 0; | 4210 | u64 extent_offset = 0; |
4211 | u64 item_end = 0; | 4211 | u64 item_end = 0; |
4212 | u64 last_size = (u64)-1; | 4212 | u64 last_size = new_size; |
4213 | u32 found_type = (u8)-1; | 4213 | u32 found_type = (u8)-1; |
4214 | int found_extent; | 4214 | int found_extent; |
4215 | int del_item; | 4215 | int del_item; |
@@ -4493,8 +4493,7 @@ out: | |||
4493 | btrfs_abort_transaction(trans, root, ret); | 4493 | btrfs_abort_transaction(trans, root, ret); |
4494 | } | 4494 | } |
4495 | error: | 4495 | error: |
4496 | if (last_size != (u64)-1 && | 4496 | if (root->root_key.objectid != BTRFS_TREE_LOG_OBJECTID) |
4497 | root->root_key.objectid != BTRFS_TREE_LOG_OBJECTID) | ||
4498 | btrfs_ordered_update_i_size(inode, last_size, NULL); | 4497 | btrfs_ordered_update_i_size(inode, last_size, NULL); |
4499 | 4498 | ||
4500 | btrfs_free_path(path); | 4499 | btrfs_free_path(path); |
@@ -4989,8 +4988,9 @@ static void evict_inode_truncate_pages(struct inode *inode) | |||
4989 | /* | 4988 | /* |
4990 | * Keep looping until we have no more ranges in the io tree. | 4989 | * Keep looping until we have no more ranges in the io tree. |
4991 | * We can have ongoing bios started by readpages (called from readahead) | 4990 | * We can have ongoing bios started by readpages (called from readahead) |
4992 | * that didn't get their end io callbacks called yet or they are still | 4991 | * that have their endio callback (extent_io.c:end_bio_extent_readpage) |
4993 | * in progress ((extent_io.c:end_bio_extent_readpage()). This means some | 4992 | * still in progress (unlocked the pages in the bio but did not yet |
4993 | * unlocked the ranges in the io tree). Therefore this means some | ||
4994 | * ranges can still be locked and eviction started because before | 4994 | * ranges can still be locked and eviction started because before |
4995 | * submitting those bios, which are executed by a separate task (work | 4995 | * submitting those bios, which are executed by a separate task (work |
4996 | * queue kthread), inode references (inode->i_count) were not taken | 4996 | * queue kthread), inode references (inode->i_count) were not taken |
@@ -7546,6 +7546,7 @@ unlock: | |||
7546 | 7546 | ||
7547 | current->journal_info = outstanding_extents; | 7547 | current->journal_info = outstanding_extents; |
7548 | btrfs_free_reserved_data_space(inode, len); | 7548 | btrfs_free_reserved_data_space(inode, len); |
7549 | set_bit(BTRFS_INODE_DIO_READY, &BTRFS_I(inode)->runtime_flags); | ||
7549 | } | 7550 | } |
7550 | 7551 | ||
7551 | /* | 7552 | /* |
@@ -7871,8 +7872,6 @@ static void btrfs_endio_direct_write(struct bio *bio, int err) | |||
7871 | struct bio *dio_bio; | 7872 | struct bio *dio_bio; |
7872 | int ret; | 7873 | int ret; |
7873 | 7874 | ||
7874 | if (err) | ||
7875 | goto out_done; | ||
7876 | again: | 7875 | again: |
7877 | ret = btrfs_dec_test_first_ordered_pending(inode, &ordered, | 7876 | ret = btrfs_dec_test_first_ordered_pending(inode, &ordered, |
7878 | &ordered_offset, | 7877 | &ordered_offset, |
@@ -7895,7 +7894,6 @@ out_test: | |||
7895 | ordered = NULL; | 7894 | ordered = NULL; |
7896 | goto again; | 7895 | goto again; |
7897 | } | 7896 | } |
7898 | out_done: | ||
7899 | dio_bio = dip->dio_bio; | 7897 | dio_bio = dip->dio_bio; |
7900 | 7898 | ||
7901 | kfree(dip); | 7899 | kfree(dip); |
@@ -8163,9 +8161,8 @@ out_err: | |||
8163 | static void btrfs_submit_direct(int rw, struct bio *dio_bio, | 8161 | static void btrfs_submit_direct(int rw, struct bio *dio_bio, |
8164 | struct inode *inode, loff_t file_offset) | 8162 | struct inode *inode, loff_t file_offset) |
8165 | { | 8163 | { |
8166 | struct btrfs_root *root = BTRFS_I(inode)->root; | 8164 | struct btrfs_dio_private *dip = NULL; |
8167 | struct btrfs_dio_private *dip; | 8165 | struct bio *io_bio = NULL; |
8168 | struct bio *io_bio; | ||
8169 | struct btrfs_io_bio *btrfs_bio; | 8166 | struct btrfs_io_bio *btrfs_bio; |
8170 | int skip_sum; | 8167 | int skip_sum; |
8171 | int write = rw & REQ_WRITE; | 8168 | int write = rw & REQ_WRITE; |
@@ -8182,7 +8179,7 @@ static void btrfs_submit_direct(int rw, struct bio *dio_bio, | |||
8182 | dip = kzalloc(sizeof(*dip), GFP_NOFS); | 8179 | dip = kzalloc(sizeof(*dip), GFP_NOFS); |
8183 | if (!dip) { | 8180 | if (!dip) { |
8184 | ret = -ENOMEM; | 8181 | ret = -ENOMEM; |
8185 | goto free_io_bio; | 8182 | goto free_ordered; |
8186 | } | 8183 | } |
8187 | 8184 | ||
8188 | dip->private = dio_bio->bi_private; | 8185 | dip->private = dio_bio->bi_private; |
@@ -8210,25 +8207,55 @@ static void btrfs_submit_direct(int rw, struct bio *dio_bio, | |||
8210 | 8207 | ||
8211 | if (btrfs_bio->end_io) | 8208 | if (btrfs_bio->end_io) |
8212 | btrfs_bio->end_io(btrfs_bio, ret); | 8209 | btrfs_bio->end_io(btrfs_bio, ret); |
8213 | free_io_bio: | ||
8214 | bio_put(io_bio); | ||
8215 | 8210 | ||
8216 | free_ordered: | 8211 | free_ordered: |
8217 | /* | 8212 | /* |
8218 | * If this is a write, we need to clean up the reserved space and kill | 8213 | * If we arrived here it means either we failed to submit the dip |
8219 | * the ordered extent. | 8214 | * or we either failed to clone the dio_bio or failed to allocate the |
8215 | * dip. If we cloned the dio_bio and allocated the dip, we can just | ||
8216 | * call bio_endio against our io_bio so that we get proper resource | ||
8217 | * cleanup if we fail to submit the dip, otherwise, we must do the | ||
8218 | * same as btrfs_endio_direct_[write|read] because we can't call these | ||
8219 | * callbacks - they require an allocated dip and a clone of dio_bio. | ||
8220 | */ | 8220 | */ |
8221 | if (write) { | 8221 | if (io_bio && dip) { |
8222 | struct btrfs_ordered_extent *ordered; | 8222 | bio_endio(io_bio, ret); |
8223 | ordered = btrfs_lookup_ordered_extent(inode, file_offset); | 8223 | /* |
8224 | if (!test_bit(BTRFS_ORDERED_PREALLOC, &ordered->flags) && | 8224 | * The end io callbacks free our dip, do the final put on io_bio |
8225 | !test_bit(BTRFS_ORDERED_NOCOW, &ordered->flags)) | 8225 | * and all the cleanup and final put for dio_bio (through |
8226 | btrfs_free_reserved_extent(root, ordered->start, | 8226 | * dio_end_io()). |
8227 | ordered->disk_len, 1); | 8227 | */ |
8228 | btrfs_put_ordered_extent(ordered); | 8228 | dip = NULL; |
8229 | btrfs_put_ordered_extent(ordered); | 8229 | io_bio = NULL; |
8230 | } else { | ||
8231 | if (write) { | ||
8232 | struct btrfs_ordered_extent *ordered; | ||
8233 | |||
8234 | ordered = btrfs_lookup_ordered_extent(inode, | ||
8235 | file_offset); | ||
8236 | set_bit(BTRFS_ORDERED_IOERR, &ordered->flags); | ||
8237 | /* | ||
8238 | * Decrements our ref on the ordered extent and removes | ||
8239 | * the ordered extent from the inode's ordered tree, | ||
8240 | * doing all the proper resource cleanup such as for the | ||
8241 | * reserved space and waking up any waiters for this | ||
8242 | * ordered extent (through btrfs_remove_ordered_extent). | ||
8243 | */ | ||
8244 | btrfs_finish_ordered_io(ordered); | ||
8245 | } else { | ||
8246 | unlock_extent(&BTRFS_I(inode)->io_tree, file_offset, | ||
8247 | file_offset + dio_bio->bi_iter.bi_size - 1); | ||
8248 | } | ||
8249 | clear_bit(BIO_UPTODATE, &dio_bio->bi_flags); | ||
8250 | /* | ||
8251 | * Releases and cleans up our dio_bio, no need to bio_put() | ||
8252 | * nor bio_endio()/bio_io_error() against dio_bio. | ||
8253 | */ | ||
8254 | dio_end_io(dio_bio, ret); | ||
8230 | } | 8255 | } |
8231 | bio_endio(dio_bio, ret); | 8256 | if (io_bio) |
8257 | bio_put(io_bio); | ||
8258 | kfree(dip); | ||
8232 | } | 8259 | } |
8233 | 8260 | ||
8234 | static ssize_t check_direct_IO(struct btrfs_root *root, struct kiocb *iocb, | 8261 | static ssize_t check_direct_IO(struct btrfs_root *root, struct kiocb *iocb, |
@@ -8330,9 +8357,18 @@ static ssize_t btrfs_direct_IO(struct kiocb *iocb, struct iov_iter *iter, | |||
8330 | btrfs_submit_direct, flags); | 8357 | btrfs_submit_direct, flags); |
8331 | if (iov_iter_rw(iter) == WRITE) { | 8358 | if (iov_iter_rw(iter) == WRITE) { |
8332 | current->journal_info = NULL; | 8359 | current->journal_info = NULL; |
8333 | if (ret < 0 && ret != -EIOCBQUEUED) | 8360 | if (ret < 0 && ret != -EIOCBQUEUED) { |
8334 | btrfs_delalloc_release_space(inode, count); | 8361 | /* |
8335 | else if (ret >= 0 && (size_t)ret < count) | 8362 | * If the error comes from submitting stage, |
8363 | * btrfs_get_blocsk_direct() has free'd data space, | ||
8364 | * and metadata space will be handled by | ||
8365 | * finish_ordered_fn, don't do that again to make | ||
8366 | * sure bytes_may_use is correct. | ||
8367 | */ | ||
8368 | if (!test_and_clear_bit(BTRFS_INODE_DIO_READY, | ||
8369 | &BTRFS_I(inode)->runtime_flags)) | ||
8370 | btrfs_delalloc_release_space(inode, count); | ||
8371 | } else if (ret >= 0 && (size_t)ret < count) | ||
8336 | btrfs_delalloc_release_space(inode, | 8372 | btrfs_delalloc_release_space(inode, |
8337 | count - (size_t)ret); | 8373 | count - (size_t)ret); |
8338 | } | 8374 | } |