Skip to content

Commit

Permalink
Add blkdiscard based wipe for TRIM drives
Browse files Browse the repository at this point in the history
Expand drive wiping capabilities by using blkdiscard for devices that
support it.
  • Loading branch information
mmlb committed Jul 2, 2024
1 parent 67cb308 commit 2cd04a1
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion 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,10 +76,23 @@ 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 {
Expand Down

0 comments on commit 2cd04a1

Please sign in to comment.