1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19#ifndef __BTRFS_ORDERED_DATA__
20#define __BTRFS_ORDERED_DATA__
21
22
23struct btrfs_ordered_inode_tree {
24 spinlock_t lock;
25 struct rb_root tree;
26 struct rb_node *last;
27};
28
29struct btrfs_ordered_sum {
30
31 u64 bytenr;
32
33
34
35
36 int len;
37 struct list_head list;
38
39 u32 sums[];
40};
41
42
43
44
45
46
47
48
49
50
51
52
53#define BTRFS_ORDERED_IO_DONE 0
54
55#define BTRFS_ORDERED_COMPLETE 1
56
57#define BTRFS_ORDERED_NOCOW 2
58
59#define BTRFS_ORDERED_COMPRESSED 3
60
61#define BTRFS_ORDERED_PREALLOC 4
62
63#define BTRFS_ORDERED_DIRECT 5
64
65#define BTRFS_ORDERED_IOERR 6
66
67#define BTRFS_ORDERED_UPDATED_ISIZE 7
68
69
70#define BTRFS_ORDERED_LOGGED_CSUM 8
71
72#define BTRFS_ORDERED_TRUNCATED 9
73
74#define BTRFS_ORDERED_LOGGED 10
75
76#define BTRFS_ORDERED_PENDING 11
77
78struct btrfs_ordered_extent {
79
80 u64 file_offset;
81
82
83 u64 start;
84
85
86 u64 len;
87
88
89 u64 disk_len;
90
91
92 u64 bytes_left;
93
94
95
96
97
98
99 u64 outstanding_isize;
100
101
102
103
104
105 u64 truncated_len;
106
107
108 unsigned long flags;
109
110
111 int compress_type;
112
113
114 atomic_t refs;
115
116
117 struct inode *inode;
118
119
120 struct list_head list;
121
122
123 struct list_head log_list;
124
125
126 struct list_head trans_list;
127
128
129 wait_queue_head_t wait;
130
131
132 struct rb_node rb_node;
133
134
135 struct list_head root_extent_list;
136
137 struct btrfs_work work;
138
139 struct completion completion;
140 struct btrfs_work flush_work;
141 struct list_head work_list;
142};
143
144
145
146
147
148static inline int btrfs_ordered_sum_size(struct btrfs_root *root,
149 unsigned long bytes)
150{
151 int num_sectors = (int)DIV_ROUND_UP(bytes, root->sectorsize);
152 return sizeof(struct btrfs_ordered_sum) + num_sectors * sizeof(u32);
153}
154
155static inline void
156btrfs_ordered_inode_tree_init(struct btrfs_ordered_inode_tree *t)
157{
158 spin_lock_init(&t->lock);
159 t->tree = RB_ROOT;
160 t->last = NULL;
161}
162
163void btrfs_put_ordered_extent(struct btrfs_ordered_extent *entry);
164void btrfs_remove_ordered_extent(struct inode *inode,
165 struct btrfs_ordered_extent *entry);
166int btrfs_dec_test_ordered_pending(struct inode *inode,
167 struct btrfs_ordered_extent **cached,
168 u64 file_offset, u64 io_size, int uptodate);
169int btrfs_dec_test_first_ordered_pending(struct inode *inode,
170 struct btrfs_ordered_extent **cached,
171 u64 *file_offset, u64 io_size,
172 int uptodate);
173int btrfs_add_ordered_extent(struct inode *inode, u64 file_offset,
174 u64 start, u64 len, u64 disk_len, int type);
175int btrfs_add_ordered_extent_dio(struct inode *inode, u64 file_offset,
176 u64 start, u64 len, u64 disk_len, int type);
177int btrfs_add_ordered_extent_compress(struct inode *inode, u64 file_offset,
178 u64 start, u64 len, u64 disk_len,
179 int type, int compress_type);
180void btrfs_add_ordered_sum(struct inode *inode,
181 struct btrfs_ordered_extent *entry,
182 struct btrfs_ordered_sum *sum);
183struct btrfs_ordered_extent *btrfs_lookup_ordered_extent(struct inode *inode,
184 u64 file_offset);
185void btrfs_start_ordered_extent(struct inode *inode,
186 struct btrfs_ordered_extent *entry, int wait);
187int btrfs_wait_ordered_range(struct inode *inode, u64 start, u64 len);
188struct btrfs_ordered_extent *
189btrfs_lookup_first_ordered_extent(struct inode * inode, u64 file_offset);
190struct btrfs_ordered_extent *btrfs_lookup_ordered_range(struct inode *inode,
191 u64 file_offset,
192 u64 len);
193bool btrfs_have_ordered_extents_in_range(struct inode *inode,
194 u64 file_offset,
195 u64 len);
196int btrfs_ordered_update_i_size(struct inode *inode, u64 offset,
197 struct btrfs_ordered_extent *ordered);
198int btrfs_find_ordered_sum(struct inode *inode, u64 offset, u64 disk_bytenr,
199 u32 *sum, int len);
200int btrfs_wait_ordered_extents(struct btrfs_root *root, int nr,
201 const u64 range_start, const u64 range_len);
202int btrfs_wait_ordered_roots(struct btrfs_fs_info *fs_info, int nr,
203 const u64 range_start, const u64 range_len);
204void btrfs_get_logged_extents(struct inode *inode,
205 struct list_head *logged_list,
206 const loff_t start,
207 const loff_t end);
208void btrfs_put_logged_extents(struct list_head *logged_list);
209void btrfs_submit_logged_extents(struct list_head *logged_list,
210 struct btrfs_root *log);
211void btrfs_wait_logged_extents(struct btrfs_trans_handle *trans,
212 struct btrfs_root *log, u64 transid);
213void btrfs_free_logged_extents(struct btrfs_root *log, u64 transid);
214int __init ordered_data_init(void);
215void ordered_data_exit(void);
216#endif
217