Skip to content

Commit

Permalink
Add blkdiscard support for disk wipe (#91)
Browse files Browse the repository at this point in the history
Uses ironlib's blkdiscard support to wipe disks that support TRIM.
  • Loading branch information
mmlb authored Jul 3, 2024
2 parents 42213c8 + 2cd04a1 commit 90681f6
Showing 1 changed file with 20 additions and 2 deletions.
22 changes: 20 additions & 2 deletions cmd/disk_wipe.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"context"
"errors"
"os"
"strings"
"time"

"github.com/bmc-toolbox/common"
Expand All @@ -15,6 +16,7 @@ import (
"github.com/spf13/cobra"
)

// nolint:gocyclo // easier to read in one big function I think
func init() {
cmd := &cobra.Command{
Use: "wipe /dev/disk",
Expand Down Expand Up @@ -74,14 +76,30 @@ func init() {

// Pick the most appropriate wipe based on the disk type and/or features supported
var wiper actions.DriveWiper
// nolint:gocritic // will have more cases soon, remove nolint then
switch drive.Protocol {
case "nvme":
wiper = utils.NewNvmeCmd(verbose)
case "sata":
// Lets figure out if the drive supports TRIM
var trim bool
for _, cap := range drive.Capabilities {
if strings.HasPrefix(cap.Description, "Data Set Management TRIM supported") {
trim = cap.Enabled
break
}
}

if trim {
// Drive supports TRIM, so we use blkdiscard
wiper = utils.NewBlkdiscardCmd(verbose)
}
}

if wiper == nil {
l.Fatal("failed find appropriate wiper drive")
l.WithFields(logrus.Fields{
"capabilities": drive.Capabilities,
"protocol": drive.Protocol,
}).Fatal("failed find appropriate drive wiper")
}

err = wiper.WipeDrive(ctx, logger, drive)
Expand Down

0 comments on commit 90681f6

Please sign in to comment.