From: Tony Asleson <tasleson@redhat.com>
To: linux-scsi@vger.kernel.org, linux-block@vger.kernel.org,
linux-fsdevel@vger.kernel.org
Subject: [RFC 5/9] block: Add support functions for persistent durable name
Date: Mon, 23 Dec 2019 16:55:54 -0600 [thread overview]
Message-ID: <20191223225558.19242-6-tasleson@redhat.com> (raw)
In-Reply-To: <20191223225558.19242-1-tasleson@redhat.com>
Add functions to retrieve and build durable name string into supplied
buffer for functions that log using struct device and struct scsi_device.
Signed-off-by: Tony Asleson <tasleson@redhat.com>
---
drivers/base/core.c | 24 ++++++++++++++++++++++++
drivers/scsi/scsi_lib.c | 20 ++++++++++++++++++++
drivers/scsi/scsi_sysfs.c | 1 +
include/linux/device.h | 2 ++
include/scsi/scsi_device.h | 3 +++
5 files changed, 50 insertions(+)
diff --git a/drivers/base/core.c b/drivers/base/core.c
index 7bd9cd366d41..93cc1c45e9d3 100644
--- a/drivers/base/core.c
+++ b/drivers/base/core.c
@@ -2009,6 +2009,30 @@ int dev_set_name(struct device *dev, const char *fmt, ...)
}
EXPORT_SYMBOL_GPL(dev_set_name);
+/**
+ * dev_durable_name - Write "DURABLE_NAME"=<durable name> in buffer
+ * @dev: device
+ * @buffer: character buffer to write results
+ * @len: length of buffer
+ * @return Number of bytes written to buffer
+ */
+int dev_durable_name(const struct device *dev, char *buffer, size_t len)
+{
+ int tmp, dlen;
+
+ if (dev->type && dev->type->durable_name) {
+ tmp = snprintf(buffer, len, "DURABLE_NAME=");
+ if (tmp < len) {
+ dlen = dev->type->durable_name(dev, buffer + tmp,
+ len - tmp);
+ if (dlen > 0 && ((dlen + tmp) < len))
+ return dlen + tmp;
+ }
+ }
+ return 0;
+}
+EXPORT_SYMBOL_GPL(dev_durable_name);
+
/**
* device_to_dev_kobj - select a /sys/dev/ directory for the device
* @dev: device
diff --git a/drivers/scsi/scsi_lib.c b/drivers/scsi/scsi_lib.c
index 91c007d26c1e..f22e59253d9d 100644
--- a/drivers/scsi/scsi_lib.c
+++ b/drivers/scsi/scsi_lib.c
@@ -3120,3 +3120,23 @@ int scsi_vpd_tpg_id(struct scsi_device *sdev, int *rel_id)
return group_id;
}
EXPORT_SYMBOL(scsi_vpd_tpg_id);
+
+int dev_to_scsi_durable_name(const struct device *dev, char *buf, size_t len)
+{
+ return scsi_durable_name(to_scsi_device(dev), buf, len);
+}
+EXPORT_SYMBOL(dev_to_scsi_durable_name);
+
+int scsi_durable_name(struct scsi_device *sdev, char *buf, size_t len)
+{
+ int vpd_len = 0;
+
+ vpd_len = scsi_vpd_lun_id(sdev, buf, len);
+ if (vpd_len > 0 && vpd_len < len)
+ vpd_len = strim_dupe(buf) + 1;
+ else
+ vpd_len = 0;
+
+ return vpd_len;
+}
+EXPORT_SYMBOL(scsi_durable_name);
diff --git a/drivers/scsi/scsi_sysfs.c b/drivers/scsi/scsi_sysfs.c
index 6d7362e7367e..ee5b8197916f 100644
--- a/drivers/scsi/scsi_sysfs.c
+++ b/drivers/scsi/scsi_sysfs.c
@@ -1560,6 +1560,7 @@ static struct device_type scsi_dev_type = {
.name = "scsi_device",
.release = scsi_device_dev_release,
.groups = scsi_sdev_attr_groups,
+ .durable_name = dev_to_scsi_durable_name,
};
void scsi_sysfs_device_initialize(struct scsi_device *sdev)
diff --git a/include/linux/device.h b/include/linux/device.h
index dd4ac8db5f57..566f6be6ee0d 100644
--- a/include/linux/device.h
+++ b/include/linux/device.h
@@ -1350,6 +1350,8 @@ static inline const char *dev_name(const struct device *dev)
extern __printf(2, 3)
int dev_set_name(struct device *dev, const char *name, ...);
+int dev_durable_name(const struct device *d, char *buffer, size_t len);
+
#ifdef CONFIG_NUMA
static inline int dev_to_node(struct device *dev)
{
diff --git a/include/scsi/scsi_device.h b/include/scsi/scsi_device.h
index 202f4d6a4342..1cb35e10f54a 100644
--- a/include/scsi/scsi_device.h
+++ b/include/scsi/scsi_device.h
@@ -455,6 +455,9 @@ extern void sdev_disable_disk_events(struct scsi_device *sdev);
extern void sdev_enable_disk_events(struct scsi_device *sdev);
extern int scsi_vpd_lun_id(struct scsi_device *, char *, size_t);
extern int scsi_vpd_tpg_id(struct scsi_device *, int *);
+extern int dev_to_scsi_durable_name(const struct device *dev, char *buf,
+ size_t len);
+extern int scsi_durable_name(struct scsi_device *sdev, char *buf, size_t len);
#ifdef CONFIG_PM
extern int scsi_autopm_get_device(struct scsi_device *);
--
2.21.0
next prev parent reply other threads:[~2019-12-23 22:56 UTC|newest]
Thread overview: 30+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-12-23 22:55 [RFC 0/9] Add persistent durable identifier to storage log messages Tony Asleson
2019-12-23 22:55 ` [RFC 1/9] lib/string: Add function to trim duplicate WS Tony Asleson
2019-12-23 23:28 ` Matthew Wilcox
2020-01-02 22:52 ` Tony Asleson
2020-01-03 14:30 ` Tony Asleson
2019-12-23 22:55 ` [RFC 2/9] printk: Bring back printk_emit Tony Asleson
2019-12-23 22:55 ` [RFC 3/9] printk: Add printk_emit_ratelimited macro Tony Asleson
2019-12-23 22:55 ` [RFC 4/9] struct device_type: Add function callback durable_name Tony Asleson
2019-12-23 22:55 ` Tony Asleson [this message]
2019-12-23 22:55 ` [RFC 6/9] create_syslog_header: Add durable name Tony Asleson
2019-12-24 0:54 ` James Bottomley
2020-01-02 22:53 ` Tony Asleson
2019-12-23 22:55 ` [RFC 7/9] print_req_error: Add persistent " Tony Asleson
2019-12-23 22:55 ` [RFC 8/9] ata_dev_printk: Add durable name to output Tony Asleson
2019-12-24 0:56 ` James Bottomley
2019-12-23 22:55 ` [RFC 9/9] __xfs_printk: " Tony Asleson
2020-01-04 2:56 ` Dave Chinner
2020-01-06 2:45 ` Tony Asleson
2020-01-06 22:02 ` Dave Chinner
2020-01-07 0:19 ` Sweet Tea Dorminy
2020-01-07 1:23 ` Dave Chinner
2020-01-07 17:01 ` Tony Asleson
2020-01-08 2:10 ` Dave Chinner
2020-01-08 16:53 ` Tony Asleson
2020-01-09 1:41 ` Alasdair G Kergon
2020-01-09 23:22 ` Dave Chinner
2020-01-10 1:28 ` Alasdair G Kergon
2020-01-10 16:13 ` Tony Asleson
2019-12-24 0:50 ` [RFC 0/9] Add persistent durable identifier to storage log messages James Bottomley
2020-01-02 22:52 ` Tony Asleson
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=20191223225558.19242-6-tasleson@redhat.com \
--to=tasleson@redhat.com \
--cc=linux-block@vger.kernel.org \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-scsi@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).