* [PATCH v2 1/2 ] Btrfs: switch to btrfs_previous_extent_item()
@ 2014-02-06 12:02 Wang Shilong
2014-02-06 12:31 ` Filipe David Manana
0 siblings, 1 reply; 2+ messages in thread
From: Wang Shilong @ 2014-02-06 12:02 UTC (permalink / raw)
To: linux-btrfs
From: Wang Shilong <wangsl.fnst@cn.fujitsu.com>
Since we have introduced btrfs_previous_extent_item() to search previous
extent item, just switch into it.
Signed-off-by: Wang Shilong <wangsl.fnst@cn.fujitsu.com>
---
Changelog:
v1->v2:
set @found_key properly and fix return value(thanks to Filipe)
---
fs/btrfs/backref.c | 37 ++++++-------------------------------
1 file changed, 6 insertions(+), 31 deletions(-)
diff --git a/fs/btrfs/backref.c b/fs/btrfs/backref.c
index c39891c..4dedb89 100644
--- a/fs/btrfs/backref.c
+++ b/fs/btrfs/backref.c
@@ -1325,38 +1325,13 @@ int extent_from_logical(struct btrfs_fs_info *fs_info, u64 logical,
if (ret < 0)
return ret;
- while (1) {
- u32 nritems;
- if (path->slots[0] == 0) {
- btrfs_set_path_blocking(path);
- ret = btrfs_prev_leaf(fs_info->extent_root, path);
- if (ret != 0) {
- if (ret > 0) {
- pr_debug("logical %llu is not within "
- "any extent\n", logical);
- ret = -ENOENT;
- }
- return ret;
- }
- } else {
- path->slots[0]--;
- }
- nritems = btrfs_header_nritems(path->nodes[0]);
- if (nritems == 0) {
- pr_debug("logical %llu is not within any extent\n",
- logical);
- return -ENOENT;
- }
- if (path->slots[0] == nritems)
- path->slots[0]--;
-
- btrfs_item_key_to_cpu(path->nodes[0], found_key,
- path->slots[0]);
- if (found_key->type == BTRFS_EXTENT_ITEM_KEY ||
- found_key->type == BTRFS_METADATA_ITEM_KEY)
- break;
+ ret = btrfs_previous_extent_item(fs_info->extent_root, path, 0);
+ if (ret) {
+ if (ret > 0)
+ ret = -ENOENT;
+ return ret;
}
-
+ btrfs_item_key_to_cpu(path->nodes[0], found_key, path->slots[0]);
if (found_key->type == BTRFS_METADATA_ITEM_KEY)
size = fs_info->extent_root->leafsize;
else if (found_key->type == BTRFS_EXTENT_ITEM_KEY)
--
1.8.4
^ permalink raw reply related [flat|nested] 2+ messages in thread* Re: [PATCH v2 1/2 ] Btrfs: switch to btrfs_previous_extent_item()
2014-02-06 12:02 [PATCH v2 1/2 ] Btrfs: switch to btrfs_previous_extent_item() Wang Shilong
@ 2014-02-06 12:31 ` Filipe David Manana
0 siblings, 0 replies; 2+ messages in thread
From: Filipe David Manana @ 2014-02-06 12:31 UTC (permalink / raw)
To: Wang Shilong; +Cc: linux-btrfs@vger.kernel.org
On Thu, Feb 6, 2014 at 12:02 PM, Wang Shilong <wangshilong1991@gmail.com> wrote:
> From: Wang Shilong <wangsl.fnst@cn.fujitsu.com>
>
> Since we have introduced btrfs_previous_extent_item() to search previous
> extent item, just switch into it.
>
> Signed-off-by: Wang Shilong <wangsl.fnst@cn.fujitsu.com>
Reviewed-by: Filipe Manana <fdmanana@gmail.com>
Thanks Shilong.
> ---
> Changelog:
> v1->v2:
> set @found_key properly and fix return value(thanks to Filipe)
> ---
> fs/btrfs/backref.c | 37 ++++++-------------------------------
> 1 file changed, 6 insertions(+), 31 deletions(-)
>
> diff --git a/fs/btrfs/backref.c b/fs/btrfs/backref.c
> index c39891c..4dedb89 100644
> --- a/fs/btrfs/backref.c
> +++ b/fs/btrfs/backref.c
> @@ -1325,38 +1325,13 @@ int extent_from_logical(struct btrfs_fs_info *fs_info, u64 logical,
> if (ret < 0)
> return ret;
>
> - while (1) {
> - u32 nritems;
> - if (path->slots[0] == 0) {
> - btrfs_set_path_blocking(path);
> - ret = btrfs_prev_leaf(fs_info->extent_root, path);
> - if (ret != 0) {
> - if (ret > 0) {
> - pr_debug("logical %llu is not within "
> - "any extent\n", logical);
> - ret = -ENOENT;
> - }
> - return ret;
> - }
> - } else {
> - path->slots[0]--;
> - }
> - nritems = btrfs_header_nritems(path->nodes[0]);
> - if (nritems == 0) {
> - pr_debug("logical %llu is not within any extent\n",
> - logical);
> - return -ENOENT;
> - }
> - if (path->slots[0] == nritems)
> - path->slots[0]--;
> -
> - btrfs_item_key_to_cpu(path->nodes[0], found_key,
> - path->slots[0]);
> - if (found_key->type == BTRFS_EXTENT_ITEM_KEY ||
> - found_key->type == BTRFS_METADATA_ITEM_KEY)
> - break;
> + ret = btrfs_previous_extent_item(fs_info->extent_root, path, 0);
> + if (ret) {
> + if (ret > 0)
> + ret = -ENOENT;
> + return ret;
> }
> -
> + btrfs_item_key_to_cpu(path->nodes[0], found_key, path->slots[0]);
> if (found_key->type == BTRFS_METADATA_ITEM_KEY)
> size = fs_info->extent_root->leafsize;
> else if (found_key->type == BTRFS_EXTENT_ITEM_KEY)
> --
> 1.8.4
>
> --
> To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at http://vger.kernel.org/majordomo-info.html
--
Filipe David Manana,
"Reasonable men adapt themselves to the world.
Unreasonable men adapt the world to themselves.
That's why all progress depends on unreasonable men."
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2014-02-06 12:31 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-02-06 12:02 [PATCH v2 1/2 ] Btrfs: switch to btrfs_previous_extent_item() Wang Shilong
2014-02-06 12:31 ` Filipe David Manana
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).