Skip to content

Commit 1e02939

Browse files
scsi: sd: Reorganize DIF/DIX code to avoid calling revalidate twice
During device discovery we ended up calling revalidate twice and thus requested the same parameters multiple times. This was originally necessary due to the request_queue and gendisk needing to be instantiated to configure the block integrity profile. Since this dependency no longer exists, reorganize the integrity probing code so it can be run once at the end of discovery and drop the superfluous revalidate call. Postponing the registration step involves splitting sd_read_protection() into two functions, one to read the device protection type and one to configure the mode of operation. As part of this cleanup, make the printing code a bit less verbose. Link: https://lore.kernel.org/r/20220302053559.32147-14-martin.petersen@oracle.com Reviewed-by: Christoph Hellwig <hch@lst.de> Reviewed-by: Johannes Thumshirn <johannes.thumshirn@wdc.com> Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
1 parent 631669a commit 1e02939

File tree

2 files changed

+36
-34
lines changed

2 files changed

+36
-34
lines changed

drivers/scsi/sd.c

Lines changed: 33 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -2176,40 +2176,48 @@ static int sd_read_protection_type(struct scsi_disk *sdkp, unsigned char *buffer
21762176
{
21772177
struct scsi_device *sdp = sdkp->device;
21782178
u8 type;
2179-
int ret = 0;
21802179

21812180
if (scsi_device_protection(sdp) == 0 || (buffer[12] & 1) == 0) {
21822181
sdkp->protection_type = 0;
2183-
return ret;
2182+
return 0;
21842183
}
21852184

21862185
type = ((buffer[12] >> 1) & 7) + 1; /* P_TYPE 0 = Type 1 */
21872186

2188-
if (type > T10_PI_TYPE3_PROTECTION)
2189-
ret = -ENODEV;
2190-
else if (scsi_host_dif_capable(sdp->host, type))
2191-
ret = 1;
2192-
2193-
if (sdkp->first_scan || type != sdkp->protection_type)
2194-
switch (ret) {
2195-
case -ENODEV:
2196-
sd_printk(KERN_ERR, sdkp, "formatted with unsupported" \
2197-
" protection type %u. Disabling disk!\n",
2198-
type);
2199-
break;
2200-
case 1:
2201-
sd_printk(KERN_NOTICE, sdkp,
2202-
"Enabling DIF Type %u protection\n", type);
2203-
break;
2204-
case 0:
2205-
sd_printk(KERN_NOTICE, sdkp,
2206-
"Disabling DIF Type %u protection\n", type);
2207-
break;
2208-
}
2187+
if (type > T10_PI_TYPE3_PROTECTION) {
2188+
sd_printk(KERN_ERR, sdkp, "formatted with unsupported" \
2189+
" protection type %u. Disabling disk!\n",
2190+
type);
2191+
sdkp->protection_type = 0;
2192+
return -ENODEV;
2193+
}
22092194

22102195
sdkp->protection_type = type;
22112196

2212-
return ret;
2197+
return 0;
2198+
}
2199+
2200+
static void sd_config_protection(struct scsi_disk *sdkp)
2201+
{
2202+
struct scsi_device *sdp = sdkp->device;
2203+
2204+
if (!sdkp->first_scan)
2205+
return;
2206+
2207+
sd_dif_config_host(sdkp);
2208+
2209+
if (!sdkp->protection_type)
2210+
return;
2211+
2212+
if (!scsi_host_dif_capable(sdp->host, sdkp->protection_type)) {
2213+
sd_printk(KERN_NOTICE, sdkp,
2214+
"Disabling DIF Type %u protection\n",
2215+
sdkp->protection_type);
2216+
sdkp->protection_type = 0;
2217+
}
2218+
2219+
sd_printk(KERN_NOTICE, sdkp, "Enabling DIF Type %u protection\n",
2220+
sdkp->protection_type);
22132221
}
22142222

22152223
static void read_capacity_error(struct scsi_disk *sdkp, struct scsi_device *sdp,
@@ -3259,6 +3267,7 @@ static int sd_revalidate_disk(struct gendisk *disk)
32593267
sd_read_app_tag_own(sdkp, buffer);
32603268
sd_read_write_same(sdkp, buffer);
32613269
sd_read_security(sdkp, buffer);
3270+
sd_config_protection(sdkp);
32623271
}
32633272

32643273
/*
@@ -3518,11 +3527,6 @@ static int sd_probe(struct device *dev)
35183527
goto out;
35193528
}
35203529

3521-
if (sdkp->capacity)
3522-
sd_dif_config_host(sdkp);
3523-
3524-
sd_revalidate_disk(gd);
3525-
35263530
if (sdkp->security) {
35273531
sdkp->opal_dev = init_opal_dev(sdkp, &sd_sec_submit);
35283532
if (sdkp->opal_dev)

drivers/scsi/sd_dif.c

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,6 @@ void sd_dif_config_host(struct scsi_disk *sdkp)
5959
bi.profile = &t10_pi_type1_crc;
6060

6161
bi.tuple_size = sizeof(struct t10_pi_tuple);
62-
sd_printk(KERN_NOTICE, sdkp,
63-
"Enabling DIX %s protection\n", bi.profile->name);
6462

6563
if (dif && type) {
6664
bi.flags |= BLK_INTEGRITY_DEVICE_CAPABLE;
@@ -72,11 +70,11 @@ void sd_dif_config_host(struct scsi_disk *sdkp)
7270
bi.tag_size = sizeof(u16) + sizeof(u32);
7371
else
7472
bi.tag_size = sizeof(u16);
75-
76-
sd_printk(KERN_NOTICE, sdkp, "DIF application tag size %u\n",
77-
bi.tag_size);
7873
}
7974

75+
sd_printk(KERN_NOTICE, sdkp,
76+
"Enabling DIX %s, application tag size %u bytes\n",
77+
bi.profile->name, bi.tag_size);
8078
out:
8179
blk_integrity_register(disk, &bi);
8280
}

0 commit comments

Comments
 (0)