Skip to content

Commit f897f65

Browse files
committed
go/runtime/host/tdx: Add support for RW drives and formats
1 parent fb92f74 commit f897f65

File tree

3 files changed

+14
-1
lines changed

3 files changed

+14
-1
lines changed

.changelog/5981.feature.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
go/runtime/host/tdx: Add support for RW drives and formats

go/runtime/bundle/component.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,8 @@ type TDXMetadata struct {
199199

200200
// Stage2Image is the name of the stage 2 VM image file.
201201
Stage2Image string `json:"stage2_image,omitempty"`
202+
// Stage2Format is the format of the stage 2 VM image file. Empty means raw.
203+
Stage2Format string `json:"stage2_format,omitempty"`
202204

203205
// Resources are the requested VM resources.
204206
Resources TDXResources `json:"resources"`

go/runtime/host/tdx/qemu.go

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,10 +155,20 @@ func (q *qemuProvisioner) getSandboxConfig(rtCfg host.Config, _ sandbox.Connecto
155155
// Configure stage 2 image.
156156
if tdxCfg.HasStage2() {
157157
stage2Image := comp.ExplodedPath(tdxCfg.Stage2Image)
158+
stage2Format := tdxCfg.Stage2Format
159+
switch stage2Format {
160+
case "":
161+
// Default to raw format.
162+
stage2Format = "raw"
163+
case "raw", "qcow2":
164+
// These formats are supported as-is.
165+
default:
166+
return process.Config{}, fmt.Errorf("format '%s' is not supported", stage2Format)
167+
}
158168

159169
cfg.Args = append(cfg.Args,
160170
// Stage 2 drive.
161-
"-drive", fmt.Sprintf("format=raw,file=%s,if=none,id=drive0,read-only=on", stage2Image),
171+
"-drive", fmt.Sprintf("format=%s,file=%s,if=none,id=drive0,snapshot=on", stage2Format, stage2Image),
162172
"-device", "virtio-blk-pci,drive=drive0",
163173
)
164174
}

0 commit comments

Comments
 (0)