1 From d188b0675b21d5a6ca27b3e741381813983f4719 Mon Sep 17 00:00:00 2001
2 From: Ryan Attard <ryanattard@ryanattard.info>
3 Date: Thu, 26 Sep 2019 11:22:17 -0500
4 Subject: [PATCH] scsi: core: Add sysfs attributes for VPD pages 0h and 89h
6 Add sysfs attributes for the ATA information page and Supported VPD Pages
9 Link: https://lore.kernel.org/r/20190926162216.56591-1-ryanattard@ryanattard.info
10 Signed-off-by: Ryan Attard <ryanattard@ryanattard.info>
11 Reviewed-by: Bart Van Assche <bvanassche@acm.org>
12 Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
14 drivers/scsi/scsi.c | 4 ++++
15 drivers/scsi/scsi_sysfs.c | 19 +++++++++++++++++++
16 include/scsi/scsi_device.h | 2 ++
17 3 files changed, 25 insertions(+)
19 --- a/drivers/scsi/scsi.c
20 +++ b/drivers/scsi/scsi.c
21 @@ -465,10 +465,14 @@ void scsi_attach_vpd(struct scsi_device
24 for (i = 4; i < vpd_buf->len; i++) {
25 + if (vpd_buf->data[i] == 0x0)
26 + scsi_update_vpd_page(sdev, 0x0, &sdev->vpd_pg0);
27 if (vpd_buf->data[i] == 0x80)
28 scsi_update_vpd_page(sdev, 0x80, &sdev->vpd_pg80);
29 if (vpd_buf->data[i] == 0x83)
30 scsi_update_vpd_page(sdev, 0x83, &sdev->vpd_pg83);
31 + if (vpd_buf->data[i] == 0x89)
32 + scsi_update_vpd_page(sdev, 0x89, &sdev->vpd_pg89);
36 --- a/drivers/scsi/scsi_sysfs.c
37 +++ b/drivers/scsi/scsi_sysfs.c
38 @@ -437,6 +437,7 @@ static void scsi_device_dev_release_user
39 struct device *parent;
40 struct list_head *this, *tmp;
41 struct scsi_vpd *vpd_pg80 = NULL, *vpd_pg83 = NULL;
42 + struct scsi_vpd *vpd_pg0 = NULL, *vpd_pg89 = NULL;
46 @@ -469,16 +470,24 @@ static void scsi_device_dev_release_user
47 sdev->request_queue = NULL;
49 mutex_lock(&sdev->inquiry_mutex);
50 + rcu_swap_protected(sdev->vpd_pg0, vpd_pg0,
51 + lockdep_is_held(&sdev->inquiry_mutex));
52 rcu_swap_protected(sdev->vpd_pg80, vpd_pg80,
53 lockdep_is_held(&sdev->inquiry_mutex));
54 rcu_swap_protected(sdev->vpd_pg83, vpd_pg83,
55 lockdep_is_held(&sdev->inquiry_mutex));
56 + rcu_swap_protected(sdev->vpd_pg89, vpd_pg89,
57 + lockdep_is_held(&sdev->inquiry_mutex));
58 mutex_unlock(&sdev->inquiry_mutex);
61 + kfree_rcu(vpd_pg0, rcu);
63 kfree_rcu(vpd_pg83, rcu);
65 kfree_rcu(vpd_pg80, rcu);
67 + kfree_rcu(vpd_pg89, rcu);
71 @@ -883,6 +892,8 @@ static struct bin_attribute dev_attr_vpd
73 sdev_vpd_pg_attr(pg83);
74 sdev_vpd_pg_attr(pg80);
75 +sdev_vpd_pg_attr(pg89);
76 +sdev_vpd_pg_attr(pg0);
78 static ssize_t show_inquiry(struct file *filep, struct kobject *kobj,
79 struct bin_attribute *bin_attr,
80 @@ -1215,12 +1226,18 @@ static umode_t scsi_sdev_bin_attr_is_vis
81 struct scsi_device *sdev = to_scsi_device(dev);
84 + if (attr == &dev_attr_vpd_pg0 && !sdev->vpd_pg0)
87 if (attr == &dev_attr_vpd_pg80 && !sdev->vpd_pg80)
90 if (attr == &dev_attr_vpd_pg83 && !sdev->vpd_pg83)
93 + if (attr == &dev_attr_vpd_pg89 && !sdev->vpd_pg89)
99 @@ -1263,8 +1280,10 @@ static struct attribute *scsi_sdev_attrs
102 static struct bin_attribute *scsi_sdev_bin_attrs[] = {
106 + &dev_attr_vpd_pg89,
110 --- a/include/scsi/scsi_device.h
111 +++ b/include/scsi/scsi_device.h
112 @@ -140,8 +140,10 @@ struct scsi_device {
113 const char * rev; /* ... "nullnullnullnull" before scan */
115 #define SCSI_VPD_PG_LEN 255
116 + struct scsi_vpd __rcu *vpd_pg0;
117 struct scsi_vpd __rcu *vpd_pg83;
118 struct scsi_vpd __rcu *vpd_pg80;
119 + struct scsi_vpd __rcu *vpd_pg89;
120 unsigned char current_tag; /* current tag */
121 struct scsi_target *sdev_target; /* used only for single_lun */