Skip to content

Commit 0f8087e

Browse files
martinkpetersenaxboe
authored andcommitted
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>
1 parent aff34e1 commit 0f8087e

9 files changed

Lines changed: 65 additions & 64 deletions

File tree

‎block/bio-integrity.c‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -177,11 +177,11 @@ bool bio_integrity_enabled(struct bio *bio)
177177
if (bi == NULL)
178178
return false;
179179

180-
if (bio_data_dir(bio) == READ && bi->verify_fn != NULL &&
180+
if (bio_data_dir(bio) == READ && bi->profile->verify_fn != NULL &&
181181
(bi->flags & BLK_INTEGRITY_VERIFY))
182182
return true;
183183

184-
if (bio_data_dir(bio) == WRITE && bi->generate_fn != NULL &&
184+
if (bio_data_dir(bio) == WRITE && bi->profile->generate_fn != NULL &&
185185
(bi->flags & BLK_INTEGRITY_GENERATE))
186186
return true;
187187

@@ -340,7 +340,7 @@ int bio_integrity_prep(struct bio *bio)
340340

341341
/* Auto-generate integrity metadata if this is a write */
342342
if (bio_data_dir(bio) == WRITE)
343-
bio_integrity_process(bio, bi->generate_fn);
343+
bio_integrity_process(bio, bi->profile->generate_fn);
344344

345345
return 0;
346346
}
@@ -361,7 +361,7 @@ static void bio_integrity_verify_fn(struct work_struct *work)
361361
struct bio *bio = bip->bip_bio;
362362
struct blk_integrity *bi = bdev_get_integrity(bio->bi_bdev);
363363

364-
bio->bi_error = bio_integrity_process(bio, bi->verify_fn);
364+
bio->bi_error = bio_integrity_process(bio, bi->profile->verify_fn);
365365

366366
/* Restore original bio completion handler */
367367
bio->bi_end_io = bip->bip_end_io;

‎block/blk-integrity.c‎

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -176,10 +176,10 @@ int blk_integrity_compare(struct gendisk *gd1, struct gendisk *gd2)
176176
return -1;
177177
}
178178

179-
if (strcmp(b1->name, b2->name)) {
179+
if (b1->profile != b2->profile) {
180180
printk(KERN_ERR "%s: %s/%s type %s != %s\n", __func__,
181181
gd1->disk_name, gd2->disk_name,
182-
b1->name, b2->name);
182+
b1->profile->name, b2->profile->name);
183183
return -1;
184184
}
185185

@@ -275,8 +275,8 @@ static ssize_t integrity_attr_store(struct kobject *kobj,
275275

276276
static ssize_t integrity_format_show(struct blk_integrity *bi, char *page)
277277
{
278-
if (bi != NULL && bi->name != NULL)
279-
return sprintf(page, "%s\n", bi->name);
278+
if (bi != NULL && bi->profile->name != NULL)
279+
return sprintf(page, "%s\n", bi->profile->name);
280280
else
281281
return sprintf(page, "none\n");
282282
}
@@ -401,7 +401,8 @@ bool blk_integrity_is_initialized(struct gendisk *disk)
401401
{
402402
struct blk_integrity *bi = blk_get_integrity(disk);
403403

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);
405406
}
406407
EXPORT_SYMBOL(blk_integrity_is_initialized);
407408

@@ -446,14 +447,12 @@ int blk_integrity_register(struct gendisk *disk, struct blk_integrity *template)
446447

447448
/* Use the provided profile as template */
448449
if (template != NULL) {
449-
bi->name = template->name;
450-
bi->generate_fn = template->generate_fn;
451-
bi->verify_fn = template->verify_fn;
450+
bi->profile = template->profile;
452451
bi->tuple_size = template->tuple_size;
453452
bi->tag_size = template->tag_size;
454453
bi->flags |= template->flags;
455454
} else
456-
bi->name = bi_unsupported_name;
455+
bi->profile->name = bi_unsupported_name;
457456

458457
disk->queue->backing_dev_info.capabilities |= BDI_CAP_STABLE_WRITES;
459458

‎block/t10-pi.c‎

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -160,38 +160,30 @@ static int t10_pi_type3_verify_ip(struct blk_integrity_iter *iter)
160160
return t10_pi_verify(iter, t10_pi_ip_fn, 3);
161161
}
162162

