aboutsummaryrefslogtreecommitdiffstats
path: root/fs/btrfs/inode.c
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@linux-foundation.org>2013-05-18 14:35:28 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2013-05-18 14:35:28 -0400
commit130901ba33c4a040e12cf7cce240c1056cc096ee (patch)
tree6471f689c88dad8bc1eabf1e404ffda60629abe7 /fs/btrfs/inode.c
parente51066824af49c2b1e9e686ee9660f58641c7f36 (diff)
parentc5cb6a0573bef87e098ee3cd946115ebe60a910e (diff)
Merge branch 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/mason/linux-btrfs
Pull btrfs fixes from Chris Mason: "Miao Xie has been very busy, fixing races and enospc problems and many other small but important pieces. Alexandre Oliva discovered some problems with how our error handling was interacting with the block layer and for now has disabled our partial handling of sub-page writes. The real sub-page work is in a series of patches from IBM that we still need to integrate and test. The code Alexandre has turned off was really incomplete. Josef has more error handling fixes and an important fix for the new skinny extent format. This also has my fix for the tracepoint crash from late in 3.9. It's the first stage in a larger clean up to get rid of btrfs_bio and make a proper bioset for all the items we need to tack into the bio. For now the bioset only holds our mirror_num and stripe_index, but for the next merge window I'll shuffle more in." * 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/mason/linux-btrfs: (25 commits) Btrfs: use a btrfs bioset instead of abusing bio internals Btrfs: make sure roots are assigned before freeing their nodes Btrfs: explicitly use global_block_rsv for quota_tree btrfs: do away with non-whole_page extent I/O Btrfs: don't invoke btrfs_invalidate_inodes() in the spin lock context Btrfs: remove BUG_ON() in btrfs_read_fs_tree_no_radix() Btrfs: pause the space balance when remounting to R/O Btrfs: fix unprotected root node of the subvolume's inode rb-tree Btrfs: fix accessing a freed tree root Btrfs: return errno if possible when we fail to allocate memory Btrfs: update the global reserve if it is empty Btrfs: don't steal the reserved space from the global reserve if their space type is different Btrfs: optimize the error handle of use_block_rsv() Btrfs: don't use global block reservation for inode cache truncation Btrfs: don't abort the current transaction if there is no enough space for inode cache Correct allowed raid levels on balance. Btrfs: fix possible memory leak in replace_path() Btrfs: fix possible memory leak in the find_parent_nodes() Btrfs: don't allow device replace on RAID5/RAID6 Btrfs: handle running extent ops with skinny metadata ...
Diffstat (limited to 'fs/btrfs/inode.c')
-rw-r--r--fs/btrfs/inode.c81
1 files changed, 53 insertions, 28 deletions
diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c
index 9b31b3b091fc..af978f7682b3 100644
--- a/fs/btrfs/inode.c
+++ b/fs/btrfs/inode.c
@@ -715,8 +715,10 @@ retry:
715 async_extent->ram_size - 1, 0); 715 async_extent->ram_size - 1, 0);
716 716
717 em = alloc_extent_map(); 717 em = alloc_extent_map();
718 if (!em) 718 if (!em) {
719 ret = -ENOMEM;
719 goto out_free_reserve; 720 goto out_free_reserve;
721 }
720 em->start = async_extent->start; 722 em->start = async_extent->start;
721 em->len = async_extent->ram_size; 723 em->len = async_extent->ram_size;
722 em->orig_start = em->start; 724 em->orig_start = em->start;
@@ -923,8 +925,10 @@ static noinline int __cow_file_range(struct btrfs_trans_handle *trans,
923 } 925 }
924 926
925 em = alloc_extent_map(); 927 em = alloc_extent_map();
926 if (!em) 928 if (!em) {
929 ret = -ENOMEM;
927 goto out_reserve; 930 goto out_reserve;
931 }
928 em->start = start; 932 em->start = start;
929 em->orig_start = em->start; 933 em->orig_start = em->start;
930 ram_size = ins.offset; 934 ram_size = ins.offset;
@@ -4724,6 +4728,7 @@ void btrfs_evict_inode(struct inode *inode)
4724 btrfs_end_transaction(trans, root); 4728 btrfs_end_transaction(trans, root);
4725 btrfs_btree_balance_dirty(root); 4729 btrfs_btree_balance_dirty(root);
4726no_delete: 4730no_delete:
4731 btrfs_remove_delayed_node(inode);
4727 clear_inode(inode); 4732 clear_inode(inode);
4728 return; 4733 return;
4729} 4734}
@@ -4839,14 +4844,13 @@ static void inode_tree_add(struct inode *inode)
4839 struct rb_node **p; 4844 struct rb_node **p;
4840 struct rb_node *parent; 4845 struct rb_node *parent;
4841 u64 ino = btrfs_ino(inode); 4846 u64 ino = btrfs_ino(inode);
4842again:
4843 p = &root->inode_tree.rb_node;
4844 parent = NULL;
4845 4847
4846 if (inode_unhashed(inode)) 4848 if (inode_unhashed(inode))
4847 return; 4849 return;
4848 4850again:
4851 parent = NULL;
4849 spin_lock(&root->inode_lock); 4852 spin_lock(&root->inode_lock);
4853 p = &root->inode_tree.rb_node;
4850 while (*p) { 4854 while (*p) {
4851 parent = *p; 4855 parent = *p;
4852 entry = rb_entry(parent, struct btrfs_inode, rb_node); 4856 entry = rb_entry(parent, struct btrfs_inode, rb_node);
@@ -6928,7 +6932,11 @@ struct btrfs_dio_private {
6928 /* IO errors */ 6932 /* IO errors */
6929 int errors; 6933 int errors;
6930 6934
6935 /* orig_bio is our btrfs_io_bio */
6931 struct bio *orig_bio; 6936 struct bio *orig_bio;
6937
6938 /* dio_bio came from fs/direct-io.c */
6939 struct bio *dio_bio;
6932}; 6940};
6933 6941
6934static void btrfs_endio_direct_read(struct bio *bio, int err) 6942static void btrfs_endio_direct_read(struct bio *bio, int err)
@@ -6938,6 +6946,7 @@ static void btrfs_endio_direct_read(struct bio *bio, int err)
6938 struct bio_vec *bvec = bio->bi_io_vec; 6946 struct bio_vec *bvec = bio->bi_io_vec;
6939 struct inode *inode = dip->inode; 6947 struct inode *inode = dip->inode;
6940 struct btrfs_root *root = BTRFS_I(inode)->root; 6948 struct btrfs_root *root = BTRFS_I(inode)->root;
6949 struct bio *dio_bio;
6941 u64 start; 6950 u64 start;
6942 6951
6943 start = dip->logical_offset; 6952 start = dip->logical_offset;
@@ -6977,14 +6986,15 @@ failed:
6977 6986
6978 unlock_extent(&BTRFS_I(inode)->io_tree, dip->logical_offset, 6987 unlock_extent(&BTRFS_I(inode)->io_tree, dip->logical_offset,
6979 dip->logical_offset + dip->bytes - 1); 6988 dip->logical_offset + dip->bytes - 1);
6980 bio->bi_private = dip->private; 6989 dio_bio = dip->dio_bio;
6981 6990
6982 kfree(dip); 6991 kfree(dip);
6983 6992
6984 /* If we had a csum failure make sure to clear the uptodate flag */ 6993 /* If we had a csum failure make sure to clear the uptodate flag */
6985 if (err) 6994 if (err)
6986 clear_bit(BIO_UPTODATE, &bio->bi_flags); 6995 clear_bit(BIO_UPTODATE, &dio_bio->bi_flags);
6987 dio_end_io(bio, err); 6996 dio_end_io(dio_bio, err);
6997 bio_put(bio);
6988} 6998}
6989 6999
6990static void btrfs_endio_direct_write(struct bio *bio, int err) 7000static void btrfs_endio_direct_write(struct bio *bio, int err)
@@ -6995,6 +7005,7 @@ static void btrfs_endio_direct_write(struct bio *bio, int err)
6995 struct btrfs_ordered_extent *ordered = NULL; 7005 struct btrfs_ordered_extent *ordered = NULL;
6996 u64 ordered_offset = dip->logical_offset; 7006 u64 ordered_offset = dip->logical_offset;
6997 u64 ordered_bytes = dip->bytes; 7007 u64 ordered_bytes = dip->bytes;
7008 struct bio *dio_bio;
6998 int ret; 7009 int ret;
6999 7010
7000 if (err) 7011 if (err)
@@ -7022,14 +7033,15 @@ out_test:
7022 goto again; 7033 goto again;
7023 } 7034 }
7024out_done: 7035out_done:
7025 bio->bi_private = dip->private; 7036 dio_bio = dip->dio_bio;
7026 7037
7027 kfree(dip); 7038 kfree(dip);
7028 7039
7029 /* If we had an error make sure to clear the uptodate flag */ 7040 /* If we had an error make sure to clear the uptodate flag */
7030 if (err) 7041 if (err)
7031 clear_bit(BIO_UPTODATE, &bio->bi_flags); 7042 clear_bit(BIO_UPTODATE, &dio_bio->bi_flags);
7032 dio_end_io(bio, err); 7043 dio_end_io(dio_bio, err);
7044 bio_put(bio);
7033} 7045}
7034 7046
7035static int __btrfs_submit_bio_start_direct_io(struct inode *inode, int rw, 7047static int __btrfs_submit_bio_start_direct_io(struct inode *inode, int rw,
@@ -7065,10 +7077,10 @@ static void btrfs_end_dio_bio(struct bio *bio, int err)
7065 if (!atomic_dec_and_test(&dip->pending_bios)) 7077 if (!atomic_dec_and_test(&dip->pending_bios))
7066 goto out; 7078 goto out;
7067 7079
7068 if (dip->errors) 7080 if (dip->errors) {
7069 bio_io_error(dip->orig_bio); 7081 bio_io_error(dip->orig_bio);
7070 else { 7082 } else {
7071 set_bit(BIO_UPTODATE, &dip->orig_bio->bi_flags); 7083 set_bit(BIO_UPTODATE, &dip->dio_bio->bi_flags);
7072 bio_endio(dip->orig_bio, 0); 7084 bio_endio(dip->orig_bio, 0);
7073 } 7085 }
7074out: 7086out:
@@ -7243,25 +7255,34 @@ out_err:
7243 return 0; 7255 return 0;
7244} 7256}
7245 7257
7246static void btrfs_submit_direct(int rw, struct bio *bio, struct inode *inode, 7258static void btrfs_submit_direct(int rw, struct bio *dio_bio,
7247 loff_t file_offset) 7259 struct inode *inode, loff_t file_offset)
7248{ 7260{
7249 struct btrfs_root *root = BTRFS_I(inode)->root; 7261 struct btrfs_root *root = BTRFS_I(inode)->root;
7250 struct btrfs_dio_private *dip; 7262 struct btrfs_dio_private *dip;
7251 struct bio_vec *bvec = bio->bi_io_vec; 7263 struct bio_vec *bvec = dio_bio->bi_io_vec;
7264 struct bio *io_bio;
7252 int skip_sum; 7265 int skip_sum;
7253 int write = rw & REQ_WRITE; 7266 int write = rw & REQ_WRITE;
7254 int ret = 0; 7267 int ret = 0;
7255 7268
7256 skip_sum = BTRFS_I(inode)->flags & BTRFS_INODE_NODATASUM; 7269 skip_sum = BTRFS_I(inode)->flags & BTRFS_INODE_NODATASUM;
7257 7270
7271 io_bio = btrfs_bio_clone(dio_bio, GFP_NOFS);
7272
7273 if (!io_bio) {
7274 ret = -ENOMEM;
7275 goto free_ordered;
7276 }
7277
7258 dip = kmalloc(sizeof(*dip), GFP_NOFS); 7278 dip = kmalloc(sizeof(*dip), GFP_NOFS);
7259 if (!dip) { 7279 if (!dip) {
7260 ret = -ENOMEM; 7280 ret = -ENOMEM;
7261 goto free_ordered; 7281 goto free_io_bio;
7262 } 7282 }
7263 7283
7264 dip->private = bio->bi_private; 7284 dip->private = dio_bio->bi_private;
7285 io_bio->bi_private = dio_bio->bi_private;
7265 dip->inode = inode; 7286 dip->inode = inode;
7266 dip->logical_offset = file_offset; 7287 dip->logical_offset = file_offset;
7267 7288
@@ -7269,22 +7290,27 @@ static void btrfs_submit_direct(int rw, struct bio *bio, struct inode *inode,
7269 do { 7290 do {
7270 dip->bytes += bvec->bv_len; 7291 dip->bytes += bvec->bv_len;
7271 bvec++; 7292 bvec++;
7272 } while (bvec <= (bio->bi_io_vec + bio->bi_vcnt - 1)); 7293 } while (bvec <= (dio_bio->bi_io_vec + dio_bio->bi_vcnt - 1));
7273 7294
7274 dip->disk_bytenr = (u64)bio->bi_sector << 9; 7295 dip->disk_bytenr = (u64)dio_bio->bi_sector << 9;
7275 bio->bi_private = dip; 7296 io_bio->bi_private = dip;
7276 dip->errors = 0; 7297 dip->errors = 0;
7277 dip->orig_bio = bio; 7298 dip->orig_bio = io_bio;
7299 dip->dio_bio = dio_bio;
7278 atomic_set(&dip->pending_bios, 0); 7300 atomic_set(&dip->pending_bios, 0);
7279 7301
7280 if (write) 7302 if (write)
7281 bio->bi_end_io = btrfs_endio_direct_write; 7303 io_bio->bi_end_io = btrfs_endio_direct_write;
7282 else 7304 else
7283 bio->bi_end_io = btrfs_endio_direct_read; 7305 io_bio->bi_end_io = btrfs_endio_direct_read;
7284 7306
7285 ret = btrfs_submit_direct_hook(rw, dip, skip_sum); 7307 ret = btrfs_submit_direct_hook(rw, dip, skip_sum);
7286 if (!ret) 7308 if (!ret)
7287 return; 7309 return;
7310
7311free_io_bio:
7312 bio_put(io_bio);
7313
7288free_ordered: 7314free_ordered:
7289 /* 7315 /*
7290 * If this is a write, we need to clean up the reserved space and kill 7316 * If this is a write, we need to clean up the reserved space and kill
@@ -7300,7 +7326,7 @@ free_ordered:
7300 btrfs_put_ordered_extent(ordered); 7326 btrfs_put_ordered_extent(ordered);
7301 btrfs_put_ordered_extent(ordered); 7327 btrfs_put_ordered_extent(ordered);
7302 } 7328 }
7303 bio_endio(bio, ret); 7329 bio_endio(dio_bio, ret);
7304} 7330}
7305 7331
7306static ssize_t check_direct_IO(struct btrfs_root *root, int rw, struct kiocb *iocb, 7332static ssize_t check_direct_IO(struct btrfs_root *root, int rw, struct kiocb *iocb,
@@ -7979,7 +8005,6 @@ void btrfs_destroy_inode(struct inode *inode)
7979 inode_tree_del(inode); 8005 inode_tree_del(inode);
7980 btrfs_drop_extent_cache(inode, 0, (u64)-1, 0); 8006 btrfs_drop_extent_cache(inode, 0, (u64)-1, 0);
7981free: 8007free:
7982 btrfs_remove_delayed_node(inode);
7983 call_rcu(&inode->i_rcu, btrfs_i_callback); 8008 call_rcu(&inode->i_rcu, btrfs_i_callback);
7984} 8009}
7985 8010