Skip to content

Commit

Permalink
Store discovered nvme capabilities in common.Capabilities
Browse files Browse the repository at this point in the history
Needed so we can figure out the correct wipe functions later on.
  • Loading branch information
mmlb committed Jun 6, 2024
1 parent 2ea9b01 commit cc443d9
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 19 deletions.
36 changes: 17 additions & 19 deletions utils/nvme.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,6 @@ func (n *Nvme) Attributes() (utilName model.CollectorUtility, absolutePath strin

// Executes nvme list, parses the output and returns a slice of *common.Drive
func (n *Nvme) Drives(ctx context.Context) ([]*common.Drive, error) {
drives := make([]*common.Drive, 0)

out, err := n.list(ctx)
if err != nil {
return nil, err
Expand All @@ -88,7 +86,8 @@ func (n *Nvme) Drives(ctx context.Context) ([]*common.Drive, error) {
return nil, err
}

for _, d := range list.Devices {
drives := make([]*common.Drive, len(list.Devices))
for i, d := range list.Devices {
dModel := d.ModelNumber

var vendor string
Expand All @@ -98,32 +97,31 @@ func (n *Nvme) Drives(ctx context.Context) ([]*common.Drive, error) {
if len(modelTokens) > 1 {
vendor = modelTokens[1]
}
drive := &common.Drive{
Common: common.Common{
LogicalName: d.DevicePath,
Serial: d.SerialNumber,
Vendor: vendor,
Model: dModel,
ProductName: d.ProductName,
Description: d.ModelNumber,
Firmware: &common.Firmware{
Installed: d.Firmware,
},
Metadata: map[string]string{},
},
}

// Collect drive capabilitiesFound
capabilitiesFound, err := n.DriveCapabilities(ctx, d.DevicePath)
if err != nil {
return nil, err
}

metadata := map[string]string{}
for _, f := range capabilitiesFound {
drive.Common.Metadata[f.Description] = strconv.FormatBool(f.Enabled)
metadata[f.Description] = strconv.FormatBool(f.Enabled)
}

drives = append(drives, drive)
drives[i] = &common.Drive{
Common: common.Common{
LogicalName: d.DevicePath,
Serial: d.SerialNumber,
Vendor: vendor,
Model: dModel,
ProductName: d.ProductName,
Description: d.ModelNumber,
Firmware: &common.Firmware{Installed: d.Firmware},
Capabilities: capabilitiesFound,
Metadata: metadata,
},
}
}

return drives, nil
Expand Down
19 changes: 19 additions & 0 deletions utils/nvme_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,19 @@ import (
)

func Test_NvmeComponents(t *testing.T) {
// nolint:dupl
expected := []*common.Drive{
{Common: common.Common{
LogicalName: "/dev/nvme0n1", Serial: "Z9DF70I8FY3L", Vendor: "TOSHIBA", Model: "KXG60ZNV256G TOSHIBA", Description: "KXG60ZNV256G TOSHIBA", Firmware: &common.Firmware{Installed: "AGGA4104"}, ProductName: "NULL",
Capabilities: []*common.Capability{
{Name: "fmns", Description: "Format Applies to All/Single Namespace(s) (t:All, f:Single)", Enabled: false},
{Name: "cens", Description: "Crypto Erase Applies to All/Single Namespace(s) (t:All, f:Single)", Enabled: false},
{Name: "cese", Description: "Crypto Erase Supported as part of Secure Erase", Enabled: true},
{Name: "cer", Description: "Crypto Erase Sanitize Operation Supported", Enabled: false},
{Name: "ber", Description: "Block Erase Sanitize Operation Supported", Enabled: false},
{Name: "owr", Description: "Overwrite Sanitize Operation Supported", Enabled: false},
{Name: "ndi", Description: "No-Deallocate After Sanitize bit in Sanitize command Supported", Enabled: false},
},
Metadata: map[string]string{
"Block Erase Sanitize Operation Supported": "false",
"Crypto Erase Applies to All/Single Namespace(s) (t:All, f:Single)": "false",
Expand All @@ -29,6 +39,15 @@ func Test_NvmeComponents(t *testing.T) {
}},
{Common: common.Common{
LogicalName: "/dev/nvme1n1", Serial: "Z9DF70I9FY3L", Vendor: "TOSHIBA", Model: "KXG60ZNV256G TOSHIBA", Description: "KXG60ZNV256G TOSHIBA", Firmware: &common.Firmware{Installed: "AGGA4104"}, ProductName: "NULL",
Capabilities: []*common.Capability{
{Name: "fmns", Description: "Format Applies to All/Single Namespace(s) (t:All, f:Single)", Enabled: false},
{Name: "cens", Description: "Crypto Erase Applies to All/Single Namespace(s) (t:All, f:Single)", Enabled: false},
{Name: "cese", Description: "Crypto Erase Supported as part of Secure Erase", Enabled: true},
{Name: "cer", Description: "Crypto Erase Sanitize Operation Supported", Enabled: false},
{Name: "ber", Description: "Block Erase Sanitize Operation Supported", Enabled: false},
{Name: "owr", Description: "Overwrite Sanitize Operation Supported", Enabled: false},
{Name: "ndi", Description: "No-Deallocate After Sanitize bit in Sanitize command Supported", Enabled: false},
},
Metadata: map[string]string{
"Block Erase Sanitize Operation Supported": "false",
"Crypto Erase Applies to All/Single Namespace(s) (t:All, f:Single)": "false",
Expand Down

0 comments on commit cc443d9

Please sign in to comment.