From: Christoph Hellwig <hch@lst.de>
To: Jens Axboe <axboe@kernel.dk>
Cc: "Martin K . Petersen" <martin.petersen@oracle.com>,
linux-block@vger.kernel.org
Subject: [PATCH 2/5] block: simplify adding the payload in bio_integrity_prep
Date: Wed, 26 Jun 2024 06:59:35 +0200 [thread overview]
Message-ID: <20240626045950.189758-3-hch@lst.de> (raw)
In-Reply-To: <20240626045950.189758-1-hch@lst.de>
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 <hch@lst.de>
---
block/bio-integrity.c | 32 ++++++--------------------------
1 file changed, 6 insertions(+), 26 deletions(-)
diff --git a/block/bio-integrity.c b/block/bio-integrity.c
index 8c5991a1c535af..2efab4b3957978 100644
--- a/block/bio-integrity.c
+++ b/block/bio-integrity.c
@@ -428,10 +428,8 @@ bool bio_integrity_prep(struct bio *bio)
{
struct bio_integrity_payload *bip;
struct blk_integrity *bi = blk_get_integrity(bio->bi_bdev->bd_disk);
+ unsigned int len;
void *buf;
- unsigned long start, end;
- unsigned int len, nr_pages;
- unsigned int bytes, offset, i;
gfp_t gfp = GFP_NOIO;
if (!bi)
@@ -471,12 +469,7 @@ bool bio_integrity_prep(struct bio *bio)
goto err_end_io;
}
- end = (((unsigned long) buf) + len + PAGE_SIZE - 1) >> PAGE_SHIFT;
- start = ((unsigned long) buf) >> PAGE_SHIFT;
- nr_pages = end - start;
-
- /* Allocate bio integrity payload and integrity vectors */
- bip = bio_integrity_alloc(bio, GFP_NOIO, nr_pages);
+ bip = bio_integrity_alloc(bio, GFP_NOIO, 1);
if (IS_ERR(bip)) {
printk(KERN_ERR "could not allocate data integrity bioset\n");
kfree(buf);
@@ -489,23 +482,10 @@ bool bio_integrity_prep(struct bio *bio)
if (bi->csum_type == BLK_INTEGRITY_CSUM_IP)
bip->bip_flags |= BIP_IP_CHECKSUM;
- /* Map it */
- offset = offset_in_page(buf);
- for (i = 0; i < nr_pages && len > 0; i++) {
- bytes = PAGE_SIZE - offset;
-
- if (bytes > len)
- bytes = len;
-
- if (bio_integrity_add_page(bio, virt_to_page(buf),
- bytes, offset) < bytes) {
- printk(KERN_ERR "could not attach integrity payload\n");
- goto err_end_io;
- }
-
- buf += bytes;
- len -= bytes;
- offset = 0;
+ if (bio_integrity_add_page(bio, virt_to_page(buf), len,
+ offset_in_page(buf)) < len) {
+ printk(KERN_ERR "could not attach integrity payload\n");
+ goto err_end_io;
}
/* Auto-generate integrity metadata if this is a write */
--
2.43.0
next prev parent reply other threads:[~2024-06-26 4:59 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-06-26 4:59 integrity cleanups Christoph Hellwig
2024-06-26 4:59 ` [PATCH 1/5] block: only zero non-PI metadata tuples in bio_integrity_prep Christoph Hellwig
2024-06-27 15:42 ` Kanchan Joshi
2024-06-26 4:59 ` Christoph Hellwig [this message]
2024-06-27 15:42 ` [PATCH 2/5] block: simplify adding the payload " Kanchan Joshi
2024-06-26 4:59 ` [PATCH 3/5] block: remove allocation failure warnings " Christoph Hellwig
2024-06-27 15:42 ` Kanchan Joshi
2024-06-26 4:59 ` [PATCH 4/5] block: switch on bio operation " Christoph Hellwig
2024-06-27 15:41 ` Kanchan Joshi
2024-06-26 4:59 ` [PATCH 5/5] block: remove bio_integrity_process Christoph Hellwig
2024-06-27 15:36 ` Kanchan Joshi
2024-06-27 15:47 ` Christoph Hellwig
2024-06-27 18:33 ` Kanchan Joshi
2024-06-28 6:02 ` Christoph Hellwig
2024-06-27 3:44 ` integrity cleanups Martin K. Petersen
2024-06-28 16:30 ` Jens Axboe
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20240626045950.189758-3-hch@lst.de \
--to=hch@lst.de \
--cc=axboe@kernel.dk \
--cc=linux-block@vger.kernel.org \
--cc=martin.petersen@oracle.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox