k3s/vendor/github.com/Microsoft/hcsshim/internal/wclayer/preparelayer.go

45 lines
1.4 KiB
Go
Raw Normal View History

2019-01-12 04:58:27 +00:00
package wclayer
import (
2020-08-10 17:43:49 +00:00
"context"
"strings"
2019-01-12 04:58:27 +00:00
"sync"
"github.com/Microsoft/hcsshim/internal/hcserror"
2020-08-10 17:43:49 +00:00
"github.com/Microsoft/hcsshim/internal/oc"
"go.opencensus.io/trace"
2019-01-12 04:58:27 +00:00
)
var prepareLayerLock sync.Mutex
// PrepareLayer finds a mounted read-write layer matching path and enables the
// the filesystem filter for use on that layer. This requires the paths to all
// parent layers, and is necessary in order to view or interact with the layer
// as an actual filesystem (reading and writing files, creating directories, etc).
// Disabling the filter must be done via UnprepareLayer.
2020-08-10 17:43:49 +00:00
func PrepareLayer(ctx context.Context, path string, parentLayerPaths []string) (err error) {
2019-07-10 00:29:38 +00:00
title := "hcsshim::PrepareLayer"
2020-08-10 17:43:49 +00:00
ctx, span := trace.StartSpan(ctx, title)
defer span.End()
defer func() { oc.SetSpanStatus(span, err) }()
span.AddAttributes(
trace.StringAttribute("path", path),
trace.StringAttribute("parentLayerPaths", strings.Join(parentLayerPaths, ", ")))
2019-01-12 04:58:27 +00:00
// Generate layer descriptors
2020-08-10 17:43:49 +00:00
layers, err := layerPathsToDescriptors(ctx, parentLayerPaths)
2019-01-12 04:58:27 +00:00
if err != nil {
return err
}
// This lock is a temporary workaround for a Windows bug. Only allowing one
// call to prepareLayer at a time vastly reduces the chance of a timeout.
prepareLayerLock.Lock()
defer prepareLayerLock.Unlock()
err = prepareLayer(&stdDriverInfo, path, layers)
if err != nil {
2019-07-10 00:29:38 +00:00
return hcserror.New(err, title+" - failed", "")
2019-01-12 04:58:27 +00:00
}
return nil
}