Btrfs: fix unexpected return value of fiemap
authorLiu Bo <bo.li.liu@oracle.com>
Wed, 18 May 2016 00:21:48 +0000 (17:21 -0700)
committerDavid Sterba <dsterba@suse.com>
Wed, 25 May 2016 17:53:54 +0000 (19:53 +0200)
btrfs's fiemap is supposed to return 0 on success and return < 0 on
error. however, ret becomes 1 after looking up the last file extent:

  btrfs_lookup_file_extent ->
    btrfs_search_slot(..., ins_len=0, cow=0)

and if the offset is beyond EOF, we'll get 'path' pointed to the place
of potentail insertion, and ret == 1.

This may confuse applications using ioctl(FIEL_IOC_FIEMAP).

Signed-off-by: Liu Bo <bo.li.liu@oracle.com>
Signed-off-by: David Sterba <dsterba@suse.com>
fs/btrfs/extent_io.c

index 2f83448d34fe422e4cf4f1e6a1b973be80119917..f661688c2102735078d0319f6b9af3723708fc4e 100644 (file)
@@ -4389,8 +4389,12 @@ int extent_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo,
        if (ret < 0) {
                btrfs_free_path(path);
                return ret;
+       } else {
+               WARN_ON(!ret);
+               if (ret == 1)
+                       ret = 0;
        }
-       WARN_ON(!ret);
+
        path->slots[0]--;
        btrfs_item_key_to_cpu(path->nodes[0], &found_key, path->slots[0]);
        found_type = found_key.type;