From: Qu Wenruo <wqu@suse.com>
To: linux-btrfs@vger.kernel.org
Subject: [PATCH v2 3/5] btrfs-progs: extent_io: Refactor alloc_extent_buffer() to follow kernel parameters
Date: Fri, 30 Mar 2018 13:48:55 +0800 [thread overview]
Message-ID: <20180330054857.6106-4-wqu@suse.com> (raw)
In-Reply-To: <20180330054857.6106-1-wqu@suse.com>
Instead of using the internal struct extent_io_tree, use struct fs_info.
This does not only unify the interface between kernel and btrfs-progs,
but also makes later btrfs_print_tree() use less parameters.
Signed-off-by: Qu Wenruo <wqu@suse.com>
---
convert/source-reiserfs.c | 3 +--
disk-io.c | 3 +--
extent_io.c | 14 +++++++++-----
extent_io.h | 3 ++-
4 files changed, 13 insertions(+), 10 deletions(-)
diff --git a/convert/source-reiserfs.c b/convert/source-reiserfs.c
index eeb68d962c5d..e0b3b685f764 100644
--- a/convert/source-reiserfs.c
+++ b/convert/source-reiserfs.c
@@ -350,8 +350,7 @@ static int convert_direct(struct btrfs_trans_handle *trans,
if (ret)
return ret;
- eb = alloc_extent_buffer(&root->fs_info->extent_cache, key.objectid,
- sectorsize);
+ eb = alloc_extent_buffer(root->fs_info, key.objectid, sectorsize);
if (!eb)
return -ENOMEM;
diff --git a/disk-io.c b/disk-io.c
index 76958aef239e..610963357675 100644
--- a/disk-io.c
+++ b/disk-io.c
@@ -184,8 +184,7 @@ struct extent_buffer *btrfs_find_tree_block(struct btrfs_fs_info *fs_info,
struct extent_buffer* btrfs_find_create_tree_block(
struct btrfs_fs_info *fs_info, u64 bytenr)
{
- return alloc_extent_buffer(&fs_info->extent_cache, bytenr,
- fs_info->nodesize);
+ return alloc_extent_buffer(fs_info, bytenr, fs_info->nodesize);
}
void readahead_tree_block(struct btrfs_fs_info *fs_info, u64 bytenr,
diff --git a/extent_io.c b/extent_io.c
index 3117782335ab..198492699438 100644
--- a/extent_io.c
+++ b/extent_io.c
@@ -545,7 +545,7 @@ out:
return ret;
}
-static struct extent_buffer *__alloc_extent_buffer(struct extent_io_tree *tree,
+static struct extent_buffer *__alloc_extent_buffer(struct btrfs_fs_info *info,
u64 bytenr, u32 blocksize)
{
struct extent_buffer *eb;
@@ -558,11 +558,12 @@ static struct extent_buffer *__alloc_extent_buffer(struct extent_io_tree *tree,
eb->len = blocksize;
eb->refs = 1;
eb->flags = 0;
- eb->tree = tree;
eb->fd = -1;
eb->dev_bytenr = (u64)-1;
eb->cache_node.start = bytenr;
eb->cache_node.size = blocksize;
+ eb->fs_info = info;
+ eb->tree = &info->extent_cache;
INIT_LIST_HEAD(&eb->recow);
INIT_LIST_HEAD(&eb->lru);
@@ -573,9 +574,11 @@ struct extent_buffer *btrfs_clone_extent_buffer(struct extent_buffer *src)
{
struct extent_buffer *new;
- new = __alloc_extent_buffer(NULL, src->start, src->len);
+ new = __alloc_extent_buffer(src->fs_info, src->start, src->len);
if (!new)
return NULL;
+ /* cloned eb is not linked into fs_info->extent_cache */
+ new->tree = NULL;
copy_extent_buffer(new, src, 0, 0, src->len);
new->flags |= EXTENT_BUFFER_DUMMY;
@@ -665,10 +668,11 @@ static void trim_extent_buffer_cache(struct extent_io_tree *tree)
}
}
-struct extent_buffer *alloc_extent_buffer(struct extent_io_tree *tree,
+struct extent_buffer *alloc_extent_buffer(struct btrfs_fs_info *fs_info,
u64 bytenr, u32 blocksize)
{
struct extent_buffer *eb;
+ struct extent_io_tree *tree = &fs_info->extent_cache;
struct cache_extent *cache;
cache = lookup_cache_extent(&tree->cache, bytenr, blocksize);
@@ -685,7 +689,7 @@ struct extent_buffer *alloc_extent_buffer(struct extent_io_tree *tree,
cache_node);
free_extent_buffer(eb);
}
- eb = __alloc_extent_buffer(tree, bytenr, blocksize);
+ eb = __alloc_extent_buffer(fs_info, bytenr, blocksize);
if (!eb)
return NULL;
ret = insert_cache_extent(&tree->cache, &eb->cache_node);
diff --git a/extent_io.h b/extent_io.h
index 17a4a8298635..f8f73089ab40 100644
--- a/extent_io.h
+++ b/extent_io.h
@@ -98,6 +98,7 @@ struct extent_buffer {
int refs;
u32 flags;
int fd;
+ struct btrfs_fs_info *fs_info;
char data[] __attribute__((aligned(8)));
};
@@ -145,7 +146,7 @@ struct extent_buffer *find_extent_buffer(struct extent_io_tree *tree,
u64 bytenr, u32 blocksize);
struct extent_buffer *find_first_extent_buffer(struct extent_io_tree *tree,
u64 start);
-struct extent_buffer *alloc_extent_buffer(struct extent_io_tree *tree,
+struct extent_buffer *alloc_extent_buffer(struct btrfs_fs_info *fs_info,
u64 bytenr, u32 blocksize);
struct extent_buffer *btrfs_clone_extent_buffer(struct extent_buffer *src);
void free_extent_buffer(struct extent_buffer *eb);
--
2.16.3
next prev parent reply other threads:[~2018-03-30 5:49 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-03-30 5:48 [PATCH v2 0/5] btrfs-progs: extent buffer related refactor and cleanup Qu Wenruo
2018-03-30 5:48 ` [PATCH v2 1/5] btrfs-progs: extent_io: Fix NULL pointer dereference in free_extent_buffer_final() Qu Wenruo
2018-03-30 5:48 ` [PATCH v2 2/5] btrfs-progs: extent_io: Init eb->lru to avoid NULL pointer dereference Qu Wenruo
2018-03-30 5:48 ` Qu Wenruo [this message]
2018-03-30 5:48 ` [PATCH v2 4/5] btrfs-progs: Unify btrfs_leaf_free_psace() parameter with kernel Qu Wenruo
2018-03-30 5:48 ` [PATCH v2 5/5] btrfs-progs: print-tree: Remove btrfs_root parameter Qu Wenruo
2018-03-30 7:01 ` [PATCH v2 0/5] btrfs-progs: extent buffer related refactor and cleanup Lu Fengqi
2018-04-09 14:54 ` David Sterba
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20180330054857.6106-4-wqu@suse.com \
--to=wqu@suse.com \
--cc=linux-btrfs@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).