@@ -81,9 +81,9 @@ struct compressed_bio {
81
81
u32 sums ;
82
82
};
83
83
84
- static int btrfs_decompress_biovec (int type , struct page * * pages_in ,
85
- u64 disk_start , struct bio_vec * bvec ,
86
- int vcnt , size_t srclen );
84
+ static int btrfs_decompress_bio (int type , struct page * * pages_in ,
85
+ u64 disk_start , struct bio * orig_bio ,
86
+ size_t srclen );
87
87
88
88
static inline int compressed_bio_size (struct btrfs_root * root ,
89
89
unsigned long disk_size )
@@ -175,11 +175,10 @@ static void end_compressed_bio_read(struct bio *bio)
175
175
/* ok, we're the last bio for this extent, lets start
176
176
* the decompression.
177
177
*/
178
- ret = btrfs_decompress_biovec (cb -> compress_type ,
178
+ ret = btrfs_decompress_bio (cb -> compress_type ,
179
179
cb -> compressed_pages ,
180
180
cb -> start ,
181
- cb -> orig_bio -> bi_io_vec ,
182
- cb -> orig_bio -> bi_vcnt ,
181
+ cb -> orig_bio ,
183
182
cb -> compressed_len );
184
183
csum_failed :
185
184
if (ret )
@@ -959,9 +958,7 @@ int btrfs_compress_pages(int type, struct address_space *mapping,
959
958
*
960
959
* disk_start is the starting logical offset of this array in the file
961
960
*
962
- * bvec is a bio_vec of pages from the file that we want to decompress into
963
- *
964
- * vcnt is the count of pages in the biovec
961
+ * orig_bio contains the pages from the file that we want to decompress into
965
962
*
966
963
* srclen is the number of bytes in pages_in
967
964
*
@@ -970,18 +967,18 @@ int btrfs_compress_pages(int type, struct address_space *mapping,
970
967
* be contiguous. They all correspond to the range of bytes covered by
971
968
* the compressed extent.
972
969
*/
973
- static int btrfs_decompress_biovec (int type , struct page * * pages_in ,
974
- u64 disk_start , struct bio_vec * bvec ,
975
- int vcnt , size_t srclen )
970
+ static int btrfs_decompress_bio (int type , struct page * * pages_in ,
971
+ u64 disk_start , struct bio * orig_bio ,
972
+ size_t srclen )
976
973
{
977
974
struct list_head * workspace ;
978
975
int ret ;
979
976
980
977
workspace = find_workspace (type );
981
978
982
- ret = btrfs_compress_op [type - 1 ]-> decompress_biovec (workspace , pages_in ,
983
- disk_start ,
984
- bvec , vcnt , srclen );
979
+ ret = btrfs_compress_op [type - 1 ]-> decompress_bio (workspace , pages_in ,
980
+ disk_start , orig_bio ,
981
+ srclen );
985
982
free_workspace (type , workspace );
986
983
return ret ;
987
984
}
@@ -1021,23 +1018,21 @@ void btrfs_exit_compress(void)
1021
1018
*/
1022
1019
int btrfs_decompress_buf2page (char * buf , unsigned long buf_start ,
1023
1020
unsigned long total_out , u64 disk_start ,
1024
- struct bio_vec * bvec , int vcnt ,
1025
- unsigned long * pg_index ,
1026
- unsigned long * pg_offset )
1021
+ struct bio * bio )
1027
1022
{
1028
1023
unsigned long buf_offset ;
1029
1024
unsigned long current_buf_start ;
1030
1025
unsigned long start_byte ;
1031
1026
unsigned long working_bytes = total_out - buf_start ;
1032
1027
unsigned long bytes ;
1033
1028
char * kaddr ;
1034
- struct page * page_out = bvec [ * pg_index ]. bv_page ;
1029
+ struct bio_vec bvec = bio_iter_iovec ( bio , bio -> bi_iter ) ;
1035
1030
1036
1031
/*
1037
1032
* start byte is the first byte of the page we're currently
1038
1033
* copying into relative to the start of the compressed data.
1039
1034
*/
1040
- start_byte = page_offset (page_out ) - disk_start ;
1035
+ start_byte = page_offset (bvec . bv_page ) - disk_start ;
1041
1036
1042
1037
/* we haven't yet hit data corresponding to this page */
1043
1038
if (total_out <= start_byte )
@@ -1057,80 +1052,46 @@ int btrfs_decompress_buf2page(char *buf, unsigned long buf_start,
1057
1052
1058
1053
/* copy bytes from the working buffer into the pages */
1059
1054
while (working_bytes > 0 ) {
1060
- bytes = min ( PAGE_SIZE - * pg_offset ,
1061
- PAGE_SIZE - buf_offset );
1055
+ bytes = min_t ( unsigned long , bvec . bv_len ,
1056
+ PAGE_SIZE - buf_offset );
1062
1057
bytes = min (bytes , working_bytes );
1063
- kaddr = kmap_atomic (page_out );
1064
- memcpy (kaddr + * pg_offset , buf + buf_offset , bytes );
1058
+
1059
+ kaddr = kmap_atomic (bvec .bv_page );
1060
+ memcpy (kaddr + bvec .bv_offset , buf + buf_offset , bytes );
1065
1061
kunmap_atomic (kaddr );
1066
- flush_dcache_page (page_out );
1062
+ flush_dcache_page (bvec . bv_page );
1067
1063
1068
- * pg_offset += bytes ;
1069
1064
buf_offset += bytes ;
1070
1065
working_bytes -= bytes ;
1071
1066
current_buf_start += bytes ;
1072
1067
1073
1068
/* check if we need to pick another page */
1074
- if ( * pg_offset == PAGE_SIZE ) {
1075
- ( * pg_index ) ++ ;
1076
- if ( * pg_index >= vcnt )
1077
- return 0 ;
1069
+ bio_advance ( bio , bytes );
1070
+ if (! bio -> bi_iter . bi_size )
1071
+ return 0 ;
1072
+ bvec = bio_iter_iovec ( bio , bio -> bi_iter ) ;
1078
1073
1079
- page_out = bvec [* pg_index ].bv_page ;
1080
- * pg_offset = 0 ;
1081
- start_byte = page_offset (page_out ) - disk_start ;
1074
+ start_byte = page_offset (bvec .bv_page ) - disk_start ;
1082
1075
1083
- /*
1084
- * make sure our new page is covered by this
1085
- * working buffer
1086
- */
1087
- if (total_out <= start_byte )
1088
- return 1 ;
1076
+ /*
1077
+ * make sure our new page is covered by this
1078
+ * working buffer
1079
+ */
1080
+ if (total_out <= start_byte )
1081
+ return 1 ;
1089
1082
1090
- /*
1091
- * the next page in the biovec might not be adjacent
1092
- * to the last page, but it might still be found
1093
- * inside this working buffer. bump our offset pointer
1094
- */
1095
- if (total_out > start_byte &&
1096
- current_buf_start < start_byte ) {
1097
- buf_offset = start_byte - buf_start ;
1098
- working_bytes = total_out - start_byte ;
1099
- current_buf_start = buf_start + buf_offset ;
1100
- }
1083
+ /*
1084
+ * the next page in the biovec might not be adjacent
1085
+ * to the last page, but it might still be found
1086
+ * inside this working buffer. bump our offset pointer
1087
+ */
1088
+ if (total_out > start_byte &&
1089
+ current_buf_start < start_byte ) {
1090
+ buf_offset = start_byte - buf_start ;
1091
+ working_bytes = total_out - start_byte ;
1092
+ current_buf_start = buf_start + buf_offset ;
1101
1093
}
1102
1094
}
1103
1095
1104
1096
return 1 ;
1105
1097
}
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
- }
0 commit comments