...

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

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

     1  //go:build windows
     2  
     3  package uvm
     4  
     5  import (
     6  	"context"
     7  
     8  	hcsschema "github.com/Microsoft/hcsshim/internal/hcs/schema2"
     9  	"github.com/Microsoft/hcsshim/internal/protocol/guestrequest"
    10  	"github.com/Microsoft/hcsshim/internal/protocol/guestresource"
    11  )
    12  
    13  // CombineLayersWCOW combines `layerPaths` with `containerRootPath` into the
    14  // container file system.
    15  //
    16  // Note: `layerPaths` and `containerRootPath` are paths from within the UVM.
    17  func (uvm *UtilityVM) CombineLayersWCOW(ctx context.Context, layerPaths []hcsschema.Layer, containerRootPath string) error {
    18  	if uvm.operatingSystem != "windows" {
    19  		return errNotSupported
    20  	}
    21  	msr := &hcsschema.ModifySettingRequest{
    22  		GuestRequest: guestrequest.ModificationRequest{
    23  			ResourceType: guestresource.ResourceTypeCombinedLayers,
    24  			RequestType:  guestrequest.RequestTypeAdd,
    25  			Settings: guestresource.WCOWCombinedLayers{
    26  				ContainerRootPath: containerRootPath,
    27  				Layers:            layerPaths,
    28  			},
    29  		},
    30  	}
    31  	return uvm.modify(ctx, msr)
    32  }
    33  
    34  // CombineLayersLCOW combines `layerPaths` and optionally `scratchPath` into an
    35  // overlay filesystem at `rootfsPath`. If `scratchPath` is empty the overlay
    36  // will be read only.
    37  //
    38  // NOTE: `layerPaths`, `scrathPath`, and `rootfsPath` are paths from within the
    39  // UVM.
    40  func (uvm *UtilityVM) CombineLayersLCOW(ctx context.Context, containerID string, layerPaths []string, scratchPath, rootfsPath string) error {
    41  	if uvm.operatingSystem != "linux" {
    42  		return errNotSupported
    43  	}
    44  
    45  	var layers []hcsschema.Layer
    46  	for _, l := range layerPaths {
    47  		layers = append(layers, hcsschema.Layer{Path: l})
    48  	}
    49  	msr := &hcsschema.ModifySettingRequest{
    50  		GuestRequest: guestrequest.ModificationRequest{
    51  			ResourceType: guestresource.ResourceTypeCombinedLayers,
    52  			RequestType:  guestrequest.RequestTypeAdd,
    53  			Settings: guestresource.LCOWCombinedLayers{
    54  				ContainerID:       containerID,
    55  				ContainerRootPath: rootfsPath,
    56  				Layers:            layers,
    57  				ScratchPath:       scratchPath,
    58  			},
    59  		},
    60  	}
    61  	return uvm.modify(ctx, msr)
    62  }
    63  
    64  // RemoveCombinedLayers removes the previously combined layers at `rootfsPath`.
    65  //
    66  // NOTE: `rootfsPath` is the path from within the UVM.
    67  func (uvm *UtilityVM) RemoveCombinedLayersWCOW(ctx context.Context, rootfsPath string) error {
    68  	msr := &hcsschema.ModifySettingRequest{
    69  		GuestRequest: guestrequest.ModificationRequest{
    70  			ResourceType: guestresource.ResourceTypeCombinedLayers,
    71  			RequestType:  guestrequest.RequestTypeRemove,
    72  			Settings: guestresource.WCOWCombinedLayers{
    73  				ContainerRootPath: rootfsPath,
    74  			},
    75  		},
    76  	}
    77  	return uvm.modify(ctx, msr)
    78  }
    79  
    80  func (uvm *UtilityVM) RemoveCombinedLayersLCOW(ctx context.Context, rootfsPath string) error {
    81  	msr := &hcsschema.ModifySettingRequest{
    82  		GuestRequest: guestrequest.ModificationRequest{
    83  			ResourceType: guestresource.ResourceTypeCombinedLayers,
    84  			RequestType:  guestrequest.RequestTypeRemove,
    85  			Settings: guestresource.LCOWCombinedLayers{
    86  				ContainerRootPath: rootfsPath,
    87  			},
    88  		},
    89  	}
    90  	return uvm.modify(ctx, msr)
    91  }
    92  

View as plain text