linux-scsi.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* Problem with scsi device sysfs attributes
@ 2021-11-11  3:31 Damien Le Moal
  2021-11-11  5:27 ` Damien Le Moal
  0 siblings, 1 reply; 3+ messages in thread
From: Damien Le Moal @ 2021-11-11  3:31 UTC (permalink / raw)
  To: Bart Van Assche, linux-scsi @ vger . kernel . org,
	Martin K . Petersen, linux-ide

Bart,

Your patch 92c4b58b15c5 ("scsi: core: Register sysfs attributes earlier")
modified the scsi device sysfs attributes initialization to use the scsi
template shost_groups and sdev_groups for adding attributes using groups instead
of arrays of attrs. However, this patch completely removed the
sysfs_create_groups() call to actually create the attributes listed in the groups.

As a result, I see many missing sysfs device attributes for at least ahci (e.g.
ncq_prio_enavle, ncq_prio_supported), but I suspect other device types may have
similar problems.

I do not see where the attribute groups in the arrray sdev->gendev_attr_groups
are registered with sysfs. In fact, it looks like sdev->gendev_attr_groups is
referenced only in scsi_sysfs.c but only for initializing it. It is never used
to actually register the attr groups... Am I missing something ?

This is at least breaking NCQ priority support right now. Did your patch
92c4b58b15c5 remove too much code ? Shouldn't we have a call to
sysfs_create_groups() somewhere ? I think that should be in
scsi_sysfs_device_initialize() but I am not 100% sure.



-- 
Damien Le Moal
Western Digital Research

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Problem with scsi device sysfs attributes
  2021-11-11  3:31 Problem with scsi device sysfs attributes Damien Le Moal
@ 2021-11-11  5:27 ` Damien Le Moal
  2021-11-11  8:46   ` Damien Le Moal
  0 siblings, 1 reply; 3+ messages in thread
From: Damien Le Moal @ 2021-11-11  5:27 UTC (permalink / raw)
  To: Bart Van Assche, linux-scsi @ vger . kernel . org,
	Martin K . Petersen, linux-ide

On 11/11/21 12:31, Damien Le Moal wrote:
> Bart,
> 
> Your patch 92c4b58b15c5 ("scsi: core: Register sysfs attributes earlier")
> modified the scsi device sysfs attributes initialization to use the scsi
> template shost_groups and sdev_groups for adding attributes using groups instead
> of arrays of attrs. However, this patch completely removed the
> sysfs_create_groups() call to actually create the attributes listed in the groups.
> 
> As a result, I see many missing sysfs device attributes for at least ahci (e.g.
> ncq_prio_enavle, ncq_prio_supported), but I suspect other device types may have
> similar problems.
> 
> I do not see where the attribute groups in the arrray sdev->gendev_attr_groups
> are registered with sysfs. In fact, it looks like sdev->gendev_attr_groups is
> referenced only in scsi_sysfs.c but only for initializing it. It is never used
> to actually register the attr groups... Am I missing something ?
> 
> This is at least breaking NCQ priority support right now. Did your patch
> 92c4b58b15c5 remove too much code ? Shouldn't we have a call to
> sysfs_create_groups() somewhere ? I think that should be in
> scsi_sysfs_device_initialize() but I am not 100% sure.

Adding this:

diff --git a/drivers/scsi/scsi_sysfs.c b/drivers/scsi/scsi_sysfs.c
index d3d362289ecc..a1a30af96e17 100644
--- a/drivers/scsi/scsi_sysfs.c
+++ b/drivers/scsi/scsi_sysfs.c
@@ -1339,6 +1339,8 @@ int scsi_sysfs_add_sdev(struct scsi_device *sdev)
 {
        int error;
        struct scsi_target *starget = sdev->sdev_target;
+       struct Scsi_Host *shost = sdev->host;
+       struct scsi_host_template *hostt = shost->hostt;

        error = scsi_target_add(starget);
        if (error)
@@ -1365,6 +1367,17 @@ int scsi_sysfs_add_sdev(struct scsi_device *sdev)
                return error;
        }

+       if (hostt->sdev_groups) {
+               error = sysfs_create_groups(&sdev->sdev_gendev.kobj,
+                                           hostt->sdev_groups);
+               if (error) {
+                       sdev_printk(KERN_INFO, sdev,
+                                   "failed to create device attributes:
%d\n",
+                                   error);
+                       return error;
+               }
+       }
+
        device_enable_async_suspend(&sdev->sdev_dev);
        error = device_add(&sdev->sdev_dev);
        if (error) {

I can see the AHCI NCQ attributes are visible under
/sysfs/block/sdX/device/.

So it looks like the LLD attribute groups added to
sdev->gendev_attr_groups by scsi_sysfs_device_initialize() using
hostt->sdev_groups are never registered with sysfs, but the default
common scsi attributes defined by scsi_sdev_attr_group are registered...
This is very weird.

I do not understand why. I cannot find where sdev->gendev_attr_groups is
used to create the attributes in sysfs...



-- 
Damien Le Moal
Western Digital Research

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: Problem with scsi device sysfs attributes
  2021-11-11  5:27 ` Damien Le Moal
