]> asedeno.scripts.mit.edu Git - linux.git/commitdiff
btrfs: Make btrfs_find_name_in_ext_backref return struct btrfs_inode_extref
authorNikolay Borisov <nborisov@suse.com>
Tue, 27 Aug 2019 11:46:29 +0000 (14:46 +0300)
committerDavid Sterba <dsterba@suse.com>
Mon, 9 Sep 2019 12:59:16 +0000 (14:59 +0200)
btrfs_find_name_in_ext_backref returns either 0/1 depending on whether it
found a backref for the given name. If it returns true then the actual
inode_ref struct is returned in one of its parameters. That's pointless,
instead refactor the function such that it returns either a pointer
to the btrfs_inode_extref or NULL it it didn't find anything. This
streamlines the function calling convention.

Signed-off-by: Nikolay Borisov <nborisov@suse.com>
Reviewed-by: David Sterba <dsterba@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
fs/btrfs/ctree.h
fs/btrfs/inode-item.c
fs/btrfs/tree-log.c

index 31ed47d195c283c639a7b4bb47dae5c78093597c..292e21b23217b527d1a1d4f92475cfa5ae4cf127 100644 (file)
@@ -2803,11 +2803,9 @@ btrfs_lookup_inode_extref(struct btrfs_trans_handle *trans,
 struct btrfs_inode_ref *btrfs_find_name_in_backref(struct extent_buffer *leaf,
                                                   int slot, const char *name,
                                                   int name_len);
-int btrfs_find_name_in_ext_backref(struct extent_buffer *leaf, int slot,
-                                  u64 ref_objectid, const char *name,
-                                  int name_len,
-                                  struct btrfs_inode_extref **extref_ret);
-
+struct btrfs_inode_extref *btrfs_find_name_in_ext_backref(
+               struct extent_buffer *leaf, int slot, u64 ref_objectid,
+               const char *name, int name_len);
 /* file-item.c */
 struct btrfs_dio_private;
 int btrfs_del_csums(struct btrfs_trans_handle *trans,
index e13cfdcc1cd1421e3d6c2cfacfd70fcc32d147a2..668701832845cb8c4daf42fcec6af8eac3c91d5d 100644 (file)
@@ -34,10 +34,9 @@ struct btrfs_inode_ref *btrfs_find_name_in_backref(struct extent_buffer *leaf,
        return NULL;
 }
 
-int btrfs_find_name_in_ext_backref(struct extent_buffer *leaf, int slot,
-                                  u64 ref_objectid,
-                                  const char *name, int name_len,
-                                  struct btrfs_inode_extref **extref_ret)
+struct btrfs_inode_extref *btrfs_find_name_in_ext_backref(
+               struct extent_buffer *leaf, int slot, u64 ref_objectid,
+               const char *name, int name_len)
 {
        struct btrfs_inode_extref *extref;
        unsigned long ptr;
@@ -62,15 +61,12 @@ int btrfs_find_name_in_ext_backref(struct extent_buffer *leaf, int slot,
 
                if (ref_name_len == name_len &&
                    btrfs_inode_extref_parent(leaf, extref) == ref_objectid &&
-                   (memcmp_extent_buffer(leaf, name, name_ptr, name_len) == 0)) {
-                       if (extref_ret)
-                               *extref_ret = extref;
-                       return 1;
-               }
+                   (memcmp_extent_buffer(leaf, name, name_ptr, name_len) == 0))
+                       return extref;
 
                cur_offset += ref_name_len + sizeof(*extref);
        }
-       return 0;
+       return NULL;
 }
 
 /* Returns NULL if no extref found */
@@ -84,7 +80,6 @@ btrfs_lookup_inode_extref(struct btrfs_trans_handle *trans,
 {
        int ret;
        struct btrfs_key key;
-       struct btrfs_inode_extref *extref;
 
        key.objectid = inode_objectid;
        key.type = BTRFS_INODE_EXTREF_KEY;
@@ -95,11 +90,9 @@ btrfs_lookup_inode_extref(struct btrfs_trans_handle *trans,
                return ERR_PTR(ret);
        if (ret > 0)
                return NULL;
-       if (!btrfs_find_name_in_ext_backref(path->nodes[0], path->slots[0],
-                                           ref_objectid, name, name_len,
-                                           &extref))
-               return NULL;
-       return extref;
+       return btrfs_find_name_in_ext_backref(path->nodes[0], path->slots[0],
+                                             ref_objectid, name, name_len);
+
 }
 
 static int btrfs_del_inode_extref(struct btrfs_trans_handle *trans,
@@ -139,9 +132,9 @@ static int btrfs_del_inode_extref(struct btrfs_trans_handle *trans,
         * This should always succeed so error here will make the FS
         * readonly.
         */
-       if (!btrfs_find_name_in_ext_backref(path->nodes[0], path->slots[0],
-                                           ref_objectid,
-                                           name, name_len, &extref)) {
+       extref = btrfs_find_name_in_ext_backref(path->nodes[0], path->slots[0],
+                                               ref_objectid, name, name_len);
+       if (!extref) {
                btrfs_handle_fs_error(root->fs_info, -ENOENT, NULL);
                ret = -EROFS;
                goto out;
@@ -284,7 +277,7 @@ static int btrfs_insert_inode_extref(struct btrfs_trans_handle *trans,
                if (btrfs_find_name_in_ext_backref(path->nodes[0],
                                                   path->slots[0],
                                                   ref_objectid,
-                                                  name, name_len, NULL))
+                                                  name, name_len))
                        goto out;
 
                btrfs_extend_item(path, ins_len);
index 7a7ae33bea51e55488badd1ce979c793aa01cd71..7a0e3f8dec5cb5c171b6944c2dbbfe25c07cd5b3 100644 (file)
@@ -968,7 +968,7 @@ static noinline int backref_in_log(struct btrfs_root *log,
                if (btrfs_find_name_in_ext_backref(path->nodes[0],
                                                   path->slots[0],
                                                   ref_objectid,
-                                                  name, namelen, NULL))
+                                                  name, namelen))
                        match = 1;
 
                goto out;
@@ -1267,9 +1267,9 @@ static int unlink_old_inode_refs(struct btrfs_trans_handle *trans,
                        goto out;
 
                if (key->type == BTRFS_INODE_EXTREF_KEY)
-                       ret = btrfs_find_name_in_ext_backref(log_eb, log_slot,
-                                                            parent_id, name,
-                                                            namelen, NULL);
+                       ret = !!btrfs_find_name_in_ext_backref(log_eb, log_slot,
+                                                              parent_id, name,
+                                                              namelen);
                else
                        ret = !!btrfs_find_name_in_backref(log_eb, log_slot,
                                                           name, namelen);
@@ -1334,9 +1334,8 @@ static int btrfs_inode_ref_exists(struct inode *inode, struct inode *dir,
                goto out;
        }
        if (key.type == BTRFS_INODE_EXTREF_KEY)
-               ret = btrfs_find_name_in_ext_backref(path->nodes[0],
-                                                    path->slots[0], parent_id,
-                                                    name, namelen, NULL);
+               ret = !!btrfs_find_name_in_ext_backref(path->nodes[0],
+                               path->slots[0], parent_id, name, namelen);
        else
                ret = !!btrfs_find_name_in_backref(path->nodes[0], path->slots[0],
                                                   name, namelen);