linux-ide.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Hannes Reinecke <hare@suse.de>
To: Damien LeMoal <damien.lemoal@wdc.com>
Cc: linux-ide@vger.kernel.org, Hannes Reinecke <hare@suse.de>
Subject: [PATCH 2/2] libata: CONFIG_ATA_SYSFS_COMPAT
Date: Fri, 25 Mar 2022 13:56:24 +0100	[thread overview]
Message-ID: <20220325125624.99929-3-hare@suse.de> (raw)
In-Reply-To: <20220325125624.99929-1-hare@suse.de>

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(+)

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);
-- 
2.29.2


  parent reply	other threads:[~2022-03-25 12:56 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-03-25 12:56 [PATCHv4 0/2] libata: sysfs naming Hannes Reinecke
2022-03-25 12:56 ` [PATCH 1/2] libata: rework " Hannes Reinecke
2022-03-26 18:08   ` [RFC PATCH] libata: ata_bus_type can be static kernel test robot
2022-03-26 18:12   ` [PATCH 1/2] libata: rework sysfs naming kernel test robot
2022-03-25 12:56 ` Hannes Reinecke [this message]
2022-03-25 16:22   ` [PATCH 2/2] libata: CONFIG_ATA_SYSFS_COMPAT Sergey Shtylyov
2022-03-25 16:29     ` Hannes Reinecke
  -- strict thread matches above, loose matches on Subject: below --
2022-03-24 12:32 [PATCHv3 0/2] libata: sysfs naming Hannes Reinecke
2022-03-24 12:32 ` [PATCH 2/2] libata: CONFIG_ATA_SYSFS_COMPAT Hannes Reinecke
2022-03-25  3:01   ` Damien Le Moal
2022-03-25  7:12     ` Hannes Reinecke
2022-03-25  7:16       ` Damien Le Moal

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220325125624.99929-3-hare@suse.de \
    --to=hare@suse.de \
    --cc=damien.lemoal@wdc.com \
    --cc=linux-ide@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).