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

go/runtime/host/tdx: Resize overlay image if needed #6077

Merged
merged 1 commit into from
Feb 21, 2025
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
1 change: 1 addition & 0 deletions .changelog/6077.bugfix.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
go/runtime/host/tdx: Resize overlay image if needed
36 changes: 35 additions & 1 deletion go/runtime/host/tdx/qemu.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import (
"context"
"encoding/json"
"errors"
"fmt"
"net"
Expand Down Expand Up @@ -283,6 +284,25 @@
// Image already exists, perform a rebase operation to account for the backing file location
// changing (e.g. due to an upgrade).
cmd := exec.Command(
defaultQemuImgPath,
"info",
"--output", "json",
image,
)
var out strings.Builder
cmd.Stderr = &out
cmd.Stdout = &out
if err := cmd.Run(); err != nil {
return "", fmt.Errorf("failed to query base image: %s\n%w", out.String(), err)

Check warning on line 296 in go/runtime/host/tdx/qemu.go

View check run for this annotation

Codecov / codecov/patch

go/runtime/host/tdx/qemu.go#L287-L296

Added lines #L287 - L296 were not covered by tests
}
var info struct {
VirtualSize int `json:"virtual-size"`

Check warning on line 299 in go/runtime/host/tdx/qemu.go

View check run for this annotation

Codecov / codecov/patch

go/runtime/host/tdx/qemu.go#L298-L299

Added lines #L298 - L299 were not covered by tests
}
if err := json.Unmarshal([]byte(out.String()), &info); err != nil {
return "", fmt.Errorf("malformed base image metadata: %w", err)

Check warning on line 302 in go/runtime/host/tdx/qemu.go

View check run for this annotation

Codecov / codecov/patch

go/runtime/host/tdx/qemu.go#L301-L302

Added lines #L301 - L302 were not covered by tests
}

cmd = exec.Command(

Check warning on line 305 in go/runtime/host/tdx/qemu.go

View check run for this annotation

Codecov / codecov/patch

go/runtime/host/tdx/qemu.go#L305

Added line #L305 was not covered by tests
defaultQemuImgPath,
"rebase",
"-u",
Expand All @@ -291,12 +311,26 @@
"-F", format,
imageFn,
)
var out strings.Builder
out.Reset()

Check warning on line 314 in go/runtime/host/tdx/qemu.go

View check run for this annotation

Codecov / codecov/patch

go/runtime/host/tdx/qemu.go#L314

Added line #L314 was not covered by tests
cmd.Stderr = &out
cmd.Stdout = &out
if err := cmd.Run(); err != nil {
return "", fmt.Errorf("failed to rebase persistent overlay image: %s\n%w", out.String(), err)
}

// Perform a resize if needed.
cmd = exec.Command(
defaultQemuImgPath,
"resize",
imageFn,
fmt.Sprintf("%d", info.VirtualSize),
)
out.Reset()
cmd.Stderr = &out
cmd.Stdout = &out
if err := cmd.Run(); err != nil {
return "", fmt.Errorf("failed to resize persistent overlay image: %s\n%w", out.String(), err)

Check warning on line 332 in go/runtime/host/tdx/qemu.go

View check run for this annotation

Codecov / codecov/patch

go/runtime/host/tdx/qemu.go#L322-L332

Added lines #L322 - L332 were not covered by tests
}
case errors.Is(err, os.ErrNotExist):
// Create image directory if it doesn't yet exist.
if err := common.Mkdir(imageDir); err != nil {
Expand Down
Loading