提交 25c9bc2e 编写于 作者: G Gerhard Heift 提交者: Chris Mason

btrfs: tree_search: eliminate redundant nr_items check

If the amount of items reached the given limit of nr_items, we can leave
copy_to_sk without updating the key. Also by returning 1 we leave the loop in
search_ioctl without rechecking if we reached the given limit.
Signed-off-by: NGerhard Heift <Gerhard@Heift.Name>
Signed-off-by: NChris Mason <clm@fb.com>
Acked-by: NDavid Sterba <dsterba@suse.cz>
上级 c7548af6
...@@ -1995,7 +1995,7 @@ static noinline int copy_to_sk(struct btrfs_root *root, ...@@ -1995,7 +1995,7 @@ static noinline int copy_to_sk(struct btrfs_root *root,
if (sizeof(sh) + item_len + *sk_offset > if (sizeof(sh) + item_len + *sk_offset >
BTRFS_SEARCH_ARGS_BUFSIZE) { BTRFS_SEARCH_ARGS_BUFSIZE) {
ret = 1; ret = 1;
goto overflow; goto out;
} }
sh.objectid = key->objectid; sh.objectid = key->objectid;
...@@ -2017,8 +2017,10 @@ static noinline int copy_to_sk(struct btrfs_root *root, ...@@ -2017,8 +2017,10 @@ static noinline int copy_to_sk(struct btrfs_root *root,
} }
(*num_found)++; (*num_found)++;
if (*num_found >= sk->nr_items) if (*num_found >= sk->nr_items) {
break; ret = 1;
goto out;
}
} }
advance_key: advance_key:
ret = 0; ret = 0;
...@@ -2033,7 +2035,7 @@ static noinline int copy_to_sk(struct btrfs_root *root, ...@@ -2033,7 +2035,7 @@ static noinline int copy_to_sk(struct btrfs_root *root,
key->objectid++; key->objectid++;
} else } else
ret = 1; ret = 1;
overflow: out:
return ret; return ret;
} }
...@@ -2085,7 +2087,7 @@ static noinline int search_ioctl(struct inode *inode, ...@@ -2085,7 +2087,7 @@ static noinline int search_ioctl(struct inode *inode,
ret = copy_to_sk(root, path, &key, sk, args->buf, ret = copy_to_sk(root, path, &key, sk, args->buf,
&sk_offset, &num_found); &sk_offset, &num_found);
btrfs_release_path(path); btrfs_release_path(path);
if (ret || num_found >= sk->nr_items) if (ret)
break; break;
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册