Skip to content

Commit

Permalink
Search for nvme device path even if non-nvme exists
Browse files Browse the repository at this point in the history
  • Loading branch information
wongma7 committed Oct 7, 2021
1 parent d90b8ea commit 25dbf8e
Showing 1 changed file with 27 additions and 11 deletions.
38 changes: 27 additions & 11 deletions pkg/driver/node_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,33 +34,49 @@ import (
// if the device is not nvme, return the path directly
// if the device is nvme, finds and returns the nvme device path eg. /dev/nvme1n1
func (d *nodeService) findDevicePath(devicePath, volumeID string, partition string) (string, error) {
devicePaths := []string{}

// If the given path exists, the device MAY be nvme. Further, it MAY be a
// symlink to the nvme device path like:
// | $ stat /dev/xvdba
// | File: ‘/dev/xvdba’ -> ‘nvme1n1’
// Since these are maybes, not guarantees, the search for the nvme device
// path below must happen and must rely on volume ID
exists, err := d.mounter.PathExists(devicePath)
if err != nil {
return "", err
return "", fmt.Errorf("failed to check if path %q exists: %v", devicePath, err)
}

// If the path exists, assume it is not nvme device
if exists {
if partition != "" {
devicePath = devicePath + diskPartitionSuffix + partition
}
return devicePath, nil
devicePaths = append(devicePaths, devicePath)
}

// Else find the nvme device path using volume ID
// This is the magic name on which AWS presents NVME devices under /dev/disk/by-id/
// For example, vol-0fab1d5e3f72a5e23 creates a symlink at
// AWS recommends identifying devices by volume ID
// (https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/nvme-ebs-volumes.html),
// so find the nvme device path using volume ID. This is the magic name on
// which AWS presents NVME devices under /dev/disk/by-id/. For example,
// vol-0fab1d5e3f72a5e23 creates a symlink at
// /dev/disk/by-id/nvme-Amazon_Elastic_Block_Store_vol0fab1d5e3f72a5e23
nvmeName := "nvme-Amazon_Elastic_Block_Store_" + strings.Replace(volumeID, "-", "", -1)

nvmeDevicePath, err := findNvmeVolume(nvmeName)
if err != nil {
return "", err

if err == nil {
if partition != "" {
nvmeDevicePath = nvmeDevicePath + nvmeDiskPartitionSuffix + partition
}
devicePaths = append(devicePaths, nvmeDevicePath)
}
if partition != "" {
nvmeDevicePath = nvmeDevicePath + nvmeDiskPartitionSuffix + partition

if len(devicePaths) == 0 {
return "", fmt.Errorf("no device path for %q found!", devicePath)
}
return nvmeDevicePath, nil

canonicalDevicePath := devicePaths[len(devicePaths)-1]
return canonicalDevicePath, nil
}

// findNvmeVolume looks for the nvme volume with the specified name
Expand Down

0 comments on commit 25dbf8e

Please sign in to comment.