@@ -143,16 +143,28 @@ static inline struct rb_node *tree_search(struct btrfs_ordered_inode_tree *tree,
143
143
return ret ;
144
144
}
145
145
146
- /*
147
- * Allocate and add a new ordered_extent into the per-inode tree.
146
+ /**
147
+ * Add an ordered extent to the per-inode tree.
148
+ *
149
+ * @inode: Inode that this extent is for.
150
+ * @file_offset: Logical offset in file where the extent starts.
151
+ * @num_bytes: Logical length of extent in file.
152
+ * @ram_bytes: Full length of unencoded data.
153
+ * @disk_bytenr: Offset of extent on disk.
154
+ * @disk_num_bytes: Size of extent on disk.
155
+ * @offset: Offset into unencoded data where file data starts.
156
+ * @flags: Flags specifying type of extent (1 << BTRFS_ORDERED_*).
157
+ * @compress_type: Compression algorithm used for data.
158
+ *
159
+ * Most of these parameters correspond to &struct btrfs_file_extent_item. The
160
+ * tree is given a single reference on the ordered extent that was inserted.
148
161
*
149
- * The tree is given a single reference on the ordered extent that was
150
- * inserted.
162
+ * Return: 0 or -ENOMEM.
151
163
*/
152
- static int __btrfs_add_ordered_extent (struct btrfs_inode * inode , u64 file_offset ,
153
- u64 disk_bytenr , u64 num_bytes ,
154
- u64 disk_num_bytes , int type , int dio ,
155
- int compress_type )
164
+ int btrfs_add_ordered_extent (struct btrfs_inode * inode , u64 file_offset ,
165
+ u64 num_bytes , u64 ram_bytes , u64 disk_bytenr ,
166
+ u64 disk_num_bytes , u64 offset , unsigned flags ,
167
+ int compress_type )
156
168
{
157
169
struct btrfs_root * root = inode -> root ;
158
170
struct btrfs_fs_info * fs_info = root -> fs_info ;
@@ -161,7 +173,8 @@ static int __btrfs_add_ordered_extent(struct btrfs_inode *inode, u64 file_offset
161
173
struct btrfs_ordered_extent * entry ;
162
174
int ret ;
163
175
164
- if (type == BTRFS_ORDERED_NOCOW || type == BTRFS_ORDERED_PREALLOC ) {
176
+ if (flags &
177
+ ((1 << BTRFS_ORDERED_NOCOW ) | (1 << BTRFS_ORDERED_PREALLOC ))) {
165
178
/* For nocow write, we can release the qgroup rsv right now */
166
179
ret = btrfs_qgroup_free_data (inode , NULL , file_offset , num_bytes );
167
180
if (ret < 0 )
@@ -181,28 +194,24 @@ static int __btrfs_add_ordered_extent(struct btrfs_inode *inode, u64 file_offset
181
194
return - ENOMEM ;
182
195
183
196
entry -> file_offset = file_offset ;
184
- entry -> disk_bytenr = disk_bytenr ;
185
197
entry -> num_bytes = num_bytes ;
198
+ entry -> ram_bytes = ram_bytes ;
199
+ entry -> disk_bytenr = disk_bytenr ;
186
200
entry -> disk_num_bytes = disk_num_bytes ;
201
+ entry -> offset = offset ;
187
202
entry -> bytes_left = num_bytes ;
188
203
entry -> inode = igrab (& inode -> vfs_inode );
189
204
entry -> compress_type = compress_type ;
190
205
entry -> truncated_len = (u64 )- 1 ;
191
206
entry -> qgroup_rsv = ret ;
192
207
entry -> physical = (u64 )- 1 ;
193
208
194
- ASSERT (type == BTRFS_ORDERED_REGULAR ||
195
- type == BTRFS_ORDERED_NOCOW ||
196
- type == BTRFS_ORDERED_PREALLOC ||
197
- type == BTRFS_ORDERED_COMPRESSED );
198
- set_bit (type , & entry -> flags );
209
+ ASSERT ((flags & ~BTRFS_ORDERED_TYPE_FLAGS ) == 0 );
210
+ entry -> flags = flags ;
199
211
200
212
percpu_counter_add_batch (& fs_info -> ordered_bytes , num_bytes ,
201
213
fs_info -> delalloc_batch );
202
214
203
- if (dio )
204
- set_bit (BTRFS_ORDERED_DIRECT , & entry -> flags );
205
-
206
215
/* one ref for the tree */
207
216
refcount_set (& entry -> refs , 1 );
208
217
init_waitqueue_head (& entry -> wait );
@@ -247,41 +256,6 @@ static int __btrfs_add_ordered_extent(struct btrfs_inode *inode, u64 file_offset
247
256
return 0 ;
248
257
}
249
258
250
- int btrfs_add_ordered_extent (struct btrfs_inode * inode , u64 file_offset ,
251
- u64 disk_bytenr , u64 num_bytes , u64 disk_num_bytes ,
252
- int type )
253
- {
254
- ASSERT (type == BTRFS_ORDERED_REGULAR ||
255
- type == BTRFS_ORDERED_NOCOW ||
256
- type == BTRFS_ORDERED_PREALLOC );
257
- return __btrfs_add_ordered_extent (inode , file_offset , disk_bytenr ,
258
- num_bytes , disk_num_bytes , type , 0 ,
259
- BTRFS_COMPRESS_NONE );
260
- }
261
-
262
- int btrfs_add_ordered_extent_dio (struct btrfs_inode * inode , u64 file_offset ,
263
- u64 disk_bytenr , u64 num_bytes ,
264
- u64 disk_num_bytes , int type )
265
- {
266
- ASSERT (type == BTRFS_ORDERED_REGULAR ||
267
- type == BTRFS_ORDERED_NOCOW ||
268
- type == BTRFS_ORDERED_PREALLOC );
269
- return __btrfs_add_ordered_extent (inode , file_offset , disk_bytenr ,
270
- num_bytes , disk_num_bytes , type , 1 ,
271
- BTRFS_COMPRESS_NONE );
272
- }
273
-
274
- int btrfs_add_ordered_extent_compress (struct btrfs_inode * inode , u64 file_offset ,
275
- u64 disk_bytenr , u64 num_bytes ,
276
- u64 disk_num_bytes , int compress_type )
277
- {
278
- ASSERT (compress_type != BTRFS_COMPRESS_NONE );
279
- return __btrfs_add_ordered_extent (inode , file_offset , disk_bytenr ,
280
- num_bytes , disk_num_bytes ,
281
- BTRFS_ORDERED_COMPRESSED , 0 ,
282
- compress_type );
283
- }
284
-
285
259
/*
286
260
* Add a struct btrfs_ordered_sum into the list of checksums to be inserted
287
261
* when an ordered extent is finished. If the list covers more than one
@@ -1052,42 +1026,18 @@ static int clone_ordered_extent(struct btrfs_ordered_extent *ordered, u64 pos,
1052
1026
struct btrfs_fs_info * fs_info = BTRFS_I (inode )-> root -> fs_info ;
1053
1027
u64 file_offset = ordered -> file_offset + pos ;
1054
1028
u64 disk_bytenr = ordered -> disk_bytenr + pos ;
1055
- u64 num_bytes = len ;
1056
- u64 disk_num_bytes = len ;
1057
- int type ;
1058
- unsigned long flags_masked = ordered -> flags & ~(1 << BTRFS_ORDERED_DIRECT );
1059
- int compress_type = ordered -> compress_type ;
1060
- unsigned long weight ;
1061
- int ret ;
1062
-
1063
- weight = hweight_long (flags_masked );
1064
- WARN_ON_ONCE (weight > 1 );
1065
- if (!weight )
1066
- type = 0 ;
1067
- else
1068
- type = __ffs (flags_masked );
1029
+ unsigned long flags = ordered -> flags & BTRFS_ORDERED_TYPE_FLAGS ;
1069
1030
1070
1031
/*
1071
- * The splitting extent is already counted and will be added again
1072
- * in btrfs_add_ordered_extent_*(). Subtract num_bytes to avoid
1073
- * double counting.
1032
+ * The splitting extent is already counted and will be added again in
1033
+ * btrfs_add_ordered_extent_*(). Subtract len to avoid double counting.
1074
1034
*/
1075
- percpu_counter_add_batch (& fs_info -> ordered_bytes , - num_bytes ,
1035
+ percpu_counter_add_batch (& fs_info -> ordered_bytes , - len ,
1076
1036
fs_info -> delalloc_batch );
1077
- if (test_bit (BTRFS_ORDERED_COMPRESSED , & ordered -> flags )) {
1078
- WARN_ON_ONCE (1 );
1079
- ret = btrfs_add_ordered_extent_compress (BTRFS_I (inode ),
1080
- file_offset , disk_bytenr , num_bytes ,
1081
- disk_num_bytes , compress_type );
1082
- } else if (test_bit (BTRFS_ORDERED_DIRECT , & ordered -> flags )) {
1083
- ret = btrfs_add_ordered_extent_dio (BTRFS_I (inode ), file_offset ,
1084
- disk_bytenr , num_bytes , disk_num_bytes , type );
1085
- } else {
1086
- ret = btrfs_add_ordered_extent (BTRFS_I (inode ), file_offset ,
1087
- disk_bytenr , num_bytes , disk_num_bytes , type );
1088
- }
1089
-
1090
- return ret ;
1037
+ WARN_ON_ONCE (flags & (1 << BTRFS_ORDERED_COMPRESSED ));
1038
+ return btrfs_add_ordered_extent (BTRFS_I (inode ), file_offset , len , len ,
1039
+ disk_bytenr , len , 0 , flags ,
1040
+ ordered -> compress_type );
1091
1041
}
1092
1042
1093
1043
int btrfs_split_ordered_extent (struct btrfs_ordered_extent * ordered , u64 pre ,
0 commit comments