struct btrfs_trans_handle;
struct btrfs_transaction;
+extern struct kmem_cache *btrfs_trans_handle_cachep;
+extern struct kmem_cache *btrfs_transaction_cachep;
+extern struct kmem_cache *btrfs_bit_radix_cachep;
extern struct kmem_cache *btrfs_path_cachep;
#define BTRFS_MAGIC "_BtRfS_M"
/* 32 bytes in various csum fields */
#define BTRFS_CSUM_SIZE 32
+/* four bytes for CRC32 */
+#define BTRFS_CRC32_SIZE 4
/*
* the key defines the order in the tree, and so it also defines (optimal)
u8 fsid[16]; /* FS specific uuid */
__le64 blocknr; /* which block this node is supposed to live in */
__le64 generation;
+ __le64 owner;
__le16 nritems;
__le16 flags;
u8 level;
*/
struct btrfs_extent_item {
__le32 refs;
+ __le64 owner;
} __attribute__ ((__packed__));
struct btrfs_inode_timespec {
__le64 generation;
__le64 size;
__le64 nblocks;
+ __le64 block_group;
__le32 nlink;
__le32 uid;
__le32 gid;
} __attribute__ ((__packed__));
struct btrfs_csum_item {
- u8 csum[BTRFS_CSUM_SIZE];
+ u8 csum;
} __attribute__ ((__packed__));
struct btrfs_device_item {
__le64 device_id;
} __attribute__ ((__packed__));
+/* tag for the radix tree of block groups in ram */
+#define BTRFS_BLOCK_GROUP_DIRTY 0
+#define BTRFS_BLOCK_GROUP_AVAIL 1
+#define BTRFS_BLOCK_GROUP_HINTS 8
+#define BTRFS_BLOCK_GROUP_SIZE (256 * 1024 * 1024)
+struct btrfs_block_group_item {
+ __le64 used;
+} __attribute__ ((__packed__));
+
+struct btrfs_block_group_cache {
+ struct btrfs_key key;
+ struct btrfs_block_group_item item;
+ struct radix_tree_root *radix;
+ u64 first_free;
+ u64 last_alloc;
+ u64 pinned;
+ u64 last_prealloc;
+ int data;
+ int cached;
+};
+
struct crypto_hash;
struct btrfs_fs_info {
struct btrfs_root *extent_root;
struct btrfs_root *tree_root;
struct btrfs_root *dev_root;
- struct btrfs_key current_insert;
- struct btrfs_key last_insert;
struct radix_tree_root fs_roots_radix;
struct radix_tree_root pending_del_radix;
struct radix_tree_root pinned_radix;
struct radix_tree_root dev_radix;
+ struct radix_tree_root block_group_radix;
+ struct radix_tree_root block_group_data_radix;
+ struct radix_tree_root extent_map_radix;
+
+ u64 extent_tree_insert[BTRFS_MAX_LEVEL * 3];
+ int extent_tree_insert_nr;
+ u64 extent_tree_prealloc[BTRFS_MAX_LEVEL * 3];
+ int extent_tree_prealloc_nr;
+
u64 generation;
struct btrfs_transaction *running_transaction;
struct btrfs_super_block *disk_super;
struct inode *btree_inode;
struct mutex trans_mutex;
struct mutex fs_mutex;
+ struct list_head trans_list;
struct crypto_hash *hash_tfm;
spinlock_t hash_lock;
+ int do_barriers;
struct kobject kobj;
};
/*
* in ram representation of the tree. extent_root is used for all allocations
- * and for the extent tree extent_root root. current_insert is used
- * only for the extent tree.
+ * and for the extent tree extent_root root.
*/
struct btrfs_root {
struct buffer_head *node;
* info about object characteristics. There is one for every file and dir in
* the FS
*/
-#define BTRFS_INODE_ITEM_KEY 1
+#define BTRFS_INODE_ITEM_KEY 1
+
+/* reserve 2-15 close to the inode for later flexibility */
/*
* dir items are the name -> inode pointers in a directory. There is one
* for every name in a directory.
*/
-#define BTRFS_DIR_ITEM_KEY 2
-#define BTRFS_DIR_INDEX_KEY 3
+#define BTRFS_DIR_ITEM_KEY 16
+#define BTRFS_DIR_INDEX_KEY 17
/*
- * inline data is file data that fits in the btree.
+ * extent data is for file data
*/
-#define BTRFS_INLINE_DATA_KEY 4
-/*
- * extent data is for data that can't fit in the btree. It points to
- * a (hopefully) huge chunk of disk
- */
-#define BTRFS_EXTENT_DATA_KEY 5
+#define BTRFS_EXTENT_DATA_KEY 18
/*
* csum items have the checksums for data in the extents
*/
-#define BTRFS_CSUM_ITEM_KEY 6
+#define BTRFS_CSUM_ITEM_KEY 19
+
+/* reserve 20-31 for other file stuff */
/*
* root items point to tree roots. There are typically in the root
* tree used by the super block to find all the other trees
*/
-#define BTRFS_ROOT_ITEM_KEY 7
+#define BTRFS_ROOT_ITEM_KEY 32
/*
* extent items are in the extent map tree. These record which blocks
* are used, and how many references there are to each block
*/
-#define BTRFS_EXTENT_ITEM_KEY 8
+#define BTRFS_EXTENT_ITEM_KEY 33
+
+/*
+ * block groups give us hints into the extent allocation trees. Which
+ * blocks are free etc etc
+ */
+#define BTRFS_BLOCK_GROUP_ITEM_KEY 34
/*
* dev items list the devices that make up the FS
*/
-#define BTRFS_DEV_ITEM_KEY 9
+#define BTRFS_DEV_ITEM_KEY 35
/*
* string items are for debugging. They just store a short string of
* data in the FS
*/
-#define BTRFS_STRING_ITEM_KEY 10
+#define BTRFS_STRING_ITEM_KEY 253
+
+
+static inline u64 btrfs_block_group_used(struct btrfs_block_group_item *bi)
+{
+ return le64_to_cpu(bi->used);
+}
+
+static inline void btrfs_set_block_group_used(struct
+ btrfs_block_group_item *bi,
+ u64 val)
+{
+ bi->used = cpu_to_le64(val);
+}
static inline u64 btrfs_inode_generation(struct btrfs_inode_item *i)
{
i->nblocks = cpu_to_le64(val);
}
+static inline u64 btrfs_inode_block_group(struct btrfs_inode_item *i)
+{
+ return le64_to_cpu(i->block_group);
+}
+
+static inline void btrfs_set_inode_block_group(struct btrfs_inode_item *i,
+ u64 val)
+{
+ i->block_group = cpu_to_le64(val);
+}
+
static inline u32 btrfs_inode_nlink(struct btrfs_inode_item *i)
{
return le32_to_cpu(i->nlink);
ei->refs = cpu_to_le32(val);
}
+static inline u64 btrfs_extent_owner(struct btrfs_extent_item *ei)
+{
+ return le64_to_cpu(ei->owner);
+}
+
+static inline void btrfs_set_extent_owner(struct btrfs_extent_item *ei, u64 val)
+{
+ ei->owner = cpu_to_le64(val);
+}
+
static inline u64 btrfs_node_blockptr(struct btrfs_node *n, int nr)
{
return le64_to_cpu(n->ptrs[nr].blockptr);
}
+
static inline void btrfs_set_node_blockptr(struct btrfs_node *n, int nr,
u64 val)
{
h->generation = cpu_to_le64(val);
}
+static inline u64 btrfs_header_owner(struct btrfs_header *h)
+{
+ return le64_to_cpu(h->owner);
+}
+
+static inline void btrfs_set_header_owner(struct btrfs_header *h,
+ u64 val)
+{
+ h->owner = cpu_to_le64(val);
+}
+
static inline u16 btrfs_header_nritems(struct btrfs_header *h)
{
return le16_to_cpu(h->nritems);
btrfs_item_offset((leaf)->items + (slot))))
/* extent-tree.c */
+struct btrfs_block_group_cache *btrfs_find_block_group(struct btrfs_root *root,
+ struct btrfs_block_group_cache
+ *hint, u64 search_start,
+ int data, int owner);
int btrfs_inc_root_ref(struct btrfs_trans_handle *trans,
struct btrfs_root *root);
struct buffer_head *btrfs_alloc_free_block(struct btrfs_trans_handle *trans,
- struct btrfs_root *root);
-int btrfs_alloc_extent(struct btrfs_trans_handle *trans, struct btrfs_root
- *root, u64 num_blocks, u64 search_start, u64
- search_end, struct btrfs_key *ins);
+ struct btrfs_root *root, u64 hint);
+int btrfs_alloc_extent(struct btrfs_trans_handle *trans,
+ struct btrfs_root *root, u64 owner,
+ u64 num_blocks, u64 search_start,
+ u64 search_end, struct btrfs_key *ins, int data);
int btrfs_inc_ref(struct btrfs_trans_handle *trans, struct btrfs_root *root,
struct buffer_head *buf);
int btrfs_free_extent(struct btrfs_trans_handle *trans, struct btrfs_root
int btrfs_inc_extent_ref(struct btrfs_trans_handle *trans,
struct btrfs_root *root,
u64 blocknr, u64 num_blocks);
+int btrfs_write_dirty_block_groups(struct btrfs_trans_handle *trans,
+ struct btrfs_root *root);
+int btrfs_free_block_groups(struct btrfs_fs_info *info);
+int btrfs_read_block_groups(struct btrfs_root *root);
/* ctree.c */
int btrfs_extend_item(struct btrfs_trans_handle *trans, struct btrfs_root
*root, struct btrfs_path *path, u32 data_size);