Skip to content

Commit c096df9

Browse files
Christoph Hellwigaxboe
authored andcommitted
block: simplify adding the payload in bio_integrity_prep
bio_integrity_add_page can add physically contiguous regions of any size, so don't bother chunking up the kmalloced buffer. Signed-off-by: Christoph Hellwig <[email protected]> Reviewed-by: Kanchan Joshi <[email protected]> Reviewed-by: Martin K. Petersen <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Jens Axboe <[email protected]>
1 parent c546d6f commit c096df9

File tree

1 file changed

+6
-26
lines changed

1 file changed

+6
-26
lines changed

block/bio-integrity.c

Lines changed: 6 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -428,10 +428,8 @@ bool bio_integrity_prep(struct bio *bio)
428428
{
429429
struct bio_integrity_payload *bip;
430430
struct blk_integrity *bi = blk_get_integrity(bio->bi_bdev->bd_disk);
431+
unsigned int len;
431432
void *buf;
432-
unsigned long start, end;
433-
unsigned int len, nr_pages;
434-
unsigned int bytes, offset, i;
435433
gfp_t gfp = GFP_NOIO;
436434

437435
if (!bi)
@@ -471,12 +469,7 @@ bool bio_integrity_prep(struct bio *bio)
471469
goto err_end_io;
472470
}
473471

474-
end = (((unsigned long) buf) + len + PAGE_SIZE - 1) >> PAGE_SHIFT;
475-
start = ((unsigned long) buf) >> PAGE_SHIFT;
476-
nr_pages = end - start;
477-
478-
/* Allocate bio integrity payload and integrity vectors */
479-
bip = bio_integrity_alloc(bio, GFP_NOIO, nr_pages);
472+
bip = bio_integrity_alloc(bio, GFP_NOIO, 1);
480473
if (IS_ERR(bip)) {
481474
printk(KERN_ERR "could not allocate data integrity bioset\n");
482475
kfree(buf);
@@ -489,23 +482,10 @@ bool bio_integrity_prep(struct bio *bio)
489482
if (bi->csum_type == BLK_INTEGRITY_CSUM_IP)
490483
bip->bip_flags |= BIP_IP_CHECKSUM;
491484

492-
/* Map it */
493-
offset = offset_in_page(buf);
494-
for (i = 0; i < nr_pages && len > 0; i++) {
495-
bytes = PAGE_SIZE - offset;
496-
497-
if (bytes > len)
498-
bytes = len;
499-
500-
if (bio_integrity_add_page(bio, virt_to_page(buf),
501-
bytes, offset) < bytes) {
502-
printk(KERN_ERR "could not attach integrity payload\n");
503-
goto err_end_io;
504-
}
505-
506-
buf += bytes;
507-
len -= bytes;
508-
offset = 0;
485+
if (bio_integrity_add_page(bio, virt_to_page(buf), len,
486+
offset_in_page(buf)) < len) {
487+
printk(KERN_ERR "could not attach integrity payload\n");
488+
goto err_end_io;
509489
}
510490

511491
/* Auto-generate integrity metadata if this is a write */

0 commit comments

Comments
 (0)