aboutsummaryrefslogtreecommitdiffstats
path: root/block/bio-integrity.c
diff options
context:
space:
mode:
authorMartin K. Petersen <martin.petersen@oracle.com>2014-09-26 19:20:01 -0400
committerJens Axboe <axboe@fb.com>2014-09-27 11:14:51 -0400
commit1859308853b19c4daf4afaab910d3d52ac1ec2ff (patch)
tree3b5a3ffcb96d88320cb609883f436b33b094ac58 /block/bio-integrity.c
parent5a2aa873059fec8b6385071d9c0802893a9b2f41 (diff)
block: Clean up the code used to generate and verify integrity metadata
Instead of the "operate" parameter we pass in a seed value and a pointer to a function that can be used to process the integrity metadata. The generation function is changed to have a return value to fit into this scheme. Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com> Reviewed-by: Sagi Grimberg <sagig@mellanox.com> Signed-off-by: Jens Axboe <axboe@fb.com>
Diffstat (limited to 'block/bio-integrity.c')
-rw-r--r--block/bio-integrity.c82
1 files changed, 22 insertions, 60 deletions
diff --git a/block/bio-integrity.c b/block/bio-integrity.c
index cf40837e7710..fe4de033b34c 100644
--- a/block/bio-integrity.c
+++ b/block/bio-integrity.c
@@ -207,49 +207,37 @@ static inline unsigned int bio_integrity_bytes(struct blk_integrity *bi,
207} 207}
208 208
209/** 209/**
210 * bio_integrity_generate_verify - Generate/verify integrity metadata for a bio 210 * bio_integrity_process - Process integrity metadata for a bio
211 * @bio: bio to generate/verify integrity metadata for 211 * @bio: bio to generate/verify integrity metadata for
212 * @operate: operate number, 1 for generate, 0 for verify 212 * @proc_fn: Pointer to the relevant processing function
213 */ 213 */
214static int bio_integrity_generate_verify(struct bio *bio, int operate) 214static int bio_integrity_process(struct bio *bio,
215 integrity_processing_fn *proc_fn)
215{ 216{
216 struct blk_integrity *bi = bdev_get_integrity(bio->bi_bdev); 217 struct blk_integrity *bi = bdev_get_integrity(bio->bi_bdev);
217 struct blk_integrity_exchg bix; 218 struct blk_integrity_iter iter;
218 struct bio_vec *bv; 219 struct bio_vec *bv;
219 struct bio_integrity_payload *bip = bio_integrity(bio); 220 struct bio_integrity_payload *bip = bio_integrity(bio);
220 sector_t seed; 221 unsigned int i, ret = 0;
221 unsigned int intervals, ret = 0, i;
222 void *prot_buf = page_address(bip->bip_vec->bv_page) + 222 void *prot_buf = page_address(bip->bip_vec->bv_page) +
223 bip->bip_vec->bv_offset; 223 bip->bip_vec->bv_offset;
224 224
225 if (operate) 225 iter.disk_name = bio->bi_bdev->bd_disk->disk_name;
226 seed = bio->bi_iter.bi_sector; 226 iter.interval = bi->interval;
227 else 227 iter.seed = bip_get_seed(bip);
228 seed = bip->bip_iter.bi_sector; 228 iter.prot_buf = prot_buf;
229
230 bix.disk_name = bio->bi_bdev->bd_disk->disk_name;
231 bix.interval = bi->interval;
232 229
233 bio_for_each_segment_all(bv, bio, i) { 230 bio_for_each_segment_all(bv, bio, i) {
234 void *kaddr = kmap_atomic(bv->bv_page); 231 void *kaddr = kmap_atomic(bv->bv_page);
235 bix.data_buf = kaddr + bv->bv_offset;
236 bix.data_size = bv->bv_len;
237 bix.prot_buf = prot_buf;
238 bix.seed = seed;
239
240 if (operate)
241 bi->generate_fn(&bix);
242 else {
243 ret = bi->verify_fn(&bix);
244 if (ret) {
245 kunmap_atomic(kaddr);
246 return ret;
247 }
248 }
249 232
250 intervals = bv->bv_len / bi->interval; 233 iter.data_buf = kaddr + bv->bv_offset;
251 seed += intervals; 234 iter.data_size = bv->bv_len;
252 prot_buf += intervals * bi->tuple_size; 235
236 ret = proc_fn(&iter);
237 if (ret) {
238 kunmap_atomic(kaddr);
239 return ret;
240 }
253 241
254 kunmap_atomic(kaddr); 242 kunmap_atomic(kaddr);
255 } 243 }
@@ -257,20 +245,6 @@ static int bio_integrity_generate_verify(struct bio *bio, int operate)
257} 245}
258 246
259/** 247/**
260 * bio_integrity_generate - Generate integrity metadata for a bio
261 * @bio: bio to generate integrity metadata for
262 *
263 * Description: Generates integrity metadata for a bio by calling the
264 * block device's generation callback function. The bio must have a
265 * bip attached with enough room to accommodate the generated
266 * integrity metadata.
267 */
268static void bio_integrity_generate(struct bio *bio)
269{
270 bio_integrity_generate_verify(bio, 1);
271}
272
273/**
274 * bio_integrity_prep - Prepare bio for integrity I/O 248 * bio_integrity_prep - Prepare bio for integrity I/O
275 * @bio: bio to prepare 249 * @bio: bio to prepare
276 * 250 *
@@ -321,7 +295,7 @@ int bio_integrity_prep(struct bio *bio)
321 295
322 bip->bip_owns_buf = 1; 296 bip->bip_owns_buf = 1;
323 bip->bip_iter.bi_size = len; 297 bip->bip_iter.bi_size = len;
324 bip->bip_iter.bi_sector = bio->bi_iter.bi_sector; 298 bip_set_seed(bip, bio->bi_iter.bi_sector);
325 299
326 /* Map it */ 300 /* Map it */
327 offset = offset_in_page(buf); 301 offset = offset_in_page(buf);
@@ -357,26 +331,13 @@ int bio_integrity_prep(struct bio *bio)
357 331
358 /* Auto-generate integrity metadata if this is a write */ 332 /* Auto-generate integrity metadata if this is a write */
359 if (bio_data_dir(bio) == WRITE) 333 if (bio_data_dir(bio) == WRITE)
360 bio_integrity_generate(bio); 334 bio_integrity_process(bio, bi->generate_fn);
361 335
362 return 0; 336 return 0;
363} 337}
364EXPORT_SYMBOL(bio_integrity_prep); 338EXPORT_SYMBOL(bio_integrity_prep);
365 339
366/** 340/**
367 * bio_integrity_verify - Verify integrity metadata for a bio
368 * @bio: bio to verify
369 *
370 * Description: This function is called to verify the integrity of a
371 * bio. The data in the bio io_vec is compared to the integrity
372 * metadata returned by the HBA.
373 */
374static int bio_integrity_verify(struct bio *bio)
375{
376 return bio_integrity_generate_verify(bio, 0);
377}
378
379/**
380 * bio_integrity_verify_fn - Integrity I/O completion worker 341 * bio_integrity_verify_fn - Integrity I/O completion worker
381 * @work: Work struct stored in bio to be verified 342 * @work: Work struct stored in bio to be verified
382 * 343 *
@@ -389,9 +350,10 @@ static void bio_integrity_verify_fn(struct work_struct *work)
389 struct bio_integrity_payload *bip = 350 struct bio_integrity_payload *bip =
390 container_of(work, struct bio_integrity_payload, bip_work); 351 container_of(work, struct bio_integrity_payload, bip_work);
391 struct bio *bio = bip->bip_bio; 352 struct bio *bio = bip->bip_bio;
353 struct blk_integrity *bi = bdev_get_integrity(bio->bi_bdev);
392 int error; 354 int error;
393 355
394 error = bio_integrity_verify(bio); 356 error = bio_integrity_process(bio, bi->verify_fn);
395 357
396 /* Restore original bio completion handler */ 358 /* Restore original bio completion handler */
397 bio->bi_end_io = bip->bip_end_io; 359 bio->bi_end_io = bip->bip_end_io;