...
1
2
3 package uvm
4
5 import (
6 "context"
7 "errors"
8 "fmt"
9
10 "github.com/Microsoft/hcsshim/internal/cpugroup"
11 "github.com/Microsoft/hcsshim/internal/hcs/resourcepaths"
12 hcsschema "github.com/Microsoft/hcsshim/internal/hcs/schema2"
13 "github.com/Microsoft/hcsshim/osversion"
14 )
15
16 var errCPUGroupCreateNotSupported = fmt.Errorf("cpu group assignment on create requires a build of %d or higher", osversion.V21H1)
17
18
19 func (uvm *UtilityVM) ReleaseCPUGroup(ctx context.Context) error {
20 if err := uvm.unsetCPUGroup(ctx); err != nil {
21 return fmt.Errorf("failed to remove VM %s from cpugroup", uvm.ID())
22 }
23 return nil
24 }
25
26
27 func (uvm *UtilityVM) SetCPUGroup(ctx context.Context, id string) error {
28 if id == "" {
29 return errors.New("must specify an ID to use when configuring a VM's cpugroup")
30 }
31 return uvm.setCPUGroup(ctx, id)
32 }
33
34
35 func (uvm *UtilityVM) setCPUGroup(ctx context.Context, id string) error {
36 req := &hcsschema.ModifySettingRequest{
37 ResourcePath: resourcepaths.CPUGroupResourcePath,
38 Settings: &hcsschema.CpuGroup{
39 Id: id,
40 },
41 }
42 if err := uvm.modify(ctx, req); err != nil {
43 return err
44 }
45 return nil
46 }
47
48
49
50
51
52
53 func (uvm *UtilityVM) unsetCPUGroup(ctx context.Context) error {
54 return uvm.setCPUGroup(ctx, cpugroup.NullGroupID)
55 }
56
View as plain text