Skip to content

Commit

Permalink
Added support for nitro instances with NVMe block devices (#38)
Browse files Browse the repository at this point in the history
  • Loading branch information
mvisonneau authored and sevagh committed Nov 6, 2018
1 parent eb4c251 commit b6af4b2
Show file tree
Hide file tree
Showing 18 changed files with 690 additions and 6 deletions.
9 changes: 9 additions & 0 deletions Gopkg.lock

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

4 changes: 4 additions & 0 deletions Gopkg.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,7 @@
[[constraint]]
branch = "master"
name = "github.com/sirupsen/logrus"

[[constraint]]
name = "github.com/mvisonneau/go-ebsnvme"
version = "0.1.0"
4 changes: 2 additions & 2 deletions attach.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,14 @@ func (e *EC2Instance) AttachEbsVolumes() {
volLogger.Fatalf("Couldn't attach: %v", err)
}
volLogger.Info(volAttachments)
volume.AttachedName = deviceName

if !filesystem.DoesDriveExistWithTimeout(deviceName, 10) {
volLogger.Fatalf("Drive %s doesn't exist after attaching - checked with stat 10 times", deviceName)
}

volume.AttachedName = deviceName
localVolumes[key] = append(localVolumes[key], volume)
}

}
}
e.Vols = localVolumes
Expand Down
13 changes: 11 additions & 2 deletions ebs.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,11 @@ func prepAndMountDrives(volName string, vols []EbsVol) {
var err error
if len(vols) == 1 {
driveLogger.Info("Single drive, no RAID")
driveName = vols[0].AttachedName
driveName, err = filesystem.GetActualBlockDeviceName(vols[0].AttachedName)
if err != nil {
driveLogger.Fatalf("Block device is not available %s : %v", vols[0].AttachedName, err)
}
driveLogger.Infof("Using %s as local block device", driveName)
} else {
if raidLevel == -1 {
driveLogger.Info("Raid level not provided, not performing further actions")
Expand All @@ -64,7 +68,12 @@ func prepAndMountDrives(volName string, vols []EbsVol) {
driveLogger.Info("Creating RAID array")
driveNames := []string{}
for _, vol := range vols {
driveNames = append(driveNames, vol.AttachedName)
driveName, err = filesystem.GetActualBlockDeviceName(vol.AttachedName)
if err != nil {
driveLogger.Fatalf("Block device is not available %s : %v", vol.AttachedName, err)
}
driveLogger.Infof("Using %s as local block device", driveName)
driveNames = append(driveNames, driveName)
}
if driveName, err = filesystem.CreateRaidArray(driveNames, volName, raidLevel); err != nil {
driveLogger.Fatalf("Error when creating reaid array: %v", err)
Expand Down
37 changes: 35 additions & 2 deletions filesystem/drive.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
package filesystem

import (
"os"
"path/filepath"
"regexp"
"time"

"github.com/sevagh/goat/execute"
"github.com/mvisonneau/go-ebsnvme/pkg/ebsnvme"
)

//DoesDriveExistWithTimeout makes 10 attempts, 2 second sleep between each, to stat a drive to check for its existence
Expand All @@ -21,8 +24,38 @@ func DoesDriveExistWithTimeout(driveName string, maxAttempts int) bool {

//DoesDriveExist does a single stat call to check if a drive exists
func DoesDriveExist(driveName string) bool {
if _, err := execute.Command("stat", []string{driveName}, ""); err != nil {
if _, err := os.Stat(driveName); os.IsNotExist(err) {
for _, file := range listNvmeBlockDevices() {
if d, _ := ebsnvme.ScanDevice(file); d.Name == driveName {
return true
}
}
return false
}
return true
}

// GetLocalBlockDeviceName returns the actual name of the block device seen
// within the instance (useful for nitros)
func GetActualBlockDeviceName(name string) (string, error) {
for _, device := range listNvmeBlockDevices() {
if d, _ := ebsnvme.ScanDevice(device); d.Name == name {
return device, nil
}
}
if _, err := os.Stat(name); os.IsNotExist(err) {
return "", err
}
return name, nil
}

func listNvmeBlockDevices() (devices []string) {
re := regexp.MustCompile("(^\\/dev\\/nvme[0-9]+n1$)")
f, _ := filepath.Glob("/dev/nvme*")
for _, d := range f {
if re.Match([]byte(d)) {
devices = append(devices, d)
}
}
return
}
2 changes: 2 additions & 0 deletions vendor/github.com/mvisonneau/go-ebsnvme/.gitignore

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

11 changes: 11 additions & 0 deletions vendor/github.com/mvisonneau/go-ebsnvme/.travis.yml

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

19 changes: 19 additions & 0 deletions vendor/github.com/mvisonneau/go-ebsnvme/CHANGELOG.md

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

17 changes: 17 additions & 0 deletions vendor/github.com/mvisonneau/go-ebsnvme/Gopkg.lock

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

3 changes: 3 additions & 0 deletions vendor/github.com/mvisonneau/go-ebsnvme/Gopkg.toml

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

191 changes: 191 additions & 0 deletions vendor/github.com/mvisonneau/go-ebsnvme/LICENSE

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

Loading

0 comments on commit b6af4b2

Please sign in to comment.