-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add DiskWipe support to nvme using sanitize (#136)
### What does this PR do Adds support to nvme for wiping the drive using sanitize ops. Both crypto erase and block erase are supported. The appropriate sanitize action is chosen based on detected capabilities. ### How can this change be tested by a PR reviewer? Run on a machine with an nvme device.
- Loading branch information
Showing
10 changed files
with
333 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
### Go template | ||
/bin/ | ||
|
||
# Test binary, build with `go test -c` | ||
*.test | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,32 @@ | ||
.DEFAULT_GOAL := help | ||
|
||
## lint | ||
lint: | ||
go run github.com/golangci/golangci-lint/cmd/[email protected] run --config .golangci.yml | ||
export GOBIN=$(CURDIR)/bin | ||
export PATH:=$(PATH):$(GOBIN) | ||
|
||
## Go test | ||
test: lint | ||
## Run all linters | ||
lint: golangci-lint check-go-generated | ||
|
||
## Run golangci-lint | ||
golangci-lint: | ||
go install github.com/golangci/golangci-lint/cmd/[email protected] | ||
golangci-lint run --config .golangci.yml | ||
|
||
## Run go generate | ||
generate: | ||
go install golang.org/x/tools/cmd/[email protected] | ||
go generate ./... | ||
|
||
## Check generated files are up to date | ||
check-go-generated: generate | ||
git diff | (! grep .) | ||
|
||
## Run go test | ||
go-test: | ||
CGO_ENABLED=0 go test -v -covermode=atomic ./... | ||
|
||
## Run all tests and linters | ||
test: go-test lint | ||
|
||
# https://gist.github.com/prwhite/8168133 | ||
# COLORS | ||
GREEN := $(shell tput -Txterm setaf 2) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
nvme-wipe |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package main | ||
|
||
import ( | ||
"context" | ||
"flag" | ||
"time" | ||
|
||
"github.com/metal-toolbox/ironlib/utils" | ||
"github.com/sirupsen/logrus" | ||
) | ||
|
||
var ( | ||
device = flag.String("device", "/dev/nvmeX", "nvme disk to wipe") | ||
verbose = flag.Bool("verbose", false, "show command runs and output") | ||
dur = flag.String("timeout", (1 * time.Minute).String(), "time to wait for command to complete") | ||
) | ||
|
||
func main() { | ||
flag.Parse() | ||
|
||
logger := logrus.New() | ||
logger.Formatter = new(logrus.TextFormatter) | ||
logger.SetLevel(logrus.TraceLevel) | ||
|
||
timeout, err := time.ParseDuration(*dur) | ||
if err != nil { | ||
logger.WithError(err).Fatal("failed to parse timeout duration") | ||
} | ||
|
||
nvme := utils.NewNvmeCmd(*verbose) | ||
|
||
ctx, cancel := context.WithTimeout(context.Background(), timeout) | ||
defer cancel() | ||
|
||
logger.Info("wiping") | ||
err = nvme.WipeDisk(ctx, logger, *device) | ||
if err != nil { | ||
logger.WithError(err).Fatal("exiting") | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.