On 3/24/22 21:32, Hannes Reinecke wrote:
Add a config option 'ATA_SYSFS_COMPAT' to create a compability
s/compability/compatibility
'ata' symlink in the PCI device sysfs directory.
I am not yet convinced if this new config option is really necessary...
We could create the symlink unconditionally, no ?
In any case, I would like to at least reduce the number of #ifdef. So
what about something like this on top of your patch:
diff --git a/drivers/ata/libata-transport.c b/drivers/ata/libata-transport.c
index a66c3480bdcf..fa249638bfb6 100644
--- a/drivers/ata/libata-transport.c
+++ b/drivers/ata/libata-transport.c
@@ -251,6 +251,40 @@ 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
@@ -260,13 +294,8 @@ static int ata_tport_match(struct
attribute_container *cont,
void ata_tport_delete(struct ata_port *ap)
{
struct device *dev = &ap->tdev;
-#ifdef CONFIG_ATA_SYSFS_COMPAT
- struct device *parent = dev->parent;
- char compat_name[64];
- sprintf(compat_name, "ata%d", ap->print_id);
- sysfs_remove_link(&parent->kobj, compat_name);
-#endif
+ ata_tport_compat_link_delete(ap);
ata_tlink_delete(&ap->link);
transport_remove_device(dev);
@@ -290,9 +319,6 @@ int ata_tport_add(struct device *parent,
{
int error;
struct device *dev = &ap->tdev;
-#ifdef CONFIG_ATA_SYSFS_COMPAT
- char compat_name[64];
-#endif
device_initialize(dev);
dev->type = &ata_port_type;
@@ -323,18 +349,14 @@ int ata_tport_add(struct device *parent,
goto tport_link_err;
}
-#ifdef CONFIG_ATA_SYSFS_COMPAT
- sprintf(compat_name, "ata%d", ap->print_id);
- error = sysfs_create_link(&parent->kobj, &dev->kobj, compat_name);
+ error = ata_tport_compat_link_add(ap);
if (error)
goto compat_link_err;
-#endif
+
return 0;
-#ifdef CONFIG_ATA_SYSFS_COMPAT
compat_link_err:
ata_tlink_delete(&ap->link);
-#endif
tport_link_err:
transport_remove_device(dev);
device_del(dev);
Signed-off-by: Hannes Reinecke <hare@xxxxxxx>
---
drivers/ata/Kconfig | 10 ++++++++++
drivers/ata/libata-transport.c | 20 ++++++++++++++++++++
2 files changed, 30 insertions(+)
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 555fe6e2293d..a66c3480bdcf 100644
--- a/drivers/ata/libata-transport.c
+++ b/drivers/ata/libata-transport.c
@@ -260,7 +260,13 @@ static int ata_tport_match(struct attribute_container *cont,
void ata_tport_delete(struct ata_port *ap)
{
struct device *dev = &ap->tdev;
+#ifdef CONFIG_ATA_SYSFS_COMPAT
+ struct device *parent = dev->parent;
+ char compat_name[64];
+ sprintf(compat_name, "ata%d", ap->print_id);
+ sysfs_remove_link(&parent->kobj, compat_name);
+#endif
ata_tlink_delete(&ap->link);
transport_remove_device(dev);
@@ -284,6 +290,9 @@ int ata_tport_add(struct device *parent,
{
int error;
struct device *dev = &ap->tdev;
+#ifdef CONFIG_ATA_SYSFS_COMPAT
+ char compat_name[64];
+#endif
device_initialize(dev);
dev->type = &ata_port_type;
@@ -313,8 +322,19 @@ int ata_tport_add(struct device *parent,
if (error) {
goto tport_link_err;
}
+
+#ifdef CONFIG_ATA_SYSFS_COMPAT
+ sprintf(compat_name, "ata%d", ap->print_id);
+ error = sysfs_create_link(&parent->kobj, &dev->kobj, compat_name);
+ if (error)
+ goto compat_link_err;
+#endif
return 0;
+#ifdef CONFIG_ATA_SYSFS_COMPAT
+ compat_link_err:
+ ata_tlink_delete(&ap->link);
+#endif
tport_link_err:
transport_remove_device(dev);
device_del(dev);
--
Damien Le Moal
Western Digital Research