Commit | Line | Data |
---|---|---|
31153d81 YZ |
1 | /* |
2 | * Copyright (C) 2008 Oracle. All rights reserved. | |
3 | * | |
4 | * This program is free software; you can redistribute it and/or | |
5 | * modify it under the terms of the GNU General Public | |
6 | * License v2 as published by the Free Software Foundation. | |
7 | * | |
8 | * This program is distributed in the hope that it will be useful, | |
9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
11 | * General Public License for more details. | |
12 | * | |
13 | * You should have received a copy of the GNU General Public | |
14 | * License along with this program; if not, write to the | |
15 | * Free Software Foundation, Inc., 59 Temple Place - Suite 330, | |
16 | * Boston, MA 021110-1307, USA. | |
17 | */ | |
18 | ||
19 | struct btrfs_extent_info { | |
20 | u64 bytenr; | |
21 | u64 num_bytes; | |
22 | u64 objectid; | |
23 | u64 offset; | |
24 | }; | |
25 | ||
26 | struct btrfs_leaf_ref { | |
27 | struct rb_node rb_node; | |
28 | struct btrfs_key key; | |
29 | int in_tree; | |
30 | atomic_t usage; | |
31 | ||
32 | u64 bytenr; | |
33 | u64 owner; | |
34 | u64 generation; | |
35 | int nritems; | |
36 | struct btrfs_extent_info extents[]; | |
37 | }; | |
38 | ||
39 | struct btrfs_leaf_ref_tree { | |
40 | struct rb_root root; | |
41 | struct btrfs_leaf_ref *last; | |
42 | u64 generation; | |
43 | spinlock_t lock; | |
44 | }; | |
45 | ||
46 | static inline size_t btrfs_leaf_ref_size(int nr_extents) | |
47 | { | |
48 | return sizeof(struct btrfs_leaf_ref) + | |
49 | sizeof(struct btrfs_extent_info) * nr_extents; | |
50 | } | |
51 | ||
52 | static inline void btrfs_leaf_ref_tree_init(struct btrfs_leaf_ref_tree *tree) | |
53 | { | |
54 | tree->root.rb_node = NULL; | |
55 | tree->last = NULL; | |
56 | tree->generation = 0; | |
57 | spin_lock_init(&tree->lock); | |
58 | } | |
59 | ||
60 | static inline int btrfs_leaf_ref_tree_empty(struct btrfs_leaf_ref_tree *tree) | |
61 | { | |
62 | return RB_EMPTY_ROOT(&tree->root); | |
63 | } | |
64 | ||
65 | void btrfs_leaf_ref_tree_init(struct btrfs_leaf_ref_tree *tree); | |
66 | struct btrfs_leaf_ref *btrfs_alloc_leaf_ref(int nr_extents); | |
67 | void btrfs_free_leaf_ref(struct btrfs_leaf_ref *ref); | |
68 | struct btrfs_leaf_ref *btrfs_lookup_leaf_ref(struct btrfs_root *root, | |
69 | struct btrfs_key *key); | |
70 | int btrfs_add_leaf_ref(struct btrfs_root *root, struct btrfs_leaf_ref *ref); | |
71 | int btrfs_remove_leaf_refs(struct btrfs_root *root); | |
72 | int btrfs_remove_leaf_ref(struct btrfs_root *root, struct btrfs_leaf_ref *ref); |