Message ID | 20220325125624.99929-3-hare@suse.de |
---|---|
State | New |
Headers | show |
Series | libata: sysfs naming | expand |
Hello! On 3/25/22 3:56 PM, Hannes Reinecke wrote: > Add a config option 'ATA_SYSFS_COMPAT' to create a compatibility > 'ata' symlink in the PCI device sysfs directory. > > Signed-off-by: Hannes Reinecke <hare@suse.de> [...] > diff --git a/drivers/ata/libata-transport.c b/drivers/ata/libata-transport.c > index e5ed5046b299..29dec89ccc2d 100644 > --- a/drivers/ata/libata-transport.c > +++ b/drivers/ata/libata-transport.c > @@ -251,6 +251,39 @@ static int ata_tport_match(struct attribute_container *cont, > return &ata_scsi_transport_template->host_attrs.ac == cont; > } > > +#ifdef CONFIG_ATA_SYSFS_COMPAT > +static int ata_tport_compat_link_add(struct ata_port *ap) > +{ > + struct device *dev = &ap->tdev; Indent with a tab, please. > + struct device *parent = dev->parent; > + char compat_name[64]; Same here. The buffer seems oversized too... > + > + sprintf(compat_name, "ata%d", ap->print_id); snprintf(), perhaps? > + > + return sysfs_create_link(&parent->kobj, &dev->kobj, compat_name); > +} > + > +static void ata_tport_compat_link_delete(struct ata_port *ap) > +{ > + struct device *dev = &ap->tdev; > + struct device *parent = dev->parent; > + char compat_name[64]; > + > + sprintf(compat_name, "ata%d", ap->print_id); snprintf()? [...] MBR, Sergey
On 3/25/22 17:22, Sergey Shtylyov wrote: > Hello! > > On 3/25/22 3:56 PM, Hannes Reinecke wrote: > >> Add a config option 'ATA_SYSFS_COMPAT' to create a compatibility >> 'ata' symlink in the PCI device sysfs directory. >> >> Signed-off-by: Hannes Reinecke <hare@suse.de> > [...] >> diff --git a/drivers/ata/libata-transport.c b/drivers/ata/libata-transport.c >> index e5ed5046b299..29dec89ccc2d 100644 >> --- a/drivers/ata/libata-transport.c >> +++ b/drivers/ata/libata-transport.c >> @@ -251,6 +251,39 @@ static int ata_tport_match(struct attribute_container *cont, >> return &ata_scsi_transport_template->host_attrs.ac == cont; >> } >> >> +#ifdef CONFIG_ATA_SYSFS_COMPAT >> +static int ata_tport_compat_link_add(struct ata_port *ap) >> +{ >> + struct device *dev = &ap->tdev; > > Indent with a tab, please. > Of course. >> + struct device *parent = dev->parent; >> + char compat_name[64]; > > Same here. The buffer seems oversized too... > Hard to tell how many ATA devices there are in the system. More than hundred? But yeah, I can reduce it. >> + >> + sprintf(compat_name, "ata%d", ap->print_id); > > snprintf(), perhaps? > OK. Cheers, Hannes
diff --git a/drivers/ata/Kconfig b/drivers/ata/Kconfig index e5641e6c52ee..f27b12ba2ce7 100644 --- a/drivers/ata/Kconfig +++ b/drivers/ata/Kconfig @@ -51,6 +51,16 @@ config ATA_VERBOSE_ERROR If unsure, say Y. +config ATA_SYSFS_COMPAT + bool "Keep original sysfs layout" + default y + help + This option retains the original sysfs layout by adding an + additional ata_port object with the name of 'ataX' in + to the ATA objects like 'ata_port', 'ata_link', and 'ata_device'. + + If unsure, say Y. + config ATA_FORCE bool "\"libata.force=\" kernel parameter support" if EXPERT default y diff --git a/drivers/ata/libata-transport.c b/drivers/ata/libata-transport.c index e5ed5046b299..29dec89ccc2d 100644 --- a/drivers/ata/libata-transport.c +++ b/drivers/ata/libata-transport.c @@ -251,6 +251,39 @@ static int ata_tport_match(struct attribute_container *cont, return &ata_scsi_transport_template->host_attrs.ac == cont; } +#ifdef CONFIG_ATA_SYSFS_COMPAT +static int ata_tport_compat_link_add(struct ata_port *ap) +{ + struct device *dev = &ap->tdev; + struct device *parent = dev->parent; + char compat_name[64]; + + sprintf(compat_name, "ata%d", ap->print_id); + + return sysfs_create_link(&parent->kobj, &dev->kobj, compat_name); +} + +static void ata_tport_compat_link_delete(struct ata_port *ap) +{ + struct device *dev = &ap->tdev; + struct device *parent = dev->parent; + char compat_name[64]; + + sprintf(compat_name, "ata%d", ap->print_id); + sysfs_remove_link(&parent->kobj, compat_name); +} + +#else + +static inline int ata_tport_compat_link_add(struct ata_port *ap) +{ + return 0; +} + +static inline void ata_tport_compat_link_delete(struct ata_port *ap) {} + +#endif + /** * ata_tport_delete -- remove ATA PORT * @ap: ATA PORT to remove @@ -261,6 +294,7 @@ void ata_tport_delete(struct ata_port *ap) { struct device *dev = &ap->tdev; + ata_tport_compat_link_delete(ap); ata_tlink_delete(&ap->link); transport_remove_device(dev); @@ -313,8 +347,15 @@ int ata_tport_add(struct device *parent, if (error) { goto tport_link_err; } + + error = ata_tport_compat_link_add(ap); + if (error) + goto compat_link_err; + return 0; + compat_link_err: + ata_tlink_delete(&ap->link); tport_link_err: transport_remove_device(dev); device_del(dev);
Add a config option 'ATA_SYSFS_COMPAT' to create a compatibility 'ata' symlink in the PCI device sysfs directory. Signed-off-by: Hannes Reinecke <hare@suse.de> --- drivers/ata/Kconfig | 10 +++++++++ drivers/ata/libata-transport.c | 41 ++++++++++++++++++++++++++++++++++ 2 files changed, 51 insertions(+)