aboutsummaryrefslogtreecommitdiffstats
path: root/fs/btrfs/ref-cache.h
diff options
context:
space:
mode:
authorYan Zheng <zheng.yan@oracle.com>2008-07-28 15:32:19 -0400
committerChris Mason <chris.mason@oracle.com>2008-09-25 11:04:05 -0400
commit31153d81284934601d08110ac7698fd9a535e4c0 (patch)
tree38f873fea3012a58d2a8f4d439a9546443617878 /fs/btrfs/ref-cache.h
parent3a115f520f391b4ab14041bdd6eedb370d944fa6 (diff)
Btrfs: Add a leaf reference cache
Much of the IO done while dropping snapshots is done looking up leaves in the filesystem trees to see if they point to any extents and to drop the references on any extents found. This creates a cache so that IO isn't required. Signed-off-by: Chris Mason <chris.mason@oracle.com>
Diffstat (limited to 'fs/btrfs/ref-cache.h')
-rw-r--r--fs/btrfs/ref-cache.h72
1 files changed, 72 insertions, 0 deletions
diff --git a/fs/btrfs/ref-cache.h b/fs/btrfs/ref-cache.h
new file mode 100644
index 000000000000..79ecc47110f2
--- /dev/null
+++ b/fs/btrfs/ref-cache.h
@@ -0,0 +1,72 @@
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
19struct btrfs_extent_info {
20 u64 bytenr;
21 u64 num_bytes;
22 u64 objectid;
23 u64 offset;
24};
25
26struct 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
39struct btrfs_leaf_ref_tree {
40 struct rb_root root;
41 struct btrfs_leaf_ref *last;
42 u64 generation;
43 spinlock_t lock;
44};
45
46static 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
52static 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
60static inline int btrfs_leaf_ref_tree_empty(struct btrfs_leaf_ref_tree *tree)
61{
62 return RB_EMPTY_ROOT(&tree->root);
63}
64
65void btrfs_leaf_ref_tree_init(struct btrfs_leaf_ref_tree *tree);
66struct btrfs_leaf_ref *btrfs_alloc_leaf_ref(int nr_extents);
67void btrfs_free_leaf_ref(struct btrfs_leaf_ref *ref);
68struct btrfs_leaf_ref *btrfs_lookup_leaf_ref(struct btrfs_root *root,
69 struct btrfs_key *key);
70int btrfs_add_leaf_ref(struct btrfs_root *root, struct btrfs_leaf_ref *ref);
71int btrfs_remove_leaf_refs(struct btrfs_root *root);
72int btrfs_remove_leaf_ref(struct btrfs_root *root, struct btrfs_leaf_ref *ref);