diff options
author | David Sterba <dsterba@suse.com> | 2016-11-30 08:02:20 -0500 |
---|---|---|
committer | David Sterba <dsterba@suse.com> | 2016-11-30 08:02:20 -0500 |
commit | 515bdc479097ec9d5f389202842345af3162f71c (patch) | |
tree | 46b5ed6bfe2a969c3725a3917426730a3b59715b | |
parent | e5517c2a5a49ed5e99047008629f1cd60246ea0e (diff) | |
parent | 1d57ee941692d0cc928526e21a1557b2ae3e11db (diff) |
Merge branch 'misc-4.10' into for-chris-4.10-20161130
33 files changed, 782 insertions, 827 deletions
diff --git a/fs/btrfs/check-integrity.c b/fs/btrfs/check-integrity.c index 8e99251650b3..86f681fd200d 100644 --- a/fs/btrfs/check-integrity.c +++ b/fs/btrfs/check-integrity.c | |||
@@ -1539,7 +1539,7 @@ static int btrfsic_map_block(struct btrfsic_state *state, u64 bytenr, u32 len, | |||
1539 | struct btrfs_device *device; | 1539 | struct btrfs_device *device; |
1540 | 1540 | ||
1541 | length = len; | 1541 | length = len; |
1542 | ret = btrfs_map_block(state->root->fs_info, READ, | 1542 | ret = btrfs_map_block(state->root->fs_info, BTRFS_MAP_READ, |
1543 | bytenr, &length, &multi, mirror_num); | 1543 | bytenr, &length, &multi, mirror_num); |
1544 | 1544 | ||
1545 | if (ret) { | 1545 | if (ret) { |
@@ -2819,10 +2819,11 @@ static void __btrfsic_submit_bio(struct bio *bio) | |||
2819 | * btrfsic_mount(), this might return NULL */ | 2819 | * btrfsic_mount(), this might return NULL */ |
2820 | dev_state = btrfsic_dev_state_lookup(bio->bi_bdev); | 2820 | dev_state = btrfsic_dev_state_lookup(bio->bi_bdev); |
2821 | if (NULL != dev_state && | 2821 | if (NULL != dev_state && |
2822 | (bio_op(bio) == REQ_OP_WRITE) && NULL != bio->bi_io_vec) { | 2822 | (bio_op(bio) == REQ_OP_WRITE) && bio_has_data(bio)) { |
2823 | unsigned int i; | 2823 | unsigned int i; |
2824 | u64 dev_bytenr; | 2824 | u64 dev_bytenr; |
2825 | u64 cur_bytenr; | 2825 | u64 cur_bytenr; |
2826 | struct bio_vec *bvec; | ||
2826 | int bio_is_patched; | 2827 | int bio_is_patched; |
2827 | char **mapped_datav; | 2828 | char **mapped_datav; |
2828 | 2829 | ||
@@ -2840,32 +2841,23 @@ static void __btrfsic_submit_bio(struct bio *bio) | |||
2840 | if (!mapped_datav) | 2841 | if (!mapped_datav) |
2841 | goto leave; | 2842 | goto leave; |
2842 | cur_bytenr = dev_bytenr; | 2843 | cur_bytenr = dev_bytenr; |
2843 | for (i = 0; i < bio->bi_vcnt; i++) { | 2844 | |
2844 | BUG_ON(bio->bi_io_vec[i].bv_len != PAGE_SIZE); | 2845 | bio_for_each_segment_all(bvec, bio, i) { |
2845 | mapped_datav[i] = kmap(bio->bi_io_vec[i].bv_page); | 2846 | BUG_ON(bvec->bv_len != PAGE_SIZE); |
2846 | if (!mapped_datav[i]) { | 2847 | mapped_datav[i] = kmap(bvec->bv_page); |
2847 | while (i > 0) { | 2848 | |
2848 | i--; | ||
2849 | kunmap(bio->bi_io_vec[i].bv_page); | ||
2850 | } | ||
2851 | kfree(mapped_datav); | ||
2852 | goto leave; | ||
2853 | } | ||
2854 | if (dev_state->state->print_mask & | 2849 | if (dev_state->state->print_mask & |
2855 | BTRFSIC_PRINT_MASK_SUBMIT_BIO_BH_VERBOSE) | 2850 | BTRFSIC_PRINT_MASK_SUBMIT_BIO_BH_VERBOSE) |
2856 | pr_info("#%u: bytenr=%llu, len=%u, offset=%u\n", | 2851 | pr_info("#%u: bytenr=%llu, len=%u, offset=%u\n", |
2857 | i, cur_bytenr, bio->bi_io_vec[i].bv_len, | 2852 | i, cur_bytenr, bvec->bv_len, bvec->bv_offset); |
2858 | bio->bi_io_vec[i].bv_offset); | 2853 | cur_bytenr += bvec->bv_len; |
2859 | cur_bytenr += bio->bi_io_vec[i].bv_len; | ||
2860 | } | 2854 | } |
2861 | btrfsic_process_written_block(dev_state, dev_bytenr, | 2855 | btrfsic_process_written_block(dev_state, dev_bytenr, |
2862 | mapped_datav, bio->bi_vcnt, | 2856 | mapped_datav, bio->bi_vcnt, |
2863 | bio, &bio_is_patched, | 2857 | bio, &bio_is_patched, |
2864 | NULL, bio->bi_opf); | 2858 | NULL, bio->bi_opf); |
2865 | while (i > 0) { | 2859 | bio_for_each_segment_all(bvec, bio, i) |
2866 | i--; | 2860 | kunmap(bvec->bv_page); |
2867 | kunmap(bio->bi_io_vec[i].bv_page); | ||
2868 | } | ||
2869 | kfree(mapped_datav); | 2861 | kfree(mapped_datav); |
2870 | } else if (NULL != dev_state && (bio->bi_opf & REQ_PREFLUSH)) { | 2862 | } else if (NULL != dev_state && (bio->bi_opf & REQ_PREFLUSH)) { |
2871 | if (dev_state->state->print_mask & | 2863 | if (dev_state->state->print_mask & |
diff --git a/fs/btrfs/compression.c b/fs/btrfs/compression.c index d4d8b7e36b2f..ae4c000cbffc 100644 --- a/fs/btrfs/compression.c +++ b/fs/btrfs/compression.c | |||
@@ -81,9 +81,9 @@ struct compressed_bio { | |||
81 | u32 sums; | 81 | u32 sums; |
82 | }; | 82 | }; |
83 | 83 | ||
84 | static int btrfs_decompress_biovec(int type, struct page **pages_in, | 84 | static int btrfs_decompress_bio(int type, struct page **pages_in, |
85 | u64 disk_start, struct bio_vec *bvec, | 85 | u64 disk_start, struct bio *orig_bio, |
86 | int vcnt, size_t srclen); | 86 | size_t srclen); |
87 | 87 | ||
88 | static inline int compressed_bio_size(struct btrfs_root *root, | 88 | static inline int compressed_bio_size(struct btrfs_root *root, |
89 | unsigned long disk_size) | 89 | unsigned long disk_size) |
@@ -120,7 +120,7 @@ static int check_compressed_csum(struct inode *inode, | |||
120 | 120 | ||
121 | kaddr = kmap_atomic(page); | 121 | kaddr = kmap_atomic(page); |
122 | csum = btrfs_csum_data(kaddr, csum, PAGE_SIZE); | 122 | csum = btrfs_csum_data(kaddr, csum, PAGE_SIZE); |
123 | btrfs_csum_final(csum, (char *)&csum); | 123 | btrfs_csum_final(csum, (u8 *)&csum); |
124 | kunmap_atomic(kaddr); | 124 | kunmap_atomic(kaddr); |
125 | 125 | ||
126 | if (csum != *cb_sum) { | 126 | if (csum != *cb_sum) { |
@@ -175,11 +175,10 @@ static void end_compressed_bio_read(struct bio *bio) | |||
175 | /* ok, we're the last bio for this extent, lets start | 175 | /* ok, we're the last bio for this extent, lets start |
176 | * the decompression. | 176 | * the decompression. |
177 | */ | 177 | */ |
178 | ret = btrfs_decompress_biovec(cb->compress_type, | 178 | ret = btrfs_decompress_bio(cb->compress_type, |
179 | cb->compressed_pages, | 179 | cb->compressed_pages, |
180 | cb->start, | 180 | cb->start, |
181 | cb->orig_bio->bi_io_vec, | 181 | cb->orig_bio, |
182 | cb->orig_bio->bi_vcnt, | ||
183 | cb->compressed_len); | 182 | cb->compressed_len); |
184 | csum_failed: | 183 | csum_failed: |
185 | if (ret) | 184 | if (ret) |
@@ -446,6 +445,13 @@ int btrfs_submit_compressed_write(struct inode *inode, u64 start, | |||
446 | return 0; | 445 | return 0; |
447 | } | 446 | } |
448 | 447 | ||
448 | static u64 bio_end_offset(struct bio *bio) | ||
449 | { | ||
450 | struct bio_vec *last = &bio->bi_io_vec[bio->bi_vcnt - 1]; | ||
451 | |||
452 | return page_offset(last->bv_page) + last->bv_len + last->bv_offset; | ||
453 | } | ||
454 | |||
449 | static noinline int add_ra_bio_pages(struct inode *inode, | 455 | static noinline int add_ra_bio_pages(struct inode *inode, |
450 | u64 compressed_end, | 456 | u64 compressed_end, |
451 | struct compressed_bio *cb) | 457 | struct compressed_bio *cb) |
@@ -464,8 +470,7 @@ static noinline int add_ra_bio_pages(struct inode *inode, | |||
464 | u64 end; | 470 | u64 end; |
465 | int misses = 0; | 471 | int misses = 0; |
466 | 472 | ||
467 | page = cb->orig_bio->bi_io_vec[cb->orig_bio->bi_vcnt - 1].bv_page; | 473 | last_offset = bio_end_offset(cb->orig_bio); |
468 | last_offset = (page_offset(page) + PAGE_SIZE); | ||
469 | em_tree = &BTRFS_I(inode)->extent_tree; | 474 | em_tree = &BTRFS_I(inode)->extent_tree; |
470 | tree = &BTRFS_I(inode)->io_tree; | 475 | tree = &BTRFS_I(inode)->io_tree; |
471 | 476 | ||
@@ -563,7 +568,6 @@ next: | |||
563 | * | 568 | * |
564 | * bio->bi_iter.bi_sector points to the compressed extent on disk | 569 | * bio->bi_iter.bi_sector points to the compressed extent on disk |
565 | * bio->bi_io_vec points to all of the inode pages | 570 | * bio->bi_io_vec points to all of the inode pages |
566 | * bio->bi_vcnt is a count of pages | ||
567 | * | 571 | * |
568 | * After the compressed pages are read, we copy the bytes into the | 572 | * After the compressed pages are read, we copy the bytes into the |
569 | * bio we were passed and then call the bio end_io calls | 573 | * bio we were passed and then call the bio end_io calls |
@@ -575,7 +579,6 @@ int btrfs_submit_compressed_read(struct inode *inode, struct bio *bio, | |||
575 | struct extent_map_tree *em_tree; | 579 | struct extent_map_tree *em_tree; |
576 | struct compressed_bio *cb; | 580 | struct compressed_bio *cb; |
577 | struct btrfs_root *root = BTRFS_I(inode)->root; | 581 | struct btrfs_root *root = BTRFS_I(inode)->root; |
578 | unsigned long uncompressed_len = bio->bi_vcnt * PAGE_SIZE; | ||
579 | unsigned long compressed_len; | 582 | unsigned long compressed_len; |
580 | unsigned long nr_pages; | 583 | unsigned long nr_pages; |
581 | unsigned long pg_index; | 584 | unsigned long pg_index; |
@@ -620,7 +623,7 @@ int btrfs_submit_compressed_read(struct inode *inode, struct bio *bio, | |||
620 | free_extent_map(em); | 623 | free_extent_map(em); |
621 | em = NULL; | 624 | em = NULL; |
622 | 625 | ||
623 | cb->len = uncompressed_len; | 626 | cb->len = bio->bi_iter.bi_size; |
624 | cb->compressed_len = compressed_len; | 627 | cb->compressed_len = compressed_len; |
625 | cb->compress_type = extent_compress_type(bio_flags); | 628 | cb->compress_type = extent_compress_type(bio_flags); |
626 | cb->orig_bio = bio; | 629 | cb->orig_bio = bio; |
@@ -648,8 +651,7 @@ int btrfs_submit_compressed_read(struct inode *inode, struct bio *bio, | |||
648 | add_ra_bio_pages(inode, em_start + em_len, cb); | 651 | add_ra_bio_pages(inode, em_start + em_len, cb); |
649 | 652 | ||
650 | /* include any pages we added in add_ra-bio_pages */ | 653 | /* include any pages we added in add_ra-bio_pages */ |
651 | uncompressed_len = bio->bi_vcnt * PAGE_SIZE; | 654 | cb->len = bio->bi_iter.bi_size; |
652 | cb->len = uncompressed_len; | ||
653 | 655 | ||
654 | comp_bio = compressed_bio_alloc(bdev, cur_disk_byte, GFP_NOFS); | 656 | comp_bio = compressed_bio_alloc(bdev, cur_disk_byte, GFP_NOFS); |
655 | if (!comp_bio) | 657 | if (!comp_bio) |
@@ -959,9 +961,7 @@ int btrfs_compress_pages(int type, struct address_space *mapping, | |||
959 | * | 961 | * |
960 | * disk_start is the starting logical offset of this array in the file | 962 | * disk_start is the starting logical offset of this array in the file |
961 | * | 963 | * |
962 | * bvec is a bio_vec of pages from the file that we want to decompress into | 964 | * orig_bio contains the pages from the file that we want to decompress into |
963 | * | ||
964 | * vcnt is the count of pages in the biovec | ||
965 | * | 965 | * |
966 | * srclen is the number of bytes in pages_in | 966 | * srclen is the number of bytes in pages_in |
967 | * | 967 | * |
@@ -970,18 +970,18 @@ int btrfs_compress_pages(int type, struct address_space *mapping, | |||
970 | * be contiguous. They all correspond to the range of bytes covered by | 970 | * be contiguous. They all correspond to the range of bytes covered by |
971 | * the compressed extent. | 971 | * the compressed extent. |
972 | */ | 972 | */ |
973 | static int btrfs_decompress_biovec(int type, struct page **pages_in, | 973 | static int btrfs_decompress_bio(int type, struct page **pages_in, |
974 | u64 disk_start, struct bio_vec *bvec, | 974 | u64 disk_start, struct bio *orig_bio, |
975 | int vcnt, size_t srclen) | 975 | size_t srclen) |
976 | { | 976 | { |
977 | struct list_head *workspace; | 977 | struct list_head *workspace; |
978 | int ret; | 978 | int ret; |
979 | 979 | ||
980 | workspace = find_workspace(type); | 980 | workspace = find_workspace(type); |
981 | 981 | ||
982 | ret = btrfs_compress_op[type-1]->decompress_biovec(workspace, pages_in, | 982 | ret = btrfs_compress_op[type-1]->decompress_bio(workspace, pages_in, |
983 | disk_start, | 983 | disk_start, orig_bio, |
984 | bvec, vcnt, srclen); | 984 | srclen); |
985 | free_workspace(type, workspace); | 985 | free_workspace(type, workspace); |
986 | return ret; | 986 | return ret; |
987 | } | 987 | } |
@@ -1021,9 +1021,7 @@ void btrfs_exit_compress(void) | |||
1021 | */ | 1021 | */ |
1022 | int btrfs_decompress_buf2page(char *buf, unsigned long buf_start, | 1022 | int btrfs_decompress_buf2page(char *buf, unsigned long buf_start, |
1023 | unsigned long total_out, u64 disk_start, | 1023 | unsigned long total_out, u64 disk_start, |
1024 | struct bio_vec *bvec, int vcnt, | 1024 | struct bio *bio) |
1025 | unsigned long *pg_index, | ||
1026 | unsigned long *pg_offset) | ||
1027 | { | 1025 | { |
1028 | unsigned long buf_offset; | 1026 | unsigned long buf_offset; |
1029 | unsigned long current_buf_start; | 1027 | unsigned long current_buf_start; |
@@ -1031,13 +1029,13 @@ int btrfs_decompress_buf2page(char *buf, unsigned long buf_start, | |||
1031 | unsigned long working_bytes = total_out - buf_start; | 1029 | unsigned long working_bytes = total_out - buf_start; |
1032 | unsigned long bytes; | 1030 | unsigned long bytes; |
1033 | char *kaddr; | 1031 | char *kaddr; |
1034 | struct page *page_out = bvec[*pg_index].bv_page; | 1032 | struct bio_vec bvec = bio_iter_iovec(bio, bio->bi_iter); |
1035 | 1033 | ||
1036 | /* | 1034 | /* |
1037 | * start byte is the first byte of the page we're currently | 1035 | * start byte is the first byte of the page we're currently |
1038 | * copying into relative to the start of the compressed data. | 1036 | * copying into relative to the start of the compressed data. |
1039 | */ | 1037 | */ |
1040 | start_byte = page_offset(page_out) - disk_start; | 1038 | start_byte = page_offset(bvec.bv_page) - disk_start; |
1041 | 1039 | ||
1042 | /* we haven't yet hit data corresponding to this page */ | 1040 | /* we haven't yet hit data corresponding to this page */ |
1043 | if (total_out <= start_byte) | 1041 | if (total_out <= start_byte) |
@@ -1057,80 +1055,46 @@ int btrfs_decompress_buf2page(char *buf, unsigned long buf_start, | |||
1057 | 1055 | ||
1058 | /* copy bytes from the working buffer into the pages */ | 1056 | /* copy bytes from the working buffer into the pages */ |
1059 | while (working_bytes > 0) { | 1057 | while (working_bytes > 0) { |
1060 | bytes = min(PAGE_SIZE - *pg_offset, | 1058 | bytes = min_t(unsigned long, bvec.bv_len, |
1061 | PAGE_SIZE - buf_offset); | 1059 | PAGE_SIZE - buf_offset); |
1062 | bytes = min(bytes, working_bytes); | 1060 | bytes = min(bytes, working_bytes); |
1063 | kaddr = kmap_atomic(page_out); | 1061 | |
1064 | memcpy(kaddr + *pg_offset, buf + buf_offset, bytes); | 1062 | kaddr = kmap_atomic(bvec.bv_page); |
1063 | memcpy(kaddr + bvec.bv_offset, buf + buf_offset, bytes); | ||
1065 | kunmap_atomic(kaddr); | 1064 | kunmap_atomic(kaddr); |
1066 | flush_dcache_page(page_out); | 1065 | flush_dcache_page(bvec.bv_page); |
1067 | 1066 | ||
1068 | *pg_offset += bytes; | ||
1069 | buf_offset += bytes; | 1067 | buf_offset += bytes; |
1070 | working_bytes -= bytes; | 1068 | working_bytes -= bytes; |
1071 | current_buf_start += bytes; | 1069 | current_buf_start += bytes; |
1072 | 1070 | ||
1073 | /* check if we need to pick another page */ | 1071 | /* check if we need to pick another page */ |
1074 | if (*pg_offset == PAGE_SIZE) { | 1072 | bio_advance(bio, bytes); |
1075 | (*pg_index)++; | 1073 | if (!bio->bi_iter.bi_size) |
1076 | if (*pg_index >= vcnt) | 1074 | return 0; |
1077 | return 0; | 1075 | bvec = bio_iter_iovec(bio, bio->bi_iter); |
1078 | 1076 | ||
1079 | page_out = bvec[*pg_index].bv_page; | 1077 | start_byte = page_offset(bvec.bv_page) - disk_start; |
1080 | *pg_offset = 0; | ||
1081 | start_byte = page_offset(page_out) - disk_start; | ||
1082 | 1078 | ||
1083 | /* | 1079 | /* |
1084 | * make sure our new page is covered by this | 1080 | * make sure our new page is covered by this |
1085 | * working buffer | 1081 | * working buffer |
1086 | */ | 1082 | */ |
1087 | if (total_out <= start_byte) | 1083 | if (total_out <= start_byte) |
1088 | return 1; | 1084 | return 1; |
1089 | 1085 | ||
1090 | /* | 1086 | /* |
1091 | * the next page in the biovec might not be adjacent | 1087 | * the next page in the biovec might not be adjacent |
1092 | * to the last page, but it might still be found | 1088 | * to the last page, but it might still be found |
1093 | * inside this working buffer. bump our offset pointer | 1089 | * inside this working buffer. bump our offset pointer |
1094 | */ | 1090 | */ |
1095 | if (total_out > start_byte && | 1091 | if (total_out > start_byte && |
1096 | current_buf_start < start_byte) { | 1092 | current_buf_start < start_byte) { |
1097 | buf_offset = start_byte - buf_start; | 1093 | buf_offset = start_byte - buf_start; |
1098 | working_bytes = total_out - start_byte; | 1094 | working_bytes = total_out - start_byte; |
1099 | current_buf_start = buf_start + buf_offset; | 1095 | current_buf_start = buf_start + buf_offset; |
1100 | } | ||
1101 | } | 1096 | } |
1102 | } | 1097 | } |
1103 | 1098 | ||
1104 | return 1; | 1099 | return 1; |
1105 | } | 1100 | } |
1106 | |||
1107 | /* | ||
1108 | * When uncompressing data, we need to make sure and zero any parts of | ||
1109 | * the biovec that were not filled in by the decompression code. pg_index | ||
1110 | * and pg_offset indicate the last page and the last offset of that page | ||
1111 | * that have been filled in. This will zero everything remaining in the | ||
1112 | * biovec. | ||
1113 | */ | ||
1114 | void btrfs_clear_biovec_end(struct bio_vec *bvec, int vcnt, | ||
1115 | unsigned long pg_index, | ||
1116 | unsigned long pg_offset) | ||
1117 | { | ||
1118 | while (pg_index < vcnt) { | ||
1119 | struct page *page = bvec[pg_index].bv_page; | ||
1120 | unsigned long off = bvec[pg_index].bv_offset; | ||
1121 | unsigned long len = bvec[pg_index].bv_len; | ||
1122 | |||
1123 | if (pg_offset < off) | ||
1124 | pg_offset = off; | ||
1125 | if (pg_offset < off + len) { | ||
1126 | unsigned long bytes = off + len - pg_offset; | ||
1127 | char *kaddr; | ||
1128 | |||
1129 | kaddr = kmap_atomic(page); | ||
1130 | memset(kaddr + pg_offset, 0, bytes); | ||
1131 | kunmap_atomic(kaddr); | ||
1132 | } | ||
1133 | pg_index++; | ||
1134 | pg_offset = 0; | ||
1135 | } | ||
1136 | } | ||
diff --git a/fs/btrfs/compression.h b/fs/btrfs/compression.h index f49d8b8c0f00..09879579fbc8 100644 --- a/fs/btrfs/compression.h +++ b/fs/btrfs/compression.h | |||
@@ -34,9 +34,7 @@ int btrfs_decompress(int type, unsigned char *data_in, struct page *dest_page, | |||
34 | unsigned long start_byte, size_t srclen, size_t destlen); | 34 | unsigned long start_byte, size_t srclen, size_t destlen); |
35 | int btrfs_decompress_buf2page(char *buf, unsigned long buf_start, | 35 | int btrfs_decompress_buf2page(char *buf, unsigned long buf_start, |
36 | unsigned long total_out, u64 disk_start, | 36 | unsigned long total_out, u64 disk_start, |
37 | struct bio_vec *bvec, int vcnt, | 37 | struct bio *bio); |
38 | unsigned long *pg_index, | ||
39 | unsigned long *pg_offset); | ||
40 | 38 | ||
41 | int btrfs_submit_compressed_write(struct inode *inode, u64 start, | 39 | int btrfs_submit_compressed_write(struct inode *inode, u64 start, |
42 | unsigned long len, u64 disk_start, | 40 | unsigned long len, u64 disk_start, |
@@ -45,9 +43,6 @@ int btrfs_submit_compressed_write(struct inode *inode, u64 start, | |||
45 | unsigned long nr_pages); | 43 | unsigned long nr_pages); |
46 | int btrfs_submit_compressed_read(struct inode *inode, struct bio *bio, | 44 | int btrfs_submit_compressed_read(struct inode *inode, struct bio *bio, |
47 | int mirror_num, unsigned long bio_flags); | 45 | int mirror_num, unsigned long bio_flags); |
48 | void btrfs_clear_biovec_end(struct bio_vec *bvec, int vcnt, | ||
49 | unsigned long pg_index, | ||
50 | unsigned long pg_offset); | ||
51 | 46 | ||
52 | enum btrfs_compression_type { | 47 | enum btrfs_compression_type { |
53 | BTRFS_COMPRESS_NONE = 0, | 48 | BTRFS_COMPRESS_NONE = 0, |
@@ -72,11 +67,10 @@ struct btrfs_compress_op { | |||
72 | unsigned long *total_out, | 67 | unsigned long *total_out, |
73 | unsigned long max_out); | 68 | unsigned long max_out); |
74 | 69 | ||
75 | int (*decompress_biovec)(struct list_head *workspace, | 70 | int (*decompress_bio)(struct list_head *workspace, |
76 | struct page **pages_in, | 71 | struct page **pages_in, |
77 | u64 disk_start, | 72 | u64 disk_start, |
78 | struct bio_vec *bvec, | 73 | struct bio *orig_bio, |
79 | int vcnt, | ||
80 | size_t srclen); | 74 | size_t srclen); |
81 | 75 | ||
82 | int (*decompress)(struct list_head *workspace, | 76 | int (*decompress)(struct list_head *workspace, |
diff --git a/fs/btrfs/ctree.c b/fs/btrfs/ctree.c index f6ba165d3f81..25286a5912fc 100644 --- a/fs/btrfs/ctree.c +++ b/fs/btrfs/ctree.c | |||
@@ -260,7 +260,7 @@ int btrfs_copy_root(struct btrfs_trans_handle *trans, | |||
260 | if (IS_ERR(cow)) | 260 | if (IS_ERR(cow)) |
261 | return PTR_ERR(cow); | 261 | return PTR_ERR(cow); |
262 | 262 | ||
263 | copy_extent_buffer(cow, buf, 0, 0, cow->len); | 263 | copy_extent_buffer_full(cow, buf); |
264 | btrfs_set_header_bytenr(cow, cow->start); | 264 | btrfs_set_header_bytenr(cow, cow->start); |
265 | btrfs_set_header_generation(cow, trans->transid); | 265 | btrfs_set_header_generation(cow, trans->transid); |
266 | btrfs_set_header_backref_rev(cow, BTRFS_MIXED_BACKREF_REV); | 266 | btrfs_set_header_backref_rev(cow, BTRFS_MIXED_BACKREF_REV); |
@@ -271,8 +271,7 @@ int btrfs_copy_root(struct btrfs_trans_handle *trans, | |||
271 | else | 271 | else |
272 | btrfs_set_header_owner(cow, new_root_objectid); | 272 | btrfs_set_header_owner(cow, new_root_objectid); |
273 | 273 | ||
274 | write_extent_buffer(cow, root->fs_info->fsid, btrfs_header_fsid(), | 274 | write_extent_buffer_fsid(cow, root->fs_info->fsid); |
275 | BTRFS_FSID_SIZE); | ||
276 | 275 | ||
277 | WARN_ON(btrfs_header_generation(buf) > trans->transid); | 276 | WARN_ON(btrfs_header_generation(buf) > trans->transid); |
278 | if (new_root_objectid == BTRFS_TREE_RELOC_OBJECTID) | 277 | if (new_root_objectid == BTRFS_TREE_RELOC_OBJECTID) |
@@ -1130,7 +1129,7 @@ static noinline int __btrfs_cow_block(struct btrfs_trans_handle *trans, | |||
1130 | 1129 | ||
1131 | /* cow is set to blocking by btrfs_init_new_buffer */ | 1130 | /* cow is set to blocking by btrfs_init_new_buffer */ |
1132 | 1131 | ||
1133 | copy_extent_buffer(cow, buf, 0, 0, cow->len); | 1132 | copy_extent_buffer_full(cow, buf); |
1134 | btrfs_set_header_bytenr(cow, cow->start); | 1133 | btrfs_set_header_bytenr(cow, cow->start); |
1135 | btrfs_set_header_generation(cow, trans->transid); | 1134 | btrfs_set_header_generation(cow, trans->transid); |
1136 | btrfs_set_header_backref_rev(cow, BTRFS_MIXED_BACKREF_REV); | 1135 | btrfs_set_header_backref_rev(cow, BTRFS_MIXED_BACKREF_REV); |
@@ -1141,8 +1140,7 @@ static noinline int __btrfs_cow_block(struct btrfs_trans_handle *trans, | |||
1141 | else | 1140 | else |
1142 | btrfs_set_header_owner(cow, root->root_key.objectid); | 1141 | btrfs_set_header_owner(cow, root->root_key.objectid); |
1143 | 1142 | ||
1144 | write_extent_buffer(cow, root->fs_info->fsid, btrfs_header_fsid(), | 1143 | write_extent_buffer_fsid(cow, root->fs_info->fsid); |
1145 | BTRFS_FSID_SIZE); | ||
1146 | 1144 | ||
1147 | ret = update_ref_for_cow(trans, root, buf, cow, &last_ref); | 1145 | ret = update_ref_for_cow(trans, root, buf, cow, &last_ref); |
1148 | if (ret) { | 1146 | if (ret) { |
@@ -1670,7 +1668,7 @@ int btrfs_realloc_node(struct btrfs_trans_handle *trans, | |||
1670 | continue; | 1668 | continue; |
1671 | } | 1669 | } |
1672 | 1670 | ||
1673 | cur = btrfs_find_tree_block(root->fs_info, blocknr); | 1671 | cur = find_extent_buffer(root->fs_info, blocknr); |
1674 | if (cur) | 1672 | if (cur) |
1675 | uptodate = btrfs_buffer_uptodate(cur, gen, 0); | 1673 | uptodate = btrfs_buffer_uptodate(cur, gen, 0); |
1676 | else | 1674 | else |
@@ -2255,7 +2253,7 @@ static void reada_for_search(struct btrfs_root *root, | |||
2255 | 2253 | ||
2256 | search = btrfs_node_blockptr(node, slot); | 2254 | search = btrfs_node_blockptr(node, slot); |
2257 | blocksize = root->nodesize; | 2255 | blocksize = root->nodesize; |
2258 | eb = btrfs_find_tree_block(root->fs_info, search); | 2256 | eb = find_extent_buffer(root->fs_info, search); |
2259 | if (eb) { | 2257 | if (eb) { |
2260 | free_extent_buffer(eb); | 2258 | free_extent_buffer(eb); |
2261 | return; | 2259 | return; |
@@ -2314,7 +2312,7 @@ static noinline void reada_for_balance(struct btrfs_root *root, | |||
2314 | if (slot > 0) { | 2312 | if (slot > 0) { |
2315 | block1 = btrfs_node_blockptr(parent, slot - 1); | 2313 | block1 = btrfs_node_blockptr(parent, slot - 1); |
2316 | gen = btrfs_node_ptr_generation(parent, slot - 1); | 2314 | gen = btrfs_node_ptr_generation(parent, slot - 1); |
2317 | eb = btrfs_find_tree_block(root->fs_info, block1); | 2315 | eb = find_extent_buffer(root->fs_info, block1); |
2318 | /* | 2316 | /* |
2319 | * if we get -eagain from btrfs_buffer_uptodate, we | 2317 | * if we get -eagain from btrfs_buffer_uptodate, we |
2320 | * don't want to return eagain here. That will loop | 2318 | * don't want to return eagain here. That will loop |
@@ -2327,7 +2325,7 @@ static noinline void reada_for_balance(struct btrfs_root *root, | |||
2327 | if (slot + 1 < nritems) { | 2325 | if (slot + 1 < nritems) { |
2328 | block2 = btrfs_node_blockptr(parent, slot + 1); | 2326 | block2 = btrfs_node_blockptr(parent, slot + 1); |
2329 | gen = btrfs_node_ptr_generation(parent, slot + 1); | 2327 | gen = btrfs_node_ptr_generation(parent, slot + 1); |
2330 | eb = btrfs_find_tree_block(root->fs_info, block2); | 2328 | eb = find_extent_buffer(root->fs_info, block2); |
2331 | if (eb && btrfs_buffer_uptodate(eb, gen, 1) != 0) | 2329 | if (eb && btrfs_buffer_uptodate(eb, gen, 1) != 0) |
2332 | block2 = 0; | 2330 | block2 = 0; |
2333 | free_extent_buffer(eb); | 2331 | free_extent_buffer(eb); |
@@ -2445,7 +2443,7 @@ read_block_for_search(struct btrfs_trans_handle *trans, | |||
2445 | blocknr = btrfs_node_blockptr(b, slot); | 2443 | blocknr = btrfs_node_blockptr(b, slot); |
2446 | gen = btrfs_node_ptr_generation(b, slot); | 2444 | gen = btrfs_node_ptr_generation(b, slot); |
2447 | 2445 | ||
2448 | tmp = btrfs_find_tree_block(root->fs_info, blocknr); | 2446 | tmp = find_extent_buffer(root->fs_info, blocknr); |
2449 | if (tmp) { | 2447 | if (tmp) { |
2450 | /* first we do an atomic uptodate check */ | 2448 | /* first we do an atomic uptodate check */ |
2451 | if (btrfs_buffer_uptodate(tmp, gen, 1) > 0) { | 2449 | if (btrfs_buffer_uptodate(tmp, gen, 1) > 0) { |
@@ -3350,7 +3348,7 @@ static noinline int insert_new_root(struct btrfs_trans_handle *trans, | |||
3350 | 3348 | ||
3351 | root_add_used(root, root->nodesize); | 3349 | root_add_used(root, root->nodesize); |
3352 | 3350 | ||
3353 | memset_extent_buffer(c, 0, 0, sizeof(struct btrfs_header)); | 3351 | memzero_extent_buffer(c, 0, sizeof(struct btrfs_header)); |
3354 | btrfs_set_header_nritems(c, 1); | 3352 | btrfs_set_header_nritems(c, 1); |
3355 | btrfs_set_header_level(c, level); | 3353 | btrfs_set_header_level(c, level); |
3356 | btrfs_set_header_bytenr(c, c->start); | 3354 | btrfs_set_header_bytenr(c, c->start); |
@@ -3358,11 +3356,8 @@ static noinline int insert_new_root(struct btrfs_trans_handle *trans, | |||
3358 | btrfs_set_header_backref_rev(c, BTRFS_MIXED_BACKREF_REV); | 3356 | btrfs_set_header_backref_rev(c, BTRFS_MIXED_BACKREF_REV); |
3359 | btrfs_set_header_owner(c, root->root_key.objectid); | 3357 | btrfs_set_header_owner(c, root->root_key.objectid); |
3360 | 3358 | ||
3361 | write_extent_buffer(c, root->fs_info->fsid, btrfs_header_fsid(), | 3359 | write_extent_buffer_fsid(c, root->fs_info->fsid); |
3362 | BTRFS_FSID_SIZE); | 3360 | write_extent_buffer_chunk_tree_uuid(c, root->fs_info->chunk_tree_uuid); |
3363 | |||
3364 | write_extent_buffer(c, root->fs_info->chunk_tree_uuid, | ||
3365 | btrfs_header_chunk_tree_uuid(c), BTRFS_UUID_SIZE); | ||
3366 | 3361 | ||
3367 | btrfs_set_node_key(c, &lower_key, 0); | 3362 | btrfs_set_node_key(c, &lower_key, 0); |
3368 | btrfs_set_node_blockptr(c, 0, lower->start); | 3363 | btrfs_set_node_blockptr(c, 0, lower->start); |
@@ -3489,17 +3484,15 @@ static noinline int split_node(struct btrfs_trans_handle *trans, | |||
3489 | 3484 | ||
3490 | root_add_used(root, root->nodesize); | 3485 | root_add_used(root, root->nodesize); |
3491 | 3486 | ||
3492 | memset_extent_buffer(split, 0, 0, sizeof(struct btrfs_header)); | 3487 | memzero_extent_buffer(split, 0, sizeof(struct btrfs_header)); |
3493 | btrfs_set_header_level(split, btrfs_header_level(c)); | 3488 | btrfs_set_header_level(split, btrfs_header_level(c)); |
3494 | btrfs_set_header_bytenr(split, split->start); | 3489 | btrfs_set_header_bytenr(split, split->start); |
3495 | btrfs_set_header_generation(split, trans->transid); | 3490 | btrfs_set_header_generation(split, trans->transid); |
3496 | btrfs_set_header_backref_rev(split, BTRFS_MIXED_BACKREF_REV); | 3491 | btrfs_set_header_backref_rev(split, BTRFS_MIXED_BACKREF_REV); |
3497 | btrfs_set_header_owner(split, root->root_key.objectid); | 3492 | btrfs_set_header_owner(split, root->root_key.objectid); |
3498 | write_extent_buffer(split, root->fs_info->fsid, | 3493 | write_extent_buffer_fsid(split, root->fs_info->fsid); |
3499 | btrfs_header_fsid(), BTRFS_FSID_SIZE); | 3494 | write_extent_buffer_chunk_tree_uuid(split, |
3500 | write_extent_buffer(split, root->fs_info->chunk_tree_uuid, | 3495 | root->fs_info->chunk_tree_uuid); |
3501 | btrfs_header_chunk_tree_uuid(split), | ||
3502 | BTRFS_UUID_SIZE); | ||
3503 | 3496 | ||
3504 | ret = tree_mod_log_eb_copy(root->fs_info, split, c, 0, | 3497 | ret = tree_mod_log_eb_copy(root->fs_info, split, c, 0, |
3505 | mid, c_nritems - mid); | 3498 | mid, c_nritems - mid); |
@@ -4277,18 +4270,14 @@ again: | |||
4277 | 4270 | ||
4278 | root_add_used(root, root->nodesize); | 4271 | root_add_used(root, root->nodesize); |
4279 | 4272 | ||
4280 | memset_extent_buffer(right, 0, 0, sizeof(struct btrfs_header)); | 4273 | memzero_extent_buffer(right, 0, sizeof(struct btrfs_header)); |
4281 | btrfs_set_header_bytenr(right, right->start); | 4274 | btrfs_set_header_bytenr(right, right->start); |
4282 | btrfs_set_header_generation(right, trans->transid); | 4275 | btrfs_set_header_generation(right, trans->transid); |
4283 | btrfs_set_header_backref_rev(right, BTRFS_MIXED_BACKREF_REV); | 4276 | btrfs_set_header_backref_rev(right, BTRFS_MIXED_BACKREF_REV); |
4284 | btrfs_set_header_owner(right, root->root_key.objectid); | 4277 | btrfs_set_header_owner(right, root->root_key.objectid); |
4285 | btrfs_set_header_level(right, 0); | 4278 | btrfs_set_header_level(right, 0); |
4286 | write_extent_buffer(right, fs_info->fsid, | 4279 | write_extent_buffer_fsid(right, fs_info->fsid); |
4287 | btrfs_header_fsid(), BTRFS_FSID_SIZE); | 4280 | write_extent_buffer_chunk_tree_uuid(right, fs_info->chunk_tree_uuid); |
4288 | |||
4289 | write_extent_buffer(right, fs_info->chunk_tree_uuid, | ||
4290 | btrfs_header_chunk_tree_uuid(right), | ||
4291 | BTRFS_UUID_SIZE); | ||
4292 | 4281 | ||
4293 | if (split == 0) { | 4282 | if (split == 0) { |
4294 | if (mid <= slot) { | 4283 | if (mid <= slot) { |
diff --git a/fs/btrfs/ctree.h b/fs/btrfs/ctree.h index 0b8ce2b9f7d0..1b25a460ecea 100644 --- a/fs/btrfs/ctree.h +++ b/fs/btrfs/ctree.h | |||
@@ -90,9 +90,6 @@ static const int btrfs_csum_sizes[] = { 4 }; | |||
90 | /* four bytes for CRC32 */ | 90 | /* four bytes for CRC32 */ |
91 | #define BTRFS_EMPTY_DIR_SIZE 0 | 91 | #define BTRFS_EMPTY_DIR_SIZE 0 |
92 | 92 | ||
93 | /* specific to btrfs_map_block(), therefore not in include/linux/blk_types.h */ | ||
94 | #define REQ_GET_READ_MIRRORS (1 << 30) | ||
95 | |||
96 | /* ioprio of readahead is set to idle */ | 93 | /* ioprio of readahead is set to idle */ |
97 | #define BTRFS_IOPRIO_READA (IOPRIO_PRIO_VALUE(IOPRIO_CLASS_IDLE, 0)) | 94 | #define BTRFS_IOPRIO_READA (IOPRIO_PRIO_VALUE(IOPRIO_CLASS_IDLE, 0)) |
98 | 95 | ||
@@ -429,6 +426,10 @@ struct btrfs_space_info { | |||
429 | struct list_head ro_bgs; | 426 | struct list_head ro_bgs; |
430 | struct list_head priority_tickets; | 427 | struct list_head priority_tickets; |
431 | struct list_head tickets; | 428 | struct list_head tickets; |
429 | /* | ||
430 | * tickets_id just indicates the next ticket will be handled, so note | ||
431 | * it's not stored per ticket. | ||
432 | */ | ||
432 | u64 tickets_id; | 433 | u64 tickets_id; |
433 | 434 | ||
434 | struct rw_semaphore groups_sem; | 435 | struct rw_semaphore groups_sem; |
@@ -798,7 +799,6 @@ struct btrfs_fs_info { | |||
798 | spinlock_t super_lock; | 799 | spinlock_t super_lock; |
799 | struct btrfs_super_block *super_copy; | 800 | struct btrfs_super_block *super_copy; |
800 | struct btrfs_super_block *super_for_commit; | 801 | struct btrfs_super_block *super_for_commit; |
801 | struct block_device *__bdev; | ||
802 | struct super_block *sb; | 802 | struct super_block *sb; |
803 | struct inode *btree_inode; | 803 | struct inode *btree_inode; |
804 | struct backing_dev_info bdi; | 804 | struct backing_dev_info bdi; |
@@ -2210,6 +2210,8 @@ btrfs_disk_balance_args_to_cpu(struct btrfs_balance_args *cpu, | |||
2210 | cpu->target = le64_to_cpu(disk->target); | 2210 | cpu->target = le64_to_cpu(disk->target); |
2211 | cpu->flags = le64_to_cpu(disk->flags); | 2211 | cpu->flags = le64_to_cpu(disk->flags); |
2212 | cpu->limit = le64_to_cpu(disk->limit); | 2212 | cpu->limit = le64_to_cpu(disk->limit); |
2213 | cpu->stripes_min = le32_to_cpu(disk->stripes_min); | ||
2214 | cpu->stripes_max = le32_to_cpu(disk->stripes_max); | ||
2213 | } | 2215 | } |
2214 | 2216 | ||
2215 | static inline void | 2217 | static inline void |
@@ -2228,6 +2230,8 @@ btrfs_cpu_balance_args_to_disk(struct btrfs_disk_balance_args *disk, | |||
2228 | disk->target = cpu_to_le64(cpu->target); | 2230 | disk->target = cpu_to_le64(cpu->target); |
2229 | disk->flags = cpu_to_le64(cpu->flags); | 2231 | disk->flags = cpu_to_le64(cpu->flags); |
2230 | disk->limit = cpu_to_le64(cpu->limit); | 2232 | disk->limit = cpu_to_le64(cpu->limit); |
2233 | disk->stripes_min = cpu_to_le32(cpu->stripes_min); | ||
2234 | disk->stripes_max = cpu_to_le32(cpu->stripes_max); | ||
2231 | } | 2235 | } |
2232 | 2236 | ||
2233 | /* struct btrfs_super_block */ | 2237 | /* struct btrfs_super_block */ |
@@ -3660,7 +3664,7 @@ struct reada_control *btrfs_reada_add(struct btrfs_root *root, | |||
3660 | int btrfs_reada_wait(void *handle); | 3664 | int btrfs_reada_wait(void *handle); |
3661 | void btrfs_reada_detach(void *handle); | 3665 | void btrfs_reada_detach(void *handle); |
3662 | int btree_readahead_hook(struct btrfs_fs_info *fs_info, | 3666 | int btree_readahead_hook(struct btrfs_fs_info *fs_info, |
3663 | struct extent_buffer *eb, u64 start, int err); | 3667 | struct extent_buffer *eb, int err); |
3664 | 3668 | ||
3665 | static inline int is_fstree(u64 rootid) | 3669 | static inline int is_fstree(u64 rootid) |
3666 | { | 3670 | { |
diff --git a/fs/btrfs/delayed-inode.c b/fs/btrfs/delayed-inode.c index 0fcf5f25d524..d90d4446f9fe 100644 --- a/fs/btrfs/delayed-inode.c +++ b/fs/btrfs/delayed-inode.c | |||
@@ -1686,7 +1686,7 @@ int btrfs_should_delete_dir_index(struct list_head *del_list, | |||
1686 | * | 1686 | * |
1687 | */ | 1687 | */ |
1688 | int btrfs_readdir_delayed_dir_index(struct dir_context *ctx, | 1688 | int btrfs_readdir_delayed_dir_index(struct dir_context *ctx, |
1689 | struct list_head *ins_list, bool *emitted) | 1689 | struct list_head *ins_list) |
1690 | { | 1690 | { |
1691 | struct btrfs_dir_item *di; | 1691 | struct btrfs_dir_item *di; |
1692 | struct btrfs_delayed_item *curr, *next; | 1692 | struct btrfs_delayed_item *curr, *next; |
@@ -1730,7 +1730,6 @@ int btrfs_readdir_delayed_dir_index(struct dir_context *ctx, | |||
1730 | 1730 | ||
1731 | if (over) | 1731 | if (over) |
1732 | return 1; | 1732 | return 1; |
1733 | *emitted = true; | ||
1734 | } | 1733 | } |
1735 | return 0; | 1734 | return 0; |
1736 | } | 1735 | } |
diff --git a/fs/btrfs/delayed-inode.h b/fs/btrfs/delayed-inode.h index 2495b3d4075f..2c1cbe245104 100644 --- a/fs/btrfs/delayed-inode.h +++ b/fs/btrfs/delayed-inode.h | |||
@@ -146,7 +146,7 @@ void btrfs_readdir_put_delayed_items(struct inode *inode, | |||
146 | int btrfs_should_delete_dir_index(struct list_head *del_list, | 146 | int btrfs_should_delete_dir_index(struct list_head *del_list, |
147 | u64 index); | 147 | u64 index); |
148 | int btrfs_readdir_delayed_dir_index(struct dir_context *ctx, | 148 | int btrfs_readdir_delayed_dir_index(struct dir_context *ctx, |
149 | struct list_head *ins_list, bool *emitted); | 149 | struct list_head *ins_list); |
150 | 150 | ||
151 | /* for init */ | 151 | /* for init */ |
152 | int __init btrfs_delayed_inode_init(void); | 152 | int __init btrfs_delayed_inode_init(void); |
diff --git a/fs/btrfs/delayed-ref.c b/fs/btrfs/delayed-ref.c index 8d93854a4b4f..ef724a5fc30e 100644 --- a/fs/btrfs/delayed-ref.c +++ b/fs/btrfs/delayed-ref.c | |||
@@ -189,6 +189,8 @@ static inline void drop_delayed_ref(struct btrfs_trans_handle *trans, | |||
189 | } else { | 189 | } else { |
190 | assert_spin_locked(&head->lock); | 190 | assert_spin_locked(&head->lock); |
191 | list_del(&ref->list); | 191 | list_del(&ref->list); |
192 | if (!list_empty(&ref->add_list)) | ||
193 | list_del(&ref->add_list); | ||
192 | } | 194 | } |
193 | ref->in_tree = 0; | 195 | ref->in_tree = 0; |
194 | btrfs_put_delayed_ref(ref); | 196 | btrfs_put_delayed_ref(ref); |
@@ -431,6 +433,15 @@ add_delayed_ref_tail_merge(struct btrfs_trans_handle *trans, | |||
431 | exist->action = ref->action; | 433 | exist->action = ref->action; |
432 | mod = -exist->ref_mod; | 434 | mod = -exist->ref_mod; |
433 | exist->ref_mod = ref->ref_mod; | 435 | exist->ref_mod = ref->ref_mod; |
436 | if (ref->action == BTRFS_ADD_DELAYED_REF) | ||
437 | list_add_tail(&exist->add_list, | ||
438 | &href->ref_add_list); | ||
439 | else if (ref->action == BTRFS_DROP_DELAYED_REF) { | ||
440 | ASSERT(!list_empty(&exist->add_list)); | ||
441 | list_del(&exist->add_list); | ||
442 | } else { | ||
443 | ASSERT(0); | ||
444 | } | ||
434 | } else | 445 | } else |
435 | mod = -ref->ref_mod; | 446 | mod = -ref->ref_mod; |
436 | } | 447 | } |
@@ -444,6 +455,8 @@ add_delayed_ref_tail_merge(struct btrfs_trans_handle *trans, | |||
444 | 455 | ||
445 | add_tail: | 456 | add_tail: |
446 | list_add_tail(&ref->list, &href->ref_list); | 457 | list_add_tail(&ref->list, &href->ref_list); |
458 | if (ref->action == BTRFS_ADD_DELAYED_REF) | ||
459 | list_add_tail(&ref->add_list, &href->ref_add_list); | ||
447 | atomic_inc(&root->num_entries); | 460 | atomic_inc(&root->num_entries); |
448 | trans->delayed_ref_updates++; | 461 | trans->delayed_ref_updates++; |
449 | spin_unlock(&href->lock); | 462 | spin_unlock(&href->lock); |
@@ -590,6 +603,7 @@ add_delayed_ref_head(struct btrfs_fs_info *fs_info, | |||
590 | head_ref->must_insert_reserved = must_insert_reserved; | 603 | head_ref->must_insert_reserved = must_insert_reserved; |
591 | head_ref->is_data = is_data; | 604 | head_ref->is_data = is_data; |
592 | INIT_LIST_HEAD(&head_ref->ref_list); | 605 | INIT_LIST_HEAD(&head_ref->ref_list); |
606 | INIT_LIST_HEAD(&head_ref->ref_add_list); | ||
593 | head_ref->processing = 0; | 607 | head_ref->processing = 0; |
594 | head_ref->total_ref_mod = count_mod; | 608 | head_ref->total_ref_mod = count_mod; |
595 | head_ref->qgroup_reserved = 0; | 609 | head_ref->qgroup_reserved = 0; |
@@ -606,7 +620,7 @@ add_delayed_ref_head(struct btrfs_fs_info *fs_info, | |||
606 | qrecord->num_bytes = num_bytes; | 620 | qrecord->num_bytes = num_bytes; |
607 | qrecord->old_roots = NULL; | 621 | qrecord->old_roots = NULL; |
608 | 622 | ||
609 | if(btrfs_qgroup_insert_dirty_extent_nolock(fs_info, | 623 | if(btrfs_qgroup_trace_extent_nolock(fs_info, |
610 | delayed_refs, qrecord)) | 624 | delayed_refs, qrecord)) |
611 | kfree(qrecord); | 625 | kfree(qrecord); |
612 | } | 626 | } |
@@ -671,6 +685,8 @@ add_delayed_tree_ref(struct btrfs_fs_info *fs_info, | |||
671 | ref->is_head = 0; | 685 | ref->is_head = 0; |
672 | ref->in_tree = 1; | 686 | ref->in_tree = 1; |
673 | ref->seq = seq; | 687 | ref->seq = seq; |
688 | INIT_LIST_HEAD(&ref->list); | ||
689 | INIT_LIST_HEAD(&ref->add_list); | ||
674 | 690 | ||
675 | full_ref = btrfs_delayed_node_to_tree_ref(ref); | 691 | full_ref = btrfs_delayed_node_to_tree_ref(ref); |
676 | full_ref->parent = parent; | 692 | full_ref->parent = parent; |
@@ -726,6 +742,8 @@ add_delayed_data_ref(struct btrfs_fs_info *fs_info, | |||
726 | ref->is_head = 0; | 742 | ref->is_head = 0; |
727 | ref->in_tree = 1; | 743 | ref->in_tree = 1; |
728 | ref->seq = seq; | 744 | ref->seq = seq; |
745 | INIT_LIST_HEAD(&ref->list); | ||
746 | INIT_LIST_HEAD(&ref->add_list); | ||
729 | 747 | ||
730 | full_ref = btrfs_delayed_node_to_data_ref(ref); | 748 | full_ref = btrfs_delayed_node_to_data_ref(ref); |
731 | full_ref->parent = parent; | 749 | full_ref->parent = parent; |
diff --git a/fs/btrfs/delayed-ref.h b/fs/btrfs/delayed-ref.h index 43f3629760e9..dba97842b47a 100644 --- a/fs/btrfs/delayed-ref.h +++ b/fs/btrfs/delayed-ref.h | |||
@@ -42,6 +42,12 @@ struct btrfs_delayed_ref_node { | |||
42 | 42 | ||
43 | /*data/tree ref use list, stored in ref_head->ref_list. */ | 43 | /*data/tree ref use list, stored in ref_head->ref_list. */ |
44 | struct list_head list; | 44 | struct list_head list; |
45 | /* | ||
46 | * If action is BTRFS_ADD_DELAYED_REF, also link this node to | ||
47 | * ref_head->ref_add_list, then we do not need to iterate the | ||
48 | * whole ref_head->ref_list to find BTRFS_ADD_DELAYED_REF nodes. | ||
49 | */ | ||
50 | struct list_head add_list; | ||
45 | 51 | ||
46 | /* the starting bytenr of the extent */ | 52 | /* the starting bytenr of the extent */ |
47 | u64 bytenr; | 53 | u64 bytenr; |
@@ -99,6 +105,8 @@ struct btrfs_delayed_ref_head { | |||
99 | 105 | ||
100 | spinlock_t lock; | 106 | spinlock_t lock; |
101 | struct list_head ref_list; | 107 | struct list_head ref_list; |
108 | /* accumulate add BTRFS_ADD_DELAYED_REF nodes to this ref_add_list. */ | ||
109 | struct list_head ref_add_list; | ||
102 | 110 | ||
103 | struct rb_node href_node; | 111 | struct rb_node href_node; |
104 | 112 | ||
diff --git a/fs/btrfs/disk-io.c b/fs/btrfs/disk-io.c index 3a57f99d96aa..811662cce977 100644 --- a/fs/btrfs/disk-io.c +++ b/fs/btrfs/disk-io.c | |||
@@ -271,7 +271,7 @@ u32 btrfs_csum_data(char *data, u32 seed, size_t len) | |||
271 | return btrfs_crc32c(seed, data, len); | 271 | return btrfs_crc32c(seed, data, len); |
272 | } | 272 | } |
273 | 273 | ||
274 | void btrfs_csum_final(u32 crc, char *result) | 274 | void btrfs_csum_final(u32 crc, u8 *result) |
275 | { | 275 | { |
276 | put_unaligned_le32(~crc, result); | 276 | put_unaligned_le32(~crc, result); |
277 | } | 277 | } |
@@ -747,7 +747,7 @@ static int btree_readpage_end_io_hook(struct btrfs_io_bio *io_bio, | |||
747 | err: | 747 | err: |
748 | if (reads_done && | 748 | if (reads_done && |
749 | test_and_clear_bit(EXTENT_BUFFER_READAHEAD, &eb->bflags)) | 749 | test_and_clear_bit(EXTENT_BUFFER_READAHEAD, &eb->bflags)) |
750 | btree_readahead_hook(fs_info, eb, eb->start, ret); | 750 | btree_readahead_hook(fs_info, eb, ret); |
751 | 751 | ||
752 | if (ret) { | 752 | if (ret) { |
753 | /* | 753 | /* |
@@ -772,7 +772,7 @@ static int btree_io_failed_hook(struct page *page, int failed_mirror) | |||
772 | eb->read_mirror = failed_mirror; | 772 | eb->read_mirror = failed_mirror; |
773 | atomic_dec(&eb->io_pages); | 773 | atomic_dec(&eb->io_pages); |
774 | if (test_and_clear_bit(EXTENT_BUFFER_READAHEAD, &eb->bflags)) | 774 | if (test_and_clear_bit(EXTENT_BUFFER_READAHEAD, &eb->bflags)) |
775 | btree_readahead_hook(eb->fs_info, eb, eb->start, -EIO); | 775 | btree_readahead_hook(eb->fs_info, eb, -EIO); |
776 | return -EIO; /* we fixed nothing */ | 776 | return -EIO; /* we fixed nothing */ |
777 | } | 777 | } |
778 | 778 | ||
@@ -1191,12 +1191,6 @@ int reada_tree_block_flagged(struct btrfs_root *root, u64 bytenr, | |||
1191 | return 0; | 1191 | return 0; |
1192 | } | 1192 | } |
1193 | 1193 | ||
1194 | struct extent_buffer *btrfs_find_tree_block(struct btrfs_fs_info *fs_info, | ||
1195 | u64 bytenr) | ||
1196 | { | ||
1197 | return find_extent_buffer(fs_info, bytenr); | ||
1198 | } | ||
1199 | |||
1200 | struct extent_buffer *btrfs_find_create_tree_block(struct btrfs_root *root, | 1194 | struct extent_buffer *btrfs_find_create_tree_block(struct btrfs_root *root, |
1201 | u64 bytenr) | 1195 | u64 bytenr) |
1202 | { | 1196 | { |
@@ -1418,18 +1412,15 @@ struct btrfs_root *btrfs_create_tree(struct btrfs_trans_handle *trans, | |||
1418 | goto fail; | 1412 | goto fail; |
1419 | } | 1413 | } |
1420 | 1414 | ||
1421 | memset_extent_buffer(leaf, 0, 0, sizeof(struct btrfs_header)); | 1415 | memzero_extent_buffer(leaf, 0, sizeof(struct btrfs_header)); |
1422 | btrfs_set_header_bytenr(leaf, leaf->start); | 1416 | btrfs_set_header_bytenr(leaf, leaf->start); |
1423 | btrfs_set_header_generation(leaf, trans->transid); | 1417 | btrfs_set_header_generation(leaf, trans->transid); |
1424 | btrfs_set_header_backref_rev(leaf, BTRFS_MIXED_BACKREF_REV); | 1418 | btrfs_set_header_backref_rev(leaf, BTRFS_MIXED_BACKREF_REV); |
1425 | btrfs_set_header_owner(leaf, objectid); | 1419 | btrfs_set_header_owner(leaf, objectid); |
1426 | root->node = leaf; | 1420 | root->node = leaf; |
1427 | 1421 | ||
1428 | write_extent_buffer(leaf, fs_info->fsid, btrfs_header_fsid(), | 1422 | write_extent_buffer_fsid(leaf, fs_info->fsid); |
1429 | BTRFS_FSID_SIZE); | 1423 | write_extent_buffer_chunk_tree_uuid(leaf, fs_info->chunk_tree_uuid); |
1430 | write_extent_buffer(leaf, fs_info->chunk_tree_uuid, | ||
1431 | btrfs_header_chunk_tree_uuid(leaf), | ||
1432 | BTRFS_UUID_SIZE); | ||
1433 | btrfs_mark_buffer_dirty(leaf); | 1424 | btrfs_mark_buffer_dirty(leaf); |
1434 | 1425 | ||
1435 | root->commit_root = btrfs_root_node(root); | 1426 | root->commit_root = btrfs_root_node(root); |
@@ -1505,15 +1496,14 @@ static struct btrfs_root *alloc_log_tree(struct btrfs_trans_handle *trans, | |||
1505 | return ERR_CAST(leaf); | 1496 | return ERR_CAST(leaf); |
1506 | } | 1497 | } |
1507 | 1498 | ||
1508 | memset_extent_buffer(leaf, 0, 0, sizeof(struct btrfs_header)); | 1499 | memzero_extent_buffer(leaf, 0, sizeof(struct btrfs_header)); |
1509 | btrfs_set_header_bytenr(leaf, leaf->start); | 1500 | btrfs_set_header_bytenr(leaf, leaf->start); |
1510 | btrfs_set_header_generation(leaf, trans->transid); | 1501 | btrfs_set_header_generation(leaf, trans->transid); |
1511 | btrfs_set_header_backref_rev(leaf, BTRFS_MIXED_BACKREF_REV); | 1502 | btrfs_set_header_backref_rev(leaf, BTRFS_MIXED_BACKREF_REV); |
1512 | btrfs_set_header_owner(leaf, BTRFS_TREE_LOG_OBJECTID); | 1503 | btrfs_set_header_owner(leaf, BTRFS_TREE_LOG_OBJECTID); |
1513 | root->node = leaf; | 1504 | root->node = leaf; |
1514 | 1505 | ||
1515 | write_extent_buffer(root->node, root->fs_info->fsid, | 1506 | write_extent_buffer_fsid(root->node, root->fs_info->fsid); |
1516 | btrfs_header_fsid(), BTRFS_FSID_SIZE); | ||
1517 | btrfs_mark_buffer_dirty(root->node); | 1507 | btrfs_mark_buffer_dirty(root->node); |
1518 | btrfs_tree_unlock(root->node); | 1508 | btrfs_tree_unlock(root->node); |
1519 | return root; | 1509 | return root; |
@@ -4354,6 +4344,8 @@ static int btrfs_destroy_delayed_refs(struct btrfs_transaction *trans, | |||
4354 | list) { | 4344 | list) { |
4355 | ref->in_tree = 0; | 4345 | ref->in_tree = 0; |
4356 | list_del(&ref->list); | 4346 | list_del(&ref->list); |
4347 | if (!list_empty(&ref->add_list)) | ||
4348 | list_del(&ref->add_list); | ||
4357 | atomic_dec(&delayed_refs->num_entries); | 4349 | atomic_dec(&delayed_refs->num_entries); |
4358 | btrfs_put_delayed_ref(ref); | 4350 | btrfs_put_delayed_ref(ref); |
4359 | } | 4351 | } |
@@ -4452,7 +4444,7 @@ static int btrfs_destroy_marked_extents(struct btrfs_root *root, | |||
4452 | 4444 | ||
4453 | clear_extent_bits(dirty_pages, start, end, mark); | 4445 | clear_extent_bits(dirty_pages, start, end, mark); |
4454 | while (start <= end) { | 4446 | while (start <= end) { |
4455 | eb = btrfs_find_tree_block(root->fs_info, start); | 4447 | eb = find_extent_buffer(root->fs_info, start); |
4456 | start += root->nodesize; | 4448 | start += root->nodesize; |
4457 | if (!eb) | 4449 | if (!eb) |
4458 | continue; | 4450 | continue; |
diff --git a/fs/btrfs/disk-io.h b/fs/btrfs/disk-io.h index 1a3237e5700f..729540701458 100644 --- a/fs/btrfs/disk-io.h +++ b/fs/btrfs/disk-io.h | |||
@@ -63,8 +63,6 @@ struct buffer_head *btrfs_read_dev_super(struct block_device *bdev); | |||
63 | int btrfs_read_dev_one_super(struct block_device *bdev, int copy_num, | 63 | int btrfs_read_dev_one_super(struct block_device *bdev, int copy_num, |
64 | struct buffer_head **bh_ret); | 64 | struct buffer_head **bh_ret); |
65 | int btrfs_commit_super(struct btrfs_root *root); | 65 | int btrfs_commit_super(struct btrfs_root *root); |
66 | struct extent_buffer *btrfs_find_tree_block(struct btrfs_fs_info *fs_info, | ||
67 | u64 bytenr); | ||
68 | struct btrfs_root *btrfs_read_fs_root(struct btrfs_root *tree_root, | 66 | struct btrfs_root *btrfs_read_fs_root(struct btrfs_root *tree_root, |
69 | struct btrfs_key *location); | 67 | struct btrfs_key *location); |
70 | int btrfs_init_fs_root(struct btrfs_root *root); | 68 | int btrfs_init_fs_root(struct btrfs_root *root); |
@@ -121,7 +119,7 @@ int btrfs_buffer_uptodate(struct extent_buffer *buf, u64 parent_transid, | |||
121 | int atomic); | 119 | int atomic); |
122 | int btrfs_read_buffer(struct extent_buffer *buf, u64 parent_transid); | 120 | int btrfs_read_buffer(struct extent_buffer *buf, u64 parent_transid); |
123 | u32 btrfs_csum_data(char *data, u32 seed, size_t len); | 121 | u32 btrfs_csum_data(char *data, u32 seed, size_t len); |
124 | void btrfs_csum_final(u32 crc, char *result); | 122 | void btrfs_csum_final(u32 crc, u8 *result); |
125 | int btrfs_bio_wq_end_io(struct btrfs_fs_info *info, struct bio *bio, | 123 | int btrfs_bio_wq_end_io(struct btrfs_fs_info *info, struct bio *bio, |
126 | enum btrfs_wq_endio_type metadata); | 124 | enum btrfs_wq_endio_type metadata); |
127 | int btrfs_wq_submit_bio(struct btrfs_fs_info *fs_info, struct inode *inode, | 125 | int btrfs_wq_submit_bio(struct btrfs_fs_info *fs_info, struct inode *inode, |
diff --git a/fs/btrfs/extent-tree.c b/fs/btrfs/extent-tree.c index 4607af38c72e..0d80136206b1 100644 --- a/fs/btrfs/extent-tree.c +++ b/fs/btrfs/extent-tree.c | |||
@@ -1114,7 +1114,7 @@ static int convert_extent_item_v0(struct btrfs_trans_handle *trans, | |||
1114 | BTRFS_BLOCK_FLAG_FULL_BACKREF); | 1114 | BTRFS_BLOCK_FLAG_FULL_BACKREF); |
1115 | bi = (struct btrfs_tree_block_info *)(item + 1); | 1115 | bi = (struct btrfs_tree_block_info *)(item + 1); |
1116 | /* FIXME: get first key of the block */ | 1116 | /* FIXME: get first key of the block */ |
1117 | memset_extent_buffer(leaf, 0, (unsigned long)bi, sizeof(*bi)); | 1117 | memzero_extent_buffer(leaf, (unsigned long)bi, sizeof(*bi)); |
1118 | btrfs_set_tree_block_level(leaf, bi, (int)owner); | 1118 | btrfs_set_tree_block_level(leaf, bi, (int)owner); |
1119 | } else { | 1119 | } else { |
1120 | btrfs_set_extent_flags(leaf, item, BTRFS_EXTENT_FLAG_DATA); | 1120 | btrfs_set_extent_flags(leaf, item, BTRFS_EXTENT_FLAG_DATA); |
@@ -2036,7 +2036,7 @@ int btrfs_discard_extent(struct btrfs_root *root, u64 bytenr, | |||
2036 | */ | 2036 | */ |
2037 | btrfs_bio_counter_inc_blocked(root->fs_info); | 2037 | btrfs_bio_counter_inc_blocked(root->fs_info); |
2038 | /* Tell the block device(s) that the sectors can be discarded */ | 2038 | /* Tell the block device(s) that the sectors can be discarded */ |
2039 | ret = btrfs_map_block(root->fs_info, REQ_OP_DISCARD, | 2039 | ret = btrfs_map_block(root->fs_info, BTRFS_MAP_DISCARD, |
2040 | bytenr, &num_bytes, &bbio, 0); | 2040 | bytenr, &num_bytes, &bbio, 0); |
2041 | /* Error condition is -ENOMEM */ | 2041 | /* Error condition is -ENOMEM */ |
2042 | if (!ret) { | 2042 | if (!ret) { |
@@ -2454,13 +2454,14 @@ select_delayed_ref(struct btrfs_delayed_ref_head *head) | |||
2454 | * the extent item from the extent tree, when there still are references | 2454 | * the extent item from the extent tree, when there still are references |
2455 | * to add, which would fail because they would not find the extent item. | 2455 | * to add, which would fail because they would not find the extent item. |
2456 | */ | 2456 | */ |
2457 | list_for_each_entry(ref, &head->ref_list, list) { | 2457 | if (!list_empty(&head->ref_add_list)) |
2458 | if (ref->action == BTRFS_ADD_DELAYED_REF) | 2458 | return list_first_entry(&head->ref_add_list, |
2459 | return ref; | 2459 | struct btrfs_delayed_ref_node, add_list); |
2460 | } | ||
2461 | 2460 | ||
2462 | return list_entry(head->ref_list.next, struct btrfs_delayed_ref_node, | 2461 | ref = list_first_entry(&head->ref_list, struct btrfs_delayed_ref_node, |
2463 | list); | 2462 | list); |
2463 | ASSERT(list_empty(&ref->add_list)); | ||
2464 | return ref; | ||
2464 | } | 2465 | } |
2465 | 2466 | ||
2466 | /* | 2467 | /* |
@@ -2620,6 +2621,8 @@ static noinline int __btrfs_run_delayed_refs(struct btrfs_trans_handle *trans, | |||
2620 | actual_count++; | 2621 | actual_count++; |
2621 | ref->in_tree = 0; | 2622 | ref->in_tree = 0; |
2622 | list_del(&ref->list); | 2623 | list_del(&ref->list); |
2624 | if (!list_empty(&ref->add_list)) | ||
2625 | list_del(&ref->add_list); | ||
2623 | } | 2626 | } |
2624 | atomic_dec(&delayed_refs->num_entries); | 2627 | atomic_dec(&delayed_refs->num_entries); |
2625 | 2628 | ||
@@ -2826,7 +2829,7 @@ int btrfs_should_throttle_delayed_refs(struct btrfs_trans_handle *trans, | |||
2826 | smp_mb(); | 2829 | smp_mb(); |
2827 | avg_runtime = fs_info->avg_delayed_ref_runtime; | 2830 | avg_runtime = fs_info->avg_delayed_ref_runtime; |
2828 | val = num_entries * avg_runtime; | 2831 | val = num_entries * avg_runtime; |
2829 | if (num_entries * avg_runtime >= NSEC_PER_SEC) | 2832 | if (val >= NSEC_PER_SEC) |
2830 | return 1; | 2833 | return 1; |
2831 | if (val >= NSEC_PER_SEC / 2) | 2834 | if (val >= NSEC_PER_SEC / 2) |
2832 | return 2; | 2835 | return 2; |
@@ -4322,6 +4325,13 @@ void btrfs_free_reserved_data_space_noquota(struct inode *inode, u64 start, | |||
4322 | */ | 4325 | */ |
4323 | void btrfs_free_reserved_data_space(struct inode *inode, u64 start, u64 len) | 4326 | void btrfs_free_reserved_data_space(struct inode *inode, u64 start, u64 len) |
4324 | { | 4327 | { |
4328 | struct btrfs_root *root = BTRFS_I(inode)->root; | ||
4329 | |||
4330 | /* Make sure the range is aligned to sectorsize */ | ||
4331 | len = round_up(start + len, root->sectorsize) - | ||
4332 | round_down(start, root->sectorsize); | ||
4333 | start = round_down(start, root->sectorsize); | ||
4334 | |||
4325 | btrfs_free_reserved_data_space_noquota(inode, start, len); | 4335 | btrfs_free_reserved_data_space_noquota(inode, start, len); |
4326 | btrfs_qgroup_free_data(inode, start, len); | 4336 | btrfs_qgroup_free_data(inode, start, len); |
4327 | } | 4337 | } |
@@ -6499,16 +6509,9 @@ void btrfs_wait_block_group_reservations(struct btrfs_block_group_cache *bg) | |||
6499 | * @num_bytes: The number of bytes in question | 6509 | * @num_bytes: The number of bytes in question |
6500 | * @delalloc: The blocks are allocated for the delalloc write | 6510 | * @delalloc: The blocks are allocated for the delalloc write |
6501 | * | 6511 | * |
6502 | * This is called by the allocator when it reserves space. Metadata | 6512 | * This is called by the allocator when it reserves space. If this is a |
6503 | * reservations should be called with RESERVE_ALLOC so we do the proper | 6513 | * reservation and the block group has become read only we cannot make the |
6504 | * ENOSPC accounting. For data we handle the reservation through clearing the | 6514 | * reservation and return -EAGAIN, otherwise this function always succeeds. |
6505 | * delalloc bits in the io_tree. We have to do this since we could end up | ||
6506 | * allocating less disk space for the amount of data we have reserved in the | ||
6507 | * case of compression. | ||
6508 | * | ||
6509 | * If this is a reservation and the block group has become read only we cannot | ||
6510 | * make the reservation and return -EAGAIN, otherwise this function always | ||
6511 | * succeeds. | ||
6512 | */ | 6515 | */ |
6513 | static int btrfs_add_reserved_bytes(struct btrfs_block_group_cache *cache, | 6516 | static int btrfs_add_reserved_bytes(struct btrfs_block_group_cache *cache, |
6514 | u64 ram_bytes, u64 num_bytes, int delalloc) | 6517 | u64 ram_bytes, u64 num_bytes, int delalloc) |
@@ -8538,220 +8541,6 @@ reada: | |||
8538 | wc->reada_slot = slot; | 8541 | wc->reada_slot = slot; |
8539 | } | 8542 | } |
8540 | 8543 | ||
8541 | static int account_leaf_items(struct btrfs_trans_handle *trans, | ||
8542 | struct btrfs_root *root, | ||
8543 | struct extent_buffer *eb) | ||
8544 | { | ||
8545 | int nr = btrfs_header_nritems(eb); | ||
8546 | int i, extent_type, ret; | ||
8547 | struct btrfs_key key; | ||
8548 | struct btrfs_file_extent_item *fi; | ||
8549 | u64 bytenr, num_bytes; | ||
8550 | |||
8551 | /* We can be called directly from walk_up_proc() */ | ||
8552 | if (!test_bit(BTRFS_FS_QUOTA_ENABLED, &root->fs_info->flags)) | ||
8553 | return 0; | ||
8554 | |||
8555 | for (i = 0; i < nr; i++) { | ||
8556 | btrfs_item_key_to_cpu(eb, &key, i); | ||
8557 | |||
8558 | if (key.type != BTRFS_EXTENT_DATA_KEY) | ||
8559 | continue; | ||
8560 | |||
8561 | fi = btrfs_item_ptr(eb, i, struct btrfs_file_extent_item); | ||
8562 | /* filter out non qgroup-accountable extents */ | ||
8563 | extent_type = btrfs_file_extent_type(eb, fi); | ||
8564 | |||
8565 | if (extent_type == BTRFS_FILE_EXTENT_INLINE) | ||
8566 | continue; | ||
8567 | |||
8568 | bytenr = btrfs_file_extent_disk_bytenr(eb, fi); | ||
8569 | if (!bytenr) | ||
8570 | continue; | ||
8571 | |||
8572 | num_bytes = btrfs_file_extent_disk_num_bytes(eb, fi); | ||
8573 | |||
8574 | ret = btrfs_qgroup_insert_dirty_extent(trans, root->fs_info, | ||
8575 | bytenr, num_bytes, GFP_NOFS); | ||
8576 | if (ret) | ||
8577 | return ret; | ||
8578 | } | ||
8579 | return 0; | ||
8580 | } | ||
8581 | |||
8582 | /* | ||
8583 | * Walk up the tree from the bottom, freeing leaves and any interior | ||
8584 | * nodes which have had all slots visited. If a node (leaf or | ||
8585 | * interior) is freed, the node above it will have it's slot | ||
8586 | * incremented. The root node will never be freed. | ||
8587 | * | ||
8588 | * At the end of this function, we should have a path which has all | ||
8589 | * slots incremented to the next position for a search. If we need to | ||
8590 | * read a new node it will be NULL and the node above it will have the | ||
8591 | * correct slot selected for a later read. | ||
8592 | * | ||
8593 | * If we increment the root nodes slot counter past the number of | ||
8594 | * elements, 1 is returned to signal completion of the search. | ||
8595 | */ | ||
8596 | static int adjust_slots_upwards(struct btrfs_root *root, | ||
8597 | struct btrfs_path *path, int root_level) | ||
8598 | { | ||
8599 | int level = 0; | ||
8600 | int nr, slot; | ||
8601 | struct extent_buffer *eb; | ||
8602 | |||
8603 | if (root_level == 0) | ||
8604 | return 1; | ||
8605 | |||
8606 | while (level <= root_level) { | ||
8607 | eb = path->nodes[level]; | ||
8608 | nr = btrfs_header_nritems(eb); | ||
8609 | path->slots[level]++; | ||
8610 | slot = path->slots[level]; | ||
8611 | if (slot >= nr || level == 0) { | ||
8612 | /* | ||
8613 | * Don't free the root - we will detect this | ||
8614 | * condition after our loop and return a | ||
8615 | * positive value for caller to stop walking the tree. | ||
8616 | */ | ||
8617 | if (level != root_level) { | ||
8618 | btrfs_tree_unlock_rw(eb, path->locks[level]); | ||
8619 | path->locks[level] = 0; | ||
8620 | |||
8621 | free_extent_buffer(eb); | ||
8622 | path->nodes[level] = NULL; | ||
8623 | path->slots[level] = 0; | ||
8624 | } | ||
8625 | } else { | ||
8626 | /* | ||
8627 | * We have a valid slot to walk back down | ||
8628 | * from. Stop here so caller can process these | ||
8629 | * new nodes. | ||
8630 | */ | ||
8631 | break; | ||
8632 | } | ||
8633 | |||
8634 | level++; | ||
8635 | } | ||
8636 | |||
8637 | eb = path->nodes[root_level]; | ||
8638 | if (path->slots[root_level] >= btrfs_header_nritems(eb)) | ||
8639 | return 1; | ||
8640 | |||
8641 | return 0; | ||
8642 | } | ||
8643 | |||
8644 | /* | ||
8645 | * root_eb is the subtree root and is locked before this function is called. | ||
8646 | */ | ||
8647 | static int account_shared_subtree(struct btrfs_trans_handle *trans, | ||
8648 | struct btrfs_root *root, | ||
8649 | struct extent_buffer *root_eb, | ||
8650 | u64 root_gen, | ||
8651 | int root_level) | ||
8652 | { | ||
8653 | int ret = 0; | ||
8654 | int level; | ||
8655 | struct extent_buffer *eb = root_eb; | ||
8656 | struct btrfs_path *path = NULL; | ||
8657 | |||
8658 | BUG_ON(root_level < 0 || root_level > BTRFS_MAX_LEVEL); | ||
8659 | BUG_ON(root_eb == NULL); | ||
8660 | |||
8661 | if (!test_bit(BTRFS_FS_QUOTA_ENABLED, &root->fs_info->flags)) | ||
8662 | return 0; | ||
8663 | |||
8664 | if (!extent_buffer_uptodate(root_eb)) { | ||
8665 | ret = btrfs_read_buffer(root_eb, root_gen); | ||
8666 | if (ret) | ||
8667 | goto out; | ||
8668 | } | ||
8669 | |||
8670 | if (root_level == 0) { | ||
8671 | ret = account_leaf_items(trans, root, root_eb); | ||
8672 | goto out; | ||
8673 | } | ||
8674 | |||
8675 | path = btrfs_alloc_path(); | ||
8676 | if (!path) | ||
8677 | return -ENOMEM; | ||
8678 | |||
8679 | /* | ||
8680 | * Walk down the tree. Missing extent blocks are filled in as | ||
8681 | * we go. Metadata is accounted every time we read a new | ||
8682 | * extent block. | ||
8683 | * | ||
8684 | * When we reach a leaf, we account for file extent items in it, | ||
8685 | * walk back up the tree (adjusting slot pointers as we go) | ||
8686 | * and restart the search process. | ||
8687 | */ | ||
8688 | extent_buffer_get(root_eb); /* For path */ | ||
8689 | path->nodes[root_level] = root_eb; | ||
8690 | path->slots[root_level] = 0; | ||
8691 | path->locks[root_level] = 0; /* so release_path doesn't try to unlock */ | ||
8692 | walk_down: | ||
8693 | level = root_level; | ||
8694 | while (level >= 0) { | ||
8695 | if (path->nodes[level] == NULL) { | ||
8696 | int parent_slot; | ||
8697 | u64 child_gen; | ||
8698 | u64 child_bytenr; | ||
8699 | |||
8700 | /* We need to get child blockptr/gen from | ||
8701 | * parent before we can read it. */ | ||
8702 | eb = path->nodes[level + 1]; | ||
8703 | parent_slot = path->slots[level + 1]; | ||
8704 | child_bytenr = btrfs_node_blockptr(eb, parent_slot); | ||
8705 | child_gen = btrfs_node_ptr_generation(eb, parent_slot); | ||
8706 | |||
8707 | eb = read_tree_block(root, child_bytenr, child_gen); | ||
8708 | if (IS_ERR(eb)) { | ||
8709 | ret = PTR_ERR(eb); | ||
8710 | goto out; | ||
8711 | } else if (!extent_buffer_uptodate(eb)) { | ||
8712 | free_extent_buffer(eb); | ||
8713 | ret = -EIO; | ||
8714 | goto out; | ||
8715 | } | ||
8716 | |||
8717 | path->nodes[level] = eb; | ||
8718 | path->slots[level] = 0; | ||
8719 | |||
8720 | btrfs_tree_read_lock(eb); | ||
8721 | btrfs_set_lock_blocking_rw(eb, BTRFS_READ_LOCK); | ||
8722 | path->locks[level] = BTRFS_READ_LOCK_BLOCKING; | ||
8723 | |||
8724 | ret = btrfs_qgroup_insert_dirty_extent(trans, | ||
8725 | root->fs_info, child_bytenr, | ||
8726 | root->nodesize, GFP_NOFS); | ||
8727 | if (ret) | ||
8728 | goto out; | ||
8729 | } | ||
8730 | |||
8731 | if (level == 0) { | ||
8732 | ret = account_leaf_items(trans, root, path->nodes[level]); | ||
8733 | if (ret) | ||
8734 | goto out; | ||
8735 | |||
8736 | /* Nonzero return here means we completed our search */ | ||
8737 | ret = adjust_slots_upwards(root, path, root_level); | ||
8738 | if (ret) | ||
8739 | break; | ||
8740 | |||
8741 | /* Restart search with new slots */ | ||
8742 | goto walk_down; | ||
8743 | } | ||
8744 | |||
8745 | level--; | ||
8746 | } | ||
8747 | |||
8748 | ret = 0; | ||
8749 | out: | ||
8750 | btrfs_free_path(path); | ||
8751 | |||
8752 | return ret; | ||
8753 | } | ||
8754 | |||
8755 | /* | 8544 | /* |
8756 | * helper to process tree block while walking down the tree. | 8545 | * helper to process tree block while walking down the tree. |
8757 | * | 8546 | * |
@@ -8873,7 +8662,7 @@ static noinline int do_walk_down(struct btrfs_trans_handle *trans, | |||
8873 | bytenr = btrfs_node_blockptr(path->nodes[level], path->slots[level]); | 8662 | bytenr = btrfs_node_blockptr(path->nodes[level], path->slots[level]); |
8874 | blocksize = root->nodesize; | 8663 | blocksize = root->nodesize; |
8875 | 8664 | ||
8876 | next = btrfs_find_tree_block(root->fs_info, bytenr); | 8665 | next = find_extent_buffer(root->fs_info, bytenr); |
8877 | if (!next) { | 8666 | if (!next) { |
8878 | next = btrfs_find_create_tree_block(root, bytenr); | 8667 | next = btrfs_find_create_tree_block(root, bytenr); |
8879 | if (IS_ERR(next)) | 8668 | if (IS_ERR(next)) |
@@ -8980,8 +8769,8 @@ skip: | |||
8980 | } | 8769 | } |
8981 | 8770 | ||
8982 | if (need_account) { | 8771 | if (need_account) { |
8983 | ret = account_shared_subtree(trans, root, next, | 8772 | ret = btrfs_qgroup_trace_subtree(trans, root, next, |
8984 | generation, level - 1); | 8773 | generation, level - 1); |
8985 | if (ret) { | 8774 | if (ret) { |
8986 | btrfs_err_rl(root->fs_info, | 8775 | btrfs_err_rl(root->fs_info, |
8987 | "Error %d accounting shared subtree. Quota is out of sync, rescan required.", | 8776 | "Error %d accounting shared subtree. Quota is out of sync, rescan required.", |
@@ -9078,7 +8867,7 @@ static noinline int walk_up_proc(struct btrfs_trans_handle *trans, | |||
9078 | else | 8867 | else |
9079 | ret = btrfs_dec_ref(trans, root, eb, 0); | 8868 | ret = btrfs_dec_ref(trans, root, eb, 0); |
9080 | BUG_ON(ret); /* -ENOMEM */ | 8869 | BUG_ON(ret); /* -ENOMEM */ |
9081 | ret = account_leaf_items(trans, root, eb); | 8870 | ret = btrfs_qgroup_trace_leaf_items(trans, root, eb); |
9082 | if (ret) { | 8871 | if (ret) { |
9083 | btrfs_err_rl(root->fs_info, | 8872 | btrfs_err_rl(root->fs_info, |
9084 | "error %d accounting leaf items. Quota is out of sync, rescan required.", | 8873 | "error %d accounting leaf items. Quota is out of sync, rescan required.", |
diff --git a/fs/btrfs/extent_io.c b/fs/btrfs/extent_io.c index 8ed05d95584a..d24af9dc76c7 100644 --- a/fs/btrfs/extent_io.c +++ b/fs/btrfs/extent_io.c | |||
@@ -2029,7 +2029,7 @@ int repair_io_failure(struct inode *inode, u64 start, u64 length, u64 logical, | |||
2029 | * read repair operation. | 2029 | * read repair operation. |
2030 | */ | 2030 | */ |
2031 | btrfs_bio_counter_inc_blocked(fs_info); | 2031 | btrfs_bio_counter_inc_blocked(fs_info); |
2032 | ret = btrfs_map_block(fs_info, WRITE, logical, | 2032 | ret = btrfs_map_block(fs_info, BTRFS_MAP_WRITE, logical, |
2033 | &map_length, &bbio, mirror_num); | 2033 | &map_length, &bbio, mirror_num); |
2034 | if (ret) { | 2034 | if (ret) { |
2035 | btrfs_bio_counter_dec(fs_info); | 2035 | btrfs_bio_counter_dec(fs_info); |
@@ -3743,7 +3743,7 @@ static noinline_for_stack int write_one_eb(struct extent_buffer *eb, | |||
3743 | if (btrfs_header_level(eb) > 0) { | 3743 | if (btrfs_header_level(eb) > 0) { |
3744 | end = btrfs_node_key_ptr_offset(nritems); | 3744 | end = btrfs_node_key_ptr_offset(nritems); |
3745 | 3745 | ||
3746 | memset_extent_buffer(eb, 0, end, eb->len - end); | 3746 | memzero_extent_buffer(eb, end, eb->len - end); |
3747 | } else { | 3747 | } else { |
3748 | /* | 3748 | /* |
3749 | * leaf: | 3749 | * leaf: |
@@ -3752,7 +3752,7 @@ static noinline_for_stack int write_one_eb(struct extent_buffer *eb, | |||
3752 | start = btrfs_item_nr_offset(nritems); | 3752 | start = btrfs_item_nr_offset(nritems); |
3753 | end = btrfs_leaf_data(eb) + | 3753 | end = btrfs_leaf_data(eb) + |
3754 | leaf_data_end(fs_info->tree_root, eb); | 3754 | leaf_data_end(fs_info->tree_root, eb); |
3755 | memset_extent_buffer(eb, 0, start, end - start); | 3755 | memzero_extent_buffer(eb, start, end - start); |
3756 | } | 3756 | } |
3757 | 3757 | ||
3758 | for (i = 0; i < num_pages; i++) { | 3758 | for (i = 0; i < num_pages; i++) { |
@@ -4720,9 +4720,9 @@ struct extent_buffer *btrfs_clone_extent_buffer(struct extent_buffer *src) | |||
4720 | WARN_ON(PageDirty(p)); | 4720 | WARN_ON(PageDirty(p)); |
4721 | SetPageUptodate(p); | 4721 | SetPageUptodate(p); |
4722 | new->pages[i] = p; | 4722 | new->pages[i] = p; |
4723 | copy_page(page_address(p), page_address(src->pages[i])); | ||
4723 | } | 4724 | } |
4724 | 4725 | ||
4725 | copy_extent_buffer(new, src, 0, 0, src->len); | ||
4726 | set_bit(EXTENT_BUFFER_UPTODATE, &new->bflags); | 4726 | set_bit(EXTENT_BUFFER_UPTODATE, &new->bflags); |
4727 | set_bit(EXTENT_BUFFER_DUMMY, &new->bflags); | 4727 | set_bit(EXTENT_BUFFER_DUMMY, &new->bflags); |
4728 | 4728 | ||
@@ -5465,6 +5465,27 @@ int memcmp_extent_buffer(struct extent_buffer *eb, const void *ptrv, | |||
5465 | return ret; | 5465 | return ret; |
5466 | } | 5466 | } |
5467 | 5467 | ||
5468 | void write_extent_buffer_chunk_tree_uuid(struct extent_buffer *eb, | ||
5469 | const void *srcv) | ||
5470 | { | ||
5471 | char *kaddr; | ||
5472 | |||
5473 | WARN_ON(!PageUptodate(eb->pages[0])); | ||
5474 | kaddr = page_address(eb->pages[0]); | ||
5475 | memcpy(kaddr + offsetof(struct btrfs_header, chunk_tree_uuid), srcv, | ||
5476 | BTRFS_FSID_SIZE); | ||
5477 | } | ||
5478 | |||
5479 | void write_extent_buffer_fsid(struct extent_buffer *eb, const void *srcv) | ||
5480 | { | ||
5481 | char *kaddr; | ||
5482 | |||
5483 | WARN_ON(!PageUptodate(eb->pages[0])); | ||
5484 | kaddr = page_address(eb->pages[0]); | ||
5485 | memcpy(kaddr + offsetof(struct btrfs_header, fsid), srcv, | ||
5486 | BTRFS_FSID_SIZE); | ||
5487 | } | ||
5488 | |||
5468 | void write_extent_buffer(struct extent_buffer *eb, const void *srcv, | 5489 | void write_extent_buffer(struct extent_buffer *eb, const void *srcv, |
5469 | unsigned long start, unsigned long len) | 5490 | unsigned long start, unsigned long len) |
5470 | { | 5491 | { |
@@ -5496,8 +5517,8 @@ void write_extent_buffer(struct extent_buffer *eb, const void *srcv, | |||
5496 | } | 5517 | } |
5497 | } | 5518 | } |
5498 | 5519 | ||
5499 | void memset_extent_buffer(struct extent_buffer *eb, char c, | 5520 | void memzero_extent_buffer(struct extent_buffer *eb, unsigned long start, |
5500 | unsigned long start, unsigned long len) | 5521 | unsigned long len) |
5501 | { | 5522 | { |
5502 | size_t cur; | 5523 | size_t cur; |
5503 | size_t offset; | 5524 | size_t offset; |
@@ -5517,7 +5538,7 @@ void memset_extent_buffer(struct extent_buffer *eb, char c, | |||
5517 | 5538 | ||
5518 | cur = min(len, PAGE_SIZE - offset); | 5539 | cur = min(len, PAGE_SIZE - offset); |
5519 | kaddr = page_address(page); | 5540 | kaddr = page_address(page); |
5520 | memset(kaddr + offset, c, cur); | 5541 | memset(kaddr + offset, 0, cur); |
5521 | 5542 | ||
5522 | len -= cur; | 5543 | len -= cur; |
5523 | offset = 0; | 5544 | offset = 0; |
@@ -5525,6 +5546,20 @@ void memset_extent_buffer(struct extent_buffer *eb, char c, | |||
5525 | } | 5546 | } |
5526 | } | 5547 | } |
5527 | 5548 | ||
5549 | void copy_extent_buffer_full(struct extent_buffer *dst, | ||
5550 | struct extent_buffer *src) | ||
5551 | { | ||
5552 | int i; | ||
5553 | unsigned num_pages; | ||
5554 | |||
5555 | ASSERT(dst->len == src->len); | ||
5556 | |||
5557 | num_pages = num_extent_pages(dst->start, dst->len); | ||
5558 | for (i = 0; i < num_pages; i++) | ||
5559 | copy_page(page_address(dst->pages[i]), | ||
5560 | page_address(src->pages[i])); | ||
5561 | } | ||
5562 | |||
5528 | void copy_extent_buffer(struct extent_buffer *dst, struct extent_buffer *src, | 5563 | void copy_extent_buffer(struct extent_buffer *dst, struct extent_buffer *src, |
5529 | unsigned long dst_offset, unsigned long src_offset, | 5564 | unsigned long dst_offset, unsigned long src_offset, |
5530 | unsigned long len) | 5565 | unsigned long len) |
diff --git a/fs/btrfs/extent_io.h b/fs/btrfs/extent_io.h index ab31d145227e..ae64c1917d0a 100644 --- a/fs/btrfs/extent_io.h +++ b/fs/btrfs/extent_io.h | |||
@@ -405,8 +405,13 @@ void read_extent_buffer(struct extent_buffer *eb, void *dst, | |||
405 | int read_extent_buffer_to_user(struct extent_buffer *eb, void __user *dst, | 405 | int read_extent_buffer_to_user(struct extent_buffer *eb, void __user *dst, |
406 | unsigned long start, | 406 | unsigned long start, |
407 | unsigned long len); | 407 | unsigned long len); |
408 | void write_extent_buffer_fsid(struct extent_buffer *eb, const void *src); | ||
409 | void write_extent_buffer_chunk_tree_uuid(struct extent_buffer *eb, | ||
410 | const void *src); | ||
408 | void write_extent_buffer(struct extent_buffer *eb, const void *src, | 411 | void write_extent_buffer(struct extent_buffer *eb, const void *src, |
409 | unsigned long start, unsigned long len); | 412 | unsigned long start, unsigned long len); |
413 | void copy_extent_buffer_full(struct extent_buffer *dst, | ||
414 | struct extent_buffer *src); | ||
410 | void copy_extent_buffer(struct extent_buffer *dst, struct extent_buffer *src, | 415 | void copy_extent_buffer(struct extent_buffer *dst, struct extent_buffer *src, |
411 | unsigned long dst_offset, unsigned long src_offset, | 416 | unsigned long dst_offset, unsigned long src_offset, |
412 | unsigned long len); | 417 | unsigned long len); |
@@ -414,8 +419,8 @@ void memcpy_extent_buffer(struct extent_buffer *dst, unsigned long dst_offset, | |||
414 | unsigned long src_offset, unsigned long len); | 419 | unsigned long src_offset, unsigned long len); |
415 | void memmove_extent_buffer(struct extent_buffer *dst, unsigned long dst_offset, | 420 | void memmove_extent_buffer(struct extent_buffer *dst, unsigned long dst_offset, |
416 | unsigned long src_offset, unsigned long len); | 421 | unsigned long src_offset, unsigned long len); |
417 | void memset_extent_buffer(struct extent_buffer *eb, char c, | 422 | void memzero_extent_buffer(struct extent_buffer *eb, unsigned long start, |
418 | unsigned long start, unsigned long len); | 423 | unsigned long len); |
419 | int extent_buffer_test_bit(struct extent_buffer *eb, unsigned long start, | 424 | int extent_buffer_test_bit(struct extent_buffer *eb, unsigned long start, |
420 | unsigned long pos); | 425 | unsigned long pos); |
421 | void extent_buffer_bitmap_set(struct extent_buffer *eb, unsigned long start, | 426 | void extent_buffer_bitmap_set(struct extent_buffer *eb, unsigned long start, |
diff --git a/fs/btrfs/file-item.c b/fs/btrfs/file-item.c index d0d571c47d33..5e74178ba9d9 100644 --- a/fs/btrfs/file-item.c +++ b/fs/btrfs/file-item.c | |||
@@ -163,7 +163,7 @@ static int __btrfs_lookup_bio_sums(struct btrfs_root *root, | |||
163 | struct inode *inode, struct bio *bio, | 163 | struct inode *inode, struct bio *bio, |
164 | u64 logical_offset, u32 *dst, int dio) | 164 | u64 logical_offset, u32 *dst, int dio) |
165 | { | 165 | { |
166 | struct bio_vec *bvec = bio->bi_io_vec; | 166 | struct bio_vec *bvec; |
167 | struct btrfs_io_bio *btrfs_bio = btrfs_io_bio(bio); | 167 | struct btrfs_io_bio *btrfs_bio = btrfs_io_bio(bio); |
168 | struct btrfs_csum_item *item = NULL; | 168 | struct btrfs_csum_item *item = NULL; |
169 | struct extent_io_tree *io_tree = &BTRFS_I(inode)->io_tree; | 169 | struct extent_io_tree *io_tree = &BTRFS_I(inode)->io_tree; |
@@ -176,8 +176,7 @@ static int __btrfs_lookup_bio_sums(struct btrfs_root *root, | |||
176 | u64 page_bytes_left; | 176 | u64 page_bytes_left; |
177 | u32 diff; | 177 | u32 diff; |
178 | int nblocks; | 178 | int nblocks; |
179 | int bio_index = 0; | 179 | int count = 0, i; |
180 | int count; | ||
181 | u16 csum_size = btrfs_super_csum_size(root->fs_info->super_copy); | 180 | u16 csum_size = btrfs_super_csum_size(root->fs_info->super_copy); |
182 | 181 | ||
183 | path = btrfs_alloc_path(); | 182 | path = btrfs_alloc_path(); |
@@ -223,8 +222,11 @@ static int __btrfs_lookup_bio_sums(struct btrfs_root *root, | |||
223 | if (dio) | 222 | if (dio) |
224 | offset = logical_offset; | 223 | offset = logical_offset; |
225 | 224 | ||
226 | page_bytes_left = bvec->bv_len; | 225 | bio_for_each_segment_all(bvec, bio, i) { |
227 | while (bio_index < bio->bi_vcnt) { | 226 | page_bytes_left = bvec->bv_len; |
227 | if (count) | ||
228 | goto next; | ||
229 | |||
228 | if (!dio) | 230 | if (!dio) |
229 | offset = page_offset(bvec->bv_page) + bvec->bv_offset; | 231 | offset = page_offset(bvec->bv_page) + bvec->bv_offset; |
230 | count = btrfs_find_ordered_sum(inode, offset, disk_bytenr, | 232 | count = btrfs_find_ordered_sum(inode, offset, disk_bytenr, |
@@ -285,29 +287,17 @@ static int __btrfs_lookup_bio_sums(struct btrfs_root *root, | |||
285 | found: | 287 | found: |
286 | csum += count * csum_size; | 288 | csum += count * csum_size; |
287 | nblocks -= count; | 289 | nblocks -= count; |
288 | 290 | next: | |
289 | while (count--) { | 291 | while (count--) { |
290 | disk_bytenr += root->sectorsize; | 292 | disk_bytenr += root->sectorsize; |
291 | offset += root->sectorsize; | 293 | offset += root->sectorsize; |
292 | page_bytes_left -= root->sectorsize; | 294 | page_bytes_left -= root->sectorsize; |
293 | if (!page_bytes_left) { | 295 | if (!page_bytes_left) |
294 | bio_index++; | 296 | break; /* move to next bio */ |
295 | /* | ||
296 | * make sure we're still inside the | ||
297 | * bio before we update page_bytes_left | ||
298 | */ | ||
299 | if (bio_index >= bio->bi_vcnt) { | ||
300 | WARN_ON_ONCE(count); | ||
301 | goto done; | ||
302 | } | ||
303 | bvec++; | ||
304 | page_bytes_left = bvec->bv_len; | ||
305 | } | ||
306 | |||
307 | } | 297 | } |
308 | } | 298 | } |
309 | 299 | ||
310 | done: | 300 | WARN_ON_ONCE(count); |
311 | btrfs_free_path(path); | 301 | btrfs_free_path(path); |
312 | return 0; | 302 | return 0; |
313 | } | 303 | } |
@@ -447,13 +437,12 @@ int btrfs_csum_one_bio(struct btrfs_root *root, struct inode *inode, | |||
447 | struct bio *bio, u64 file_start, int contig) | 437 | struct bio *bio, u64 file_start, int contig) |
448 | { | 438 | { |
449 | struct btrfs_ordered_sum *sums; | 439 | struct btrfs_ordered_sum *sums; |
450 | struct btrfs_ordered_extent *ordered; | 440 | struct btrfs_ordered_extent *ordered = NULL; |
451 | char *data; | 441 | char *data; |
452 | struct bio_vec *bvec = bio->bi_io_vec; | 442 | struct bio_vec *bvec; |
453 | int bio_index = 0; | ||
454 | int index; | 443 | int index; |
455 | int nr_sectors; | 444 | int nr_sectors; |
456 | int i; | 445 | int i, j; |
457 | unsigned long total_bytes = 0; | 446 | unsigned long total_bytes = 0; |
458 | unsigned long this_sum_bytes = 0; | 447 | unsigned long this_sum_bytes = 0; |
459 | u64 offset; | 448 | u64 offset; |
@@ -470,17 +459,20 @@ int btrfs_csum_one_bio(struct btrfs_root *root, struct inode *inode, | |||
470 | if (contig) | 459 | if (contig) |
471 | offset = file_start; | 460 | offset = file_start; |
472 | else | 461 | else |
473 | offset = page_offset(bvec->bv_page) + bvec->bv_offset; | 462 | offset = 0; /* shut up gcc */ |
474 | 463 | ||
475 | ordered = btrfs_lookup_ordered_extent(inode, offset); | ||
476 | BUG_ON(!ordered); /* Logic error */ | ||
477 | sums->bytenr = (u64)bio->bi_iter.bi_sector << 9; | 464 | sums->bytenr = (u64)bio->bi_iter.bi_sector << 9; |
478 | index = 0; | 465 | index = 0; |
479 | 466 | ||
480 | while (bio_index < bio->bi_vcnt) { | 467 | bio_for_each_segment_all(bvec, bio, j) { |
481 | if (!contig) | 468 | if (!contig) |
482 | offset = page_offset(bvec->bv_page) + bvec->bv_offset; | 469 | offset = page_offset(bvec->bv_page) + bvec->bv_offset; |
483 | 470 | ||
471 | if (!ordered) { | ||
472 | ordered = btrfs_lookup_ordered_extent(inode, offset); | ||
473 | BUG_ON(!ordered); /* Logic error */ | ||
474 | } | ||
475 | |||
484 | data = kmap_atomic(bvec->bv_page); | 476 | data = kmap_atomic(bvec->bv_page); |
485 | 477 | ||
486 | nr_sectors = BTRFS_BYTES_TO_BLKS(root->fs_info, | 478 | nr_sectors = BTRFS_BYTES_TO_BLKS(root->fs_info, |
@@ -529,9 +521,6 @@ int btrfs_csum_one_bio(struct btrfs_root *root, struct inode *inode, | |||
529 | } | 521 | } |
530 | 522 | ||
531 | kunmap_atomic(data); | 523 | kunmap_atomic(data); |
532 | |||
533 | bio_index++; | ||
534 | bvec++; | ||
535 | } | 524 | } |
536 | this_sum_bytes = 0; | 525 | this_sum_bytes = 0; |
537 | btrfs_add_ordered_sum(inode, ordered, sums); | 526 | btrfs_add_ordered_sum(inode, ordered, sums); |
@@ -689,7 +678,7 @@ int btrfs_del_csums(struct btrfs_trans_handle *trans, | |||
689 | item_offset = btrfs_item_ptr_offset(leaf, | 678 | item_offset = btrfs_item_ptr_offset(leaf, |
690 | path->slots[0]); | 679 | path->slots[0]); |
691 | 680 | ||
692 | memset_extent_buffer(leaf, 0, item_offset + offset, | 681 | memzero_extent_buffer(leaf, item_offset + offset, |
693 | shift_len); | 682 | shift_len); |
694 | key.offset = bytenr; | 683 | key.offset = bytenr; |
695 | 684 | ||
diff --git a/fs/btrfs/file.c b/fs/btrfs/file.c index 3a14c87d9c92..3c1f4be36f16 100644 --- a/fs/btrfs/file.c +++ b/fs/btrfs/file.c | |||
@@ -27,7 +27,6 @@ | |||
27 | #include <linux/falloc.h> | 27 | #include <linux/falloc.h> |
28 | #include <linux/swap.h> | 28 | #include <linux/swap.h> |
29 | #include <linux/writeback.h> | 29 | #include <linux/writeback.h> |
30 | #include <linux/statfs.h> | ||
31 | #include <linux/compat.h> | 30 | #include <linux/compat.h> |
32 | #include <linux/slab.h> | 31 | #include <linux/slab.h> |
33 | #include <linux/btrfs.h> | 32 | #include <linux/btrfs.h> |
@@ -706,6 +705,7 @@ int __btrfs_drop_extents(struct btrfs_trans_handle *trans, | |||
706 | u64 num_bytes = 0; | 705 | u64 num_bytes = 0; |
707 | u64 extent_offset = 0; | 706 | u64 extent_offset = 0; |
708 | u64 extent_end = 0; | 707 | u64 extent_end = 0; |
708 | u64 last_end = start; | ||
709 | int del_nr = 0; | 709 | int del_nr = 0; |
710 | int del_slot = 0; | 710 | int del_slot = 0; |
711 | int extent_type; | 711 | int extent_type; |
@@ -797,8 +797,10 @@ next_slot: | |||
797 | * extent item in the call to setup_items_for_insert() later | 797 | * extent item in the call to setup_items_for_insert() later |
798 | * in this function. | 798 | * in this function. |
799 | */ | 799 | */ |
800 | if (extent_end == key.offset && extent_end >= search_start) | 800 | if (extent_end == key.offset && extent_end >= search_start) { |
801 | last_end = extent_end; | ||
801 | goto delete_extent_item; | 802 | goto delete_extent_item; |
803 | } | ||
802 | 804 | ||
803 | if (extent_end <= search_start) { | 805 | if (extent_end <= search_start) { |
804 | path->slots[0]++; | 806 | path->slots[0]++; |
@@ -861,6 +863,12 @@ next_slot: | |||
861 | key.offset = start; | 863 | key.offset = start; |
862 | } | 864 | } |
863 | /* | 865 | /* |
866 | * From here on out we will have actually dropped something, so | ||
867 | * last_end can be updated. | ||
868 | */ | ||
869 | last_end = extent_end; | ||
870 | |||
871 | /* | ||
864 | * | ---- range to drop ----- | | 872 | * | ---- range to drop ----- | |
865 | * | -------- extent -------- | | 873 | * | -------- extent -------- | |
866 | */ | 874 | */ |
@@ -1010,7 +1018,7 @@ delete_extent_item: | |||
1010 | if (!replace_extent || !(*key_inserted)) | 1018 | if (!replace_extent || !(*key_inserted)) |
1011 | btrfs_release_path(path); | 1019 | btrfs_release_path(path); |
1012 | if (drop_end) | 1020 | if (drop_end) |
1013 | *drop_end = found ? min(end, extent_end) : end; | 1021 | *drop_end = found ? min(end, last_end) : end; |
1014 | return ret; | 1022 | return ret; |
1015 | } | 1023 | } |
1016 | 1024 | ||
@@ -2224,9 +2232,15 @@ static int fill_holes(struct btrfs_trans_handle *trans, struct inode *inode, | |||
2224 | key.offset = offset; | 2232 | key.offset = offset; |
2225 | 2233 | ||
2226 | ret = btrfs_search_slot(trans, root, &key, path, 0, 1); | 2234 | ret = btrfs_search_slot(trans, root, &key, path, 0, 1); |
2227 | if (ret < 0) | 2235 | if (ret <= 0) { |
2236 | /* | ||
2237 | * We should have dropped this offset, so if we find it then | ||
2238 | * something has gone horribly wrong. | ||
2239 | */ | ||
2240 | if (ret == 0) | ||
2241 | ret = -EINVAL; | ||
2228 | return ret; | 2242 | return ret; |
2229 | BUG_ON(!ret); | 2243 | } |
2230 | 2244 | ||
2231 | leaf = path->nodes[0]; | 2245 | leaf = path->nodes[0]; |
2232 | if (hole_mergeable(inode, leaf, path->slots[0]-1, offset, end)) { | 2246 | if (hole_mergeable(inode, leaf, path->slots[0]-1, offset, end)) { |
@@ -2525,10 +2539,17 @@ static int btrfs_punch_hole(struct inode *inode, loff_t offset, loff_t len) | |||
2525 | 2539 | ||
2526 | trans->block_rsv = &root->fs_info->trans_block_rsv; | 2540 | trans->block_rsv = &root->fs_info->trans_block_rsv; |
2527 | 2541 | ||
2528 | if (cur_offset < ino_size) { | 2542 | if (cur_offset < drop_end && cur_offset < ino_size) { |
2529 | ret = fill_holes(trans, inode, path, cur_offset, | 2543 | ret = fill_holes(trans, inode, path, cur_offset, |
2530 | drop_end); | 2544 | drop_end); |
2531 | if (ret) { | 2545 | if (ret) { |
2546 | /* | ||
2547 | * If we failed then we didn't insert our hole | ||
2548 | * entries for the area we dropped, so now the | ||
2549 | * fs is corrupted, so we must abort the | ||
2550 | * transaction. | ||
2551 | */ | ||
2552 | btrfs_abort_transaction(trans, ret); | ||
2532 | err = ret; | 2553 | err = ret; |
2533 | break; | 2554 | break; |
2534 | } | 2555 | } |
@@ -2593,6 +2614,8 @@ static int btrfs_punch_hole(struct inode *inode, loff_t offset, loff_t len) | |||
2593 | if (cur_offset < ino_size && cur_offset < drop_end) { | 2614 | if (cur_offset < ino_size && cur_offset < drop_end) { |
2594 | ret = fill_holes(trans, inode, path, cur_offset, drop_end); | 2615 | ret = fill_holes(trans, inode, path, cur_offset, drop_end); |
2595 | if (ret) { | 2616 | if (ret) { |
2617 | /* Same comment as above. */ | ||
2618 | btrfs_abort_transaction(trans, ret); | ||
2596 | err = ret; | 2619 | err = ret; |
2597 | goto out_trans; | 2620 | goto out_trans; |
2598 | } | 2621 | } |
diff --git a/fs/btrfs/free-space-cache.c b/fs/btrfs/free-space-cache.c index e4b48f377d3a..c698dccb3757 100644 --- a/fs/btrfs/free-space-cache.c +++ b/fs/btrfs/free-space-cache.c | |||
@@ -75,8 +75,6 @@ static struct inode *__lookup_free_space_inode(struct btrfs_root *root, | |||
75 | btrfs_release_path(path); | 75 | btrfs_release_path(path); |
76 | 76 | ||
77 | inode = btrfs_iget(root->fs_info->sb, &location, root, NULL); | 77 | inode = btrfs_iget(root->fs_info->sb, &location, root, NULL); |
78 | if (!inode) | ||
79 | return ERR_PTR(-ENOENT); | ||
80 | if (IS_ERR(inode)) | 78 | if (IS_ERR(inode)) |
81 | return inode; | 79 | return inode; |
82 | if (is_bad_inode(inode)) { | 80 | if (is_bad_inode(inode)) { |
@@ -153,7 +151,7 @@ static int __create_free_space_inode(struct btrfs_root *root, | |||
153 | inode_item = btrfs_item_ptr(leaf, path->slots[0], | 151 | inode_item = btrfs_item_ptr(leaf, path->slots[0], |
154 | struct btrfs_inode_item); | 152 | struct btrfs_inode_item); |
155 | btrfs_item_key(leaf, &disk_key, path->slots[0]); | 153 | btrfs_item_key(leaf, &disk_key, path->slots[0]); |
156 | memset_extent_buffer(leaf, 0, (unsigned long)inode_item, | 154 | memzero_extent_buffer(leaf, (unsigned long)inode_item, |
157 | sizeof(*inode_item)); | 155 | sizeof(*inode_item)); |
158 | btrfs_set_inode_generation(leaf, inode_item, trans->transid); | 156 | btrfs_set_inode_generation(leaf, inode_item, trans->transid); |
159 | btrfs_set_inode_size(leaf, inode_item, 0); | 157 | btrfs_set_inode_size(leaf, inode_item, 0); |
@@ -181,7 +179,7 @@ static int __create_free_space_inode(struct btrfs_root *root, | |||
181 | leaf = path->nodes[0]; | 179 | leaf = path->nodes[0]; |
182 | header = btrfs_item_ptr(leaf, path->slots[0], | 180 | header = btrfs_item_ptr(leaf, path->slots[0], |
183 | struct btrfs_free_space_header); | 181 | struct btrfs_free_space_header); |
184 | memset_extent_buffer(leaf, 0, (unsigned long)header, sizeof(*header)); | 182 | memzero_extent_buffer(leaf, (unsigned long)header, sizeof(*header)); |
185 | btrfs_set_free_space_key(leaf, header, &disk_key); | 183 | btrfs_set_free_space_key(leaf, header, &disk_key); |
186 | btrfs_mark_buffer_dirty(leaf); | 184 | btrfs_mark_buffer_dirty(leaf); |
187 | btrfs_release_path(path); | 185 | btrfs_release_path(path); |
@@ -476,7 +474,7 @@ static void io_ctl_set_crc(struct btrfs_io_ctl *io_ctl, int index) | |||
476 | 474 | ||
477 | crc = btrfs_csum_data(io_ctl->orig + offset, crc, | 475 | crc = btrfs_csum_data(io_ctl->orig + offset, crc, |
478 | PAGE_SIZE - offset); | 476 | PAGE_SIZE - offset); |
479 | btrfs_csum_final(crc, (char *)&crc); | 477 | btrfs_csum_final(crc, (u8 *)&crc); |
480 | io_ctl_unmap_page(io_ctl); | 478 | io_ctl_unmap_page(io_ctl); |
481 | tmp = page_address(io_ctl->pages[0]); | 479 | tmp = page_address(io_ctl->pages[0]); |
482 | tmp += index; | 480 | tmp += index; |
@@ -504,7 +502,7 @@ static int io_ctl_check_crc(struct btrfs_io_ctl *io_ctl, int index) | |||
504 | io_ctl_map_page(io_ctl, 0); | 502 | io_ctl_map_page(io_ctl, 0); |
505 | crc = btrfs_csum_data(io_ctl->orig + offset, crc, | 503 | crc = btrfs_csum_data(io_ctl->orig + offset, crc, |
506 | PAGE_SIZE - offset); | 504 | PAGE_SIZE - offset); |
507 | btrfs_csum_final(crc, (char *)&crc); | 505 | btrfs_csum_final(crc, (u8 *)&crc); |
508 | if (val != crc) { | 506 | if (val != crc) { |
509 | btrfs_err_rl(io_ctl->root->fs_info, | 507 | btrfs_err_rl(io_ctl->root->fs_info, |
510 | "csum mismatch on free space cache"); | 508 | "csum mismatch on free space cache"); |
diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c index 8e3a5a266917..c96d94ef846d 100644 --- a/fs/btrfs/inode.c +++ b/fs/btrfs/inode.c | |||
@@ -30,7 +30,6 @@ | |||
30 | #include <linux/mpage.h> | 30 | #include <linux/mpage.h> |
31 | #include <linux/swap.h> | 31 | #include <linux/swap.h> |
32 | #include <linux/writeback.h> | 32 | #include <linux/writeback.h> |
33 | #include <linux/statfs.h> | ||
34 | #include <linux/compat.h> | 33 | #include <linux/compat.h> |
35 | #include <linux/bit_spinlock.h> | 34 | #include <linux/bit_spinlock.h> |
36 | #include <linux/xattr.h> | 35 | #include <linux/xattr.h> |
@@ -1864,7 +1863,7 @@ int btrfs_merge_bio_hook(struct page *page, unsigned long offset, | |||
1864 | 1863 | ||
1865 | length = bio->bi_iter.bi_size; | 1864 | length = bio->bi_iter.bi_size; |
1866 | map_length = length; | 1865 | map_length = length; |
1867 | ret = btrfs_map_block(root->fs_info, bio_op(bio), logical, | 1866 | ret = btrfs_map_block(root->fs_info, btrfs_op(bio), logical, |
1868 | &map_length, NULL, 0); | 1867 | &map_length, NULL, 0); |
1869 | if (ret < 0) | 1868 | if (ret < 0) |
1870 | return ret; | 1869 | return ret; |
@@ -3103,7 +3102,7 @@ static int __readpage_endio_check(struct inode *inode, | |||
3103 | 3102 | ||
3104 | kaddr = kmap_atomic(page); | 3103 | kaddr = kmap_atomic(page); |
3105 | csum = btrfs_csum_data(kaddr + pgoff, csum, len); | 3104 | csum = btrfs_csum_data(kaddr + pgoff, csum, len); |
3106 | btrfs_csum_final(csum, (char *)&csum); | 3105 | btrfs_csum_final(csum, (u8 *)&csum); |
3107 | if (csum != csum_expected) | 3106 | if (csum != csum_expected) |
3108 | goto zeroit; | 3107 | goto zeroit; |
3109 | 3108 | ||
@@ -5805,20 +5804,11 @@ static int btrfs_real_readdir(struct file *file, struct dir_context *ctx) | |||
5805 | int slot; | 5804 | int slot; |
5806 | unsigned char d_type; | 5805 | unsigned char d_type; |
5807 | int over = 0; | 5806 | int over = 0; |
5808 | u32 di_cur; | ||
5809 | u32 di_total; | ||
5810 | u32 di_len; | ||
5811 | int key_type = BTRFS_DIR_INDEX_KEY; | ||
5812 | char tmp_name[32]; | 5807 | char tmp_name[32]; |
5813 | char *name_ptr; | 5808 | char *name_ptr; |
5814 | int name_len; | 5809 | int name_len; |
5815 | int is_curr = 0; /* ctx->pos points to the current index? */ | ||
5816 | bool emitted; | ||
5817 | bool put = false; | 5810 | bool put = false; |
5818 | 5811 | struct btrfs_key location; | |
5819 | /* FIXME, use a real flag for deciding about the key type */ | ||
5820 | if (root->fs_info->tree_root == root) | ||
5821 | key_type = BTRFS_DIR_ITEM_KEY; | ||
5822 | 5812 | ||
5823 | if (!dir_emit_dots(file, ctx)) | 5813 | if (!dir_emit_dots(file, ctx)) |
5824 | return 0; | 5814 | return 0; |
@@ -5829,14 +5819,11 @@ static int btrfs_real_readdir(struct file *file, struct dir_context *ctx) | |||
5829 | 5819 | ||
5830 | path->reada = READA_FORWARD; | 5820 | path->reada = READA_FORWARD; |
5831 | 5821 | ||
5832 | if (key_type == BTRFS_DIR_INDEX_KEY) { | 5822 | INIT_LIST_HEAD(&ins_list); |
5833 | INIT_LIST_HEAD(&ins_list); | 5823 | INIT_LIST_HEAD(&del_list); |
5834 | INIT_LIST_HEAD(&del_list); | 5824 | put = btrfs_readdir_get_delayed_items(inode, &ins_list, &del_list); |
5835 | put = btrfs_readdir_get_delayed_items(inode, &ins_list, | ||
5836 | &del_list); | ||
5837 | } | ||
5838 | 5825 | ||
5839 | key.type = key_type; | 5826 | key.type = BTRFS_DIR_INDEX_KEY; |
5840 | key.offset = ctx->pos; | 5827 | key.offset = ctx->pos; |
5841 | key.objectid = btrfs_ino(inode); | 5828 | key.objectid = btrfs_ino(inode); |
5842 | 5829 | ||
@@ -5844,7 +5831,6 @@ static int btrfs_real_readdir(struct file *file, struct dir_context *ctx) | |||
5844 | if (ret < 0) | 5831 | if (ret < 0) |
5845 | goto err; | 5832 | goto err; |
5846 | 5833 | ||
5847 | emitted = false; | ||
5848 | while (1) { | 5834 | while (1) { |
5849 | leaf = path->nodes[0]; | 5835 | leaf = path->nodes[0]; |
5850 | slot = path->slots[0]; | 5836 | slot = path->slots[0]; |
@@ -5862,98 +5848,52 @@ static int btrfs_real_readdir(struct file *file, struct dir_context *ctx) | |||
5862 | 5848 | ||
5863 | if (found_key.objectid != key.objectid) | 5849 | if (found_key.objectid != key.objectid) |
5864 | break; | 5850 | break; |
5865 | if (found_key.type != key_type) | 5851 | if (found_key.type != BTRFS_DIR_INDEX_KEY) |
5866 | break; | 5852 | break; |
5867 | if (found_key.offset < ctx->pos) | 5853 | if (found_key.offset < ctx->pos) |
5868 | goto next; | 5854 | goto next; |
5869 | if (key_type == BTRFS_DIR_INDEX_KEY && | 5855 | if (btrfs_should_delete_dir_index(&del_list, found_key.offset)) |
5870 | btrfs_should_delete_dir_index(&del_list, | ||
5871 | found_key.offset)) | ||
5872 | goto next; | 5856 | goto next; |
5873 | 5857 | ||
5874 | ctx->pos = found_key.offset; | 5858 | ctx->pos = found_key.offset; |
5875 | is_curr = 1; | ||
5876 | 5859 | ||
5877 | di = btrfs_item_ptr(leaf, slot, struct btrfs_dir_item); | 5860 | di = btrfs_item_ptr(leaf, slot, struct btrfs_dir_item); |
5878 | di_cur = 0; | 5861 | if (verify_dir_item(root, leaf, di)) |
5879 | di_total = btrfs_item_size(leaf, item); | 5862 | goto next; |
5880 | |||
5881 | while (di_cur < di_total) { | ||
5882 | struct btrfs_key location; | ||
5883 | |||
5884 | if (verify_dir_item(root, leaf, di)) | ||
5885 | break; | ||
5886 | 5863 | ||
5887 | name_len = btrfs_dir_name_len(leaf, di); | 5864 | name_len = btrfs_dir_name_len(leaf, di); |
5888 | if (name_len <= sizeof(tmp_name)) { | 5865 | if (name_len <= sizeof(tmp_name)) { |
5889 | name_ptr = tmp_name; | 5866 | name_ptr = tmp_name; |
5890 | } else { | 5867 | } else { |
5891 | name_ptr = kmalloc(name_len, GFP_KERNEL); | 5868 | name_ptr = kmalloc(name_len, GFP_KERNEL); |
5892 | if (!name_ptr) { | 5869 | if (!name_ptr) { |
5893 | ret = -ENOMEM; | 5870 | ret = -ENOMEM; |
5894 | goto err; | 5871 | goto err; |
5895 | } | ||
5896 | } | 5872 | } |
5897 | read_extent_buffer(leaf, name_ptr, | 5873 | } |
5898 | (unsigned long)(di + 1), name_len); | 5874 | read_extent_buffer(leaf, name_ptr, (unsigned long)(di + 1), |
5899 | 5875 | name_len); | |
5900 | d_type = btrfs_filetype_table[btrfs_dir_type(leaf, di)]; | ||
5901 | btrfs_dir_item_key_to_cpu(leaf, di, &location); | ||
5902 | 5876 | ||
5877 | d_type = btrfs_filetype_table[btrfs_dir_type(leaf, di)]; | ||
5878 | btrfs_dir_item_key_to_cpu(leaf, di, &location); | ||
5903 | 5879 | ||
5904 | /* is this a reference to our own snapshot? If so | 5880 | over = !dir_emit(ctx, name_ptr, name_len, location.objectid, |
5905 | * skip it. | 5881 | d_type); |
5906 | * | ||
5907 | * In contrast to old kernels, we insert the snapshot's | ||
5908 | * dir item and dir index after it has been created, so | ||
5909 | * we won't find a reference to our own snapshot. We | ||
5910 | * still keep the following code for backward | ||
5911 | * compatibility. | ||
5912 | */ | ||
5913 | if (location.type == BTRFS_ROOT_ITEM_KEY && | ||
5914 | location.objectid == root->root_key.objectid) { | ||
5915 | over = 0; | ||
5916 | goto skip; | ||
5917 | } | ||
5918 | over = !dir_emit(ctx, name_ptr, name_len, | ||
5919 | location.objectid, d_type); | ||
5920 | 5882 | ||
5921 | skip: | 5883 | if (name_ptr != tmp_name) |
5922 | if (name_ptr != tmp_name) | 5884 | kfree(name_ptr); |
5923 | kfree(name_ptr); | ||
5924 | 5885 | ||
5925 | if (over) | 5886 | if (over) |
5926 | goto nopos; | 5887 | goto nopos; |
5927 | emitted = true; | 5888 | ctx->pos++; |
5928 | di_len = btrfs_dir_name_len(leaf, di) + | ||
5929 | btrfs_dir_data_len(leaf, di) + sizeof(*di); | ||
5930 | di_cur += di_len; | ||
5931 | di = (struct btrfs_dir_item *)((char *)di + di_len); | ||
5932 | } | ||
5933 | next: | 5889 | next: |
5934 | path->slots[0]++; | 5890 | path->slots[0]++; |
5935 | } | 5891 | } |
5936 | 5892 | ||
5937 | if (key_type == BTRFS_DIR_INDEX_KEY) { | 5893 | ret = btrfs_readdir_delayed_dir_index(ctx, &ins_list); |
5938 | if (is_curr) | 5894 | if (ret) |
5939 | ctx->pos++; | ||
5940 | ret = btrfs_readdir_delayed_dir_index(ctx, &ins_list, &emitted); | ||
5941 | if (ret) | ||
5942 | goto nopos; | ||
5943 | } | ||
5944 | |||
5945 | /* | ||
5946 | * If we haven't emitted any dir entry, we must not touch ctx->pos as | ||
5947 | * it was was set to the termination value in previous call. We assume | ||
5948 | * that "." and ".." were emitted if we reach this point and set the | ||
5949 | * termination value as well for an empty directory. | ||
5950 | */ | ||
5951 | if (ctx->pos > 2 && !emitted) | ||
5952 | goto nopos; | 5895 | goto nopos; |
5953 | 5896 | ||
5954 | /* Reached end of directory/root. Bump pos past the last item. */ | ||
5955 | ctx->pos++; | ||
5956 | |||
5957 | /* | 5897 | /* |
5958 | * Stop new entries from being returned after we return the last | 5898 | * Stop new entries from being returned after we return the last |
5959 | * entry. | 5899 | * entry. |
@@ -5971,12 +5911,10 @@ next: | |||
5971 | * last entry requires it because doing so has broken 32bit apps | 5911 | * last entry requires it because doing so has broken 32bit apps |
5972 | * in the past. | 5912 | * in the past. |
5973 | */ | 5913 | */ |
5974 | if (key_type == BTRFS_DIR_INDEX_KEY) { | 5914 | if (ctx->pos >= INT_MAX) |
5975 | if (ctx->pos >= INT_MAX) | 5915 | ctx->pos = LLONG_MAX; |
5976 | ctx->pos = LLONG_MAX; | 5916 | else |
5977 | else | 5917 | ctx->pos = INT_MAX; |
5978 | ctx->pos = INT_MAX; | ||
5979 | } | ||
5980 | nopos: | 5918 | nopos: |
5981 | ret = 0; | 5919 | ret = 0; |
5982 | err: | 5920 | err: |
@@ -6277,7 +6215,7 @@ static struct inode *btrfs_new_inode(struct btrfs_trans_handle *trans, | |||
6277 | 6215 | ||
6278 | inode_item = btrfs_item_ptr(path->nodes[0], path->slots[0], | 6216 | inode_item = btrfs_item_ptr(path->nodes[0], path->slots[0], |
6279 | struct btrfs_inode_item); | 6217 | struct btrfs_inode_item); |
6280 | memset_extent_buffer(path->nodes[0], 0, (unsigned long)inode_item, | 6218 | memzero_extent_buffer(path->nodes[0], (unsigned long)inode_item, |
6281 | sizeof(*inode_item)); | 6219 | sizeof(*inode_item)); |
6282 | fill_inode_item(trans, path->nodes[0], inode_item, inode); | 6220 | fill_inode_item(trans, path->nodes[0], inode_item, inode); |
6283 | 6221 | ||
@@ -7049,11 +6987,11 @@ insert: | |||
7049 | * extent causing the -EEXIST. | 6987 | * extent causing the -EEXIST. |
7050 | */ | 6988 | */ |
7051 | if (existing->start == em->start && | 6989 | if (existing->start == em->start && |
7052 | extent_map_end(existing) == extent_map_end(em) && | 6990 | extent_map_end(existing) >= extent_map_end(em) && |
7053 | em->block_start == existing->block_start) { | 6991 | em->block_start == existing->block_start) { |
7054 | /* | 6992 | /* |
7055 | * these two extents are the same, it happens | 6993 | * The existing extent map already encompasses the |
7056 | * with inlines especially | 6994 | * entire extent map we tried to add. |
7057 | */ | 6995 | */ |
7058 | free_extent_map(em); | 6996 | free_extent_map(em); |
7059 | em = existing; | 6997 | em = existing; |
@@ -7783,10 +7721,12 @@ static int btrfs_get_blocks_direct(struct inode *inode, sector_t iblock, | |||
7783 | } | 7721 | } |
7784 | 7722 | ||
7785 | /* | 7723 | /* |
7786 | * this will cow the extent, reset the len in case we changed | 7724 | * this will cow the extent, if em is within [start, len], then |
7787 | * it above | 7725 | * probably we've found a preallocated/existing extent, let's |
7726 | * give it a chance to use preallocated space. | ||
7788 | */ | 7727 | */ |
7789 | len = bh_result->b_size; | 7728 | len = min_t(u64, bh_result->b_size, em->len - (start - em->start)); |
7729 | len = ALIGN(len, root->sectorsize); | ||
7790 | free_extent_map(em); | 7730 | free_extent_map(em); |
7791 | em = btrfs_new_extent_direct(inode, start, len); | 7731 | em = btrfs_new_extent_direct(inode, start, len); |
7792 | if (IS_ERR(em)) { | 7732 | if (IS_ERR(em)) { |
@@ -8394,7 +8334,7 @@ static int btrfs_submit_direct_hook(struct btrfs_dio_private *dip, | |||
8394 | struct btrfs_root *root = BTRFS_I(inode)->root; | 8334 | struct btrfs_root *root = BTRFS_I(inode)->root; |
8395 | struct bio *bio; | 8335 | struct bio *bio; |
8396 | struct bio *orig_bio = dip->orig_bio; | 8336 | struct bio *orig_bio = dip->orig_bio; |
8397 | struct bio_vec *bvec = orig_bio->bi_io_vec; | 8337 | struct bio_vec *bvec; |
8398 | u64 start_sector = orig_bio->bi_iter.bi_sector; | 8338 | u64 start_sector = orig_bio->bi_iter.bi_sector; |
8399 | u64 file_offset = dip->logical_offset; | 8339 | u64 file_offset = dip->logical_offset; |
8400 | u64 submit_len = 0; | 8340 | u64 submit_len = 0; |
@@ -8403,10 +8343,10 @@ static int btrfs_submit_direct_hook(struct btrfs_dio_private *dip, | |||
8403 | int async_submit = 0; | 8343 | int async_submit = 0; |
8404 | int nr_sectors; | 8344 | int nr_sectors; |
8405 | int ret; | 8345 | int ret; |
8406 | int i; | 8346 | int i, j; |
8407 | 8347 | ||
8408 | map_length = orig_bio->bi_iter.bi_size; | 8348 | map_length = orig_bio->bi_iter.bi_size; |
8409 | ret = btrfs_map_block(root->fs_info, bio_op(orig_bio), | 8349 | ret = btrfs_map_block(root->fs_info, btrfs_op(orig_bio), |
8410 | start_sector << 9, &map_length, NULL, 0); | 8350 | start_sector << 9, &map_length, NULL, 0); |
8411 | if (ret) | 8351 | if (ret) |
8412 | return -EIO; | 8352 | return -EIO; |
@@ -8433,7 +8373,7 @@ static int btrfs_submit_direct_hook(struct btrfs_dio_private *dip, | |||
8433 | btrfs_io_bio(bio)->logical = file_offset; | 8373 | btrfs_io_bio(bio)->logical = file_offset; |
8434 | atomic_inc(&dip->pending_bios); | 8374 | atomic_inc(&dip->pending_bios); |
8435 | 8375 | ||
8436 | while (bvec <= (orig_bio->bi_io_vec + orig_bio->bi_vcnt - 1)) { | 8376 | bio_for_each_segment_all(bvec, orig_bio, j) { |
8437 | nr_sectors = BTRFS_BYTES_TO_BLKS(root->fs_info, bvec->bv_len); | 8377 | nr_sectors = BTRFS_BYTES_TO_BLKS(root->fs_info, bvec->bv_len); |
8438 | i = 0; | 8378 | i = 0; |
8439 | next_block: | 8379 | next_block: |
@@ -8472,7 +8412,7 @@ next_block: | |||
8472 | btrfs_io_bio(bio)->logical = file_offset; | 8412 | btrfs_io_bio(bio)->logical = file_offset; |
8473 | 8413 | ||
8474 | map_length = orig_bio->bi_iter.bi_size; | 8414 | map_length = orig_bio->bi_iter.bi_size; |
8475 | ret = btrfs_map_block(root->fs_info, bio_op(orig_bio), | 8415 | ret = btrfs_map_block(root->fs_info, btrfs_op(orig_bio), |
8476 | start_sector << 9, | 8416 | start_sector << 9, |
8477 | &map_length, NULL, 0); | 8417 | &map_length, NULL, 0); |
8478 | if (ret) { | 8418 | if (ret) { |
@@ -8487,7 +8427,6 @@ next_block: | |||
8487 | i++; | 8427 | i++; |
8488 | goto next_block; | 8428 | goto next_block; |
8489 | } | 8429 | } |
8490 | bvec++; | ||
8491 | } | 8430 | } |
8492 | } | 8431 | } |
8493 | 8432 | ||
diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c index 7acbd2cf6192..4a20f3e68cb4 100644 --- a/fs/btrfs/ioctl.c +++ b/fs/btrfs/ioctl.c | |||
@@ -33,7 +33,6 @@ | |||
33 | #include <linux/namei.h> | 33 | #include <linux/namei.h> |
34 | #include <linux/swap.h> | 34 | #include <linux/swap.h> |
35 | #include <linux/writeback.h> | 35 | #include <linux/writeback.h> |
36 | #include <linux/statfs.h> | ||
37 | #include <linux/compat.h> | 36 | #include <linux/compat.h> |
38 | #include <linux/bit_spinlock.h> | 37 | #include <linux/bit_spinlock.h> |
39 | #include <linux/security.h> | 38 | #include <linux/security.h> |
@@ -502,17 +501,15 @@ static noinline int create_subvol(struct inode *dir, | |||
502 | goto fail; | 501 | goto fail; |
503 | } | 502 | } |
504 | 503 | ||
505 | memset_extent_buffer(leaf, 0, 0, sizeof(struct btrfs_header)); | 504 | memzero_extent_buffer(leaf, 0, sizeof(struct btrfs_header)); |
506 | btrfs_set_header_bytenr(leaf, leaf->start); | 505 | btrfs_set_header_bytenr(leaf, leaf->start); |
507 | btrfs_set_header_generation(leaf, trans->transid); | 506 | btrfs_set_header_generation(leaf, trans->transid); |
508 | btrfs_set_header_backref_rev(leaf, BTRFS_MIXED_BACKREF_REV); | 507 | btrfs_set_header_backref_rev(leaf, BTRFS_MIXED_BACKREF_REV); |
509 | btrfs_set_header_owner(leaf, objectid); | 508 | btrfs_set_header_owner(leaf, objectid); |
510 | 509 | ||
511 | write_extent_buffer(leaf, root->fs_info->fsid, btrfs_header_fsid(), | 510 | write_extent_buffer_fsid(leaf, root->fs_info->fsid); |
512 | BTRFS_FSID_SIZE); | 511 | write_extent_buffer_chunk_tree_uuid(leaf, |
513 | write_extent_buffer(leaf, root->fs_info->chunk_tree_uuid, | 512 | root->fs_info->chunk_tree_uuid); |
514 | btrfs_header_chunk_tree_uuid(leaf), | ||
515 | BTRFS_UUID_SIZE); | ||
516 | btrfs_mark_buffer_dirty(leaf); | 513 | btrfs_mark_buffer_dirty(leaf); |
517 | 514 | ||
518 | inode_item = &root_item->inode; | 515 | inode_item = &root_item->inode; |
@@ -4572,11 +4569,8 @@ static long btrfs_ioctl_logical_to_ino(struct btrfs_root *root, | |||
4572 | return -EPERM; | 4569 | return -EPERM; |
4573 | 4570 | ||
4574 | loi = memdup_user(arg, sizeof(*loi)); | 4571 | loi = memdup_user(arg, sizeof(*loi)); |
4575 | if (IS_ERR(loi)) { | 4572 | if (IS_ERR(loi)) |
4576 | ret = PTR_ERR(loi); | 4573 | return PTR_ERR(loi); |
4577 | loi = NULL; | ||
4578 | goto out; | ||
4579 | } | ||
4580 | 4574 | ||
4581 | path = btrfs_alloc_path(); | 4575 | path = btrfs_alloc_path(); |
4582 | if (!path) { | 4576 | if (!path) { |
@@ -5203,11 +5197,8 @@ static long btrfs_ioctl_set_received_subvol_32(struct file *file, | |||
5203 | int ret = 0; | 5197 | int ret = 0; |
5204 | 5198 | ||
5205 | args32 = memdup_user(arg, sizeof(*args32)); | 5199 | args32 = memdup_user(arg, sizeof(*args32)); |
5206 | if (IS_ERR(args32)) { | 5200 | if (IS_ERR(args32)) |
5207 | ret = PTR_ERR(args32); | 5201 | return PTR_ERR(args32); |
5208 | args32 = NULL; | ||
5209 | goto out; | ||
5210 | } | ||
5211 | 5202 | ||
5212 | args64 = kmalloc(sizeof(*args64), GFP_KERNEL); | 5203 | args64 = kmalloc(sizeof(*args64), GFP_KERNEL); |
5213 | if (!args64) { | 5204 | if (!args64) { |
@@ -5255,11 +5246,8 @@ static long btrfs_ioctl_set_received_subvol(struct file *file, | |||
5255 | int ret = 0; | 5246 | int ret = 0; |
5256 | 5247 | ||
5257 | sa = memdup_user(arg, sizeof(*sa)); | 5248 | sa = memdup_user(arg, sizeof(*sa)); |
5258 | if (IS_ERR(sa)) { | 5249 | if (IS_ERR(sa)) |
5259 | ret = PTR_ERR(sa); | 5250 | return PTR_ERR(sa); |
5260 | sa = NULL; | ||
5261 | goto out; | ||
5262 | } | ||
5263 | 5251 | ||
5264 | ret = _btrfs_ioctl_set_received_subvol(file, sa); | 5252 | ret = _btrfs_ioctl_set_received_subvol(file, sa); |
5265 | 5253 | ||
diff --git a/fs/btrfs/lzo.c b/fs/btrfs/lzo.c index 48655da0f4ca..45d26980caf9 100644 --- a/fs/btrfs/lzo.c +++ b/fs/btrfs/lzo.c | |||
@@ -254,25 +254,21 @@ out: | |||
254 | return ret; | 254 | return ret; |
255 | } | 255 | } |
256 | 256 | ||
257 | static int lzo_decompress_biovec(struct list_head *ws, | 257 | static int lzo_decompress_bio(struct list_head *ws, |
258 | struct page **pages_in, | 258 | struct page **pages_in, |
259 | u64 disk_start, | 259 | u64 disk_start, |
260 | struct bio_vec *bvec, | 260 | struct bio *orig_bio, |
261 | int vcnt, | ||
262 | size_t srclen) | 261 | size_t srclen) |
263 | { | 262 | { |
264 | struct workspace *workspace = list_entry(ws, struct workspace, list); | 263 | struct workspace *workspace = list_entry(ws, struct workspace, list); |
265 | int ret = 0, ret2; | 264 | int ret = 0, ret2; |
266 | char *data_in; | 265 | char *data_in; |
267 | unsigned long page_in_index = 0; | 266 | unsigned long page_in_index = 0; |
268 | unsigned long page_out_index = 0; | ||
269 | unsigned long total_pages_in = DIV_ROUND_UP(srclen, PAGE_SIZE); | 267 | unsigned long total_pages_in = DIV_ROUND_UP(srclen, PAGE_SIZE); |
270 | unsigned long buf_start; | 268 | unsigned long buf_start; |
271 | unsigned long buf_offset = 0; | 269 | unsigned long buf_offset = 0; |
272 | unsigned long bytes; | 270 | unsigned long bytes; |
273 | unsigned long working_bytes; | 271 | unsigned long working_bytes; |
274 | unsigned long pg_offset; | ||
275 | |||
276 | size_t in_len; | 272 | size_t in_len; |
277 | size_t out_len; | 273 | size_t out_len; |
278 | unsigned long in_offset; | 274 | unsigned long in_offset; |
@@ -292,7 +288,6 @@ static int lzo_decompress_biovec(struct list_head *ws, | |||
292 | in_page_bytes_left = PAGE_SIZE - LZO_LEN; | 288 | in_page_bytes_left = PAGE_SIZE - LZO_LEN; |
293 | 289 | ||
294 | tot_out = 0; | 290 | tot_out = 0; |
295 | pg_offset = 0; | ||
296 | 291 | ||
297 | while (tot_in < tot_len) { | 292 | while (tot_in < tot_len) { |
298 | in_len = read_compress_length(data_in + in_offset); | 293 | in_len = read_compress_length(data_in + in_offset); |
@@ -365,16 +360,14 @@ cont: | |||
365 | tot_out += out_len; | 360 | tot_out += out_len; |
366 | 361 | ||
367 | ret2 = btrfs_decompress_buf2page(workspace->buf, buf_start, | 362 | ret2 = btrfs_decompress_buf2page(workspace->buf, buf_start, |
368 | tot_out, disk_start, | 363 | tot_out, disk_start, orig_bio); |
369 | bvec, vcnt, | ||
370 | &page_out_index, &pg_offset); | ||
371 | if (ret2 == 0) | 364 | if (ret2 == 0) |
372 | break; | 365 | break; |
373 | } | 366 | } |
374 | done: | 367 | done: |
375 | kunmap(pages_in[page_in_index]); | 368 | kunmap(pages_in[page_in_index]); |
376 | if (!ret) | 369 | if (!ret) |
377 | btrfs_clear_biovec_end(bvec, vcnt, page_out_index, pg_offset); | 370 | zero_fill_bio(orig_bio); |
378 | return ret; | 371 | return ret; |
379 | } | 372 | } |
380 | 373 | ||
@@ -438,6 +431,6 @@ const struct btrfs_compress_op btrfs_lzo_compress = { | |||
438 | .alloc_workspace = lzo_alloc_workspace, | 431 | .alloc_workspace = lzo_alloc_workspace, |
439 | .free_workspace = lzo_free_workspace, | 432 | .free_workspace = lzo_free_workspace, |
440 | .compress_pages = lzo_compress_pages, | 433 | .compress_pages = lzo_compress_pages, |
441 | .decompress_biovec = lzo_decompress_biovec, | 434 | .decompress_bio = lzo_decompress_bio, |
442 | .decompress = lzo_decompress, | 435 | .decompress = lzo_decompress, |
443 | }; | 436 | }; |
diff --git a/fs/btrfs/qgroup.c b/fs/btrfs/qgroup.c index 11f4fffe503e..605a3227980a 100644 --- a/fs/btrfs/qgroup.c +++ b/fs/btrfs/qgroup.c | |||
@@ -131,8 +131,15 @@ struct btrfs_qgroup_list { | |||
131 | struct btrfs_qgroup *member; | 131 | struct btrfs_qgroup *member; |
132 | }; | 132 | }; |
133 | 133 | ||
134 | #define ptr_to_u64(x) ((u64)(uintptr_t)x) | 134 | static inline u64 qgroup_to_aux(struct btrfs_qgroup *qg) |
135 | #define u64_to_ptr(x) ((struct btrfs_qgroup *)(uintptr_t)x) | 135 | { |
136 | return (u64)(uintptr_t)qg; | ||
137 | } | ||
138 | |||
139 | static inline struct btrfs_qgroup* unode_aux_to_qgroup(struct ulist_node *n) | ||
140 | { | ||
141 | return (struct btrfs_qgroup *)(uintptr_t)n->aux; | ||
142 | } | ||
136 | 143 | ||
137 | static int | 144 | static int |
138 | qgroup_rescan_init(struct btrfs_fs_info *fs_info, u64 progress_objectid, | 145 | qgroup_rescan_init(struct btrfs_fs_info *fs_info, u64 progress_objectid, |
@@ -1066,7 +1073,7 @@ static int __qgroup_excl_accounting(struct btrfs_fs_info *fs_info, | |||
1066 | /* Get all of the parent groups that contain this qgroup */ | 1073 | /* Get all of the parent groups that contain this qgroup */ |
1067 | list_for_each_entry(glist, &qgroup->groups, next_group) { | 1074 | list_for_each_entry(glist, &qgroup->groups, next_group) { |
1068 | ret = ulist_add(tmp, glist->group->qgroupid, | 1075 | ret = ulist_add(tmp, glist->group->qgroupid, |
1069 | ptr_to_u64(glist->group), GFP_ATOMIC); | 1076 | qgroup_to_aux(glist->group), GFP_ATOMIC); |
1070 | if (ret < 0) | 1077 | if (ret < 0) |
1071 | goto out; | 1078 | goto out; |
1072 | } | 1079 | } |
@@ -1074,7 +1081,7 @@ static int __qgroup_excl_accounting(struct btrfs_fs_info *fs_info, | |||
1074 | /* Iterate all of the parents and adjust their reference counts */ | 1081 | /* Iterate all of the parents and adjust their reference counts */ |
1075 | ULIST_ITER_INIT(&uiter); | 1082 | ULIST_ITER_INIT(&uiter); |
1076 | while ((unode = ulist_next(tmp, &uiter))) { | 1083 | while ((unode = ulist_next(tmp, &uiter))) { |
1077 | qgroup = u64_to_ptr(unode->aux); | 1084 | qgroup = unode_aux_to_qgroup(unode); |
1078 | qgroup->rfer += sign * num_bytes; | 1085 | qgroup->rfer += sign * num_bytes; |
1079 | qgroup->rfer_cmpr += sign * num_bytes; | 1086 | qgroup->rfer_cmpr += sign * num_bytes; |
1080 | WARN_ON(sign < 0 && qgroup->excl < num_bytes); | 1087 | WARN_ON(sign < 0 && qgroup->excl < num_bytes); |
@@ -1087,7 +1094,7 @@ static int __qgroup_excl_accounting(struct btrfs_fs_info *fs_info, | |||
1087 | /* Add any parents of the parents */ | 1094 | /* Add any parents of the parents */ |
1088 | list_for_each_entry(glist, &qgroup->groups, next_group) { | 1095 | list_for_each_entry(glist, &qgroup->groups, next_group) { |
1089 | ret = ulist_add(tmp, glist->group->qgroupid, | 1096 | ret = ulist_add(tmp, glist->group->qgroupid, |
1090 | ptr_to_u64(glist->group), GFP_ATOMIC); | 1097 | qgroup_to_aux(glist->group), GFP_ATOMIC); |
1091 | if (ret < 0) | 1098 | if (ret < 0) |
1092 | goto out; | 1099 | goto out; |
1093 | } | 1100 | } |
@@ -1450,7 +1457,7 @@ int btrfs_qgroup_prepare_account_extents(struct btrfs_trans_handle *trans, | |||
1450 | return ret; | 1457 | return ret; |
1451 | } | 1458 | } |
1452 | 1459 | ||
1453 | int btrfs_qgroup_insert_dirty_extent_nolock(struct btrfs_fs_info *fs_info, | 1460 | int btrfs_qgroup_trace_extent_nolock(struct btrfs_fs_info *fs_info, |
1454 | struct btrfs_delayed_ref_root *delayed_refs, | 1461 | struct btrfs_delayed_ref_root *delayed_refs, |
1455 | struct btrfs_qgroup_extent_record *record) | 1462 | struct btrfs_qgroup_extent_record *record) |
1456 | { | 1463 | { |
@@ -1460,7 +1467,7 @@ int btrfs_qgroup_insert_dirty_extent_nolock(struct btrfs_fs_info *fs_info, | |||
1460 | u64 bytenr = record->bytenr; | 1467 | u64 bytenr = record->bytenr; |
1461 | 1468 | ||
1462 | assert_spin_locked(&delayed_refs->lock); | 1469 | assert_spin_locked(&delayed_refs->lock); |
1463 | trace_btrfs_qgroup_insert_dirty_extent(fs_info, record); | 1470 | trace_btrfs_qgroup_trace_extent(fs_info, record); |
1464 | 1471 | ||
1465 | while (*p) { | 1472 | while (*p) { |
1466 | parent_node = *p; | 1473 | parent_node = *p; |
@@ -1479,7 +1486,7 @@ int btrfs_qgroup_insert_dirty_extent_nolock(struct btrfs_fs_info *fs_info, | |||
1479 | return 0; | 1486 | return 0; |
1480 | } | 1487 | } |
1481 | 1488 | ||
1482 | int btrfs_qgroup_insert_dirty_extent(struct btrfs_trans_handle *trans, | 1489 | int btrfs_qgroup_trace_extent(struct btrfs_trans_handle *trans, |
1483 | struct btrfs_fs_info *fs_info, u64 bytenr, u64 num_bytes, | 1490 | struct btrfs_fs_info *fs_info, u64 bytenr, u64 num_bytes, |
1484 | gfp_t gfp_flag) | 1491 | gfp_t gfp_flag) |
1485 | { | 1492 | { |
@@ -1502,7 +1509,7 @@ int btrfs_qgroup_insert_dirty_extent(struct btrfs_trans_handle *trans, | |||
1502 | record->old_roots = NULL; | 1509 | record->old_roots = NULL; |
1503 | 1510 | ||
1504 | spin_lock(&delayed_refs->lock); | 1511 | spin_lock(&delayed_refs->lock); |
1505 | ret = btrfs_qgroup_insert_dirty_extent_nolock(fs_info, delayed_refs, | 1512 | ret = btrfs_qgroup_trace_extent_nolock(fs_info, delayed_refs, |
1506 | record); | 1513 | record); |
1507 | spin_unlock(&delayed_refs->lock); | 1514 | spin_unlock(&delayed_refs->lock); |
1508 | if (ret > 0) | 1515 | if (ret > 0) |
@@ -1510,6 +1517,219 @@ int btrfs_qgroup_insert_dirty_extent(struct btrfs_trans_handle *trans, | |||
1510 | return 0; | 1517 | return 0; |
1511 | } | 1518 | } |
1512 | 1519 | ||
1520 | int btrfs_qgroup_trace_leaf_items(struct btrfs_trans_handle *trans, | ||
1521 | struct btrfs_root *root, | ||
1522 | struct extent_buffer *eb) | ||
1523 | { | ||
1524 | int nr = btrfs_header_nritems(eb); | ||
1525 | int i, extent_type, ret; | ||
1526 | struct btrfs_key key; | ||
1527 | struct btrfs_file_extent_item *fi; | ||
1528 | u64 bytenr, num_bytes; | ||
1529 | |||
1530 | /* We can be called directly from walk_up_proc() */ | ||
1531 | if (!test_bit(BTRFS_FS_QUOTA_ENABLED, &root->fs_info->flags)) | ||
1532 | return 0; | ||
1533 | |||
1534 | for (i = 0; i < nr; i++) { | ||
1535 | btrfs_item_key_to_cpu(eb, &key, i); | ||
1536 | |||
1537 | if (key.type != BTRFS_EXTENT_DATA_KEY) | ||
1538 | continue; | ||
1539 | |||
1540 | fi = btrfs_item_ptr(eb, i, struct btrfs_file_extent_item); | ||
1541 | /* filter out non qgroup-accountable extents */ | ||
1542 | extent_type = btrfs_file_extent_type(eb, fi); | ||
1543 | |||
1544 | if (extent_type == BTRFS_FILE_EXTENT_INLINE) | ||
1545 | continue; | ||
1546 | |||
1547 | bytenr = btrfs_file_extent_disk_bytenr(eb, fi); | ||
1548 | if (!bytenr) | ||
1549 | continue; | ||
1550 | |||
1551 | num_bytes = btrfs_file_extent_disk_num_bytes(eb, fi); | ||
1552 | |||
1553 | ret = btrfs_qgroup_trace_extent(trans, root->fs_info, | ||
1554 | bytenr, num_bytes, GFP_NOFS); | ||
1555 | if (ret) | ||
1556 | return ret; | ||
1557 | } | ||
1558 | return 0; | ||
1559 | } | ||
1560 | |||
1561 | /* | ||
1562 | * Walk up the tree from the bottom, freeing leaves and any interior | ||
1563 | * nodes which have had all slots visited. If a node (leaf or | ||
1564 | * interior) is freed, the node above it will have it's slot | ||
1565 | * incremented. The root node will never be freed. | ||
1566 | * | ||
1567 | * At the end of this function, we should have a path which has all | ||
1568 | * slots incremented to the next position for a search. If we need to | ||
1569 | * read a new node it will be NULL and the node above it will have the | ||
1570 | * correct slot selected for a later read. | ||
1571 | * | ||
1572 | * If we increment the root nodes slot counter past the number of | ||
1573 | * elements, 1 is returned to signal completion of the search. | ||
1574 | */ | ||
1575 | static int adjust_slots_upwards(struct btrfs_root *root, | ||
1576 | struct btrfs_path *path, int root_level) | ||
1577 | { | ||
1578 | int level = 0; | ||
1579 | int nr, slot; | ||
1580 | struct extent_buffer *eb; | ||
1581 | |||
1582 | if (root_level == 0) | ||
1583 | return 1; | ||
1584 | |||
1585 | while (level <= root_level) { | ||
1586 | eb = path->nodes[level]; | ||
1587 | nr = btrfs_header_nritems(eb); | ||
1588 | path->slots[level]++; | ||
1589 | slot = path->slots[level]; | ||
1590 | if (slot >= nr || level == 0) { | ||
1591 | /* | ||
1592 | * Don't free the root - we will detect this | ||
1593 | * condition after our loop and return a | ||
1594 | * positive value for caller to stop walking the tree. | ||
1595 | */ | ||
1596 | if (level != root_level) { | ||
1597 | btrfs_tree_unlock_rw(eb, path->locks[level]); | ||
1598 | path->locks[level] = 0; | ||
1599 | |||
1600 | free_extent_buffer(eb); | ||
1601 | path->nodes[level] = NULL; | ||
1602 | path->slots[level] = 0; | ||
1603 | } | ||
1604 | } else { | ||
1605 | /* | ||
1606 | * We have a valid slot to walk back down | ||
1607 | * from. Stop here so caller can process these | ||
1608 | * new nodes. | ||
1609 | */ | ||
1610 | break; | ||
1611 | } | ||
1612 | |||
1613 | level++; | ||
1614 | } | ||
1615 | |||
1616 | eb = path->nodes[root_level]; | ||
1617 | if (path->slots[root_level] >= btrfs_header_nritems(eb)) | ||
1618 | return 1; | ||
1619 | |||
1620 | return 0; | ||
1621 | } | ||
1622 | |||
1623 | int btrfs_qgroup_trace_subtree(struct btrfs_trans_handle *trans, | ||
1624 | struct btrfs_root *root, | ||
1625 | struct extent_buffer *root_eb, | ||
1626 | u64 root_gen, int root_level) | ||
1627 | { | ||
1628 | int ret = 0; | ||
1629 | int level; | ||
1630 | struct extent_buffer *eb = root_eb; | ||
1631 | struct btrfs_path *path = NULL; | ||
1632 | |||
1633 | BUG_ON(root_level < 0 || root_level > BTRFS_MAX_LEVEL); | ||
1634 | BUG_ON(root_eb == NULL); | ||
1635 | |||
1636 | if (!test_bit(BTRFS_FS_QUOTA_ENABLED, &root->fs_info->flags)) | ||
1637 | return 0; | ||
1638 | |||
1639 | if (!extent_buffer_uptodate(root_eb)) { | ||
1640 | ret = btrfs_read_buffer(root_eb, root_gen); | ||
1641 | if (ret) | ||
1642 | goto out; | ||
1643 | } | ||
1644 | |||
1645 | if (root_level == 0) { | ||
1646 | ret = btrfs_qgroup_trace_leaf_items(trans, root, root_eb); | ||
1647 | goto out; | ||
1648 | } | ||
1649 | |||
1650 | path = btrfs_alloc_path(); | ||
1651 | if (!path) | ||
1652 | return -ENOMEM; | ||
1653 | |||
1654 | /* | ||
1655 | * Walk down the tree. Missing extent blocks are filled in as | ||
1656 | * we go. Metadata is accounted every time we read a new | ||
1657 | * extent block. | ||
1658 | * | ||
1659 | * When we reach a leaf, we account for file extent items in it, | ||
1660 | * walk back up the tree (adjusting slot pointers as we go) | ||
1661 | * and restart the search process. | ||
1662 | */ | ||
1663 | extent_buffer_get(root_eb); /* For path */ | ||
1664 | path->nodes[root_level] = root_eb; | ||
1665 | path->slots[root_level] = 0; | ||
1666 | path->locks[root_level] = 0; /* so release_path doesn't try to unlock */ | ||
1667 | walk_down: | ||
1668 | level = root_level; | ||
1669 | while (level >= 0) { | ||
1670 | if (path->nodes[level] == NULL) { | ||
1671 | int parent_slot; | ||
1672 | u64 child_gen; | ||
1673 | u64 child_bytenr; | ||
1674 | |||
1675 | /* | ||
1676 | * We need to get child blockptr/gen from parent before | ||
1677 | * we can read it. | ||
1678 | */ | ||
1679 | eb = path->nodes[level + 1]; | ||
1680 | parent_slot = path->slots[level + 1]; | ||
1681 | child_bytenr = btrfs_node_blockptr(eb, parent_slot); | ||
1682 | child_gen = btrfs_node_ptr_generation(eb, parent_slot); | ||
1683 | |||
1684 | eb = read_tree_block(root, child_bytenr, child_gen); | ||
1685 | if (IS_ERR(eb)) { | ||
1686 | ret = PTR_ERR(eb); | ||
1687 | goto out; | ||
1688 | } else if (!extent_buffer_uptodate(eb)) { | ||
1689 | free_extent_buffer(eb); | ||
1690 | ret = -EIO; | ||
1691 | goto out; | ||
1692 | } | ||
1693 | |||
1694 | path->nodes[level] = eb; | ||
1695 | path->slots[level] = 0; | ||
1696 | |||
1697 | btrfs_tree_read_lock(eb); | ||
1698 | btrfs_set_lock_blocking_rw(eb, BTRFS_READ_LOCK); | ||
1699 | path->locks[level] = BTRFS_READ_LOCK_BLOCKING; | ||
1700 | |||
1701 | ret = btrfs_qgroup_trace_extent(trans, | ||
1702 | root->fs_info, child_bytenr, | ||
1703 | root->nodesize, GFP_NOFS); | ||
1704 | if (ret) | ||
1705 | goto out; | ||
1706 | } | ||
1707 | |||
1708 | if (level == 0) { | ||
1709 | ret = btrfs_qgroup_trace_leaf_items(trans, root, | ||
1710 | path->nodes[level]); | ||
1711 | if (ret) | ||
1712 | goto out; | ||
1713 | |||
1714 | /* Nonzero return here means we completed our search */ | ||
1715 | ret = adjust_slots_upwards(root, path, root_level); | ||
1716 | if (ret) | ||
1717 | break; | ||
1718 | |||
1719 | /* Restart search with new slots */ | ||
1720 | goto walk_down; | ||
1721 | } | ||
1722 | |||
1723 | level--; | ||
1724 | } | ||
1725 | |||
1726 | ret = 0; | ||
1727 | out: | ||
1728 | btrfs_free_path(path); | ||
1729 | |||
1730 | return ret; | ||
1731 | } | ||
1732 | |||
1513 | #define UPDATE_NEW 0 | 1733 | #define UPDATE_NEW 0 |
1514 | #define UPDATE_OLD 1 | 1734 | #define UPDATE_OLD 1 |
1515 | /* | 1735 | /* |
@@ -1535,30 +1755,30 @@ static int qgroup_update_refcnt(struct btrfs_fs_info *fs_info, | |||
1535 | continue; | 1755 | continue; |
1536 | 1756 | ||
1537 | ulist_reinit(tmp); | 1757 | ulist_reinit(tmp); |
1538 | ret = ulist_add(qgroups, qg->qgroupid, ptr_to_u64(qg), | 1758 | ret = ulist_add(qgroups, qg->qgroupid, qgroup_to_aux(qg), |
1539 | GFP_ATOMIC); | 1759 | GFP_ATOMIC); |
1540 | if (ret < 0) | 1760 | if (ret < 0) |
1541 | return ret; | 1761 | return ret; |
1542 | ret = ulist_add(tmp, qg->qgroupid, ptr_to_u64(qg), GFP_ATOMIC); | 1762 | ret = ulist_add(tmp, qg->qgroupid, qgroup_to_aux(qg), GFP_ATOMIC); |
1543 | if (ret < 0) | 1763 | if (ret < 0) |
1544 | return ret; | 1764 | return ret; |
1545 | ULIST_ITER_INIT(&tmp_uiter); | 1765 | ULIST_ITER_INIT(&tmp_uiter); |
1546 | while ((tmp_unode = ulist_next(tmp, &tmp_uiter))) { | 1766 | while ((tmp_unode = ulist_next(tmp, &tmp_uiter))) { |
1547 | struct btrfs_qgroup_list *glist; | 1767 | struct btrfs_qgroup_list *glist; |
1548 | 1768 | ||
1549 | qg = u64_to_ptr(tmp_unode->aux); | 1769 | qg = unode_aux_to_qgroup(tmp_unode); |
1550 | if (update_old) | 1770 | if (update_old) |
1551 | btrfs_qgroup_update_old_refcnt(qg, seq, 1); | 1771 | btrfs_qgroup_update_old_refcnt(qg, seq, 1); |
1552 | else | 1772 | else |
1553 | btrfs_qgroup_update_new_refcnt(qg, seq, 1); | 1773 | btrfs_qgroup_update_new_refcnt(qg, seq, 1); |
1554 | list_for_each_entry(glist, &qg->groups, next_group) { | 1774 | list_for_each_entry(glist, &qg->groups, next_group) { |
1555 | ret = ulist_add(qgroups, glist->group->qgroupid, | 1775 | ret = ulist_add(qgroups, glist->group->qgroupid, |
1556 | ptr_to_u64(glist->group), | 1776 | qgroup_to_aux(glist->group), |
1557 | GFP_ATOMIC); | 1777 | GFP_ATOMIC); |
1558 | if (ret < 0) | 1778 | if (ret < 0) |
1559 | return ret; | 1779 | return ret; |
1560 | ret = ulist_add(tmp, glist->group->qgroupid, | 1780 | ret = ulist_add(tmp, glist->group->qgroupid, |
1561 | ptr_to_u64(glist->group), | 1781 | qgroup_to_aux(glist->group), |
1562 | GFP_ATOMIC); | 1782 | GFP_ATOMIC); |
1563 | if (ret < 0) | 1783 | if (ret < 0) |
1564 | return ret; | 1784 | return ret; |
@@ -1619,7 +1839,7 @@ static int qgroup_update_counters(struct btrfs_fs_info *fs_info, | |||
1619 | while ((unode = ulist_next(qgroups, &uiter))) { | 1839 | while ((unode = ulist_next(qgroups, &uiter))) { |
1620 | bool dirty = false; | 1840 | bool dirty = false; |
1621 | 1841 | ||
1622 | qg = u64_to_ptr(unode->aux); | 1842 | qg = unode_aux_to_qgroup(unode); |
1623 | cur_old_count = btrfs_qgroup_get_old_refcnt(qg, seq); | 1843 | cur_old_count = btrfs_qgroup_get_old_refcnt(qg, seq); |
1624 | cur_new_count = btrfs_qgroup_get_new_refcnt(qg, seq); | 1844 | cur_new_count = btrfs_qgroup_get_new_refcnt(qg, seq); |
1625 | 1845 | ||
@@ -2125,7 +2345,7 @@ static int qgroup_reserve(struct btrfs_root *root, u64 num_bytes) | |||
2125 | struct btrfs_qgroup *qg; | 2345 | struct btrfs_qgroup *qg; |
2126 | struct btrfs_qgroup_list *glist; | 2346 | struct btrfs_qgroup_list *glist; |
2127 | 2347 | ||
2128 | qg = u64_to_ptr(unode->aux); | 2348 | qg = unode_aux_to_qgroup(unode); |
2129 | 2349 | ||
2130 | if ((qg->lim_flags & BTRFS_QGROUP_LIMIT_MAX_RFER) && | 2350 | if ((qg->lim_flags & BTRFS_QGROUP_LIMIT_MAX_RFER) && |
2131 | qg->reserved + (s64)qg->rfer + num_bytes > | 2351 | qg->reserved + (s64)qg->rfer + num_bytes > |
@@ -2157,7 +2377,7 @@ static int qgroup_reserve(struct btrfs_root *root, u64 num_bytes) | |||
2157 | while ((unode = ulist_next(fs_info->qgroup_ulist, &uiter))) { | 2377 | while ((unode = ulist_next(fs_info->qgroup_ulist, &uiter))) { |
2158 | struct btrfs_qgroup *qg; | 2378 | struct btrfs_qgroup *qg; |
2159 | 2379 | ||
2160 | qg = u64_to_ptr(unode->aux); | 2380 | qg = unode_aux_to_qgroup(unode); |
2161 | 2381 | ||
2162 | qg->reserved += num_bytes; | 2382 | qg->reserved += num_bytes; |
2163 | } | 2383 | } |
@@ -2202,7 +2422,7 @@ void btrfs_qgroup_free_refroot(struct btrfs_fs_info *fs_info, | |||
2202 | struct btrfs_qgroup *qg; | 2422 | struct btrfs_qgroup *qg; |
2203 | struct btrfs_qgroup_list *glist; | 2423 | struct btrfs_qgroup_list *glist; |
2204 | 2424 | ||
2205 | qg = u64_to_ptr(unode->aux); | 2425 | qg = unode_aux_to_qgroup(unode); |
2206 | 2426 | ||
2207 | qg->reserved -= num_bytes; | 2427 | qg->reserved -= num_bytes; |
2208 | 2428 | ||
diff --git a/fs/btrfs/qgroup.h b/fs/btrfs/qgroup.h index 1bc64c864b62..99c879dbedc1 100644 --- a/fs/btrfs/qgroup.h +++ b/fs/btrfs/qgroup.h | |||
@@ -23,6 +23,34 @@ | |||
23 | #include "delayed-ref.h" | 23 | #include "delayed-ref.h" |
24 | 24 | ||
25 | /* | 25 | /* |
26 | * Btrfs qgroup overview | ||
27 | * | ||
28 | * Btrfs qgroup splits into 3 main part: | ||
29 | * 1) Reserve | ||
30 | * Reserve metadata/data space for incoming operations | ||
31 | * Affect how qgroup limit works | ||
32 | * | ||
33 | * 2) Trace | ||
34 | * Tell btrfs qgroup to trace dirty extents. | ||
35 | * | ||
36 | * Dirty extents including: | ||
37 | * - Newly allocated extents | ||
38 | * - Extents going to be deleted (in this trans) | ||
39 | * - Extents whose owner is going to be modified | ||
40 | * | ||
41 | * This is the main part affects whether qgroup numbers will stay | ||
42 | * consistent. | ||
43 | * Btrfs qgroup can trace clean extents and won't cause any problem, | ||
44 | * but it will consume extra CPU time, it should be avoided if possible. | ||
45 | * | ||
46 | * 3) Account | ||
47 | * Btrfs qgroup will updates its numbers, based on dirty extents traced | ||
48 | * in previous step. | ||
49 | * | ||
50 | * Normally at qgroup rescan and transaction commit time. | ||
51 | */ | ||
52 | |||
53 | /* | ||
26 | * Record a dirty extent, and info qgroup to update quota on it | 54 | * Record a dirty extent, and info qgroup to update quota on it |
27 | * TODO: Use kmem cache to alloc it. | 55 | * TODO: Use kmem cache to alloc it. |
28 | */ | 56 | */ |
@@ -65,8 +93,8 @@ struct btrfs_delayed_extent_op; | |||
65 | int btrfs_qgroup_prepare_account_extents(struct btrfs_trans_handle *trans, | 93 | int btrfs_qgroup_prepare_account_extents(struct btrfs_trans_handle *trans, |
66 | struct btrfs_fs_info *fs_info); | 94 | struct btrfs_fs_info *fs_info); |
67 | /* | 95 | /* |
68 | * Insert one dirty extent record into @delayed_refs, informing qgroup to | 96 | * Inform qgroup to trace one dirty extent, its info is recorded in @record. |
69 | * account that extent at commit trans time. | 97 | * So qgroup can account it at commit trans time. |
70 | * | 98 | * |
71 | * No lock version, caller must acquire delayed ref lock and allocate memory. | 99 | * No lock version, caller must acquire delayed ref lock and allocate memory. |
72 | * | 100 | * |
@@ -74,14 +102,15 @@ int btrfs_qgroup_prepare_account_extents(struct btrfs_trans_handle *trans, | |||
74 | * Return >0 for existing record, caller can free @record safely. | 102 | * Return >0 for existing record, caller can free @record safely. |
75 | * Error is not possible | 103 | * Error is not possible |
76 | */ | 104 | */ |
77 | int btrfs_qgroup_insert_dirty_extent_nolock( | 105 | int btrfs_qgroup_trace_extent_nolock( |
78 | struct btrfs_fs_info *fs_info, | 106 | struct btrfs_fs_info *fs_info, |
79 | struct btrfs_delayed_ref_root *delayed_refs, | 107 | struct btrfs_delayed_ref_root *delayed_refs, |
80 | struct btrfs_qgroup_extent_record *record); | 108 | struct btrfs_qgroup_extent_record *record); |
81 | 109 | ||
82 | /* | 110 | /* |
83 | * Insert one dirty extent record into @delayed_refs, informing qgroup to | 111 | * Inform qgroup to trace one dirty extent, specified by @bytenr and |
84 | * account that extent at commit trans time. | 112 | * @num_bytes. |
113 | * So qgroup can account it at commit trans time. | ||
85 | * | 114 | * |
86 | * Better encapsulated version. | 115 | * Better encapsulated version. |
87 | * | 116 | * |
@@ -89,10 +118,33 @@ int btrfs_qgroup_insert_dirty_extent_nolock( | |||
89 | * Return <0 for error, like memory allocation failure or invalid parameter | 118 | * Return <0 for error, like memory allocation failure or invalid parameter |
90 | * (NULL trans) | 119 | * (NULL trans) |
91 | */ | 120 | */ |
92 | int btrfs_qgroup_insert_dirty_extent(struct btrfs_trans_handle *trans, | 121 | int btrfs_qgroup_trace_extent(struct btrfs_trans_handle *trans, |
93 | struct btrfs_fs_info *fs_info, u64 bytenr, u64 num_bytes, | 122 | struct btrfs_fs_info *fs_info, u64 bytenr, u64 num_bytes, |
94 | gfp_t gfp_flag); | 123 | gfp_t gfp_flag); |
95 | 124 | ||
125 | /* | ||
126 | * Inform qgroup to trace all leaf items of data | ||
127 | * | ||
128 | * Return 0 for success | ||
129 | * Return <0 for error(ENOMEM) | ||
130 | */ | ||
131 | int btrfs_qgroup_trace_leaf_items(struct btrfs_trans_handle *trans, | ||
132 | struct btrfs_root *root, | ||
133 | struct extent_buffer *eb); | ||
134 | /* | ||
135 | * Inform qgroup to trace a whole subtree, including all its child tree | ||
136 | * blocks and data. | ||
137 | * The root tree block is specified by @root_eb. | ||
138 | * | ||
139 | * Normally used by relocation(tree block swap) and subvolume deletion. | ||
140 | * | ||
141 | * Return 0 for success | ||
142 | * Return <0 for error(ENOMEM or tree search error) | ||
143 | */ | ||
144 | int btrfs_qgroup_trace_subtree(struct btrfs_trans_handle *trans, | ||
145 | struct btrfs_root *root, | ||
146 | struct extent_buffer *root_eb, | ||
147 | u64 root_gen, int root_level); | ||
96 | int | 148 | int |
97 | btrfs_qgroup_account_extent(struct btrfs_trans_handle *trans, | 149 | btrfs_qgroup_account_extent(struct btrfs_trans_handle *trans, |
98 | struct btrfs_fs_info *fs_info, | 150 | struct btrfs_fs_info *fs_info, |
diff --git a/fs/btrfs/raid56.c b/fs/btrfs/raid56.c index d016d4a79864..eece126d6973 100644 --- a/fs/btrfs/raid56.c +++ b/fs/btrfs/raid56.c | |||
@@ -1144,10 +1144,10 @@ static void validate_rbio_for_rmw(struct btrfs_raid_bio *rbio) | |||
1144 | static void index_rbio_pages(struct btrfs_raid_bio *rbio) | 1144 | static void index_rbio_pages(struct btrfs_raid_bio *rbio) |
1145 | { | 1145 | { |
1146 | struct bio *bio; | 1146 | struct bio *bio; |
1147 | struct bio_vec *bvec; | ||
1147 | u64 start; | 1148 | u64 start; |
1148 | unsigned long stripe_offset; | 1149 | unsigned long stripe_offset; |
1149 | unsigned long page_index; | 1150 | unsigned long page_index; |
1150 | struct page *p; | ||
1151 | int i; | 1151 | int i; |
1152 | 1152 | ||
1153 | spin_lock_irq(&rbio->bio_list_lock); | 1153 | spin_lock_irq(&rbio->bio_list_lock); |
@@ -1156,10 +1156,8 @@ static void index_rbio_pages(struct btrfs_raid_bio *rbio) | |||
1156 | stripe_offset = start - rbio->bbio->raid_map[0]; | 1156 | stripe_offset = start - rbio->bbio->raid_map[0]; |
1157 | page_index = stripe_offset >> PAGE_SHIFT; | 1157 | page_index = stripe_offset >> PAGE_SHIFT; |
1158 | 1158 | ||
1159 | for (i = 0; i < bio->bi_vcnt; i++) { | 1159 | bio_for_each_segment_all(bvec, bio, i) |
1160 | p = bio->bi_io_vec[i].bv_page; | 1160 | rbio->bio_pages[page_index + i] = bvec->bv_page; |
1161 | rbio->bio_pages[page_index + i] = p; | ||
1162 | } | ||
1163 | } | 1161 | } |
1164 | spin_unlock_irq(&rbio->bio_list_lock); | 1162 | spin_unlock_irq(&rbio->bio_list_lock); |
1165 | } | 1163 | } |
@@ -1433,13 +1431,11 @@ static int fail_bio_stripe(struct btrfs_raid_bio *rbio, | |||
1433 | */ | 1431 | */ |
1434 | static void set_bio_pages_uptodate(struct bio *bio) | 1432 | static void set_bio_pages_uptodate(struct bio *bio) |
1435 | { | 1433 | { |
1434 | struct bio_vec *bvec; | ||
1436 | int i; | 1435 | int i; |
1437 | struct page *p; | ||
1438 | 1436 | ||
1439 | for (i = 0; i < bio->bi_vcnt; i++) { | 1437 | bio_for_each_segment_all(bvec, bio, i) |
1440 | p = bio->bi_io_vec[i].bv_page; | 1438 | SetPageUptodate(bvec->bv_page); |
1441 | SetPageUptodate(p); | ||
1442 | } | ||
1443 | } | 1439 | } |
1444 | 1440 | ||
1445 | /* | 1441 | /* |
diff --git a/fs/btrfs/reada.c b/fs/btrfs/reada.c index 75bab76739be..f0beb63a6d82 100644 --- a/fs/btrfs/reada.c +++ b/fs/btrfs/reada.c | |||
@@ -107,18 +107,14 @@ static int reada_add_block(struct reada_control *rc, u64 logical, | |||
107 | /* in case of err, eb might be NULL */ | 107 | /* in case of err, eb might be NULL */ |
108 | static void __readahead_hook(struct btrfs_fs_info *fs_info, | 108 | static void __readahead_hook(struct btrfs_fs_info *fs_info, |
109 | struct reada_extent *re, struct extent_buffer *eb, | 109 | struct reada_extent *re, struct extent_buffer *eb, |
110 | u64 start, int err) | 110 | int err) |
111 | { | 111 | { |
112 | int level = 0; | ||
113 | int nritems; | 112 | int nritems; |
114 | int i; | 113 | int i; |
115 | u64 bytenr; | 114 | u64 bytenr; |
116 | u64 generation; | 115 | u64 generation; |
117 | struct list_head list; | 116 | struct list_head list; |
118 | 117 | ||
119 | if (eb) | ||
120 | level = btrfs_header_level(eb); | ||
121 | |||
122 | spin_lock(&re->lock); | 118 | spin_lock(&re->lock); |
123 | /* | 119 | /* |
124 | * just take the full list from the extent. afterwards we | 120 | * just take the full list from the extent. afterwards we |
@@ -143,7 +139,7 @@ static void __readahead_hook(struct btrfs_fs_info *fs_info, | |||
143 | * trigger more readahead depending from the content, e.g. | 139 | * trigger more readahead depending from the content, e.g. |
144 | * fetch the checksums for the extents in the leaf. | 140 | * fetch the checksums for the extents in the leaf. |
145 | */ | 141 | */ |
146 | if (!level) | 142 | if (!btrfs_header_level(eb)) |
147 | goto cleanup; | 143 | goto cleanup; |
148 | 144 | ||
149 | nritems = btrfs_header_nritems(eb); | 145 | nritems = btrfs_header_nritems(eb); |
@@ -213,12 +209,8 @@ cleanup: | |||
213 | return; | 209 | return; |
214 | } | 210 | } |
215 | 211 | ||
216 | /* | ||
217 | * start is passed separately in case eb in NULL, which may be the case with | ||
218 | * failed I/O | ||
219 | */ | ||
220 | int btree_readahead_hook(struct btrfs_fs_info *fs_info, | 212 | int btree_readahead_hook(struct btrfs_fs_info *fs_info, |
221 | struct extent_buffer *eb, u64 start, int err) | 213 | struct extent_buffer *eb, int err) |
222 | { | 214 | { |
223 | int ret = 0; | 215 | int ret = 0; |
224 | struct reada_extent *re; | 216 | struct reada_extent *re; |
@@ -226,7 +218,7 @@ int btree_readahead_hook(struct btrfs_fs_info *fs_info, | |||
226 | /* find extent */ | 218 | /* find extent */ |
227 | spin_lock(&fs_info->reada_lock); | 219 | spin_lock(&fs_info->reada_lock); |
228 | re = radix_tree_lookup(&fs_info->reada_tree, | 220 | re = radix_tree_lookup(&fs_info->reada_tree, |
229 | start >> PAGE_SHIFT); | 221 | eb->start >> PAGE_SHIFT); |
230 | if (re) | 222 | if (re) |
231 | re->refcnt++; | 223 | re->refcnt++; |
232 | spin_unlock(&fs_info->reada_lock); | 224 | spin_unlock(&fs_info->reada_lock); |
@@ -235,7 +227,7 @@ int btree_readahead_hook(struct btrfs_fs_info *fs_info, | |||
235 | goto start_machine; | 227 | goto start_machine; |
236 | } | 228 | } |
237 | 229 | ||
238 | __readahead_hook(fs_info, re, eb, start, err); | 230 | __readahead_hook(fs_info, re, eb, err); |
239 | reada_extent_put(fs_info, re); /* our ref */ | 231 | reada_extent_put(fs_info, re); /* our ref */ |
240 | 232 | ||
241 | start_machine: | 233 | start_machine: |
@@ -354,8 +346,8 @@ static struct reada_extent *reada_find_extent(struct btrfs_root *root, | |||
354 | * map block | 346 | * map block |
355 | */ | 347 | */ |
356 | length = blocksize; | 348 | length = blocksize; |
357 | ret = btrfs_map_block(fs_info, REQ_GET_READ_MIRRORS, logical, &length, | 349 | ret = btrfs_map_block(fs_info, BTRFS_MAP_GET_READ_MIRRORS, logical, |
358 | &bbio, 0); | 350 | &length, &bbio, 0); |
359 | if (ret || !bbio || length < blocksize) | 351 | if (ret || !bbio || length < blocksize) |
360 | goto error; | 352 | goto error; |
361 | 353 | ||
@@ -401,7 +393,6 @@ static struct reada_extent *reada_find_extent(struct btrfs_root *root, | |||
401 | ret = radix_tree_insert(&fs_info->reada_tree, index, re); | 393 | ret = radix_tree_insert(&fs_info->reada_tree, index, re); |
402 | if (ret == -EEXIST) { | 394 | if (ret == -EEXIST) { |
403 | re_exist = radix_tree_lookup(&fs_info->reada_tree, index); | 395 | re_exist = radix_tree_lookup(&fs_info->reada_tree, index); |
404 | BUG_ON(!re_exist); | ||
405 | re_exist->refcnt++; | 396 | re_exist->refcnt++; |
406 | spin_unlock(&fs_info->reada_lock); | 397 | spin_unlock(&fs_info->reada_lock); |
407 | btrfs_dev_replace_unlock(&fs_info->dev_replace, 0); | 398 | btrfs_dev_replace_unlock(&fs_info->dev_replace, 0); |
@@ -448,7 +439,6 @@ static struct reada_extent *reada_find_extent(struct btrfs_root *root, | |||
448 | /* ignore whether the entry was inserted */ | 439 | /* ignore whether the entry was inserted */ |
449 | radix_tree_delete(&dev->reada_extents, index); | 440 | radix_tree_delete(&dev->reada_extents, index); |
450 | } | 441 | } |
451 | BUG_ON(fs_info == NULL); | ||
452 | radix_tree_delete(&fs_info->reada_tree, index); | 442 | radix_tree_delete(&fs_info->reada_tree, index); |
453 | spin_unlock(&fs_info->reada_lock); | 443 | spin_unlock(&fs_info->reada_lock); |
454 | btrfs_dev_replace_unlock(&fs_info->dev_replace, 0); | 444 | btrfs_dev_replace_unlock(&fs_info->dev_replace, 0); |
@@ -717,9 +707,9 @@ static int reada_start_machine_dev(struct btrfs_fs_info *fs_info, | |||
717 | ret = reada_tree_block_flagged(fs_info->extent_root, logical, | 707 | ret = reada_tree_block_flagged(fs_info->extent_root, logical, |
718 | mirror_num, &eb); | 708 | mirror_num, &eb); |
719 | if (ret) | 709 | if (ret) |
720 | __readahead_hook(fs_info, re, NULL, logical, ret); | 710 | __readahead_hook(fs_info, re, NULL, ret); |
721 | else if (eb) | 711 | else if (eb) |
722 | __readahead_hook(fs_info, re, eb, eb->start, ret); | 712 | __readahead_hook(fs_info, re, eb, ret); |
723 | 713 | ||
724 | if (eb) | 714 | if (eb) |
725 | free_extent_buffer(eb); | 715 | free_extent_buffer(eb); |
diff --git a/fs/btrfs/relocation.c b/fs/btrfs/relocation.c index c4af0cdb783d..3dc7232aa038 100644 --- a/fs/btrfs/relocation.c +++ b/fs/btrfs/relocation.c | |||
@@ -1901,6 +1901,29 @@ again: | |||
1901 | BUG_ON(ret); | 1901 | BUG_ON(ret); |
1902 | 1902 | ||
1903 | /* | 1903 | /* |
1904 | * Info qgroup to trace both subtrees. | ||
1905 | * | ||
1906 | * We must trace both trees. | ||
1907 | * 1) Tree reloc subtree | ||
1908 | * If not traced, we will leak data numbers | ||
1909 | * 2) Fs subtree | ||
1910 | * If not traced, we will double count old data | ||
1911 | * and tree block numbers, if current trans doesn't free | ||
1912 | * data reloc tree inode. | ||
1913 | */ | ||
1914 | ret = btrfs_qgroup_trace_subtree(trans, src, parent, | ||
1915 | btrfs_header_generation(parent), | ||
1916 | btrfs_header_level(parent)); | ||
1917 | if (ret < 0) | ||
1918 | break; | ||
1919 | ret = btrfs_qgroup_trace_subtree(trans, dest, | ||
1920 | path->nodes[level], | ||
1921 | btrfs_header_generation(path->nodes[level]), | ||
1922 | btrfs_header_level(path->nodes[level])); | ||
1923 | if (ret < 0) | ||
1924 | break; | ||
1925 | |||
1926 | /* | ||
1904 | * swap blocks in fs tree and reloc tree. | 1927 | * swap blocks in fs tree and reloc tree. |
1905 | */ | 1928 | */ |
1906 | btrfs_set_node_blockptr(parent, slot, new_bytenr); | 1929 | btrfs_set_node_blockptr(parent, slot, new_bytenr); |
@@ -3949,90 +3972,6 @@ int prepare_to_relocate(struct reloc_control *rc) | |||
3949 | return 0; | 3972 | return 0; |
3950 | } | 3973 | } |
3951 | 3974 | ||
3952 | /* | ||
3953 | * Qgroup fixer for data chunk relocation. | ||
3954 | * The data relocation is done in the following steps | ||
3955 | * 1) Copy data extents into data reloc tree | ||
3956 | * 2) Create tree reloc tree(special snapshot) for related subvolumes | ||
3957 | * 3) Modify file extents in tree reloc tree | ||
3958 | * 4) Merge tree reloc tree with original fs tree, by swapping tree blocks | ||
3959 | * | ||
3960 | * The problem is, data and tree reloc tree are not accounted to qgroup, | ||
3961 | * and 4) will only info qgroup to track tree blocks change, not file extents | ||
3962 | * in the tree blocks. | ||
3963 | * | ||
3964 | * The good news is, related data extents are all in data reloc tree, so we | ||
3965 | * only need to info qgroup to track all file extents in data reloc tree | ||
3966 | * before commit trans. | ||
3967 | */ | ||
3968 | static int qgroup_fix_relocated_data_extents(struct btrfs_trans_handle *trans, | ||
3969 | struct reloc_control *rc) | ||
3970 | { | ||
3971 | struct btrfs_fs_info *fs_info = rc->extent_root->fs_info; | ||
3972 | struct inode *inode = rc->data_inode; | ||
3973 | struct btrfs_root *data_reloc_root = BTRFS_I(inode)->root; | ||
3974 | struct btrfs_path *path; | ||
3975 | struct btrfs_key key; | ||
3976 | int ret = 0; | ||
3977 | |||
3978 | if (!test_bit(BTRFS_FS_QUOTA_ENABLED, &fs_info->flags)) | ||
3979 | return 0; | ||
3980 | |||
3981 | /* | ||
3982 | * Only for stage where we update data pointers the qgroup fix is | ||
3983 | * valid. | ||
3984 | * For MOVING_DATA stage, we will miss the timing of swapping tree | ||
3985 | * blocks, and won't fix it. | ||
3986 | */ | ||
3987 | if (!(rc->stage == UPDATE_DATA_PTRS && rc->extents_found)) | ||
3988 | return 0; | ||
3989 | |||
3990 | path = btrfs_alloc_path(); | ||
3991 | if (!path) | ||
3992 | return -ENOMEM; | ||
3993 | key.objectid = btrfs_ino(inode); | ||
3994 | key.type = BTRFS_EXTENT_DATA_KEY; | ||
3995 | key.offset = 0; | ||
3996 | |||
3997 | ret = btrfs_search_slot(NULL, data_reloc_root, &key, path, 0, 0); | ||
3998 | if (ret < 0) | ||
3999 | goto out; | ||
4000 | |||
4001 | lock_extent(&BTRFS_I(inode)->io_tree, 0, (u64)-1); | ||
4002 | while (1) { | ||
4003 | struct btrfs_file_extent_item *fi; | ||
4004 | |||
4005 | btrfs_item_key_to_cpu(path->nodes[0], &key, path->slots[0]); | ||
4006 | if (key.objectid > btrfs_ino(inode)) | ||
4007 | break; | ||
4008 | if (key.type != BTRFS_EXTENT_DATA_KEY) | ||
4009 | goto next; | ||
4010 | fi = btrfs_item_ptr(path->nodes[0], path->slots[0], | ||
4011 | struct btrfs_file_extent_item); | ||
4012 | if (btrfs_file_extent_type(path->nodes[0], fi) != | ||
4013 | BTRFS_FILE_EXTENT_REG) | ||
4014 | goto next; | ||
4015 | ret = btrfs_qgroup_insert_dirty_extent(trans, fs_info, | ||
4016 | btrfs_file_extent_disk_bytenr(path->nodes[0], fi), | ||
4017 | btrfs_file_extent_disk_num_bytes(path->nodes[0], fi), | ||
4018 | GFP_NOFS); | ||
4019 | if (ret < 0) | ||
4020 | break; | ||
4021 | next: | ||
4022 | ret = btrfs_next_item(data_reloc_root, path); | ||
4023 | if (ret < 0) | ||
4024 | break; | ||
4025 | if (ret > 0) { | ||
4026 | ret = 0; | ||
4027 | break; | ||
4028 | } | ||
4029 | } | ||
4030 | unlock_extent(&BTRFS_I(inode)->io_tree, 0 , (u64)-1); | ||
4031 | out: | ||
4032 | btrfs_free_path(path); | ||
4033 | return ret; | ||
4034 | } | ||
4035 | |||
4036 | static noinline_for_stack int relocate_block_group(struct reloc_control *rc) | 3975 | static noinline_for_stack int relocate_block_group(struct reloc_control *rc) |
4037 | { | 3976 | { |
4038 | struct rb_root blocks = RB_ROOT; | 3977 | struct rb_root blocks = RB_ROOT; |
@@ -4223,13 +4162,6 @@ restart: | |||
4223 | err = PTR_ERR(trans); | 4162 | err = PTR_ERR(trans); |
4224 | goto out_free; | 4163 | goto out_free; |
4225 | } | 4164 | } |
4226 | ret = qgroup_fix_relocated_data_extents(trans, rc); | ||
4227 | if (ret < 0) { | ||
4228 | btrfs_abort_transaction(trans, ret); | ||
4229 | if (!err) | ||
4230 | err = ret; | ||
4231 | goto out_free; | ||
4232 | } | ||
4233 | btrfs_commit_transaction(trans, rc->extent_root); | 4165 | btrfs_commit_transaction(trans, rc->extent_root); |
4234 | out_free: | 4166 | out_free: |
4235 | btrfs_free_block_rsv(rc->extent_root, rc->block_rsv); | 4167 | btrfs_free_block_rsv(rc->extent_root, rc->block_rsv); |
@@ -4255,7 +4187,7 @@ static int __insert_orphan_inode(struct btrfs_trans_handle *trans, | |||
4255 | 4187 | ||
4256 | leaf = path->nodes[0]; | 4188 | leaf = path->nodes[0]; |
4257 | item = btrfs_item_ptr(leaf, path->slots[0], struct btrfs_inode_item); | 4189 | item = btrfs_item_ptr(leaf, path->slots[0], struct btrfs_inode_item); |
4258 | memset_extent_buffer(leaf, 0, (unsigned long)item, sizeof(*item)); | 4190 | memzero_extent_buffer(leaf, (unsigned long)item, sizeof(*item)); |
4259 | btrfs_set_inode_generation(leaf, item, 1); | 4191 | btrfs_set_inode_generation(leaf, item, 1); |
4260 | btrfs_set_inode_size(leaf, item, 0); | 4192 | btrfs_set_inode_size(leaf, item, 0); |
4261 | btrfs_set_inode_mode(leaf, item, S_IFREG | 0600); | 4193 | btrfs_set_inode_mode(leaf, item, S_IFREG | 0600); |
@@ -4333,6 +4265,45 @@ static struct reloc_control *alloc_reloc_control(struct btrfs_fs_info *fs_info) | |||
4333 | } | 4265 | } |
4334 | 4266 | ||
4335 | /* | 4267 | /* |
4268 | * Print the block group being relocated | ||
4269 | */ | ||
4270 | static void describe_relocation(struct btrfs_fs_info *fs_info, | ||
4271 | struct btrfs_block_group_cache *block_group) | ||
4272 | { | ||
4273 | char buf[128]; /* prefixed by a '|' that'll be dropped */ | ||
4274 | u64 flags = block_group->flags; | ||
4275 | |||
4276 | /* Shouldn't happen */ | ||
4277 | if (!flags) { | ||
4278 | strcpy(buf, "|NONE"); | ||
4279 | } else { | ||
4280 | char *bp = buf; | ||
4281 | |||
4282 | #define DESCRIBE_FLAG(f, d) \ | ||
4283 | if (flags & BTRFS_BLOCK_GROUP_##f) { \ | ||
4284 | bp += snprintf(bp, buf - bp + sizeof(buf), "|%s", d); \ | ||
4285 | flags &= ~BTRFS_BLOCK_GROUP_##f; \ | ||
4286 | } | ||
4287 | DESCRIBE_FLAG(DATA, "data"); | ||
4288 | DESCRIBE_FLAG(SYSTEM, "system"); | ||
4289 | DESCRIBE_FLAG(METADATA, "metadata"); | ||
4290 | DESCRIBE_FLAG(RAID0, "raid0"); | ||
4291 | DESCRIBE_FLAG(RAID1, "raid1"); | ||
4292 | DESCRIBE_FLAG(DUP, "dup"); | ||
4293 | DESCRIBE_FLAG(RAID10, "raid10"); | ||
4294 | DESCRIBE_FLAG(RAID5, "raid5"); | ||
4295 | DESCRIBE_FLAG(RAID6, "raid6"); | ||
4296 | if (flags) | ||
4297 | snprintf(buf, buf - bp + sizeof(buf), "|0x%llx", flags); | ||
4298 | #undef DESCRIBE_FLAG | ||
4299 | } | ||
4300 | |||
4301 | btrfs_info(fs_info, | ||
4302 | "relocating block group %llu flags %s", | ||
4303 | block_group->key.objectid, buf + 1); | ||
4304 | } | ||
4305 | |||
4306 | /* | ||
4336 | * function to relocate all extents in a block group. | 4307 | * function to relocate all extents in a block group. |
4337 | */ | 4308 | */ |
4338 | int btrfs_relocate_block_group(struct btrfs_root *extent_root, u64 group_start) | 4309 | int btrfs_relocate_block_group(struct btrfs_root *extent_root, u64 group_start) |
@@ -4388,9 +4359,7 @@ int btrfs_relocate_block_group(struct btrfs_root *extent_root, u64 group_start) | |||
4388 | goto out; | 4359 | goto out; |
4389 | } | 4360 | } |
4390 | 4361 | ||
4391 | btrfs_info(extent_root->fs_info, | 4362 | describe_relocation(extent_root->fs_info, rc->block_group); |
4392 | "relocating block group %llu flags %llu", | ||
4393 | rc->block_group->key.objectid, rc->block_group->flags); | ||
4394 | 4363 | ||
4395 | btrfs_wait_block_group_reservations(rc->block_group); | 4364 | btrfs_wait_block_group_reservations(rc->block_group); |
4396 | btrfs_wait_nocow_writers(rc->block_group); | 4365 | btrfs_wait_nocow_writers(rc->block_group); |
@@ -4598,11 +4567,6 @@ int btrfs_recover_relocation(struct btrfs_root *root) | |||
4598 | err = PTR_ERR(trans); | 4567 | err = PTR_ERR(trans); |
4599 | goto out_free; | 4568 | goto out_free; |
4600 | } | 4569 | } |
4601 | err = qgroup_fix_relocated_data_extents(trans, rc); | ||
4602 | if (err < 0) { | ||
4603 | btrfs_abort_transaction(trans, err); | ||
4604 | goto out_free; | ||
4605 | } | ||
4606 | err = btrfs_commit_transaction(trans, rc->extent_root); | 4570 | err = btrfs_commit_transaction(trans, rc->extent_root); |
4607 | out_free: | 4571 | out_free: |
4608 | kfree(rc); | 4572 | kfree(rc); |
diff --git a/fs/btrfs/scrub.c b/fs/btrfs/scrub.c index fffb9ab8526e..589d79219c18 100644 --- a/fs/btrfs/scrub.c +++ b/fs/btrfs/scrub.c | |||
@@ -1334,8 +1334,8 @@ static int scrub_setup_recheck_block(struct scrub_block *original_sblock, | |||
1334 | * with a length of PAGE_SIZE, each returned stripe | 1334 | * with a length of PAGE_SIZE, each returned stripe |
1335 | * represents one mirror | 1335 | * represents one mirror |
1336 | */ | 1336 | */ |
1337 | ret = btrfs_map_sblock(fs_info, REQ_GET_READ_MIRRORS, logical, | 1337 | ret = btrfs_map_sblock(fs_info, BTRFS_MAP_GET_READ_MIRRORS, |
1338 | &mapped_length, &bbio, 0, 1); | 1338 | logical, &mapped_length, &bbio, 0, 1); |
1339 | if (ret || !bbio || mapped_length < sublen) { | 1339 | if (ret || !bbio || mapped_length < sublen) { |
1340 | btrfs_put_bbio(bbio); | 1340 | btrfs_put_bbio(bbio); |
1341 | return -EIO; | 1341 | return -EIO; |
@@ -2191,8 +2191,8 @@ static void scrub_missing_raid56_pages(struct scrub_block *sblock) | |||
2191 | int ret; | 2191 | int ret; |
2192 | int i; | 2192 | int i; |
2193 | 2193 | ||
2194 | ret = btrfs_map_sblock(fs_info, REQ_GET_READ_MIRRORS, logical, &length, | 2194 | ret = btrfs_map_sblock(fs_info, BTRFS_MAP_GET_READ_MIRRORS, logical, |
2195 | &bbio, 0, 1); | 2195 | &length, &bbio, 0, 1); |
2196 | if (ret || !bbio || !bbio->raid_map) | 2196 | if (ret || !bbio || !bbio->raid_map) |
2197 | goto bbio_out; | 2197 | goto bbio_out; |
2198 | 2198 | ||
@@ -2778,7 +2778,7 @@ static void scrub_parity_check_and_repair(struct scrub_parity *sparity) | |||
2778 | goto out; | 2778 | goto out; |
2779 | 2779 | ||
2780 | length = sparity->logic_end - sparity->logic_start; | 2780 | length = sparity->logic_end - sparity->logic_start; |
2781 | ret = btrfs_map_sblock(sctx->dev_root->fs_info, WRITE, | 2781 | ret = btrfs_map_sblock(sctx->dev_root->fs_info, BTRFS_MAP_WRITE, |
2782 | sparity->logic_start, | 2782 | sparity->logic_start, |
2783 | &length, &bbio, 0, 1); | 2783 | &length, &bbio, 0, 1); |
2784 | if (ret || !bbio || !bbio->raid_map) | 2784 | if (ret || !bbio || !bbio->raid_map) |
@@ -2988,8 +2988,9 @@ again: | |||
2988 | 2988 | ||
2989 | mapped_length = extent_len; | 2989 | mapped_length = extent_len; |
2990 | bbio = NULL; | 2990 | bbio = NULL; |
2991 | ret = btrfs_map_block(fs_info, READ, extent_logical, | 2991 | ret = btrfs_map_block(fs_info, BTRFS_MAP_READ, |
2992 | &mapped_length, &bbio, 0); | 2992 | extent_logical, &mapped_length, &bbio, |
2993 | 0); | ||
2993 | if (!ret) { | 2994 | if (!ret) { |
2994 | if (!bbio || mapped_length < extent_len) | 2995 | if (!bbio || mapped_length < extent_len) |
2995 | ret = -EIO; | 2996 | ret = -EIO; |
@@ -4076,7 +4077,7 @@ static void scrub_remap_extent(struct btrfs_fs_info *fs_info, | |||
4076 | int ret; | 4077 | int ret; |
4077 | 4078 | ||
4078 | mapped_length = extent_len; | 4079 | mapped_length = extent_len; |
4079 | ret = btrfs_map_block(fs_info, READ, extent_logical, | 4080 | ret = btrfs_map_block(fs_info, BTRFS_MAP_READ, extent_logical, |
4080 | &mapped_length, &bbio, 0); | 4081 | &mapped_length, &bbio, 0); |
4081 | if (ret || !bbio || mapped_length < extent_len || | 4082 | if (ret || !bbio || mapped_length < extent_len || |
4082 | !bbio->stripes[0].dev->bdev) { | 4083 | !bbio->stripes[0].dev->bdev) { |
diff --git a/fs/btrfs/super.c b/fs/btrfs/super.c index 74ed5aae6cea..adec3a0b01d5 100644 --- a/fs/btrfs/super.c +++ b/fs/btrfs/super.c | |||
@@ -2086,10 +2086,6 @@ static int btrfs_statfs(struct dentry *dentry, struct kstatfs *buf) | |||
2086 | u64 thresh = 0; | 2086 | u64 thresh = 0; |
2087 | int mixed = 0; | 2087 | int mixed = 0; |
2088 | 2088 | ||
2089 | /* | ||
2090 | * holding chunk_mutex to avoid allocating new chunks, holding | ||
2091 | * device_list_mutex to avoid the device being removed | ||
2092 | */ | ||
2093 | rcu_read_lock(); | 2089 | rcu_read_lock(); |
2094 | list_for_each_entry_rcu(found, head, list) { | 2090 | list_for_each_entry_rcu(found, head, list) { |
2095 | if (found->flags & BTRFS_BLOCK_GROUP_DATA) { | 2091 | if (found->flags & BTRFS_BLOCK_GROUP_DATA) { |
diff --git a/fs/btrfs/tests/extent-io-tests.c b/fs/btrfs/tests/extent-io-tests.c index caad80bb9bd0..2c7a0a922510 100644 --- a/fs/btrfs/tests/extent-io-tests.c +++ b/fs/btrfs/tests/extent-io-tests.c | |||
@@ -306,7 +306,7 @@ static int __test_eb_bitmaps(unsigned long *bitmap, struct extent_buffer *eb, | |||
306 | int ret; | 306 | int ret; |
307 | 307 | ||
308 | memset(bitmap, 0, len); | 308 | memset(bitmap, 0, len); |
309 | memset_extent_buffer(eb, 0, 0, len); | 309 | memzero_extent_buffer(eb, 0, len); |
310 | if (memcmp_extent_buffer(eb, bitmap, 0, len) != 0) { | 310 | if (memcmp_extent_buffer(eb, bitmap, 0, len) != 0) { |
311 | test_msg("Bitmap was not zeroed\n"); | 311 | test_msg("Bitmap was not zeroed\n"); |
312 | return -EINVAL; | 312 | return -EINVAL; |
diff --git a/fs/btrfs/tree-log.c b/fs/btrfs/tree-log.c index 3d33c4e41e5f..e0478f51cf16 100644 --- a/fs/btrfs/tree-log.c +++ b/fs/btrfs/tree-log.c | |||
@@ -689,7 +689,7 @@ static noinline int replay_one_extent(struct btrfs_trans_handle *trans, | |||
689 | * as the owner of the file extent changed from log tree | 689 | * as the owner of the file extent changed from log tree |
690 | * (doesn't affect qgroup) to fs/file tree(affects qgroup) | 690 | * (doesn't affect qgroup) to fs/file tree(affects qgroup) |
691 | */ | 691 | */ |
692 | ret = btrfs_qgroup_insert_dirty_extent(trans, root->fs_info, | 692 | ret = btrfs_qgroup_trace_extent(trans, root->fs_info, |
693 | btrfs_file_extent_disk_bytenr(eb, item), | 693 | btrfs_file_extent_disk_bytenr(eb, item), |
694 | btrfs_file_extent_disk_num_bytes(eb, item), | 694 | btrfs_file_extent_disk_num_bytes(eb, item), |
695 | GFP_NOFS); | 695 | GFP_NOFS); |
diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c index 71a60cc01451..1886b94f13ac 100644 --- a/fs/btrfs/volumes.c +++ b/fs/btrfs/volumes.c | |||
@@ -1595,8 +1595,8 @@ static int btrfs_alloc_dev_extent(struct btrfs_trans_handle *trans, | |||
1595 | btrfs_set_dev_extent_chunk_objectid(leaf, extent, chunk_objectid); | 1595 | btrfs_set_dev_extent_chunk_objectid(leaf, extent, chunk_objectid); |
1596 | btrfs_set_dev_extent_chunk_offset(leaf, extent, chunk_offset); | 1596 | btrfs_set_dev_extent_chunk_offset(leaf, extent, chunk_offset); |
1597 | 1597 | ||
1598 | write_extent_buffer(leaf, root->fs_info->chunk_tree_uuid, | 1598 | write_extent_buffer_chunk_tree_uuid(leaf, |
1599 | btrfs_dev_extent_chunk_tree_uuid(extent), BTRFS_UUID_SIZE); | 1599 | root->fs_info->chunk_tree_uuid); |
1600 | 1600 | ||
1601 | btrfs_set_dev_extent_length(leaf, extent, num_bytes); | 1601 | btrfs_set_dev_extent_length(leaf, extent, num_bytes); |
1602 | btrfs_mark_buffer_dirty(leaf); | 1602 | btrfs_mark_buffer_dirty(leaf); |
@@ -3062,7 +3062,7 @@ static int insert_balance_item(struct btrfs_root *root, | |||
3062 | leaf = path->nodes[0]; | 3062 | leaf = path->nodes[0]; |
3063 | item = btrfs_item_ptr(leaf, path->slots[0], struct btrfs_balance_item); | 3063 | item = btrfs_item_ptr(leaf, path->slots[0], struct btrfs_balance_item); |
3064 | 3064 | ||
3065 | memset_extent_buffer(leaf, 0, (unsigned long)item, sizeof(*item)); | 3065 | memzero_extent_buffer(leaf, (unsigned long)item, sizeof(*item)); |
3066 | 3066 | ||
3067 | btrfs_cpu_balance_args_to_disk(&disk_bargs, &bctl->data); | 3067 | btrfs_cpu_balance_args_to_disk(&disk_bargs, &bctl->data); |
3068 | btrfs_set_balance_data(leaf, item, &disk_bargs); | 3068 | btrfs_set_balance_data(leaf, item, &disk_bargs); |
@@ -5329,7 +5329,8 @@ void btrfs_put_bbio(struct btrfs_bio *bbio) | |||
5329 | kfree(bbio); | 5329 | kfree(bbio); |
5330 | } | 5330 | } |
5331 | 5331 | ||
5332 | static int __btrfs_map_block(struct btrfs_fs_info *fs_info, int op, | 5332 | static int __btrfs_map_block(struct btrfs_fs_info *fs_info, |
5333 | enum btrfs_map_op op, | ||
5333 | u64 logical, u64 *length, | 5334 | u64 logical, u64 *length, |
5334 | struct btrfs_bio **bbio_ret, | 5335 | struct btrfs_bio **bbio_ret, |
5335 | int mirror_num, int need_raid_map) | 5336 | int mirror_num, int need_raid_map) |
@@ -5414,7 +5415,7 @@ static int __btrfs_map_block(struct btrfs_fs_info *fs_info, int op, | |||
5414 | raid56_full_stripe_start *= full_stripe_len; | 5415 | raid56_full_stripe_start *= full_stripe_len; |
5415 | } | 5416 | } |
5416 | 5417 | ||
5417 | if (op == REQ_OP_DISCARD) { | 5418 | if (op == BTRFS_MAP_DISCARD) { |
5418 | /* we don't discard raid56 yet */ | 5419 | /* we don't discard raid56 yet */ |
5419 | if (map->type & BTRFS_BLOCK_GROUP_RAID56_MASK) { | 5420 | if (map->type & BTRFS_BLOCK_GROUP_RAID56_MASK) { |
5420 | ret = -EOPNOTSUPP; | 5421 | ret = -EOPNOTSUPP; |
@@ -5427,7 +5428,7 @@ static int __btrfs_map_block(struct btrfs_fs_info *fs_info, int op, | |||
5427 | For other RAID types and for RAID[56] reads, just allow a single | 5428 | For other RAID types and for RAID[56] reads, just allow a single |
5428 | stripe (on a single disk). */ | 5429 | stripe (on a single disk). */ |
5429 | if ((map->type & BTRFS_BLOCK_GROUP_RAID56_MASK) && | 5430 | if ((map->type & BTRFS_BLOCK_GROUP_RAID56_MASK) && |
5430 | (op == REQ_OP_WRITE)) { | 5431 | (op == BTRFS_MAP_WRITE)) { |
5431 | max_len = stripe_len * nr_data_stripes(map) - | 5432 | max_len = stripe_len * nr_data_stripes(map) - |
5432 | (offset - raid56_full_stripe_start); | 5433 | (offset - raid56_full_stripe_start); |
5433 | } else { | 5434 | } else { |
@@ -5452,8 +5453,8 @@ static int __btrfs_map_block(struct btrfs_fs_info *fs_info, int op, | |||
5452 | btrfs_dev_replace_set_lock_blocking(dev_replace); | 5453 | btrfs_dev_replace_set_lock_blocking(dev_replace); |
5453 | 5454 | ||
5454 | if (dev_replace_is_ongoing && mirror_num == map->num_stripes + 1 && | 5455 | if (dev_replace_is_ongoing && mirror_num == map->num_stripes + 1 && |
5455 | op != REQ_OP_WRITE && op != REQ_OP_DISCARD && | 5456 | op != BTRFS_MAP_WRITE && op != BTRFS_MAP_DISCARD && |
5456 | op != REQ_GET_READ_MIRRORS && dev_replace->tgtdev != NULL) { | 5457 | op != BTRFS_MAP_GET_READ_MIRRORS && dev_replace->tgtdev != NULL) { |
5457 | /* | 5458 | /* |
5458 | * in dev-replace case, for repair case (that's the only | 5459 | * in dev-replace case, for repair case (that's the only |
5459 | * case where the mirror is selected explicitly when | 5460 | * case where the mirror is selected explicitly when |
@@ -5474,7 +5475,7 @@ static int __btrfs_map_block(struct btrfs_fs_info *fs_info, int op, | |||
5474 | int found = 0; | 5475 | int found = 0; |
5475 | u64 physical_of_found = 0; | 5476 | u64 physical_of_found = 0; |
5476 | 5477 | ||
5477 | ret = __btrfs_map_block(fs_info, REQ_GET_READ_MIRRORS, | 5478 | ret = __btrfs_map_block(fs_info, BTRFS_MAP_GET_READ_MIRRORS, |
5478 | logical, &tmp_length, &tmp_bbio, 0, 0); | 5479 | logical, &tmp_length, &tmp_bbio, 0, 0); |
5479 | if (ret) { | 5480 | if (ret) { |
5480 | WARN_ON(tmp_bbio != NULL); | 5481 | WARN_ON(tmp_bbio != NULL); |
@@ -5484,7 +5485,7 @@ static int __btrfs_map_block(struct btrfs_fs_info *fs_info, int op, | |||
5484 | tmp_num_stripes = tmp_bbio->num_stripes; | 5485 | tmp_num_stripes = tmp_bbio->num_stripes; |
5485 | if (mirror_num > tmp_num_stripes) { | 5486 | if (mirror_num > tmp_num_stripes) { |
5486 | /* | 5487 | /* |
5487 | * REQ_GET_READ_MIRRORS does not contain this | 5488 | * BTRFS_MAP_GET_READ_MIRRORS does not contain this |
5488 | * mirror, that means that the requested area | 5489 | * mirror, that means that the requested area |
5489 | * is not left of the left cursor | 5490 | * is not left of the left cursor |
5490 | */ | 5491 | */ |
@@ -5540,17 +5541,17 @@ static int __btrfs_map_block(struct btrfs_fs_info *fs_info, int op, | |||
5540 | (offset + *length); | 5541 | (offset + *length); |
5541 | 5542 | ||
5542 | if (map->type & BTRFS_BLOCK_GROUP_RAID0) { | 5543 | if (map->type & BTRFS_BLOCK_GROUP_RAID0) { |
5543 | if (op == REQ_OP_DISCARD) | 5544 | if (op == BTRFS_MAP_DISCARD) |
5544 | num_stripes = min_t(u64, map->num_stripes, | 5545 | num_stripes = min_t(u64, map->num_stripes, |
5545 | stripe_nr_end - stripe_nr_orig); | 5546 | stripe_nr_end - stripe_nr_orig); |
5546 | stripe_nr = div_u64_rem(stripe_nr, map->num_stripes, | 5547 | stripe_nr = div_u64_rem(stripe_nr, map->num_stripes, |
5547 | &stripe_index); | 5548 | &stripe_index); |
5548 | if (op != REQ_OP_WRITE && op != REQ_OP_DISCARD && | 5549 | if (op != BTRFS_MAP_WRITE && op != BTRFS_MAP_DISCARD && |
5549 | op != REQ_GET_READ_MIRRORS) | 5550 | op != BTRFS_MAP_GET_READ_MIRRORS) |
5550 | mirror_num = 1; | 5551 | mirror_num = 1; |
5551 | } else if (map->type & BTRFS_BLOCK_GROUP_RAID1) { | 5552 | } else if (map->type & BTRFS_BLOCK_GROUP_RAID1) { |
5552 | if (op == REQ_OP_WRITE || op == REQ_OP_DISCARD || | 5553 | if (op == BTRFS_MAP_WRITE || op == BTRFS_MAP_DISCARD || |
5553 | op == REQ_GET_READ_MIRRORS) | 5554 | op == BTRFS_MAP_GET_READ_MIRRORS) |
5554 | num_stripes = map->num_stripes; | 5555 | num_stripes = map->num_stripes; |
5555 | else if (mirror_num) | 5556 | else if (mirror_num) |
5556 | stripe_index = mirror_num - 1; | 5557 | stripe_index = mirror_num - 1; |
@@ -5563,8 +5564,8 @@ static int __btrfs_map_block(struct btrfs_fs_info *fs_info, int op, | |||
5563 | } | 5564 | } |
5564 | 5565 | ||
5565 | } else if (map->type & BTRFS_BLOCK_GROUP_DUP) { | 5566 | } else if (map->type & BTRFS_BLOCK_GROUP_DUP) { |
5566 | if (op == REQ_OP_WRITE || op == REQ_OP_DISCARD || | 5567 | if (op == BTRFS_MAP_WRITE || op == BTRFS_MAP_DISCARD || |
5567 | op == REQ_GET_READ_MIRRORS) { | 5568 | op == BTRFS_MAP_GET_READ_MIRRORS) { |
5568 | num_stripes = map->num_stripes; | 5569 | num_stripes = map->num_stripes; |
5569 | } else if (mirror_num) { | 5570 | } else if (mirror_num) { |
5570 | stripe_index = mirror_num - 1; | 5571 | stripe_index = mirror_num - 1; |
@@ -5578,9 +5579,9 @@ static int __btrfs_map_block(struct btrfs_fs_info *fs_info, int op, | |||
5578 | stripe_nr = div_u64_rem(stripe_nr, factor, &stripe_index); | 5579 | stripe_nr = div_u64_rem(stripe_nr, factor, &stripe_index); |
5579 | stripe_index *= map->sub_stripes; | 5580 | stripe_index *= map->sub_stripes; |
5580 | 5581 | ||
5581 | if (op == REQ_OP_WRITE || op == REQ_GET_READ_MIRRORS) | 5582 | if (op == BTRFS_MAP_WRITE || op == BTRFS_MAP_GET_READ_MIRRORS) |
5582 | num_stripes = map->sub_stripes; | 5583 | num_stripes = map->sub_stripes; |
5583 | else if (op == REQ_OP_DISCARD) | 5584 | else if (op == BTRFS_MAP_DISCARD) |
5584 | num_stripes = min_t(u64, map->sub_stripes * | 5585 | num_stripes = min_t(u64, map->sub_stripes * |
5585 | (stripe_nr_end - stripe_nr_orig), | 5586 | (stripe_nr_end - stripe_nr_orig), |
5586 | map->num_stripes); | 5587 | map->num_stripes); |
@@ -5598,7 +5599,7 @@ static int __btrfs_map_block(struct btrfs_fs_info *fs_info, int op, | |||
5598 | 5599 | ||
5599 | } else if (map->type & BTRFS_BLOCK_GROUP_RAID56_MASK) { | 5600 | } else if (map->type & BTRFS_BLOCK_GROUP_RAID56_MASK) { |
5600 | if (need_raid_map && | 5601 | if (need_raid_map && |
5601 | (op == REQ_OP_WRITE || op == REQ_GET_READ_MIRRORS || | 5602 | (op == BTRFS_MAP_WRITE || op == BTRFS_MAP_GET_READ_MIRRORS || |
5602 | mirror_num > 1)) { | 5603 | mirror_num > 1)) { |
5603 | /* push stripe_nr back to the start of the full stripe */ | 5604 | /* push stripe_nr back to the start of the full stripe */ |
5604 | stripe_nr = div_u64(raid56_full_stripe_start, | 5605 | stripe_nr = div_u64(raid56_full_stripe_start, |
@@ -5626,8 +5627,8 @@ static int __btrfs_map_block(struct btrfs_fs_info *fs_info, int op, | |||
5626 | /* We distribute the parity blocks across stripes */ | 5627 | /* We distribute the parity blocks across stripes */ |
5627 | div_u64_rem(stripe_nr + stripe_index, map->num_stripes, | 5628 | div_u64_rem(stripe_nr + stripe_index, map->num_stripes, |
5628 | &stripe_index); | 5629 | &stripe_index); |
5629 | if ((op != REQ_OP_WRITE && op != REQ_OP_DISCARD && | 5630 | if ((op != BTRFS_MAP_WRITE && op != BTRFS_MAP_DISCARD && |
5630 | op != REQ_GET_READ_MIRRORS) && mirror_num <= 1) | 5631 | op != BTRFS_MAP_GET_READ_MIRRORS) && mirror_num <= 1) |
5631 | mirror_num = 1; | 5632 | mirror_num = 1; |
5632 | } | 5633 | } |
5633 | } else { | 5634 | } else { |
@@ -5650,9 +5651,9 @@ static int __btrfs_map_block(struct btrfs_fs_info *fs_info, int op, | |||
5650 | 5651 | ||
5651 | num_alloc_stripes = num_stripes; | 5652 | num_alloc_stripes = num_stripes; |
5652 | if (dev_replace_is_ongoing) { | 5653 | if (dev_replace_is_ongoing) { |
5653 | if (op == REQ_OP_WRITE || op == REQ_OP_DISCARD) | 5654 | if (op == BTRFS_MAP_WRITE || op == BTRFS_MAP_DISCARD) |
5654 | num_alloc_stripes <<= 1; | 5655 | num_alloc_stripes <<= 1; |
5655 | if (op == REQ_GET_READ_MIRRORS) | 5656 | if (op == BTRFS_MAP_GET_READ_MIRRORS) |
5656 | num_alloc_stripes++; | 5657 | num_alloc_stripes++; |
5657 | tgtdev_indexes = num_stripes; | 5658 | tgtdev_indexes = num_stripes; |
5658 | } | 5659 | } |
@@ -5668,7 +5669,7 @@ static int __btrfs_map_block(struct btrfs_fs_info *fs_info, int op, | |||
5668 | /* build raid_map */ | 5669 | /* build raid_map */ |
5669 | if (map->type & BTRFS_BLOCK_GROUP_RAID56_MASK && | 5670 | if (map->type & BTRFS_BLOCK_GROUP_RAID56_MASK && |
5670 | need_raid_map && | 5671 | need_raid_map && |
5671 | ((op == REQ_OP_WRITE || op == REQ_GET_READ_MIRRORS) || | 5672 | ((op == BTRFS_MAP_WRITE || op == BTRFS_MAP_GET_READ_MIRRORS) || |
5672 | mirror_num > 1)) { | 5673 | mirror_num > 1)) { |
5673 | u64 tmp; | 5674 | u64 tmp; |
5674 | unsigned rot; | 5675 | unsigned rot; |
@@ -5693,7 +5694,7 @@ static int __btrfs_map_block(struct btrfs_fs_info *fs_info, int op, | |||
5693 | RAID6_Q_STRIPE; | 5694 | RAID6_Q_STRIPE; |
5694 | } | 5695 | } |
5695 | 5696 | ||
5696 | if (op == REQ_OP_DISCARD) { | 5697 | if (op == BTRFS_MAP_DISCARD) { |
5697 | u32 factor = 0; | 5698 | u32 factor = 0; |
5698 | u32 sub_stripes = 0; | 5699 | u32 sub_stripes = 0; |
5699 | u64 stripes_per_dev = 0; | 5700 | u64 stripes_per_dev = 0; |
@@ -5773,7 +5774,7 @@ static int __btrfs_map_block(struct btrfs_fs_info *fs_info, int op, | |||
5773 | } | 5774 | } |
5774 | } | 5775 | } |
5775 | 5776 | ||
5776 | if (op == REQ_OP_WRITE || op == REQ_GET_READ_MIRRORS) | 5777 | if (op == BTRFS_MAP_WRITE || op == BTRFS_MAP_GET_READ_MIRRORS) |
5777 | max_errors = btrfs_chunk_max_errors(map); | 5778 | max_errors = btrfs_chunk_max_errors(map); |
5778 | 5779 | ||
5779 | if (bbio->raid_map) | 5780 | if (bbio->raid_map) |
@@ -5781,7 +5782,7 @@ static int __btrfs_map_block(struct btrfs_fs_info *fs_info, int op, | |||
5781 | 5782 | ||
5782 | tgtdev_indexes = 0; | 5783 | tgtdev_indexes = 0; |
5783 | if (dev_replace_is_ongoing && | 5784 | if (dev_replace_is_ongoing && |
5784 | (op == REQ_OP_WRITE || op == REQ_OP_DISCARD) && | 5785 | (op == BTRFS_MAP_WRITE || op == BTRFS_MAP_DISCARD) && |
5785 | dev_replace->tgtdev != NULL) { | 5786 | dev_replace->tgtdev != NULL) { |
5786 | int index_where_to_add; | 5787 | int index_where_to_add; |
5787 | u64 srcdev_devid = dev_replace->srcdev->devid; | 5788 | u64 srcdev_devid = dev_replace->srcdev->devid; |
@@ -5816,7 +5817,8 @@ static int __btrfs_map_block(struct btrfs_fs_info *fs_info, int op, | |||
5816 | } | 5817 | } |
5817 | } | 5818 | } |
5818 | num_stripes = index_where_to_add; | 5819 | num_stripes = index_where_to_add; |
5819 | } else if (dev_replace_is_ongoing && (op == REQ_GET_READ_MIRRORS) && | 5820 | } else if (dev_replace_is_ongoing && |
5821 | op == BTRFS_MAP_GET_READ_MIRRORS && | ||
5820 | dev_replace->tgtdev != NULL) { | 5822 | dev_replace->tgtdev != NULL) { |
5821 | u64 srcdev_devid = dev_replace->srcdev->devid; | 5823 | u64 srcdev_devid = dev_replace->srcdev->devid; |
5822 | int index_srcdev = 0; | 5824 | int index_srcdev = 0; |
@@ -5888,7 +5890,7 @@ out: | |||
5888 | return ret; | 5890 | return ret; |
5889 | } | 5891 | } |
5890 | 5892 | ||
5891 | int btrfs_map_block(struct btrfs_fs_info *fs_info, int op, | 5893 | int btrfs_map_block(struct btrfs_fs_info *fs_info, enum btrfs_map_op op, |
5892 | u64 logical, u64 *length, | 5894 | u64 logical, u64 *length, |
5893 | struct btrfs_bio **bbio_ret, int mirror_num) | 5895 | struct btrfs_bio **bbio_ret, int mirror_num) |
5894 | { | 5896 | { |
@@ -5897,7 +5899,7 @@ int btrfs_map_block(struct btrfs_fs_info *fs_info, int op, | |||
5897 | } | 5899 | } |
5898 | 5900 | ||
5899 | /* For Scrub/replace */ | 5901 | /* For Scrub/replace */ |
5900 | int btrfs_map_sblock(struct btrfs_fs_info *fs_info, int op, | 5902 | int btrfs_map_sblock(struct btrfs_fs_info *fs_info, enum btrfs_map_op op, |
5901 | u64 logical, u64 *length, | 5903 | u64 logical, u64 *length, |
5902 | struct btrfs_bio **bbio_ret, int mirror_num, | 5904 | struct btrfs_bio **bbio_ret, int mirror_num, |
5903 | int need_raid_map) | 5905 | int need_raid_map) |
diff --git a/fs/btrfs/volumes.h b/fs/btrfs/volumes.h index 09ed29c67848..9029a3134922 100644 --- a/fs/btrfs/volumes.h +++ b/fs/btrfs/volumes.h | |||
@@ -371,14 +371,35 @@ struct btrfs_balance_control { | |||
371 | struct btrfs_balance_progress stat; | 371 | struct btrfs_balance_progress stat; |
372 | }; | 372 | }; |
373 | 373 | ||
374 | enum btrfs_map_op { | ||
375 | BTRFS_MAP_READ, | ||
376 | BTRFS_MAP_WRITE, | ||
377 | BTRFS_MAP_DISCARD, | ||
378 | BTRFS_MAP_GET_READ_MIRRORS, | ||
379 | }; | ||
380 | |||
381 | static inline enum btrfs_map_op btrfs_op(struct bio *bio) | ||
382 | { | ||
383 | switch (bio_op(bio)) { | ||
384 | case REQ_OP_DISCARD: | ||
385 | return BTRFS_MAP_DISCARD; | ||
386 | case REQ_OP_WRITE: | ||
387 | return BTRFS_MAP_WRITE; | ||
388 | default: | ||
389 | WARN_ON_ONCE(1); | ||
390 | case REQ_OP_READ: | ||
391 | return BTRFS_MAP_READ; | ||
392 | } | ||
393 | } | ||
394 | |||
374 | int btrfs_account_dev_extents_size(struct btrfs_device *device, u64 start, | 395 | int btrfs_account_dev_extents_size(struct btrfs_device *device, u64 start, |
375 | u64 end, u64 *length); | 396 | u64 end, u64 *length); |
376 | void btrfs_get_bbio(struct btrfs_bio *bbio); | 397 | void btrfs_get_bbio(struct btrfs_bio *bbio); |
377 | void btrfs_put_bbio(struct btrfs_bio *bbio); | 398 | void btrfs_put_bbio(struct btrfs_bio *bbio); |
378 | int btrfs_map_block(struct btrfs_fs_info *fs_info, int op, | 399 | int btrfs_map_block(struct btrfs_fs_info *fs_info, enum btrfs_map_op op, |
379 | u64 logical, u64 *length, | 400 | u64 logical, u64 *length, |
380 | struct btrfs_bio **bbio_ret, int mirror_num); | 401 | struct btrfs_bio **bbio_ret, int mirror_num); |
381 | int btrfs_map_sblock(struct btrfs_fs_info *fs_info, int op, | 402 | int btrfs_map_sblock(struct btrfs_fs_info *fs_info, enum btrfs_map_op op, |
382 | u64 logical, u64 *length, | 403 | u64 logical, u64 *length, |
383 | struct btrfs_bio **bbio_ret, int mirror_num, | 404 | struct btrfs_bio **bbio_ret, int mirror_num, |
384 | int need_raid_map); | 405 | int need_raid_map); |
diff --git a/fs/btrfs/zlib.c b/fs/btrfs/zlib.c index 441b81a3e545..da497f184ff4 100644 --- a/fs/btrfs/zlib.c +++ b/fs/btrfs/zlib.c | |||
@@ -210,10 +210,9 @@ out: | |||
210 | return ret; | 210 | return ret; |
211 | } | 211 | } |
212 | 212 | ||
213 | static int zlib_decompress_biovec(struct list_head *ws, struct page **pages_in, | 213 | static int zlib_decompress_bio(struct list_head *ws, struct page **pages_in, |
214 | u64 disk_start, | 214 | u64 disk_start, |
215 | struct bio_vec *bvec, | 215 | struct bio *orig_bio, |
216 | int vcnt, | ||
217 | size_t srclen) | 216 | size_t srclen) |
218 | { | 217 | { |
219 | struct workspace *workspace = list_entry(ws, struct workspace, list); | 218 | struct workspace *workspace = list_entry(ws, struct workspace, list); |
@@ -222,10 +221,8 @@ static int zlib_decompress_biovec(struct list_head *ws, struct page **pages_in, | |||
222 | char *data_in; | 221 | char *data_in; |
223 | size_t total_out = 0; | 222 | size_t total_out = 0; |
224 | unsigned long page_in_index = 0; | 223 | unsigned long page_in_index = 0; |
225 | unsigned long page_out_index = 0; | ||
226 | unsigned long total_pages_in = DIV_ROUND_UP(srclen, PAGE_SIZE); | 224 | unsigned long total_pages_in = DIV_ROUND_UP(srclen, PAGE_SIZE); |
227 | unsigned long buf_start; | 225 | unsigned long buf_start; |
228 | unsigned long pg_offset; | ||
229 | 226 | ||
230 | data_in = kmap(pages_in[page_in_index]); | 227 | data_in = kmap(pages_in[page_in_index]); |
231 | workspace->strm.next_in = data_in; | 228 | workspace->strm.next_in = data_in; |
@@ -235,7 +232,6 @@ static int zlib_decompress_biovec(struct list_head *ws, struct page **pages_in, | |||
235 | workspace->strm.total_out = 0; | 232 | workspace->strm.total_out = 0; |
236 | workspace->strm.next_out = workspace->buf; | 233 | workspace->strm.next_out = workspace->buf; |
237 | workspace->strm.avail_out = PAGE_SIZE; | 234 | workspace->strm.avail_out = PAGE_SIZE; |
238 | pg_offset = 0; | ||
239 | 235 | ||
240 | /* If it's deflate, and it's got no preset dictionary, then | 236 | /* If it's deflate, and it's got no preset dictionary, then |
241 | we can tell zlib to skip the adler32 check. */ | 237 | we can tell zlib to skip the adler32 check. */ |
@@ -250,6 +246,7 @@ static int zlib_decompress_biovec(struct list_head *ws, struct page **pages_in, | |||
250 | 246 | ||
251 | if (Z_OK != zlib_inflateInit2(&workspace->strm, wbits)) { | 247 | if (Z_OK != zlib_inflateInit2(&workspace->strm, wbits)) { |
252 | pr_warn("BTRFS: inflateInit failed\n"); | 248 | pr_warn("BTRFS: inflateInit failed\n"); |
249 | kunmap(pages_in[page_in_index]); | ||
253 | return -EIO; | 250 | return -EIO; |
254 | } | 251 | } |
255 | while (workspace->strm.total_in < srclen) { | 252 | while (workspace->strm.total_in < srclen) { |
@@ -266,8 +263,7 @@ static int zlib_decompress_biovec(struct list_head *ws, struct page **pages_in, | |||
266 | 263 | ||
267 | ret2 = btrfs_decompress_buf2page(workspace->buf, buf_start, | 264 | ret2 = btrfs_decompress_buf2page(workspace->buf, buf_start, |
268 | total_out, disk_start, | 265 | total_out, disk_start, |
269 | bvec, vcnt, | 266 | orig_bio); |
270 | &page_out_index, &pg_offset); | ||
271 | if (ret2 == 0) { | 267 | if (ret2 == 0) { |
272 | ret = 0; | 268 | ret = 0; |
273 | goto done; | 269 | goto done; |
@@ -300,7 +296,7 @@ done: | |||
300 | if (data_in) | 296 | if (data_in) |
301 | kunmap(pages_in[page_in_index]); | 297 | kunmap(pages_in[page_in_index]); |
302 | if (!ret) | 298 | if (!ret) |
303 | btrfs_clear_biovec_end(bvec, vcnt, page_out_index, pg_offset); | 299 | zero_fill_bio(orig_bio); |
304 | return ret; | 300 | return ret; |
305 | } | 301 | } |
306 | 302 | ||
@@ -407,6 +403,6 @@ const struct btrfs_compress_op btrfs_zlib_compress = { | |||
407 | .alloc_workspace = zlib_alloc_workspace, | 403 | .alloc_workspace = zlib_alloc_workspace, |
408 | .free_workspace = zlib_free_workspace, | 404 | .free_workspace = zlib_free_workspace, |
409 | .compress_pages = zlib_compress_pages, | 405 | .compress_pages = zlib_compress_pages, |
410 | .decompress_biovec = zlib_decompress_biovec, | 406 | .decompress_bio = zlib_decompress_bio, |
411 | .decompress = zlib_decompress, | 407 | .decompress = zlib_decompress, |
412 | }; | 408 | }; |
diff --git a/include/trace/events/btrfs.h b/include/trace/events/btrfs.h index e030d6f6c19a..e61bbc3b82d5 100644 --- a/include/trace/events/btrfs.h +++ b/include/trace/events/btrfs.h | |||
@@ -1406,7 +1406,7 @@ DEFINE_EVENT(btrfs_qgroup_extent, btrfs_qgroup_account_extents, | |||
1406 | TP_ARGS(fs_info, rec) | 1406 | TP_ARGS(fs_info, rec) |
1407 | ); | 1407 | ); |
1408 | 1408 | ||
1409 | DEFINE_EVENT(btrfs_qgroup_extent, btrfs_qgroup_insert_dirty_extent, | 1409 | DEFINE_EVENT(btrfs_qgroup_extent, btrfs_qgroup_trace_extent, |
1410 | 1410 | ||
1411 | TP_PROTO(struct btrfs_fs_info *fs_info, | 1411 | TP_PROTO(struct btrfs_fs_info *fs_info, |
1412 | struct btrfs_qgroup_extent_record *rec), | 1412 | struct btrfs_qgroup_extent_record *rec), |