Skip to content

Commit 36f0201

Browse files
committed
Make copies of the VMGS for each confidential pod
Even though VMGS files aren't written to, we can't share the same file across multiple pods because HCS seems to be taking an exclusive lock on the file. To handle this, we make copies of the VMGS file (similar to how we make copies of the EFI VHD) per pod. This commit also changes the name of the default VMGS file to `cwcow.snp.vmgs` to better convey that by default we run in SNP mode. If a different VMGS file is desired, `"io.microsoft.virtualmachine.wcow.gueststatefile"` annotation can be used to override that. This commit also adds the code to handle the UVM console pipe annotation, if provided, for windows pods. Signed-off-by: Amit Barve <ambarve@microsoft.com>
1 parent cf12ec2 commit 36f0201

File tree

3 files changed

+14
-3
lines changed

3 files changed

+14
-3
lines changed

cmd/containerd-shim-runhcs-v1/pod.go

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ func initializeWCOWBootFiles(ctx context.Context, wopts *uvm.OptionsWCOW, rootfs
3737
if s.Windows != nil {
3838
layerFolders = s.Windows.LayerFolders
3939
}
40+
log.G(ctx).WithField("options", log.Format(ctx, *wopts)).Debug("initialize WCOW boot files")
4041

4142
wopts.BootFiles, err = layers.GetWCOWUVMBootFilesFromLayers(ctx, rootfs, layerFolders)
4243
if err != nil {
@@ -50,6 +51,16 @@ func initializeWCOWBootFiles(ctx context.Context, wopts *uvm.OptionsWCOW, rootfs
5051
// we use measured EFI & rootfs for confidential UVMs, use those instead of the ones passed in layers/rootfs
5152
wopts.BootFiles.BlockCIMFiles.EFIVHDPath = uvm.GetDefaultConfidentialEFIPath()
5253
wopts.BootFiles.BlockCIMFiles.BootCIMVHDPath = uvm.GetDefaultConfidentialBootCIMPath()
54+
55+
// make a copy of the vmgs file as the same vmgs can not be used by multiple pods in parallel
56+
// TODO(ambarve): for C-LCOW we make a copy in the bundle directory, is it better
57+
// to use the bundle directory instead of the snapshot directory?
58+
vmgsCopyPath := filepath.Join(filepath.Dir(wopts.BootFiles.BlockCIMFiles.ScratchVHDPath), filepath.Base(wopts.GuestStateFilePath))
59+
if err := copyfile.CopyFile(ctx, wopts.GuestStateFilePath, vmgsCopyPath, false); err != nil {
60+
return fmt.Errorf("failed to make a copy of VMGS: %w", err)
61+
}
62+
wopts.GuestStateFilePath = vmgsCopyPath
63+
5364
} else if wopts.BootFiles.BootType == uvm.BlockCIMBoot {
5465
// Supporting hyperv isolation with block CIM layers requires changes in
5566
// the image pull path to prepare the EFI VHD. But more importantly, since both the
@@ -69,7 +80,7 @@ func initializeWCOWBootFiles(ctx context.Context, wopts *uvm.OptionsWCOW, rootfs
6980
// UVM.
7081
writableEFIVHDPath := filepath.Join(filepath.Dir(wopts.BootFiles.BlockCIMFiles.ScratchVHDPath), filepath.Base(wopts.BootFiles.BlockCIMFiles.EFIVHDPath))
7182
if err := copyfile.CopyFile(ctx, wopts.BootFiles.BlockCIMFiles.EFIVHDPath, writableEFIVHDPath, false); err != nil {
72-
return fmt.Errorf("failed to copy EFI VHD at %s: %w", writableEFIVHDPath, err)
83+
return fmt.Errorf("failed to copy EFI VHD: %w", err)
7384
}
7485
wopts.BootFiles.BlockCIMFiles.EFIVHDPath = writableEFIVHDPath
7586
}

internal/oci/uvm.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -330,6 +330,7 @@ func specToUVMCreateOptionsCommon(ctx context.Context, opts *uvm.Options, s *spe
330330
opts.NumaProcessorCounts)
331331
opts.NumaMemoryBlocksCounts = ParseAnnotationCommaSeparatedUint64(ctx, s.Annotations, annotations.NumaCountOfMemoryBlocks,
332332
opts.NumaMemoryBlocksCounts)
333+
opts.ConsolePipe = ParseAnnotationsString(s.Annotations, iannotations.UVMConsolePipe, opts.ConsolePipe)
333334

334335
maps.Copy(opts.AdditionalHyperVConfig, parseHVSocketServiceTable(ctx, s.Annotations))
335336

@@ -376,7 +377,6 @@ func SpecToUVMCreateOpts(ctx context.Context, s *specs.Spec, id, owner string) (
376377
lopts.UVMReferenceInfoFile = ParseAnnotationsString(s.Annotations, annotations.LCOWReferenceInfoFile, lopts.UVMReferenceInfoFile)
377378
lopts.KernelBootOptions = ParseAnnotationsString(s.Annotations, annotations.KernelBootOptions, lopts.KernelBootOptions)
378379
lopts.DisableTimeSyncService = ParseAnnotationsBool(ctx, s.Annotations, annotations.DisableLCOWTimeSyncService, lopts.DisableTimeSyncService)
379-
lopts.ConsolePipe = ParseAnnotationsString(s.Annotations, iannotations.UVMConsolePipe, lopts.ConsolePipe)
380380
handleAnnotationPreferredRootFSType(ctx, s.Annotations, lopts)
381381
handleAnnotationKernelDirectBoot(ctx, s.Annotations, lopts)
382382
handleAnnotationFullyPhysicallyBacked(ctx, s.Annotations, lopts)

internal/uvm/create_wcow.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ func defaultConfidentialWCOWOSBootFilesPath() string {
6666
}
6767

6868
func GetDefaultConfidentialVMGSPath() string {
69-
return filepath.Join(defaultConfidentialWCOWOSBootFilesPath(), "cwcow.vmgs")
69+
return filepath.Join(defaultConfidentialWCOWOSBootFilesPath(), "cwcow.snp.vmgs")
7070
}
7171

7272
func GetDefaultConfidentialBootCIMPath() string {

0 commit comments

Comments
 (0)