Skip to content

Commit

Permalink
Merge pull request #56 from dell/1469_nvme_wwn_matching
Browse files Browse the repository at this point in the history
Fix detection and matching of wwn to nguid.
  • Loading branch information
donatwork authored Sep 19, 2024
2 parents 46d67e0 + f9095c6 commit 0821759
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 16 deletions.
52 changes: 36 additions & 16 deletions nvme.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,12 @@ const (

// NVMePortDefault - NVMe TCP port
NVMePortDefault = ":4420"

// PowerMaxOUIPrefix - PowerMax format 6 OUI prefix
PowerMaxOUIPrefix = "6000097"

// PowerStoreOUIPrefix - PowerStore format 6 OUI prefix
PowerStoreOUIPrefix = "68ccf09"
)

// NVMeConnectorParams - type definition for NVMe connector params
Expand Down Expand Up @@ -526,15 +532,23 @@ func (c *NVMeConnector) discoverDevice(ctx context.Context, wg *sync.WaitGroup,
result <- devicePathResult
}

// wwnMatches checks if the given nguid and wwn match.
//
// Parameters:
// - nguid: a string representing the nguid.
// - wwn: a string representing the wwn.
//
// Returns:
// - a boolean indicating whether the wwn matches the nguid.
func (c *NVMeConnector) wwnMatches(nguid, wwn string) bool {
/*
// PowerStore
Sample wwn : naa.68ccf098001111a2222b3d4444a1b23c
wwn1 : 1111a2222b3d4444
wwn2 : a1b23c
token1: 1111a2222b3d4444
token2: a1b23c
Sample nguid : 1111a2222b3d44448ccf096800a1b23c
/ pmax:
// PowerMax
nguid: 12635330303134340000976000012000
wwn: 60000970000120001263533030313434
11aaa111111111a11a111a1111aa1111
Expand All @@ -545,23 +559,29 @@ func (c *NVMeConnector) wwnMatches(nguid, wwn string) bool {
if len(wwn) < 32 {
return false
}
var wwn1, wwn2 string
if strings.Contains(wwn, "naa") {
// powerstore
wwn1 = wwn[13 : len(wwn)-7]
wwn2 = wwn[len(wwn)-6 : len(wwn)-1]
if strings.Contains(nguid, wwn1) && strings.Contains(nguid, wwn2) {

wwn = strings.ToLower(wwn)
if strings.HasPrefix(wwn, "naa.") {
wwn = wwn[4:]
}

var token1, token2 string
if strings.HasPrefix(wwn, PowerStoreOUIPrefix) {
token1 = wwn[13 : len(wwn)-7]
token2 = wwn[len(wwn)-6 : len(wwn)-1]
log.Infof("PowerStore: %s %s %s %t", token1, token2, nguid, strings.Contains(nguid, token2))
if strings.Contains(nguid, token1) && strings.Contains(nguid, token2) {
return true
}
} else {
// pmax
wwn1 = wwn[16:]
wwn2 = wwn[1:7]
log.Infof("Powermax: %s %s %s %t", wwn1, wwn2, nguid, strings.HasPrefix(nguid, wwn1+wwn2))
if strings.HasPrefix(nguid, wwn1+wwn2) {
} else if strings.HasPrefix(wwn, PowerMaxOUIPrefix) {
token1 = wwn[16:]
token2 = wwn[1:7]
log.Infof("Powermax: %s %s %s %t", token1, token2, nguid, strings.HasPrefix(nguid, token1+token2))
if strings.HasPrefix(nguid, token1+token2) {
return true
}
}

return false
}

Expand Down
28 changes: 28 additions & 0 deletions nvme_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ package gobrick

import (
"context"
"fmt"
"reflect"
"testing"
"time"
Expand Down Expand Up @@ -174,3 +175,30 @@ func TestNVME_Connector_ConnectVolume(t *testing.T) {
})
}
}

func TestNVME_wwnMatches(t *testing.T) {
tests := []struct {
nguid string
wwn string
want bool
}{
{nguid: "0f8da909812540628ccf09680039914f", wwn: "naa.68ccf098000f8da9098125406239914f", want: true},
{nguid: "0f8da909812540628ccf09680039914f", wwn: "NAA.68ccf098000f8da9098125406239914f", want: true},
{nguid: "0f8da909812540628ccf09680039914f", wwn: "68ccf098000f8da9098125406239914f", want: true},
{nguid: "0f8da909812540628ccf09680039914f", wwn: "68CCF098000F8DA9098125406239914F", want: true},
{nguid: "0f8da909812540628ccf09680039914f", wwn: "60000978000f8da9098125406239914f", want: false},
{nguid: "12635330303134340000976000012000", wwn: "60000970000120001263533030313434", want: true},
{nguid: "12635330303134340000976000012000", wwn: "68ccf070000120001263533030313434", want: false},
{nguid: "12635330303134340000976000012000", wwn: "8ccf070000120001263533030313434", want: false},
{nguid: "12635330303134340000976000012000", wwn: "68CCF070000120001263533030313434", want: false},
}

for _, tt := range tests {
t.Run(fmt.Sprintf("(%s,%s) should be %v", tt.nguid, tt.wwn, tt.want), func(t *testing.T) {
c := &NVMeConnector{}
if c.wwnMatches(tt.nguid, tt.wwn) != tt.want {
t.Errorf("wwnMatches(%v, %v) = %v, want %v", tt.nguid, tt.wwn, !tt.want, tt.want)
}
})
}
}

0 comments on commit 0821759

Please sign in to comment.