Skip to content

Commit

Permalink
Don't trim device prefix for existing volumes in DeviceManager
Browse files Browse the repository at this point in the history
If a volume is (already) mounted at /dev/sdX, DM will trim the prefix
and claim the volume should be mounted at /dev/xvdX - this causes the
driver to get stuck in an infinite loop waiting for the volume to be
attached to the wrong location. This bug commonly is triggered by
manually mounting a volume using the AWS console, because it uses the
prefix /dev/sdX by default.

Signed-off-by: Connor Catlett <[email protected]>
  • Loading branch information
ConnorJC3 committed Feb 13, 2023
1 parent c4baaa7 commit 8ec5252
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 7 deletions.
16 changes: 13 additions & 3 deletions pkg/cloud/devicemanager/allocator.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ import (

// ExistingNames is a map of assigned device names. Presence of a key with a device
// name in the map means that the device is allocated. Value is irrelevant and
// can be used for anything that NameAllocator user wants. Only the relevant
// part of device name should be in the map, e.g. "ba" for "/dev/xvdba".
// can be used for anything that NameAllocator user wants. The name can be prefixed
// with /dev/sd or /dev/xvd
type ExistingNames map[string]string

// On AWS, we should assign new (not yet used) device names to attached volumes.
Expand Down Expand Up @@ -55,7 +55,17 @@ func (d *nameAllocator) GetNext(existingNames ExistingNames) (string, error) {
for _, c1 := range []string{"b", "c"} {
for c2 := 'a'; c2 <= 'z'; c2++ {
name := fmt.Sprintf("%s%s", c1, string(c2))
if _, found := existingNames[name]; !found {
foundAny = false
if _, found := existingNames[name]; found {
foundAny = true
}
if _, found := "/dev/sd" + existingNames[name]; found {
foundAny = true
}
if _, found := "/dev/xvd" + existingNames[name]; found {
foundAny = true
}
if !foundAny {
return name, nil
}
}
Expand Down
5 changes: 1 addition & 4 deletions pkg/cloud/devicemanager/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -207,9 +207,6 @@ func (d *deviceManager) getDeviceNamesInUse(instance *ec2.Instance) map[string]s
inUse := map[string]string{}
for _, blockDevice := range instance.BlockDeviceMappings {
name := aws.StringValue(blockDevice.DeviceName)
// trims /dev/sd or /dev/xvd from device name
name = strings.TrimPrefix(name, "/dev/sd")
name = strings.TrimPrefix(name, "/dev/xvd")

if len(name) < 1 || len(name) > 2 {
klog.InfoS("Unexpected EBS DeviceName", "DeviceName", aws.StringValue(blockDevice.DeviceName))
Expand All @@ -227,7 +224,7 @@ func (d *deviceManager) getDeviceNamesInUse(instance *ec2.Instance) map[string]s
func (d *deviceManager) getPath(inUse map[string]string, volumeID string) string {
for name, volID := range inUse {
if volumeID == volID {
return devPreffix + name
return name
}
}
return ""
Expand Down

0 comments on commit 8ec5252

Please sign in to comment.