@@ -239,6 +239,19 @@ struct btrfs_device_item {
239
239
__le64 device_id ;
240
240
} __attribute__ ((__packed__ ));
241
241
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
+
242
255
struct crypto_hash ;
243
256
struct btrfs_fs_info {
244
257
struct btrfs_root * extent_root ;
@@ -249,6 +262,7 @@ struct btrfs_fs_info {
249
262
struct radix_tree_root pending_del_radix ;
250
263
struct radix_tree_root pinned_radix ;
251
264
struct radix_tree_root dev_radix ;
265
+ struct radix_tree_root block_group_radix ;
252
266
253
267
u64 extent_tree_insert [BTRFS_MAX_LEVEL * 3 ];
254
268
int extent_tree_insert_nr ;
@@ -301,49 +315,67 @@ struct btrfs_root {
301
315
* info about object characteristics. There is one for every file and dir in
302
316
* the FS
303
317
*/
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 */
305
321
306
322
/*
307
323
* dir items are the name -> inode pointers in a directory. There is one
308
324
* for every name in a directory.
309
325
*/
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
312
328
/*
313
- * inline data is file data that fits in the btree.
329
+ * extent data is for file data
314
330
*/
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
321
332
/*
322
333
* csum items have the checksums for data in the extents
323
334
*/
324
- #define BTRFS_CSUM_ITEM_KEY 6
335
+ #define BTRFS_CSUM_ITEM_KEY 19
336
+
337
+ /* reserve 20-31 for other file stuff */
325
338
326
339
/*
327
340
* root items point to tree roots. There are typically in the root
328
341
* tree used by the super block to find all the other trees
329
342
*/
330
- #define BTRFS_ROOT_ITEM_KEY 7
343
+ #define BTRFS_ROOT_ITEM_KEY 32
331
344
/*
332
345
* extent items are in the extent map tree. These record which blocks
333
346
* are used, and how many references there are to each block
334
347
*/
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
336
355
337
356
/*
338
357
* dev items list the devices that make up the FS
339
358
*/
340
- #define BTRFS_DEV_ITEM_KEY 9
359
+ #define BTRFS_DEV_ITEM_KEY 35
341
360
342
361
/*
343
362
* string items are for debugging. They just store a short string of
344
363
* data in the FS
345
364
*/
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
+ }
347
379
348
380
static inline u64 btrfs_inode_generation (struct btrfs_inode_item * i )
349
381
{
@@ -1037,6 +1069,10 @@ int btrfs_finish_extent_commit(struct btrfs_trans_handle *trans, struct
1037
1069
int btrfs_inc_extent_ref (struct btrfs_trans_handle * trans ,
1038
1070
struct btrfs_root * root ,
1039
1071
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 );
1040
1076
/* ctree.c */
1041
1077
int btrfs_extend_item (struct btrfs_trans_handle * trans , struct btrfs_root
1042
1078
* root , struct btrfs_path * path , u32 data_size );
0 commit comments