btrfs: simplify insert_orphan_item
authorDavid Sterba <dsterba@suse.cz>
Fri, 2 Jan 2015 18:12:57 +0000 (19:12 +0100)
committerSasha Levin <sasha.levin@oracle.com>
Thu, 23 Apr 2015 18:58:24 +0000 (14:58 -0400)
[ Upstream commit 9c4f61f01d269815bb7c37be3ede59c5587747c6 ]

We can search and add the orphan item in one go,
btrfs_insert_orphan_item will find out if the item already exists.

Signed-off-by: David Sterba <dsterba@suse.cz>
Signed-off-by: Sasha Levin <sasha.levin@oracle.com>
fs/btrfs/tree-log.c

index 8b40b35..3b68c75 100644 (file)
@@ -1266,21 +1266,13 @@ out:
 }
 
 static int insert_orphan_item(struct btrfs_trans_handle *trans,
-                             struct btrfs_root *root, u64 offset)
+                             struct btrfs_root *root, u64 ino)
 {
        int ret;
-       struct btrfs_path *path;
-
-       path = btrfs_alloc_path();
-       if (!path)
-               return -ENOMEM;
 
-       ret = btrfs_find_item(root, path, BTRFS_ORPHAN_OBJECTID,
-                       offset, BTRFS_ORPHAN_ITEM_KEY, NULL);
-       if (ret > 0)
-               ret = btrfs_insert_orphan_item(trans, root, offset);
-
-       btrfs_free_path(path);
+       ret = btrfs_insert_orphan_item(trans, root, ino);
+       if (ret == -EEXIST)
+               ret = 0;
 
        return ret;
 }