@@ -39,7 +39,7 @@ static void bio_integrity_verify_fn(struct work_struct *work)
3939 container_of (work , struct bio_integrity_data , work );
4040 struct bio * bio = bid -> bio ;
4141
42- blk_integrity_verify_iter (bio , & bid -> saved_bio_iter );
42+ bio -> bi_status = bio_integrity_verify (bio , & bid -> saved_bio_iter );
4343 bio_integrity_finish (bid );
4444 bio_endio (bio );
4545}
@@ -50,11 +50,6 @@ static bool bip_should_check(struct bio_integrity_payload *bip)
5050 return bip -> bip_flags & BIP_CHECK_FLAGS ;
5151}
5252
53- static bool bi_offload_capable (struct blk_integrity * bi )
54- {
55- return bi -> metadata_size == bi -> pi_tuple_size ;
56- }
57-
5853/**
5954 * __bio_integrity_endio - Integrity I/O completion function
6055 * @bio: Protected bio
@@ -84,83 +79,30 @@ bool __bio_integrity_endio(struct bio *bio)
8479/**
8580 * bio_integrity_prep - Prepare bio for integrity I/O
8681 * @bio: bio to prepare
82+ * @action: preparation action needed (BI_ACT_*)
8783 *
88- * Checks if the bio already has an integrity payload attached. If it does, the
89- * payload has been generated by another kernel subsystem, and we just pass it
90- * through.
91- * Otherwise allocates integrity payload and for writes the integrity metadata
92- * will be generated. For reads, the completion handler will verify the
93- * metadata.
84+ * Allocate the integrity payload. For writes, generate the integrity metadata
85+ * and for reads, setup the completion handler to verify the metadata.
86+ *
87+ * This is used for bios that do not have user integrity payloads attached.
9488 */
95- bool bio_integrity_prep (struct bio * bio )
89+ void bio_integrity_prep (struct bio * bio , unsigned int action )
9690{
97- struct blk_integrity * bi = blk_get_integrity (bio -> bi_bdev -> bd_disk );
9891 struct bio_integrity_data * bid ;
99- bool set_flags = true;
100- gfp_t gfp = GFP_NOIO ;
101-
102- if (!bi )
103- return true;
104-
105- if (!bio_sectors (bio ))
106- return true;
107-
108- /* Already protected? */
109- if (bio_integrity (bio ))
110- return true;
111-
112- switch (bio_op (bio )) {
113- case REQ_OP_READ :
114- if (bi -> flags & BLK_INTEGRITY_NOVERIFY ) {
115- if (bi_offload_capable (bi ))
116- return true;
117- set_flags = false;
118- }
119- break ;
120- case REQ_OP_WRITE :
121- /*
122- * Zero the memory allocated to not leak uninitialized kernel
123- * memory to disk for non-integrity metadata where nothing else
124- * initializes the memory.
125- */
126- if (bi -> flags & BLK_INTEGRITY_NOGENERATE ) {
127- if (bi_offload_capable (bi ))
128- return true;
129- set_flags = false;
130- gfp |= __GFP_ZERO ;
131- } else if (bi -> metadata_size > bi -> pi_tuple_size )
132- gfp |= __GFP_ZERO ;
133- break ;
134- default :
135- return true;
136- }
137-
138- if (WARN_ON_ONCE (bio_has_crypt_ctx (bio )))
139- return true;
14092
14193 bid = mempool_alloc (& bid_pool , GFP_NOIO );
14294 bio_integrity_init (bio , & bid -> bip , & bid -> bvec , 1 );
14395 bid -> bio = bio ;
14496 bid -> bip .bip_flags |= BIP_BLOCK_INTEGRITY ;
145- bio_integrity_alloc_buf (bio , gfp & __GFP_ZERO );
146-
147- bip_set_seed (& bid -> bip , bio -> bi_iter .bi_sector );
148-
149- if (set_flags ) {
150- if (bi -> csum_type == BLK_INTEGRITY_CSUM_IP )
151- bid -> bip .bip_flags |= BIP_IP_CHECKSUM ;
152- if (bi -> csum_type )
153- bid -> bip .bip_flags |= BIP_CHECK_GUARD ;
154- if (bi -> flags & BLK_INTEGRITY_REF_TAG )
155- bid -> bip .bip_flags |= BIP_CHECK_REFTAG ;
156- }
97+ bio_integrity_alloc_buf (bio , action & BI_ACT_ZERO );
98+ if (action & BI_ACT_CHECK )
99+ bio_integrity_setup_default (bio );
157100
158101 /* Auto-generate integrity metadata if this is a write */
159102 if (bio_data_dir (bio ) == WRITE && bip_should_check (& bid -> bip ))
160- blk_integrity_generate (bio );
103+ bio_integrity_generate (bio );
161104 else
162105 bid -> saved_bio_iter = bio -> bi_iter ;
163- return true;
164106}
165107EXPORT_SYMBOL (bio_integrity_prep );
166108
0 commit comments