Bug 1846559

Summary: lsscsi bug in my_strcopy() in collect_disk_wwn_nodes() results in no wwn being collected
Product: Red Hat Enterprise Linux 8 Reporter: Dwight (Bud) Brown <bubrown>
Component: lsscsiAssignee: Tomáš Bžatek <tbzatek>
Status: CLOSED ERRATA QA Contact: Filip Suba <fsuba>
Severity: medium Docs Contact:
Priority: unspecified    
Version: 8.3CC: cwei, jmagrini, nyewale
Target Milestone: rcFlags: pm-rhel: mirror+
Target Release: 8.0   
Hardware: Unspecified   
OS: Unspecified   
Whiteboard:
Fixed In Version: lsscsi-0.32-1.el8 Doc Type: If docs needed, set a value
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2021-05-18 14:56:54 UTC Type: Bug
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:
Attachments:
Description Flags
collect_disk_wwn_nodes: Fix WWN string copy
none
one_ndev_entry: Print WWN along in combination with other print modes none

Description Dwight (Bud) Brown 2020-06-11 22:30:52 UTC
Description of problem:
lsscsi --wwn does not produce output like it should, wwn field only has '0'


Version-Release number of selected component (if applicable):
0.31, bug is present in lsscsi-0.31.tgz @ http://sg.danny.cz/scsi/lsscsi.html as well.

How reproducible:
100%

Steps to Reproduce:
1. lsscsi --wwn
2.
3.

Actual results:
# lsscsi --wwn
[0:0:0:0]    storage HP       P410i            6.60                                  -        
[0:1:0:0]    disk    HP       LOGICAL VOLUME   6.60  0                                   /dev/sda 
[0:1:0:1]    disk    HP       LOGICAL VOLUME   6.60  0                                   /dev/sdb 
[1:0:0:0]    cd/dvd  hp       DVD A  DS8A8SH   KHE4                                  /dev/sr0 


Expected results:
With change from '2' to '3' length:

# ./lsscsi.dbg --wwn
[0:0:0:0]    storage HP       P410i            6.60                                  -        
[0:1:0:0]    disk    HP       LOGICAL VOLUME   6.60  0x3600508b1001cf6d83cad2f9741e23e5  /dev/sda 
[0:1:0:1]    disk    HP       LOGICAL VOLUME   6.60  0x3600508b1001c033030ea6dada3776da  /dev/sdb 
[1:0:0:0]    cd/dvd  hp       DVD A  DS8A8SH   KHE4                                  /dev/sr0 


Additional info:

Specific bug is this line:

my_strcopy(cur_ent->wwn, "0x", 2); 

should be:

my_strcopy(cur_ent->wwn, "0x", 3);

the code reserves one from max len (2) for \0, so only copies "0\0" to wwn.  Next line puts wwn starting at location 2:

                my_strcopy(cur_ent->wwn + 2, dep->d_name + 5,
                           sizeof(cur_ent->wwn) - 2);

the the \0 at indx [1] terminates the string.




A separate RFE might be to collect wwn- if scsi- for a device isn't present but not sure if that condition arises.

Also something weird with nvme and --wwn, when specified and nvme is present, the vendor name is replaced with eui. string

$ lsscsi 
[0:0:0:0]    disk    Samsung  Portable SSD T5  0     /dev/sda 
[N:0:2:1]    disk    SAMSUNG MZVKW512HMJP-000L7__1              /dev/nvme0n1

$ lsscsi --wwn
[0:0:0:0]    disk    Samsung  Portable SSD T5  0                                     /dev/sda 
[N:0:2:1]    disk    eui.002538c57100a087                       /dev/nvme0n1

Comment 1 Tomáš Bžatek 2020-07-08 14:51:06 UTC
Created attachment 1700319 [details]
collect_disk_wwn_nodes: Fix WWN string copy

(In reply to Dwight (Bud) Brown from comment #0)
> Specific bug is this line:
> 
> my_strcopy(cur_ent->wwn, "0x", 2); 
> 
> should be:
> 
> my_strcopy(cur_ent->wwn, "0x", 3);

Thanks for spotting this!

Comment 2 Tomáš Bžatek 2020-07-08 14:51:44 UTC
Created attachment 1700320 [details]
one_ndev_entry: Print WWN along in combination with other print modes

> Also something weird with nvme and --wwn, when specified and nvme is
> present, the vendor name is replaced with eui. string
> 
> $ lsscsi 
> [0:0:0:0]    disk    Samsung  Portable SSD T5  0     /dev/sda 
> [N:0:2:1]    disk    SAMSUNG MZVKW512HMJP-000L7__1              /dev/nvme0n1
> 
> $ lsscsi --wwn
> [0:0:0:0]    disk    Samsung  Portable SSD T5  0                            
> /dev/sda 
> [N:0:2:1]    disk    eui.002538c57100a087                       /dev/nvme0n1

Yeah, for some reason the WWN switch is exclusive to other print modes for NVMe devices, the attached patch tentatively decouples that, though there might be some alignment issues. 

Anyway, I've sent these patches to the lsscsi author for review.

Comment 7 Filip Suba 2020-11-26 09:39:12 UTC
Verified with lsscsi-0.32-2.el8.

# lsscsi --wwn
[2:0:1:0]    disk    LIO-ORG  test             4.0   0x3600140525c59211c1534e85aa2117f7  /dev/sda

Comment 9 errata-xmlrpc 2021-05-18 14:56:54 UTC
Since the problem described in this bug report should be
resolved in a recent advisory, it has been closed with a
resolution of ERRATA.

For information on the advisory (lsscsi bug fix and enhancement update), and where to find the updated
files, follow the link below.

If the solution does not work for you, open a new bug report.

https://access.redhat.com/errata/RHBA-2021:1634