[PATCH] rc32434_wdt: fix compilation failure
[linux-2.6/linux-2.6-openrd.git] / fs / bio-integrity.c
blob49a34e7f7306d49af72b6d84fda277b82d01cc01
1 /*
2 * bio-integrity.c - bio data integrity extensions
4 * Copyright (C) 2007, 2008, 2009 Oracle Corporation
5 * Written by: Martin K. Petersen <martin.petersen@oracle.com>
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License version
9 * 2 as published by the Free Software Foundation.
11 * This program is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; see the file COPYING. If not, write to
18 * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139,
19 * USA.
23 #include <linux/blkdev.h>
24 #include <linux/mempool.h>
25 #include <linux/bio.h>
26 #include <linux/workqueue.h>
28 struct integrity_slab {
29 struct kmem_cache *slab;
30 unsigned short nr_vecs;
31 char name[8];
34 #define IS(x) { .nr_vecs = x, .name = "bip-"__stringify(x) }
35 struct integrity_slab bip_slab[BIOVEC_NR_POOLS] __read_mostly = {
36 IS(1), IS(4), IS(16), IS(64), IS(128), IS(BIO_MAX_PAGES),
38 #undef IS
40 static struct workqueue_struct *kintegrityd_wq;
42 static inline unsigned int vecs_to_idx(unsigned int nr)
44 switch (nr) {
45 case 1:
46 return 0;
47 case 2 ... 4:
48 return 1;
49 case 5 ... 16:
50 return 2;
51 case 17 ... 64:
52 return 3;
53 case 65 ... 128:
54 return 4;
55 case 129 ... BIO_MAX_PAGES:
56 return 5;
57 default:
58 BUG();
62 static inline int use_bip_pool(unsigned int idx)
64 if (idx == BIOVEC_NR_POOLS)
65 return 1;
67 return 0;
70 /**
71 * bio_integrity_alloc_bioset - Allocate integrity payload and attach it to bio
72 * @bio: bio to attach integrity metadata to
73 * @gfp_mask: Memory allocation mask
74 * @nr_vecs: Number of integrity metadata scatter-gather elements
75 * @bs: bio_set to allocate from
77 * Description: This function prepares a bio for attaching integrity
78 * metadata. nr_vecs specifies the maximum number of pages containing
79 * integrity metadata that can be attached.
81 struct bio_integrity_payload *bio_integrity_alloc_bioset(struct bio *bio,
82 gfp_t gfp_mask,
83 unsigned int nr_vecs,
84 struct bio_set *bs)
86 struct bio_integrity_payload *bip;
87 unsigned int idx = vecs_to_idx(nr_vecs);
89 BUG_ON(bio == NULL);
90 bip = NULL;
92 /* Lower order allocations come straight from slab */
93 if (!use_bip_pool(idx))
94 bip = kmem_cache_alloc(bip_slab[idx].slab, gfp_mask);
96 /* Use mempool if lower order alloc failed or max vecs were requested */
97 if (bip == NULL) {
98 bip = mempool_alloc(bs->bio_integrity_pool, gfp_mask);
100 if (unlikely(bip == NULL)) {
101 printk(KERN_ERR "%s: could not alloc bip\n", __func__);
102 return NULL;
106 memset(bip, 0, sizeof(*bip));
108 bip->bip_slab = idx;
109 bip->bip_bio = bio;
110 bio->bi_integrity = bip;
112 return bip;
114 EXPORT_SYMBOL(bio_integrity_alloc_bioset);
117 * bio_integrity_alloc - Allocate integrity payload and attach it to bio
118 * @bio: bio to attach integrity metadata to
119 * @gfp_mask: Memory allocation mask
120 * @nr_vecs: Number of integrity metadata scatter-gather elements
122 * Description: This function prepares a bio for attaching integrity
123 * metadata. nr_vecs specifies the maximum number of pages containing
124 * integrity metadata that can be attached.
126 struct bio_integrity_payload *bio_integrity_alloc(struct bio *bio,
127 gfp_t gfp_mask,
128 unsigned int nr_vecs)
130 return bio_integrity_alloc_bioset(bio, gfp_mask, nr_vecs, fs_bio_set);
132 EXPORT_SYMBOL(bio_integrity_alloc);
135 * bio_integrity_free - Free bio integrity payload
136 * @bio: bio containing bip to be freed
137 * @bs: bio_set this bio was allocated from
139 * Description: Used to free the integrity portion of a bio. Usually
140 * called from bio_free().
142 void bio_integrity_free(struct bio *bio, struct bio_set *bs)
144 struct bio_integrity_payload *bip = bio->bi_integrity;
146 BUG_ON(bip == NULL);
148 /* A cloned bio doesn't own the integrity metadata */
149 if (!bio_flagged(bio, BIO_CLONED) && !bio_flagged(bio, BIO_FS_INTEGRITY)
150 && bip->bip_buf != NULL)
151 kfree(bip->bip_buf);
153 if (use_bip_pool(bip->bip_slab))
154 mempool_free(bip, bs->bio_integrity_pool);
155 else
156 kmem_cache_free(bip_slab[bip->bip_slab].slab, bip);
158 bio->bi_integrity = NULL;
160 EXPORT_SYMBOL(bio_integrity_free);
163 * bio_integrity_add_page - Attach integrity metadata
164 * @bio: bio to update
165 * @page: page containing integrity metadata
166 * @len: number of bytes of integrity metadata in page
167 * @offset: start offset within page
169 * Description: Attach a page containing integrity metadata to bio.
171 int bio_integrity_add_page(struct bio *bio, struct page *page,
172 unsigned int len, unsigned int offset)
174 struct bio_integrity_payload *bip = bio->bi_integrity;
175 struct bio_vec *iv;
177 if (bip->bip_vcnt >= bvec_nr_vecs(bip->bip_slab)) {
178 printk(KERN_ERR "%s: bip_vec full\n", __func__);
179 return 0;
182 iv = bip_vec_idx(bip, bip->bip_vcnt);
183 BUG_ON(iv == NULL);
185 iv->bv_page = page;
186 iv->bv_len = len;
187 iv->bv_offset = offset;
188 bip->bip_vcnt++;
190 return len;
192 EXPORT_SYMBOL(bio_integrity_add_page);
194 static int bdev_integrity_enabled(struct block_device *bdev, int rw)
196 struct blk_integrity *bi = bdev_get_integrity(bdev);
198 if (bi == NULL)
199 return 0;
201 if (rw == READ && bi->verify_fn != NULL &&
202 (bi->flags & INTEGRITY_FLAG_READ))
203 return 1;
205 if (rw == WRITE && bi->generate_fn != NULL &&
206 (bi->flags & INTEGRITY_FLAG_WRITE))
207 return 1;
209 return 0;
213 * bio_integrity_enabled - Check whether integrity can be passed
214 * @bio: bio to check
216 * Description: Determines whether bio_integrity_prep() can be called
217 * on this bio or not. bio data direction and target device must be
218 * set prior to calling. The functions honors the write_generate and
219 * read_verify flags in sysfs.
221 int bio_integrity_enabled(struct bio *bio)
223 /* Already protected? */
224 if (bio_integrity(bio))
225 return 0;
227 return bdev_integrity_enabled(bio->bi_bdev, bio_data_dir(bio));
229 EXPORT_SYMBOL(bio_integrity_enabled);
232 * bio_integrity_hw_sectors - Convert 512b sectors to hardware ditto
233 * @bi: blk_integrity profile for device
234 * @sectors: Number of 512 sectors to convert
236 * Description: The block layer calculates everything in 512 byte
237 * sectors but integrity metadata is done in terms of the hardware
238 * sector size of the storage device. Convert the block layer sectors
239 * to physical sectors.
241 static inline unsigned int bio_integrity_hw_sectors(struct blk_integrity *bi,
242 unsigned int sectors)
244 /* At this point there are only 512b or 4096b DIF/EPP devices */
245 if (bi->sector_size == 4096)
246 return sectors >>= 3;
248 return sectors;
252 * bio_integrity_tag_size - Retrieve integrity tag space
253 * @bio: bio to inspect
255 * Description: Returns the maximum number of tag bytes that can be
256 * attached to this bio. Filesystems can use this to determine how
257 * much metadata to attach to an I/O.
259 unsigned int bio_integrity_tag_size(struct bio *bio)
261 struct blk_integrity *bi = bdev_get_integrity(bio->bi_bdev);
263 BUG_ON(bio->bi_size == 0);
265 return bi->tag_size * (bio->bi_size / bi->sector_size);
267 EXPORT_SYMBOL(bio_integrity_tag_size);
269 int bio_integrity_tag(struct bio *bio, void *tag_buf, unsigned int len, int set)
271 struct bio_integrity_payload *bip = bio->bi_integrity;
272 struct blk_integrity *bi = bdev_get_integrity(bio->bi_bdev);
273 unsigned int nr_sectors;
275 BUG_ON(bip->bip_buf == NULL);
277 if (bi->tag_size == 0)
278 return -1;
280 nr_sectors = bio_integrity_hw_sectors(bi,
281 DIV_ROUND_UP(len, bi->tag_size));
283 if (nr_sectors * bi->tuple_size > bip->bip_size) {
284 printk(KERN_ERR "%s: tag too big for bio: %u > %u\n",
285 __func__, nr_sectors * bi->tuple_size, bip->bip_size);
286 return -1;
289 if (set)
290 bi->set_tag_fn(bip->bip_buf, tag_buf, nr_sectors);
291 else
292 bi->get_tag_fn(bip->bip_buf, tag_buf, nr_sectors);
294 return 0;
298 * bio_integrity_set_tag - Attach a tag buffer to a bio
299 * @bio: bio to attach buffer to
300 * @tag_buf: Pointer to a buffer containing tag data
301 * @len: Length of the included buffer
303 * Description: Use this function to tag a bio by leveraging the extra
304 * space provided by devices formatted with integrity protection. The
305 * size of the integrity buffer must be <= to the size reported by
306 * bio_integrity_tag_size().
308 int bio_integrity_set_tag(struct bio *bio, void *tag_buf, unsigned int len)
310 BUG_ON(bio_data_dir(bio) != WRITE);
312 return bio_integrity_tag(bio, tag_buf, len, 1);
314 EXPORT_SYMBOL(bio_integrity_set_tag);
317 * bio_integrity_get_tag - Retrieve a tag buffer from a bio
318 * @bio: bio to retrieve buffer from
319 * @tag_buf: Pointer to a buffer for the tag data
320 * @len: Length of the target buffer
322 * Description: Use this function to retrieve the tag buffer from a
323 * completed I/O. The size of the integrity buffer must be <= to the
324 * size reported by bio_integrity_tag_size().
326 int bio_integrity_get_tag(struct bio *bio, void *tag_buf, unsigned int len)
328 BUG_ON(bio_data_dir(bio) != READ);
330 return bio_integrity_tag(bio, tag_buf, len, 0);
332 EXPORT_SYMBOL(bio_integrity_get_tag);
335 * bio_integrity_generate - Generate integrity metadata for a bio
336 * @bio: bio to generate integrity metadata for
338 * Description: Generates integrity metadata for a bio by calling the
339 * block device's generation callback function. The bio must have a
340 * bip attached with enough room to accommodate the generated
341 * integrity metadata.
343 static void bio_integrity_generate(struct bio *bio)
345 struct blk_integrity *bi = bdev_get_integrity(bio->bi_bdev);
346 struct blk_integrity_exchg bix;
347 struct bio_vec *bv;
348 sector_t sector = bio->bi_sector;
349 unsigned int i, sectors, total;
350 void *prot_buf = bio->bi_integrity->bip_buf;
352 total = 0;
353 bix.disk_name = bio->bi_bdev->bd_disk->disk_name;
354 bix.sector_size = bi->sector_size;
356 bio_for_each_segment(bv, bio, i) {
357 void *kaddr = kmap_atomic(bv->bv_page, KM_USER0);
358 bix.data_buf = kaddr + bv->bv_offset;
359 bix.data_size = bv->bv_len;
360 bix.prot_buf = prot_buf;
361 bix.sector = sector;
363 bi->generate_fn(&bix);
365 sectors = bv->bv_len / bi->sector_size;
366 sector += sectors;
367 prot_buf += sectors * bi->tuple_size;
368 total += sectors * bi->tuple_size;
369 BUG_ON(total > bio->bi_integrity->bip_size);
371 kunmap_atomic(kaddr, KM_USER0);
375 static inline unsigned short blk_integrity_tuple_size(struct blk_integrity *bi)
377 if (bi)
378 return bi->tuple_size;
380 return 0;
384 * bio_integrity_prep - Prepare bio for integrity I/O
385 * @bio: bio to prepare
387 * Description: Allocates a buffer for integrity metadata, maps the
388 * pages and attaches them to a bio. The bio must have data
389 * direction, target device and start sector set priot to calling. In
390 * the WRITE case, integrity metadata will be generated using the
391 * block device's integrity function. In the READ case, the buffer
392 * will be prepared for DMA and a suitable end_io handler set up.
394 int bio_integrity_prep(struct bio *bio)
396 struct bio_integrity_payload *bip;
397 struct blk_integrity *bi;
398 struct request_queue *q;
399 void *buf;
400 unsigned long start, end;
401 unsigned int len, nr_pages;
402 unsigned int bytes, offset, i;
403 unsigned int sectors;
405 bi = bdev_get_integrity(bio->bi_bdev);
406 q = bdev_get_queue(bio->bi_bdev);
407 BUG_ON(bi == NULL);
408 BUG_ON(bio_integrity(bio));
410 sectors = bio_integrity_hw_sectors(bi, bio_sectors(bio));
412 /* Allocate kernel buffer for protection data */
413 len = sectors * blk_integrity_tuple_size(bi);
414 buf = kmalloc(len, GFP_NOIO | __GFP_NOFAIL | q->bounce_gfp);
415 if (unlikely(buf == NULL)) {
416 printk(KERN_ERR "could not allocate integrity buffer\n");
417 return -EIO;
420 end = (((unsigned long) buf) + len + PAGE_SIZE - 1) >> PAGE_SHIFT;
421 start = ((unsigned long) buf) >> PAGE_SHIFT;
422 nr_pages = end - start;
424 /* Allocate bio integrity payload and integrity vectors */
425 bip = bio_integrity_alloc(bio, GFP_NOIO, nr_pages);
426 if (unlikely(bip == NULL)) {
427 printk(KERN_ERR "could not allocate data integrity bioset\n");
428 kfree(buf);
429 return -EIO;
432 bip->bip_buf = buf;
433 bip->bip_size = len;
434 bip->bip_sector = bio->bi_sector;
436 /* Map it */
437 offset = offset_in_page(buf);
438 for (i = 0 ; i < nr_pages ; i++) {
439 int ret;
440 bytes = PAGE_SIZE - offset;
442 if (len <= 0)
443 break;
445 if (bytes > len)
446 bytes = len;
448 ret = bio_integrity_add_page(bio, virt_to_page(buf),
449 bytes, offset);
451 if (ret == 0)
452 return 0;
454 if (ret < bytes)
455 break;
457 buf += bytes;
458 len -= bytes;
459 offset = 0;
462 /* Install custom I/O completion handler if read verify is enabled */
463 if (bio_data_dir(bio) == READ) {
464 bip->bip_end_io = bio->bi_end_io;
465 bio->bi_end_io = bio_integrity_endio;
468 /* Auto-generate integrity metadata if this is a write */
469 if (bio_data_dir(bio) == WRITE)
470 bio_integrity_generate(bio);
472 return 0;
474 EXPORT_SYMBOL(bio_integrity_prep);
477 * bio_integrity_verify - Verify integrity metadata for a bio
478 * @bio: bio to verify
480 * Description: This function is called to verify the integrity of a
481 * bio. The data in the bio io_vec is compared to the integrity
482 * metadata returned by the HBA.
484 static int bio_integrity_verify(struct bio *bio)
486 struct blk_integrity *bi = bdev_get_integrity(bio->bi_bdev);
487 struct blk_integrity_exchg bix;
488 struct bio_vec *bv;
489 sector_t sector = bio->bi_integrity->bip_sector;
490 unsigned int i, sectors, total, ret;
491 void *prot_buf = bio->bi_integrity->bip_buf;
493 ret = total = 0;
494 bix.disk_name = bio->bi_bdev->bd_disk->disk_name;
495 bix.sector_size = bi->sector_size;
497 bio_for_each_segment(bv, bio, i) {
498 void *kaddr = kmap_atomic(bv->bv_page, KM_USER0);
499 bix.data_buf = kaddr + bv->bv_offset;
500 bix.data_size = bv->bv_len;
501 bix.prot_buf = prot_buf;
502 bix.sector = sector;
504 ret = bi->verify_fn(&bix);
506 if (ret) {
507 kunmap_atomic(kaddr, KM_USER0);
508 return ret;
511 sectors = bv->bv_len / bi->sector_size;
512 sector += sectors;
513 prot_buf += sectors * bi->tuple_size;
514 total += sectors * bi->tuple_size;
515 BUG_ON(total > bio->bi_integrity->bip_size);
517 kunmap_atomic(kaddr, KM_USER0);
520 return ret;
524 * bio_integrity_verify_fn - Integrity I/O completion worker
525 * @work: Work struct stored in bio to be verified
527 * Description: This workqueue function is called to complete a READ
528 * request. The function verifies the transferred integrity metadata
529 * and then calls the original bio end_io function.
531 static void bio_integrity_verify_fn(struct work_struct *work)
533 struct bio_integrity_payload *bip =
534 container_of(work, struct bio_integrity_payload, bip_work);
535 struct bio *bio = bip->bip_bio;
536 int error;
538 error = bio_integrity_verify(bio);
540 /* Restore original bio completion handler */
541 bio->bi_end_io = bip->bip_end_io;
542 bio_endio(bio, error);
546 * bio_integrity_endio - Integrity I/O completion function
547 * @bio: Protected bio
548 * @error: Pointer to errno
550 * Description: Completion for integrity I/O
552 * Normally I/O completion is done in interrupt context. However,
553 * verifying I/O integrity is a time-consuming task which must be run
554 * in process context. This function postpones completion
555 * accordingly.
557 void bio_integrity_endio(struct bio *bio, int error)
559 struct bio_integrity_payload *bip = bio->bi_integrity;
561 BUG_ON(bip->bip_bio != bio);
563 /* In case of an I/O error there is no point in verifying the
564 * integrity metadata. Restore original bio end_io handler
565 * and run it.
567 if (error) {
568 bio->bi_end_io = bip->bip_end_io;
569 bio_endio(bio, error);
571 return;
574 INIT_WORK(&bip->bip_work, bio_integrity_verify_fn);
575 queue_work(kintegrityd_wq, &bip->bip_work);
577 EXPORT_SYMBOL(bio_integrity_endio);
580 * bio_integrity_mark_head - Advance bip_vec skip bytes
581 * @bip: Integrity vector to advance
582 * @skip: Number of bytes to advance it
584 void bio_integrity_mark_head(struct bio_integrity_payload *bip,
585 unsigned int skip)
587 struct bio_vec *iv;
588 unsigned int i;
590 bip_for_each_vec(iv, bip, i) {
591 if (skip == 0) {
592 bip->bip_idx = i;
593 return;
594 } else if (skip >= iv->bv_len) {
595 skip -= iv->bv_len;
596 } else { /* skip < iv->bv_len) */
597 iv->bv_offset += skip;
598 iv->bv_len -= skip;
599 bip->bip_idx = i;
600 return;
606 * bio_integrity_mark_tail - Truncate bip_vec to be len bytes long
607 * @bip: Integrity vector to truncate
608 * @len: New length of integrity vector
610 void bio_integrity_mark_tail(struct bio_integrity_payload *bip,
611 unsigned int len)
613 struct bio_vec *iv;
614 unsigned int i;
616 bip_for_each_vec(iv, bip, i) {
617 if (len == 0) {
618 bip->bip_vcnt = i;
619 return;
620 } else if (len >= iv->bv_len) {
621 len -= iv->bv_len;
622 } else { /* len < iv->bv_len) */
623 iv->bv_len = len;
624 len = 0;
630 * bio_integrity_advance - Advance integrity vector
631 * @bio: bio whose integrity vector to update
632 * @bytes_done: number of data bytes that have been completed
634 * Description: This function calculates how many integrity bytes the
635 * number of completed data bytes correspond to and advances the
636 * integrity vector accordingly.
638 void bio_integrity_advance(struct bio *bio, unsigned int bytes_done)
640 struct bio_integrity_payload *bip = bio->bi_integrity;
641 struct blk_integrity *bi = bdev_get_integrity(bio->bi_bdev);
642 unsigned int nr_sectors;
644 BUG_ON(bip == NULL);
645 BUG_ON(bi == NULL);
647 nr_sectors = bio_integrity_hw_sectors(bi, bytes_done >> 9);
648 bio_integrity_mark_head(bip, nr_sectors * bi->tuple_size);
650 EXPORT_SYMBOL(bio_integrity_advance);
653 * bio_integrity_trim - Trim integrity vector
654 * @bio: bio whose integrity vector to update
655 * @offset: offset to first data sector
656 * @sectors: number of data sectors
658 * Description: Used to trim the integrity vector in a cloned bio.
659 * The ivec will be advanced corresponding to 'offset' data sectors
660 * and the length will be truncated corresponding to 'len' data
661 * sectors.
663 void bio_integrity_trim(struct bio *bio, unsigned int offset,
664 unsigned int sectors)
666 struct bio_integrity_payload *bip = bio->bi_integrity;
667 struct blk_integrity *bi = bdev_get_integrity(bio->bi_bdev);
668 unsigned int nr_sectors;
670 BUG_ON(bip == NULL);
671 BUG_ON(bi == NULL);
672 BUG_ON(!bio_flagged(bio, BIO_CLONED));
674 nr_sectors = bio_integrity_hw_sectors(bi, sectors);
675 bip->bip_sector = bip->bip_sector + offset;
676 bio_integrity_mark_head(bip, offset * bi->tuple_size);
677 bio_integrity_mark_tail(bip, sectors * bi->tuple_size);
679 EXPORT_SYMBOL(bio_integrity_trim);
682 * bio_integrity_split - Split integrity metadata
683 * @bio: Protected bio
684 * @bp: Resulting bio_pair
685 * @sectors: Offset
687 * Description: Splits an integrity page into a bio_pair.
689 void bio_integrity_split(struct bio *bio, struct bio_pair *bp, int sectors)
691 struct blk_integrity *bi;
692 struct bio_integrity_payload *bip = bio->bi_integrity;
693 unsigned int nr_sectors;
695 if (bio_integrity(bio) == 0)
696 return;
698 bi = bdev_get_integrity(bio->bi_bdev);
699 BUG_ON(bi == NULL);
700 BUG_ON(bip->bip_vcnt != 1);
702 nr_sectors = bio_integrity_hw_sectors(bi, sectors);
704 bp->bio1.bi_integrity = &bp->bip1;
705 bp->bio2.bi_integrity = &bp->bip2;
707 bp->iv1 = bip->bip_vec[0];
708 bp->iv2 = bip->bip_vec[0];
710 bp->bip1.bip_vec[0] = bp->iv1;
711 bp->bip2.bip_vec[0] = bp->iv2;
713 bp->iv1.bv_len = sectors * bi->tuple_size;
714 bp->iv2.bv_offset += sectors * bi->tuple_size;
715 bp->iv2.bv_len -= sectors * bi->tuple_size;
717 bp->bip1.bip_sector = bio->bi_integrity->bip_sector;
718 bp->bip2.bip_sector = bio->bi_integrity->bip_sector + nr_sectors;
720 bp->bip1.bip_vcnt = bp->bip2.bip_vcnt = 1;
721 bp->bip1.bip_idx = bp->bip2.bip_idx = 0;
723 EXPORT_SYMBOL(bio_integrity_split);
726 * bio_integrity_clone - Callback for cloning bios with integrity metadata
727 * @bio: New bio
728 * @bio_src: Original bio
729 * @gfp_mask: Memory allocation mask
730 * @bs: bio_set to allocate bip from
732 * Description: Called to allocate a bip when cloning a bio
734 int bio_integrity_clone(struct bio *bio, struct bio *bio_src,
735 gfp_t gfp_mask, struct bio_set *bs)
737 struct bio_integrity_payload *bip_src = bio_src->bi_integrity;
738 struct bio_integrity_payload *bip;
740 BUG_ON(bip_src == NULL);
742 bip = bio_integrity_alloc_bioset(bio, gfp_mask, bip_src->bip_vcnt, bs);
744 if (bip == NULL)
745 return -EIO;
747 memcpy(bip->bip_vec, bip_src->bip_vec,
748 bip_src->bip_vcnt * sizeof(struct bio_vec));
750 bip->bip_sector = bip_src->bip_sector;
751 bip->bip_vcnt = bip_src->bip_vcnt;
752 bip->bip_idx = bip_src->bip_idx;
754 return 0;
756 EXPORT_SYMBOL(bio_integrity_clone);
758 int bioset_integrity_create(struct bio_set *bs, int pool_size)
760 unsigned int max_slab = vecs_to_idx(BIO_MAX_PAGES);
762 bs->bio_integrity_pool =
763 mempool_create_slab_pool(pool_size, bip_slab[max_slab].slab);
765 if (!bs->bio_integrity_pool)
766 return -1;
768 return 0;
770 EXPORT_SYMBOL(bioset_integrity_create);
772 void bioset_integrity_free(struct bio_set *bs)
774 if (bs->bio_integrity_pool)
775 mempool_destroy(bs->bio_integrity_pool);
777 EXPORT_SYMBOL(bioset_integrity_free);
779 void __init bio_integrity_init(void)
781 unsigned int i;
783 kintegrityd_wq = create_workqueue("kintegrityd");
784 if (!kintegrityd_wq)
785 panic("Failed to create kintegrityd\n");
787 for (i = 0 ; i < BIOVEC_NR_POOLS ; i++) {
788 unsigned int size;
790 size = sizeof(struct bio_integrity_payload)
791 + bip_slab[i].nr_vecs * sizeof(struct bio_vec);
793 bip_slab[i].slab =
794 kmem_cache_create(bip_slab[i].name, size, 0,
795 SLAB_HWCACHE_ALIGN|SLAB_PANIC, NULL);