diff options
Diffstat (limited to 'fs/btrfs/ctree.h')
-rw-r--r-- | fs/btrfs/ctree.h | 100 |
1 files changed, 89 insertions, 11 deletions
diff --git a/fs/btrfs/ctree.h b/fs/btrfs/ctree.h index eaf286abad17..8db9234f6b41 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,13 +396,15 @@ 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) |
400 | #define BTRFS_FEATURE_INCOMPAT_MIXED_GROUPS (1ULL << 2) | ||
379 | 401 | ||
380 | #define BTRFS_FEATURE_COMPAT_SUPP 0ULL | 402 | #define BTRFS_FEATURE_COMPAT_SUPP 0ULL |
381 | #define BTRFS_FEATURE_COMPAT_RO_SUPP 0ULL | 403 | #define BTRFS_FEATURE_COMPAT_RO_SUPP 0ULL |
382 | #define BTRFS_FEATURE_INCOMPAT_SUPP \ | 404 | #define BTRFS_FEATURE_INCOMPAT_SUPP \ |
383 | (BTRFS_FEATURE_INCOMPAT_MIXED_BACKREF | \ | 405 | (BTRFS_FEATURE_INCOMPAT_MIXED_BACKREF | \ |
384 | BTRFS_FEATURE_INCOMPAT_DEFAULT_SUBVOL) | 406 | BTRFS_FEATURE_INCOMPAT_DEFAULT_SUBVOL | \ |
407 | BTRFS_FEATURE_INCOMPAT_MIXED_GROUPS) | ||
385 | 408 | ||
386 | /* | 409 | /* |
387 | * A leaf is full of items. offset and size tell us where to find | 410 | * A leaf is full of items. offset and size tell us where to find |
@@ -675,7 +698,8 @@ struct btrfs_block_group_item { | |||
675 | struct btrfs_space_info { | 698 | struct btrfs_space_info { |
676 | u64 flags; | 699 | u64 flags; |
677 | 700 | ||
678 | u64 total_bytes; /* total bytes in the space */ | 701 | u64 total_bytes; /* total bytes in the space, |
702 | this doesn't take mirrors into account */ | ||
679 | u64 bytes_used; /* total bytes used, | 703 | u64 bytes_used; /* total bytes used, |
680 | this does't take mirrors into account */ | 704 | this does't take mirrors into account */ |
681 | u64 bytes_pinned; /* total bytes pinned, will be freed when the | 705 | u64 bytes_pinned; /* total bytes pinned, will be freed when the |
@@ -687,6 +711,8 @@ struct btrfs_space_info { | |||
687 | u64 bytes_may_use; /* number of bytes that may be used for | 711 | u64 bytes_may_use; /* number of bytes that may be used for |
688 | delalloc/allocations */ | 712 | delalloc/allocations */ |
689 | u64 disk_used; /* total bytes used on disk */ | 713 | u64 disk_used; /* total bytes used on disk */ |
714 | u64 disk_total; /* total bytes on disk, takes mirrors into | ||
715 | account */ | ||
690 | 716 | ||
691 | int full; /* indicates that we cannot allocate any more | 717 | int full; /* indicates that we cannot allocate any more |
692 | chunks for this space */ | 718 | chunks for this space */ |
@@ -750,6 +776,14 @@ enum btrfs_caching_type { | |||
750 | BTRFS_CACHE_FINISHED = 2, | 776 | BTRFS_CACHE_FINISHED = 2, |
751 | }; | 777 | }; |
752 | 778 | ||
779 | enum btrfs_disk_cache_state { | ||
780 | BTRFS_DC_WRITTEN = 0, | ||
781 | BTRFS_DC_ERROR = 1, | ||
782 | BTRFS_DC_CLEAR = 2, | ||
783 | BTRFS_DC_SETUP = 3, | ||
784 | BTRFS_DC_NEED_WRITE = 4, | ||
785 | }; | ||
786 | |||
753 | struct btrfs_caching_control { | 787 | struct btrfs_caching_control { |
754 | struct list_head list; | 788 | struct list_head list; |
755 | struct mutex mutex; | 789 | struct mutex mutex; |
@@ -763,6 +797,7 @@ struct btrfs_block_group_cache { | |||
763 | struct btrfs_key key; | 797 | struct btrfs_key key; |
764 | struct btrfs_block_group_item item; | 798 | struct btrfs_block_group_item item; |
765 | struct btrfs_fs_info *fs_info; | 799 | struct btrfs_fs_info *fs_info; |
800 | struct inode *inode; | ||
766 | spinlock_t lock; | 801 | spinlock_t lock; |
767 | u64 pinned; | 802 | u64 pinned; |
768 | u64 reserved; | 803 | u64 reserved; |
@@ -773,8 +808,11 @@ struct btrfs_block_group_cache { | |||
773 | int extents_thresh; | 808 | int extents_thresh; |
774 | int free_extents; | 809 | int free_extents; |
775 | int total_bitmaps; | 810 | int total_bitmaps; |
776 | int ro; | 811 | int ro:1; |
777 | int dirty; | 812 | int dirty:1; |
813 | int iref:1; | ||
814 | |||
815 | int disk_cache_state; | ||
778 | 816 | ||
779 | /* cache tracking stuff */ | 817 | /* cache tracking stuff */ |
780 | int cached; | 818 | int cached; |
@@ -863,6 +901,7 @@ struct btrfs_fs_info { | |||
863 | struct btrfs_transaction *running_transaction; | 901 | struct btrfs_transaction *running_transaction; |
864 | wait_queue_head_t transaction_throttle; | 902 | wait_queue_head_t transaction_throttle; |
865 | wait_queue_head_t transaction_wait; | 903 | wait_queue_head_t transaction_wait; |
904 | wait_queue_head_t transaction_blocked_wait; | ||
866 | wait_queue_head_t async_submit_wait; | 905 | wait_queue_head_t async_submit_wait; |
867 | 906 | ||
868 | struct btrfs_super_block super_copy; | 907 | struct btrfs_super_block super_copy; |
@@ -949,6 +988,7 @@ struct btrfs_fs_info { | |||
949 | struct btrfs_workers endio_meta_workers; | 988 | struct btrfs_workers endio_meta_workers; |
950 | struct btrfs_workers endio_meta_write_workers; | 989 | struct btrfs_workers endio_meta_write_workers; |
951 | struct btrfs_workers endio_write_workers; | 990 | struct btrfs_workers endio_write_workers; |
991 | struct btrfs_workers endio_freespace_worker; | ||
952 | struct btrfs_workers submit_workers; | 992 | struct btrfs_workers submit_workers; |
953 | /* | 993 | /* |
954 | * fixup workers take dirty pages that didn't properly go through | 994 | * fixup workers take dirty pages that didn't properly go through |
@@ -1192,6 +1232,9 @@ struct btrfs_root { | |||
1192 | #define BTRFS_MOUNT_NOSSD (1 << 9) | 1232 | #define BTRFS_MOUNT_NOSSD (1 << 9) |
1193 | #define BTRFS_MOUNT_DISCARD (1 << 10) | 1233 | #define BTRFS_MOUNT_DISCARD (1 << 10) |
1194 | #define BTRFS_MOUNT_FORCE_COMPRESS (1 << 11) | 1234 | #define BTRFS_MOUNT_FORCE_COMPRESS (1 << 11) |
1235 | #define BTRFS_MOUNT_SPACE_CACHE (1 << 12) | ||
1236 | #define BTRFS_MOUNT_CLEAR_CACHE (1 << 13) | ||
1237 | #define BTRFS_MOUNT_USER_SUBVOL_RM_ALLOWED (1 << 14) | ||
1195 | 1238 | ||
1196 | #define btrfs_clear_opt(o, opt) ((o) &= ~BTRFS_MOUNT_##opt) | 1239 | #define btrfs_clear_opt(o, opt) ((o) &= ~BTRFS_MOUNT_##opt) |
1197 | #define btrfs_set_opt(o, opt) ((o) |= BTRFS_MOUNT_##opt) | 1240 | #define btrfs_set_opt(o, opt) ((o) |= BTRFS_MOUNT_##opt) |
@@ -1665,6 +1708,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); | 1708 | write_eb_member(eb, item, struct btrfs_dir_item, location, key); |
1666 | } | 1709 | } |
1667 | 1710 | ||
1711 | BTRFS_SETGET_FUNCS(free_space_entries, struct btrfs_free_space_header, | ||
1712 | num_entries, 64); | ||
1713 | BTRFS_SETGET_FUNCS(free_space_bitmaps, struct btrfs_free_space_header, | ||
1714 | num_bitmaps, 64); | ||
1715 | BTRFS_SETGET_FUNCS(free_space_generation, struct btrfs_free_space_header, | ||
1716 | generation, 64); | ||
1717 | |||
1718 | static inline void btrfs_free_space_key(struct extent_buffer *eb, | ||
1719 | struct btrfs_free_space_header *h, | ||
1720 | struct btrfs_disk_key *key) | ||
1721 | { | ||
1722 | read_eb_member(eb, h, struct btrfs_free_space_header, location, key); | ||
1723 | } | ||
1724 | |||
1725 | static inline void btrfs_set_free_space_key(struct extent_buffer *eb, | ||
1726 | struct btrfs_free_space_header *h, | ||
1727 | struct btrfs_disk_key *key) | ||
1728 | { | ||
1729 | write_eb_member(eb, h, struct btrfs_free_space_header, location, key); | ||
1730 | } | ||
1731 | |||
1668 | /* struct btrfs_disk_key */ | 1732 | /* struct btrfs_disk_key */ |
1669 | BTRFS_SETGET_STACK_FUNCS(disk_key_objectid, struct btrfs_disk_key, | 1733 | BTRFS_SETGET_STACK_FUNCS(disk_key_objectid, struct btrfs_disk_key, |
1670 | objectid, 64); | 1734 | objectid, 64); |
@@ -1876,6 +1940,8 @@ BTRFS_SETGET_STACK_FUNCS(super_incompat_flags, struct btrfs_super_block, | |||
1876 | incompat_flags, 64); | 1940 | incompat_flags, 64); |
1877 | BTRFS_SETGET_STACK_FUNCS(super_csum_type, struct btrfs_super_block, | 1941 | BTRFS_SETGET_STACK_FUNCS(super_csum_type, struct btrfs_super_block, |
1878 | csum_type, 16); | 1942 | csum_type, 16); |
1943 | BTRFS_SETGET_STACK_FUNCS(super_cache_generation, struct btrfs_super_block, | ||
1944 | cache_generation, 64); | ||
1879 | 1945 | ||
1880 | static inline int btrfs_super_csum_size(struct btrfs_super_block *s) | 1946 | static inline int btrfs_super_csum_size(struct btrfs_super_block *s) |
1881 | { | 1947 | { |
@@ -1988,6 +2054,12 @@ static inline struct dentry *fdentry(struct file *file) | |||
1988 | return file->f_path.dentry; | 2054 | return file->f_path.dentry; |
1989 | } | 2055 | } |
1990 | 2056 | ||
2057 | static inline bool btrfs_mixed_space_info(struct btrfs_space_info *space_info) | ||
2058 | { | ||
2059 | return ((space_info->flags & BTRFS_BLOCK_GROUP_METADATA) && | ||
2060 | (space_info->flags & BTRFS_BLOCK_GROUP_DATA)); | ||
2061 | } | ||
2062 | |||
1991 | /* extent-tree.c */ | 2063 | /* extent-tree.c */ |
1992 | void btrfs_put_block_group(struct btrfs_block_group_cache *cache); | 2064 | void btrfs_put_block_group(struct btrfs_block_group_cache *cache); |
1993 | int btrfs_run_delayed_refs(struct btrfs_trans_handle *trans, | 2065 | int btrfs_run_delayed_refs(struct btrfs_trans_handle *trans, |
@@ -2079,7 +2151,7 @@ int btrfs_check_data_free_space(struct inode *inode, u64 bytes); | |||
2079 | void btrfs_free_reserved_data_space(struct inode *inode, u64 bytes); | 2151 | void btrfs_free_reserved_data_space(struct inode *inode, u64 bytes); |
2080 | int btrfs_trans_reserve_metadata(struct btrfs_trans_handle *trans, | 2152 | int btrfs_trans_reserve_metadata(struct btrfs_trans_handle *trans, |
2081 | struct btrfs_root *root, | 2153 | struct btrfs_root *root, |
2082 | int num_items, int *retries); | 2154 | int num_items); |
2083 | void btrfs_trans_release_metadata(struct btrfs_trans_handle *trans, | 2155 | void btrfs_trans_release_metadata(struct btrfs_trans_handle *trans, |
2084 | struct btrfs_root *root); | 2156 | struct btrfs_root *root); |
2085 | int btrfs_orphan_reserve_metadata(struct btrfs_trans_handle *trans, | 2157 | int btrfs_orphan_reserve_metadata(struct btrfs_trans_handle *trans, |
@@ -2100,7 +2172,7 @@ void btrfs_add_durable_block_rsv(struct btrfs_fs_info *fs_info, | |||
2100 | int btrfs_block_rsv_add(struct btrfs_trans_handle *trans, | 2172 | int btrfs_block_rsv_add(struct btrfs_trans_handle *trans, |
2101 | struct btrfs_root *root, | 2173 | struct btrfs_root *root, |
2102 | struct btrfs_block_rsv *block_rsv, | 2174 | struct btrfs_block_rsv *block_rsv, |
2103 | u64 num_bytes, int *retries); | 2175 | u64 num_bytes); |
2104 | int btrfs_block_rsv_check(struct btrfs_trans_handle *trans, | 2176 | int btrfs_block_rsv_check(struct btrfs_trans_handle *trans, |
2105 | struct btrfs_root *root, | 2177 | struct btrfs_root *root, |
2106 | struct btrfs_block_rsv *block_rsv, | 2178 | struct btrfs_block_rsv *block_rsv, |
@@ -2115,6 +2187,7 @@ int btrfs_set_block_group_ro(struct btrfs_root *root, | |||
2115 | struct btrfs_block_group_cache *cache); | 2187 | struct btrfs_block_group_cache *cache); |
2116 | int btrfs_set_block_group_rw(struct btrfs_root *root, | 2188 | int btrfs_set_block_group_rw(struct btrfs_root *root, |
2117 | struct btrfs_block_group_cache *cache); | 2189 | struct btrfs_block_group_cache *cache); |
2190 | void btrfs_put_block_group_cache(struct btrfs_fs_info *info); | ||
2118 | /* ctree.c */ | 2191 | /* ctree.c */ |
2119 | int btrfs_bin_search(struct extent_buffer *eb, struct btrfs_key *key, | 2192 | int btrfs_bin_search(struct extent_buffer *eb, struct btrfs_key *key, |
2120 | int level, int *slot); | 2193 | int level, int *slot); |
@@ -2373,7 +2446,8 @@ int btrfs_truncate_inode_items(struct btrfs_trans_handle *trans, | |||
2373 | u32 min_type); | 2446 | u32 min_type); |
2374 | 2447 | ||
2375 | int btrfs_start_delalloc_inodes(struct btrfs_root *root, int delay_iput); | 2448 | int btrfs_start_delalloc_inodes(struct btrfs_root *root, int delay_iput); |
2376 | int btrfs_start_one_delalloc_inode(struct btrfs_root *root, int delay_iput); | 2449 | int btrfs_start_one_delalloc_inode(struct btrfs_root *root, int delay_iput, |
2450 | int sync); | ||
2377 | int btrfs_set_extent_delalloc(struct inode *inode, u64 start, u64 end, | 2451 | int btrfs_set_extent_delalloc(struct inode *inode, u64 start, u64 end, |
2378 | struct extent_state **cached_state); | 2452 | struct extent_state **cached_state); |
2379 | int btrfs_writepages(struct address_space *mapping, | 2453 | int btrfs_writepages(struct address_space *mapping, |
@@ -2426,6 +2500,10 @@ void btrfs_run_delayed_iputs(struct btrfs_root *root); | |||
2426 | int btrfs_prealloc_file_range(struct inode *inode, int mode, | 2500 | int btrfs_prealloc_file_range(struct inode *inode, int mode, |
2427 | u64 start, u64 num_bytes, u64 min_size, | 2501 | u64 start, u64 num_bytes, u64 min_size, |
2428 | loff_t actual_len, u64 *alloc_hint); | 2502 | loff_t actual_len, u64 *alloc_hint); |
2503 | int btrfs_prealloc_file_range_trans(struct inode *inode, | ||
2504 | struct btrfs_trans_handle *trans, int mode, | ||
2505 | u64 start, u64 num_bytes, u64 min_size, | ||
2506 | loff_t actual_len, u64 *alloc_hint); | ||
2429 | extern const struct dentry_operations btrfs_dentry_operations; | 2507 | extern const struct dentry_operations btrfs_dentry_operations; |
2430 | 2508 | ||
2431 | /* ioctl.c */ | 2509 | /* ioctl.c */ |