hc
2024-05-10 9999e48639b3cecb08ffb37358bcba3b48161b29
kernel/block/bio-integrity.c
....@@ -1,23 +1,9 @@
1
+// SPDX-License-Identifier: GPL-2.0
12 /*
23 * bio-integrity.c - bio data integrity extensions
34 *
45 * Copyright (C) 2007, 2008, 2009 Oracle Corporation
56 * Written by: Martin K. Petersen <martin.petersen@oracle.com>
6
- *
7
- * This program is free software; you can redistribute it and/or
8
- * modify it under the terms of the GNU General Public License version
9
- * 2 as published by the Free Software Foundation.
10
- *
11
- * This program is distributed in the hope that it will be useful, but
12
- * WITHOUT ANY WARRANTY; without even the implied warranty of
13
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14
- * General Public License for more details.
15
- *
16
- * You should have received a copy of the GNU General Public License
17
- * along with this program; see the file COPYING. If not, write to
18
- * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139,
19
- * USA.
20
- *
217 */
228
239 #include <linux/blkdev.h>
....@@ -38,7 +24,8 @@
3824 flush_workqueue(kintegrityd_wq);
3925 }
4026
41
-void __bio_integrity_free(struct bio_set *bs, struct bio_integrity_payload *bip)
27
+static void __bio_integrity_free(struct bio_set *bs,
28
+ struct bio_integrity_payload *bip)
4229 {
4330 if (bs && mempool_initialized(&bs->bio_integrity_pool)) {
4431 if (bip->bip_vec)
....@@ -68,9 +55,11 @@
6855 struct bio_set *bs = bio->bi_pool;
6956 unsigned inline_vecs;
7057
58
+ if (WARN_ON_ONCE(bio_has_crypt_ctx(bio)))
59
+ return ERR_PTR(-EOPNOTSUPP);
60
+
7161 if (!bs || !mempool_initialized(&bs->bio_integrity_pool)) {
72
- bip = kmalloc(sizeof(struct bio_integrity_payload) +
73
- sizeof(struct bio_vec) * nr_vecs, gfp_mask);
62
+ bip = kmalloc(struct_size(bip, bip_inline_vecs, nr_vecs), gfp_mask);
7463 inline_vecs = nr_vecs;
7564 } else {
7665 bip = mempool_alloc(&bs->bio_integrity_pool, gfp_mask);
....@@ -114,7 +103,7 @@
114103 * Description: Used to free the integrity portion of a bio. Usually
115104 * called from bio_free().
116105 */
117
-static void bio_integrity_free(struct bio *bio)
106
+void bio_integrity_free(struct bio *bio)
118107 {
119108 struct bio_integrity_payload *bip = bio_integrity(bio);
120109 struct bio_set *bs = bio->bi_pool;
....@@ -314,6 +303,8 @@
314303 if (bio_data_dir(bio) == WRITE) {
315304 bio_integrity_process(bio, &bio->bi_iter,
316305 bi->profile->generate_fn);
306
+ } else {
307
+ bip->bio_iter = bio->bi_iter;
317308 }
318309 return true;
319310
....@@ -339,20 +330,14 @@
339330 container_of(work, struct bio_integrity_payload, bip_work);
340331 struct bio *bio = bip->bip_bio;
341332 struct blk_integrity *bi = blk_get_integrity(bio->bi_disk);
342
- struct bvec_iter iter = bio->bi_iter;
343333
344334 /*
345335 * At the moment verify is called bio's iterator was advanced
346336 * during split and completion, we need to rewind iterator to
347337 * it's original position.
348338 */
349
- if (bio_rewind_iter(bio, &iter, iter.bi_done)) {
350
- bio->bi_status = bio_integrity_process(bio, &iter,
351
- bi->profile->verify_fn);
352
- } else {
353
- bio->bi_status = BLK_STS_IOERR;
354
- }
355
-
339
+ bio->bi_status = bio_integrity_process(bio, &bip->bio_iter,
340
+ bi->profile->verify_fn);
356341 bio_integrity_free(bio);
357342 bio_endio(bio);
358343 }
....@@ -402,7 +387,6 @@
402387 bip->bip_iter.bi_sector += bio_integrity_intervals(bi, bytes_done >> 9);
403388 bvec_iter_advance(bip->bip_vec, &bip->bip_iter, bytes);
404389 }
405
-EXPORT_SYMBOL(bio_integrity_advance);
406390
407391 /**
408392 * bio_integrity_trim - Trim integrity vector
....@@ -444,6 +428,7 @@
444428
445429 bip->bip_vcnt = bip_src->bip_vcnt;
446430 bip->bip_iter = bip_src->bip_iter;
431
+ bip->bip_flags = bip_src->bip_flags & ~BIP_BLOCK_INTEGRITY;
447432
448433 return 0;
449434 }
....@@ -472,7 +457,6 @@
472457 mempool_exit(&bs->bio_integrity_pool);
473458 mempool_exit(&bs->bvec_integrity_pool);
474459 }
475
-EXPORT_SYMBOL(bioset_integrity_free);
476460
477461 void __init bio_integrity_init(void)
478462 {