Skip to content

Commit

Permalink
btrfs: tree_search: eliminate redundant nr_items check
Browse files Browse the repository at this point in the history
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 <[email protected]>
Signed-off-by: Chris Mason <[email protected]>
Acked-by: David Sterba <[email protected]>
  • Loading branch information
gheift authored and masoncl committed Jun 13, 2014
1 parent c7548af commit 25c9bc2
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions fs/btrfs/ioctl.c
Original file line number Diff line number Diff line change
Expand Up @@ -1995,7 +1995,7 @@ static noinline int copy_to_sk(struct btrfs_root *root,
if (sizeof(sh) + item_len + *sk_offset >
BTRFS_SEARCH_ARGS_BUFSIZE) {
ret = 1;
goto overflow;
goto out;
}

sh.objectid = key->objectid;
Expand All @@ -2017,8 +2017,10 @@ static noinline int copy_to_sk(struct btrfs_root *root,
}
(*num_found)++;

if (*num_found >= sk->nr_items)
break;
if (*num_found >= sk->nr_items) {
ret = 1;
goto out;
}
}
advance_key:
ret = 0;
Expand All @@ -2033,7 +2035,7 @@ static noinline int copy_to_sk(struct btrfs_root *root,
key->objectid++;
} else
ret = 1;
overflow:
out:
return ret;
}

Expand Down Expand Up @@ -2085,7 +2087,7 @@ static noinline int search_ioctl(struct inode *inode,
ret = copy_to_sk(root, path, &key, sk, args->buf,
&sk_offset, &num_found);
btrfs_release_path(path);
if (ret || num_found >= sk->nr_items)
if (ret)
break;

}
Expand Down

0 comments on commit 25c9bc2

Please sign in to comment.