...

Source file src/github.com/Microsoft/hcsshim/internal/wclayer/preparelayer.go

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

     1  //go:build windows
     2  
     3  package wclayer
     4  
     5  import (
     6  	"context"
     7  	"strings"
     8  	"sync"
     9  
    10  	"github.com/Microsoft/hcsshim/internal/hcserror"
    11  	"github.com/Microsoft/hcsshim/internal/oc"
    12  	"go.opencensus.io/trace"
    13  )
    14  
    15  var prepareLayerLock sync.Mutex
    16  
    17  // PrepareLayer finds a mounted read-write layer matching path and enables the
    18  // the filesystem filter for use on that layer.  This requires the paths to all
    19  // parent layers, and is necessary in order to view or interact with the layer
    20  // as an actual filesystem (reading and writing files, creating directories, etc).
    21  // Disabling the filter must be done via UnprepareLayer.
    22  func PrepareLayer(ctx context.Context, path string, parentLayerPaths []string) (err error) {
    23  	title := "hcsshim::PrepareLayer"
    24  	ctx, span := oc.StartSpan(ctx, title)
    25  	defer span.End()
    26  	defer func() { oc.SetSpanStatus(span, err) }()
    27  	span.AddAttributes(
    28  		trace.StringAttribute("path", path),
    29  		trace.StringAttribute("parentLayerPaths", strings.Join(parentLayerPaths, ", ")))
    30  
    31  	// Generate layer descriptors
    32  	layers, err := layerPathsToDescriptors(ctx, parentLayerPaths)
    33  	if err != nil {
    34  		return err
    35  	}
    36  
    37  	// This lock is a temporary workaround for a Windows bug. Only allowing one
    38  	// call to prepareLayer at a time vastly reduces the chance of a timeout.
    39  	prepareLayerLock.Lock()
    40  	defer prepareLayerLock.Unlock()
    41  	err = prepareLayer(&stdDriverInfo, path, layers)
    42  	if err != nil {
    43  		return hcserror.New(err, title, "")
    44  	}
    45  	return nil
    46  }
    47  

View as plain text