Adds Builder and VM Manager interfaces + implementation for UVM#2597
Adds Builder and VM Manager interfaces + implementation for UVM#2597rawahars wants to merge 3 commits intomicrosoft:mainfrom
Conversation
207c612 to
00b1f90
Compare
Refactor UVM responsibilities into clear builder vs vmmanager packages and document the intended 3-layer VM model. Key changes: - Introduce internal/vm/builder for HCS compute system construction. - Introduce internal/vm/vmmanager for host-side lifecycle/resource control. - Move UVM interfaces and shared types into focused locations. - Add internal/vm/README.md describing layer boundaries and usage flow. - Remove legacy internal/vm/hcs files and rename/move implementations. Signed-off-by: Harsh Rawat <harshrawat@microsoft.com>
Signed-off-by: Harsh Rawat <harshrawat@microsoft.com>
00b1f90 to
7519c12
Compare
internal/vm/vmmanager/vmsocket.go
Outdated
|
|
||
| var _ VMSocketManager = (*UtilityVM)(nil) | ||
|
|
||
| func (uvm *UtilityVM) VMSocketListen(connID guid.GUID) (net.Listener, error) { |
There was a problem hiding this comment.
This is in the wrong spot. Should be a higher level package IMO
There was a problem hiding this comment.
Yes, that sounds good. We can implement this in VM Controller too since we can extract the VM's ID via this interface.
internal/vm/vmmanager/scsi.go
Outdated
| request := &hcsschema.ModifySettingRequest{ | ||
| RequestType: guestrequest.RequestTypeAdd, | ||
| Settings: hcsschema.Attachment{ | ||
| Path: disk.Path, |
There was a problem hiding this comment.
Why do we copy the disk? Why cant we just assign it to settings?
There was a problem hiding this comment.
I’ve updated this to assign the disk directly. I avoided this before because the old shim only set specific fields, but since we can move that logic to the upper layer, we can pass the whole object.
| } | ||
|
|
||
| // Cache the VM ID of the utility VM. | ||
| properties, err := cs.Properties(ctx) |
There was a problem hiding this comment.
Do the properties return in any compute system state?
There was a problem hiding this comment.
In this specific method, the properties are queried to get the RuntimeID.
For higher layers, we have a method PropertiesV2 under LifetimeManager which can be used to query properties.
|
|
||
| defer func() { | ||
| if cs != nil { | ||
| _ = cs.Terminate(ctx) |
There was a problem hiding this comment.
We dont start it why do we need terminate? Just delete right?
There was a problem hiding this comment.
No at the point when this defer is registered, we would have started the compute system. If there is a failure in Properties call, we move to terminate it.
| request := &hcsschema.ModifySettingRequest{ | ||
| ResourcePath: fmt.Sprintf(resourcepaths.VirtualPCIResourceFormat, vmbusGUID), | ||
| RequestType: guestrequest.RequestTypeAdd, | ||
| Settings: hcsschema.VirtualPciDevice{ |
There was a problem hiding this comment.
Seems like we should actually have the API for the PCI device, and then this one is actually add function
internal/vm/builder/scsi.go
Outdated
| } | ||
|
|
||
| ctrl.Attachments[lun] = disk | ||
| uvmb.doc.VirtualMachine.Devices.Scsi[controller] = ctrl |
There was a problem hiding this comment.
I've forgotten my golang. Can you not do this in place without the copy out / update model?
There was a problem hiding this comment.
Yes, nice catch! I have removed it and added a test too.
|
|
||
| var _ ProcessorOptions = (*UtilityVM)(nil) | ||
|
|
||
| func (uvmb *UtilityVM) SetProcessorLimits(config *hcsschema.VirtualMachineProcessor) { |
There was a problem hiding this comment.
This one is odd. If you had the VirtualMachineProcessor you would have already set its .Count/.Limit/,Weight and they would be in the builder right? Seems like if we need this overload we would want it to reflect a smaller set of just count/limit/weight overrides
internal/vm/builder/device.go
Outdated
| return errors.Wrapf(errAlreadySet, "device %v already assigned to utility VM", device) | ||
| } | ||
|
|
||
| vmbusGUID, err := guid.NewV4() |
There was a problem hiding this comment.
The caller should pass this guid. You will need in in the controller layers for save/restore alignment.
There was a problem hiding this comment.
Nice catch! Changed this.
internal/vm/builder/device.go
Outdated
| } | ||
|
|
||
| func (uvmb *UtilityVM) SetSerialConsole(port uint32, listenerPath string) error { | ||
| if !strings.HasPrefix(listenerPath, `\\.\pipe\`) { |
There was a problem hiding this comment.
You should also allow the administrators pipe prefix
There was a problem hiding this comment.
The administrators pipe prefix(\\.\pipe\ProtectedPrefix\Administrator\) is already allowed since it starts with \\.\pipe\. I've added a test case to explicitly verify this.
| case vm.Windows: | ||
| doc.VirtualMachine.Devices.VirtualSmb = &hcsschema.VirtualSmb{} | ||
| case vm.Linux: | ||
| doc.VirtualMachine.Devices.Plan9 = &hcsschema.Plan9{} |
There was a problem hiding this comment.
We should add this at the time of its use right? We dont want 9pfs if the caller has no shares right?
There was a problem hiding this comment.
IIRC these are added pre-emptively so that HCS can perform warm-up logic on its end.
Signed-off-by: Harsh Rawat <harshrawat@microsoft.com>
This pull request introduces a major refactor and formalization of the Utility VM (UVM) builder and management interfaces. It separates the responsibilities for VM configuration, host-side management, and guest-side actions into clear, testable layers. The changes include a new, well-documented builder interface, VM manager interface, concrete builder and VM manager implementations, along with comprehensive unit tests for the builder's functionality.
The most important changes are:
Architectural Refactor and Documentation
README.mdto theinternal/vmpackage, clearly explaining the separation of concerns between the Builder, VM Manager, and Guest Manager layers, and documenting the responsibilities and flow for each layer.Builder Interface and Implementation
UVMBuilderinterface with a new, comprehensiveBuilderinterface ininternal/vm/builder.go, providing modular access to memory, processor, NUMA, device, boot, and storage QoS configuration managers.Builderinterface ininternal/vm/builder/builder.gofor creating and configuringhcsschema.ComputeSystemdocuments.VM Manager Interface and Implementation
Testing
These changes establish a foundation for future VM configuration and management features.