...

Source file src/github.com/Microsoft/hcsshim/internal/uvm/modify.go

Documentation: github.com/Microsoft/hcsshim/internal/uvm

     1  //go:build windows
     2  
     3  package uvm
     4  
     5  import (
     6  	"context"
     7  	"fmt"
     8  
     9  	hcsschema "github.com/Microsoft/hcsshim/internal/hcs/schema2"
    10  	"github.com/Microsoft/hcsshim/internal/log"
    11  	"github.com/Microsoft/hcsshim/internal/protocol/guestrequest"
    12  )
    13  
    14  // Modify modifies the compute system by sending a request to HCS.
    15  func (uvm *UtilityVM) modify(ctx context.Context, doc *hcsschema.ModifySettingRequest) (err error) {
    16  	if doc.GuestRequest == nil || uvm.gc == nil {
    17  		return uvm.hcsSystem.Modify(ctx, doc)
    18  	}
    19  
    20  	hostdoc := *doc
    21  	hostdoc.GuestRequest = nil
    22  	if doc.ResourcePath != "" && doc.RequestType == guestrequest.RequestTypeAdd {
    23  		err = uvm.hcsSystem.Modify(ctx, &hostdoc)
    24  		if err != nil {
    25  			return fmt.Errorf("adding VM resources: %s", err)
    26  		}
    27  		defer func() {
    28  			if err != nil {
    29  				hostdoc.RequestType = guestrequest.RequestTypeRemove
    30  				rerr := uvm.hcsSystem.Modify(ctx, &hostdoc)
    31  				if rerr != nil {
    32  					log.G(ctx).WithError(rerr).Error("failed to roll back resource add")
    33  				}
    34  			}
    35  		}()
    36  	}
    37  	err = uvm.gc.Modify(ctx, doc.GuestRequest)
    38  	if err != nil {
    39  		return fmt.Errorf("guest modify: %s", err)
    40  	}
    41  	if doc.ResourcePath != "" && doc.RequestType == guestrequest.RequestTypeRemove {
    42  		err = uvm.hcsSystem.Modify(ctx, &hostdoc)
    43  		if err != nil {
    44  			err = fmt.Errorf("removing VM resources: %s", err)
    45  			log.G(ctx).WithError(err).Error("failed to remove host resources after successful guest request")
    46  			return err
    47  		}
    48  	}
    49  	return nil
    50  }
    51  

View as plain text