163-
struct blk_integrity t10_pi_type1_crc = {
163+
struct blk_integrity_profile t10_pi_type1_crc = {
164164
.name = "T10-DIF-TYPE1-CRC",
165165
.generate_fn = t10_pi_type1_generate_crc,
166166
.verify_fn = t10_pi_type1_verify_crc,
167-
.tuple_size = sizeof(struct t10_pi_tuple),
168-
.tag_size = 0,
169167
};
170168
EXPORT_SYMBOL(t10_pi_type1_crc);
171169

172-
struct blk_integrity t10_pi_type1_ip = {
170+
struct blk_integrity_profile t10_pi_type1_ip = {
173171
.name = "T10-DIF-TYPE1-IP",
174172
.generate_fn = t10_pi_type1_generate_ip,
175173
.verify_fn = t10_pi_type1_verify_ip,
176-
.tuple_size = sizeof(struct t10_pi_tuple),
177-
.tag_size = 0,
178174
};
179175
EXPORT_SYMBOL(t10_pi_type1_ip);
180176

181-
struct blk_integrity t10_pi_type3_crc = {
177+
struct blk_integrity_profile t10_pi_type3_crc = {
182178
.name = "T10-DIF-TYPE3-CRC",
183179
.generate_fn = t10_pi_type3_generate_crc,
184180
.verify_fn = t10_pi_type3_verify_crc,
185-
.tuple_size = sizeof(struct t10_pi_tuple),
186-
.tag_size = 0,
187181
};
188182
EXPORT_SYMBOL(t10_pi_type3_crc);
189183

190-
struct blk_integrity t10_pi_type3_ip = {
184+
struct blk_integrity_profile t10_pi_type3_ip = {
191185
.name = "T10-DIF-TYPE3-IP",
192186
.generate_fn = t10_pi_type3_generate_ip,
193187
.verify_fn = t10_pi_type3_verify_ip,
194-
.tuple_size = sizeof(struct t10_pi_tuple),
195-
.tag_size = 0,
196188
};
197189
EXPORT_SYMBOL(t10_pi_type3_ip);

‎drivers/nvdimm/core.c‎

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -399,19 +399,22 @@ static int nd_pi_nop_generate_verify(struct blk_integrity_iter *iter)
399399

400400
int nd_integrity_init(struct gendisk *disk, unsigned long meta_size)
401401
{
402-
struct blk_integrity integrity = {
402+
struct blk_integrity bi;
403+
static struct blk_integrity_profile profile = {
403404
.name = "ND-PI-NOP",
404405
.generate_fn = nd_pi_nop_generate_verify,
405406
.verify_fn = nd_pi_nop_generate_verify,
406-
.tuple_size = meta_size,
407-
.tag_size = meta_size,
408407
};
409408
int ret;
410409

411410
if (meta_size == 0)
412411
return 0;
413412

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);
415418
if (ret)
416419
return ret;
417420

‎drivers/nvme/host/pci.c‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -558,7 +558,7 @@ static int nvme_noop_generate(struct blk_integrity_iter *iter)
558558
return 0;
559559
}
560560

561-
struct blk_integrity nvme_meta_noop = {
561+
struct blk_integrity_profile nvme_meta_noop = {
562562
.name = "NVME_META_NOOP",
563563
.generate_fn = nvme_noop_generate,
564564
.verify_fn = nvme_noop_verify,
@@ -570,14 +570,14 @@ static void nvme_init_integrity(struct nvme_ns *ns)
570570

571571
switch (ns->pi_type) {
572572
case NVME_NS_DPS_PI_TYPE3:
573-
integrity = t10_pi_type3_crc;
573+
integrity.profile = &t10_pi_type3_crc;
574574
break;
575575
case NVME_NS_DPS_PI_TYPE1:
576576
case NVME_NS_DPS_PI_TYPE2:
577-
integrity = t10_pi_type1_crc;
577+
integrity.profile = &t10_pi_type1_crc;
578578
break;
579579
default:
580-
integrity = nvme_meta_noop;
580+
integrity.profile = &nvme_meta_noop;
581581
break;
582582
}
583583
integrity.tuple_size = ns->ms;

‎drivers/scsi/sd_dif.c‎

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ void sd_dif_config_host(struct scsi_disk *sdkp)
4343
struct scsi_device *sdp = sdkp->device;
4444
struct gendisk *disk = sdkp->disk;
4545
u8 type = sdkp->protection_type;
46+
struct blk_integrity bi;
4647
int dif, dix;
4748

4849
dif = scsi_host_dif_capable(sdp->host, type);
@@ -55,39 +56,43 @@ void sd_dif_config_host(struct scsi_disk *sdkp)
5556
if (!dix)
5657
return;
5758

59+
memset(&bi, 0, sizeof(bi));
60+
5861
/* Enable DMA of protection information */
5962
if (scsi_host_get_guard(sdkp->device->host) & SHOST_DIX_GUARD_IP) {
6063
if (type == SD_DIF_TYPE3_PROTECTION)
61-
blk_integrity_register(disk, &t10_pi_type3_ip);
64+
bi.profile = &t10_pi_type3_ip;
6265
else
63-
blk_integrity_register(disk, &t10_pi_type1_ip);
66+
bi.profile = &t10_pi_type1_ip;
6467

65-
disk->integrity->flags |= BLK_INTEGRITY_IP_CHECKSUM;
68+
bi.flags |= BLK_INTEGRITY_IP_CHECKSUM;
6669
} else
6770
if (type == SD_DIF_TYPE3_PROTECTION)
68-
blk_integrity_register(disk, &t10_pi_type3_crc);
71+
bi.profile = &t10_pi_type3_crc;
6972
else
70-
blk_integrity_register(disk, &t10_pi_type1_crc);
73+
bi.profile = &t10_pi_type1_crc;
7174

75+
bi.tuple_size = sizeof(struct t10_pi_tuple);
7276
sd_printk(KERN_NOTICE, sdkp,
73-
"Enabling DIX %s protection\n", disk->integrity->name);
77+
"Enabling DIX %s protection\n", bi.profile->name);
7478

75-
/* Signal to block layer that we support sector tagging */
7679
if (dif && type) {
77-
78-
disk->integrity->flags |= BLK_INTEGRITY_DEVICE_CAPABLE;
80+
bi.flags |= BLK_INTEGRITY_DEVICE_CAPABLE;
7981

8082
if (!sdkp->ATO)
81-
return;
83+
goto out;
8284

8385
if (type == SD_DIF_TYPE3_PROTECTION)
84-
disk->integrity->tag_size = sizeof(u16) + sizeof(u32);
86+
bi.tag_size = sizeof(u16) + sizeof(u32);
8587
else
86-
disk->integrity->tag_size = sizeof(u16);
88+
bi.tag_size = sizeof(u16);
8789

8890
sd_printk(KERN_NOTICE, sdkp, "DIF application tag size %u\n",
89-
disk->integrity->tag_size);
91+
bi.tag_size);
9092
}
93+
94+
out:
95+
blk_integrity_register(disk, &bi);
9196
}
9297

9398
/*

‎drivers/target/target_core_iblock.c‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -155,17 +155,17 @@ static int iblock_configure_device(struct se_device *dev)
155155
if (bi) {
156156
struct bio_set *bs = ib_dev->ibd_bio_set;
157157

158-
if (!strcmp(bi->name, "T10-DIF-TYPE3-IP") ||
159-
!strcmp(bi->name, "T10-DIF-TYPE1-IP")) {
158+
if (!strcmp(bi->profile->name, "T10-DIF-TYPE3-IP") ||
159+
!strcmp(bi->profile->name, "T10-DIF-TYPE1-IP")) {
160160
pr_err("IBLOCK export of blk_integrity: %s not"
161-
" supported\n", bi->name);
161+
" supported\n", bi->profile->name);
162162
ret = -ENOSYS;
163163
goto out_blkdev_put;
164164
}
165165

166-
if (!strcmp(bi->name, "T10-DIF-TYPE3-CRC")) {
166+
if (!strcmp(bi->profile->name, "T10-DIF-TYPE3-CRC")) {
167167
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")) {
169169
dev->dev_attrib.pi_prot_type = TARGET_DIF_TYPE1_PROT;
170170
}
171171

‎include/linux/blkdev.h‎

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1462,16 +1462,18 @@ struct blk_integrity_iter {
14621462

14631463
typedef int (integrity_processing_fn) (struct blk_integrity_iter *);
14641464

1465-
struct blk_integrity {
1466-
integrity_processing_fn *generate_fn;
1467-
integrity_processing_fn *verify_fn;
1468-
1469-
unsigned short flags;
1470-
unsigned short tuple_size;
1471-
unsigned short interval;
1472-
unsigned short tag_size;
1465+
struct blk_integrity_profile {
1466+
integrity_processing_fn *generate_fn;
1467+
integrity_processing_fn *verify_fn;
1468+
const char *name;
1469+
};
14731470

1474-
const char *name;
1471+
struct 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;
14751477
};
14761478

14771479
extern bool blk_integrity_is_initialized(struct gendisk *);

‎include/linux/t10-pi.h‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@ struct t10_pi_tuple {
1414
};
1515

1616

17-
extern struct blk_integrity t10_pi_type1_crc;
18-
extern struct blk_integrity t10_pi_type1_ip;
19-
extern struct blk_integrity t10_pi_type3_crc;
20-
extern struct blk_integrity t10_pi_type3_ip;
17+
extern struct blk_integrity_profile t10_pi_type1_crc;
18+
extern struct blk_integrity_profile t10_pi_type1_ip;
19+
extern struct blk_integrity_profile t10_pi_type3_crc;
20+
extern struct blk_integrity_profile t10_pi_type3_ip;
2121

2222
#endif

0 commit comments

Comments
 (0)