Skip to content

Commit 4df04fb

Browse files
WIP: Remaplun fix by reading the wwid instead the vpdpath in case of 3PAR (#168)
* Remaplun fix by reading the wwid instead the vpdpath in case of 3PAR Signed-off-by: bhagyashree_sarawate <[email protected]>
1 parent 29ccbba commit 4df04fb

File tree

1 file changed

+71
-13
lines changed

1 file changed

+71
-13
lines changed

linux/device.go

Lines changed: 71 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -621,7 +621,14 @@ func cleanupStaleScsiPaths(volume *model.Volume) (err error) {
621621

622622
// obtain current path serial using sysfs vpd80 page
623623
var serialNumber string
624-
serialNumber, err = getVpd80FromSysfs(h, c, t, l)
624+
vendorName, _ := getVendorFromSysfs(h, c, t, l)
625+
if strings.Contains(vendorName, "3PARdata"){
626+
serialNumber, err = getWwidFromSysfs(h, c, t, l)
627+
}else {
628+
// obtain current path serial using sysfs vpd80 page
629+
serialNumber, err = getVpd80FromSysfs(h, c, t, l)
630+
}
631+
//serialNumber, err = getVpd80FromSysfs(h, c, t, l)
625632
if err != nil {
626633
log.Debugf("unable to read vpd_pg80 from sysfs for %s:%s:%s:%s err=%s. Continue with other paths", h, c, t, l, err.Error())
627634
continue
@@ -853,7 +860,15 @@ func cleanupUnmappedDevice(oldSerial string, volumelunID string) error {
853860
continue
854861
}
855862
var currentSerial string
856-
currentSerial, err = getVpd80FromSysfs(h, c, t, l)
863+
vendorName, _ := getVendorFromSysfs(h, c, t, l)
864+
if strings.Contains(vendorName, "3PARdata"){
865+
currentSerial, err = getWwidFromSysfs(h, c, t, l)
866+
}else {
867+
// obtain current path serial using sysfs vpd80 page
868+
currentSerial, err = getVpd80FromSysfs(h, c, t, l)
869+
}
870+
871+
//currentSerial, err = getVpd80FromSysfs(h, c, t, l)
857872
if err != nil {
858873
log.Debugf("unable to get serial for h:c:t:l %s:%s:%s:%s err=%s, continue with other paths", h, c, t, l, err.Error())
859874
continue
@@ -895,13 +910,20 @@ func cleanupUnmappedDevice(oldSerial string, volumelunID string) error {
895910
// check if a lun path has been remapped and update paths with new lun
896911
// serial in this case is volume serial (i.e without prefix 2) as we are directly getting from vpd page 80
897912
func checkRemappedLunPath(h string, c string, t string, l string, serial string, lunID string) (remappedLunFound bool, oldSerial string, err error) {
913+
log.Tracef(">>>>> checkRemappedLunPath")
898914
// check if the path is in offline state and assume its a stale path with same lunID so we rescan the path again.
899915
state, err := getDeviceState(h, c, t, l)
900916
if err != nil {
901917
return false, "", err
902918
}
903-
// obtain current path serial using sysfs vpd80 page
904-
oldSerial, err = getVpd80FromSysfs(h, c, t, l)
919+
vendorName, _ := getVendorFromSysfs(h, c, t, l)
920+
if strings.Contains(vendorName, "3PARdata"){
921+
oldSerial, err = getWwidFromSysfs(h, c, t, l)
922+
}else {
923+
// obtain current path serial using sysfs vpd80 page
924+
oldSerial, err = getVpd80FromSysfs(h, c, t, l)
925+
}
926+
905927
if err != nil {
906928
return false, "", err
907929
}
@@ -915,19 +937,24 @@ func checkRemappedLunPath(h string, c string, t string, l string, serial string,
915937
log.Debugf("%s:%s:%s:%s lun-id %s is in offline state, assuming remapped-lun", h, c, t, l, lunID)
916938
return true, oldSerial, nil
917939
}
918-
940+
if strings.Contains(vendorName, "3PARdata"){
941+
log.Debugf("found remapped lun with oldserial %s and Serial %s", oldSerial, serial)
942+
} else{
919943
// check for serial number mismatch
920-
updatedSerial, err := getDeviceSerialByHctl(h, c, t, l)
921-
if err != nil {
922-
// continue with other paths
923-
return false, "", err
924-
}
944+
updatedSerial, err := getDeviceSerialByHctl(h, c, t, l)
945+
if err != nil {
946+
// continue with other paths
947+
return false, "", err
948+
}
925949

926-
if updatedSerial != serial {
927-
return false, "", nil
950+
if updatedSerial != serial {
951+
return false, "", nil
952+
}
953+
log.Debugf("found remapped lun with oldserial %s and updatedSerial %s", oldSerial, updatedSerial)
928954
}
955+
929956
// updated path serial matches serial of the new lun attached
930-
log.Debugf("found remapped lun with oldserial %s and updatedSerial %s", oldSerial, updatedSerial)
957+
931958
return true, oldSerial, nil
932959
}
933960

@@ -989,6 +1016,37 @@ func getDeviceState(h string, c string, t string, l string) (state string, err e
9891016
return state, nil
9901017
}
9911018

1019+
func getVendorFromSysfs(h string, c string, t string, l string) (vendorName string, err error){
1020+
log.Tracef(">>>>> getVendorFromSysfs")
1021+
vendorPath := fmt.Sprintf("/sys/class/scsi_device/%s:%s:%s:%s/device/vendor", h, c, t, l)
1022+
out, err := util.FileReadFirstLine(vendorPath)
1023+
log.Info("vendor: ", out)
1024+
if err != nil {
1025+
return "", err
1026+
}
1027+
return out, nil
1028+
}
1029+
1030+
func getWwidFromSysfs(h string, c string, t string, l string) (serial string, err error){
1031+
1032+
log.Tracef(">>>>> getWwidFromSysfs")
1033+
1034+
wwidPath := fmt.Sprintf("/sys/class/scsi_device/%s:%s:%s:%s/device/wwid", h, c, t, l)
1035+
wwidOut, wwidErr := util.FileReadFirstLine(wwidPath)
1036+
if wwidErr != nil {
1037+
return "", wwidErr
1038+
}
1039+
log.Info("wwidOut", wwidOut)
1040+
// extract serial from format: naa.60002ac0000000000a0066ef0001db2c
1041+
entries := strings.Split(wwidOut, ".")
1042+
if len(entries) > 1 {
1043+
return entries[1], nil
1044+
}
1045+
return "", fmt.Errorf("invalid serial number found with wwid %s", wwidOut)
1046+
1047+
1048+
}
1049+
9921050
func getVpd80FromSysfs(h string, c string, t string, l string) (serial string, err error) {
9931051
vpdPath := fmt.Sprintf("/sys/class/scsi_device/%s:%s:%s:%s/device/vpd_pg80", h, c, t, l)
9941052
out, err := util.FileReadFirstLine(vpdPath)

0 commit comments

Comments
 (0)