Skip to content

Commit 9078a3e

Browse files
chrismason-xxDavid Woodhouse
authored andcommitted
Btrfs: start of block group code
Signed-off-by: Chris Mason <[email protected]>
1 parent f2458e1 commit 9078a3e

File tree

6 files changed

+252
-32
lines changed

6 files changed

+252
-32
lines changed

fs/btrfs/ctree.h

Lines changed: 51 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,19 @@ struct btrfs_device_item {
239239
__le64 device_id;
240240
} __attribute__ ((__packed__));
241241

242+
/* tag for the radix tree of block groups in ram */
243+
#define BTRFS_BLOCK_GROUP_DIRTY 0
244+
#define BTRFS_BLOCK_GROUP_HINTS 8
245+
#define BTRFS_BLOCK_GROUP_SIZE (256 * 1024 * 1024)
246+
struct btrfs_block_group_item {
247+
__le64 used;
248+
} __attribute__ ((__packed__));
249+
250+
struct btrfs_block_group_cache {
251+
struct btrfs_key key;
252+
struct btrfs_block_group_item item;
253+
};
254+
242255
struct crypto_hash;
243256
struct btrfs_fs_info {
244257
struct btrfs_root *extent_root;
@@ -249,6 +262,7 @@ struct btrfs_fs_info {
249262
struct radix_tree_root pending_del_radix;
250263
struct radix_tree_root pinned_radix;
251264
struct radix_tree_root dev_radix;
265+
struct radix_tree_root block_group_radix;
252266

253267
u64 extent_tree_insert[BTRFS_MAX_LEVEL * 3];
254268
int extent_tree_insert_nr;
@@ -301,49 +315,67 @@ struct btrfs_root {
301315
* info about object characteristics. There is one for every file and dir in
302316
* the FS
303317
*/
304-
#define BTRFS_INODE_ITEM_KEY 1
318+
#define BTRFS_INODE_ITEM_KEY 1
319+
320+
/* reserve 2-15 close to the inode for later flexibility */
305321

306322
/*
307323
* dir items are the name -> inode pointers in a directory. There is one
308324
* for every name in a directory.
309325
*/
310-
#define BTRFS_DIR_ITEM_KEY 2
311-
#define BTRFS_DIR_INDEX_KEY 3
326+
#define BTRFS_DIR_ITEM_KEY 16
327+
#define BTRFS_DIR_INDEX_KEY 17
312328
/*
313-
* inline data is file data that fits in the btree.
329+
* extent data is for file data
314330
*/
315-
#define BTRFS_INLINE_DATA_KEY 4
316-
/*
317-
* extent data is for data that can't fit in the btree. It points to
318-
* a (hopefully) huge chunk of disk
319-
*/
320-
#define BTRFS_EXTENT_DATA_KEY 5
331+
#define BTRFS_EXTENT_DATA_KEY 18
321332
/*
322333
* csum items have the checksums for data in the extents
323334
*/
324-
#define BTRFS_CSUM_ITEM_KEY 6
335+
#define BTRFS_CSUM_ITEM_KEY 19
336+
337+
/* reserve 20-31 for other file stuff */
325338

326339
/*
327340
* root items point to tree roots. There are typically in the root
328341
* tree used by the super block to find all the other trees
329342
*/
330-
#define BTRFS_ROOT_ITEM_KEY 7
343+
#define BTRFS_ROOT_ITEM_KEY 32
331344
/*
332345
* extent items are in the extent map tree. These record which blocks
333346
* are used, and how many references there are to each block
334347
*/
335-
#define BTRFS_EXTENT_ITEM_KEY 8
348+
#define BTRFS_EXTENT_ITEM_KEY 33
349+
350+
/*
351+
* block groups give us hints into the extent allocation trees. Which
352+
* blocks are free etc etc
353+
*/
354+
#define BTRFS_BLOCK_GROUP_ITEM_KEY 34
336355

337356
/*
338357
* dev items list the devices that make up the FS
339358
*/
340-
#define BTRFS_DEV_ITEM_KEY 9
359+
#define BTRFS_DEV_ITEM_KEY 35
341360

342361
/*
343362
* string items are for debugging. They just store a short string of
344363
* data in the FS
345364
*/
346-
#define BTRFS_STRING_ITEM_KEY 10
365+
#define BTRFS_STRING_ITEM_KEY 253
366+
367+
368+
static inline u64 btrfs_block_group_used(struct btrfs_block_group_item *bi)
369+
{
370+
return le64_to_cpu(bi->used);
371+
}
372+
373+
static inline void btrfs_set_block_group_used(struct
374+
btrfs_block_group_item *bi,
375+
u64 val)
376+
{
377+
bi->used = cpu_to_le64(val);
378+
}
347379

348380
static inline u64 btrfs_inode_generation(struct btrfs_inode_item *i)
349381
{
@@ -1037,6 +1069,10 @@ int btrfs_finish_extent_commit(struct btrfs_trans_handle *trans, struct
10371069
int btrfs_inc_extent_ref(struct btrfs_trans_handle *trans,
10381070
struct btrfs_root *root,
10391071
u64 blocknr, u64 num_blocks);
1072+
int btrfs_write_dirty_block_groups(struct btrfs_trans_handle *trans,
1073+
struct btrfs_root *root);
1074+
int btrfs_free_block_groups(struct btrfs_fs_info *info);
1075+
int btrfs_read_block_groups(struct btrfs_root *root);
10401076
/* ctree.c */
10411077
int btrfs_extend_item(struct btrfs_trans_handle *trans, struct btrfs_root
10421078
*root, struct btrfs_path *path, u32 data_size);

fs/btrfs/disk-io.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -529,6 +529,7 @@ struct btrfs_root *open_ctree(struct super_block *sb)
529529
init_bit_radix(&fs_info->pending_del_radix);
530530
INIT_RADIX_TREE(&fs_info->fs_roots_radix, GFP_NOFS);
531531
INIT_RADIX_TREE(&fs_info->dev_radix, GFP_NOFS);
532+
INIT_RADIX_TREE(&fs_info->block_group_radix, GFP_KERNEL);
532533
INIT_LIST_HEAD(&fs_info->trans_list);
533534
sb_set_blocksize(sb, 4096);
534535
fs_info->running_transaction = NULL;
@@ -613,6 +614,8 @@ struct btrfs_root *open_ctree(struct super_block *sb)
613614
BTRFS_EXTENT_TREE_OBJECTID, extent_root);
614615
BUG_ON(ret);
615616

617+
btrfs_read_block_groups(extent_root);
618+
616619
fs_info->generation = btrfs_super_generation(disk_super) + 1;
617620
memset(&fs_info->kobj, 0, sizeof(fs_info->kobj));
618621
kobj_set_kset_s(fs_info, btrfs_subsys);
@@ -741,6 +744,7 @@ int close_ctree(struct btrfs_root *root)
741744
iput(fs_info->btree_inode);
742745

743746
free_dev_radix(fs_info);
747+
btrfs_free_block_groups(root->fs_info);
744748
del_fs_roots(fs_info);
745749
kfree(fs_info->extent_root);
746750
kfree(fs_info->tree_root);

0 commit comments

Comments
 (0)