@ 2021-11-11  8:46   ` Damien Le Moal
  0 siblings, 0 replies; 3+ messages in thread
From: Damien Le Moal @ 2021-11-11  8:46 UTC (permalink / raw)
  To: Bart Van Assche, linux-scsi @ vger . kernel . org,
	Martin K . Petersen, linux-ide

On 11/11/21 14:27, Damien Le Moal wrote:
> On 11/11/21 12:31, Damien Le Moal wrote:
>> Bart,
>>
>> Your patch 92c4b58b15c5 ("scsi: core: Register sysfs attributes earlier")
>> modified the scsi device sysfs attributes initialization to use the scsi
>> template shost_groups and sdev_groups for adding attributes using groups instead
>> of arrays of attrs. However, this patch completely removed the
>> sysfs_create_groups() call to actually create the attributes listed in the groups.
>>
>> As a result, I see many missing sysfs device attributes for at least ahci (e.g.
>> ncq_prio_enavle, ncq_prio_supported), but I suspect other device types may have
>> similar problems.
>>
>> I do not see where the attribute groups in the arrray sdev->gendev_attr_groups
>> are registered with sysfs. In fact, it looks like sdev->gendev_attr_groups is
>> referenced only in scsi_sysfs.c but only for initializing it. It is never used
>> to actually register the attr groups... Am I missing something ?
>>
>> This is at least breaking NCQ priority support right now. Did your patch
>> 92c4b58b15c5 remove too much code ? Shouldn't we have a call to
>> sysfs_create_groups() somewhere ? I think that should be in
>> scsi_sysfs_device_initialize() but I am not 100% sure.
> 
> Adding this:
> 
> diff --git a/drivers/scsi/scsi_sysfs.c b/drivers/scsi/scsi_sysfs.c
> index d3d362289ecc..a1a30af96e17 100644
> --- a/drivers/scsi/scsi_sysfs.c
> +++ b/drivers/scsi/scsi_sysfs.c
> @@ -1339,6 +1339,8 @@ int scsi_sysfs_add_sdev(struct scsi_device *sdev)
>  {
>         int error;
>         struct scsi_target *starget = sdev->sdev_target;
> +       struct Scsi_Host *shost = sdev->host;
> +       struct scsi_host_template *hostt = shost->hostt;
> 
>         error = scsi_target_add(starget);
>         if (error)
> @@ -1365,6 +1367,17 @@ int scsi_sysfs_add_sdev(struct scsi_device *sdev)
>                 return error;
>         }
> 
> +       if (hostt->sdev_groups) {
> +               error = sysfs_create_groups(&sdev->sdev_gendev.kobj,
> +                                           hostt->sdev_groups);
> +               if (error) {
> +                       sdev_printk(KERN_INFO, sdev,
> +                                   "failed to create device attributes:
> %d\n",
> +                                   error);
> +                       return error;
> +               }
> +       }
> +
>         device_enable_async_suspend(&sdev->sdev_dev);
>         error = device_add(&sdev->sdev_dev);
>         if (error) {
> 
> I can see the AHCI NCQ attributes are visible under
> /sysfs/block/sdX/device/.
> 
> So it looks like the LLD attribute groups added to
> sdev->gendev_attr_groups by scsi_sysfs_device_initialize() using
> hostt->sdev_groups are never registered with sysfs, but the default
> common scsi attributes defined by scsi_sdev_attr_group are registered...
> This is very weird.
> 
> I do not understand why. I cannot find where sdev->gendev_attr_groups is
> used to create the attributes in sysfs...

I figured it out: scsi_sdev_attr_groups is set in scsi_dev_type (struct
device_type) and so the attributes defined in this group are created in
sysfs when the scis device sdev_gendev is added. However, the additional
attribute groups in sdev->gendev_attr_groups added by the LLD are never
processed since scsi_dev_type->groups is scsi_sdev_attr_groups and not
sdev->gendev_attr_groups.

I sent a patch. Please let me know what you think.


-- 
Damien Le Moal
Western Digital Research

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2021-11-11  8:46 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-11-11  3:31 Problem with scsi device sysfs attributes Damien Le Moal
2021-11-11  5:27 ` Damien Le Moal
2021-11-11  8:46   ` Damien Le Moal

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).