@@ -188,14 +188,23 @@ void vdo_set_bio_properties(struct bio *bio, struct vio *vio, bio_end_io_t callb
188188
189189/*
190190 * Prepares the bio to perform IO with the specified buffer. May only be used on a VDO-allocated
191- * bio, as it assumes the bio wraps a 4k buffer that is 4k aligned, but there does not have to be a
192- * vio associated with the bio.
191+ * bio, as it assumes the bio wraps a 4k-multiple buffer that is 4k aligned, but there does not
192+ * have to be a vio associated with the bio.
193193 */
194194int vio_reset_bio (struct vio * vio , char * data , bio_end_io_t callback ,
195195 blk_opf_t bi_opf , physical_block_number_t pbn )
196196{
197- int bvec_count , offset , len , i ;
197+ return vio_reset_bio_with_size (vio , data , vio -> block_count * VDO_BLOCK_SIZE ,
198+ callback , bi_opf , pbn );
199+ }
200+
201+ int vio_reset_bio_with_size (struct vio * vio , char * data , int size , bio_end_io_t callback ,
202+ blk_opf_t bi_opf , physical_block_number_t pbn )
203+ {
204+ int bvec_count , offset , i ;
198205 struct bio * bio = vio -> bio ;
206+ int vio_size = vio -> block_count * VDO_BLOCK_SIZE ;
207+ int remaining ;
199208
200209 bio_reset (bio , bio -> bi_bdev , bi_opf );
201210 vdo_set_bio_properties (bio , vio , callback , bi_opf , pbn );
@@ -205,22 +214,21 @@ int vio_reset_bio(struct vio *vio, char *data, bio_end_io_t callback,
205214 bio -> bi_ioprio = 0 ;
206215 bio -> bi_io_vec = bio -> bi_inline_vecs ;
207216 bio -> bi_max_vecs = vio -> block_count + 1 ;
208- len = VDO_BLOCK_SIZE * vio -> block_count ;
217+ if (VDO_ASSERT (size <= vio_size , "specified size %d is not greater than allocated %d" ,
218+ size , vio_size ) != VDO_SUCCESS )
219+ size = vio_size ;
220+ vio -> io_size = size ;
209221 offset = offset_in_page (data );
210- bvec_count = DIV_ROUND_UP (offset + len , PAGE_SIZE );
222+ bvec_count = DIV_ROUND_UP (offset + size , PAGE_SIZE );
223+ remaining = size ;
211224
212- /*
213- * If we knew that data was always on one page, or contiguous pages, we wouldn't need the
214- * loop. But if we're using vmalloc, it's not impossible that the data is in different
215- * pages that can't be merged in bio_add_page...
216- */
217- for (i = 0 ; (i < bvec_count ) && (len > 0 ); i ++ ) {
225+ for (i = 0 ; (i < bvec_count ) && (remaining > 0 ); i ++ ) {
218226 struct page * page ;
219227 int bytes_added ;
220228 int bytes = PAGE_SIZE - offset ;
221229
222- if (bytes > len )
223- bytes = len ;
230+ if (bytes > remaining )
231+ bytes = remaining ;
224232
225233 page = is_vmalloc_addr (data ) ? vmalloc_to_page (data ) : virt_to_page (data );
226234 bytes_added = bio_add_page (bio , page , bytes , offset );
@@ -232,7 +240,7 @@ int vio_reset_bio(struct vio *vio, char *data, bio_end_io_t callback,
232240 }
233241
234242 data += bytes ;
235- len -= bytes ;
243+ remaining -= bytes ;
236244 offset = 0 ;
237245 }
238246
0 commit comments