diff options
author | Gerhard Heift <gerhard@heift.name> | 2014-01-30 10:23:57 -0500 |
---|---|---|
committer | Chris Mason <clm@fb.com> | 2014-06-12 21:20:39 -0400 |
commit | 25c9bc2e2bc9d67de7fc49ff2784cae5de755192 (patch) | |
tree | fe51f95796bd4e6126c70bcc48e01ed08add3f57 | |
parent | c7548af69d9ef71512eb52d8009521eba3e768fd (diff) |
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: Gerhard Heift <Gerhard@Heift.Name>
Signed-off-by: Chris Mason <clm@fb.com>
Acked-by: David Sterba <dsterba@suse.cz>
-rw-r--r-- | fs/btrfs/ioctl.c | 12 |
1 files changed, 7 insertions, 5 deletions
diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c index c2e796b664c1..65148cd102cd 100644 --- a/fs/btrfs/ioctl.c +++ b/fs/btrfs/ioctl.c | |||
@@ -1995,7 +1995,7 @@ static noinline int copy_to_sk(struct btrfs_root *root, | |||
1995 | if (sizeof(sh) + item_len + *sk_offset > | 1995 | if (sizeof(sh) + item_len + *sk_offset > |
1996 | BTRFS_SEARCH_ARGS_BUFSIZE) { | 1996 | BTRFS_SEARCH_ARGS_BUFSIZE) { |
1997 | ret = 1; | 1997 | ret = 1; |
1998 | goto overflow; | 1998 | goto out; |
1999 | } | 1999 | } |
2000 | 2000 | ||
2001 | sh.objectid = key->objectid; | 2001 | sh.objectid = key->objectid; |
@@ -2017,8 +2017,10 @@ static noinline int copy_to_sk(struct btrfs_root *root, | |||
2017 | } | 2017 | } |
2018 | (*num_found)++; | 2018 | (*num_found)++; |
2019 | 2019 | ||
2020 | if (*num_found >= sk->nr_items) | 2020 | if (*num_found >= sk->nr_items) { |
2021 | break; | 2021 | ret = 1; |
2022 | goto out; | ||
2023 | } | ||
2022 | } | 2024 | } |
2023 | advance_key: | 2025 | advance_key: |
2024 | ret = 0; | 2026 | ret = 0; |
@@ -2033,7 +2035,7 @@ advance_key: | |||
2033 | key->objectid++; | 2035 | key->objectid++; |
2034 | } else | 2036 | } else |
2035 | ret = 1; | 2037 | ret = 1; |
2036 | overflow: | 2038 | out: |
2037 | return ret; | 2039 | return ret; |
2038 | } | 2040 | } |
2039 | 2041 | ||
@@ -2085,7 +2087,7 @@ static noinline int search_ioctl(struct inode *inode, | |||
2085 | ret = copy_to_sk(root, path, &key, sk, args->buf, | 2087 | ret = copy_to_sk(root, path, &key, sk, args->buf, |
2086 | &sk_offset, &num_found); | 2088 | &sk_offset, &num_found); |
2087 | btrfs_release_path(path); | 2089 | btrfs_release_path(path); |
2088 | if (ret || num_found >= sk->nr_items) | 2090 | if (ret) |
2089 | break; | 2091 | break; |
2090 | 2092 | ||
2091 | } | 2093 | } |