kernel: bump 5.4 to 5.4.34
[oweals/openwrt.git] / target / linux / generic / backport-5.4 / 800-v5.5-scsi-core-Add-sysfs-attributes-for-VPD-pages-0h-and-.patch
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
5
6 Add sysfs attributes for the ATA information page and Supported VPD Pages
7 page.
8
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>
13 ---
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(+)
18
19 --- a/drivers/scsi/scsi.c
20 +++ b/drivers/scsi/scsi.c
21 @@ -465,10 +465,14 @@ void scsi_attach_vpd(struct scsi_device
22                 return;
23  
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);
33         }
34         kfree(vpd_buf);
35  }
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;
43         unsigned long flags;
44  
45         sdev = container_of(work, struct scsi_device, ew.work);
46 @@ -466,16 +467,24 @@ static void scsi_device_dev_release_user
47         sdev->request_queue = NULL;
48  
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);
59  
60 +       if (vpd_pg0)
61 +               kfree_rcu(vpd_pg0, rcu);
62         if (vpd_pg83)
63                 kfree_rcu(vpd_pg83, rcu);
64         if (vpd_pg80)
65                 kfree_rcu(vpd_pg80, rcu);
66 +       if (vpd_pg89)
67 +               kfree_rcu(vpd_pg89, rcu);
68         kfree(sdev->inquiry);
69         kfree(sdev);
70  
71 @@ -868,6 +877,8 @@ static struct bin_attribute dev_attr_vpd
72  
73  sdev_vpd_pg_attr(pg83);
74  sdev_vpd_pg_attr(pg80);
75 +sdev_vpd_pg_attr(pg89);
76 +sdev_vpd_pg_attr(pg0);
77  
78  static ssize_t show_inquiry(struct file *filep, struct kobject *kobj,
79                             struct bin_attribute *bin_attr,
80 @@ -1200,12 +1211,18 @@ static umode_t scsi_sdev_bin_attr_is_vis
81         struct scsi_device *sdev = to_scsi_device(dev);
82  
83  
84 +       if (attr == &dev_attr_vpd_pg0 && !sdev->vpd_pg0)
85 +               return 0;
86 +
87         if (attr == &dev_attr_vpd_pg80 && !sdev->vpd_pg80)
88                 return 0;
89  
90         if (attr == &dev_attr_vpd_pg83 && !sdev->vpd_pg83)
91                 return 0;
92  
93 +       if (attr == &dev_attr_vpd_pg89 && !sdev->vpd_pg89)
94 +               return 0;
95 +
96         return S_IRUGO;
97  }
98  
99 @@ -1248,8 +1265,10 @@ static struct attribute *scsi_sdev_attrs
100  };
101  
102  static struct bin_attribute *scsi_sdev_bin_attrs[] = {
103 +       &dev_attr_vpd_pg0,
104         &dev_attr_vpd_pg83,
105         &dev_attr_vpd_pg80,
106 +       &dev_attr_vpd_pg89,
107         &dev_attr_inquiry,
108         NULL
109  };
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 */
114  
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 */
122