aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNikolay Borisov <nborisov@suse.com>2018-11-01 08:09:50 -0400
committerDavid Sterba <dsterba@suse.com>2018-12-17 08:51:28 -0500
commite06a1fc99cc7eca09118cc02c4d7540fa69e9d09 (patch)
tree3a628c775a371dc6b4387cdaa17d701193c45263
parent65a680f6b7d6e83ca3a440588d3581f4a38265bf (diff)
btrfs: Remove extent_io_ops::set_bit_hook extent_io callback
This callback is used to properly account delalloc extents for data inodes (ordinary file inodes and freespace v1 inodes). Those can be easily identified since they have their extent_io trees ->private_data member point to the inode. Let's exploit this fact to remove the needless indirection through extent_io_hooks and directly call the function. Also give the function a name which reflects its purpose - btrfs_set_delalloc_extent. This patch also modified test_find_delalloc so that the extent_io_tree used for testing doesn't have its ->private_data set which would have caused a crash in btrfs_set_delalloc_extent due to the btrfs_inode->root member not being initialised. The old version of the code also didn't call set_bit_hook since the extent_io ops weren't set for the inode. No functional changes. Reviewed-by: Josef Bacik <josef@toxicpanda.com> Signed-off-by: Nikolay Borisov <nborisov@suse.com> Reviewed-by: David Sterba <dsterba@suse.com> Signed-off-by: David Sterba <dsterba@suse.com>
-rw-r--r--fs/btrfs/ctree.h2
-rw-r--r--fs/btrfs/extent_io.c11
-rw-r--r--fs/btrfs/extent_io.h2
-rw-r--r--fs/btrfs/inode.c12
-rw-r--r--fs/btrfs/tests/extent-io-tests.c2
5 files changed, 10 insertions, 19 deletions
diff --git a/fs/btrfs/ctree.h b/fs/btrfs/ctree.h
index edcbca9cd813..9a0e4e1c59ea 100644
--- a/fs/btrfs/ctree.h
+++ b/fs/btrfs/ctree.h
@@ -3150,6 +3150,8 @@ int btrfs_create_subvol_root(struct btrfs_trans_handle *trans,
3150 struct btrfs_root *new_root, 3150 struct btrfs_root *new_root,
3151 struct btrfs_root *parent_root, 3151 struct btrfs_root *parent_root,
3152 u64 new_dirid); 3152 u64 new_dirid);
3153void btrfs_set_delalloc_extent(struct inode *inode, struct extent_state *state,
3154 unsigned *bits);
3153int btrfs_merge_bio_hook(struct page *page, unsigned long offset, 3155int btrfs_merge_bio_hook(struct page *page, unsigned long offset,
3154 size_t size, struct bio *bio, 3156 size_t size, struct bio *bio,
3155 unsigned long bio_flags); 3157 unsigned long bio_flags);
diff --git a/fs/btrfs/extent_io.c b/fs/btrfs/extent_io.c
index c63334c6b008..1678adae7963 100644
--- a/fs/btrfs/extent_io.c
+++ b/fs/btrfs/extent_io.c
@@ -404,13 +404,6 @@ static void merge_state(struct extent_io_tree *tree,
404 } 404 }
405} 405}
406 406
407static void set_state_cb(struct extent_io_tree *tree,
408 struct extent_state *state, unsigned *bits)
409{
410 if (tree->ops && tree->ops->set_bit_hook)
411 tree->ops->set_bit_hook(tree->private_data, state, bits);
412}
413
414static void clear_state_cb(struct extent_io_tree *tree, 407static void clear_state_cb(struct extent_io_tree *tree,
415 struct extent_state *state, unsigned *bits) 408 struct extent_state *state, unsigned *bits)
416{ 409{
@@ -809,7 +802,9 @@ static void set_state_bits(struct extent_io_tree *tree,
809 unsigned bits_to_set = *bits & ~EXTENT_CTLBITS; 802 unsigned bits_to_set = *bits & ~EXTENT_CTLBITS;
810 int ret; 803 int ret;
811 804
812 set_state_cb(tree, state, bits); 805 if (tree->private_data && is_data_inode(tree->private_data))
806 btrfs_set_delalloc_extent(tree->private_data, state, bits);
807
813 if ((bits_to_set & EXTENT_DIRTY) && !(state->state & EXTENT_DIRTY)) { 808 if ((bits_to_set & EXTENT_DIRTY) && !(state->state & EXTENT_DIRTY)) {
814 u64 range = state->end - state->start + 1; 809 u64 range = state->end - state->start + 1;
815 tree->dirty_bytes += range; 810 tree->dirty_bytes += range;
diff --git a/fs/btrfs/extent_io.h b/fs/btrfs/extent_io.h
index 3cb84a0fbaab..b3235d46b5c3 100644
--- a/fs/btrfs/extent_io.h
+++ b/fs/btrfs/extent_io.h
@@ -106,8 +106,6 @@ struct extent_io_ops {
106 /* 106 /*
107 * Optional hooks, called if the pointer is not NULL 107 * Optional hooks, called if the pointer is not NULL
108 */ 108 */
109 void (*set_bit_hook)(void *private_data, struct extent_state *state,
110 unsigned *bits);
111 void (*clear_bit_hook)(void *private_data, 109 void (*clear_bit_hook)(void *private_data,
112 struct extent_state *state, 110 struct extent_state *state,
113 unsigned *bits); 111 unsigned *bits);
diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c
index 175ef341b8ae..f95733fc9704 100644
--- a/fs/btrfs/inode.c
+++ b/fs/btrfs/inode.c
@@ -1755,15 +1755,12 @@ static void btrfs_del_delalloc_inode(struct btrfs_root *root,
1755} 1755}
1756 1756
1757/* 1757/*
1758 * extent_io.c set_bit_hook, used to track delayed allocation 1758 * Properly track delayed allocation bytes in the inode and to maintain the
1759 * bytes in this file, and to maintain the list of inodes that 1759 * list of inodes that have pending delalloc work to be done.
1760 * have pending delalloc work to be done.
1761 */ 1760 */
1762static void btrfs_set_bit_hook(void *private_data, 1761void btrfs_set_delalloc_extent(struct inode *inode, struct extent_state *state,
1763 struct extent_state *state, unsigned *bits) 1762 unsigned *bits)
1764{ 1763{
1765 struct inode *inode = private_data;
1766
1767 struct btrfs_fs_info *fs_info = btrfs_sb(inode->i_sb); 1764 struct btrfs_fs_info *fs_info = btrfs_sb(inode->i_sb);
1768 1765
1769 if ((*bits & EXTENT_DEFRAG) && !(*bits & EXTENT_DELALLOC)) 1766 if ((*bits & EXTENT_DEFRAG) && !(*bits & EXTENT_DELALLOC))
@@ -10512,7 +10509,6 @@ static const struct extent_io_ops btrfs_extent_io_ops = {
10512 .readpage_io_failed_hook = btrfs_readpage_io_failed_hook, 10509 .readpage_io_failed_hook = btrfs_readpage_io_failed_hook,
10513 10510
10514 /* optional callbacks */ 10511 /* optional callbacks */
10515 .set_bit_hook = btrfs_set_bit_hook,
10516 .clear_bit_hook = btrfs_clear_bit_hook, 10512 .clear_bit_hook = btrfs_clear_bit_hook,
10517 .merge_extent_hook = btrfs_merge_extent_hook, 10513 .merge_extent_hook = btrfs_merge_extent_hook,
10518 .split_extent_hook = btrfs_split_extent_hook, 10514 .split_extent_hook = btrfs_split_extent_hook,
diff --git a/fs/btrfs/tests/extent-io-tests.c b/fs/btrfs/tests/extent-io-tests.c
index 9e0f4a01be14..ac8b5e35797d 100644
--- a/fs/btrfs/tests/extent-io-tests.c
+++ b/fs/btrfs/tests/extent-io-tests.c
@@ -76,7 +76,7 @@ static int test_find_delalloc(u32 sectorsize)
76 return -ENOMEM; 76 return -ENOMEM;
77 } 77 }
78 78
79 extent_io_tree_init(&tmp, inode); 79 extent_io_tree_init(&tmp, NULL);
80 80
81 /* 81 /*
82 * First go through and create and mark all of our pages dirty, we pin 82 * First go through and create and mark all of our pages dirty, we pin