Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 0 additions & 13 deletions internal/gcs/guestconnection.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@ import (
"strings"
"sync"

"github.com/Microsoft/go-winio"
"github.com/Microsoft/go-winio/pkg/guid"
"github.com/Microsoft/hcsshim/internal/cow"
"github.com/Microsoft/hcsshim/internal/hcs/schema1"
"github.com/Microsoft/hcsshim/internal/log"
Expand All @@ -34,17 +32,6 @@ const (
// the vsock port `port`.
type IoListenFunc func(port uint32) (net.Listener, error)

// HvsockIoListen returns an implementation of IoListenFunc that listens
// on the specified vsock port for the VM specified by `vmID`.
func HvsockIoListen(vmID guid.GUID) IoListenFunc {
return func(port uint32) (net.Listener, error) {
return winio.ListenHvsock(&winio.HvsockAddr{
VMID: vmID,
ServiceID: winio.VsockServiceID(port),
})
}
}

// GuestConnectionConfig contains options for creating a guest connection.
type GuestConnectionConfig struct {
// Conn specifies the connection to use for the bridge. It will be closed
Expand Down
18 changes: 15 additions & 3 deletions internal/oci/uvm.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,9 +156,13 @@ const (
// the TemplateID. It is the client's responsibility to make sure that the sandbox
// within which a cloned container needs to be created must also be created from the
// same template.
annotationTemplateID = "io.microsoft.virtualmachine.templateid"
annotationNetworkConfigProxy = "io.microsoft.network.ncproxy"
AnnotationNcproxyContainerID = "io.microsoft.network.ncproxy.containerid"
annotationTemplateID = "io.microsoft.virtualmachine.templateid"
annotationNetworkConfigProxy = "io.microsoft.network.ncproxy"
AnnotationNcproxyContainerID = "io.microsoft.network.ncproxy.containerid"
annotationsVMSource = "io.microsoft.virtualmachine.vmsource"
annotationVMServiceAddress = "io.microsoft.virtualmachine.vmservice.address"
annotationVMServiceBinPath = "io.microsoft.virtualmachine.vmservice.path"
annotationIgnoreSupportedCheck = "io.microsoft.virtualmachine.vmservice.ignoresupported"
)

// parseAnnotationsBool searches `a` for `key` and if found verifies that the
Expand Down Expand Up @@ -462,6 +466,10 @@ func SpecToUVMCreateOpts(ctx context.Context, s *specs.Spec, id, owner string) (
lopts.BootFilesPath = parseAnnotationsString(s.Annotations, annotationBootFilesRootPath, lopts.BootFilesPath)
lopts.CPUGroupID = parseAnnotationsString(s.Annotations, annotationCPUGroupID, lopts.CPUGroupID)
lopts.NetworkConfigProxy = parseAnnotationsString(s.Annotations, annotationNetworkConfigProxy, lopts.NetworkConfigProxy)
lopts.VMSource = parseAnnotationsString(s.Annotations, annotationsVMSource, lopts.VMSource)
lopts.VMServiceAddress = parseAnnotationsString(s.Annotations, annotationVMServiceAddress, lopts.VMServiceAddress)
lopts.VMServicePath = parseAnnotationsString(s.Annotations, annotationVMServiceBinPath, lopts.VMServicePath)
lopts.IgnoreSupportedCheck = parseAnnotationsBool(ctx, s.Annotations, annotationIgnoreSupportedCheck, lopts.IgnoreSupportedCheck)
handleAnnotationPreferredRootFSType(ctx, s.Annotations, lopts)
handleAnnotationKernelDirectBoot(ctx, s.Annotations, lopts)

Expand All @@ -486,6 +494,10 @@ func SpecToUVMCreateOpts(ctx context.Context, s *specs.Spec, id, owner string) (
wopts.CPUGroupID = parseAnnotationsString(s.Annotations, annotationCPUGroupID, wopts.CPUGroupID)
wopts.NetworkConfigProxy = parseAnnotationsString(s.Annotations, annotationNetworkConfigProxy, wopts.NetworkConfigProxy)
wopts.NoDirectMap = parseAnnotationsBool(ctx, s.Annotations, annotationVSMBNoDirectMap, wopts.NoDirectMap)
wopts.VMSource = parseAnnotationsString(s.Annotations, annotationsVMSource, wopts.VMSource)
wopts.VMServiceAddress = parseAnnotationsString(s.Annotations, annotationVMServiceAddress, wopts.VMServiceAddress)
wopts.VMServicePath = parseAnnotationsString(s.Annotations, annotationVMServiceBinPath, wopts.VMServicePath)
wopts.IgnoreSupportedCheck = parseAnnotationsBool(ctx, s.Annotations, annotationIgnoreSupportedCheck, wopts.IgnoreSupportedCheck)
handleAnnotationFullyPhysicallyBacked(ctx, s.Annotations, wopts)
if err := handleCloneAnnotations(ctx, s.Annotations, wopts); err != nil {
return nil, err
Expand Down
15 changes: 5 additions & 10 deletions internal/uvm/clone.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,11 @@ import (
"fmt"

"github.com/Microsoft/hcsshim/internal/cow"
hcsschema "github.com/Microsoft/hcsshim/internal/hcs/schema2"
"github.com/Microsoft/hcsshim/internal/vm"
"github.com/pkg/errors"
)

const (
hcsComputeSystemSaveType = "AsTemplate"
// default namespace ID used for all template and clone VMs.
DEFAULT_CLONE_NETWORK_NAMESPACE_ID = "89EB8A86-E253-41FD-9800-E6D88EB2E18A"
)
Expand Down Expand Up @@ -55,8 +54,8 @@ type Cloneable interface {
// A struct to keep all the information that might be required during cloning process of
// a resource.
type cloneData struct {
// doc spec for the clone
doc *hcsschema.ComputeSystem
// Builder for the virtual machine document.
builder vm.UVMBuilder
// scratchFolder of the clone
scratchFolder string
// UVMID of the clone
Expand Down Expand Up @@ -112,14 +111,10 @@ func (uvm *UtilityVM) GenerateTemplateConfig() (*UVMTemplateConfig, error) {
// uvm must be in the paused state before it can be saved as a template.save call will throw
// an incorrect uvm state exception if uvm is not in the paused state at the time of saving.
func (uvm *UtilityVM) SaveAsTemplate(ctx context.Context) error {
if err := uvm.hcsSystem.Pause(ctx); err != nil {
if err := uvm.vm.Pause(ctx); err != nil {
return errors.Wrap(err, "error pausing the VM")
}

saveOptions := hcsschema.SaveOptions{
SaveType: hcsComputeSystemSaveType,
}
if err := uvm.hcsSystem.Save(ctx, saveOptions); err != nil {
if err := uvm.vm.Save(ctx); err != nil {
return errors.Wrap(err, "error saving the VM")
}
return nil
Expand Down
48 changes: 21 additions & 27 deletions internal/uvm/combine_layers.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,15 @@ func (uvm *UtilityVM) CombineLayersWCOW(ctx context.Context, layerPaths []hcssch
if uvm.operatingSystem != "windows" {
return errNotSupported
}
msr := &hcsschema.ModifySettingRequest{
GuestRequest: guestrequest.GuestRequest{
ResourceType: guestrequest.ResourceTypeCombinedLayers,
RequestType: requesttype.Add,
Settings: guestrequest.CombinedLayers{
ContainerRootPath: containerRootPath,
Layers: layerPaths,
},
guestReq := guestrequest.GuestRequest{
ResourceType: guestrequest.ResourceTypeCombinedLayers,
RequestType: requesttype.Add,
Settings: guestrequest.CombinedLayers{
ContainerRootPath: containerRootPath,
Layers: layerPaths,
},
}
return uvm.modify(ctx, msr)
return uvm.GuestRequest(ctx, guestReq)
}

// CombineLayersLCOW combines `layerPaths` and optionally `scratchPath` into an
Expand All @@ -44,32 +42,28 @@ func (uvm *UtilityVM) CombineLayersLCOW(ctx context.Context, layerPaths []string
for _, l := range layerPaths {
layers = append(layers, hcsschema.Layer{Path: l})
}
msr := &hcsschema.ModifySettingRequest{
GuestRequest: guestrequest.GuestRequest{
ResourceType: guestrequest.ResourceTypeCombinedLayers,
RequestType: requesttype.Add,
Settings: guestrequest.CombinedLayers{
ContainerRootPath: rootfsPath,
Layers: layers,
ScratchPath: scratchPath,
},
guestReq := guestrequest.GuestRequest{
ResourceType: guestrequest.ResourceTypeCombinedLayers,
RequestType: requesttype.Add,
Settings: guestrequest.CombinedLayers{
ContainerRootPath: rootfsPath,
Layers: layers,
ScratchPath: scratchPath,
},
}
return uvm.modify(ctx, msr)
return uvm.GuestRequest(ctx, guestReq)
}

// RemoveCombinedLayers removes the previously combined layers at `rootfsPath`.
//
// NOTE: `rootfsPath` is the path from within the UVM.
func (uvm *UtilityVM) RemoveCombinedLayers(ctx context.Context, rootfsPath string) error {
msr := &hcsschema.ModifySettingRequest{
GuestRequest: guestrequest.GuestRequest{
ResourceType: guestrequest.ResourceTypeCombinedLayers,
RequestType: requesttype.Remove,
Settings: guestrequest.CombinedLayers{
ContainerRootPath: rootfsPath,
},
guestReq := guestrequest.GuestRequest{
ResourceType: guestrequest.ResourceTypeCombinedLayers,
RequestType: requesttype.Remove,
Settings: guestrequest.CombinedLayers{
ContainerRootPath: rootfsPath,
},
}
return uvm.modify(ctx, msr)
return uvm.GuestRequest(ctx, guestReq)
}
10 changes: 5 additions & 5 deletions internal/uvm/computeagent.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import (

"github.com/Microsoft/go-winio"
"github.com/Microsoft/hcsshim/internal/computeagent"
hcsschema "github.com/Microsoft/hcsshim/internal/hcs/schema2"
"github.com/Microsoft/hcsshim/internal/hns"
"github.com/Microsoft/hcsshim/internal/vm"
"github.com/Microsoft/hcsshim/pkg/octtrpc"
"github.com/containerd/ttrpc"
"github.com/pkg/errors"
Expand Down Expand Up @@ -69,16 +69,16 @@ func (ca *computeAgent) ModifyNIC(ctx context.Context, req *computeagent.ModifyN
return nil, errors.Wrapf(err, "failed to get endpoint with name `%s`", req.EndpointName)
}

moderationValue := hcsschema.InterruptModerationValue(req.IovPolicySettings.InterruptModeration)
moderationName := hcsschema.InterruptModerationValueToName[moderationValue]
moderationValue := vm.InterruptModerationValue(req.IovPolicySettings.InterruptModeration)
moderationName := vm.InterruptModerationValueToName[moderationValue]

iovSettings := &hcsschema.IovSettings{
iovSettings := &vm.IovSettings{
OffloadWeight: &req.IovPolicySettings.IovOffloadWeight,
QueuePairsRequested: &req.IovPolicySettings.QueuePairsRequested,
InterruptModeration: &moderationName,
}

nic := &hcsschema.NetworkAdapter{
nic := &vm.NetworkAdapter{
EndpointId: endpoint.Id,
MacAddress: endpoint.MacAddress,
IovSettings: iovSettings,
Expand Down
18 changes: 6 additions & 12 deletions internal/uvm/cpugroups.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,11 @@ package uvm

import (
"context"
"errors"
"fmt"

"github.com/Microsoft/hcsshim/internal/cpugroup"
"github.com/Microsoft/hcsshim/internal/hcs/resourcepaths"
hcsschema "github.com/Microsoft/hcsshim/internal/hcs/schema2"
"github.com/Microsoft/hcsshim/internal/vm"
"github.com/pkg/errors"
)

// Build that assigning a cpu group on creation of a vm is supported
Expand All @@ -33,16 +32,11 @@ func (uvm *UtilityVM) SetCPUGroup(ctx context.Context, id string) error {

// setCPUGroup sets the VM's cpugroup
func (uvm *UtilityVM) setCPUGroup(ctx context.Context, id string) error {
req := &hcsschema.ModifySettingRequest{
ResourcePath: resourcepaths.CPUGroupResourcePath,
Settings: &hcsschema.CpuGroup{
Id: id,
},
windows, ok := uvm.vm.(vm.WindowsConfigManager)
if !ok {
return errors.Wrap(vm.ErrNotSupported, "stopping cpu group operation")
}
if err := uvm.modify(ctx, req); err != nil {
return err
}
return nil
return windows.SetCPUGroup(ctx, id)
}

// unsetCPUGroup sets the VM's cpugroup to the null group ID
Expand Down
15 changes: 7 additions & 8 deletions internal/uvm/cpulimits_update.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,15 @@ package uvm
import (
"context"

"github.com/Microsoft/hcsshim/internal/hcs/resourcepaths"
hcsschema "github.com/Microsoft/hcsshim/internal/hcs/schema2"
"github.com/Microsoft/hcsshim/internal/vm"
"github.com/pkg/errors"
)

// UpdateCPULimits updates the CPU limits of the utility vm
func (uvm *UtilityVM) UpdateCPULimits(ctx context.Context, limits *hcsschema.ProcessorLimits) error {
req := &hcsschema.ModifySettingRequest{
ResourcePath: resourcepaths.CPULimitsResourcePath,
Settings: limits,
func (uvm *UtilityVM) UpdateCPULimits(ctx context.Context, limits *vm.ProcessorLimits) error {
cpu, ok := uvm.vm.(vm.ProcessorManager)
if !ok || !uvm.vm.Supported(vm.Processor, vm.Update) {
return errors.Wrap(vm.ErrNotSupported, "stopping update of cpus")
}

return uvm.modify(ctx, req)
return cpu.SetProcessorLimits(ctx, limits)
}
Loading