Skip to contentSkip to conversation

btrfs: Use struct inode* to replace extent_io_tree::private_data

PATCH In review Qu Wenruo 6 participants 9 messages Feb 25, 2019 – Feb 26, 2019 Btrfs file system

lore
Share & tools
lore

Qu Wenruo

author
#0 lore raw

PATCH 1/1 btrfs: Use struct inode* to replace extent_io_tree::private_data

All users of extent_io_tree::private_data are expecting struct inode*. So just use struct inode* to replace extent_io_tree::private_data, and this should provide better type check.

---
 fs/btrfs/extent_io.c | 36 +++++++++++++++++-------------------
 fs/btrfs/extent_io.h |  4 ++--
 fs/btrfs/inode.c     |  2 +-
 3 files changed, 20 insertions(+), 22 deletions(-)
fs/btrfs/extent_io.c +17 -19
index e0a96f74e81e..2fd78b10830b 100644
@@ -89,7 +89,7 @@ void btrfs_leak_debug_check(void)
 static inline void __btrfs_debug_check_extent_io_range(const char *caller,
 		struct extent_io_tree *tree, u64 start, u64 end)
 {
-	struct inode *inode = tree->private_data;
+	struct inode *inode = tree->inode;
 	u64 isize;
 
 	if (!inode || !is_data_inode(inode))
@@ -201,13 +201,13 @@ void __cold extent_io_exit(void)
 }
 
 void extent_io_tree_init(struct extent_io_tree *tree,
-			 void *private_data)
+			 struct inode *inode)
 {
 	tree->state = RB_ROOT;
 	tree->ops = NULL;
 	tree->dirty_bytes = 0;
 	spin_lock_init(&tree->lock);
-	tree->private_data = private_data;
+	tree->inode = inode;
 }
 
 static struct extent_state *alloc_extent_state(gfp_t mask)
