xref: /openbmc/linux/fs/btrfs/backref.h (revision 61dbb952)
19888c340SDavid Sterba /* SPDX-License-Identifier: GPL-2.0 */
2a542ad1bSJan Schmidt /*
3a542ad1bSJan Schmidt  * Copyright (C) 2011 STRATO.  All rights reserved.
4a542ad1bSJan Schmidt  */
5a542ad1bSJan Schmidt 
69888c340SDavid Sterba #ifndef BTRFS_BACKREF_H
79888c340SDavid Sterba #define BTRFS_BACKREF_H
8a542ad1bSJan Schmidt 
955e301fdSFilipe Brandenburger #include <linux/btrfs.h>
108da6d581SJan Schmidt #include "ulist.h"
11741188d3SQu Wenruo #include "disk-io.h"
1291cb916cSAlexander Block #include "extent_io.h"
13a542ad1bSJan Schmidt 
14a542ad1bSJan Schmidt struct inode_fs_paths {
15a542ad1bSJan Schmidt 	struct btrfs_path		*btrfs_path;
16a542ad1bSJan Schmidt 	struct btrfs_root		*fs_root;
17a542ad1bSJan Schmidt 	struct btrfs_data_container	*fspath;
18a542ad1bSJan Schmidt };
19a542ad1bSJan Schmidt 
2012a824dcSFilipe Manana struct btrfs_backref_shared_cache_entry {
2112a824dcSFilipe Manana 	u64 bytenr;
2212a824dcSFilipe Manana 	u64 gen;
2312a824dcSFilipe Manana 	bool is_shared;
2412a824dcSFilipe Manana };
2512a824dcSFilipe Manana 
26*61dbb952SFilipe Manana struct btrfs_backref_share_check_ctx {
2712a824dcSFilipe Manana 	/*
2812a824dcSFilipe Manana 	 * A path from a root to a leaf that has a file extent item pointing to
2912a824dcSFilipe Manana 	 * a given data extent should never exceed the maximum b+tree height.
3012a824dcSFilipe Manana 	 */
31*61dbb952SFilipe Manana 	struct btrfs_backref_shared_cache_entry path_cache_entries[BTRFS_MAX_LEVEL];
32*61dbb952SFilipe Manana 	bool use_path_cache;
3312a824dcSFilipe Manana };
3412a824dcSFilipe Manana 
35a542ad1bSJan Schmidt typedef int (iterate_extent_inodes_t)(u64 inum, u64 offset, u64 root,
36a542ad1bSJan Schmidt 		void *ctx);
37a542ad1bSJan Schmidt 
38a542ad1bSJan Schmidt int extent_from_logical(struct btrfs_fs_info *fs_info, u64 logical,
3969917e43SLiu Bo 			struct btrfs_path *path, struct btrfs_key *found_key,
4069917e43SLiu Bo 			u64 *flags);
41a542ad1bSJan Schmidt 
42a542ad1bSJan Schmidt int tree_backref_for_extent(unsigned long *ptr, struct extent_buffer *eb,
436eda71d0SLiu Bo 			    struct btrfs_key *key, struct btrfs_extent_item *ei,
446eda71d0SLiu Bo 			    u32 item_size, u64 *out_root, u8 *out_level);
45a542ad1bSJan Schmidt 
46a542ad1bSJan Schmidt int iterate_extent_inodes(struct btrfs_fs_info *fs_info,
47a542ad1bSJan Schmidt 				u64 extent_item_objectid,
487a3ae2f8SJan Schmidt 				u64 extent_offset, int search_commit_root,
49c995ab3cSZygo Blaxell 				iterate_extent_inodes_t *iterate, void *ctx,
50c995ab3cSZygo Blaxell 				bool ignore_offset);
51a542ad1bSJan Schmidt 
52a542ad1bSJan Schmidt int iterate_inodes_from_logical(u64 logical, struct btrfs_fs_info *fs_info,
53e3059ec0SDavid Sterba 				struct btrfs_path *path, void *ctx,
54c995ab3cSZygo Blaxell 				bool ignore_offset);
55a542ad1bSJan Schmidt 
56a542ad1bSJan Schmidt int paths_from_inode(u64 inum, struct inode_fs_paths *ipath);
57a542ad1bSJan Schmidt 
5819b546d7SQu Wenruo int btrfs_find_all_leafs(struct btrfs_trans_handle *trans,
5919b546d7SQu Wenruo 			 struct btrfs_fs_info *fs_info, u64 bytenr,
6019b546d7SQu Wenruo 			 u64 time_seq, struct ulist **leafs,
6119b546d7SQu Wenruo 			 const u64 *extent_item_pos, bool ignore_offset);
628da6d581SJan Schmidt int btrfs_find_all_roots(struct btrfs_trans_handle *trans,
638da6d581SJan Schmidt 			 struct btrfs_fs_info *fs_info, u64 bytenr,
64c7bcbb21SFilipe Manana 			 u64 time_seq, struct ulist **roots,
658949b9a1SFilipe Manana 			 bool skip_commit_root_sem);
6696b5bd77SJan Schmidt char *btrfs_ref_to_path(struct btrfs_root *fs_root, struct btrfs_path *path,
6796b5bd77SJan Schmidt 			u32 name_len, unsigned long name_off,
6896b5bd77SJan Schmidt 			struct extent_buffer *eb_in, u64 parent,
6996b5bd77SJan Schmidt 			char *dest, u32 size);
708da6d581SJan Schmidt 
71a542ad1bSJan Schmidt struct btrfs_data_container *init_data_container(u32 total_bytes);
72a542ad1bSJan Schmidt struct inode_fs_paths *init_ipath(s32 total_bytes, struct btrfs_root *fs_root,
73a542ad1bSJan Schmidt 					struct btrfs_path *path);
74a542ad1bSJan Schmidt void free_ipath(struct inode_fs_paths *ipath);
75a542ad1bSJan Schmidt 
76f186373fSMark Fasheh int btrfs_find_one_extref(struct btrfs_root *root, u64 inode_objectid,
77f186373fSMark Fasheh 			  u64 start_off, struct btrfs_path *path,
78f186373fSMark Fasheh 			  struct btrfs_inode_extref **ret_extref,
79f186373fSMark Fasheh 			  u64 *found_off);
80ceb707daSFilipe Manana int btrfs_is_data_extent_shared(struct btrfs_inode *inode, u64 bytenr,
81b8f164e3SFilipe Manana 				u64 extent_gen,
8212a824dcSFilipe Manana 				struct ulist *roots, struct ulist *tmp,
83*61dbb952SFilipe Manana 				struct btrfs_backref_share_check_ctx *ctx);
84f186373fSMark Fasheh 
85b9e9a6cbSWang Shilong int __init btrfs_prelim_ref_init(void);
86e67c718bSDavid Sterba void __cold btrfs_prelim_ref_exit(void);
8700142756SJeff Mahoney 
8800142756SJeff Mahoney struct prelim_ref {
8900142756SJeff Mahoney 	struct rb_node rbnode;
9000142756SJeff Mahoney 	u64 root_id;
9100142756SJeff Mahoney 	struct btrfs_key key_for_search;
9200142756SJeff Mahoney 	int level;
9300142756SJeff Mahoney 	int count;
9400142756SJeff Mahoney 	struct extent_inode_elem *inode_list;
9500142756SJeff Mahoney 	u64 parent;
9600142756SJeff Mahoney 	u64 wanted_disk_byte;
9700142756SJeff Mahoney };
9800142756SJeff Mahoney 
99a37f232bSQu Wenruo /*
100a37f232bSQu Wenruo  * Iterate backrefs of one extent.
101a37f232bSQu Wenruo  *
102a37f232bSQu Wenruo  * Now it only supports iteration of tree block in commit root.
103a37f232bSQu Wenruo  */
104a37f232bSQu Wenruo struct btrfs_backref_iter {
105a37f232bSQu Wenruo 	u64 bytenr;
106a37f232bSQu Wenruo 	struct btrfs_path *path;
107a37f232bSQu Wenruo 	struct btrfs_fs_info *fs_info;
108a37f232bSQu Wenruo 	struct btrfs_key cur_key;
109a37f232bSQu Wenruo 	u32 item_ptr;
110a37f232bSQu Wenruo 	u32 cur_ptr;
111a37f232bSQu Wenruo 	u32 end_ptr;
112a37f232bSQu Wenruo };
113a37f232bSQu Wenruo 
114a37f232bSQu Wenruo struct btrfs_backref_iter *btrfs_backref_iter_alloc(
115a37f232bSQu Wenruo 		struct btrfs_fs_info *fs_info, gfp_t gfp_flag);
116a37f232bSQu Wenruo 
117a37f232bSQu Wenruo static inline void btrfs_backref_iter_free(struct btrfs_backref_iter *iter)
118a37f232bSQu Wenruo {
119a37f232bSQu Wenruo 	if (!iter)
120a37f232bSQu Wenruo 		return;
121a37f232bSQu Wenruo 	btrfs_free_path(iter->path);
122a37f232bSQu Wenruo 	kfree(iter);
123a37f232bSQu Wenruo }
124a37f232bSQu Wenruo 
125c39c2ddcSQu Wenruo static inline struct extent_buffer *btrfs_backref_get_eb(
126c39c2ddcSQu Wenruo 		struct btrfs_backref_iter *iter)
127c39c2ddcSQu Wenruo {
128c39c2ddcSQu Wenruo 	if (!iter)
129c39c2ddcSQu Wenruo 		return NULL;
130c39c2ddcSQu Wenruo 	return iter->path->nodes[0];
131c39c2ddcSQu Wenruo }
132c39c2ddcSQu Wenruo 
133c39c2ddcSQu Wenruo /*
134c39c2ddcSQu Wenruo  * For metadata with EXTENT_ITEM key (non-skinny) case, the first inline data
135c39c2ddcSQu Wenruo  * is btrfs_tree_block_info, without a btrfs_extent_inline_ref header.
136c39c2ddcSQu Wenruo  *
137c39c2ddcSQu Wenruo  * This helper determines if that's the case.
138c39c2ddcSQu Wenruo  */
139c39c2ddcSQu Wenruo static inline bool btrfs_backref_has_tree_block_info(
140c39c2ddcSQu Wenruo 		struct btrfs_backref_iter *iter)
141c39c2ddcSQu Wenruo {
142c39c2ddcSQu Wenruo 	if (iter->cur_key.type == BTRFS_EXTENT_ITEM_KEY &&
143c39c2ddcSQu Wenruo 	    iter->cur_ptr - iter->item_ptr == sizeof(struct btrfs_extent_item))
144c39c2ddcSQu Wenruo 		return true;
145c39c2ddcSQu Wenruo 	return false;
146c39c2ddcSQu Wenruo }
147c39c2ddcSQu Wenruo 
148a37f232bSQu Wenruo int btrfs_backref_iter_start(struct btrfs_backref_iter *iter, u64 bytenr);
149a37f232bSQu Wenruo 
150c39c2ddcSQu Wenruo int btrfs_backref_iter_next(struct btrfs_backref_iter *iter);
151c39c2ddcSQu Wenruo 
152c39c2ddcSQu Wenruo static inline bool btrfs_backref_iter_is_inline_ref(
153c39c2ddcSQu Wenruo 		struct btrfs_backref_iter *iter)
154c39c2ddcSQu Wenruo {
155c39c2ddcSQu Wenruo 	if (iter->cur_key.type == BTRFS_EXTENT_ITEM_KEY ||
156c39c2ddcSQu Wenruo 	    iter->cur_key.type == BTRFS_METADATA_ITEM_KEY)
157c39c2ddcSQu Wenruo 		return true;
158c39c2ddcSQu Wenruo 	return false;
159c39c2ddcSQu Wenruo }
160c39c2ddcSQu Wenruo 
161a37f232bSQu Wenruo static inline void btrfs_backref_iter_release(struct btrfs_backref_iter *iter)
162a37f232bSQu Wenruo {
163a37f232bSQu Wenruo 	iter->bytenr = 0;
164a37f232bSQu Wenruo 	iter->item_ptr = 0;
165a37f232bSQu Wenruo 	iter->cur_ptr = 0;
166a37f232bSQu Wenruo 	iter->end_ptr = 0;
167a37f232bSQu Wenruo 	btrfs_release_path(iter->path);
168a37f232bSQu Wenruo 	memset(&iter->cur_key, 0, sizeof(iter->cur_key));
169a37f232bSQu Wenruo }
170a37f232bSQu Wenruo 
17170535441SQu Wenruo /*
17270535441SQu Wenruo  * Backref cache related structures
17370535441SQu Wenruo  *
17470535441SQu Wenruo  * The whole objective of backref_cache is to build a bi-directional map
17570535441SQu Wenruo  * of tree blocks (represented by backref_node) and all their parents.
17670535441SQu Wenruo  */
17770535441SQu Wenruo 
17870535441SQu Wenruo /*
17970535441SQu Wenruo  * Represent a tree block in the backref cache
18070535441SQu Wenruo  */
18170535441SQu Wenruo struct btrfs_backref_node {
182e9a28dc5SQu Wenruo 	struct {
18370535441SQu Wenruo 		struct rb_node rb_node;
18470535441SQu Wenruo 		u64 bytenr;
185e9a28dc5SQu Wenruo 	}; /* Use rb_simple_node for search/insert */
18670535441SQu Wenruo 
18770535441SQu Wenruo 	u64 new_bytenr;
18870535441SQu Wenruo 	/* Objectid of tree block owner, can be not uptodate */
18970535441SQu Wenruo 	u64 owner;
19070535441SQu Wenruo 	/* Link to pending, changed or detached list */
19170535441SQu Wenruo 	struct list_head list;
19270535441SQu Wenruo 
19370535441SQu Wenruo 	/* List of upper level edges, which link this node to its parents */
19470535441SQu Wenruo 	struct list_head upper;
19570535441SQu Wenruo 	/* List of lower level edges, which link this node to its children */
19670535441SQu Wenruo 	struct list_head lower;
19770535441SQu Wenruo 
19870535441SQu Wenruo 	/* NULL if this node is not tree root */
19970535441SQu Wenruo 	struct btrfs_root *root;
20070535441SQu Wenruo 	/* Extent buffer got by COWing the block */
20170535441SQu Wenruo 	struct extent_buffer *eb;
20270535441SQu Wenruo 	/* Level of the tree block */
20370535441SQu Wenruo 	unsigned int level:8;
20492a7cc42SQu Wenruo 	/* Is the block in a non-shareable tree */
20570535441SQu Wenruo 	unsigned int cowonly:1;
20670535441SQu Wenruo 	/* 1 if no child node is in the cache */
20770535441SQu Wenruo 	unsigned int lowest:1;
20870535441SQu Wenruo 	/* Is the extent buffer locked */
20970535441SQu Wenruo 	unsigned int locked:1;
21070535441SQu Wenruo 	/* Has the block been processed */
21170535441SQu Wenruo 	unsigned int processed:1;
21270535441SQu Wenruo 	/* Have backrefs of this block been checked */
21370535441SQu Wenruo 	unsigned int checked:1;
21470535441SQu Wenruo 	/*
21570535441SQu Wenruo 	 * 1 if corresponding block has been COWed but some upper level block
21670535441SQu Wenruo 	 * pointers may not point to the new location
21770535441SQu Wenruo 	 */
21870535441SQu Wenruo 	unsigned int pending:1;
21970535441SQu Wenruo 	/* 1 if the backref node isn't connected to any other backref node */
22070535441SQu Wenruo 	unsigned int detached:1;
22170535441SQu Wenruo 
22270535441SQu Wenruo 	/*
22370535441SQu Wenruo 	 * For generic purpose backref cache, where we only care if it's a reloc
22470535441SQu Wenruo 	 * root, doesn't care the source subvolid.
22570535441SQu Wenruo 	 */
22670535441SQu Wenruo 	unsigned int is_reloc_root:1;
22770535441SQu Wenruo };
22870535441SQu Wenruo 
22970535441SQu Wenruo #define LOWER	0
23070535441SQu Wenruo #define UPPER	1
23170535441SQu Wenruo 
23270535441SQu Wenruo /*
23370535441SQu Wenruo  * Represent an edge connecting upper and lower backref nodes.
23470535441SQu Wenruo  */
23570535441SQu Wenruo struct btrfs_backref_edge {
23670535441SQu Wenruo 	/*
23770535441SQu Wenruo 	 * list[LOWER] is linked to btrfs_backref_node::upper of lower level
23870535441SQu Wenruo 	 * node, and list[UPPER] is linked to btrfs_backref_node::lower of
23970535441SQu Wenruo 	 * upper level node.
24070535441SQu Wenruo 	 *
24170535441SQu Wenruo 	 * Also, build_backref_tree() uses list[UPPER] for pending edges, before
24270535441SQu Wenruo 	 * linking list[UPPER] to its upper level nodes.
24370535441SQu Wenruo 	 */
24470535441SQu Wenruo 	struct list_head list[2];
24570535441SQu Wenruo 
24670535441SQu Wenruo 	/* Two related nodes */
24770535441SQu Wenruo 	struct btrfs_backref_node *node[2];
24870535441SQu Wenruo };
24970535441SQu Wenruo 
25070535441SQu Wenruo struct btrfs_backref_cache {
25170535441SQu Wenruo 	/* Red black tree of all backref nodes in the cache */
25270535441SQu Wenruo 	struct rb_root rb_root;
25370535441SQu Wenruo 	/* For passing backref nodes to btrfs_reloc_cow_block */
25470535441SQu Wenruo 	struct btrfs_backref_node *path[BTRFS_MAX_LEVEL];
25570535441SQu Wenruo 	/*
25670535441SQu Wenruo 	 * List of blocks that have been COWed but some block pointers in upper
25770535441SQu Wenruo 	 * level blocks may not reflect the new location
25870535441SQu Wenruo 	 */
25970535441SQu Wenruo 	struct list_head pending[BTRFS_MAX_LEVEL];
26070535441SQu Wenruo 	/* List of backref nodes with no child node */
26170535441SQu Wenruo 	struct list_head leaves;
26270535441SQu Wenruo 	/* List of blocks that have been COWed in current transaction */
26370535441SQu Wenruo 	struct list_head changed;
26470535441SQu Wenruo 	/* List of detached backref node. */
26570535441SQu Wenruo 	struct list_head detached;
26670535441SQu Wenruo 
26770535441SQu Wenruo 	u64 last_trans;
26870535441SQu Wenruo 
26970535441SQu Wenruo 	int nr_nodes;
27070535441SQu Wenruo 	int nr_edges;
27170535441SQu Wenruo 
27270535441SQu Wenruo 	/* List of unchecked backref edges during backref cache build */
27370535441SQu Wenruo 	struct list_head pending_edge;
27470535441SQu Wenruo 
27570535441SQu Wenruo 	/* List of useless backref nodes during backref cache build */
27670535441SQu Wenruo 	struct list_head useless_node;
27770535441SQu Wenruo 
27870535441SQu Wenruo 	struct btrfs_fs_info *fs_info;
27970535441SQu Wenruo 
28070535441SQu Wenruo 	/*
28170535441SQu Wenruo 	 * Whether this cache is for relocation
28270535441SQu Wenruo 	 *
28370535441SQu Wenruo 	 * Reloction backref cache require more info for reloc root compared
28470535441SQu Wenruo 	 * to generic backref cache.
28570535441SQu Wenruo 	 */
28670535441SQu Wenruo 	unsigned int is_reloc;
28770535441SQu Wenruo };
28870535441SQu Wenruo 
289584fb121SQu Wenruo void btrfs_backref_init_cache(struct btrfs_fs_info *fs_info,
290584fb121SQu Wenruo 			      struct btrfs_backref_cache *cache, int is_reloc);
291b1818dabSQu Wenruo struct btrfs_backref_node *btrfs_backref_alloc_node(
292b1818dabSQu Wenruo 		struct btrfs_backref_cache *cache, u64 bytenr, int level);
29347254d07SQu Wenruo struct btrfs_backref_edge *btrfs_backref_alloc_edge(
29447254d07SQu Wenruo 		struct btrfs_backref_cache *cache);
295584fb121SQu Wenruo 
296f39911e5SQu Wenruo #define		LINK_LOWER	(1 << 0)
297f39911e5SQu Wenruo #define		LINK_UPPER	(1 << 1)
298f39911e5SQu Wenruo static inline void btrfs_backref_link_edge(struct btrfs_backref_edge *edge,
299f39911e5SQu Wenruo 					   struct btrfs_backref_node *lower,
300f39911e5SQu Wenruo 					   struct btrfs_backref_node *upper,
301f39911e5SQu Wenruo 					   int link_which)
302f39911e5SQu Wenruo {
303f39911e5SQu Wenruo 	ASSERT(upper && lower && upper->level == lower->level + 1);
304f39911e5SQu Wenruo 	edge->node[LOWER] = lower;
305f39911e5SQu Wenruo 	edge->node[UPPER] = upper;
306f39911e5SQu Wenruo 	if (link_which & LINK_LOWER)
307f39911e5SQu Wenruo 		list_add_tail(&edge->list[LOWER], &lower->upper);
308f39911e5SQu Wenruo 	if (link_which & LINK_UPPER)
309f39911e5SQu Wenruo 		list_add_tail(&edge->list[UPPER], &upper->lower);
310f39911e5SQu Wenruo }
311f39911e5SQu Wenruo 
312741188d3SQu Wenruo static inline void btrfs_backref_free_node(struct btrfs_backref_cache *cache,
313741188d3SQu Wenruo 					   struct btrfs_backref_node *node)
314741188d3SQu Wenruo {
315741188d3SQu Wenruo 	if (node) {
316eddda68dSJosef Bacik 		ASSERT(list_empty(&node->list));
317eddda68dSJosef Bacik 		ASSERT(list_empty(&node->lower));
318eddda68dSJosef Bacik 		ASSERT(node->eb == NULL);
319741188d3SQu Wenruo 		cache->nr_nodes--;
320741188d3SQu Wenruo 		btrfs_put_root(node->root);
321741188d3SQu Wenruo 		kfree(node);
322741188d3SQu Wenruo 	}
323741188d3SQu Wenruo }
324741188d3SQu Wenruo 
325741188d3SQu Wenruo static inline void btrfs_backref_free_edge(struct btrfs_backref_cache *cache,
326741188d3SQu Wenruo 					   struct btrfs_backref_edge *edge)
327741188d3SQu Wenruo {
328741188d3SQu Wenruo 	if (edge) {
329741188d3SQu Wenruo 		cache->nr_edges--;
330741188d3SQu Wenruo 		kfree(edge);
331741188d3SQu Wenruo 	}
332741188d3SQu Wenruo }
333741188d3SQu Wenruo 
334b0fe7078SQu Wenruo static inline void btrfs_backref_unlock_node_buffer(
335b0fe7078SQu Wenruo 		struct btrfs_backref_node *node)
336b0fe7078SQu Wenruo {
337b0fe7078SQu Wenruo 	if (node->locked) {
338b0fe7078SQu Wenruo 		btrfs_tree_unlock(node->eb);
339b0fe7078SQu Wenruo 		node->locked = 0;
340b0fe7078SQu Wenruo 	}
341b0fe7078SQu Wenruo }
342b0fe7078SQu Wenruo 
343b0fe7078SQu Wenruo static inline void btrfs_backref_drop_node_buffer(
344b0fe7078SQu Wenruo 		struct btrfs_backref_node *node)
345b0fe7078SQu Wenruo {
346b0fe7078SQu Wenruo 	if (node->eb) {
347b0fe7078SQu Wenruo 		btrfs_backref_unlock_node_buffer(node);
348b0fe7078SQu Wenruo 		free_extent_buffer(node->eb);
349b0fe7078SQu Wenruo 		node->eb = NULL;
350b0fe7078SQu Wenruo 	}
351b0fe7078SQu Wenruo }
352b0fe7078SQu Wenruo 
353b0fe7078SQu Wenruo /*
354b0fe7078SQu Wenruo  * Drop the backref node from cache without cleaning up its children
355b0fe7078SQu Wenruo  * edges.
356b0fe7078SQu Wenruo  *
357b0fe7078SQu Wenruo  * This can only be called on node without parent edges.
358b0fe7078SQu Wenruo  * The children edges are still kept as is.
359b0fe7078SQu Wenruo  */
360b0fe7078SQu Wenruo static inline void btrfs_backref_drop_node(struct btrfs_backref_cache *tree,
361b0fe7078SQu Wenruo 					   struct btrfs_backref_node *node)
362b0fe7078SQu Wenruo {
363eddda68dSJosef Bacik 	ASSERT(list_empty(&node->upper));
364b0fe7078SQu Wenruo 
365b0fe7078SQu Wenruo 	btrfs_backref_drop_node_buffer(node);
366eddda68dSJosef Bacik 	list_del_init(&node->list);
367eddda68dSJosef Bacik 	list_del_init(&node->lower);
368b0fe7078SQu Wenruo 	if (!RB_EMPTY_NODE(&node->rb_node))
369b0fe7078SQu Wenruo 		rb_erase(&node->rb_node, &tree->rb_root);
370b0fe7078SQu Wenruo 	btrfs_backref_free_node(tree, node);
371b0fe7078SQu Wenruo }
372b0fe7078SQu Wenruo 
373023acb07SQu Wenruo void btrfs_backref_cleanup_node(struct btrfs_backref_cache *cache,
374023acb07SQu Wenruo 				struct btrfs_backref_node *node);
375023acb07SQu Wenruo 
37613fe1bdbSQu Wenruo void btrfs_backref_release_cache(struct btrfs_backref_cache *cache);
37713fe1bdbSQu Wenruo 
378982c92cbSQu Wenruo static inline void btrfs_backref_panic(struct btrfs_fs_info *fs_info,
379982c92cbSQu Wenruo 				       u64 bytenr, int errno)
380982c92cbSQu Wenruo {
381982c92cbSQu Wenruo 	btrfs_panic(fs_info, errno,
382982c92cbSQu Wenruo 		    "Inconsistency in backref cache found at offset %llu",
383982c92cbSQu Wenruo 		    bytenr);
384982c92cbSQu Wenruo }
385982c92cbSQu Wenruo 
3861b60d2ecSQu Wenruo int btrfs_backref_add_tree_node(struct btrfs_backref_cache *cache,
3871b60d2ecSQu Wenruo 				struct btrfs_path *path,
3881b60d2ecSQu Wenruo 				struct btrfs_backref_iter *iter,
3891b60d2ecSQu Wenruo 				struct btrfs_key *node_key,
3901b60d2ecSQu Wenruo 				struct btrfs_backref_node *cur);
3911b60d2ecSQu Wenruo 
392fc997ed0SQu Wenruo int btrfs_backref_finish_upper_links(struct btrfs_backref_cache *cache,
393fc997ed0SQu Wenruo 				     struct btrfs_backref_node *start);
394fc997ed0SQu Wenruo 
3951b23ea18SQu Wenruo void btrfs_backref_error_cleanup(struct btrfs_backref_cache *cache,
3961b23ea18SQu Wenruo 				 struct btrfs_backref_node *node);
3971b23ea18SQu Wenruo 
398a542ad1bSJan Schmidt #endif
399