Skip to content

Commit

Permalink
extract disk wiping from disk partitioning
Browse files Browse the repository at this point in the history
Signed-off-by: Moath Qasim <[email protected]>
  • Loading branch information
moadqassem committed Sep 15, 2022
1 parent 5f58001 commit 7d47827
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 25 deletions.
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
}

0 comments on commit 7d47827

Please sign in to comment.