Skip to content
This repository has been archived by the owner on Aug 12, 2021. It is now read-only.

Commit

Permalink
use MiB for raw disk allocations
Browse files Browse the repository at this point in the history
  • Loading branch information
bluestealth committed Sep 2, 2020
1 parent 8856173 commit c44418a
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
9 changes: 8 additions & 1 deletion pkg/common/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
"path/filepath"
"syscall"

"github.com/docker/go-units"
"github.com/docker/machine/libmachine/drivers"
"github.com/docker/machine/libmachine/mcnflag"
"github.com/docker/machine/libmachine/mcnutils"
Expand Down Expand Up @@ -52,6 +53,12 @@ func (d *CommonDriver) SetConfigFromFlags(flags drivers.DriverOptions) error {
return nil
}

func diskSizeInMiB(diskSizeMB int) int64 {
result := int64(diskSizeMB)
result *= units.MiB
return result
}

func createRawDiskImage(sshKeyPath, diskPath string, diskSizeMb int) error {
tarBuf, err := mcnutils.MakeDiskImage(sshKeyPath)
if err != nil {
Expand All @@ -74,7 +81,7 @@ func createRawDiskImage(sshKeyPath, diskPath string, diskSizeMb int) error {
return errors.Wrapf(err, "closing file %s", diskPath)
}

if err := os.Truncate(diskPath, int64(diskSizeMb*1000000)); err != nil {
if err := os.Truncate(diskPath, diskSizeInMiB(diskSizeMb)); err != nil {
return errors.Wrap(err, "truncate")
}
return nil
Expand Down
2 changes: 1 addition & 1 deletion pkg/common/common_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ func Test_createDiskImage(t *testing.T) {
diskPath := filepath.Join(tmpdir, "disk")

sizeInMb := 100
sizeInBytes := int64(sizeInMb) * 1000000
sizeInBytes := int64(104857600)
if err := createRawDiskImage(sshPath, diskPath, sizeInMb); err != nil {
t.Errorf("createDiskImage() error = %v", err)
}
Expand Down

0 comments on commit c44418a

Please sign in to comment.