Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extract disk wiping from disk partitioning #91

Merged
merged 1 commit into from
Sep 21, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions actions/rootio/v1/cmd/rootio.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ var rootioCmd = &cobra.Command{
}

func init() {
rootioCmd.AddCommand(rootioWipe)
rootioCmd.AddCommand(rootioFormat)
rootioCmd.AddCommand(rootioPartition)
rootioCmd.AddCommand(rootioMount)
Expand Down Expand Up @@ -116,6 +117,29 @@ var rootioPartition = &cobra.Command{
},
}

var rootioWipe = &cobra.Command{
Use: "wipe",
Short: "Use rootio to wipe disks based upon metadata",
Run: func(cmd *cobra.Command, args []string) {
for disk := range metadata.Instance.Storage.Disks {
err := storage.VerifyBlockDevice(metadata.Instance.Storage.Disks[disk].Device)
if err != nil {
log.Error(err)
}
err = storage.ExamineDisk(metadata.Instance.Storage.Disks[disk])
if err != nil {
log.Error(err)
}

err = storage.Wipe(metadata.Instance.Storage.Disks[disk])
log.Infoln("Wiping")
if err != nil {
log.Error(err)
}
}
},
}

var rootioVersion = &cobra.Command{
Use: "version",
Short: "Version and Release information about the rootio storage manager",
Expand Down
25 changes: 0 additions & 25 deletions actions/rootio/v1/pkg/storage/partition.go
Original file line number Diff line number Diff line change
Expand Up @@ -197,28 +197,3 @@ func MBRPartition(d types.Disk) error {
}
return nil
}

// Wipe will clean the table from a disk.
func Wipe(d types.Disk) error {
disk, err := os.OpenFile(d.Device, os.O_CREATE|os.O_WRONLY, 0o644)
if err != nil {
return err
}
defer disk.Close()
bigBuff := make([]byte, 1024*1024*1024)
n, err := disk.Write(bigBuff)
if err != nil {
return err
}
log.Infof("Wrote [%d] bytes to [%s]", n, d.Device)
log.Infoln("Flushing writes to new partition")
err = disk.Sync()
if err != nil {
return err
}
err = disk.Close()
if err != nil {
return err
}
return nil
}
33 changes: 33 additions & 0 deletions actions/rootio/v1/pkg/storage/wipe.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package storage

import (
"os"

log "github.com/sirupsen/logrus"
"github.com/tinkerbell/hub/actions/rootio/v1/pkg/types.go"
)

// Wipe will clean the table from a disk.
func Wipe(d types.Disk) error {
disk, err := os.OpenFile(d.Device, os.O_CREATE|os.O_WRONLY, 0o644)
if err != nil {
return err
}
defer disk.Close()
bigBuff := make([]byte, 1024*1024*1024)
n, err := disk.Write(bigBuff)
if err != nil {
return err
}
log.Infof("Wrote [%d] bytes to [%s]", n, d.Device)
log.Infoln("Flushing writes to new partition")
err = disk.Sync()
if err != nil {
return err
}
err = disk.Close()
if err != nil {
return err
}
return nil
}