Skip to content
This repository has been archived by the owner on Jul 16, 2020. It is now read-only.

Commit

Permalink
ciao-launcher: Use MiB in the launcher storage code
Browse files Browse the repository at this point in the history
This makes us more consistent with the rest of ciao and general industry
expectations.

Fixes: #990

Signed-off-by: Rob Bradford <[email protected]>
  • Loading branch information
rbradford committed Jan 16, 2017
1 parent 3d1ed2b commit 6b01622
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 13 deletions.
2 changes: 1 addition & 1 deletion ciao-launcher/docker.go
Original file line number Diff line number Diff line change
Expand Up @@ -495,7 +495,7 @@ func (d *docker) computeInstanceDiskspace() int {
return -1
}

return int(*con.SizeRootFs / 1000000)
return int(*con.SizeRootFs / (1024 * 1024))
}

func (d *docker) stats() (disk, memory, cpu int) {
Expand Down
4 changes: 2 additions & 2 deletions ciao-launcher/docker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -775,8 +775,8 @@ func TestDockerStats(t *testing.T) {
t.Errorf("Expected memory usage of 100. Got %d", mem)
}

if disk != 10 {
t.Errorf("Expected disk usage of 10. Got %d", disk)
if disk != 9 {
t.Errorf("Expected disk usage of 9. Got %d", disk)
}

if cpu != -1 {
Expand Down
18 changes: 9 additions & 9 deletions ciao-launcher/qemu.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,9 @@ func (q *qemuV) init(cfg *vmConfig, instanceDir string) {
}

func extractImageInfo(r io.Reader) int {
imageSizeMB := -1
imageSizeMiB := -1
scanner := bufio.NewScanner(r)
for scanner.Scan() && imageSizeMB == -1 {
for scanner.Scan() && imageSizeMiB == -1 {
line := scanner.Text()
matches := virtualSizeRegexp.FindStringSubmatch(line)
if matches == nil {
Expand All @@ -109,20 +109,20 @@ func extractImageInfo(r io.Reader) int {
break
}

size := sizeInBytes / (1000 * 1000)
size := sizeInBytes / (1024 * 1024)
if size > int64((^uint(0))>>1) {
glog.Warningf("Unexpectedly large disk size found: %d MB",
glog.Warningf("Unexpectedly large disk size found: %d MiB",
size)
break
}

imageSizeMB = int(size)
if int64(imageSizeMB)*1000*1000 < sizeInBytes {
imageSizeMB++
imageSizeMiB = int(size)
if int64(imageSizeMiB)*1024*1024 < sizeInBytes {
imageSizeMiB++
}
}

return imageSizeMB
return imageSizeMiB
}

func (q *qemuV) imageInfo(imagePath string) (int, error) {
Expand Down Expand Up @@ -683,7 +683,7 @@ func (q *qemuV) computeInstanceDiskspace(instanceDir string) int {
if err != nil {
return -1
}
return int(fi.Size() / 1000000)
return int(fi.Size() / (1024 * 1024))
}

func (q *qemuV) stats() (disk, memory, cpu int) {
Expand Down
2 changes: 1 addition & 1 deletion ciao-launcher/qemu_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ func TestExtractImageInfo(t *testing.T) {
}{
{
"imageInfoTestGood",
908,
865,
imageInfoTestGood,
},
{
Expand Down

0 comments on commit 6b01622

Please sign in to comment.