Skip to content

Commit f2636a7

Browse files
author
John Howard
committed
Annotation for preferred rootfs type
Signed-off-by: John Howard <jhoward@microsoft.com>
1 parent 263722c commit f2636a7

File tree

2 files changed

+46
-13
lines changed

2 files changed

+46
-13
lines changed

cmd/runhcs/container.go

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,26 @@ func parseAnnotationsBool(a map[string]string, key string) *bool {
241241
return nil
242242
}
243243

244+
// parseAnnotationsPreferredRootFSType searches `a` for `key` and verifies that the
245+
// value is in the set of allowed values. If `key` is not found returns `nil`.
246+
// Otherwise returns the index at which it was found in allowed values.
247+
func parseAnnotationsPreferredRootFSType(a map[string]string, key string) *uvm.PreferredRootFSType {
248+
if v, ok := a[key]; ok {
249+
// Following array must match enumeration uvm.PreferredRootFSType indexes
250+
possibles := []string{"initrd", "vhd"}
251+
for index, possible := range possibles {
252+
if possible == v {
253+
prfstype := uvm.PreferredRootFSType(index)
254+
return &prfstype
255+
}
256+
}
257+
logrus.Warningf("annotation: '%s', with value: '%s' must be one of %+v", key, v, possibles)
258+
return nil
259+
260+
}
261+
return nil
262+
}
263+
244264
// parseAnnotationsUint32 searches `a` for `key` and if found verifies that the
245265
// value is a 32 bit unsigned integer. If `key` is not found returns `nil`.
246266
func parseAnnotationsUint32(a map[string]string, key string) *uint32 {
@@ -449,6 +469,7 @@ func createContainer(cfg *containerConfig) (_ *container, err error) {
449469
annotationEnableDeferredCommit = "io.microsoft.virtualmachine.computetopology.memory.enabledeferredcommit"
450470
annotationVPMemCount = "io.microsoft.virtualmachine.devices.virtualpmem.maximumcount"
451471
annotationVPMemSize = "io.microsoft.virtualmachine.devices.virtualpmem.maximumsizebytes"
472+
annotationPreferredRootFSType = "io.microsoft.virtualmachine.lcow.preferredrootfstype"
452473
)
453474

454475
opts := &uvm.UVMOptions{
@@ -461,6 +482,7 @@ func createContainer(cfg *containerConfig) (_ *container, err error) {
461482
EnableDeferredCommit: parseAnnotationsBool(cfg.Spec.Annotations, annotationEnableDeferredCommit),
462483
VPMemDeviceCount: parseAnnotationsUint32(cfg.Spec.Annotations, annotationVPMemCount),
463484
VPMemSizeBytes: parseAnnotationsUint64(cfg.Spec.Annotations, annotationVPMemSize),
485+
PreferredRootFSType: parseAnnotationsPreferredRootFSType(cfg.Spec.Annotations, annotationPreferredRootFSType),
464486
}
465487

466488
shim, err := c.startVMShim(cfg.VMLogFile, opts)

internal/uvm/create.go

Lines changed: 24 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -44,20 +44,31 @@ type UVMOptions struct {
4444
LayerFolders []string // Set of folders for base layers and scratch. Ordered from top most read-only through base read-only layer, followed by scratch
4545

4646
// LCOW specific parameters
47-
BootFilesPath string // Folder in which kernel and root file system reside. Defaults to \Program Files\Linux Containers
48-
KernelFile string // Filename under BootFilesPath for the kernel. Defaults to `kernel`
49-
RootFSFile string // Filename under BootFilesPath for the UVMs root file system. Defaults are `initrd.img` or `rootfs.vhd`.
50-
PreferredRootFSType *PreferredRootFSType // Controls searching for the RootFSFile.
51-
KernelBootOptions string // Additional boot options for the kernel
52-
EnableGraphicsConsole bool // If true, enable a graphics console for the utility VM
53-
ConsolePipe string // The named pipe path to use for the serial console. eg \\.\pipe\vmpipe
54-
SCSIControllerCount *int // The number of SCSI controllers. Defaults to 1 if omitted. Currently we only support 0 or 1.
47+
BootFilesPath string // Folder in which kernel and root file system reside. Defaults to \Program Files\Linux Containers
48+
KernelFile string // Filename under BootFilesPath for the kernel. Defaults to `kernel`
49+
RootFSFile string // Filename under BootFilesPath for the UVMs root file system. Defaults are `initrd.img` or `rootfs.vhd`.
50+
KernelBootOptions string // Additional boot options for the kernel
51+
EnableGraphicsConsole bool // If true, enable a graphics console for the utility VM
52+
ConsolePipe string // The named pipe path to use for the serial console. eg \\.\pipe\vmpipe
53+
SCSIControllerCount *int // The number of SCSI controllers. Defaults to 1 if omitted. Currently we only support 0 or 1.
5554

5655
// Fields that can be configured via OCI annotations in runhcs.
57-
AllowOvercommit *bool // Memory for UVM. Defaults to true. For physical backed memory, set to false. io.microsoft.virtualmachine.computetopology.memory.allowovercommit=true|false
58-
EnableDeferredCommit *bool // Memory for UVM. Defaults to false. For virtual memory with deferred commit, set to true. io.microsoft.virtualmachine.computetopology.memory.enabledeferredcommit=true|false
59-
VPMemDeviceCount *uint32 // Number of VPMem devices. Limit at 128. If booting UVM from VHD, device 0 is taken. LCOW Only. io.microsoft.virtualmachine.devices.virtualpmem.maximumcount
60-
VPMemSizeBytes *uint64 // Size of the VPMem devices. LCOW Only. Defaults to 4GB. io.microsoft.virtualmachine.devices.virtualpmem.maximumsizebytes
56+
57+
// Memory for UVM. Defaults to true. For physical backed memory, set to false. io.microsoft.virtualmachine.computetopology.memory.allowovercommit=true|false
58+
AllowOvercommit *bool
59+
60+
// Memory for UVM. Defaults to false. For virtual memory with deferred commit, set to true. io.microsoft.virtualmachine.computetopology.memory.enabledeferredcommit=true|false
61+
EnableDeferredCommit *bool
62+
63+
// Number of VPMem devices. Limit at 128. If booting UVM from VHD, device 0 is taken. LCOW Only. io.microsoft.virtualmachine.devices.virtualpmem.maximumcount
64+
VPMemDeviceCount *uint32
65+
66+
// Size of the VPMem devices. LCOW Only. Defaults to 4GB. io.microsoft.virtualmachine.devices.virtualpmem.maximumsizebytes
67+
VPMemSizeBytes *uint64
68+
69+
// Controls searching for the RootFSFile. Defaults to initrd (0). Can be set to VHD (1). io.microsoft.virtualmachine.lcow.preferredrootfstype
70+
// Note this uses an arbitrary annotation strict which has no direct mapping to the HCS schema.
71+
PreferredRootFSType *PreferredRootFSType
6172
}
6273

6374
const linuxLogVsockPort = 109
@@ -101,7 +112,7 @@ func Create(opts *UVMOptions) (_ *UtilityVM, err error) {
101112
attachments := make(map[string]hcsschema.Attachment)
102113
scsi := make(map[string]hcsschema.Scsi)
103114
uvm.scsiControllerCount = 1
104-
var actualRootFSType PreferredRootFSType = PreferredRootFSTypeInitRd // TODO Should we switch to VPMem/VHD as default?
115+
var actualRootFSType PreferredRootFSType = PreferredRootFSTypeInitRd
105116

106117
if uvm.operatingSystem == "windows" {
107118
if len(opts.LayerFolders) < 2 {

0 commit comments

Comments
 (0)