preparelayer.go 1.3 KB

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