diff options
Diffstat (limited to 'fs/btrfs/disk-io.c')
-rw-r--r-- | fs/btrfs/disk-io.c | 20 |
1 files changed, 19 insertions, 1 deletions
diff --git a/fs/btrfs/disk-io.c b/fs/btrfs/disk-io.c index d9698fda2d12..98fe70193397 100644 --- a/fs/btrfs/disk-io.c +++ b/fs/btrfs/disk-io.c | |||
@@ -329,6 +329,8 @@ static int verify_parent_transid(struct extent_io_tree *io_tree, | |||
329 | { | 329 | { |
330 | struct extent_state *cached_state = NULL; | 330 | struct extent_state *cached_state = NULL; |
331 | int ret; | 331 | int ret; |
332 | bool need_lock = (current->journal_info == | ||
333 | (void *)BTRFS_SEND_TRANS_STUB); | ||
332 | 334 | ||
333 | if (!parent_transid || btrfs_header_generation(eb) == parent_transid) | 335 | if (!parent_transid || btrfs_header_generation(eb) == parent_transid) |
334 | return 0; | 336 | return 0; |
@@ -336,6 +338,11 @@ static int verify_parent_transid(struct extent_io_tree *io_tree, | |||
336 | if (atomic) | 338 | if (atomic) |
337 | return -EAGAIN; | 339 | return -EAGAIN; |
338 | 340 | ||
341 | if (need_lock) { | ||
342 | btrfs_tree_read_lock(eb); | ||
343 | btrfs_set_lock_blocking_rw(eb, BTRFS_READ_LOCK); | ||
344 | } | ||
345 | |||
339 | lock_extent_bits(io_tree, eb->start, eb->start + eb->len - 1, | 346 | lock_extent_bits(io_tree, eb->start, eb->start + eb->len - 1, |
340 | 0, &cached_state); | 347 | 0, &cached_state); |
341 | if (extent_buffer_uptodate(eb) && | 348 | if (extent_buffer_uptodate(eb) && |
@@ -347,10 +354,21 @@ static int verify_parent_transid(struct extent_io_tree *io_tree, | |||
347 | "found %llu\n", | 354 | "found %llu\n", |
348 | eb->start, parent_transid, btrfs_header_generation(eb)); | 355 | eb->start, parent_transid, btrfs_header_generation(eb)); |
349 | ret = 1; | 356 | ret = 1; |
350 | clear_extent_buffer_uptodate(eb); | 357 | |
358 | /* | ||
359 | * Things reading via commit roots that don't have normal protection, | ||
360 | * like send, can have a really old block in cache that may point at a | ||
361 | * block that has been free'd and re-allocated. So don't clear uptodate | ||
362 | * if we find an eb that is under IO (dirty/writeback) because we could | ||
363 | * end up reading in the stale data and then writing it back out and | ||
364 | * making everybody very sad. | ||
365 | */ | ||
366 | if (!extent_buffer_under_io(eb)) | ||
367 | clear_extent_buffer_uptodate(eb); | ||
351 | out: | 368 | out: |
352 | unlock_extent_cached(io_tree, eb->start, eb->start + eb->len - 1, | 369 | unlock_extent_cached(io_tree, eb->start, eb->start + eb->len - 1, |
353 | &cached_state, GFP_NOFS); | 370 | &cached_state, GFP_NOFS); |
371 | btrfs_tree_read_unlock_blocking(eb); | ||
354 | return ret; | 372 | return ret; |
355 | } | 373 | } |
356 | 374 | ||