2008-07-28 15:32:19 -04:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2008 Oracle. All rights reserved.
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public
|
|
|
|
* License v2 as published by the Free Software Foundation.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public
|
|
|
|
* License along with this program; if not, write to the
|
|
|
|
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
|
|
* Boston, MA 021110-1307, USA.
|
|
|
|
*/
|
2008-07-28 15:32:51 -04:00
|
|
|
#ifndef __REFCACHE__
|
|
|
|
#define __REFCACHE__
|
2008-07-28 15:32:19 -04:00
|
|
|
|
|
|
|
struct btrfs_extent_info {
|
2008-09-29 15:18:18 -04:00
|
|
|
/* bytenr and num_bytes find the extent in the extent allocation tree */
|
2008-07-28 15:32:19 -04:00
|
|
|
u64 bytenr;
|
|
|
|
u64 num_bytes;
|
2008-09-29 15:18:18 -04:00
|
|
|
|
|
|
|
/* objectid and offset find the back reference for the file */
|
2008-07-28 15:32:19 -04:00
|
|
|
u64 objectid;
|
|
|
|
u64 offset;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct btrfs_leaf_ref {
|
|
|
|
struct rb_node rb_node;
|
2008-09-26 10:04:53 -04:00
|
|
|
struct btrfs_leaf_ref_tree *tree;
|
2008-07-28 15:32:19 -04:00
|
|
|
int in_tree;
|
|
|
|
atomic_t usage;
|
|
|
|
|
2008-07-30 16:29:20 -04:00
|
|
|
u64 root_gen;
|
2008-07-28 15:32:19 -04:00
|
|
|
u64 bytenr;
|
|
|
|
u64 owner;
|
|
|
|
u64 generation;
|
|
|
|
int nritems;
|
|
|
|
|
2008-07-28 15:32:51 -04:00
|
|
|
struct list_head list;
|
|
|
|
struct btrfs_extent_info extents[];
|
2008-07-28 15:32:19 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
static inline size_t btrfs_leaf_ref_size(int nr_extents)
|
|
|
|
{
|
2008-07-30 16:29:20 -04:00
|
|
|
return sizeof(struct btrfs_leaf_ref) +
|
2008-07-28 15:32:19 -04:00
|
|
|
sizeof(struct btrfs_extent_info) * nr_extents;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void btrfs_leaf_ref_tree_init(struct btrfs_leaf_ref_tree *tree)
|
|
|
|
{
|
2010-02-23 14:43:04 -05:00
|
|
|
tree->root = RB_ROOT;
|
2008-07-28 15:32:51 -04:00
|
|
|
INIT_LIST_HEAD(&tree->list);
|
2008-07-28 15:32:19 -04:00
|
|
|
spin_lock_init(&tree->lock);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline int btrfs_leaf_ref_tree_empty(struct btrfs_leaf_ref_tree *tree)
|
|
|
|
{
|
|
|
|
return RB_EMPTY_ROOT(&tree->root);
|
|
|
|
}
|
|
|
|
|
|
|
|
void btrfs_leaf_ref_tree_init(struct btrfs_leaf_ref_tree *tree);
|
2008-07-30 16:29:20 -04:00
|
|
|
struct btrfs_leaf_ref *btrfs_alloc_leaf_ref(struct btrfs_root *root,
|
|
|
|
int nr_extents);
|
|
|
|
void btrfs_free_leaf_ref(struct btrfs_root *root, struct btrfs_leaf_ref *ref);
|
2008-07-28 15:32:19 -04:00
|
|
|
struct btrfs_leaf_ref *btrfs_lookup_leaf_ref(struct btrfs_root *root,
|
2008-07-28 15:32:51 -04:00
|
|
|
u64 bytenr);
|
2008-09-26 10:04:53 -04:00
|
|
|
int btrfs_add_leaf_ref(struct btrfs_root *root, struct btrfs_leaf_ref *ref,
|
|
|
|
int shared);
|
|
|
|
int btrfs_remove_leaf_refs(struct btrfs_root *root, u64 max_root_gen,
|
|
|
|
int shared);
|
2008-07-28 15:32:19 -04:00
|
|
|
int btrfs_remove_leaf_ref(struct btrfs_root *root, struct btrfs_leaf_ref *ref);
|
2008-07-28 15:32:51 -04:00
|
|
|
#endif
|