* [PATCH 0/4] Remove indirect iterators for inode references
@ 2022-06-08 21:35 David Sterba
2022-06-08 21:36 ` [PATCH 1/4] btrfs: call inode_to_path directly and drop indirection David Sterba
` (4 more replies)
0 siblings, 5 replies; 6+ messages in thread
From: David Sterba @ 2022-06-08 21:35 UTC (permalink / raw)
To: linux-btrfs; +Cc: David Sterba
There's support for a generic iterator over inode references that is for
example used to resolve inode number to all paths but there's only one
such iterator implementation so it's not necessary, unless somebody has
an idea for more such iterators. There is a similar pattern used for
extent iterator utilizing the indirection, but I think we can remove it
for the inode refs.
David Sterba (4):
btrfs: call inode_to_path directly and drop indirection
btrfs: simplify parameters of backref iterators
btrfs: sink iterator parameter to btrfs_ioctl_logical_to_ino
btrfs: remove unused typedefs get_extent_t and btrfs_work_func_t
fs/btrfs/async-thread.h | 1 -
fs/btrfs/backref.c | 88 +++++++++++++++++++++++------------------
fs/btrfs/backref.h | 3 +-
fs/btrfs/extent_io.h | 4 --
fs/btrfs/ioctl.c | 22 +----------
5 files changed, 51 insertions(+), 67 deletions(-)
--
2.36.1
^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH 1/4] btrfs: call inode_to_path directly and drop indirection
2022-06-08 21:35 [PATCH 0/4] Remove indirect iterators for inode references David Sterba
@ 2022-06-08 21:36 ` David Sterba
2022-06-08 21:36 ` [PATCH 2/4] btrfs: simplify parameters of backref iterators David Sterba
` (3 subsequent siblings)
4 siblings, 0 replies; 6+ messages in thread
From: David Sterba @ 2022-06-08 21:36 UTC (permalink / raw)
To: linux-btrfs; +Cc: David Sterba
The functions for iterating inode reference take a function parameter
but there's only one value, inode_to_path(). Remove the indirection and
call the function. As paths_from_inode would become just an alias for
iterate_irefs(), merge the two into one function.
Signed-off-by: David Sterba <dsterba@suse.com>
---
fs/btrfs/backref.c | 50 +++++++++++++++++++---------------------------
1 file changed, 20 insertions(+), 30 deletions(-)
diff --git a/fs/btrfs/backref.c b/fs/btrfs/backref.c
index ebc392ea1d74..df3352f8be24 100644
--- a/fs/btrfs/backref.c
+++ b/fs/btrfs/backref.c
@@ -2054,12 +2054,11 @@ int iterate_inodes_from_logical(u64 logical, struct btrfs_fs_info *fs_info,
return ret;
}
-typedef int (iterate_irefs_t)(u64 parent, u32 name_len, unsigned long name_off,
- struct extent_buffer *eb, void *ctx);
+static int inode_to_path(u64 inum, u32 name_len, unsigned long name_off,
+ struct extent_buffer *eb, void *ctx);
static int iterate_inode_refs(u64 inum, struct btrfs_root *fs_root,
- struct btrfs_path *path,
- iterate_irefs_t *iterate, void *ctx)
+ struct btrfs_path *path, void *ctx)
{
int ret = 0;
int slot;
@@ -2103,7 +2102,7 @@ static int iterate_inode_refs(u64 inum, struct btrfs_root *fs_root,
"following ref at offset %u for inode %llu in tree %llu",
cur, found_key.objectid,
fs_root->root_key.objectid);
- ret = iterate(parent, name_len,
+ ret = inode_to_path(parent, name_len,
(unsigned long)(iref + 1), eb, ctx);
if (ret)
break;
@@ -2119,8 +2118,7 @@ static int iterate_inode_refs(u64 inum, struct btrfs_root *fs_root,
}
static int iterate_inode_extrefs(u64 inum, struct btrfs_root *fs_root,
- struct btrfs_path *path,
- iterate_irefs_t *iterate, void *ctx)
+ struct btrfs_path *path, void *ctx)
{
int ret;
int slot;
@@ -2162,7 +2160,7 @@ static int iterate_inode_extrefs(u64 inum, struct btrfs_root *fs_root,
extref = (struct btrfs_inode_extref *)(ptr + cur_offset);
parent = btrfs_inode_extref_parent(eb, extref);
name_len = btrfs_inode_extref_name_len(eb, extref);
- ret = iterate(parent, name_len,
+ ret = inode_to_path(parent, name_len,
(unsigned long)&extref->name, eb, ctx);
if (ret)
break;
@@ -2180,26 +2178,6 @@ static int iterate_inode_extrefs(u64 inum, struct btrfs_root *fs_root,
return ret;
}
-static int iterate_irefs(u64 inum, struct btrfs_root *fs_root,
- struct btrfs_path *path, iterate_irefs_t *iterate,
- void *ctx)
-{
- int ret;
- int found_refs = 0;
-
- ret = iterate_inode_refs(inum, fs_root, path, iterate, ctx);
- if (!ret)
- ++found_refs;
- else if (ret != -ENOENT)
- return ret;
-
- ret = iterate_inode_extrefs(inum, fs_root, path, iterate, ctx);
- if (ret == -ENOENT && found_refs)
- return 0;
-
- return ret;
-}
-
/*
* returns 0 if the path could be dumped (probably truncated)
* returns <0 in case of an error
@@ -2248,8 +2226,20 @@ static int inode_to_path(u64 inum, u32 name_len, unsigned long name_off,
*/
int paths_from_inode(u64 inum, struct inode_fs_paths *ipath)
{
- return iterate_irefs(inum, ipath->fs_root, ipath->btrfs_path,
- inode_to_path, ipath);
+ int ret;
+ int found_refs = 0;
+
+ ret = iterate_inode_refs(inum, ipath->fs_root, ipath->btrfs_path, ipath);
+ if (!ret)
+ ++found_refs;
+ else if (ret != -ENOENT)
+ return ret;
+
+ ret = iterate_inode_extrefs(inum, ipath->fs_root, ipath->btrfs_path, ipath);
+ if (ret == -ENOENT && found_refs)
+ return 0;
+
+ return ret;
}
struct btrfs_data_container *init_data_container(u32 total_bytes)
--
2.36.1
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [PATCH 2/4] btrfs: simplify parameters of backref iterators
2022-06-08 21:35 [PATCH 0/4] Remove indirect iterators for inode references David Sterba
2022-06-08 21:36 ` [PATCH 1/4] btrfs: call inode_to_path directly and drop indirection David Sterba
@ 2022-06-08 21:36 ` David Sterba
2022-06-08 21:36 ` [PATCH 3/4] btrfs: sink iterator parameter to btrfs_ioctl_logical_to_ino David Sterba
` (2 subsequent siblings)
4 siblings, 0 replies; 6+ messages in thread
From: David Sterba @ 2022-06-08 21:36 UTC (permalink / raw)
To: linux-btrfs; +Cc: David Sterba
The inode reference iterator interface takes parameters that are derived
from the context parameter, but as it's a void* type the values are
passed individually.
Change the ctx type to inode_fs_path as it's the only thing we pass and
drop any parameters that are derived from that.
Signed-off-by: David Sterba <dsterba@suse.com>
---
fs/btrfs/backref.c | 23 ++++++++++++-----------
1 file changed, 12 insertions(+), 11 deletions(-)
diff --git a/fs/btrfs/backref.c b/fs/btrfs/backref.c
index df3352f8be24..e62f142fd3e5 100644
--- a/fs/btrfs/backref.c
+++ b/fs/btrfs/backref.c
@@ -2055,10 +2055,9 @@ int iterate_inodes_from_logical(u64 logical, struct btrfs_fs_info *fs_info,
}
static int inode_to_path(u64 inum, u32 name_len, unsigned long name_off,
- struct extent_buffer *eb, void *ctx);
+ struct extent_buffer *eb, struct inode_fs_paths *ipath);
-static int iterate_inode_refs(u64 inum, struct btrfs_root *fs_root,
- struct btrfs_path *path, void *ctx)
+static int iterate_inode_refs(u64 inum, struct inode_fs_paths *ipath)
{
int ret = 0;
int slot;
@@ -2067,6 +2066,8 @@ static int iterate_inode_refs(u64 inum, struct btrfs_root *fs_root,
u32 name_len;
u64 parent = 0;
int found = 0;
+ struct btrfs_root *fs_root = ipath->fs_root;
+ struct btrfs_path *path = ipath->btrfs_path;
struct extent_buffer *eb;
struct btrfs_inode_ref *iref;
struct btrfs_key found_key;
@@ -2103,7 +2104,7 @@ static int iterate_inode_refs(u64 inum, struct btrfs_root *fs_root,
cur, found_key.objectid,
fs_root->root_key.objectid);
ret = inode_to_path(parent, name_len,
- (unsigned long)(iref + 1), eb, ctx);
+ (unsigned long)(iref + 1), eb, ipath);
if (ret)
break;
len = sizeof(*iref) + name_len;
@@ -2117,14 +2118,15 @@ static int iterate_inode_refs(u64 inum, struct btrfs_root *fs_root,
return ret;
}
-static int iterate_inode_extrefs(u64 inum, struct btrfs_root *fs_root,
- struct btrfs_path *path, void *ctx)
+static int iterate_inode_extrefs(u64 inum, struct inode_fs_paths *ipath)
{
int ret;
int slot;
u64 offset = 0;
u64 parent;
int found = 0;
+ struct btrfs_root *fs_root = ipath->fs_root;
+ struct btrfs_path *path = ipath->btrfs_path;
struct extent_buffer *eb;
struct btrfs_inode_extref *extref;
u32 item_size;
@@ -2161,7 +2163,7 @@ static int iterate_inode_extrefs(u64 inum, struct btrfs_root *fs_root,
parent = btrfs_inode_extref_parent(eb, extref);
name_len = btrfs_inode_extref_name_len(eb, extref);
ret = inode_to_path(parent, name_len,
- (unsigned long)&extref->name, eb, ctx);
+ (unsigned long)&extref->name, eb, ipath);
if (ret)
break;
@@ -2183,9 +2185,8 @@ static int iterate_inode_extrefs(u64 inum, struct btrfs_root *fs_root,
* returns <0 in case of an error
*/
static int inode_to_path(u64 inum, u32 name_len, unsigned long name_off,
- struct extent_buffer *eb, void *ctx)
+ struct extent_buffer *eb, struct inode_fs_paths *ipath)
{
- struct inode_fs_paths *ipath = ctx;
char *fspath;
char *fspath_min;
int i = ipath->fspath->elem_cnt;
@@ -2229,13 +2230,13 @@ int paths_from_inode(u64 inum, struct inode_fs_paths *ipath)
int ret;
int found_refs = 0;
- ret = iterate_inode_refs(inum, ipath->fs_root, ipath->btrfs_path, ipath);
+ ret = iterate_inode_refs(inum, ipath);
if (!ret)
++found_refs;
else if (ret != -ENOENT)
return ret;
- ret = iterate_inode_extrefs(inum, ipath->fs_root, ipath->btrfs_path, ipath);
+ ret = iterate_inode_extrefs(inum, ipath);
if (ret == -ENOENT && found_refs)
return 0;
--
2.36.1
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [PATCH 3/4] btrfs: sink iterator parameter to btrfs_ioctl_logical_to_ino
2022-06-08 21:35 [PATCH 0/4] Remove indirect iterators for inode references David Sterba
2022-06-08 21:36 ` [PATCH 1/4] btrfs: call inode_to_path directly and drop indirection David Sterba
2022-06-08 21:36 ` [PATCH 2/4] btrfs: simplify parameters of backref iterators David Sterba
@ 2022-06-08 21:36 ` David Sterba
2022-06-08 21:36 ` [PATCH 4/4] btrfs: remove unused typedefs get_extent_t and btrfs_work_func_t David Sterba
2022-06-17 15:06 ` [PATCH 0/4] Remove indirect iterators for inode references David Sterba
4 siblings, 0 replies; 6+ messages in thread
From: David Sterba @ 2022-06-08 21:36 UTC (permalink / raw)
To: linux-btrfs; +Cc: David Sterba
There's only one function we pass to iterate_inodes_from_logical as
iterator, so we can drop the indirection and call it directly, after
moving the function to backref.c
Signed-off-by: David Sterba <dsterba@suse.com>
---
fs/btrfs/backref.c | 25 ++++++++++++++++++++++---
fs/btrfs/backref.h | 3 +--
fs/btrfs/ioctl.c | 22 +---------------------
3 files changed, 24 insertions(+), 26 deletions(-)
diff --git a/fs/btrfs/backref.c b/fs/btrfs/backref.c
index e62f142fd3e5..d385357e19b6 100644
--- a/fs/btrfs/backref.c
+++ b/fs/btrfs/backref.c
@@ -2028,10 +2028,29 @@ int iterate_extent_inodes(struct btrfs_fs_info *fs_info,
return ret;
}
+static int build_ino_list(u64 inum, u64 offset, u64 root, void *ctx)
+{
+ struct btrfs_data_container *inodes = ctx;
+ const size_t c = 3 * sizeof(u64);
+
+ if (inodes->bytes_left >= c) {
+ inodes->bytes_left -= c;
+ inodes->val[inodes->elem_cnt] = inum;
+ inodes->val[inodes->elem_cnt + 1] = offset;
+ inodes->val[inodes->elem_cnt + 2] = root;
+ inodes->elem_cnt += 3;
+ } else {
+ inodes->bytes_missing += c - inodes->bytes_left;
+ inodes->bytes_left = 0;
+ inodes->elem_missed += 3;
+ }
+
+ return 0;
+}
+
int iterate_inodes_from_logical(u64 logical, struct btrfs_fs_info *fs_info,
struct btrfs_path *path,
- iterate_extent_inodes_t *iterate, void *ctx,
- bool ignore_offset)
+ void *ctx, bool ignore_offset)
{
int ret;
u64 extent_item_pos;
@@ -2049,7 +2068,7 @@ int iterate_inodes_from_logical(u64 logical, struct btrfs_fs_info *fs_info,
extent_item_pos = logical - found_key.objectid;
ret = iterate_extent_inodes(fs_info, found_key.objectid,
extent_item_pos, search_commit_root,
- iterate, ctx, ignore_offset);
+ build_ino_list, ctx, ignore_offset);
return ret;
}
diff --git a/fs/btrfs/backref.h b/fs/btrfs/backref.h
index ba454032dbe2..2759de7d324c 100644
--- a/fs/btrfs/backref.h
+++ b/fs/btrfs/backref.h
@@ -35,8 +35,7 @@ int iterate_extent_inodes(struct btrfs_fs_info *fs_info,
bool ignore_offset);
int iterate_inodes_from_logical(u64 logical, struct btrfs_fs_info *fs_info,
- struct btrfs_path *path,
- iterate_extent_inodes_t *iterate, void *ctx,
+ struct btrfs_path *path, void *ctx,
bool ignore_offset);
int paths_from_inode(u64 inum, struct inode_fs_paths *ipath);
diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c
index 679ce4c5c341..7e1b4b0fbd6c 100644
--- a/fs/btrfs/ioctl.c
+++ b/fs/btrfs/ioctl.c
@@ -4243,26 +4243,6 @@ static long btrfs_ioctl_ino_to_path(struct btrfs_root *root, void __user *arg)
return ret;
}
-static int build_ino_list(u64 inum, u64 offset, u64 root, void *ctx)
-{
- struct btrfs_data_container *inodes = ctx;
- const size_t c = 3 * sizeof(u64);
-
- if (inodes->bytes_left >= c) {
- inodes->bytes_left -= c;
- inodes->val[inodes->elem_cnt] = inum;
- inodes->val[inodes->elem_cnt + 1] = offset;
- inodes->val[inodes->elem_cnt + 2] = root;
- inodes->elem_cnt += 3;
- } else {
- inodes->bytes_missing += c - inodes->bytes_left;
- inodes->bytes_left = 0;
- inodes->elem_missed += 3;
- }
-
- return 0;
-}
-
static long btrfs_ioctl_logical_to_ino(struct btrfs_fs_info *fs_info,
void __user *arg, int version)
{
@@ -4312,7 +4292,7 @@ static long btrfs_ioctl_logical_to_ino(struct btrfs_fs_info *fs_info,
}
ret = iterate_inodes_from_logical(loi->logical, fs_info, path,
- build_ino_list, inodes, ignore_offset);
+ inodes, ignore_offset);
if (ret == -EINVAL)
ret = -ENOENT;
if (ret < 0)
--
2.36.1
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [PATCH 4/4] btrfs: remove unused typedefs get_extent_t and btrfs_work_func_t
2022-06-08 21:35 [PATCH 0/4] Remove indirect iterators for inode references David Sterba
` (2 preceding siblings ...)
2022-06-08 21:36 ` [PATCH 3/4] btrfs: sink iterator parameter to btrfs_ioctl_logical_to_ino David Sterba
@ 2022-06-08 21:36 ` David Sterba
2022-06-17 15:06 ` [PATCH 0/4] Remove indirect iterators for inode references David Sterba
4 siblings, 0 replies; 6+ messages in thread
From: David Sterba @ 2022-06-08 21:36 UTC (permalink / raw)
To: linux-btrfs; +Cc: David Sterba
Signed-off-by: David Sterba <dsterba@suse.com>
---
fs/btrfs/async-thread.h | 1 -
fs/btrfs/extent_io.h | 4 ----
2 files changed, 5 deletions(-)
diff --git a/fs/btrfs/async-thread.h b/fs/btrfs/async-thread.h
index 07960529b360..6e2596ddae10 100644
--- a/fs/btrfs/async-thread.h
+++ b/fs/btrfs/async-thread.h
@@ -13,7 +13,6 @@ struct btrfs_fs_info;
struct btrfs_workqueue;
struct btrfs_work;
typedef void (*btrfs_func_t)(struct btrfs_work *arg);
-typedef void (*btrfs_work_func_t)(struct work_struct *arg);
struct btrfs_work {
btrfs_func_t func;
diff --git a/fs/btrfs/extent_io.h b/fs/btrfs/extent_io.h
index 72966cf21961..c0f1fb63eeae 100644
--- a/fs/btrfs/extent_io.h
+++ b/fs/btrfs/extent_io.h
@@ -142,10 +142,6 @@ static inline void extent_changeset_free(struct extent_changeset *changeset)
struct extent_map_tree;
-typedef struct extent_map *(get_extent_t)(struct btrfs_inode *inode,
- struct page *page, size_t pg_offset,
- u64 start, u64 len);
-
int try_release_extent_mapping(struct page *page, gfp_t mask);
int try_release_extent_buffer(struct page *page);
--
2.36.1
^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH 0/4] Remove indirect iterators for inode references
2022-06-08 21:35 [PATCH 0/4] Remove indirect iterators for inode references David Sterba
` (3 preceding siblings ...)
2022-06-08 21:36 ` [PATCH 4/4] btrfs: remove unused typedefs get_extent_t and btrfs_work_func_t David Sterba
@ 2022-06-17 15:06 ` David Sterba
4 siblings, 0 replies; 6+ messages in thread
From: David Sterba @ 2022-06-17 15:06 UTC (permalink / raw)
To: David Sterba; +Cc: linux-btrfs
On Wed, Jun 08, 2022 at 11:35:57PM +0200, David Sterba wrote:
> There's support for a generic iterator over inode references that is for
> example used to resolve inode number to all paths but there's only one
> such iterator implementation so it's not necessary, unless somebody has
> an idea for more such iterators. There is a similar pattern used for
> extent iterator utilizing the indirection, but I think we can remove it
> for the inode refs.
>
> David Sterba (4):
> btrfs: call inode_to_path directly and drop indirection
> btrfs: simplify parameters of backref iterators
> btrfs: sink iterator parameter to btrfs_ioctl_logical_to_ino
> btrfs: remove unused typedefs get_extent_t and btrfs_work_func_t
Added to misc-next.
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2022-06-17 15:10 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-06-08 21:35 [PATCH 0/4] Remove indirect iterators for inode references David Sterba
2022-06-08 21:36 ` [PATCH 1/4] btrfs: call inode_to_path directly and drop indirection David Sterba
2022-06-08 21:36 ` [PATCH 2/4] btrfs: simplify parameters of backref iterators David Sterba
2022-06-08 21:36 ` [PATCH 3/4] btrfs: sink iterator parameter to btrfs_ioctl_logical_to_ino David Sterba
2022-06-08 21:36 ` [PATCH 4/4] btrfs: remove unused typedefs get_extent_t and btrfs_work_func_t David Sterba
2022-06-17 15:06 ` [PATCH 0/4] Remove indirect iterators for inode references David Sterba
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).