Skip to content

Commit

Permalink
Move blkdiscard example into diskwipe
Browse files Browse the repository at this point in the history
Better off in diskwipe than solo.
  • Loading branch information
mmlb committed Jun 10, 2024
1 parent 01ffcd9 commit 1b9927d
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 55 deletions.
46 changes: 0 additions & 46 deletions examples/blkdiscard/main.go

This file was deleted.

32 changes: 23 additions & 9 deletions examples/diskwipe/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package main
import (
"context"
"flag"
"strings"
"time"

"github.com/bmc-toolbox/common"
Expand Down Expand Up @@ -65,15 +66,28 @@ func main() {
case "nvme":
wiper = utils.NewNvmeCmd(*verbose)
case "sata":
wiper = utils.NewFillZeroCmd(*verbose)

// If the user supplied a non-default timeout then we'll honor it, otherwise we just go with a huge timeout.
// If this were *real* code and not an example some work could be done to guesstimate a timeout based on disk size.
if timeout == defaultTimeout {
l.WithField("timeout", timeout.String()).Info("increasing timeout")
timeout = 24 * time.Hour
ctx, cancel = context.WithTimeout(context.WithoutCancel(ctx), timeout)
defer cancel()
// Lets see if drive supports TRIM, if so we'll use blkdiscard
for _, cap := range drive.Capabilities {
if strings.HasPrefix(cap.Description, "Data Set Management TRIM supported") {
if cap.Enabled {
wiper = utils.NewBlkdiscardCmd(*verbose)
}
break
}
}

// drive does not support TRIM so we fall back to filling it up with zero
if wiper == nil {
wiper = utils.NewFillZeroCmd(*verbose)

// If the user supplied a non-default timeout then we'll honor it, otherwise we just go with a huge timeout.
// If this were *real* code and not an example some work could be done to guesstimate a timeout based on disk size.
if timeout == defaultTimeout {
l.WithField("timeout", timeout.String()).Info("increasing timeout")
timeout = 24 * time.Hour
ctx, cancel = context.WithTimeout(context.WithoutCancel(ctx), timeout)
defer cancel()
}
}
}

Expand Down

0 comments on commit 1b9927d

Please sign in to comment.