1
2
3#ifndef BTRFS_SPACE_INFO_H
4#define BTRFS_SPACE_INFO_H
5
6struct btrfs_space_info {
7 spinlock_t lock;
8
9 u64 total_bytes;
10
11 u64 bytes_used;
12
13 u64 bytes_pinned;
14
15 u64 bytes_reserved;
16
17 u64 bytes_may_use;
18
19 u64 bytes_readonly;
20
21 u64 max_extent_size;
22
23
24
25 unsigned int full:1;
26
27 unsigned int chunk_alloc:1;
28
29 unsigned int flush:1;
30
31 unsigned int force_alloc;
32
33
34 u64 disk_used;
35 u64 disk_total;
36
37
38 u64 flags;
39
40
41
42
43
44
45
46
47
48
49
50 struct percpu_counter total_bytes_pinned;
51
52 struct list_head list;
53
54 struct list_head ro_bgs;
55 struct list_head priority_tickets;
56 struct list_head tickets;
57
58
59
60
61 u64 tickets_id;
62
63 struct rw_semaphore groups_sem;
64
65 struct list_head block_groups[BTRFS_NR_RAID_TYPES];
66 wait_queue_head_t wait;
67
68 struct kobject kobj;
69 struct kobject *block_group_kobjs[BTRFS_NR_RAID_TYPES];
70};
71
72struct reserve_ticket {
73 u64 orig_bytes;
74 u64 bytes;
75 int error;
76 struct list_head list;
77 wait_queue_head_t wait;
78};
79
80static inline bool btrfs_mixed_space_info(struct btrfs_space_info *space_info)
81{
82 return ((space_info->flags & BTRFS_BLOCK_GROUP_METADATA) &&
83 (space_info->flags & BTRFS_BLOCK_GROUP_DATA));
84}
85
86
87
88
89
90#define DECLARE_SPACE_INFO_UPDATE(name) \
91static inline void \
92btrfs_space_info_update_##name(struct btrfs_fs_info *fs_info, \
93 struct btrfs_space_info *sinfo, \
94 s64 bytes) \
95{ \
96 lockdep_assert_held(&sinfo->lock); \
97 trace_update_##name(fs_info, sinfo, sinfo->name, bytes); \
98 if (bytes < 0 && sinfo->name < -bytes) { \
99 WARN_ON(1); \
100 sinfo->name = 0; \
101 return; \
102 } \
103 sinfo->name += bytes; \
104}
105
106DECLARE_SPACE_INFO_UPDATE(bytes_may_use);
107DECLARE_SPACE_INFO_UPDATE(bytes_pinned);
108
109void btrfs_space_info_add_new_bytes(struct btrfs_fs_info *fs_info,
110 struct btrfs_space_info *space_info,
111 u64 num_bytes);
112void btrfs_space_info_add_old_bytes(struct btrfs_fs_info *fs_info,
113 struct btrfs_space_info *space_info,
114 u64 num_bytes);
115int btrfs_init_space_info(struct btrfs_fs_info *fs_info);
116void btrfs_update_space_info(struct btrfs_fs_info *info, u64 flags,
117 u64 total_bytes, u64 bytes_used,
118 u64 bytes_readonly,
119 struct btrfs_space_info **space_info);
120struct btrfs_space_info *btrfs_find_space_info(struct btrfs_fs_info *info,
121 u64 flags);
122u64 btrfs_space_info_used(struct btrfs_space_info *s_info,
123 bool may_use_included);
124void btrfs_clear_space_info_full(struct btrfs_fs_info *info);
125void btrfs_dump_space_info(struct btrfs_fs_info *fs_info,
126 struct btrfs_space_info *info, u64 bytes,
127 int dump_block_groups);
128int btrfs_reserve_metadata_bytes(struct btrfs_root *root,
129 struct btrfs_block_rsv *block_rsv,
130 u64 orig_bytes,
131 enum btrfs_reserve_flush_enum flush);
132
133#endif
134