Skip to content

Commit

Permalink
(feat): AWS Nvme Fixes + Permissions Fix
Browse files Browse the repository at this point in the history
  • Loading branch information
lasith-kg committed Nov 23, 2023
1 parent cbab7f9 commit a87aa65
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 7 deletions.
17 changes: 11 additions & 6 deletions internal/config/modifier.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,20 +64,25 @@ func NewAwsNVMeDriverModifier(nvmeService service.NVMeService, deviceService ser
}

func (andm *AwsNitroNVMeModifier) Modify(c *Config) error {
for name, cd := range c.Devices {
if _, err := andm.deviceService.GetBlockDevice(name); err == nil {
continue
}
bds, err := andm.deviceService.GetBlockDevices()
if err != nil {
return err
}
for _, name := range bds {
if !strings.HasPrefix(name, "/dev/nvme") {
continue
}
bdm, err := andm.nvmeService.GetBlockDeviceMapping(name)
if err != nil {
continue
}
cd, exists := c.Devices[bdm]
if !exists {
continue
}
log.Printf("🔵 Detected that %s is a nitro-based AWS NVMe device, originally mapped to %s", name, bdm)
c.Devices[bdm] = cd
delete(c.Devices, name)
c.Devices[name] = cd
delete(c.Devices, bdm)
}
return nil
}
2 changes: 1 addition & 1 deletion internal/model/device.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ func (mop MountOptions) String() string {
}

func (mop MountOptions) Remount(enabled bool) MountOptions {
mops := strings.Split(string(mop), ",")
mops := strings.Split(mop.String(), ",")
if enabled {
index := -1
for i, op := range mops {
Expand Down
19 changes: 19 additions & 0 deletions internal/service/device.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
// Device Service Interface [START]

type DeviceService interface {
GetBlockDevices() ([]string, error)
GetBlockDevice(name string) (*model.BlockDevice, error)
}

Expand Down Expand Up @@ -38,6 +39,24 @@ func NewLinuxDeviceService(rc *utils.RunnerCache) *LinuxDeviceService {
}
}

func (du *LinuxDeviceService) GetBlockDevices() ([]string, error) {
r := du.runnerCache.GetRunner(utils.Lsblk)
output, err := r.Command("--nodeps", "-o", "NAME,LABEL,FSTYPE,MOUNTPOINT", "-J")
if err != nil {
return nil, err
}
lbd := &LsblkBlockDeviceResponse{}
err = json.Unmarshal([]byte(output), lbd)
if err != nil {
return nil, err
}
d := make([]string, len(lbd.BlockDevices))
for i, _ := range d {
d[i] = "/dev/" + utils.SafeString(lbd.BlockDevices[i].Name)
}
return d, nil
}

func (du *LinuxDeviceService) GetBlockDevice(name string) (*model.BlockDevice, error) {
r := du.runnerCache.GetRunner(utils.Lsblk)
output, err := r.Command("--nodeps", "-o", "NAME,UUID,LABEL,FSTYPE,MOUNTPOINT", "-J", name)
Expand Down

0 comments on commit a87aa65

Please sign in to comment.