Skip to content

Commit e60ac0b

Browse files
scsi: core: Cache VPD pages b0, b1, b2
The SCSI disk driver consults VPD pages b0 (Block Limits), b1 (Block Device Characteristics), and b2 (Logical Block Provisioning). Instead of having sd.c request these pages every revalidate cycle, cache them along with the other commonly used VPDs. Link: https://lore.kernel.org/r/20220302053559.32147-6-martin.petersen@oracle.com Reviewed-by: Hannes Reinecke <hare@suse.de> Reviewed-by: Christoph Hellwig <hch@lst.de> Reviewed-by: Johannes Thumshirn <johannes.thumshirn@wdc.com> Reviewed-by: Bart Van Assche <bvanassche@acm.org> Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
1 parent e17d634 commit e60ac0b

File tree

3 files changed

+38
-0
lines changed

3 files changed

+38
-0
lines changed

drivers/scsi/scsi.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -483,6 +483,12 @@ void scsi_attach_vpd(struct scsi_device *sdev)
483483
scsi_update_vpd_page(sdev, 0x83, &sdev->vpd_pg83);
484484
if (vpd_buf->data[i] == 0x89)
485485
scsi_update_vpd_page(sdev, 0x89, &sdev->vpd_pg89);
486+
if (vpd_buf->data[i] == 0xb0)
487+
scsi_update_vpd_page(sdev, 0xb0, &sdev->vpd_pgb0);
488+
if (vpd_buf->data[i] == 0xb1)
489+
scsi_update_vpd_page(sdev, 0xb1, &sdev->vpd_pgb1);
490+
if (vpd_buf->data[i] == 0xb2)
491+
scsi_update_vpd_page(sdev, 0xb2, &sdev->vpd_pgb2);
486492
}
487493
kfree(vpd_buf);
488494
}

drivers/scsi/scsi_sysfs.c

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -448,6 +448,7 @@ static void scsi_device_dev_release_usercontext(struct work_struct *work)
448448
struct list_head *this, *tmp;
449449
struct scsi_vpd *vpd_pg80 = NULL, *vpd_pg83 = NULL;
450450
struct scsi_vpd *vpd_pg0 = NULL, *vpd_pg89 = NULL;
451+
struct scsi_vpd *vpd_pgb0 = NULL, *vpd_pgb1 = NULL, *vpd_pgb2 = NULL;
451452
unsigned long flags;
452453
struct module *mod;
453454

@@ -490,6 +491,12 @@ static void scsi_device_dev_release_usercontext(struct work_struct *work)
490491
lockdep_is_held(&sdev->inquiry_mutex));
491492
vpd_pg89 = rcu_replace_pointer(sdev->vpd_pg89, vpd_pg89,
492493
lockdep_is_held(&sdev->inquiry_mutex));
494+
vpd_pgb0 = rcu_replace_pointer(sdev->vpd_pgb0, vpd_pgb0,
495+
lockdep_is_held(&sdev->inquiry_mutex));
496+
vpd_pgb1 = rcu_replace_pointer(sdev->vpd_pgb1, vpd_pgb1,
497+
lockdep_is_held(&sdev->inquiry_mutex));
498+
vpd_pgb2 = rcu_replace_pointer(sdev->vpd_pgb2, vpd_pgb2,
499+
lockdep_is_held(&sdev->inquiry_mutex));
493500
mutex_unlock(&sdev->inquiry_mutex);
494501

495502
if (vpd_pg0)
@@ -500,6 +507,12 @@ static void scsi_device_dev_release_usercontext(struct work_struct *work)
500507
kfree_rcu(vpd_pg80, rcu);
501508
if (vpd_pg89)
502509
kfree_rcu(vpd_pg89, rcu);
510+
if (vpd_pgb0)
511+
kfree_rcu(vpd_pgb0, rcu);
512+
if (vpd_pgb1)
513+
kfree_rcu(vpd_pgb1, rcu);
514+
if (vpd_pgb2)
515+
kfree_rcu(vpd_pgb2, rcu);
503516
kfree(sdev->inquiry);
504517
kfree(sdev);
505518

@@ -913,6 +926,9 @@ static struct bin_attribute dev_attr_vpd_##_page = { \
913926
sdev_vpd_pg_attr(pg83);
914927
sdev_vpd_pg_attr(pg80);
915928
sdev_vpd_pg_attr(pg89);
929+
sdev_vpd_pg_attr(pgb0);
930+
sdev_vpd_pg_attr(pgb1);
931+
sdev_vpd_pg_attr(pgb2);
916932
sdev_vpd_pg_attr(pg0);
917933

918934
static ssize_t show_inquiry(struct file *filep, struct kobject *kobj,
@@ -1250,6 +1266,15 @@ static umode_t scsi_sdev_bin_attr_is_visible(struct kobject *kobj,
12501266
if (attr == &dev_attr_vpd_pg89 && !sdev->vpd_pg89)
12511267
return 0;
12521268

1269+
if (attr == &dev_attr_vpd_pgb0 && !sdev->vpd_pgb0)
1270+
return 0;
1271+
1272+
if (attr == &dev_attr_vpd_pgb1 && !sdev->vpd_pgb1)
1273+
return 0;
1274+
1275+
if (attr == &dev_attr_vpd_pgb2 && !sdev->vpd_pgb2)
1276+
return 0;
1277+
12531278
return S_IRUGO;
12541279
}
12551280

@@ -1296,6 +1321,9 @@ static struct bin_attribute *scsi_sdev_bin_attrs[] = {
12961321
&dev_attr_vpd_pg83,
12971322
&dev_attr_vpd_pg80,
12981323
&dev_attr_vpd_pg89,
1324+
&dev_attr_vpd_pgb0,
1325+
&dev_attr_vpd_pgb1,
1326+
&dev_attr_vpd_pgb2,
12991327
&dev_attr_inquiry,
13001328
NULL
13011329
};

include/scsi/scsi_device.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,10 @@ struct scsi_device {
149149
struct scsi_vpd __rcu *vpd_pg83;
150150
struct scsi_vpd __rcu *vpd_pg80;
151151
struct scsi_vpd __rcu *vpd_pg89;
152+
struct scsi_vpd __rcu *vpd_pgb0;
153+
struct scsi_vpd __rcu *vpd_pgb1;
154+
struct scsi_vpd __rcu *vpd_pgb2;
155+
152156
struct scsi_target *sdev_target;
153157

154158
blist_flags_t sdev_bflags; /* black/white flags as also found in

0 commit comments

Comments
 (0)