Skip to content

Commit

Permalink
Remove dependency on unicode
Browse files Browse the repository at this point in the history
  • Loading branch information
lasith-kg authored Nov 23, 2023
1 parent dc0fc5a commit d0adfcc
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions internal/service/nvme.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"os"
"strings"
"syscall"
"unicode"
"unsafe"
)

Expand Down Expand Up @@ -151,13 +150,13 @@ func (ns *AwsNitroNVMeService) GetBlockDeviceMapping(device string) (string, err

func (ns *AwsNitroNVMeService) isEBSVolume(nd *NVMeDevice) bool {
vid := nd.IdCtrl.Vid
mn := strings.TrimRightFunc(string(nd.IdCtrl.Mn[:]), unicode.IsSpace)
mn := strings.TrimRightFunc(string(nd.IdCtrl.Mn[:]), ns.TrimModelNumber)
return vid == AMZN_NVME_VID && mn == AMZN_NVME_EBS_MN
}

func (ns *AwsNitroNVMeService) isInstanceStoreVolume(nd *NVMeDevice) bool {
vid := nd.IdCtrl.Vid
mn := strings.TrimRightFunc(string(nd.IdCtrl.Mn[:]), unicode.IsSpace)
mn := strings.TrimRightFunc(string(nd.IdCtrl.Mn[:]), ns.TrimModelNumber)
return vid == AMZN_NVME_VID && mn == AMZN_NVME_INS_MN
}

Expand Down Expand Up @@ -188,6 +187,12 @@ func (ns *AwsNitroNVMeService) getBlockDeviceMapping(nd *NVMeDevice) (string, er
return bdm, nil
}

func (ns *AwsNitroNVMeService) TrimModelNumber(r rune) bool {
// Explanation:
// - Both the AWS EC2 and EBS team use the 0x20 (space) byte to pad out the Model Number
return r == 0x20
}

func (ns *AwsNitroNVMeService) TrimVendorSpecfic(r rune) bool {
// Explanation:
// - The AWS EC2 team uses the 0x00 (null) byte to pad out the Vendor Specific allocation
Expand Down

0 comments on commit d0adfcc

Please sign in to comment.