Skip to content

Commit

Permalink
Local check for device names
Browse files Browse the repository at this point in the history
  • Loading branch information
monder committed Mar 15, 2016
1 parent ea48265 commit fcebc9e
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions ebs_driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -245,11 +245,14 @@ func (d *ebsVolumeDriver) attachVolume(name string) (string, error) {
// for recommended naming scheme (/dev/sd[f-p]).
for _, c := range "fghijklmnop" {
dev := "/dev/sd" + string(c)
altdev := "/dev/xvd" + string(c)

// TODO: we could check locally first to eliminate a few network
// roundtrips in the event that some devices are used. Even if we
// did that, however, we'd need the checks regarding the AWS request
// failing below, because of TOCTOU.
if _, err := os.Lstat(dev); err == nil {
continue
}
if _, err := os.Lstat(altdev); err == nil {
continue
}

if _, err := d.ec2.AttachVolume(&ec2.AttachVolumeInput{
Device: aws.String(dev),
Expand All @@ -276,7 +279,6 @@ func (d *ebsVolumeDriver) attachVolume(name string) (string, error) {
if _, err := os.Lstat(dev); os.IsNotExist(err) {
// On newer Linux kernels, /dev/sd* is mapped to /dev/xvd*. See
// if that's the case.
altdev := "/dev/xvd" + string(c)
if _, err := os.Lstat(altdev); os.IsNotExist(err) {
d.detachVolume(name)
return "", fmt.Errorf("Device %v is missing after attach.", dev)
Expand Down

0 comments on commit fcebc9e

Please sign in to comment.