Btrfs: don't miss inode ref items in BTRFS_IOC_INO_LOOKUP.
[opensuse:kernel-source.git] / patches.suse / btrfs-0029-don-t-miss-inode-ref-items-in-btrfs_IOC_INO_LO.patch
1 From: Filipe David Borba Manana <fdmanana@gmail.com>
2 Date: Wed, 14 Aug 2013 03:00:21 +0100
3 Patch-mainline: 3.122
4 Git-commit: 18674c6cc10e78745f7af7faf26583ea9fe78c38
5 Subject: [PATCH] Btrfs: don't miss inode ref items in
6  BTRFS_IOC_INO_LOOKUP
7
8 If the inode ref key was not found and the current leaf slot
9 was 0 (first item in the leaf) the code would always return
10 -ENOENT. This was not correct because the desired inode ref
11 item might be the last item in the previous leaf.
12
13 Signed-off-by: Filipe David Borba Manana <fdmanana@gmail.com>
14 Signed-off-by: Josef Bacik <jbacik@fusionio.com>
15 Signed-off-by: Chris Mason <chris.mason@fusionio.com>
16 Signed-off-by: David Sterba <dsterba@suse.cz>
17 ---
18  fs/btrfs/ioctl.c |   18 ++++++++++--------
19  1 file changed, 10 insertions(+), 8 deletions(-)
20
21 --- a/fs/btrfs/ioctl.c
22 +++ b/fs/btrfs/ioctl.c
23 @@ -2009,19 +2009,21 @@ static noinline int btrfs_search_path_in
24                 ret = btrfs_search_slot(NULL, root, &key, path, 0, 0);
25                 if (ret < 0)
26                         goto out;
27 +               else if (ret > 0) {
28 +                       ret = btrfs_previous_item(root, path, dirid,
29 +                                                 BTRFS_INODE_REF_KEY);
30 +                       if (ret < 0)
31 +                               goto out;
32 +                       else if (ret > 0) {
33 +                               ret = -ENOENT;
34 +                               goto out;
35 +                       }
36 +               }
37  
38                 l = path->nodes[0];
39                 slot = path->slots[0];
40 -               if (ret > 0 && slot > 0)
41 -                       slot--;
42                 btrfs_item_key_to_cpu(l, &key, slot);
43  
44 -               if (ret > 0 && (key.objectid != dirid ||
45 -                               key.type != BTRFS_INODE_REF_KEY)) {
46 -                       ret = -ENOENT;
47 -                       goto out;
48 -               }
49 -
50                 iref = btrfs_item_ptr(l, slot, struct btrfs_inode_ref);
51                 len = btrfs_inode_ref_name_len(l, iref);
52                 ptr -= len + 1;