@@ -376,9 +376,8 @@ static void merge_state(struct extent_io_tree *tree,
 		other = rb_entry(other_node, struct extent_state, rb_node);
 		if (other->end == state->start - 1 &&
 		    other->state == state->state) {
-			if (tree->private_data &&
-			    is_data_inode(tree->private_data))
-				btrfs_merge_delalloc_extent(tree->private_data,
+			if (tree->inode && is_data_inode(tree->inode))
+				btrfs_merge_delalloc_extent(tree->inode,
 							    state, other);
 			state->start = other->start;
 			rb_erase(&other->rb_node, &tree->state);
@@ -391,9 +390,8 @@ static void merge_state(struct extent_io_tree *tree,
 		other = rb_entry(other_node, struct extent_state, rb_node);
 		if (other->start == state->end + 1 &&
 		    other->state == state->state) {
-			if (tree->private_data &&
-			    is_data_inode(tree->private_data))
-				btrfs_merge_delalloc_extent(tree->private_data,
+			if (tree->inode && is_data_inode(tree->inode))
+				btrfs_merge_delalloc_extent(tree->inode,
 							    state, other);
 			state->end = other->end;
 			rb_erase(&other->rb_node, &tree->state);
@@ -464,8 +462,8 @@ static int split_state(struct extent_io_tree *tree, struct extent_state *orig,
 {
 	struct rb_node *node;
 
-	if (tree->private_data && is_data_inode(tree->private_data))
-		btrfs_split_delalloc_extent(tree->private_data, orig, split);
+	if (tree->inode && is_data_inode(tree->inode))
+		btrfs_split_delalloc_extent(tree->inode, orig, split);
 
 	prealloc->start = orig->start;
 	prealloc->end = split - 1;
@@ -512,8 +510,8 @@ static struct extent_state *clear_state_bit(struct extent_io_tree *tree,
 		tree->dirty_bytes -= range;
 	}
 
-	if (tree->private_data && is_data_inode(tree->private_data))
-		btrfs_clear_delalloc_extent(tree->private_data, state, bits);
+	if (tree->inode && is_data_inode(tree->inode))
+		btrfs_clear_delalloc_extent(tree->inode, state, bits);
 
 	ret = add_extent_changeset(state, bits_to_clear, changeset, 0);
 	BUG_ON(ret < 0);
@@ -547,7 +545,7 @@ alloc_extent_state_atomic(struct extent_state *prealloc)
 
 static void extent_io_tree_panic(struct extent_io_tree *tree, int err)
 {
-	struct inode *inode = tree->private_data;
+	struct inode *inode = tree->inode;
 
 	btrfs_panic(btrfs_sb(inode->i_sb), err,
 	"locking error: extent tree was modified by another thread while locked");
@@ -791,8 +789,8 @@ static void set_state_bits(struct extent_io_tree *tree,
 	unsigned bits_to_set = *bits & ~EXTENT_CTLBITS;
 	int ret;
 
-	if (tree->private_data && is_data_inode(tree->private_data))
-		btrfs_set_delalloc_extent(tree->private_data, state, bits);
+	if (tree->inode && is_data_inode(tree->inode))
+		btrfs_set_delalloc_extent(tree->inode, state, bits);
 
 	if ((bits_to_set & EXTENT_DIRTY) && !(state->state & EXTENT_DIRTY)) {
 		u64 range = state->end - state->start + 1;
@@ -2378,8 +2376,8 @@ static int bio_readpage_error(struct bio *failed_bio, u64 phy_offset,
 		"Repair Read Error: submitting new read[%#x] to this_mirror=%d, in_validation=%d",
 		read_mode, failrec->this_mirror, failrec->in_validation);
 
-	status = tree->ops->submit_bio_hook(tree->private_data, bio, failrec->this_mirror,
-					 failrec->bio_flags, 0);
+	status = tree->ops->submit_bio_hook(tree->inode, bio,
+				failrec->this_mirror, failrec->bio_flags, 0);
 	if (status) {
 		free_io_failure(failure_tree, tree, failrec);
 		bio_put(bio);
@@ -2706,7 +2704,7 @@ static int __must_check submit_one_bio(struct bio *bio, int mirror_num,
 	bio->bi_private = NULL;
 
 	if (tree->ops)
-		ret = tree->ops->submit_bio_hook(tree->private_data, bio,
+		ret = tree->ops->submit_bio_hook(tree->inode, bio,
 					   mirror_num, bio_flags, start);
 	else
 		btrfsic_submit_bio(bio);
fs/btrfs/extent_io.h +2 -2
index 9673be3f3d1f..b656d65bca83 100644
@@ -109,7 +109,7 @@ struct extent_io_ops {
 
 struct extent_io_tree {
 	struct rb_root state;
-	void *private_data;
+	struct inode *inode;
 	u64 dirty_bytes;
 	int track_uptodate;
 	spinlock_t lock;
@@ -240,7 +240,7 @@ typedef struct extent_map *(get_extent_t)(struct btrfs_inode *inode,
 					  u64 start, u64 len,
 					  int create);
 
-void extent_io_tree_init(struct extent_io_tree *tree, void *private_data);
+void extent_io_tree_init(struct extent_io_tree *tree, struct inode *inode);
 int try_release_extent_mapping(struct page *page, gfp_t mask);
 int try_release_extent_buffer(struct page *page);
 int lock_extent_bits(struct extent_io_tree *tree, u64 start, u64 end,
fs/btrfs/inode.c +1 -1
index 5c349667c761..4fc82f582fa5 100644
@@ -10403,7 +10403,7 @@ static int btrfs_tmpfile(struct inode *dir, struct dentry *dentry, umode_t mode)
 
 void btrfs_set_range_writeback(struct extent_io_tree *tree, u64 start, u64 end)
 {
-	struct inode *inode = tree->private_data;
+	struct inode *inode = tree->inode;
 	unsigned long index = start >> PAGE_SHIFT;
 	unsigned long end_index = end >> PAGE_SHIFT;
 	struct page *page;
Signature · 1 line
2.20.1
Reviewed-by on v1 1/1
#1 lore raw
Quoted 6 lines · Qu Wenruo

All users of extent_io_tree::private_data are expecting struct inode*. So just use struct inode* to replace extent_io_tree::private_data, and this should provide better type check.

Looks good.

Quoted 159 lines
---
 fs/btrfs/extent_io.c | 36 +++++++++++++++++-------------------
 fs/btrfs/extent_io.h |  4 ++--
 fs/btrfs/inode.c     |  2 +-
 3 files changed, 20 insertions(+), 22 deletions(-)
fs/btrfs/extent_io.c +17 -19
index e0a96f74e81e..2fd78b10830b 100644
@@ -89,7 +89,7 @@ void btrfs_leak_debug_check(void)
 static inline void __btrfs_debug_check_extent_io_range(const char *caller,
                struct extent_io_tree *tree, u64 start, u64 end)
 {
-       struct inode *inode = tree->private_data;
+       struct inode *inode = tree->inode;
        u64 isize;
 
        if (!inode || !is_data_inode(inode))
@@ -201,13 +201,13 @@ void __cold extent_io_exit(void)
 }
 
 void extent_io_tree_init(struct extent_io_tree *tree,
-                        void *private_data)
+                        struct inode *inode)
 {
        tree->state = RB_ROOT;
        tree->ops = NULL;
        tree->dirty_bytes = 0;
        spin_lock_init(&tree->lock);
-       tree->private_data = private_data;
+       tree->inode = inode;
 }
 
 static struct extent_state *alloc_extent_state(gfp_t mask)
@@ -376,9 +376,8 @@ static void merge_state(struct extent_io_tree *tree,
                other = rb_entry(other_node, struct extent_state, rb_node);
                if (other->end == state->start - 1 &&
                    other->state == state->state) {
-                       if (tree->private_data &&
-                           is_data_inode(tree->private_data))
-                               btrfs_merge_delalloc_extent(tree->private_data,
+                       if (tree->inode && is_data_inode(tree->inode))
+                               btrfs_merge_delalloc_extent(tree->inode,
                                                            state, other);
                        state->start = other->start;
                        rb_erase(&other->rb_node, &tree->state);
@@ -391,9 +390,8 @@ static void merge_state(struct extent_io_tree *tree,
                other = rb_entry(other_node, struct extent_state, rb_node);
                if (other->start == state->end + 1 &&
                    other->state == state->state) {
-                       if (tree->private_data &&
-                           is_data_inode(tree->private_data))
-                               btrfs_merge_delalloc_extent(tree->private_data,
+                       if (tree->inode && is_data_inode(tree->inode))
+                               btrfs_merge_delalloc_extent(tree->inode,
                                                            state, other);
                        state->end = other->end;
                        rb_erase(&other->rb_node, &tree->state);
@@ -464,8 +462,8 @@ static int split_state(struct extent_io_tree *tree, struct extent_state *orig,
 {
        struct rb_node *node;
 
-       if (tree->private_data && is_data_inode(tree->private_data))
-               btrfs_split_delalloc_extent(tree->private_data, orig, split);
+       if (tree->inode && is_data_inode(tree->inode))
+               btrfs_split_delalloc_extent(tree->inode, orig, split);
 
        prealloc->start = orig->start;
        prealloc->end = split - 1;
@@ -512,8 +510,8 @@ static struct extent_state *clear_state_bit(struct extent_io_tree *tree,
                tree->dirty_bytes -= range;
        }
 
-       if (tree->private_data && is_data_inode(tree->private_data))
-               btrfs_clear_delalloc_extent(tree->private_data, state, bits);
+       if (tree->inode && is_data_inode(tree->inode))
+               btrfs_clear_delalloc_extent(tree->inode, state, bits);
 
        ret = add_extent_changeset(state, bits_to_clear, changeset, 0);
        BUG_ON(ret < 0);
@@ -547,7 +545,7 @@ alloc_extent_state_atomic(struct extent_state *prealloc)
 
 static void extent_io_tree_panic(struct extent_io_tree *tree, int err)
 {
-       struct inode *inode = tree->private_data;
+       struct inode *inode = tree->inode;
 
        btrfs_panic(btrfs_sb(inode->i_sb), err,
        "locking error: extent tree was modified by another thread while locked");
@@ -791,8 +789,8 @@ static void set_state_bits(struct extent_io_tree *tree,
        unsigned bits_to_set = *bits & ~EXTENT_CTLBITS;
        int ret;
 
-       if (tree->private_data && is_data_inode(tree->private_data))
-               btrfs_set_delalloc_extent(tree->private_data, state, bits);
+       if (tree->inode && is_data_inode(tree->inode))
+               btrfs_set_delalloc_extent(tree->inode, state, bits);
 
        if ((bits_to_set & EXTENT_DIRTY) && !(state->state & EXTENT_DIRTY)) {
                u64 range = state->end - state->start + 1;
@@ -2378,8 +2376,8 @@ static int bio_readpage_error(struct bio *failed_bio, u64 phy_offset,
                "Repair Read Error: submitting new read[%#x] to this_mirror=%d, in_validation=%d",
                read_mode, failrec->this_mirror, failrec->in_validation);
 
-       status = tree->ops->submit_bio_hook(tree->private_data, bio, failrec->this_mirror,
-                                        failrec->bio_flags, 0);
+       status = tree->ops->submit_bio_hook(tree->inode, bio,
+                               failrec->this_mirror, failrec->bio_flags, 0);
        if (status) {
                free_io_failure(failure_tree, tree, failrec);
                bio_put(bio);
@@ -2706,7 +2704,7 @@ static int __must_check submit_one_bio(struct bio *bio, int mirror_num,
        bio->bi_private = NULL;
 
        if (tree->ops)
-               ret = tree->ops->submit_bio_hook(tree->private_data, bio,
+               ret = tree->ops->submit_bio_hook(tree->inode, bio,
                                           mirror_num, bio_flags, start);
        else
                btrfsic_submit_bio(bio);
fs/btrfs/extent_io.h +2 -2
index 9673be3f3d1f..b656d65bca83 100644
@@ -109,7 +109,7 @@ struct extent_io_ops {
 
 struct extent_io_tree {
        struct rb_root state;
-       void *private_data;
+       struct inode *inode;
        u64 dirty_bytes;
        int track_uptodate;
        spinlock_t lock;
@@ -240,7 +240,7 @@ typedef struct extent_map *(get_extent_t)(struct btrfs_inode *inode,
                                          u64 start, u64 len,
                                          int create);
 
-void extent_io_tree_init(struct extent_io_tree *tree, void *private_data);
+void extent_io_tree_init(struct extent_io_tree *tree, struct inode *inode);
 int try_release_extent_mapping(struct page *page, gfp_t mask);
 int try_release_extent_buffer(struct page *page);
 int lock_extent_bits(struct extent_io_tree *tree, u64 start, u64 end,
fs/btrfs/inode.c +1 -2
index 5c349667c761..4fc82f582fa5 100644
@@ -10403,7 +10403,7 @@ static int btrfs_tmpfile(struct inode *dir, struct dentry *dentry, umode_t mode)
 
 void btrfs_set_range_writeback(struct extent_io_tree *tree, u64 start, u64 end)
 {
-       struct inode *inode = tree->private_data;
+       struct inode *inode = tree->inode;
        unsigned long index = start >> PAGE_SHIFT;
        unsigned long end_index = end >> PAGE_SHIFT;
        struct page *page;
--

2.20.1

Signature · 3 lines
Filipe David Manana,

“Whether you think you can, or you think you can't — you're right.”
#3 lore raw
In reply to Qu Wenruo

fs/btrfs/extent_io.h struct extent_io_ops { · line 115

Quoted 12 lines · Qu Wenruo

All users of extent_io_tree::private_data are expecting struct inode*. So just use struct inode* to replace extent_io_tree::private_data, and this should provide better type check.

struct extent_io_tree {

fs/btrfs/extent_io.h +1 -1
 	struct rb_root state;
-	void *private_data;
+	struct inode *inode;
 	u64 dirty_bytes;
 	int track_uptodate;
 	spinlock_t lock;

So this is effectively reverting c6100a4b4e3d1650deafd ("Btrfs: replace tree->mapping with tree->private_data"), that seems to be preparatory work for btree_inode removal. I haven't heared any news about that work for a long time though, so if this is going to land any time soon then we can keep it there. Otherwise, well, ack for the patch.

#4 lore raw
Quoted 5 lines · David Sterba
Quoted 4 lines · Qu Wenruo

All users of extent_io_tree::private_data are expecting struct inode*. So just use struct inode* to replace extent_io_tree::private_data, and this should provide better type check.

Quoted 11 lines

fs/btrfs/extent_io.h struct extent_io_ops { · line 115

Quoted 8 lines

struct extent_io_tree {

fs/btrfs/extent_io.h +1 -1
 	struct rb_root state;
-	void *private_data;
+	struct inode *inode;
 	u64 dirty_bytes;
 	int track_uptodate;
 	spinlock_t lock;

So this is effectively reverting c6100a4b4e3d1650deafd ("Btrfs: replace tree->mapping with tree->private_data"),

That commit message doesn't explain why this is needed for btree_inode removal.

Any idea what the extra type would be used in that case?

Thanks,
Qu

Quoted 5 lines

that seems to be preparatory
work for btree_inode removal. I haven't heared any news about that work for a long time though, so if this is going to land any time soon then we can keep it there. Otherwise, well, ack for the patch.

#5 lore raw
Quoted 20 lines · Qu Wenruo
Quoted 5 lines · David Sterba
Quoted 4 lines · Qu Wenruo

All users of extent_io_tree::private_data are expecting struct inode*. So just use struct inode* to replace extent_io_tree::private_data, and this should provide better type check.

Quoted 11 lines

fs/btrfs/extent_io.h struct extent_io_ops { · line 115

Quoted 8 lines

struct extent_io_tree {

fs/btrfs/extent_io.h +1 -1
 	struct rb_root state;
-	void *private_data;
+	struct inode *inode;
 	u64 dirty_bytes;
 	int track_uptodate;
 	spinlock_t lock;

So this is effectively reverting c6100a4b4e3d1650deafd ("Btrfs: replace tree->mapping with tree->private_data"),

Quoted 4 lines

That commit message doesn't explain why this is needed for btree_inode removal.

Any idea what the extra type would be used in that case?

I don't know, Josef in CC to answer that.

#6 lore raw
Quoted 21 lines · David Sterba
Quoted 20 lines · Qu Wenruo
Quoted 16 lines · David Sterba

fs/btrfs/extent_io.h struct extent_io_ops { · line 115

Quoted 12 lines · Qu Wenruo

All users of extent_io_tree::private_data are expecting struct inode*. So just use struct inode* to replace extent_io_tree::private_data, and this should provide better type check.

struct extent_io_tree {

fs/btrfs/extent_io.h +1 -1
 	struct rb_root state;
-	void *private_data;
+	struct inode *inode;
 	u64 dirty_bytes;
 	int track_uptodate;
 	spinlock_t lock;

So this is effectively reverting c6100a4b4e3d1650deafd ("Btrfs: replace tree->mapping with tree->private_data"),

Quoted 6 lines
Quoted 4 lines

That commit message doesn't explain why this is needed for btree_inode removal.

Any idea what the extra type would be used in that case?

I don't know, Josef in CC to answer that.

Yeah there's a mapping tree thing I make to keep track of the metadata, it holds the radix tree for the eb's and a bunch of other stuff. This needs to stay a void *. Thanks,

Josef

#7 lore raw
Quoted 25 lines · Josef Bacik
Quoted 24 lines · David Sterba
Quoted 23 lines · Qu Wenruo
Quoted 5 lines · David Sterba
Quoted 4 lines · Qu Wenruo

All users of extent_io_tree::private_data are expecting struct inode*. So just use struct inode* to replace extent_io_tree::private_data, and this should provide better type check.

Quoted 11 lines

fs/btrfs/extent_io.h struct extent_io_ops { · line 115

Quoted 8 lines

struct extent_io_tree {

fs/btrfs/extent_io.h +1 -1
 	struct rb_root state;
-	void *private_data;
+	struct inode *inode;
 	u64 dirty_bytes;
 	int track_uptodate;
 	spinlock_t lock;

So this is effectively reverting c6100a4b4e3d1650deafd ("Btrfs: replace tree->mapping with tree->private_data"),

That commit message doesn't explain why this is needed for btree_inode removal.

Quoted 7 lines
Quoted 3 lines
Quoted 1 line

Any idea what the extra type would be used in that case?

I don't know, Josef in CC to answer that.

Yeah there's a mapping tree thing I make to keep track of the metadata, it holds the radix tree for the eb's and a bunch of other stuff. This needs to stay a void *. Thanks,

Then what about an union here?

BTW, for no btree_inode case, how do we distinguish regular inode pointer with yours? An extra member?

Thanks,
Qu

Quoted 3 lines

Josef

#8 lore raw
Quoted 32 lines · Qu Wenruo
Quoted 29 lines · Josef Bacik
Quoted 27 lines · David Sterba
Quoted 20 lines · Qu Wenruo
Quoted 5 lines · David Sterba
Quoted 4 lines · Qu Wenruo

All users of extent_io_tree::private_data are expecting struct inode*. So just use struct inode* to replace extent_io_tree::private_data, and this should provide better type check.

Quoted 11 lines

fs/btrfs/extent_io.h struct extent_io_ops { · line 115

Quoted 8 lines

struct extent_io_tree {

fs/btrfs/extent_io.h +1 -1
 	struct rb_root state;
-	void *private_data;
+	struct inode *inode;
 	u64 dirty_bytes;
 	int track_uptodate;
 	spinlock_t lock;

So this is effectively reverting c6100a4b4e3d1650deafd ("Btrfs: replace tree->mapping with tree->private_data"),

Quoted 4 lines

That commit message doesn't explain why this is needed for btree_inode removal.

Any idea what the extra type would be used in that case?

I don't know, Josef in CC to answer that.

Quoted 9 lines
Quoted 3 lines

Yeah there's a mapping tree thing I make to keep track of the metadata, it holds the radix tree for the eb's and a bunch of other stuff. This needs to stay a void *. Thanks,

Then what about an union here?

BTW, for no btree_inode case, how do we distinguish regular inode pointer with yours? An extra member?

We don't have to, the only place the inode is used is when doing the callbacks. The callbacks are implementation specific, so the btree extent_io callbacks know that the void *private_data is their struct btrfs_eb_info, and the inode ones know it's their struct inode *. Thanks,

Josef