Skip to content

Commit

Permalink
Btrfs: start of block group code
Browse files Browse the repository at this point in the history
Signed-off-by: Chris Mason <chris.mason@oracle.com>
  • Loading branch information
Chris Mason authored and David Woodhouse committed Apr 26, 2007
1 parent f2458e1 commit 9078a3e
Show file tree
Hide file tree
Showing 6 changed files with 252 additions and 32 deletions.
66 changes: 51 additions & 15 deletions fs/btrfs/ctree.h
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,19 @@ 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_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 crypto_hash;
struct btrfs_fs_info {
struct btrfs_root *extent_root;
Expand All @@ -249,6 +262,7 @@ struct btrfs_fs_info {
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;

u64 extent_tree_insert[BTRFS_MAX_LEVEL * 3];
int extent_tree_insert_nr;
Expand Down Expand Up @@ -301,49 +315,67 @@ struct btrfs_root {
* 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)
{
Expand Down Expand Up @@ -1037,6 +1069,10 @@ int btrfs_finish_extent_commit(struct btrfs_trans_handle *trans, struct
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);
Expand Down
4 changes: 4 additions & 0 deletions fs/btrfs/disk-io.c
Original file line number Diff line number Diff line change
Expand Up @@ -529,6 +529,7 @@ struct btrfs_root *open_ctree(struct super_block *sb)
init_bit_radix(&fs_info->pending_del_radix);
INIT_RADIX_TREE(&fs_info->fs_roots_radix, GFP_NOFS);
INIT_RADIX_TREE(&fs_info->dev_radix, GFP_NOFS);
INIT_RADIX_TREE(&fs_info->block_group_radix, GFP_KERNEL);
INIT_LIST_HEAD(&fs_info->trans_list);
sb_set_blocksize(sb, 4096);
fs_info->running_transaction = NULL;
Expand Down Expand Up @@ -613,6 +614,8 @@ struct btrfs_root *open_ctree(struct super_block *sb)
BTRFS_EXTENT_TREE_OBJECTID, extent_root);
BUG_ON(ret);

btrfs_read_block_groups(extent_root);

fs_info->generation = btrfs_super_generation(disk_super) + 1;
memset(&fs_info->kobj, 0, sizeof(fs_info->kobj));
kobj_set_kset_s(fs_info, btrfs_subsys);
Expand Down Expand Up @@ -741,6 +744,7 @@ int close_ctree(struct btrfs_root *root)
iput(fs_info->btree_inode);

free_dev_radix(fs_info);
btrfs_free_block_groups(root->fs_info);
del_fs_roots(fs_info);
kfree(fs_info->extent_root);
kfree(fs_info->tree_root);
Expand Down
Loading

0 comments on commit 9078a3e

Please sign in to comment.