diff options
author | Josef Bacik <josef@redhat.com> | 2010-06-21 14:48:16 -0400 |
---|---|---|
committer | Josef Bacik <josef@redhat.com> | 2010-10-28 15:59:09 -0400 |
commit | 0af3d00bad38d3bb9912a60928ad0669f17bdb76 (patch) | |
tree | abbf4c773138a33dcde483ac60f016c4b5e55dcc /fs/btrfs/ctree.h | |
parent | f6f94e2ab1b33f0082ac22d71f66385a60d8157f (diff) |
Btrfs: create special free space cache inode
In order to save free space cache, we need an inode to hold the data, and we
need a special item to point at the right inode for the right block group. So
first, create a special item that will point to the right inode, and the number
of extent entries we will have and the number of bitmaps we will have. We
truncate and pre-allocate space everytime to make sure it's uptodate.
This feature will be turned on as soon as you mount with -o space_cache, however
it is safe to boot into old kernels, they will just generate the cache the old
fashion way. When you boot back into a newer kernel we will notice that we
modified and not the cache and automatically discard the cache.
Signed-off-by: Josef Bacik <josef@redhat.com>
Diffstat (limited to 'fs/btrfs/ctree.h')
-rw-r--r-- | fs/btrfs/ctree.h | 74 |
1 files changed, 68 insertions, 6 deletions
diff --git a/fs/btrfs/ctree.h b/fs/btrfs/ctree.h index eaf286abad1..46f52e1bead 100644 --- a/fs/btrfs/ctree.h +++ b/fs/btrfs/ctree.h | |||
@@ -99,6 +99,9 @@ struct btrfs_ordered_sum; | |||
99 | */ | 99 | */ |
100 | #define BTRFS_EXTENT_CSUM_OBJECTID -10ULL | 100 | #define BTRFS_EXTENT_CSUM_OBJECTID -10ULL |
101 | 101 | ||
102 | /* For storing free space cache */ | ||
103 | #define BTRFS_FREE_SPACE_OBJECTID -11ULL | ||
104 | |||
102 | /* dummy objectid represents multiple objectids */ | 105 | /* dummy objectid represents multiple objectids */ |
103 | #define BTRFS_MULTIPLE_OBJECTIDS -255ULL | 106 | #define BTRFS_MULTIPLE_OBJECTIDS -255ULL |
104 | 107 | ||
@@ -265,6 +268,22 @@ struct btrfs_chunk { | |||
265 | /* additional stripes go here */ | 268 | /* additional stripes go here */ |
266 | } __attribute__ ((__packed__)); | 269 | } __attribute__ ((__packed__)); |
267 | 270 | ||
271 | #define BTRFS_FREE_SPACE_EXTENT 1 | ||
272 | #define BTRFS_FREE_SPACE_BITMAP 2 | ||
273 | |||
274 | struct btrfs_free_space_entry { | ||
275 | __le64 offset; | ||
276 | __le64 bytes; | ||
277 | u8 type; | ||
278 | } __attribute__ ((__packed__)); | ||
279 | |||
280 | struct btrfs_free_space_header { | ||
281 | struct btrfs_disk_key location; | ||
282 | __le64 generation; | ||
283 | __le64 num_entries; | ||
284 | __le64 num_bitmaps; | ||
285 | } __attribute__ ((__packed__)); | ||
286 | |||
268 | static inline unsigned long btrfs_chunk_item_size(int num_stripes) | 287 | static inline unsigned long btrfs_chunk_item_size(int num_stripes) |
269 | { | 288 | { |
270 | BUG_ON(num_stripes == 0); | 289 | BUG_ON(num_stripes == 0); |
@@ -365,8 +384,10 @@ struct btrfs_super_block { | |||
365 | 384 | ||
366 | char label[BTRFS_LABEL_SIZE]; | 385 | char label[BTRFS_LABEL_SIZE]; |
367 | 386 | ||
387 | __le64 cache_generation; | ||
388 | |||
368 | /* future expansion */ | 389 | /* future expansion */ |
369 | __le64 reserved[32]; | 390 | __le64 reserved[31]; |
370 | u8 sys_chunk_array[BTRFS_SYSTEM_CHUNK_ARRAY_SIZE]; | 391 | u8 sys_chunk_array[BTRFS_SYSTEM_CHUNK_ARRAY_SIZE]; |
371 | } __attribute__ ((__packed__)); | 392 | } __attribute__ ((__packed__)); |
372 | 393 | ||
@@ -375,12 +396,12 @@ struct btrfs_super_block { | |||
375 | * ones specified below then we will fail to mount | 396 | * ones specified below then we will fail to mount |
376 | */ | 397 | */ |
377 | #define BTRFS_FEATURE_INCOMPAT_MIXED_BACKREF (1ULL << 0) | 398 | #define BTRFS_FEATURE_INCOMPAT_MIXED_BACKREF (1ULL << 0) |
378 | #define BTRFS_FEATURE_INCOMPAT_DEFAULT_SUBVOL (2ULL << 0) | 399 | #define BTRFS_FEATURE_INCOMPAT_DEFAULT_SUBVOL (1ULL << 1) |
379 | 400 | ||
380 | #define BTRFS_FEATURE_COMPAT_SUPP 0ULL | 401 | #define BTRFS_FEATURE_COMPAT_SUPP 0ULL |
381 | #define BTRFS_FEATURE_COMPAT_RO_SUPP 0ULL | 402 | #define BTRFS_FEATURE_COMPAT_RO_SUPP 0ULL |
382 | #define BTRFS_FEATURE_INCOMPAT_SUPP \ | 403 | #define BTRFS_FEATURE_INCOMPAT_SUPP \ |
383 | (BTRFS_FEATURE_INCOMPAT_MIXED_BACKREF | \ | 404 | (BTRFS_FEATURE_INCOMPAT_MIXED_BACKREF | \ |
384 | BTRFS_FEATURE_INCOMPAT_DEFAULT_SUBVOL) | 405 | BTRFS_FEATURE_INCOMPAT_DEFAULT_SUBVOL) |
385 | 406 | ||
386 | /* | 407 | /* |
@@ -750,6 +771,14 @@ enum btrfs_caching_type { | |||
750 | BTRFS_CACHE_FINISHED = 2, | 771 | BTRFS_CACHE_FINISHED = 2, |
751 | }; | 772 | }; |
752 | 773 | ||
774 | enum btrfs_disk_cache_state { | ||
775 | BTRFS_DC_WRITTEN = 0, | ||
776 | BTRFS_DC_ERROR = 1, | ||
777 | BTRFS_DC_CLEAR = 2, | ||
778 | BTRFS_DC_SETUP = 3, | ||
779 | BTRFS_DC_NEED_WRITE = 4, | ||
780 | }; | ||
781 | |||
753 | struct btrfs_caching_control { | 782 | struct btrfs_caching_control { |
754 | struct list_head list; | 783 | struct list_head list; |
755 | struct mutex mutex; | 784 | struct mutex mutex; |
@@ -763,6 +792,7 @@ struct btrfs_block_group_cache { | |||
763 | struct btrfs_key key; | 792 | struct btrfs_key key; |
764 | struct btrfs_block_group_item item; | 793 | struct btrfs_block_group_item item; |
765 | struct btrfs_fs_info *fs_info; | 794 | struct btrfs_fs_info *fs_info; |
795 | struct inode *inode; | ||
766 | spinlock_t lock; | 796 | spinlock_t lock; |
767 | u64 pinned; | 797 | u64 pinned; |
768 | u64 reserved; | 798 | u64 reserved; |
@@ -773,8 +803,11 @@ struct btrfs_block_group_cache { | |||
773 | int extents_thresh; | 803 | int extents_thresh; |
774 | int free_extents; | 804 | int free_extents; |
775 | int total_bitmaps; | 805 | int total_bitmaps; |
776 | int ro; | 806 | int ro:1; |
777 | int dirty; | 807 | int dirty:1; |
808 | int iref:1; | ||
809 | |||
810 | int disk_cache_state; | ||
778 | 811 | ||
779 | /* cache tracking stuff */ | 812 | /* cache tracking stuff */ |
780 | int cached; | 813 | int cached; |
@@ -1192,6 +1225,7 @@ struct btrfs_root { | |||
1192 | #define BTRFS_MOUNT_NOSSD (1 << 9) | 1225 | #define BTRFS_MOUNT_NOSSD (1 << 9) |
1193 | #define BTRFS_MOUNT_DISCARD (1 << 10) | 1226 | #define BTRFS_MOUNT_DISCARD (1 << 10) |
1194 | #define BTRFS_MOUNT_FORCE_COMPRESS (1 << 11) | 1227 | #define BTRFS_MOUNT_FORCE_COMPRESS (1 << 11) |
1228 | #define BTRFS_MOUNT_SPACE_CACHE (1 << 12) | ||
1195 | 1229 | ||
1196 | #define btrfs_clear_opt(o, opt) ((o) &= ~BTRFS_MOUNT_##opt) | 1230 | #define btrfs_clear_opt(o, opt) ((o) &= ~BTRFS_MOUNT_##opt) |
1197 | #define btrfs_set_opt(o, opt) ((o) |= BTRFS_MOUNT_##opt) | 1231 | #define btrfs_set_opt(o, opt) ((o) |= BTRFS_MOUNT_##opt) |
@@ -1665,6 +1699,27 @@ static inline void btrfs_set_dir_item_key(struct extent_buffer *eb, | |||
1665 | write_eb_member(eb, item, struct btrfs_dir_item, location, key); | 1699 | write_eb_member(eb, item, struct btrfs_dir_item, location, key); |
1666 | } | 1700 | } |
1667 | 1701 | ||
1702 | BTRFS_SETGET_FUNCS(free_space_entries, struct btrfs_free_space_header, | ||
1703 | num_entries, 64); | ||
1704 | BTRFS_SETGET_FUNCS(free_space_bitmaps, struct btrfs_free_space_header, | ||
1705 | num_bitmaps, 64); | ||
1706 | BTRFS_SETGET_FUNCS(free_space_generation, struct btrfs_free_space_header, | ||
1707 | generation, 64); | ||
1708 | |||
1709 | static inline void btrfs_free_space_key(struct extent_buffer *eb, | ||
1710 | struct btrfs_free_space_header *h, | ||
1711 | struct btrfs_disk_key *key) | ||
1712 | { | ||
1713 | read_eb_member(eb, h, struct btrfs_free_space_header, location, key); | ||
1714 | } | ||
1715 | |||
1716 | static inline void btrfs_set_free_space_key(struct extent_buffer *eb, | ||
1717 | struct btrfs_free_space_header *h, | ||
1718 | struct btrfs_disk_key *key) | ||
1719 | { | ||
1720 | write_eb_member(eb, h, struct btrfs_free_space_header, location, key); | ||
1721 | } | ||
1722 | |||
1668 | /* struct btrfs_disk_key */ | 1723 | /* struct btrfs_disk_key */ |
1669 | BTRFS_SETGET_STACK_FUNCS(disk_key_objectid, struct btrfs_disk_key, | 1724 | BTRFS_SETGET_STACK_FUNCS(disk_key_objectid, struct btrfs_disk_key, |
1670 | objectid, 64); | 1725 | objectid, 64); |
@@ -1876,6 +1931,8 @@ BTRFS_SETGET_STACK_FUNCS(super_incompat_flags, struct btrfs_super_block, | |||
1876 | incompat_flags, 64); | 1931 | incompat_flags, 64); |
1877 | BTRFS_SETGET_STACK_FUNCS(super_csum_type, struct btrfs_super_block, | 1932 | BTRFS_SETGET_STACK_FUNCS(super_csum_type, struct btrfs_super_block, |
1878 | csum_type, 16); | 1933 | csum_type, 16); |
1934 | BTRFS_SETGET_STACK_FUNCS(super_cache_generation, struct btrfs_super_block, | ||
1935 | cache_generation, 64); | ||
1879 | 1936 | ||
1880 | static inline int btrfs_super_csum_size(struct btrfs_super_block *s) | 1937 | static inline int btrfs_super_csum_size(struct btrfs_super_block *s) |
1881 | { | 1938 | { |
@@ -2115,6 +2172,7 @@ int btrfs_set_block_group_ro(struct btrfs_root *root, | |||
2115 | struct btrfs_block_group_cache *cache); | 2172 | struct btrfs_block_group_cache *cache); |
2116 | int btrfs_set_block_group_rw(struct btrfs_root *root, | 2173 | int btrfs_set_block_group_rw(struct btrfs_root *root, |
2117 | struct btrfs_block_group_cache *cache); | 2174 | struct btrfs_block_group_cache *cache); |
2175 | void btrfs_put_block_group_cache(struct btrfs_fs_info *info); | ||
2118 | /* ctree.c */ | 2176 | /* ctree.c */ |
2119 | int btrfs_bin_search(struct extent_buffer *eb, struct btrfs_key *key, | 2177 | int btrfs_bin_search(struct extent_buffer *eb, struct btrfs_key *key, |
2120 | int level, int *slot); | 2178 | int level, int *slot); |
@@ -2426,6 +2484,10 @@ void btrfs_run_delayed_iputs(struct btrfs_root *root); | |||
2426 | int btrfs_prealloc_file_range(struct inode *inode, int mode, | 2484 | int btrfs_prealloc_file_range(struct inode *inode, int mode, |
2427 | u64 start, u64 num_bytes, u64 min_size, | 2485 | u64 start, u64 num_bytes, u64 min_size, |
2428 | loff_t actual_len, u64 *alloc_hint); | 2486 | loff_t actual_len, u64 *alloc_hint); |
2487 | int btrfs_prealloc_file_range_trans(struct inode *inode, | ||
2488 | struct btrfs_trans_handle *trans, int mode, | ||
2489 | u64 start, u64 num_bytes, u64 min_size, | ||
2490 | loff_t actual_len, u64 *alloc_hint); | ||
2429 | extern const struct dentry_operations btrfs_dentry_operations; | 2491 | extern const struct dentry_operations btrfs_dentry_operations; |
2430 | 2492 | ||
2431 | /* ioctl.c */ | 2493 | /* ioctl.c */ |