1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef _LINUX_BIO_INTEGRITY_H
3 #define _LINUX_BIO_INTEGRITY_H
8 BIP_BLOCK_INTEGRITY
= 1 << 0, /* block layer owns integrity data */
9 BIP_MAPPED_INTEGRITY
= 1 << 1, /* ref tag has been remapped */
10 BIP_CTRL_NOCHECK
= 1 << 2, /* disable HBA integrity checking */
11 BIP_DISK_NOCHECK
= 1 << 3, /* disable disk integrity checking */
12 BIP_IP_CHECKSUM
= 1 << 4, /* IP checksum */
13 BIP_COPY_USER
= 1 << 5, /* Kernel bounce buffer in use */
16 struct bio_integrity_payload
{
17 struct bio
*bip_bio
; /* parent bio */
19 struct bvec_iter bip_iter
;
21 unsigned short bip_vcnt
; /* # of integrity bio_vecs */
22 unsigned short bip_max_vcnt
; /* integrity bio_vec slots */
23 unsigned short bip_flags
; /* control flags */
25 struct bvec_iter bio_iter
; /* for rewinding parent bio */
27 struct work_struct bip_work
; /* I/O completion */
29 struct bio_vec
*bip_vec
;
30 struct bio_vec bip_inline_vecs
[];/* embedded bvec array */
33 #ifdef CONFIG_BLK_DEV_INTEGRITY
35 #define bip_for_each_vec(bvl, bip, iter) \
36 for_each_bvec(bvl, (bip)->bip_vec, iter, (bip)->bip_iter)
38 #define bio_for_each_integrity_vec(_bvl, _bio, _iter) \
40 bip_for_each_vec(_bvl, _bio->bi_integrity, _iter)
42 static inline struct bio_integrity_payload
*bio_integrity(struct bio
*bio
)
44 if (bio
->bi_opf
& REQ_INTEGRITY
)
45 return bio
->bi_integrity
;
50 static inline bool bio_integrity_flagged(struct bio
*bio
, enum bip_flags flag
)
52 struct bio_integrity_payload
*bip
= bio_integrity(bio
);
55 return bip
->bip_flags
& flag
;
60 static inline sector_t
bip_get_seed(struct bio_integrity_payload
*bip
)
62 return bip
->bip_iter
.bi_sector
;
65 static inline void bip_set_seed(struct bio_integrity_payload
*bip
,
68 bip
->bip_iter
.bi_sector
= seed
;
71 struct bio_integrity_payload
*bio_integrity_alloc(struct bio
*bio
, gfp_t gfp
,
73 int bio_integrity_add_page(struct bio
*bio
, struct page
*page
, unsigned int len
,
75 int bio_integrity_map_user(struct bio
*bio
, void __user
*ubuf
, ssize_t len
);
76 void bio_integrity_unmap_user(struct bio
*bio
);
77 bool bio_integrity_prep(struct bio
*bio
);
78 void bio_integrity_advance(struct bio
*bio
, unsigned int bytes_done
);
79 void bio_integrity_trim(struct bio
*bio
);
80 int bio_integrity_clone(struct bio
*bio
, struct bio
*bio_src
, gfp_t gfp_mask
);
81 int bioset_integrity_create(struct bio_set
*bs
, int pool_size
);
82 void bioset_integrity_free(struct bio_set
*bs
);
83 void bio_integrity_init(void);
85 #else /* CONFIG_BLK_DEV_INTEGRITY */
87 static inline struct bio_integrity_payload
*bio_integrity(struct bio
*bio
)
92 static inline int bioset_integrity_create(struct bio_set
*bs
, int pool_size
)
97 static inline void bioset_integrity_free(struct bio_set
*bs
)
101 static inline int bio_integrity_map_user(struct bio
*bio
, void __user
*ubuf
,
107 static inline void bio_integrity_unmap_user(struct bio
*bio
)
111 static inline bool bio_integrity_prep(struct bio
*bio
)
116 static inline int bio_integrity_clone(struct bio
*bio
, struct bio
*bio_src
,
122 static inline void bio_integrity_advance(struct bio
*bio
,
123 unsigned int bytes_done
)
127 static inline void bio_integrity_trim(struct bio
*bio
)
131 static inline void bio_integrity_init(void)
135 static inline bool bio_integrity_flagged(struct bio
*bio
, enum bip_flags flag
)
140 static inline struct bio_integrity_payload
*
141 bio_integrity_alloc(struct bio
*bio
, gfp_t gfp
, unsigned int nr
)
143 return ERR_PTR(-EINVAL
);
146 static inline int bio_integrity_add_page(struct bio
*bio
, struct page
*page
,
147 unsigned int len
, unsigned int offset
)
151 #endif /* CONFIG_BLK_DEV_INTEGRITY */
152 #endif /* _LINUX_BIO_INTEGRITY_H */