@@ -60,34 +60,6 @@ const (
6060 PreferredRootFSTypeInitRd PreferredRootFSType = iota
6161 PreferredRootFSTypeVHD
6262 PreferredRootFSTypeNA
63-
64- entropyVsockPort = 1
65- linuxLogVsockPort = 109
66- )
67-
68- const (
69- // InitrdFile is the default file name for an initrd.img used to boot LCOW.
70- InitrdFile = "initrd.img"
71- // VhdFile is the default file name for a rootfs.vhd used to boot LCOW.
72- VhdFile = "rootfs.vhd"
73- // DefaultDmVerityRootfsVhd is the default file name for a dmverity_rootfs.vhd,
74- // which is mounted by the GuestStateFile during boot and used as the root file
75- // system when booting in the SNP case. Similar to layer VHDs, the Merkle tree
76- // is appended after ext4 filesystem ends.
77- DefaultDmVerityRootfsVhd = "rootfs.vhd"
78- // KernelFile is the default file name for a kernel used to boot LCOW.
79- KernelFile = "kernel"
80- // UncompressedKernelFile is the default file name for an uncompressed
81- // kernel used to boot LCOW with KernelDirect.
82- UncompressedKernelFile = "vmlinux"
83- // GuestStateFile is the default file name for a vmgs (VM Guest State) file
84- // which contains the kernel and kernel command which mounts DmVerityVhdFile
85- // when booting in the SNP case.
86- GuestStateFile = "kernel.vmgs"
87- // UVMReferenceInfoFile is the default file name for a COSE_Sign1
88- // reference UVM info, which can be made available to workload containers
89- // and can be used for validation purposes.
90- UVMReferenceInfoFile = "reference_info.cose"
9163)
9264
9365type ConfidentialLCOWOptions struct {
@@ -143,17 +115,17 @@ func NewDefaultOptionsLCOW(id, owner string) *OptionsLCOW {
143115 kernelDirectSupported := osversion .Build () >= 18286
144116 opts := & OptionsLCOW {
145117 Options : newDefaultOptions (id , owner ),
146- KernelFile : KernelFile ,
118+ KernelFile : vmutils . KernelFile ,
147119 KernelDirect : kernelDirectSupported ,
148- RootFSFile : InitrdFile ,
120+ RootFSFile : vmutils . InitrdFile ,
149121 KernelBootOptions : "" ,
150122 UseGuestConnection : true ,
151123 ExecCommandLine : fmt .Sprintf ("/bin/gcs -v4 -log-format json -loglevel %s" , logrus .StandardLogger ().Level .String ()),
152124 ForwardStdout : false ,
153125 ForwardStderr : true ,
154126 OutputHandlerCreator : vmutils .ParseGCSLogrus ,
155- VPMemDeviceCount : DefaultVPMEMCount ,
156- VPMemSizeBytes : DefaultVPMemSizeBytes ,
127+ VPMemDeviceCount : vmutils . DefaultVPMEMCount ,
128+ VPMemSizeBytes : vmutils . DefaultVPMemSizeBytes ,
157129 VPMemNoMultiMapping : osversion .Get ().Build < osversion .V19H1 ,
158130 PreferredRootFSType : PreferredRootFSTypeInitRd ,
159131 EnableColdDiscardHint : false ,
@@ -163,7 +135,7 @@ func NewDefaultOptionsLCOW(id, owner string) *OptionsLCOW {
163135 ConfidentialLCOWOptions : & ConfidentialLCOWOptions {
164136 ConfidentialCommonOptions : & ConfidentialCommonOptions {
165137 SecurityPolicyEnabled : false ,
166- UVMReferenceInfoFile : UVMReferenceInfoFile ,
138+ UVMReferenceInfoFile : vmutils . DefaultUVMReferenceInfoFile ,
167139 },
168140 },
169141 }
@@ -196,29 +168,29 @@ func (opts *OptionsLCOW) UpdateBootFilesPath(ctx context.Context, path string) {
196168
197169 opts .BootFilesPath = path
198170
199- if _ , err := os .Stat (filepath .Join (opts .BootFilesPath , VhdFile )); err == nil {
171+ if _ , err := os .Stat (filepath .Join (opts .BootFilesPath , vmutils . VhdFile )); err == nil {
200172 // We have a rootfs.vhd in the boot files path. Use it over an initrd.img
201- opts .RootFSFile = VhdFile
173+ opts .RootFSFile = vmutils . VhdFile
202174 opts .PreferredRootFSType = PreferredRootFSTypeVHD
203175
204176 log .G (ctx ).WithFields (logrus.Fields {
205177 logfields .UVMID : opts .ID ,
206- VhdFile : filepath .Join (opts .BootFilesPath , VhdFile ),
207- }).Debug ("updated LCOW root filesystem to " + VhdFile )
178+ vmutils . VhdFile : filepath .Join (opts .BootFilesPath , vmutils . VhdFile ),
179+ }).Debug ("updated LCOW root filesystem to " + vmutils . VhdFile )
208180 }
209181
210182 if opts .KernelDirect {
211183 // KernelDirect supports uncompressed kernel if the kernel is present.
212184 // Default to uncompressed if on box. NOTE: If `kernel` is already
213185 // uncompressed and simply named 'kernel' it will still be used
214186 // uncompressed automatically.
215- if _ , err := os .Stat (filepath .Join (opts .BootFilesPath , UncompressedKernelFile )); err == nil {
216- opts .KernelFile = UncompressedKernelFile
187+ if _ , err := os .Stat (filepath .Join (opts .BootFilesPath , vmutils . UncompressedKernelFile )); err == nil {
188+ opts .KernelFile = vmutils . UncompressedKernelFile
217189
218190 log .G (ctx ).WithFields (logrus.Fields {
219- logfields .UVMID : opts .ID ,
220- UncompressedKernelFile : filepath .Join (opts .BootFilesPath , UncompressedKernelFile ),
221- }).Debug ("updated LCOW kernel file to " + UncompressedKernelFile )
191+ logfields .UVMID : opts .ID ,
192+ vmutils . UncompressedKernelFile : filepath .Join (opts .BootFilesPath , vmutils . UncompressedKernelFile ),
193+ }).Debug ("updated LCOW kernel file to " + vmutils . UncompressedKernelFile )
222194 }
223195 }
224196}
@@ -242,7 +214,7 @@ func fetchProcessor(ctx context.Context, opts *OptionsLCOW, uvm *UtilityVM) (*hc
242214 // We can set a cpu group for the VM at creation time in recent builds.
243215 if opts .CPUGroupID != "" {
244216 if osversion .Build () < osversion .V21H1 {
245- return nil , errCPUGroupCreateNotSupported
217+ return nil , vmutils . ErrCPUGroupCreateNotSupported
246218 }
247219 processor .CpuGroup = & hcsschema.CpuGroup {Id : opts .CPUGroupID }
248220 }
@@ -363,7 +335,7 @@ func makeLCOWVMGSDoc(ctx context.Context, opts *OptionsLCOW, uvm *UtilityVM) (_
363335 }
364336 }()
365337
366- dmVerityRootFsFullPath := filepath .Join (opts .BundleDirectory , DefaultDmVerityRootfsVhd )
338+ dmVerityRootFsFullPath := filepath .Join (opts .BundleDirectory , vmutils . DefaultDmVerityRootfsVhd )
367339 if err := copyfile .CopyFile (ctx , dmVerityRootfsTemplatePath , dmVerityRootFsFullPath , true ); err != nil {
368340 return nil , fmt .Errorf ("failed to copy DM Verity rootfs template file: %w" , err )
369341 }
@@ -425,7 +397,7 @@ func makeLCOWVMGSDoc(ctx context.Context, opts *OptionsLCOW, uvm *UtilityVM) (_
425397 // entropyVsockPort - 1 is the entropy port,
426398 // linuxLogVsockPort - 109 used by vsockexec to log stdout/stderr logging,
427399 // 0x40000000 + 1 (LinuxGcsVsockPort + 1) is the bridge (see guestconnectiuon.go)
428- hvSockets := []uint32 {entropyVsockPort , linuxLogVsockPort , prot .LinuxGcsVsockPort , prot .LinuxGcsVsockPort + 1 }
400+ hvSockets := []uint32 {vmutils . LinuxEntropyVsockPort , vmutils . LinuxLogVsockPort , prot .LinuxGcsVsockPort , prot .LinuxGcsVsockPort + 1 }
429401 hvSockets = append (hvSockets , opts .ExtraVSockPorts ... )
430402 for _ , whichSocket := range hvSockets {
431403 key := winio .VsockServiceID (whichSocket ).String ()
@@ -836,18 +808,18 @@ func makeLCOWDoc(ctx context.Context, opts *OptionsLCOW, uvm *UtilityVM) (_ *hcs
836808 }
837809
838810 // Inject initial entropy over vsock during init launch.
839- entropyArgs := fmt .Sprintf ("-e %d" , entropyVsockPort )
811+ entropyArgs := fmt .Sprintf ("-e %d" , vmutils . LinuxEntropyVsockPort )
840812
841813 // With default options, run GCS with stderr pointing to the vsock port
842814 // created below in order to forward guest logs to logrus.
843815 execCmdArgs := "/bin/vsockexec"
844816
845817 if opts .ForwardStdout {
846- execCmdArgs += fmt .Sprintf (" -o %d" , linuxLogVsockPort )
818+ execCmdArgs += fmt .Sprintf (" -o %d" , vmutils . LinuxLogVsockPort )
847819 }
848820
849821 if opts .ForwardStderr {
850- execCmdArgs += fmt .Sprintf (" -e %d" , linuxLogVsockPort )
822+ execCmdArgs += fmt .Sprintf (" -e %d" , vmutils . LinuxLogVsockPort )
851823 }
852824
853825 if opts .DisableTimeSyncService {
@@ -994,7 +966,7 @@ func CreateLCOW(ctx context.Context, opts *OptionsLCOW) (_ *UtilityVM, err error
994966 }
995967
996968 // Create a socket to inject entropy during boot.
997- uvm .entropyListener , err = uvm .listenVsock (entropyVsockPort )
969+ uvm .entropyListener , err = uvm .listenVsock (vmutils . LinuxEntropyVsockPort )
998970 if err != nil {
999971 return nil , err
1000972 }
@@ -1004,7 +976,7 @@ func CreateLCOW(ctx context.Context, opts *OptionsLCOW) (_ *UtilityVM, err error
1004976 if opts .ForwardStdout || opts .ForwardStderr {
1005977 uvm .outputHandler = opts .OutputHandlerCreator (opts .ID )
1006978 uvm .outputProcessingDone = make (chan struct {})
1007- uvm .outputListener , err = uvm .listenVsock (linuxLogVsockPort )
979+ uvm .outputListener , err = uvm .listenVsock (vmutils . LinuxLogVsockPort )
1008980 if err != nil {
1009981 return nil , err
1010982 }
0 commit comments