Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

block: move integrity handling out of <linux/blkdev.h>

Split the integrity/metadata handling definitions out into a new header.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Johannes Thumshirn <johannes.thumshirn@wdc.com>
Link: https://lore.kernel.org/r/20210920123328.1399408-17-hch@lst.de
Signed-off-by: Jens Axboe <axboe@kernel.dk>

authored by

Christoph Hellwig and committed by
Jens Axboe
fe45e630 badf7f64

+205 -187
+1
block/bdev.c
··· 12 12 #include <linux/major.h> 13 13 #include <linux/device_cgroup.h> 14 14 #include <linux/blkdev.h> 15 + #include <linux/blk-integrity.h> 15 16 #include <linux/backing-dev.h> 16 17 #include <linux/module.h> 17 18 #include <linux/blkpg.h>
+1 -1
block/bio-integrity.c
··· 6 6 * Written by: Martin K. Petersen <martin.petersen@oracle.com> 7 7 */ 8 8 9 - #include <linux/blkdev.h> 9 + #include <linux/blk-integrity.h> 10 10 #include <linux/mempool.h> 11 11 #include <linux/export.h> 12 12 #include <linux/bio.h>
+1
block/blk-core.c
··· 18 18 #include <linux/blkdev.h> 19 19 #include <linux/blk-mq.h> 20 20 #include <linux/blk-pm.h> 21 + #include <linux/blk-integrity.h> 21 22 #include <linux/highmem.h> 22 23 #include <linux/mm.h> 23 24 #include <linux/pagemap.h>
+1 -1
block/blk-integrity.c
··· 6 6 * Written by: Martin K. Petersen <martin.petersen@oracle.com> 7 7 */ 8 8 9 - #include <linux/blkdev.h> 9 + #include <linux/blk-integrity.h> 10 10 #include <linux/backing-dev.h> 11 11 #include <linux/mempool.h> 12 12 #include <linux/bio.h>
+1
block/blk-merge.c
··· 6 6 #include <linux/module.h> 7 7 #include <linux/bio.h> 8 8 #include <linux/blkdev.h> 9 + #include <linux/blk-integrity.h> 9 10 #include <linux/scatterlist.h> 10 11 11 12 #include <trace/events/block.h>
+1
block/blk-mq.c
··· 10 10 #include <linux/backing-dev.h> 11 11 #include <linux/bio.h> 12 12 #include <linux/blkdev.h> 13 + #include <linux/blk-integrity.h> 13 14 #include <linux/kmemleak.h> 14 15 #include <linux/mm.h> 15 16 #include <linux/init.h>
+1
block/keyslot-manager.c
··· 35 35 #include <linux/pm_runtime.h> 36 36 #include <linux/wait.h> 37 37 #include <linux/blkdev.h> 38 + #include <linux/blk-integrity.h> 38 39 39 40 struct blk_ksm_keyslot { 40 41 atomic_t slot_refs;
+1 -1
block/t10-pi.c
··· 5 5 */ 6 6 7 7 #include <linux/t10-pi.h> 8 - #include <linux/blkdev.h> 8 + #include <linux/blk-integrity.h> 9 9 #include <linux/crc-t10dif.h> 10 10 #include <linux/module.h> 11 11 #include <net/checksum.h>
+1
drivers/md/dm-bio-record.h
··· 8 8 #define DM_BIO_RECORD_H 9 9 10 10 #include <linux/bio.h> 11 + #include <linux/blk-integrity.h> 11 12 12 13 /* 13 14 * There are lots of mutable fields in the bio struct that get
+1
drivers/md/dm-crypt.c
··· 15 15 #include <linux/key.h> 16 16 #include <linux/bio.h> 17 17 #include <linux/blkdev.h> 18 + #include <linux/blk-integrity.h> 18 19 #include <linux/mempool.h> 19 20 #include <linux/slab.h> 20 21 #include <linux/crypto.h>
+1
drivers/md/dm-table.c
··· 10 10 #include <linux/module.h> 11 11 #include <linux/vmalloc.h> 12 12 #include <linux/blkdev.h> 13 + #include <linux/blk-integrity.h> 13 14 #include <linux/namei.h> 14 15 #include <linux/ctype.h> 15 16 #include <linux/string.h>
+1
drivers/md/md.c
··· 41 41 #include <linux/sched/signal.h> 42 42 #include <linux/kthread.h> 43 43 #include <linux/blkdev.h> 44 + #include <linux/blk-integrity.h> 44 45 #include <linux/badblocks.h> 45 46 #include <linux/sysctl.h> 46 47 #include <linux/seq_file.h>
+1
drivers/nvdimm/core.c
··· 7 7 #include <linux/export.h> 8 8 #include <linux/module.h> 9 9 #include <linux/blkdev.h> 10 + #include <linux/blk-integrity.h> 10 11 #include <linux/device.h> 11 12 #include <linux/ctype.h> 12 13 #include <linux/ndctl.h>
+1
drivers/nvme/host/core.c
··· 6 6 7 7 #include <linux/blkdev.h> 8 8 #include <linux/blk-mq.h> 9 + #include <linux/blk-integrity.h> 9 10 #include <linux/compat.h> 10 11 #include <linux/delay.h> 11 12 #include <linux/errno.h>
+1
drivers/nvme/host/pci.c
··· 10 10 #include <linux/blkdev.h> 11 11 #include <linux/blk-mq.h> 12 12 #include <linux/blk-mq-pci.h> 13 + #include <linux/blk-integrity.h> 13 14 #include <linux/dmi.h> 14 15 #include <linux/init.h> 15 16 #include <linux/interrupt.h>
+1
drivers/nvme/host/rdma.c
··· 13 13 #include <linux/atomic.h> 14 14 #include <linux/blk-mq.h> 15 15 #include <linux/blk-mq-rdma.h> 16 + #include <linux/blk-integrity.h> 16 17 #include <linux/types.h> 17 18 #include <linux/list.h> 18 19 #include <linux/mutex.h>
+1
drivers/nvme/target/io-cmd-bdev.c
··· 5 5 */ 6 6 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt 7 7 #include <linux/blkdev.h> 8 + #include <linux/blk-integrity.h> 8 9 #include <linux/module.h> 9 10 #include "nvmet.h" 10 11
+1
drivers/nvme/target/rdma.c
··· 5 5 */ 6 6 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt 7 7 #include <linux/atomic.h> 8 + #include <linux/blk-integrity.h> 8 9 #include <linux/ctype.h> 9 10 #include <linux/delay.h> 10 11 #include <linux/err.h>
+1
drivers/scsi/scsi_lib.c
··· 21 21 #include <linux/hardirq.h> 22 22 #include <linux/scatterlist.h> 23 23 #include <linux/blk-mq.h> 24 + #include <linux/blk-integrity.h> 24 25 #include <linux/ratelimit.h> 25 26 #include <asm/unaligned.h> 26 27
+1 -1
drivers/scsi/sd_dif.c
··· 6 6 * Written by: Martin K. Petersen <martin.petersen@oracle.com> 7 7 */ 8 8 9 - #include <linux/blkdev.h> 9 + #include <linux/blk-integrity.h> 10 10 #include <linux/t10-pi.h> 11 11 12 12 #include <scsi/scsi.h>
+1
drivers/scsi/virtio_scsi.c
··· 22 22 #include <linux/virtio_scsi.h> 23 23 #include <linux/cpu.h> 24 24 #include <linux/blkdev.h> 25 + #include <linux/blk-integrity.h> 25 26 #include <scsi/scsi_host.h> 26 27 #include <scsi/scsi_device.h> 27 28 #include <scsi/scsi_cmnd.h>
+1
drivers/target/target_core_iblock.c
··· 16 16 #include <linux/timer.h> 17 17 #include <linux/fs.h> 18 18 #include <linux/blkdev.h> 19 + #include <linux/blk-integrity.h> 19 20 #include <linux/slab.h> 20 21 #include <linux/spinlock.h> 21 22 #include <linux/bio.h>
+183
include/linux/blk-integrity.h
··· 1 + /* SPDX-License-Identifier: GPL-2.0 */ 2 + #ifndef _LINUX_BLK_INTEGRITY_H 3 + #define _LINUX_BLK_INTEGRITY_H 4 + 5 + #include <linux/blk-mq.h> 6 + 7 + struct request; 8 + 9 + enum blk_integrity_flags { 10 + BLK_INTEGRITY_VERIFY = 1 << 0, 11 + BLK_INTEGRITY_GENERATE = 1 << 1, 12 + BLK_INTEGRITY_DEVICE_CAPABLE = 1 << 2, 13 + BLK_INTEGRITY_IP_CHECKSUM = 1 << 3, 14 + }; 15 + 16 + struct blk_integrity_iter { 17 + void *prot_buf; 18 + void *data_buf; 19 + sector_t seed; 20 + unsigned int data_size; 21 + unsigned short interval; 22 + const char *disk_name; 23 + }; 24 + 25 + typedef blk_status_t (integrity_processing_fn) (struct blk_integrity_iter *); 26 + typedef void (integrity_prepare_fn) (struct request *); 27 + typedef void (integrity_complete_fn) (struct request *, unsigned int); 28 + 29 + struct blk_integrity_profile { 30 + integrity_processing_fn *generate_fn; 31 + integrity_processing_fn *verify_fn; 32 + integrity_prepare_fn *prepare_fn; 33 + integrity_complete_fn *complete_fn; 34 + const char *name; 35 + }; 36 + 37 + #ifdef CONFIG_BLK_DEV_INTEGRITY 38 + void blk_integrity_register(struct gendisk *, struct blk_integrity *); 39 + void blk_integrity_unregister(struct gendisk *); 40 + int blk_integrity_compare(struct gendisk *, struct gendisk *); 41 + int blk_rq_map_integrity_sg(struct request_queue *, struct bio *, 42 + struct scatterlist *); 43 + int blk_rq_count_integrity_sg(struct request_queue *, struct bio *); 44 + 45 + static inline struct blk_integrity *blk_get_integrity(struct gendisk *disk) 46 + { 47 + struct blk_integrity *bi = &disk->queue->integrity; 48 + 49 + if (!bi->profile) 50 + return NULL; 51 + 52 + return bi; 53 + } 54 + 55 + static inline struct blk_integrity * 56 + bdev_get_integrity(struct block_device *bdev) 57 + { 58 + return blk_get_integrity(bdev->bd_disk); 59 + } 60 + 61 + static inline bool 62 + blk_integrity_queue_supports_integrity(struct request_queue *q) 63 + { 64 + return q->integrity.profile; 65 + } 66 + 67 + static inline void blk_queue_max_integrity_segments(struct request_queue *q, 68 + unsigned int segs) 69 + { 70 + q->limits.max_integrity_segments = segs; 71 + } 72 + 73 + static inline unsigned short 74 + queue_max_integrity_segments(const struct request_queue *q) 75 + { 76 + return q->limits.max_integrity_segments; 77 + } 78 + 79 + /** 80 + * bio_integrity_intervals - Return number of integrity intervals for a bio 81 + * @bi: blk_integrity profile for device 82 + * @sectors: Size of the bio in 512-byte sectors 83 + * 84 + * Description: The block layer calculates everything in 512 byte 85 + * sectors but integrity metadata is done in terms of the data integrity 86 + * interval size of the storage device. Convert the block layer sectors 87 + * to the appropriate number of integrity intervals. 88 + */ 89 + static inline unsigned int bio_integrity_intervals(struct blk_integrity *bi, 90 + unsigned int sectors) 91 + { 92 + return sectors >> (bi->interval_exp - 9); 93 + } 94 + 95 + static inline unsigned int bio_integrity_bytes(struct blk_integrity *bi, 96 + unsigned int sectors) 97 + { 98 + return bio_integrity_intervals(bi, sectors) * bi->tuple_size; 99 + } 100 + 101 + static inline bool blk_integrity_rq(struct request *rq) 102 + { 103 + return rq->cmd_flags & REQ_INTEGRITY; 104 + } 105 + 106 + /* 107 + * Return the first bvec that contains integrity data. Only drivers that are 108 + * limited to a single integrity segment should use this helper. 109 + */ 110 + static inline struct bio_vec *rq_integrity_vec(struct request *rq) 111 + { 112 + if (WARN_ON_ONCE(queue_max_integrity_segments(rq->q) > 1)) 113 + return NULL; 114 + return rq->bio->bi_integrity->bip_vec; 115 + } 116 + #else /* CONFIG_BLK_DEV_INTEGRITY */ 117 + static inline int blk_rq_count_integrity_sg(struct request_queue *q, 118 + struct bio *b) 119 + { 120 + return 0; 121 + } 122 + static inline int blk_rq_map_integrity_sg(struct request_queue *q, 123 + struct bio *b, 124 + struct scatterlist *s) 125 + { 126 + return 0; 127 + } 128 + static inline struct blk_integrity *bdev_get_integrity(struct block_device *b) 129 + { 130 + return NULL; 131 + } 132 + static inline struct blk_integrity *blk_get_integrity(struct gendisk *disk) 133 + { 134 + return NULL; 135 + } 136 + static inline bool 137 + blk_integrity_queue_supports_integrity(struct request_queue *q) 138 + { 139 + return false; 140 + } 141 + static inline int blk_integrity_compare(struct gendisk *a, struct gendisk *b) 142 + { 143 + return 0; 144 + } 145 + static inline void blk_integrity_register(struct gendisk *d, 146 + struct blk_integrity *b) 147 + { 148 + } 149 + static inline void blk_integrity_unregister(struct gendisk *d) 150 + { 151 + } 152 + static inline void blk_queue_max_integrity_segments(struct request_queue *q, 153 + unsigned int segs) 154 + { 155 + } 156 + static inline unsigned short 157 + queue_max_integrity_segments(const struct request_queue *q) 158 + { 159 + return 0; 160 + } 161 + 162 + static inline unsigned int bio_integrity_intervals(struct blk_integrity *bi, 163 + unsigned int sectors) 164 + { 165 + return 0; 166 + } 167 + 168 + static inline unsigned int bio_integrity_bytes(struct blk_integrity *bi, 169 + unsigned int sectors) 170 + { 171 + return 0; 172 + } 173 + static inline int blk_integrity_rq(struct request *rq) 174 + { 175 + return 0; 176 + } 177 + 178 + static inline struct bio_vec *rq_integrity_vec(struct request *rq) 179 + { 180 + return NULL; 181 + } 182 + #endif /* CONFIG_BLK_DEV_INTEGRITY */ 183 + #endif /* _LINUX_BLK_INTEGRITY_H */
-183
include/linux/blkdev.h
··· 1555 1555 #define MODULE_ALIAS_BLOCKDEV_MAJOR(major) \ 1556 1556 MODULE_ALIAS("block-major-" __stringify(major) "-*") 1557 1557 1558 - #if defined(CONFIG_BLK_DEV_INTEGRITY) 1559 - 1560 - enum blk_integrity_flags { 1561 - BLK_INTEGRITY_VERIFY = 1 << 0, 1562 - BLK_INTEGRITY_GENERATE = 1 << 1, 1563 - BLK_INTEGRITY_DEVICE_CAPABLE = 1 << 2, 1564 - BLK_INTEGRITY_IP_CHECKSUM = 1 << 3, 1565 - }; 1566 - 1567 - struct blk_integrity_iter { 1568 - void *prot_buf; 1569 - void *data_buf; 1570 - sector_t seed; 1571 - unsigned int data_size; 1572 - unsigned short interval; 1573 - const char *disk_name; 1574 - }; 1575 - 1576 - typedef blk_status_t (integrity_processing_fn) (struct blk_integrity_iter *); 1577 - typedef void (integrity_prepare_fn) (struct request *); 1578 - typedef void (integrity_complete_fn) (struct request *, unsigned int); 1579 - 1580 - struct blk_integrity_profile { 1581 - integrity_processing_fn *generate_fn; 1582 - integrity_processing_fn *verify_fn; 1583 - integrity_prepare_fn *prepare_fn; 1584 - integrity_complete_fn *complete_fn; 1585 - const char *name; 1586 - }; 1587 - 1588 - extern void blk_integrity_register(struct gendisk *, struct blk_integrity *); 1589 - extern void blk_integrity_unregister(struct gendisk *); 1590 - extern int blk_integrity_compare(struct gendisk *, struct gendisk *); 1591 - extern int blk_rq_map_integrity_sg(struct request_queue *, struct bio *, 1592 - struct scatterlist *); 1593 - extern int blk_rq_count_integrity_sg(struct request_queue *, struct bio *); 1594 - 1595 - static inline struct blk_integrity *blk_get_integrity(struct gendisk *disk) 1596 - { 1597 - struct blk_integrity *bi = &disk->queue->integrity; 1598 - 1599 - if (!bi->profile) 1600 - return NULL; 1601 - 1602 - return bi; 1603 - } 1604 - 1605 - static inline 1606 - struct blk_integrity *bdev_get_integrity(struct block_device *bdev) 1607 - { 1608 - return blk_get_integrity(bdev->bd_disk); 1609 - } 1610 - 1611 - static inline bool 1612 - blk_integrity_queue_supports_integrity(struct request_queue *q) 1613 - { 1614 - return q->integrity.profile; 1615 - } 1616 - 1617 - static inline bool blk_integrity_rq(struct request *rq) 1618 - { 1619 - return rq->cmd_flags & REQ_INTEGRITY; 1620 - } 1621 - 1622 - static inline void blk_queue_max_integrity_segments(struct request_queue *q, 1623 - unsigned int segs) 1624 - { 1625 - q->limits.max_integrity_segments = segs; 1626 - } 1627 - 1628 - static inline unsigned short 1629 - queue_max_integrity_segments(const struct request_queue *q) 1630 - { 1631 - return q->limits.max_integrity_segments; 1632 - } 1633 - 1634 - /** 1635 - * bio_integrity_intervals - Return number of integrity intervals for a bio 1636 - * @bi: blk_integrity profile for device 1637 - * @sectors: Size of the bio in 512-byte sectors 1638 - * 1639 - * Description: The block layer calculates everything in 512 byte 1640 - * sectors but integrity metadata is done in terms of the data integrity 1641 - * interval size of the storage device. Convert the block layer sectors 1642 - * to the appropriate number of integrity intervals. 1643 - */ 1644 - static inline unsigned int bio_integrity_intervals(struct blk_integrity *bi, 1645 - unsigned int sectors) 1646 - { 1647 - return sectors >> (bi->interval_exp - 9); 1648 - } 1649 - 1650 - static inline unsigned int bio_integrity_bytes(struct blk_integrity *bi, 1651 - unsigned int sectors) 1652 - { 1653 - return bio_integrity_intervals(bi, sectors) * bi->tuple_size; 1654 - } 1655 - 1656 - /* 1657 - * Return the first bvec that contains integrity data. Only drivers that are 1658 - * limited to a single integrity segment should use this helper. 1659 - */ 1660 - static inline struct bio_vec *rq_integrity_vec(struct request *rq) 1661 - { 1662 - if (WARN_ON_ONCE(queue_max_integrity_segments(rq->q) > 1)) 1663 - return NULL; 1664 - return rq->bio->bi_integrity->bip_vec; 1665 - } 1666 - 1667 - #else /* CONFIG_BLK_DEV_INTEGRITY */ 1668 - 1669 - struct bio; 1670 - struct block_device; 1671 - struct gendisk; 1672 - struct blk_integrity; 1673 - 1674 - static inline int blk_integrity_rq(struct request *rq) 1675 - { 1676 - return 0; 1677 - } 1678 - static inline int blk_rq_count_integrity_sg(struct request_queue *q, 1679 - struct bio *b) 1680 - { 1681 - return 0; 1682 - } 1683 - static inline int blk_rq_map_integrity_sg(struct request_queue *q, 1684 - struct bio *b, 1685 - struct scatterlist *s) 1686 - { 1687 - return 0; 1688 - } 1689 - static inline struct blk_integrity *bdev_get_integrity(struct block_device *b) 1690 - { 1691 - return NULL; 1692 - } 1693 - static inline struct blk_integrity *blk_get_integrity(struct gendisk *disk) 1694 - { 1695 - return NULL; 1696 - } 1697 - static inline bool 1698 - blk_integrity_queue_supports_integrity(struct request_queue *q) 1699 - { 1700 - return false; 1701 - } 1702 - static inline int blk_integrity_compare(struct gendisk *a, struct gendisk *b) 1703 - { 1704 - return 0; 1705 - } 1706 - static inline void blk_integrity_register(struct gendisk *d, 1707 - struct blk_integrity *b) 1708 - { 1709 - } 1710 - static inline void blk_integrity_unregister(struct gendisk *d) 1711 - { 1712 - } 1713 - static inline void blk_queue_max_integrity_segments(struct request_queue *q, 1714 - unsigned int segs) 1715 - { 1716 - } 1717 - static inline unsigned short queue_max_integrity_segments(const struct request_queue *q) 1718 - { 1719 - return 0; 1720 - } 1721 - 1722 - static inline unsigned int bio_integrity_intervals(struct blk_integrity *bi, 1723 - unsigned int sectors) 1724 - { 1725 - return 0; 1726 - } 1727 - 1728 - static inline unsigned int bio_integrity_bytes(struct blk_integrity *bi, 1729 - unsigned int sectors) 1730 - { 1731 - return 0; 1732 - } 1733 - 1734 - static inline struct bio_vec *rq_integrity_vec(struct request *rq) 1735 - { 1736 - return NULL; 1737 - } 1738 - 1739 - #endif /* CONFIG_BLK_DEV_INTEGRITY */ 1740 - 1741 1558 #ifdef CONFIG_BLK_INLINE_ENCRYPTION 1742 1559 1743 1560 bool blk_ksm_register(struct blk_keyslot_manager *ksm, struct request_queue *q);