diff options
Diffstat (limited to 'fs/btrfs/extent_io.c')
-rw-r--r-- | fs/btrfs/extent_io.c | 52 |
1 files changed, 47 insertions, 5 deletions
diff --git a/fs/btrfs/extent_io.c b/fs/btrfs/extent_io.c index e7e7afb4a872..fe443fece851 100644 --- a/fs/btrfs/extent_io.c +++ b/fs/btrfs/extent_io.c | |||
@@ -77,10 +77,29 @@ void btrfs_leak_debug_check(void) | |||
77 | kmem_cache_free(extent_buffer_cache, eb); | 77 | kmem_cache_free(extent_buffer_cache, eb); |
78 | } | 78 | } |
79 | } | 79 | } |
80 | |||
81 | #define btrfs_debug_check_extent_io_range(inode, start, end) \ | ||
82 | __btrfs_debug_check_extent_io_range(__func__, (inode), (start), (end)) | ||
83 | static inline void __btrfs_debug_check_extent_io_range(const char *caller, | ||
84 | struct inode *inode, u64 start, u64 end) | ||
85 | { | ||
86 | u64 isize = i_size_read(inode); | ||
87 | |||
88 | if (end >= PAGE_SIZE && (end % 2) == 0 && end != isize - 1) { | ||
89 | printk_ratelimited(KERN_DEBUG | ||
90 | "btrfs: %s: ino %llu isize %llu odd range [%llu,%llu]\n", | ||
91 | caller, | ||
92 | (unsigned long long)btrfs_ino(inode), | ||
93 | (unsigned long long)isize, | ||
94 | (unsigned long long)start, | ||
95 | (unsigned long long)end); | ||
96 | } | ||
97 | } | ||
80 | #else | 98 | #else |
81 | #define btrfs_leak_debug_add(new, head) do {} while (0) | 99 | #define btrfs_leak_debug_add(new, head) do {} while (0) |
82 | #define btrfs_leak_debug_del(entry) do {} while (0) | 100 | #define btrfs_leak_debug_del(entry) do {} while (0) |
83 | #define btrfs_leak_debug_check() do {} while (0) | 101 | #define btrfs_leak_debug_check() do {} while (0) |
102 | #define btrfs_debug_check_extent_io_range(c, s, e) do {} while (0) | ||
84 | #endif | 103 | #endif |
85 | 104 | ||
86 | #define BUFFER_LRU_MAX 64 | 105 | #define BUFFER_LRU_MAX 64 |
@@ -522,6 +541,11 @@ int clear_extent_bit(struct extent_io_tree *tree, u64 start, u64 end, | |||
522 | int err; | 541 | int err; |
523 | int clear = 0; | 542 | int clear = 0; |
524 | 543 | ||
544 | btrfs_debug_check_extent_io_range(tree->mapping->host, start, end); | ||
545 | |||
546 | if (bits & EXTENT_DELALLOC) | ||
547 | bits |= EXTENT_NORESERVE; | ||
548 | |||
525 | if (delete) | 549 | if (delete) |
526 | bits |= ~EXTENT_CTLBITS; | 550 | bits |= ~EXTENT_CTLBITS; |
527 | bits |= EXTENT_FIRST_DELALLOC; | 551 | bits |= EXTENT_FIRST_DELALLOC; |
@@ -677,6 +701,8 @@ static void wait_extent_bit(struct extent_io_tree *tree, u64 start, u64 end, | |||
677 | struct extent_state *state; | 701 | struct extent_state *state; |
678 | struct rb_node *node; | 702 | struct rb_node *node; |
679 | 703 | ||
704 | btrfs_debug_check_extent_io_range(tree->mapping->host, start, end); | ||
705 | |||
680 | spin_lock(&tree->lock); | 706 | spin_lock(&tree->lock); |
681 | again: | 707 | again: |
682 | while (1) { | 708 | while (1) { |
@@ -769,6 +795,8 @@ __set_extent_bit(struct extent_io_tree *tree, u64 start, u64 end, | |||
769 | u64 last_start; | 795 | u64 last_start; |
770 | u64 last_end; | 796 | u64 last_end; |
771 | 797 | ||
798 | btrfs_debug_check_extent_io_range(tree->mapping->host, start, end); | ||
799 | |||
772 | bits |= EXTENT_FIRST_DELALLOC; | 800 | bits |= EXTENT_FIRST_DELALLOC; |
773 | again: | 801 | again: |
774 | if (!prealloc && (mask & __GFP_WAIT)) { | 802 | if (!prealloc && (mask & __GFP_WAIT)) { |
@@ -989,6 +1017,8 @@ int convert_extent_bit(struct extent_io_tree *tree, u64 start, u64 end, | |||
989 | u64 last_start; | 1017 | u64 last_start; |
990 | u64 last_end; | 1018 | u64 last_end; |
991 | 1019 | ||
1020 | btrfs_debug_check_extent_io_range(tree->mapping->host, start, end); | ||
1021 | |||
992 | again: | 1022 | again: |
993 | if (!prealloc && (mask & __GFP_WAIT)) { | 1023 | if (!prealloc && (mask & __GFP_WAIT)) { |
994 | prealloc = alloc_extent_state(mask); | 1024 | prealloc = alloc_extent_state(mask); |
@@ -2450,11 +2480,12 @@ static void end_bio_extent_readpage(struct bio *bio, int err) | |||
2450 | struct extent_state *cached = NULL; | 2480 | struct extent_state *cached = NULL; |
2451 | struct extent_state *state; | 2481 | struct extent_state *state; |
2452 | struct btrfs_io_bio *io_bio = btrfs_io_bio(bio); | 2482 | struct btrfs_io_bio *io_bio = btrfs_io_bio(bio); |
2483 | struct inode *inode = page->mapping->host; | ||
2453 | 2484 | ||
2454 | pr_debug("end_bio_extent_readpage: bi_sector=%llu, err=%d, " | 2485 | pr_debug("end_bio_extent_readpage: bi_sector=%llu, err=%d, " |
2455 | "mirror=%lu\n", (u64)bio->bi_sector, err, | 2486 | "mirror=%lu\n", (u64)bio->bi_sector, err, |
2456 | io_bio->mirror_num); | 2487 | io_bio->mirror_num); |
2457 | tree = &BTRFS_I(page->mapping->host)->io_tree; | 2488 | tree = &BTRFS_I(inode)->io_tree; |
2458 | 2489 | ||
2459 | /* We always issue full-page reads, but if some block | 2490 | /* We always issue full-page reads, but if some block |
2460 | * in a page fails to read, blk_update_request() will | 2491 | * in a page fails to read, blk_update_request() will |
@@ -2528,6 +2559,14 @@ static void end_bio_extent_readpage(struct bio *bio, int err) | |||
2528 | unlock_extent_cached(tree, start, end, &cached, GFP_ATOMIC); | 2559 | unlock_extent_cached(tree, start, end, &cached, GFP_ATOMIC); |
2529 | 2560 | ||
2530 | if (uptodate) { | 2561 | if (uptodate) { |
2562 | loff_t i_size = i_size_read(inode); | ||
2563 | pgoff_t end_index = i_size >> PAGE_CACHE_SHIFT; | ||
2564 | unsigned offset; | ||
2565 | |||
2566 | /* Zero out the end if this page straddles i_size */ | ||
2567 | offset = i_size & (PAGE_CACHE_SIZE-1); | ||
2568 | if (page->index == end_index && offset) | ||
2569 | zero_user_segment(page, offset, PAGE_CACHE_SIZE); | ||
2531 | SetPageUptodate(page); | 2570 | SetPageUptodate(page); |
2532 | } else { | 2571 | } else { |
2533 | ClearPageUptodate(page); | 2572 | ClearPageUptodate(page); |
@@ -2957,7 +2996,7 @@ static int __extent_writepage(struct page *page, struct writeback_control *wbc, | |||
2957 | pg_offset = i_size & (PAGE_CACHE_SIZE - 1); | 2996 | pg_offset = i_size & (PAGE_CACHE_SIZE - 1); |
2958 | if (page->index > end_index || | 2997 | if (page->index > end_index || |
2959 | (page->index == end_index && !pg_offset)) { | 2998 | (page->index == end_index && !pg_offset)) { |
2960 | page->mapping->a_ops->invalidatepage(page, 0); | 2999 | page->mapping->a_ops->invalidatepage(page, 0, PAGE_CACHE_SIZE); |
2961 | unlock_page(page); | 3000 | unlock_page(page); |
2962 | return 0; | 3001 | return 0; |
2963 | } | 3002 | } |
@@ -4009,7 +4048,7 @@ int extent_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo, | |||
4009 | } | 4048 | } |
4010 | 4049 | ||
4011 | while (!end) { | 4050 | while (!end) { |
4012 | u64 offset_in_extent; | 4051 | u64 offset_in_extent = 0; |
4013 | 4052 | ||
4014 | /* break if the extent we found is outside the range */ | 4053 | /* break if the extent we found is outside the range */ |
4015 | if (em->start >= max || extent_map_end(em) < off) | 4054 | if (em->start >= max || extent_map_end(em) < off) |
@@ -4025,9 +4064,12 @@ int extent_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo, | |||
4025 | 4064 | ||
4026 | /* | 4065 | /* |
4027 | * record the offset from the start of the extent | 4066 | * record the offset from the start of the extent |
4028 | * for adjusting the disk offset below | 4067 | * for adjusting the disk offset below. Only do this if the |
4068 | * extent isn't compressed since our in ram offset may be past | ||
4069 | * what we have actually allocated on disk. | ||
4029 | */ | 4070 | */ |
4030 | offset_in_extent = em_start - em->start; | 4071 | if (!test_bit(EXTENT_FLAG_COMPRESSED, &em->flags)) |
4072 | offset_in_extent = em_start - em->start; | ||
4031 | em_end = extent_map_end(em); | 4073 | em_end = extent_map_end(em); |
4032 | em_len = em_end - em_start; | 4074 | em_len = em_end - em_start; |
4033 | emflags = em->flags; | 4075 | emflags = em->flags; |