diff options
author | Bart Van Assche <bvanassche@acm.org> | 2021-10-12 16:35:13 -0700 |
---|---|---|
committer | Martin K. Petersen <martin.petersen@oracle.com> | 2021-10-16 21:45:52 -0400 |
commit | 92c4b58b15c56298b1b225c1d2e533165b3e32af (patch) | |
tree | c59608ec54742e0aa884314dc72507390aad36eb /drivers/scsi/hosts.c | |
parent | af049dfd0b105bab32170d1c68826a4cd8424efd (diff) | |
download | linux-92c4b58b15c56298b1b225c1d2e533165b3e32af.tar.bz2 |
scsi: core: Register sysfs attributes earlier
A quote from Documentation/driver-api/driver-model/device.rst:
"Word of warning: While the kernel allows device_create_file() and
device_remove_file() to be called on a device at any time, userspace has
strict expectations on when attributes get created. When a new device is
registered in the kernel, a uevent is generated to notify userspace (like
udev) that a new device is available. If attributes are added after the
device is registered, then userspace won't get notified and userspace will
not know about the new attributes."
Hence register SCSI host sysfs attributes before the SCSI host shost_dev
uevent is emitted instead of after that event has been emitted.
Link: https://lore.kernel.org/r/20211012233558.4066756-2-bvanassche@acm.org
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Reviewed-by: Benjamin Block <bblock@linux.ibm.com>
Signed-off-by: Bart Van Assche <bvanassche@acm.org>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
Diffstat (limited to 'drivers/scsi/hosts.c')
-rw-r--r-- | drivers/scsi/hosts.c | 23 |
1 files changed, 21 insertions, 2 deletions
diff --git a/drivers/scsi/hosts.c b/drivers/scsi/hosts.c index d78cec702596..09157792d36b 100644 --- a/drivers/scsi/hosts.c +++ b/drivers/scsi/hosts.c @@ -376,7 +376,7 @@ static struct device_type scsi_host_type = { struct Scsi_Host *scsi_host_alloc(struct scsi_host_template *sht, int privsize) { struct Scsi_Host *shost; - int index; + int index, i, j = 0; shost = kzalloc(sizeof(struct Scsi_Host) + privsize, GFP_KERNEL); if (!shost) @@ -481,7 +481,26 @@ struct Scsi_Host *scsi_host_alloc(struct scsi_host_template *sht, int privsize) shost->shost_dev.parent = &shost->shost_gendev; shost->shost_dev.class = &shost_class; dev_set_name(&shost->shost_dev, "host%d", shost->host_no); - shost->shost_dev.groups = scsi_sysfs_shost_attr_groups; + shost->shost_dev.groups = shost->shost_dev_attr_groups; + shost->shost_dev_attr_groups[j++] = &scsi_shost_attr_group; + if (sht->shost_attrs) { + shost->lld_attr_group = (struct attribute_group){ + .attrs = scsi_convert_dev_attrs(&shost->shost_gendev, + sht->shost_attrs) + }; + if (shost->lld_attr_group.attrs) + shost->shost_dev_attr_groups[j++] = + &shost->lld_attr_group; + } + if (sht->shost_groups) { + for (i = 0; sht->shost_groups[i] && + j < ARRAY_SIZE(shost->shost_dev_attr_groups); + i++, j++) { + shost->shost_dev_attr_groups[j] = + sht->shost_groups[i]; + } + } + WARN_ON_ONCE(j >= ARRAY_SIZE(shost->shost_dev_attr_groups)); shost->ehandler = kthread_run(scsi_error_handler, shost, "scsi_eh_%d", shost->host_no); |