Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bugfix/NVMe Ephemeral Changes #10

Merged
merged 8 commits into from
Mar 7, 2022
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions internal/scsi/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,12 @@ type SCSI interface {
GetNVMEDeviceWWN(ctx context.Context, devices []string) (string, error)
GetDevicesByWWN(ctx context.Context, wwn string) ([]string, error)
GetDMDeviceByChildren(ctx context.Context, devices []string) (string, error)
GetNVMEDMDeviceByChildren(ctx context.Context, devices []string) (string, error)
GetNVMEMultipathDMName(device string, pattern string) ([]string, error)
GetDMChildren(ctx context.Context, dmPath string) ([]string, error)
CheckDeviceIsValid(ctx context.Context, device string) bool
GetDeviceNameByHCTL(ctx context.Context, h scsi.HCTL) (string, error)
WaitUdevSymlink(ctx context.Context, deviceName string, wwn string) error
WaitUdevSymlinkNVMe(ctx context.Context, deviceName string, wwn string) error
GetNVMESymlink(checkPath string) (string, error)
}
45 changes: 45 additions & 0 deletions internal/scsi/scsi_mock.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion nvme_tcp.go
Original file line number Diff line number Diff line change
Expand Up @@ -398,7 +398,7 @@ func (c *NVMeTCPConnector) connectMultipathDevice(

if wwn != "" && mpath == "" {
var err error
mpath, err = c.scsi.GetDMDeviceByChildren(ctx, devices)
mpath, err = c.scsi.GetNVMEDMDeviceByChildren(ctx, devices)
if err != nil {
logger.Debug(ctx, "failed to get DM by children: %s", err.Error())
}
Expand Down
85 changes: 79 additions & 6 deletions pkg/scsi/scsi.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,16 @@ import (
"golang.org/x/sync/singleflight"
)

// constants
const (
diskByIDPath = "/dev/disk/by-id/"
diskByIDSCSIPath = diskByIDPath + "scsi-"
diskByIDDMPath = diskByIDPath + "dm-uuid-mpath-"
diskByIDDMPathNVMe = diskByIDPath + "dm-uuid-mpath-eui."
scsiIDPath = "/lib/udev/scsi_id"
diskByIDPath = "/dev/disk/by-id/"
diskByIDSCSIPath = diskByIDPath + "scsi-"
diskByIDDMPath = diskByIDPath + "dm-uuid-mpath-"
diskByIDDMPathNVMe = diskByIDPath + "dm-uuid-mpath-eui."
scsiIDPath = "/lib/udev/scsi_id"
maxRetryCount = 10
NVMEMultipathSleepTime = 500
NVMESymlinkSleepTime = 200
)

// NewSCSI initializes scsi struct
Expand Down Expand Up @@ -157,6 +161,12 @@ func (s *Scsi) GetDMDeviceByChildren(ctx context.Context, devices []string) (str
return s.getDMDeviceByChildren(ctx, devices)
}

// GetNVMEDMDeviceByChildren fetches multipath device name
func (s *Scsi) GetNVMEDMDeviceByChildren(ctx context.Context, devices []string) (string, error) {
defer tracer.TraceFuncCall(ctx, "scsi.GetNVMEDMDeviceByChildren")()
return s.getNVMEDMDeviceByChildren(ctx, devices)
}

// GetDMChildren fetches multipath block devices
func (s *Scsi) GetDMChildren(ctx context.Context, dm string) ([]string, error) {
defer tracer.TraceFuncCall(ctx, "scsi.GetDMChildren")()
Expand Down Expand Up @@ -355,6 +365,55 @@ func (s *Scsi) getDMDeviceByChildren(ctx context.Context, devices []string) (str
return "", errors.New("dm not found")
}

//GetNVMEMultipathDMName finds the multipath DM mame for NVMe
func (s *Scsi) GetNVMEMultipathDMName(device string, pattern string) ([]string, error) {

var retryCount = 0
for {
matches, err := s.filePath.Glob(fmt.Sprintf(pattern, device))
if len(matches) > 0 || retryCount == maxRetryCount {
return matches, err
}
time.Sleep(NVMEMultipathSleepTime * time.Millisecond)
retryCount = retryCount + 1
}
}

func (s *Scsi) getNVMEDMDeviceByChildren(ctx context.Context, devices []string) (string, error) {
logger.Info(ctx, "multipath - trying to find multipath DM name")

pattern := "/sys/block/%s/holders/dm-*"

var match string

for _, d := range devices {
matches, err := s.GetNVMEMultipathDMName(d, pattern)
//matches, err := s.filePath.Glob(fmt.Sprintf(pattern, d))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove commented code

if err != nil {
return "", err
}
for _, m := range matches {
data, err := s.fileReader.ReadFile(path.Join(m, "dm/uuid"))
if err != nil {
logger.Error(ctx, "multipath - failed to read dm id file: %s", err.Error())
continue
}
if strings.HasPrefix(string(data), "mpath") {
_, dm := path.Split(m)
if match == "" {
match = dm
} else if dm != match {
return "", &DevicesHaveDifferentParentsErr{}
}
}
}
}
if match != "" {
return match, nil
}
return "", errors.New("dm not found")
}

func (s *Scsi) getDMChildren(ctx context.Context, dm string) ([]string, error) {
logger.Info(ctx, "multipath - get block device included in DM")
var devices []string
Expand Down Expand Up @@ -503,14 +562,28 @@ func (s *Scsi) waitUdevSymlink(ctx context.Context, deviceName string, wwn strin
return nil
}

//GetNVMESymlink return the NVMe symlink for the given path
func (s *Scsi) GetNVMESymlink(checkPath string) (string, error) {

var retryCount = 1
for {
symlink, err := s.filePath.EvalSymlinks(checkPath)
if err == nil || retryCount == maxRetryCount {
return symlink, err
}
time.Sleep(NVMESymlinkSleepTime * time.Millisecond)
retryCount = retryCount + 1
}
}

func (s *Scsi) waitUdevSymlinkNVMe(ctx context.Context, deviceName string, wwn string) error {
var checkPath string
if strings.HasPrefix(deviceName, "dm-") {
checkPath = diskByIDDMPathNVMe + wwn
} else {
checkPath = diskByIDSCSIPath + wwn
}
symlink, err := s.filePath.EvalSymlinks(checkPath)
symlink, err := s.GetNVMESymlink(checkPath)
if err != nil {
msg := fmt.Sprintf("symlink for path %s not found: %s", checkPath, err.Error())
logger.Error(ctx, msg)
Expand Down