preparelayer.go 1.4 KB

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