@@ -22,9 +22,17 @@ void blk_flush_integrity(void)
2222 flush_workqueue (kintegrityd_wq );
2323}
2424
25- static void __bio_integrity_free (struct bio_set * bs ,
26- struct bio_integrity_payload * bip )
25+ /**
26+ * bio_integrity_free - Free bio integrity payload
27+ * @bio: bio containing bip to be freed
28+ *
29+ * Description: Free the integrity portion of a bio.
30+ */
31+ void bio_integrity_free (struct bio * bio )
2732{
33+ struct bio_integrity_payload * bip = bio_integrity (bio );
34+ struct bio_set * bs = bio -> bi_pool ;
35+
2836 if (bs && mempool_initialized (& bs -> bio_integrity_pool )) {
2937 if (bip -> bip_vec )
3038 bvec_free (& bs -> bvec_integrity_pool , bip -> bip_vec ,
@@ -33,6 +41,8 @@ static void __bio_integrity_free(struct bio_set *bs,
3341 } else {
3442 kfree (bip );
3543 }
44+ bio -> bi_integrity = NULL ;
45+ bio -> bi_opf &= ~REQ_INTEGRITY ;
3646}
3747
3848/**
@@ -86,7 +96,10 @@ struct bio_integrity_payload *bio_integrity_alloc(struct bio *bio,
8696
8797 return bip ;
8898err :
89- __bio_integrity_free (bs , bip );
99+ if (bs && mempool_initialized (& bs -> bio_integrity_pool ))
100+ mempool_free (bip , & bs -> bio_integrity_pool );
101+ else
102+ kfree (bip );
90103 return ERR_PTR (- ENOMEM );
91104}
92105EXPORT_SYMBOL (bio_integrity_alloc );
@@ -118,63 +131,26 @@ static void bio_integrity_uncopy_user(struct bio_integrity_payload *bip)
118131 bio_integrity_unpin_bvec (copy , nr_vecs , true);
119132}
120133
121- static void bio_integrity_unmap_user (struct bio_integrity_payload * bip )
122- {
123- bool dirty = bio_data_dir (bip -> bip_bio ) == READ ;
124-
125- if (bip -> bip_flags & BIP_COPY_USER ) {
126- if (dirty )
127- bio_integrity_uncopy_user (bip );
128- kfree (bvec_virt (bip -> bip_vec ));
129- return ;
130- }
131-
132- bio_integrity_unpin_bvec (bip -> bip_vec , bip -> bip_max_vcnt , dirty );
133- }
134-
135134/**
136- * bio_integrity_free - Free bio integrity payload
137- * @bio: bio containing bip to be freed
135+ * bio_integrity_unmap_user - Unmap user integrity payload
136+ * @bio: bio containing bip to be unmapped
138137 *
139- * Description: Used to free the integrity portion of a bio. Usually
140- * called from bio_free().
138+ * Unmap the user mapped integrity portion of a bio.
141139 */
142- void bio_integrity_free (struct bio * bio )
140+ void bio_integrity_unmap_user (struct bio * bio )
143141{
144142 struct bio_integrity_payload * bip = bio_integrity (bio );
145- struct bio_set * bs = bio -> bi_pool ;
146143
147- if (bip -> bip_flags & BIP_INTEGRITY_USER )
148- return ;
149- if (bip -> bip_flags & BIP_BLOCK_INTEGRITY )
144+ if (bip -> bip_flags & BIP_COPY_USER ) {
145+ if ( bio_data_dir ( bio ) == READ )
146+ bio_integrity_uncopy_user (bip );
150147 kfree (bvec_virt (bip -> bip_vec ));
151-
152- __bio_integrity_free (bs , bip );
153- bio -> bi_integrity = NULL ;
154- bio -> bi_opf &= ~REQ_INTEGRITY ;
155- }
156-
157- /**
158- * bio_integrity_unmap_free_user - Unmap and free bio user integrity payload
159- * @bio: bio containing bip to be unmapped and freed
160- *
161- * Description: Used to unmap and free the user mapped integrity portion of a
162- * bio. Submitter attaching the user integrity buffer is responsible for
163- * unmapping and freeing it during completion.
164- */
165- void bio_integrity_unmap_free_user (struct bio * bio )
166- {
167- struct bio_integrity_payload * bip = bio_integrity (bio );
168- struct bio_set * bs = bio -> bi_pool ;
169-
170- if (WARN_ON_ONCE (!(bip -> bip_flags & BIP_INTEGRITY_USER )))
171148 return ;
172- bio_integrity_unmap_user ( bip );
173- __bio_integrity_free ( bs , bip );
174- bio -> bi_integrity = NULL ;
175- bio -> bi_opf &= ~ REQ_INTEGRITY ;
149+ }
150+
151+ bio_integrity_unpin_bvec ( bip -> bip_vec , bip -> bip_max_vcnt ,
152+ bio_data_dir ( bio ) == READ ) ;
176153}
177- EXPORT_SYMBOL (bio_integrity_unmap_free_user );
178154
179155/**
180156 * bio_integrity_add_page - Attach integrity metadata
@@ -274,7 +250,7 @@ static int bio_integrity_copy_user(struct bio *bio, struct bio_vec *bvec,
274250 goto free_bip ;
275251 }
276252
277- bip -> bip_flags |= BIP_INTEGRITY_USER | BIP_COPY_USER ;
253+ bip -> bip_flags |= BIP_COPY_USER ;
278254 bip -> bip_iter .bi_sector = seed ;
279255 bip -> bip_vcnt = nr_vecs ;
280256 return 0 ;
@@ -295,7 +271,6 @@ static int bio_integrity_init_user(struct bio *bio, struct bio_vec *bvec,
295271 return PTR_ERR (bip );
296272
297273 memcpy (bip -> bip_vec , bvec , nr_vecs * sizeof (* bvec ));
298- bip -> bip_flags |= BIP_INTEGRITY_USER ;
299274 bip -> bip_iter .bi_sector = seed ;
300275 bip -> bip_iter .bi_size = len ;
301276 bip -> bip_vcnt = nr_vecs ;
@@ -503,6 +478,8 @@ static void bio_integrity_verify_fn(struct work_struct *work)
503478 struct bio * bio = bip -> bip_bio ;
504479
505480 blk_integrity_verify (bio );
481+
482+ kfree (bvec_virt (bip -> bip_vec ));
506483 bio_integrity_free (bio );
507484 bio_endio (bio );
508485}
@@ -523,13 +500,13 @@ bool __bio_integrity_endio(struct bio *bio)
523500 struct blk_integrity * bi = blk_get_integrity (bio -> bi_bdev -> bd_disk );
524501 struct bio_integrity_payload * bip = bio_integrity (bio );
525502
526- if (bio_op (bio ) == REQ_OP_READ && !bio -> bi_status &&
527- (bip -> bip_flags & BIP_BLOCK_INTEGRITY ) && bi -> csum_type ) {
503+ if (bio_op (bio ) == REQ_OP_READ && !bio -> bi_status && bi -> csum_type ) {
528504 INIT_WORK (& bip -> bip_work , bio_integrity_verify_fn );
529505 queue_work (kintegrityd_wq , & bip -> bip_work );
530506 return false;
531507 }
532508
509+ kfree (bvec_virt (bip -> bip_vec ));
533510 bio_integrity_free (bio );
534511 return true;
535512}
0 commit comments