Add persistent durable identifier to storage log messages
Subsystems (6)
v2 cover Add persistent durable identifier to storage log messages
Today users have no easy way to correlate kernel log messages for storage devices across reboots, device dynamic add/remove, or when the device is physically or logically moved from from system to system. This is due to the existing log IDs which identify how the device is attached and not a unique ID of what is attached. Additionally, even when the attachment hasn't changed, it's not always obvious which messages belong to the device as the different areas in the storage stack use different identifiers, eg. (sda, sata1.00, sd 0:0:0:0).
This change addresses this by adding a unique ID to each log message. It couples the existing structured key/value logging capability and VPD 0x83 device identification.
An example of logs filtered for a specific device utilizing this patch series.
$ journalctl -b _KERNEL_DURABLE_NAME="`cat /sys/block/sdb/device/wwid`"
| cut -c 25- | fmt -t
9-08-22 13:21:35 CDT, end at Wed 2020-05-13 15:40:26 CDT. --
l: scsi 1:0:0:0: Attached scsi generic sg1 type 0
l: sd 1:0:0:0: [sdb] 209715200 512-byte logical blocks: (107 GB/100 GiB)
l: sd 1:0:0:0: [sdb] Write Protect is off
l: sd 1:0:0:0: [sdb] Mode Sense: 00 3a 00 00
l: sd 1:0:0:0: [sdb] Write cache: enabled, read cache: enabled, doesn't
support DPO or FUA
l: sd 1:0:0:0: [sdb] Attached SCSI disk
l: sd 1:0:0:0: ata2.00: exception Emask 0x0 SAct 0x800000 SErr 0x800000
action 0x6 frozen
l: sd 1:0:0:0: ata2.00: failed command: READ FPDMA QUEUED
l: sd 1:0:0:0: ata2.00: cmd 60/20:b8:10:27:00/00:00:00:00:00/40 tag 23
ncq dma 16384 in res 40/00:00:00:4f:c2/00:00:00:00:00/00
Emask 0x4 (timeout)
l: sd 1:0:0:0: ata2.00: status: { DRDY }
l: sd 1:0:0:0: ata2.00: configured for UDMA/100
l: sd 1:0:0:0: [sdb] tag#23 FAILED Result: hostbyte=DID_OK
driverbyte=DRIVER_SENSE cmd_age=30s
l: sd 1:0:0:0: [sdb] tag#23 Sense Key : Illegal Request [current]
l: sd 1:0:0:0: [sdb] tag#23 Add. Sense: Unaligned write command
l: sd 1:0:0:0: [sdb] tag#23 CDB: Read(10) 28 00 00 00 27 10 00 00 20 00
l: block sdb: blk_update_request: I/O error, dev sdb, sector 10000 op
0x0:(READ) flags 0x80700 phys_seg 4 prio class 0
l: sd 1:0:0:0: ata2.00: exception Emask 0x0 SAct 0x2 SErr 0x2 action
0x6 frozen
l: sd 1:0:0:0: ata2.00: failed command: READ FPDMA QUEUED
l: sd 1:0:0:0: ata2.00: cmd 60/08:08:10:27:00/00:00:00:00:00/40 tag 1 ncq
dma 4096 in res 40/00:ff:00:00:00/00:00:00:00:00/00 Emask 0x4
(timeout)
l: sd 1:0:0:0: ata2.00: status: { DRDY }
l: sd 1:0:0:0: ata2.00: configured for UDMA/100
l: sd 1:0:0:0: ata2.00: exception Emask 0x0 SAct 0x800000 SErr 0x800000
action 0x6 frozen
l: sd 1:0:0:0: ata2.00: failed command: READ FPDMA QUEUED
l: sd 1:0:0:0: ata2.00: cmd 60/08:b8:10:27:00/00:00:00:00:00/40 tag 23 ncq
dma 4096 in res 40/00:00:00:4f:c2/00:00:00:00:00/00 Emask 0x4
(timeout)
l: sd 1:0:0:0: ata2.00: status: { DRDY }
l: sd 1:0:0:0: ata2.00: configured for UDMA/100
l: sd 1:0:0:0: ata2.00: NCQ disabled due to excessive errors
l: sd 1:0:0:0: ata2.00: exception Emask 0x0 SAct 0x4000 SErr 0x4000
action 0x6 frozen
l: sd 1:0:0:0: ata2.00: failed command: READ FPDMA QUEUED
l: sd 1:0:0:0: ata2.00: cmd 60/08:70:10:27:00/00:00:00:00:00/40 tag 14 ncq
dma 4096 in res 40/00:00:00:00:00/00:00:00:00:00/00 Emask 0x4
(timeout)
l: sd 1:0:0:0: ata2.00: status: { DRDY }
l: sd 1:0:0:0: ata2.00: configured for UDMA/100
l: sd 1:0:0:0: ata2.00: device reported invalid CHS sector 0This change is incomplete. With the plethora of different logging techniques utilized in the kernel it will take some coordinated effort and additional changes. I tried a few different approaches, to cover as much as I could without resorting to changing every print statement in all the storage layers, but maybe there is a better, more elegant approach?
I believe having this functionality is very useful and important for system configurations of all sizes. I mentioned this change briefly in:
https://lore.kernel.org/lkml/[email protected]/
Questions
1. Where is the best place to put the durable_name callback function?
2. What is best "KEY" value?
v2:
- Incorporated changes suggested by James Bottomley
- Removed string function which removed leading/trailing/duplicate adjacent spaces from generated id, value matches /sys/block/<device>/device/wwid
- Remove xfs patch, limiting changes to lower block layers
- Moved callback from struct device_type to struct device. Struct device_type is typically static const and with a number of different areas using shared implementation of genhd unable to modify for each of the different areas.
Tony Asleson (7):
struct device: Add function callback durable_name
create_syslog_header: Add durable name
print_req_error: Use dev_printk
buffer_io_error: Use dev_printk
ata_dev_printk: Use dev_printk
scsi: Add durable_name for dev_printk
nvme: Add durable name for dev_printk
block/blk-core.c | 5 ++++- drivers/ata/libata-core.c | 10 +++++++--- drivers/base/core.c | 29 +++++++++++++++++++++++++++++ drivers/nvme/host/core.c | 18 ++++++++++++++++++ drivers/scsi/scsi_lib.c | 14 ++++++++++++++ drivers/scsi/scsi_sysfs.c | 23 +++++++++++++++++++++++ drivers/scsi/sd.c | 2 ++ fs/buffer.c | 10 ++++++++-- include/linux/device.h | 4 ++++ include/scsi/scsi_device.h | 3 +++ 10 files changed, 112 insertions(+), 6 deletions(-)
base-commit: 7111951b8d4973bda27ff663f2cf18b663d15b48
Signature · 1 line
2.25.4
RFC PATCH v2 1/7 struct device: Add function callback durable_name
Function callback and function to be used to write a persistent durable name to the supplied character buffer. This will be used to add structured key-value data to log messages for hardware related errors which allows end users to correlate message and specific hardware.
--- drivers/base/core.c | 24 ++++++++++++++++++++++++ include/linux/device.h | 4 ++++ 2 files changed, 28 insertions(+)
drivers/base/core.c +24 -0
@@ -2281,6 +2281,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 && dev->durable_name) { + tmp =snprintf (buffer, len,"DURABLE_NAME=" ); +if (tmp < len) { + dlen = dev->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
include/linux/device.h +4 -0
@@ -616,6 +616,8 @@ struct device {struct iommu_fwspec *iommu_fwspec;struct iommu_param *iommu_param; +int (*durable_name)(const struct device *dev,char *buff,size_t len); + bool offline_disabled:1; bool offline:1; bool of_node_reused:1;
@@ -657,6 +659,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) {
Signature · 1 line
2.25.4
RFC PATCH v2 2/7 create_syslog_header: Add durable name
In reply to Tony AslesonThis gets us a persistent durable name for code that logs messages in the block layer that have the appropriate callbacks setup for durable name.
--- drivers/base/core.c | 5 +++++ 1 file changed, 5 insertions(+)
drivers/base/core.c +5 -0
@@ -3577,6 +3577,7 @@ create_syslog_header(const struct device *dev, char *hdr, size_t hdrlen) {const char *subsys;size_t pos =0 ; +int dlen;if (dev->class) subsys = dev->class->name;
@@ -3619,6 +3620,10 @@ create_syslog_header(const struct device *dev, char *hdr, size_t hdrlen) "DEVICE=+%s:%s", subsys, dev_name(dev)); } + dlen =dev_durable_name (dev, hdr + (pos +1 ), hdrlen - (pos +1 )); +if (dlen) + pos += dlen +1 ; +if (pos >= hdrlen) goto overflow;
Signature · 1 line
2.25.4
RFC PATCH v2 3/7 print_req_error: Use dev_printk
In reply to Tony Asleson--- block/blk-core.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
block/blk-core.c +4 -1
@@ -213,12 +213,15 @@ EXPORT_SYMBOL_GPL(blk_status_to_errno);static void print_req_error (struct request *req,blk_status_t status,const char *caller) { +struct device *dev;int idx = (__force int )status;if (WARN_ON_ONCE (idx >=ARRAY_SIZE (blk_errors)))return ; - printk_ratelimited(KERN_ERR + dev = (req->rq_disk) ?disk_to_dev (req->rq_disk) :NULL ; + + dev_err_ratelimited(dev, "%s: %s error, dev %s, sector %llu op 0x%x:(%s) flags 0x%x " "phys_seg %u prio class %u\n", caller, blk_errors[idx].name,
Signature · 1 line
2.25.4
RFC PATCH v2 4/7 buffer_io_error: Use dev_printk
In reply to Tony Asleson--- fs/buffer.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-)
fs/buffer.c +8 -2
@@ -133,10 +133,16 @@ __clear_page_buffers(struct page *page)static void buffer_io_error (struct buffer_head *bh,char *msg) { -if (!test_bit (BH_Quiet, &bh->b_state)) -printk_ratelimited (KERN_ERR +if (!test_bit (BH_Quiet, &bh->b_state)) { +struct device *gendev; + + gendev = (bh->b_bdev->bd_disk) ? +disk_to_dev (bh->b_bdev->bd_disk) :NULL ; + +dev_err_ratelimited (gendev,"Buffer I/O error on dev %pg, logical block %llu%s\n" , bh->b_bdev, (unsigned long long )bh->b_blocknr, msg); + } }/*
Signature · 1 line
2.25.4
RFC PATCH v2 5/7 ata_dev_printk: Use dev_printk
In reply to Tony AslesonUtilize the dev_printk function which will add structured data to the log message.
--- drivers/ata/libata-core.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-)
drivers/ata/libata-core.c +7 -3
@@ -7301,6 +7301,7 @@ EXPORT_SYMBOL(ata_link_printk);void ata_dev_printk (const struct ata_device *dev,const char *level,const char *fmt, ...) { +const struct device *gendev;struct va_format vaf;va_list args;
@@ -7309,9 +7310,12 @@ void ata_dev_printk(const struct ata_device *dev, const char *level, vaf.fmt = fmt; vaf.va = &args; -printk ("%sata%u.%02u: %pV" , - level, dev->link->ap->print_id, dev->link->pmp + dev->devno, - &vaf); + gendev = (dev->sdev) ? &dev->sdev->sdev_gendev : &dev->tdev; + +dev_printk (level, gendev,"ata%u.%02u: %pV" , + dev->link->ap->print_id, + dev->link->pmp + dev->devno, + &vaf);va_end (args); }
Signature · 1 line
2.25.4
Re: [RFC PATCH v2 5/7] ata_dev_printk: Use dev_printk
Quoted 27 lines · Tony Asleson
Utilize the
dev_printkfunction which will add structured data to the log message.Signed-off-by Tony Asleson <[email protected]>--- drivers/ata/libata-core.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-)drivers/ata/libata-core.c +1
-2@@ -7301,6 +7301,7 @@ EXPORT_SYMBOL(ata_link_printk);void ata_dev_printk (const struct ata_device *dev,const char *level,const char *fmt, ...) { +const struct device *gendev;struct va_format vaf;va_list args;@@ -7309,9 +7310,12 @@ void ata_dev_printk(const struct ata_device *dev, const char *level, vaf.fmt = fmt; vaf.va = &args; - printk("%sata%u.%02u: %pV", - level, dev->link->ap->print_id, dev->link->pmp + dev->devno,
drivers/ata/libata-core.c void ata_dev_printk(const struct ata_device *dev, const char *level, · line 7321
Quoted 10 lines
drivers/ata/libata-core.c +6
-1- &vaf); + gendev = (dev->sdev) ? &dev->sdev->sdev_gendev : &dev->tdev; + +dev_printk (level, gendev,"ata%u.%02u: %pV" , + dev->link->ap->print_id, + dev->link->pmp + dev->devno, + &vaf);va_end (args); }
That is wrong.dev_printk() will already prefix the logging message with the device name, so we'll end up having the name printed twice.
Cheers,
Hannes
Signature · 4 lines
Dr. Hannes Reinecke Teamlead Storage & Networking [email protected] +49 911 74053 688 SUSE Software Solutions GmbH, Maxfeldstr. 5, 90409 Nürnberg HRB 36809 (AG Nürnberg), Geschäftsführer: Felix Imendörffer
Re: [RFC PATCH v2 5/7] ata_dev_printk: Use dev_printk
Quoted 31 lines · Hannes Reinecke
Quoted 30 lines · Tony Asleson
Utilize the
dev_printkfunction which will add structured data to the log message.Signed-off-by Tony Asleson <[email protected]>---
drivers/ata/libata-core.c| 10 +++++++---1 file changed, 7 insertions(+), 3 deletions(-)drivers/ata/libata-core.c +1
-0@@ -7301,6 +7301,7 @@ EXPORT_SYMBOL(ata_link_printk); void ata_dev_printk(const struct ata_device *dev, const char *level, const char *fmt, ...) { + const struct device *gendev; struct va_format vaf; va_list args;@@ -7309,9 +7310,12 @@ void ata_dev_printk(const struct
ata_device*dev, const char *level,
vaf.fmt = fmt;
vaf.va = &args;
- printk("%sata%u.%02u: %pV",
- level,dev->link->ap->print_id,dev->link->pmp+dev->devno, - &vaf);
+ gendev = (dev->sdev) ?&dev->sdev->sdev_gendev:&dev->tdev; +
+ dev_printk(level, gendev, "ata%u.%02u: %pV",
+dev->link->ap->print_id,
Quoted 8 lines
Quoted 5 lines
+
dev->link->pmp+dev->devno,
+ &vaf);
va_end(args);
}That is wrong.
dev_printk()will already prefix the logging message with the device name, so we'll end up having the name printed twice.
It certainly could be. Early in boot when &dev->sdev->sdev_gendev == NULL and &dev->tdev is used we get
dev1.0: ata1.00: configured for UDMA/100
later when &dev->sdev->sdev_gendev != NULL we get
sd 1:0:0:0: [sdb] 209715200 512-byte logical blocks: (107 GB/100 GiB)
to clarify, your point is dev1.0 is redundant as ata1.00 exists in the message?
In the block layer print_req_error we get:
block sdb: blk_update_request: I/O error, dev sdb, sector 10000 op 0x0:(READ) flags 0x80700 phys_seg 4 prio class 0
Which seems a bit more redundant.
I've been trying to be careful to not change the human readable portion of the message, so not to disturb all the log scraping tools that exist mining errors. Maybe this is the wrong approach? In my original patch series I brought back printk_emit so that I could add the structured data without introducing changes in the message text output. James Bottomley suggested using dev_printk which certainly made things cleaner, but it does add the prefix.
Thanks,
Tony
Re: Re: [RFC PATCH v2 5/7] ata_dev_printk: Use dev_printk
Quoted 41 lines · Tony Asleson
Quoted 31 lines · Hannes Reinecke
Quoted 30 lines · Tony Asleson
Utilize the
dev_printkfunction which will add structured data to the log message.Signed-off-by Tony Asleson <[email protected]>---
drivers/ata/libata-core.c| 10 +++++++---1 file changed, 7 insertions(+), 3 deletions(-)drivers/ata/libata-core.c +1
-0@@ -7301,6 +7301,7 @@ EXPORT_SYMBOL(ata_link_printk); void ata_dev_printk(const struct ata_device *dev, const char *level, const char *fmt, ...) { + const struct device *gendev; struct va_format vaf; va_list args;@@ -7309,9 +7310,12 @@ void ata_dev_printk(const struct
ata_device*dev, const char *level,
vaf.fmt = fmt;
vaf.va = &args;
- printk("%sata%u.%02u: %pV",
- level,dev->link->ap->print_id,dev->link->pmp+dev->devno, - &vaf);
+ gendev = (dev->sdev) ?&dev->sdev->sdev_gendev:&dev->tdev; +
+ dev_printk(level, gendev, "ata%u.%02u: %pV",
+dev->link->ap->print_id,Quoted 8 lines
Quoted 5 lines
+
dev->link->pmp+dev->devno,
+ &vaf);
va_end(args);
}That is wrong.
dev_printk()will already prefix the logging message with the device name, so we'll end up having the name printed twice.
Quoted 8 lines
It certainly could be. Early in boot when
&dev->sdev->sdev_gendev== NULL and&dev->tdevis used we getdev1.0: ata1.00: configured for UDMA/100
later when
&dev->sdev->sdev_gendev!= NULL we getsd 1:0:0:0: [sdb] 209715200 512-byte logical blocks: (107 GB/100 GiB)
This one comes from the SCSI layer.
From libata we get i.e.:
sd 1:0:0:0: ata2.00: exception Emask 0x0 SAct 0x800000 SErr 0x800000 action 0x6 frozen
instead of
ata2.00: exception Emask 0x0 SAct 0x800000 SErr 0x800000 action 0x6 frozen
Quoted 8 lines
to clarify, your point is dev1.0 is redundant as ata1.00 exists in the message?
In the block layer
print_req_errorwe get:block sdb:
blk_update_request: I/O error, dev sdb, sector 10000 op 0x0:(READ) flags0x80700phys_seg4 prio class 0
I think it should be modified to not include dev any longer:
block sdb: blk_update_request: I/O error, sector 10000 op 0x0:(READ) flags 0x80700 phys_seg 4 prio class 0
but it is up to Jens to make a final decision on that.
Quoted 1 line
Which seems a bit more redundant.
Yes but it is a debug message visible only on error while for libata _all_ messages are now changed.
Best regards,
--
Bartlomiej Zolnierkiewicz
Samsung R&D Institute Poland
Samsung Electronics
Quoted 12 lines
I've been trying to be careful to not change the human readable portion of the message, so not to disturb all the log scraping tools that exist mining errors. Maybe this is the wrong approach? In my original patch series I brought back
printk_emitso that I could add the structured data without introducing changes in the message text output. James Bottomley suggested usingdev_printkwhich certainly made things cleaner, but it does add the prefix.Thanks,
Tony
RFC PATCH v2 6/7 scsi: Add durable_name for dev_printk
In reply to Tony AslesonAdd the needed functions to fill out the durable_name function call back for scsi based storage devices. This allows calls into dev_printk for scsi devices to have a persistent id associated with them.
--- drivers/scsi/scsi_lib.c | 14 ++++++++++++++ drivers/scsi/scsi_sysfs.c | 23 +++++++++++++++++++++++ drivers/scsi/sd.c | 2 ++ include/scsi/scsi_device.h | 3 +++ 4 files changed, 42 insertions(+)
drivers/scsi/scsi_lib.c +14 -0
@@ -3121,3 +3121,17 @@ int scsi_vpd_tpg_id(struct scsi_device *sdev, int *rel_id)return group_id; }EXPORT_SYMBOL (scsi_vpd_tpg_id); + +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++; +else + vpd_len =0 ; + +return vpd_len; +} +EXPORT_SYMBOL (scsi_durable_name);
drivers/scsi/scsi_sysfs.c +23 -0
@@ -1582,6 +1582,28 @@ static struct device_type scsi_dev_type = { .groups = scsi_sdev_attr_groups, }; + +int dev_to_scsi_durable_name (const struct device *dev,char *buf,size_t len) +{ +struct scsi_device *sd_dev =NULL ; + +// When we go through dev_printk in the scsi layer, dev is embedded +// in a struct scsi_device. When we go through the block layer, +// dev is embedded in struct genhd, thus we need different paths to +// retrieve the struct scsi_device to call scsi_durable_name. +if (dev->type == &scsi_dev_type) { + sd_dev =to_scsi_device (dev); + }else if (dev->parent && dev->parent->type == &scsi_dev_type) { + sd_dev =to_scsi_device (dev->parent); + }else { +// We have a pointer to something else, bail +return 0 ; + } + +return scsi_durable_name (sd_dev, buf, len); +} +EXPORT_SYMBOL (dev_to_scsi_durable_name); +void scsi_sysfs_device_initialize (struct scsi_device *sdev) {unsigned long flags;
@@ -1591,6 +1613,7 @@ void scsi_sysfs_device_initialize(struct scsi_device *sdev)device_initialize (&sdev->sdev_gendev); sdev->sdev_gendev.bus = &scsi_bus_type; sdev->sdev_gendev.type = &scsi_dev_type; + sdev->sdev_gendev.durable_name = dev_to_scsi_durable_name;dev_set_name (&sdev->sdev_gendev,"%d:%d:%d:%llu" , sdev->host->host_no, sdev->channel, sdev->id, sdev->lun);
drivers/scsi/sd.c +2 -0
@@ -3359,6 +3359,8 @@ static int sd_probe(struct device *dev) gd->private_data = &sdkp->driver; gd->queue = sdkp->device->request_queue; +disk_to_dev (gd)->durable_name = dev_to_scsi_durable_name; +/* defaults, until the device tells us otherwise */ sdp->sector_size =512 ; sdkp->capacity =0 ;
include/scsi/scsi_device.h +3 -0
@@ -459,6 +459,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 *);
Signature · 1 line
2.25.4
RFC PATCH v2 7/7 nvme: Add durable name for dev_printk
In reply to Tony Asleson--- drivers/nvme/host/core.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+)
drivers/nvme/host/core.c +18 -0
@@ -2614,6 +2614,22 @@ static bool nvme_validate_cntlid(struct nvme_subsystem *subsys,return true; } +static ssize_t wwid_show (struct device *dev,struct device_attribute *attr, +char *buf); + +static int dev_to_nvme_durable_name (const struct device *dev,char *buf,size_t len) +{ +char serial[128 ]; +ssize_t serial_len =wwid_show ((struct device *)dev,NULL , serial); + +if (serial_len >0 && serial_len < len) { + serial_len -=1 ;// Remove the '\n' from the string +strncpy (buf, serial, serial_len); +return serial_len; + } +return 0 ; +} +static int nvme_init_subsystem (struct nvme_ctrl *ctrl,struct nvme_id_ctrl *id) {struct nvme_subsystem *subsys, *found;
@@ -3541,6 +3557,8 @@ static int nvme_alloc_ns(struct nvme_ctrl *ctrl, unsigned nsid) disk->queue = ns->queue; disk->flags = flags;memcpy (disk->disk_name, disk_name,DISK_NAME_LEN ); +disk_to_dev (disk)->durable_name = dev_to_nvme_durable_name; + ns->disk = disk;__nvme_revalidate_disk (disk, id);
Signature · 1 line
2.25.4
Keith Busch
maintainerRe: [RFC PATCH v2 7/7] nvme: Add durable name for dev_printk
drivers/nvme/host/core.c static bool nvme_validate_cntlid(struct nvme_subsystem *subsys, · line 2623
Quoted 4 lines · Tony Asleson
drivers/nvme/host/core.c +4
-0+static int dev_to_nvme_durable_name (const struct device *dev,char *buf,size_t len) +{ +char serial[128 ]; +ssize_t serial_len =wwid_show ((struct device *)dev,NULL , serial);
wwid_show() can generate a serial larger than 128 bytes.
drivers/nvme/host/core.c static bool nvme_validate_cntlid(struct nvme_subsystem *subsys, · line 2626
Quoted 3 lines
drivers/nvme/host/core.c +3
-0+ +if (serial_len >0 && serial_len < len) { + serial_len -=1 ;// Remove the '\n' from the string
Comments in this driver should use the /* */ style.
Quoted 5 lines
drivers/nvme/host/core.c +5
-0+strncpy (buf, serial, serial_len); +return serial_len; + } +return 0 ; +}
Re: [RFC PATCH v2 7/7] nvme: Add durable name for dev_printk
Quoted 7 lines · Keith Busch
drivers/nvme/host/core.c static bool nvme_validate_cntlid(struct nvme_subsystem *subsys, · line 2623
Quoted 4 lines · Tony Asleson
drivers/nvme/host/core.c +4
-0+static int dev_to_nvme_durable_name (const struct device *dev,char *buf,size_t len) +{ +char serial[128 ]; +ssize_t serial_len =wwid_show ((struct device *)dev,NULL , serial);
wwid_show()can generate a serial larger than 128 bytes.
Looking at this again
return sprintf(buf, "nvme.%04x-%*phN-%*phN-%08x\n",
subsys->vendor_id,
serial_len, subsys->serial,
model_len, subsys->model,
subsys->ns_id);'nvme.' = 5vendor_id = 4
'-' = 1
serial (20 * 2) = 40
'-' = 1
model (40 * 2) = 80
'-' = 1ns_id = 8
'\n' = 1
5 + 4 + 1 + 40 + 1 + 80 + 1 + 8 + 1 = 141
Does this match your understanding?
My mistake was thinking each byte of SN and Model = 1 character in output, instead of 2.
This will also require the buffer used in dev_vprintk_emit to be quite a bit bigger to accommodate max size.
Quoted 5 lines
drivers/nvme/host/core.c static bool nvme_validate_cntlid(struct nvme_subsystem *subsys, · line 2626
Quoted 3 lines
drivers/nvme/host/core.c +3
-0+ +if (serial_len >0 && serial_len < len) { + serial_len -=1 ;// Remove the '\n' from the string Comments in this driver should use the /* */ style.
OK, will revise.
Quoted 7 lines
drivers/nvme/host/core.c static bool nvme_validate_cntlid(struct nvme_subsystem *subsys, · line 2631
Quoted 6 lines
drivers/nvme/host/core.c +5
-0+strncpy (buf, serial, serial_len); +return serial_len; + } +return 0 ; +}
Thanks
-Tony
Keith Busch
maintainerRe: [RFC PATCH v2 7/7] nvme: Add durable name for dev_printk
Quoted 27 lines · Tony Asleson
Quoted 7 lines · Keith Busch
drivers/nvme/host/core.c static bool nvme_validate_cntlid(struct nvme_subsystem *subsys, · line 2623
Quoted 4 lines · Tony Asleson
drivers/nvme/host/core.c +4
-0+static int dev_to_nvme_durable_name (const struct device *dev,char *buf,size_t len) +{ +char serial[128 ]; +ssize_t serial_len =wwid_show ((struct device *)dev,NULL , serial);
wwid_show()can generate a serial larger than 128 bytes.Looking at this again
return sprintf(buf, "nvme.%04x-%*phN-%*phN-%08x\n",
subsys->vendor_id, serial_len, subsys->serial, model_len, subsys->model, subsys->ns_id);'nvme.' = 5
vendor_id= 4
'-' = 1
serial (20 * 2) = 40
'-' = 1
model (40 * 2) = 80
'-' = 1ns_id= 8
'\n' = 1
Quoted 3 lines
5 + 4 + 1 + 40 + 1 + 80 + 1 + 8 + 1 = 141
Does this match your understanding?
Yep, that looks like the correct max possible length. I didn't actually count it out, but I just knew it could be larger than 128. :)