Skip to content

Commit d188b06

Browse files
Ryan Attardmartinkpetersen
authored andcommitted
scsi: core: Add sysfs attributes for VPD pages 0h and 89h
Add sysfs attributes for the ATA information page and Supported VPD Pages page. Link: https://lore.kernel.org/r/20190926162216.56591-1-ryanattard@ryanattard.info Signed-off-by: Ryan Attard <ryanattard@ryanattard.info> Reviewed-by: Bart Van Assche <bvanassche@acm.org> Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
1 parent 9e32231 commit d188b06

3 files changed

Lines changed: 25 additions & 0 deletions

File tree

‎drivers/scsi/scsi.c‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -465,10 +465,14 @@ void scsi_attach_vpd(struct scsi_device *sdev)
465465
return;
466466

467467
for (i = 4; i < vpd_buf->len; i++) {
468+
if (vpd_buf->data[i] == 0x0)
469+
scsi_update_vpd_page(sdev, 0x0, &sdev->vpd_pg0);
468470
if (vpd_buf->data[i] == 0x80)
469471
scsi_update_vpd_page(sdev, 0x80, &sdev->vpd_pg80);
470472
if (vpd_buf->data[i] == 0x83)
471473
scsi_update_vpd_page(sdev, 0x83, &sdev->vpd_pg83);
474+
if (vpd_buf->data[i] == 0x89)
475+
scsi_update_vpd_page(sdev, 0x89, &sdev->vpd_pg89);
472476
}
473477
kfree(vpd_buf);
474478
}

‎drivers/scsi/scsi_sysfs.c‎

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -437,6 +437,7 @@ static void scsi_device_dev_release_usercontext(struct work_struct *work)
437437
struct device *parent;
438438
struct list_head *this, *tmp;
439439
struct scsi_vpd *vpd_pg80 = NULL, *vpd_pg83 = NULL;
440+
struct scsi_vpd *vpd_pg0 = NULL, *vpd_pg89 = NULL;
440441
unsigned long flags;
441442

442443
sdev = container_of(work, struct scsi_device, ew.work);
@@ -466,16 +467,24 @@ static void scsi_device_dev_release_usercontext(struct work_struct *work)
466467
sdev->request_queue = NULL;
467468

468469
mutex_lock(&sdev->inquiry_mutex);
470+
rcu_swap_protected(sdev->vpd_pg0, vpd_pg0,
471+
lockdep_is_held(&sdev->inquiry_mutex));
469472
rcu_swap_protected(sdev->vpd_pg80, vpd_pg80,
470473
lockdep_is_held(&sdev->inquiry_mutex));
471474
rcu_swap_protected(sdev->vpd_pg83, vpd_pg83,
472475
lockdep_is_held(&sdev->inquiry_mutex));
476+
rcu_swap_protected(sdev->vpd_pg89, vpd_pg89,
477+
lockdep_is_held(&sdev->inquiry_mutex));
473478
mutex_unlock(&sdev->inquiry_mutex);
474479

480+
if (vpd_pg0)
481+
kfree_rcu(vpd_pg0, rcu);
475482
if (vpd_pg83)
476483
kfree_rcu(vpd_pg83, rcu);
477484
if (vpd_pg80)
478485
kfree_rcu(vpd_pg80, rcu);
486+
if (vpd_pg89)
487+
kfree_rcu(vpd_pg89, rcu);
479488
kfree(sdev->inquiry);
480489
kfree(sdev);
481490

@@ -859,6 +868,8 @@ static struct bin_attribute dev_attr_vpd_##_page = { \
859868

860869
sdev_vpd_pg_attr(pg83);
861870
sdev_vpd_pg_attr(pg80);
871+
sdev_vpd_pg_attr(pg89);
872+
sdev_vpd_pg_attr(pg0);
862873

863874
static ssize_t show_inquiry(struct file *filep, struct kobject *kobj,
864875
struct bin_attribute *bin_attr,
@@ -1191,12 +1202,18 @@ static umode_t scsi_sdev_bin_attr_is_visible(struct kobject *kobj,
11911202
struct scsi_device *sdev = to_scsi_device(dev);
11921203

11931204

1205+
if (attr == &dev_attr_vpd_pg0 && !sdev->vpd_pg0)
1206+
return 0;
1207+
11941208
if (attr == &dev_attr_vpd_pg80 && !sdev->vpd_pg80)
11951209
return 0;
11961210

11971211
if (attr == &dev_attr_vpd_pg83 && !sdev->vpd_pg83)
11981212
return 0;
11991213

1214+
if (attr == &dev_attr_vpd_pg89 && !sdev->vpd_pg89)
1215+
return 0;
1216+
12001217
return S_IRUGO;
12011218
}
12021219

@@ -1239,8 +1256,10 @@ static struct attribute *scsi_sdev_attrs[] = {
12391256
};
12401257

12411258
static struct bin_attribute *scsi_sdev_bin_attrs[] = {
1259+
&dev_attr_vpd_pg0,
12421260
&dev_attr_vpd_pg83,
12431261
&dev_attr_vpd_pg80,
1262+
&dev_attr_vpd_pg89,
12441263
&dev_attr_inquiry,
12451264
NULL
12461265
};

‎include/scsi/scsi_device.h‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,8 +140,10 @@ struct scsi_device {
140140
const char * rev; /* ... "nullnullnullnull" before scan */
141141

142142
#define SCSI_VPD_PG_LEN 255
143+
struct scsi_vpd __rcu *vpd_pg0;
143144
struct scsi_vpd __rcu *vpd_pg83;
144145
struct scsi_vpd __rcu *vpd_pg80;
146+
struct scsi_vpd __rcu *vpd_pg89;
145147
unsigned char current_tag; /* current tag */
146148
struct scsi_target *sdev_target; /* used only for single_lun */
147149

0 commit comments

Comments
 (0)