diff options
author | Chris Mason <chris.mason@oracle.com> | 2010-11-28 19:56:33 -0500 |
---|---|---|
committer | Chris Mason <chris.mason@oracle.com> | 2010-11-28 19:56:33 -0500 |
commit | 163cf09c2a0ee5cac6285f9347975bd1e97725da (patch) | |
tree | 5a83cd42d57fcc4d92d12965b5eafdb472e89b02 /fs/btrfs/ordered-data.c | |
parent | 450ba0ea06b6ed3612d27f2b7127a9de4160f285 (diff) |
Btrfs: deal with DIO bios that span more than one ordered extent
The new DIO bio splitting code has problems when the bio
spans more than one ordered extent. This will happen as the
generic DIO code merges our get_blocks calls together into
a bigger single bio.
This fixes things by walking forward in the ordered extent
code finding all the overlapping ordered extents and completing them
all at once.
Signed-off-by: Chris Mason <chris.mason@oracle.com>
Diffstat (limited to 'fs/btrfs/ordered-data.c')
-rw-r--r-- | fs/btrfs/ordered-data.c | 67 |
1 files changed, 67 insertions, 0 deletions
diff --git a/fs/btrfs/ordered-data.c b/fs/btrfs/ordered-data.c index f4621f6deca1..ae7737e352c9 100644 --- a/fs/btrfs/ordered-data.c +++ b/fs/btrfs/ordered-data.c | |||
@@ -250,6 +250,73 @@ int btrfs_add_ordered_sum(struct inode *inode, | |||
250 | 250 | ||
251 | /* | 251 | /* |
252 | * this is used to account for finished IO across a given range | 252 | * this is used to account for finished IO across a given range |
253 | * of the file. The IO may span ordered extents. If | ||
254 | * a given ordered_extent is completely done, 1 is returned, otherwise | ||
255 | * 0. | ||
256 | * | ||
257 | * test_and_set_bit on a flag in the struct btrfs_ordered_extent is used | ||
258 | * to make sure this function only returns 1 once for a given ordered extent. | ||
259 | * | ||
260 | * file_offset is updated to one byte past the range that is recorded as | ||
261 | * complete. This allows you to walk forward in the file. | ||
262 | */ | ||
263 | int btrfs_dec_test_first_ordered_pending(struct inode *inode, | ||
264 | struct btrfs_ordered_extent **cached, | ||
265 | u64 *file_offset, u64 io_size) | ||
266 | { | ||
267 | struct btrfs_ordered_inode_tree *tree; | ||
268 | struct rb_node *node; | ||
269 | struct btrfs_ordered_extent *entry = NULL; | ||
270 | int ret; | ||
271 | u64 dec_end; | ||
272 | u64 dec_start; | ||
273 | u64 to_dec; | ||
274 | |||
275 | tree = &BTRFS_I(inode)->ordered_tree; | ||
276 | spin_lock(&tree->lock); | ||
277 | node = tree_search(tree, *file_offset); | ||
278 | if (!node) { | ||
279 | ret = 1; | ||
280 | goto out; | ||
281 | } | ||
282 | |||
283 | entry = rb_entry(node, struct btrfs_ordered_extent, rb_node); | ||
284 | if (!offset_in_entry(entry, *file_offset)) { | ||
285 | ret = 1; | ||
286 | goto out; | ||
287 | } | ||
288 | |||
289 | dec_start = max(*file_offset, entry->file_offset); | ||
290 | dec_end = min(*file_offset + io_size, entry->file_offset + | ||
291 | entry->len); | ||
292 | *file_offset = dec_end; | ||
293 | if (dec_start > dec_end) { | ||
294 | printk(KERN_CRIT "bad ordering dec_start %llu end %llu\n", | ||
295 | (unsigned long long)dec_start, | ||
296 | (unsigned long long)dec_end); | ||
297 | } | ||
298 | to_dec = dec_end - dec_start; | ||
299 | if (to_dec > entry->bytes_left) { | ||
300 | printk(KERN_CRIT "bad ordered accounting left %llu size %llu\n", | ||
301 | (unsigned long long)entry->bytes_left, | ||
302 | (unsigned long long)to_dec); | ||
303 | } | ||
304 | entry->bytes_left -= to_dec; | ||
305 | if (entry->bytes_left == 0) | ||
306 | ret = test_and_set_bit(BTRFS_ORDERED_IO_DONE, &entry->flags); | ||
307 | else | ||
308 | ret = 1; | ||
309 | out: | ||
310 | if (!ret && cached && entry) { | ||
311 | *cached = entry; | ||
312 | atomic_inc(&entry->refs); | ||
313 | } | ||
314 | spin_unlock(&tree->lock); | ||
315 | return ret == 0; | ||
316 | } | ||
317 | |||
318 | /* | ||
319 | * this is used to account for finished IO across a given range | ||
253 | * of the file. The IO should not span ordered extents. If | 320 | * of the file. The IO should not span ordered extents. If |
254 | * a given ordered_extent is completely done, 1 is returned, otherwise | 321 | * a given ordered_extent is completely done, 1 is returned, otherwise |
255 | * 0. | 322 | * 0. |