Skip to content

Commit

Permalink
scsi: Register SCSI device sysfs attributes earlier
Browse files Browse the repository at this point in the history
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 device sysfs attributes before the SCSI host shost_dev
uevent is emitted instead of after that event has been emitted.

Fixes: 86b87cd ("scsi: core: host template attribute groups")
Signed-off-by: Bart Van Assche <bvanassche@acm.org>
  • Loading branch information
bvanassche committed Sep 27, 2021
1 parent 983ecfd commit 3d4f1af
Show file tree
Hide file tree
Showing 28 changed files with 232 additions and 125 deletions.
4 changes: 2 additions & 2 deletions drivers/ata/ahci.h
Expand Up @@ -377,7 +377,7 @@ struct ahci_host_priv {
extern int ahci_ignore_sss;

extern const struct attribute_group *ahci_shost_attr_groups[];
extern struct device_attribute *ahci_sdev_attrs[];
extern const struct attribute_group *ahci_sdev_attr_groups[];

/*
* This must be instantiated by the edge drivers. Read the comments
Expand All @@ -389,7 +389,7 @@ extern struct device_attribute *ahci_sdev_attrs[];
.sg_tablesize = AHCI_MAX_SG, \
.dma_boundary = AHCI_DMA_BOUNDARY, \
.shost_attr_groups = ahci_shost_attr_groups, \
.sdev_attrs = ahci_sdev_attrs, \
.sdev_attr_groups = ahci_sdev_attr_groups, \
.change_queue_depth = ata_scsi_change_queue_depth, \
.tag_alloc_policy = BLK_TAG_ALLOC_RR, \
.slave_configure = ata_scsi_slave_config
Expand Down
21 changes: 15 additions & 6 deletions drivers/ata/libahci.c
Expand Up @@ -131,14 +131,23 @@ const struct attribute_group *ahci_shost_attr_groups[] = {
};
EXPORT_SYMBOL_GPL(ahci_shost_attr_groups);

struct device_attribute *ahci_sdev_attrs[] = {
&dev_attr_sw_activity,
&dev_attr_unload_heads,
&dev_attr_ncq_prio_supported,
&dev_attr_ncq_prio_enable,
struct attribute *ahci_sdev_attrs[] = {
&dev_attr_sw_activity.attr,
&dev_attr_unload_heads.attr,
&dev_attr_ncq_prio_supported.attr,
&dev_attr_ncq_prio_enable.attr,
NULL
};
EXPORT_SYMBOL_GPL(ahci_sdev_attrs);

static const struct attribute_group ahci_sdev_attr_group = {
.attrs = ahci_sdev_attrs
};

const struct attribute_group *ahci_sdev_attr_groups[] = {
&ahci_sdev_attr_group,
NULL
};
EXPORT_SYMBOL_GPL(ahci_sdev_attr_groups);

struct ata_port_operations ahci_ops = {
.inherits = &sata_pmp_port_ops,
Expand Down
19 changes: 14 additions & 5 deletions drivers/ata/libata-sata.c
Expand Up @@ -922,13 +922,22 @@ DEVICE_ATTR(ncq_prio_enable, S_IRUGO | S_IWUSR,
ata_ncq_prio_enable_show, ata_ncq_prio_enable_store);
EXPORT_SYMBOL_GPL(dev_attr_ncq_prio_enable);

struct device_attribute *ata_ncq_sdev_attrs[] = {
&dev_attr_unload_heads,
&dev_attr_ncq_prio_enable,
&dev_attr_ncq_prio_supported,
struct attribute *ata_ncq_sdev_attrs[] = {
&dev_attr_unload_heads.attr,
&dev_attr_ncq_prio_enable.attr,
&dev_attr_ncq_prio_supported.attr,
NULL
};
EXPORT_SYMBOL_GPL(ata_ncq_sdev_attrs);

static const struct attribute_group ata_ncq_sdev_attr_group = {
.attrs = ata_ncq_sdev_attrs
};

const struct attribute_group *ata_ncq_sdev_attr_groups[] = {
&ata_ncq_sdev_attr_group,
NULL
};
EXPORT_SYMBOL_GPL(ata_ncq_sdev_attr_groups);

static ssize_t
ata_scsi_em_message_store(struct device *dev, struct device_attribute *attr,
Expand Down
15 changes: 12 additions & 3 deletions drivers/ata/libata-scsi.c
Expand Up @@ -234,11 +234,20 @@ static void ata_scsi_set_invalid_parameter(struct ata_device *dev,
field, 0xff, 0);
}

struct device_attribute *ata_common_sdev_attrs[] = {
&dev_attr_unload_heads,
static struct attribute *ata_common_sdev_attrs[] = {
&dev_attr_unload_heads.attr,
NULL
};
EXPORT_SYMBOL_GPL(ata_common_sdev_attrs);

static const struct attribute_group ata_common_sdev_attr_group = {
.attrs = ata_common_sdev_attrs
};

const struct attribute_group *ata_common_sdev_attr_groups[] = {
&ata_common_sdev_attr_group,
NULL
};
EXPORT_SYMBOL_GPL(ata_common_sdev_attr_groups);

/**
* ata_std_bios_param - generic bios head/sector/cylinder calculator used by sd.
Expand Down
2 changes: 1 addition & 1 deletion drivers/ata/pata_macio.c
Expand Up @@ -923,7 +923,7 @@ static struct scsi_host_template pata_macio_sht = {
*/
.max_segment_size = MAX_DBDMA_SEG,
.slave_configure = pata_macio_slave_config,
.sdev_attrs = ata_common_sdev_attrs,
.sdev_attr_groups = ata_common_sdev_attr_groups,
.can_queue = ATA_DEF_QUEUE,
.tag_alloc_policy = BLK_TAG_ALLOC_RR,
};
Expand Down
2 changes: 1 addition & 1 deletion drivers/ata/sata_mv.c
Expand Up @@ -670,7 +670,7 @@ static struct scsi_host_template mv6_sht = {
.can_queue = MV_MAX_Q_DEPTH - 1,
.sg_tablesize = MV_MAX_SG_CT / 2,
.dma_boundary = MV_DMA_BOUNDARY,
.sdev_attrs = ata_ncq_sdev_attrs,
.sdev_attr_groups = ata_ncq_sdev_attr_groups,
.change_queue_depth = ata_scsi_change_queue_depth,
.tag_alloc_policy = BLK_TAG_ALLOC_RR,
.slave_configure = ata_scsi_slave_config
Expand Down
4 changes: 2 additions & 2 deletions drivers/ata/sata_nv.c
Expand Up @@ -380,7 +380,7 @@ static struct scsi_host_template nv_adma_sht = {
.sg_tablesize = NV_ADMA_SGTBL_TOTAL_LEN,
.dma_boundary = NV_ADMA_DMA_BOUNDARY,
.slave_configure = nv_adma_slave_config,
.sdev_attrs = ata_ncq_sdev_attrs,
.sdev_attr_groups = ata_ncq_sdev_attr_groups,
.change_queue_depth = ata_scsi_change_queue_depth,
.tag_alloc_policy = BLK_TAG_ALLOC_RR,
};
Expand All @@ -391,7 +391,7 @@ static struct scsi_host_template nv_swncq_sht = {
.sg_tablesize = LIBATA_MAX_PRD,
.dma_boundary = ATA_DMA_BOUNDARY,
.slave_configure = nv_swncq_slave_config,
.sdev_attrs = ata_ncq_sdev_attrs,
.sdev_attr_groups = ata_ncq_sdev_attr_groups,
.change_queue_depth = ata_scsi_change_queue_depth,
.tag_alloc_policy = BLK_TAG_ALLOC_RR,
};
Expand Down
2 changes: 1 addition & 1 deletion drivers/ata/sata_sil24.c
Expand Up @@ -379,7 +379,7 @@ static struct scsi_host_template sil24_sht = {
.sg_tablesize = SIL24_MAX_SGE,
.dma_boundary = ATA_DMA_BOUNDARY,
.tag_alloc_policy = BLK_TAG_ALLOC_FIFO,
.sdev_attrs = ata_ncq_sdev_attrs,
.sdev_attr_groups = ata_ncq_sdev_attr_groups,
.change_queue_depth = ata_scsi_change_queue_depth,
.slave_configure = ata_scsi_slave_config
};
Expand Down
6 changes: 3 additions & 3 deletions drivers/firewire/sbp2.c
Expand Up @@ -1578,8 +1578,8 @@ static ssize_t sbp2_sysfs_ieee1394_id_show(struct device *dev,

static DEVICE_ATTR(ieee1394_id, S_IRUGO, sbp2_sysfs_ieee1394_id_show, NULL);

static struct device_attribute *sbp2_scsi_sysfs_attrs[] = {
&dev_attr_ieee1394_id,
static struct attribute *sbp2_scsi_sysfs_attrs[] = {
&dev_attr_ieee1394_id.attr,
NULL
};

Expand All @@ -1595,7 +1595,7 @@ static struct scsi_host_template scsi_driver_template = {
.sg_tablesize = SG_ALL,
.max_segment_size = SBP2_MAX_SEG_SIZE,
.can_queue = 1,
.sdev_attrs = sbp2_scsi_sysfs_attrs,
.sdev_attr_groups = sbp2_scsi_sysfs_attr_groups,
};

MODULE_AUTHOR("Kristian Hoegsberg <krh@bitplanet.net>");
Expand Down
2 changes: 1 addition & 1 deletion drivers/s390/scsi/zfcp_ext.h
Expand Up @@ -184,7 +184,7 @@ extern const struct attribute_group *zfcp_sysfs_adapter_attr_groups[];
extern const struct attribute_group *zfcp_unit_attr_groups[];
extern const struct attribute_group *zfcp_port_attr_groups[];
extern struct mutex zfcp_sysfs_port_units_mutex;
extern struct device_attribute *zfcp_sysfs_sdev_attrs[];
extern const struct attribute_group *zfcp_sysfs_sdev_attr_groups[];
extern const struct attribute_group *zfcp_shost_attr_groups[];
bool zfcp_sysfs_port_is_removing(const struct zfcp_port *const port);

Expand Down
2 changes: 1 addition & 1 deletion drivers/s390/scsi/zfcp_scsi.c
Expand Up @@ -445,7 +445,7 @@ static struct scsi_host_template zfcp_scsi_host_template = {
.max_segment_size = ZFCP_QDIO_SBALE_LEN,
.dma_boundary = ZFCP_QDIO_SBALE_LEN - 1,
.shost_attr_groups = zfcp_shost_attr_groups,
.sdev_attrs = zfcp_sysfs_sdev_attrs,
.sdev_attr_groups = zfcp_sysfs_sdev_attr_groups,
.track_queue_depth = 1,
.supported_mode = MODE_INITIATOR,
};
Expand Down
31 changes: 20 additions & 11 deletions drivers/s390/scsi/zfcp_sysfs.c
Expand Up @@ -672,17 +672,26 @@ ZFCP_DEFINE_SCSI_ATTR(zfcp_in_recovery, "%d\n",
ZFCP_DEFINE_SCSI_ATTR(zfcp_status, "0x%08x\n",
atomic_read(&zfcp_sdev->status));

struct device_attribute *zfcp_sysfs_sdev_attrs[] = {
&dev_attr_fcp_lun,
&dev_attr_wwpn,
&dev_attr_hba_id,
&dev_attr_read_latency,
&dev_attr_write_latency,
&dev_attr_cmd_latency,
&dev_attr_zfcp_access_denied,
&dev_attr_zfcp_failed,
&dev_attr_zfcp_in_recovery,
&dev_attr_zfcp_status,
struct attribute *zfcp_sysfs_sdev_attrs[] = {
&dev_attr_fcp_lun.attr,
&dev_attr_wwpn.attr,
&dev_attr_hba_id.attr,
&dev_attr_read_latency.attr,
&dev_attr_write_latency.attr,
&dev_attr_cmd_latency.attr,
&dev_attr_zfcp_access_denied.attr,
&dev_attr_zfcp_failed.attr,
&dev_attr_zfcp_in_recovery.attr,
&dev_attr_zfcp_status.attr,
NULL
};

static const struct attribute_group zfcp_sysfs_sdev_attr_group = {
.attrs = zfcp_sysfs_sdev_attrs
};

const struct attribute_group *zfcp_sysfs_sdev_attr_groups[] = {
&zfcp_sysfs_sdev_attr_group,
NULL
};

Expand Down
19 changes: 14 additions & 5 deletions drivers/scsi/53c700.c
Expand Up @@ -163,7 +163,7 @@ STATIC int NCR_700_slave_configure(struct scsi_device *SDpnt);
STATIC void NCR_700_slave_destroy(struct scsi_device *SDpnt);
static int NCR_700_change_queue_depth(struct scsi_device *SDpnt, int depth);

STATIC struct device_attribute *NCR_700_dev_attrs[];
STATIC const struct attribute_group *NCR_700_dev_attr_groups[];

STATIC struct scsi_transport_template *NCR_700_transport_template = NULL;

Expand Down Expand Up @@ -300,8 +300,8 @@ NCR_700_detect(struct scsi_host_template *tpnt,
static int banner = 0;
int j;

if(tpnt->sdev_attrs == NULL)
tpnt->sdev_attrs = NCR_700_dev_attrs;
if (tpnt->sdev_attr_groups == NULL)
tpnt->sdev_attr_groups = NCR_700_dev_attr_groups;

memory = dma_alloc_coherent(dev, TOTAL_MEM_SIZE, &pScript, GFP_KERNEL);
if (!memory) {
Expand Down Expand Up @@ -2087,11 +2087,20 @@ static struct device_attribute NCR_700_active_tags_attr = {
.show = NCR_700_show_active_tags,
};

STATIC struct device_attribute *NCR_700_dev_attrs[] = {
&NCR_700_active_tags_attr,
STATIC struct attribute *NCR_700_dev_attrs[] = {
&NCR_700_active_tags_attr.attr,
NULL,
};

STATIC const struct attribute_group NCR_700_dev_attr_group = {
.attrs = NCR_700_dev_attrs
};

STATIC const struct attribute_group *NCR_700_dev_attr_groups[] = {
&NCR_700_dev_attr_group,
NULL
};

EXPORT_SYMBOL(NCR_700_detect);
EXPORT_SYMBOL(NCR_700_release);
EXPORT_SYMBOL(NCR_700_intr);
Expand Down
17 changes: 13 additions & 4 deletions drivers/scsi/aacraid/linit.c
Expand Up @@ -605,12 +605,21 @@ static struct device_attribute aac_unique_id_attr = {



static struct device_attribute *aac_dev_attrs[] = {
&aac_raid_level_attr,
&aac_unique_id_attr,
static struct attribute *aac_dev_attrs[] = {
&aac_raid_level_attr.attr,
&aac_unique_id_attr.attr,
NULL,
};

static const struct attribute_group aac_dev_attr_group = {
.attrs = aac_dev_attrs
};

static const struct attribute_group *aac_dev_attr_groups[] = {
&aac_dev_attr_group,
NULL
};

static int aac_ioctl(struct scsi_device *sdev, unsigned int cmd,
void __user *arg)
{
Expand Down Expand Up @@ -1495,7 +1504,7 @@ static struct scsi_host_template aac_driver_template = {
.shost_attr_groups = aac_attr_groups,
.slave_configure = aac_slave_configure,
.change_queue_depth = aac_change_queue_depth,
.sdev_attrs = aac_dev_attrs,
.sdev_attr_groups = aac_dev_attr_groups,
.eh_abort_handler = aac_eh_abort,
.eh_device_reset_handler = aac_eh_dev_reset,
.eh_target_reset_handler = aac_eh_target_reset,
Expand Down
11 changes: 10 additions & 1 deletion drivers/scsi/cxlflash/main.c
Expand Up @@ -3139,6 +3139,15 @@ static struct attribute *cxlflash_dev_attrs[] = {
NULL
};

static const struct attribute_group cxlflash_dev_attr_group = {
.attrs = cxlflash_dev_attrs
};

static const struct attribute_group *cxlflash_dev_attr_groups[] = {
&cxlflash_dev_attr_group,
NULL
};

/*
* Host template
*/
Expand All @@ -3160,7 +3169,7 @@ static struct scsi_host_template driver_template = {
.sg_tablesize = 1, /* No scatter gather support */
.max_sectors = CXLFLASH_MAX_SECTORS,
.shost_attr_groups = cxlflash_host_attr_groups,
.sdev_attrs = cxlflash_dev_attrs,
.sdev_attr_groups = cxlflash_dev_attr_groups,
};

/*
Expand Down
25 changes: 17 additions & 8 deletions drivers/scsi/hpsa.c
Expand Up @@ -936,16 +936,25 @@ static DEVICE_ATTR(ctlr_num, S_IRUGO,
static DEVICE_ATTR(legacy_board, S_IRUGO,
host_show_legacy_board, NULL);

static struct device_attribute *hpsa_sdev_attrs[] = {
&dev_attr_raid_level,
&dev_attr_lunid,
&dev_attr_unique_id,
&dev_attr_hp_ssd_smart_path_enabled,
&dev_attr_path_info,
&dev_attr_sas_address,
static struct attribute *hpsa_sdev_attrs[] = {
&dev_attr_raid_level.attr,
&dev_attr_lunid.attr,
&dev_attr_unique_id.attr,
&dev_attr_hp_ssd_smart_path_enabled.attr,
&dev_attr_path_info.attr,
&dev_attr_sas_address.attr,
NULL,
};

static const struct attribute_group hpsa_sdev_attr_group = {
.attrs = hpsa_sdev_attrs
};

static const struct attribute_group *hpsa_sdev_attr_groups[] = {
&hpsa_sdev_attr_group,
NULL
};

static struct attribute *hpsa_shost_attrs[] = {
&dev_attr_rescan.attr,
&dev_attr_firmware_revision.attr,
Expand Down Expand Up @@ -989,7 +998,7 @@ static struct scsi_host_template hpsa_driver_template = {
#ifdef CONFIG_COMPAT
.compat_ioctl = hpsa_compat_ioctl,
#endif
.sdev_attrs = hpsa_sdev_attrs,
.sdev_attr_groups = hpsa_sdev_attr_groups,
.shost_attr_groups = hpsa_shost_attr_groups,
.max_sectors = 2048,
.no_write_same = 1,
Expand Down

0 comments on commit 3d4f1af

Please sign in to comment.