Skip to content

Commit 09e2b0b

Browse files
hreineckemartinkpetersen
authored andcommitted
scsi: rescan VPD attributes
The VPD page information might change, so we need to be able to update it. This patch implements a VPD page rescan whenever the 'rescan' sysfs attribute is triggered. Signed-off-by: Hannes Reinecke <hare@suse.de> Reviewed-by: Johannes Thumshirn <jthumshirn@suse.de> Reviewed-by: Shane Seymour <shane.seymour@hpe.com> Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
1 parent fe0798c commit 09e2b0b

File tree

5 files changed

+39
-10
lines changed

5 files changed

+39
-10
lines changed

drivers/scsi/scsi.c

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -782,7 +782,7 @@ void scsi_attach_vpd(struct scsi_device *sdev)
782782
int vpd_len = SCSI_VPD_PG_LEN;
783783
int pg80_supported = 0;
784784
int pg83_supported = 0;
785-
unsigned char *vpd_buf;
785+
unsigned char __rcu *vpd_buf, *orig_vpd_buf = NULL;
786786

787787
if (sdev->skip_vpd_pages)
788788
return;
@@ -828,8 +828,16 @@ void scsi_attach_vpd(struct scsi_device *sdev)
828828
kfree(vpd_buf);
829829
goto retry_pg80;
830830
}
831+
mutex_lock(&sdev->inquiry_mutex);
832+
orig_vpd_buf = sdev->vpd_pg80;
831833
sdev->vpd_pg80_len = result;
832-
sdev->vpd_pg80 = vpd_buf;
834+
rcu_assign_pointer(sdev->vpd_pg80, vpd_buf);
835+
mutex_unlock(&sdev->inquiry_mutex);
836+
synchronize_rcu();
837+
if (orig_vpd_buf) {
838+
kfree(orig_vpd_buf);
839+
orig_vpd_buf = NULL;
840+
}
833841
vpd_len = SCSI_VPD_PG_LEN;
834842
}
835843

@@ -849,8 +857,14 @@ void scsi_attach_vpd(struct scsi_device *sdev)
849857
kfree(vpd_buf);
850858
goto retry_pg83;
851859
}
860+
mutex_lock(&sdev->inquiry_mutex);
861+
orig_vpd_buf = sdev->vpd_pg83;
852862
sdev->vpd_pg83_len = result;
853-
sdev->vpd_pg83 = vpd_buf;
863+
rcu_assign_pointer(sdev->vpd_pg83, vpd_buf);
864+
mutex_unlock(&sdev->inquiry_mutex);
865+
synchronize_rcu();
866+
if (orig_vpd_buf)
867+
kfree(orig_vpd_buf);
854868
}
855869
}
856870

drivers/scsi/scsi_scan.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,7 @@ static struct scsi_device *scsi_alloc_sdev(struct scsi_target *starget,
236236
INIT_LIST_HEAD(&sdev->starved_entry);
237237
INIT_LIST_HEAD(&sdev->event_list);
238238
spin_lock_init(&sdev->list_lock);
239+
mutex_init(&sdev->inquiry_mutex);
239240
INIT_WORK(&sdev->event_work, scsi_evt_thread);
240241
INIT_WORK(&sdev->requeue_work, scsi_requeue_run_queue);
241242

@@ -1516,6 +1517,9 @@ EXPORT_SYMBOL(scsi_add_device);
15161517
void scsi_rescan_device(struct device *dev)
15171518
{
15181519
device_lock(dev);
1520+
1521+
scsi_attach_vpd(to_scsi_device(dev));
1522+
15191523
if (dev->driver && try_module_get(dev->driver->owner)) {
15201524
struct scsi_driver *drv = to_scsi_driver(dev->driver);
15211525

drivers/scsi/scsi_sysfs.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -760,11 +760,15 @@ show_vpd_##_page(struct file *filp, struct kobject *kobj, \
760760
{ \
761761
struct device *dev = container_of(kobj, struct device, kobj); \
762762
struct scsi_device *sdev = to_scsi_device(dev); \
763+
int ret; \
763764
if (!sdev->vpd_##_page) \
764765
return -EINVAL; \
765-
return memory_read_from_buffer(buf, count, &off, \
766-
sdev->vpd_##_page, \
766+
rcu_read_lock(); \
767+
ret = memory_read_from_buffer(buf, count, &off, \
768+
rcu_dereference(sdev->vpd_##_page), \
767769
sdev->vpd_##_page##_len); \
770+
rcu_read_unlock(); \
771+
return ret; \
768772
} \
769773
static struct bin_attribute dev_attr_vpd_##_page = { \
770774
.attr = {.name = __stringify(vpd_##_page), .mode = S_IRUGO }, \

drivers/scsi/ses.c

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -554,17 +554,22 @@ static void ses_match_to_enclosure(struct enclosure_device *edev,
554554
struct scsi_device *sdev)
555555
{
556556
unsigned char *desc;
557+
unsigned char __rcu *vpd_pg83;
557558
struct efd efd = {
558559
.addr = 0,
559560
};
560561

561562
ses_enclosure_data_process(edev, to_scsi_device(edev->edev.parent), 0);
562563

563-
if (!sdev->vpd_pg83_len)
564+
rcu_read_lock();
565+
vpd_pg83 = rcu_dereference(sdev->vpd_pg83);
566+
if (!vpd_pg83) {
567+
rcu_read_unlock();
564568
return;
569+
}
565570

566-
desc = sdev->vpd_pg83 + 4;
567-
while (desc < sdev->vpd_pg83 + sdev->vpd_pg83_len) {
571+
desc = vpd_pg83 + 4;
572+
while (desc < vpd_pg83 + sdev->vpd_pg83_len) {
568573
enum scsi_protocol proto = desc[0] >> 4;
569574
u8 code_set = desc[0] & 0x0f;
570575
u8 piv = desc[1] & 0x80;
@@ -578,6 +583,7 @@ static void ses_match_to_enclosure(struct enclosure_device *edev,
578583

579584
desc += len + 4;
580585
}
586+
rcu_read_unlock();
581587
if (efd.addr) {
582588
efd.dev = &sdev->sdev_gendev;
583589

include/scsi/scsi_device.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@ struct scsi_device {
109109
char type;
110110
char scsi_level;
111111
char inq_periph_qual; /* PQ from INQUIRY data */
112+
struct mutex inquiry_mutex;
112113
unsigned char inquiry_len; /* valid bytes in 'inquiry' */
113114
unsigned char * inquiry; /* INQUIRY response data */
114115
const char * vendor; /* [back_compat] point into 'inquiry' ... */
@@ -117,9 +118,9 @@ struct scsi_device {
117118

118119
#define SCSI_VPD_PG_LEN 255
119120
int vpd_pg83_len;
120-
unsigned char *vpd_pg83;
121+
unsigned char __rcu *vpd_pg83;
121122
int vpd_pg80_len;
122-
unsigned char *vpd_pg80;
123+
unsigned char __rcu *vpd_pg80;
123124
unsigned char current_tag; /* current tag */
124125
struct scsi_target *sdev_target; /* used only for single_lun */
125126

0 commit comments

Comments
 (0)