aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMartin K. Petersen <martin.petersen@oracle.com>2015-10-21 13:19:33 -0400
committerJens Axboe <axboe@fb.com>2015-10-21 16:42:38 -0400
commit0f8087ecdeac921fc4920f1328f55c15080bc6aa (patch)
tree6027fd7061230f1488f74938b6bebf804be88376
parentaff34e192e4eeacfb8b5ffc68e10a240f2c0c6d7 (diff)
block: Consolidate static integrity profile properties
We previously made a complete copy of a device's data integrity profile even though several of the fields inside the blk_integrity struct are pointers to fixed template entries in t10-pi.c. Split the static and per-device portions so that we can reference the template directly. Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com> Reported-by: Christoph Hellwig <hch@lst.de> Reviewed-by: Sagi Grimberg <sagig@mellanox.com> Cc: Dan Williams <dan.j.williams@intel.com> Signed-off-by: Dan Williams <dan.j.williams@intel.com> Signed-off-by: Jens Axboe <axboe@fb.com>
-rw-r--r--block/bio-integrity.c8
-rw-r--r--block/blk-integrity.c17
-rw-r--r--block/t10-pi.c16
-rw-r--r--drivers/nvdimm/core.c11
-rw-r--r--drivers/nvme/host/pci.c8
-rw-r--r--drivers/scsi/sd_dif.c31
-rw-r--r--drivers/target/target_core_iblock.c10
-rw-r--r--include/linux/blkdev.h20
-rw-r--r--include/linux/t10-pi.h8
9 files changed, 65 insertions, 64 deletions
diff --git a/block/bio-integrity.c b/block/bio-integrity.c
index 14b8faf8b09d..a10ffe19a8dd 100644
--- a/block/bio-integrity.c
+++ b/block/bio-integrity.c
@@ -177,11 +177,11 @@ bool bio_integrity_enabled(struct bio *bio)
177 if (bi == NULL) 177 if (bi == NULL)
178 return false; 178 return false;
179 179
180 if (bio_data_dir(bio) == READ && bi->verify_fn != NULL && 180 if (bio_data_dir(bio) == READ && bi->profile->verify_fn != NULL &&
181 (bi->flags & BLK_INTEGRITY_VERIFY)) 181 (bi->flags & BLK_INTEGRITY_VERIFY))
182 return true; 182 return true;
183 183
184 if (bio_data_dir(bio) == WRITE && bi->generate_fn != NULL && 184 if (bio_data_dir(bio) == WRITE && bi->profile->generate_fn != NULL &&
185 (bi->flags & BLK_INTEGRITY_GENERATE)) 185 (bi->flags & BLK_INTEGRITY_GENERATE))
186 return true; 186 return true;
187 187
@@ -340,7 +340,7 @@ int bio_integrity_prep(struct bio *bio)
340 340
341 /* Auto-generate integrity metadata if this is a write */ 341 /* Auto-generate integrity metadata if this is a write */
342 if (bio_data_dir(bio) == WRITE) 342 if (bio_data_dir(bio) == WRITE)
343 bio_integrity_process(bio, bi->generate_fn); 343 bio_integrity_process(bio, bi->profile->generate_fn);
344 344
345 return 0; 345 return 0;
346} 346}
@@ -361,7 +361,7 @@ static void bio_integrity_verify_fn(struct work_struct *work)
361 struct bio *bio = bip->bip_bio; 361 struct bio *bio = bip->bip_bio;
362 struct blk_integrity *bi = bdev_get_integrity(bio->bi_bdev); 362 struct blk_integrity *bi = bdev_get_integrity(bio->bi_bdev);
363 363
364 bio->bi_error = bio_integrity_process(bio, bi->verify_fn); 364 bio->bi_error = bio_integrity_process(bio, bi->profile->verify_fn);
365 365
366 /* Restore original bio completion handler */ 366 /* Restore original bio completion handler */
367 bio->bi_end_io = bip->bip_end_io; 367 bio->bi_end_io = bip->bip_end_io;
diff --git a/block/blk-integrity.c b/block/blk-integrity.c
index 182bfd2383ea..daf590ab3b46 100644
--- a/block/blk-integrity.c
+++ b/block/blk-integrity.c
@@ -176,10 +176,10 @@ int blk_integrity_compare(struct gendisk *gd1, struct gendisk *gd2)
176 return -1; 176 return -1;
177 } 177 }
178 178
179 if (strcmp(b1->name, b2->name)) { 179 if (b1->profile != b2->profile) {
180 printk(KERN_ERR "%s: %s/%s type %s != %s\n", __func__, 180 printk(KERN_ERR "%s: %s/%s type %s != %s\n", __func__,
181 gd1->disk_name, gd2->disk_name, 181 gd1->disk_name, gd2->disk_name,
182 b1->name, b2->name); 182 b1->profile->name, b2->profile->name);
183 return -1; 183 return -1;
184 } 184 }
185 185
@@ -275,8 +275,8 @@ static ssize_t integrity_attr_store(struct kobject *kobj,
275 275
276static ssize_t integrity_format_show(struct blk_integrity *bi, char *page) 276static ssize_t integrity_format_show(struct blk_integrity *bi, char *page)
277{ 277{
278 if (bi != NULL && bi->name != NULL) 278 if (bi != NULL && bi->profile->name != NULL)
279 return sprintf(page, "%s\n", bi->name); 279 return sprintf(page, "%s\n", bi->profile->name);
280 else 280 else
281 return sprintf(page, "none\n"); 281 return sprintf(page, "none\n");
282} 282}
@@ -401,7 +401,8 @@ bool blk_integrity_is_initialized(struct gendisk *disk)
401{ 401{
402 struct blk_integrity *bi = blk_get_integrity(disk); 402 struct blk_integrity *bi = blk_get_integrity(disk);
403 403
404 return (bi && bi->name && strcmp(bi->name, bi_unsupported_name) != 0); 404 return (bi && bi->profile->name && strcmp(bi->profile->name,
405 bi_unsupported_name) != 0);
405} 406}
406EXPORT_SYMBOL(blk_integrity_is_initialized); 407EXPORT_SYMBOL(blk_integrity_is_initialized);
407 408
@@ -446,14 +447,12 @@ int blk_integrity_register(struct gendisk *disk, struct blk_integrity *template)
446 447
447 /* Use the provided profile as template */ 448 /* Use the provided profile as template */
448 if (template != NULL) { 449 if (template != NULL) {
449 bi->name = template->name; 450 bi->profile = template->profile;
450 bi->generate_fn = template->generate_fn;
451 bi->verify_fn = template->verify_fn;
452 bi->tuple_size = template->tuple_size; 451 bi->tuple_size = template->tuple_size;
453 bi->tag_size = template->tag_size; 452 bi->tag_size = template->tag_size;
454 bi->flags |= template->flags; 453 bi->flags |= template->flags;
455 } else 454 } else
456 bi->name = bi_unsupported_name; 455 bi->profile->name = bi_unsupported_name;
457 456
458 disk->queue->backing_dev_info.capabilities |= BDI_CAP_STABLE_WRITES; 457 disk->queue->backing_dev_info.capabilities |= BDI_CAP_STABLE_WRITES;
459 458
diff --git a/block/t10-pi.c b/block/t10-pi.c
index 24d6e9715318..2c97912335a9 100644
--- a/block/t10-pi.c
+++ b/block/t10-pi.c
@@ -160,38 +160,30 @@ static int t10_pi_type3_verify_ip(struct blk_integrity_iter *iter)
160 return t10_pi_verify(iter, t10_pi_ip_fn, 3); 160 return t10_pi_verify(iter, t10_pi_ip_fn, 3);
161} 161}
162 162
163struct blk_integrity t10_pi_type1_crc = { 163struct blk_integrity_profile t10_pi_type1_crc = {
164 .name = "T10-DIF-TYPE1-CRC", 164 .name = "T10-DIF-TYPE1-CRC",
165 .generate_fn = t10_pi_type1_generate_crc, 165 .generate_fn = t10_pi_type1_generate_crc,
166 .verify_fn = t10_pi_type1_verify_crc, 166 .verify_fn = t10_pi_type1_verify_crc,
167 .tuple_size = sizeof(struct t10_pi_tuple),
168 .tag_size = 0,
169}; 167};
170EXPORT_SYMBOL(t10_pi_type1_crc); 168EXPORT_SYMBOL(t10_pi_type1_crc);
171 169
172struct blk_integrity t10_pi_type1_ip = { 170struct blk_integrity_profile t10_pi_type1_ip = {
173 .name = "T10-DIF-TYPE1-IP", 171 .name = "T10-DIF-TYPE1-IP",
174 .generate_fn = t10_pi_type1_generate_ip, 172 .generate_fn = t10_pi_type1_generate_ip,
175 .verify_fn = t10_pi_type1_verify_ip, 173 .verify_fn = t10_pi_type1_verify_ip,
176 .tuple_size = sizeof(struct t10_pi_tuple),
177 .tag_size = 0,
178}; 174};
179EXPORT_SYMBOL(t10_pi_type1_ip); 175EXPORT_SYMBOL(t10_pi_type1_ip);
180 176
181struct blk_integrity t10_pi_type3_crc = { 177struct blk_integrity_profile t10_pi_type3_crc = {
182 .name = "T10-DIF-TYPE3-CRC", 178 .name = "T10-DIF-TYPE3-CRC",
183 .generate_fn = t10_pi_type3_generate_crc, 179 .generate_fn = t10_pi_type3_generate_crc,
184 .verify_fn = t10_pi_type3_verify_crc, 180 .verify_fn = t10_pi_type3_verify_crc,
185 .tuple_size = sizeof(struct t10_pi_tuple),
186 .tag_size = 0,
187}; 181};
188EXPORT_SYMBOL(t10_pi_type3_crc); 182EXPORT_SYMBOL(t10_pi_type3_crc);
189 183
190struct blk_integrity t10_pi_type3_ip = { 184struct blk_integrity_profile t10_pi_type3_ip = {
191 .name = "T10-DIF-TYPE3-IP", 185 .name = "T10-DIF-TYPE3-IP",
192 .generate_fn = t10_pi_type3_generate_ip, 186 .generate_fn = t10_pi_type3_generate_ip,
193 .verify_fn = t10_pi_type3_verify_ip, 187 .verify_fn = t10_pi_type3_verify_ip,
194 .tuple_size = sizeof(struct t10_pi_tuple),
195 .tag_size = 0,
196}; 188};
197EXPORT_SYMBOL(t10_pi_type3_ip); 189EXPORT_SYMBOL(t10_pi_type3_ip);
diff --git a/drivers/nvdimm/core.c b/drivers/nvdimm/core.c
index cb62ec6a12d0..7df89b547ae1 100644
--- a/drivers/nvdimm/core.c
+++ b/drivers/nvdimm/core.c
@@ -399,19 +399,22 @@ static int nd_pi_nop_generate_verify(struct blk_integrity_iter *iter)
399 399
400int nd_integrity_init(struct gendisk *disk, unsigned long meta_size) 400int nd_integrity_init(struct gendisk *disk, unsigned long meta_size)
401{ 401{
402 struct blk_integrity integrity = { 402 struct blk_integrity bi;
403 static struct blk_integrity_profile profile = {
403 .name = "ND-PI-NOP", 404 .name = "ND-PI-NOP",
404 .generate_fn = nd_pi_nop_generate_verify, 405 .generate_fn = nd_pi_nop_generate_verify,
405 .verify_fn = nd_pi_nop_generate_verify, 406 .verify_fn = nd_pi_nop_generate_verify,
406 .tuple_size = meta_size,
407 .tag_size = meta_size,
408 }; 407 };
409 int ret; 408 int ret;
410 409
411 if (meta_size == 0) 410 if (meta_size == 0)
412 return 0; 411 return 0;
413 412
414 ret = blk_integrity_register(disk, &integrity); 413 bi.profile = &profile;
414 bi.tuple_size = meta_size;
415 bi.tag_size = meta_size;
416
417 ret = blk_integrity_register(disk, &bi);
415 if (ret) 418 if (ret)
416 return ret; 419 return ret;
417 420
diff --git a/drivers/nvme/host/pci.c b/drivers/nvme/host/pci.c
index 22d83752ae87..04e3d60a1e45 100644
--- a/drivers/nvme/host/pci.c
+++ b/drivers/nvme/host/pci.c
@@ -558,7 +558,7 @@ static int nvme_noop_generate(struct blk_integrity_iter *iter)
558 return 0; 558 return 0;
559} 559}
560 560
561struct blk_integrity nvme_meta_noop = { 561struct blk_integrity_profile nvme_meta_noop = {
562 .name = "NVME_META_NOOP", 562 .name = "NVME_META_NOOP",
563 .generate_fn = nvme_noop_generate, 563 .generate_fn = nvme_noop_generate,
564 .verify_fn = nvme_noop_verify, 564 .verify_fn = nvme_noop_verify,
@@ -570,14 +570,14 @@ static void nvme_init_integrity(struct nvme_ns *ns)
570 570
571 switch (ns->pi_type) { 571 switch (ns->pi_type) {
572 case NVME_NS_DPS_PI_TYPE3: 572 case NVME_NS_DPS_PI_TYPE3:
573 integrity = t10_pi_type3_crc; 573 integrity.profile = &t10_pi_type3_crc;
574 break; 574 break;
575 case NVME_NS_DPS_PI_TYPE1: 575 case NVME_NS_DPS_PI_TYPE1:
576 case NVME_NS_DPS_PI_TYPE2: 576 case NVME_NS_DPS_PI_TYPE2:
577 integrity = t10_pi_type1_crc; 577 integrity.profile = &t10_pi_type1_crc;
578 break; 578 break;
579 default: 579 default:
580 integrity = nvme_meta_noop; 580 integrity.profile = &nvme_meta_noop;
581 break; 581 break;
582 } 582 }
583 integrity.tuple_size = ns->ms; 583 integrity.tuple_size = ns->ms;
diff --git a/drivers/scsi/sd_dif.c b/drivers/scsi/sd_dif.c
index 5c06d292b94c..987bf392c336 100644
--- a/drivers/scsi/sd_dif.c
+++ b/drivers/scsi/sd_dif.c
@@ -43,6 +43,7 @@ void sd_dif_config_host(struct scsi_disk *sdkp)
43 struct scsi_device *sdp = sdkp->device; 43 struct scsi_device *sdp = sdkp->device;
44 struct gendisk *disk = sdkp->disk; 44 struct gendisk *disk = sdkp->disk;
45 u8 type = sdkp->protection_type; 45 u8 type = sdkp->protection_type;
46 struct blk_integrity bi;
46 int dif, dix; 47 int dif, dix;
47 48
48 dif = scsi_host_dif_capable(sdp->host, type); 49 dif = scsi_host_dif_capable(sdp->host, type);
@@ -55,39 +56,43 @@ void sd_dif_config_host(struct scsi_disk *sdkp)
55 if (!dix) 56 if (!dix)
56 return; 57 return;
57 58
59 memset(&bi, 0, sizeof(bi));
60
58 /* Enable DMA of protection information */ 61 /* Enable DMA of protection information */
59 if (scsi_host_get_guard(sdkp->device->host) & SHOST_DIX_GUARD_IP) { 62 if (scsi_host_get_guard(sdkp->device->host) & SHOST_DIX_GUARD_IP) {
60 if (type == SD_DIF_TYPE3_PROTECTION) 63 if (type == SD_DIF_TYPE3_PROTECTION)
61 blk_integrity_register(disk, &t10_pi_type3_ip); 64 bi.profile = &t10_pi_type3_ip;
62 else 65 else
63 blk_integrity_register(disk, &t10_pi_type1_ip); 66 bi.profile = &t10_pi_type1_ip;
64 67
65 disk->integrity->flags |= BLK_INTEGRITY_IP_CHECKSUM; 68 bi.flags |= BLK_INTEGRITY_IP_CHECKSUM;
66 } else 69 } else
67 if (type == SD_DIF_TYPE3_PROTECTION) 70 if (type == SD_DIF_TYPE3_PROTECTION)
68 blk_integrity_register(disk, &t10_pi_type3_crc); 71 bi.profile = &t10_pi_type3_crc;
69 else 72 else
70 blk_integrity_register(disk, &t10_pi_type1_crc); 73 bi.profile = &t10_pi_type1_crc;
71 74
75 bi.tuple_size = sizeof(struct t10_pi_tuple);
72 sd_printk(KERN_NOTICE, sdkp, 76 sd_printk(KERN_NOTICE, sdkp,
73 "Enabling DIX %s protection\n", disk->integrity->name); 77 "Enabling DIX %s protection\n", bi.profile->name);
74 78
75 /* Signal to block layer that we support sector tagging */
76 if (dif && type) { 79 if (dif && type) {
77 80 bi.flags |= BLK_INTEGRITY_DEVICE_CAPABLE;
78 disk->integrity->flags |= BLK_INTEGRITY_DEVICE_CAPABLE;
79 81
80 if (!sdkp->ATO) 82 if (!sdkp->ATO)
81 return; 83 goto out;
82 84
83 if (type == SD_DIF_TYPE3_PROTECTION) 85 if (type == SD_DIF_TYPE3_PROTECTION)
84 disk->integrity->tag_size = sizeof(u16) + sizeof(u32); 86 bi.tag_size = sizeof(u16) + sizeof(u32);
85 else 87 else
86 disk->integrity->tag_size = sizeof(u16); 88 bi.tag_size = sizeof(u16);
87 89
88 sd_printk(KERN_NOTICE, sdkp, "DIF application tag size %u\n", 90 sd_printk(KERN_NOTICE, sdkp, "DIF application tag size %u\n",
89 disk->integrity->tag_size); 91 bi.tag_size);
90 } 92 }
93
94out:
95 blk_integrity_register(disk, &bi);
91} 96}
92 97
93/* 98/*
diff --git a/drivers/target/target_core_iblock.c b/drivers/target/target_core_iblock.c
index 0f19e11acac2..f29c69120054 100644
--- a/drivers/target/target_core_iblock.c
+++ b/drivers/target/target_core_iblock.c
@@ -155,17 +155,17 @@ static int iblock_configure_device(struct se_device *dev)
155 if (bi) { 155 if (bi) {
156 struct bio_set *bs = ib_dev->ibd_bio_set; 156 struct bio_set *bs = ib_dev->ibd_bio_set;
157 157
158 if (!strcmp(bi->name, "T10-DIF-TYPE3-IP") || 158 if (!strcmp(bi->profile->name, "T10-DIF-TYPE3-IP") ||
159 !strcmp(bi->name, "T10-DIF-TYPE1-IP")) { 159 !strcmp(bi->profile->name, "T10-DIF-TYPE1-IP")) {
160 pr_err("IBLOCK export of blk_integrity: %s not" 160 pr_err("IBLOCK export of blk_integrity: %s not"
161 " supported\n", bi->name); 161 " supported\n", bi->profile->name);
162 ret = -ENOSYS; 162 ret = -ENOSYS;
163 goto out_blkdev_put; 163 goto out_blkdev_put;
164 } 164 }
165 165
166 if (!strcmp(bi->name, "T10-DIF-TYPE3-CRC")) { 166 if (!strcmp(bi->profile->name, "T10-DIF-TYPE3-CRC")) {
167 dev->dev_attrib.pi_prot_type = TARGET_DIF_TYPE3_PROT; 167 dev->dev_attrib.pi_prot_type = TARGET_DIF_TYPE3_PROT;
168 } else if (!strcmp(bi->name, "T10-DIF-TYPE1-CRC")) { 168 } else if (!strcmp(bi->profile->name, "T10-DIF-TYPE1-CRC")) {
169 dev->dev_attrib.pi_prot_type = TARGET_DIF_TYPE1_PROT; 169 dev->dev_attrib.pi_prot_type = TARGET_DIF_TYPE1_PROT;
170 } 170 }
171 171
diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h
index 830f9c07d4bb..f36c6476f1c7 100644
--- a/include/linux/blkdev.h
+++ b/include/linux/blkdev.h
@@ -1462,16 +1462,18 @@ struct blk_integrity_iter {
1462 1462
1463typedef int (integrity_processing_fn) (struct blk_integrity_iter *); 1463typedef int (integrity_processing_fn) (struct blk_integrity_iter *);
1464 1464
1465struct blk_integrity { 1465struct blk_integrity_profile {
1466 integrity_processing_fn *generate_fn; 1466 integrity_processing_fn *generate_fn;
1467 integrity_processing_fn *verify_fn; 1467 integrity_processing_fn *verify_fn;
1468 1468 const char *name;
1469 unsigned short flags; 1469};
1470 unsigned short tuple_size;
1471 unsigned short interval;
1472 unsigned short tag_size;
1473 1470
1474 const char *name; 1471struct blk_integrity {
1472 struct blk_integrity_profile *profile;
1473 unsigned short flags;
1474 unsigned short tuple_size;
1475 unsigned short interval;
1476 unsigned short tag_size;
1475}; 1477};
1476 1478
1477extern bool blk_integrity_is_initialized(struct gendisk *); 1479extern bool blk_integrity_is_initialized(struct gendisk *);
diff --git a/include/linux/t10-pi.h b/include/linux/t10-pi.h
index 6a8b9942632d..dd8de82cf5b5 100644
--- a/include/linux/t10-pi.h
+++ b/include/linux/t10-pi.h
@@ -14,9 +14,9 @@ struct t10_pi_tuple {
14}; 14};
15 15
16 16
17extern struct blk_integrity t10_pi_type1_crc; 17extern struct blk_integrity_profile t10_pi_type1_crc;
18extern struct blk_integrity t10_pi_type1_ip; 18extern struct blk_integrity_profile t10_pi_type1_ip;
19extern struct blk_integrity t10_pi_type3_crc; 19extern struct blk_integrity_profile t10_pi_type3_crc;
20extern struct blk_integrity t10_pi_type3_ip; 20extern struct blk_integrity_profile t10_pi_type3_ip;
21 21
22#endif 22#endif