mirror of
https://mirrors.bfsu.edu.cn/git/linux.git
synced 2024-12-01 08:04:22 +08:00
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 <hch@lst.de> Reviewed-by: Kanchan Joshi <joshi.k@samsung.com> Reviewed-by: Martin K. Petersen <martin.petersen@oracle.com> Link: https://lore.kernel.org/r/20240626045950.189758-3-hch@lst.de Signed-off-by: Jens Axboe <axboe@kernel.dk>
This commit is contained in:
parent
c546d6f438
commit
c096df9083
@ -428,10 +428,8 @@ bool bio_integrity_prep(struct bio *bio)
|
|||||||
{
|
{
|
||||||
struct bio_integrity_payload *bip;
|
struct bio_integrity_payload *bip;
|
||||||
struct blk_integrity *bi = blk_get_integrity(bio->bi_bdev->bd_disk);
|
struct blk_integrity *bi = blk_get_integrity(bio->bi_bdev->bd_disk);
|
||||||
|
unsigned int len;
|
||||||
void *buf;
|
void *buf;
|
||||||
unsigned long start, end;
|
|
||||||
unsigned int len, nr_pages;
|
|
||||||
unsigned int bytes, offset, i;
|
|
||||||
gfp_t gfp = GFP_NOIO;
|
gfp_t gfp = GFP_NOIO;
|
||||||
|
|
||||||
if (!bi)
|
if (!bi)
|
||||||
@ -471,12 +469,7 @@ bool bio_integrity_prep(struct bio *bio)
|
|||||||
goto err_end_io;
|
goto err_end_io;
|
||||||
}
|
}
|
||||||
|
|
||||||
end = (((unsigned long) buf) + len + PAGE_SIZE - 1) >> PAGE_SHIFT;
|
bip = bio_integrity_alloc(bio, GFP_NOIO, 1);
|
||||||
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);
|
|
||||||
if (IS_ERR(bip)) {
|
if (IS_ERR(bip)) {
|
||||||
printk(KERN_ERR "could not allocate data integrity bioset\n");
|
printk(KERN_ERR "could not allocate data integrity bioset\n");
|
||||||
kfree(buf);
|
kfree(buf);
|
||||||
@ -489,23 +482,10 @@ bool bio_integrity_prep(struct bio *bio)
|
|||||||
if (bi->csum_type == BLK_INTEGRITY_CSUM_IP)
|
if (bi->csum_type == BLK_INTEGRITY_CSUM_IP)
|
||||||
bip->bip_flags |= BIP_IP_CHECKSUM;
|
bip->bip_flags |= BIP_IP_CHECKSUM;
|
||||||
|
|
||||||
/* Map it */
|
if (bio_integrity_add_page(bio, virt_to_page(buf), len,
|
||||||
offset = offset_in_page(buf);
|
offset_in_page(buf)) < len) {
|
||||||
for (i = 0; i < nr_pages && len > 0; i++) {
|
printk(KERN_ERR "could not attach integrity payload\n");
|
||||||
bytes = PAGE_SIZE - offset;
|
goto err_end_io;
|
||||||
|
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Auto-generate integrity metadata if this is a write */
|
/* Auto-generate integrity metadata if this is a write */
|
||||||
|
Loading…
Reference in New Issue
Block a user