preparelayer.go 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. package hcsshim
  2. import (
  3. "sync"
  4. "github.com/Sirupsen/logrus"
  5. )
  6. var prepareLayerLock sync.Mutex
  7. // PrepareLayer finds a mounted read-write layer matching layerId and enables the
  8. // the filesystem filter for use on that layer. This requires the paths to all
  9. // parent layers, and is necessary in order to view or interact with the layer
  10. // as an actual filesystem (reading and writing files, creating directories, etc).
  11. // Disabling the filter must be done via UnprepareLayer.
  12. func PrepareLayer(info DriverInfo, layerId string, parentLayerPaths []string) error {
  13. title := "hcsshim::PrepareLayer "
  14. logrus.Debugf(title+"flavour %d layerId %s", info.Flavour, layerId)
  15. // Generate layer descriptors
  16. layers, err := layerPathsToDescriptors(parentLayerPaths)
  17. if err != nil {
  18. return err
  19. }
  20. // Convert info to API calling convention
  21. infop, err := convertDriverInfo(info)
  22. if err != nil {
  23. logrus.Error(err)
  24. return err
  25. }
  26. // This lock is a temporary workaround for a Windows bug. Only allowing one
  27. // call to prepareLayer at a time vastly reduces the chance of a timeout.
  28. prepareLayerLock.Lock()
  29. defer prepareLayerLock.Unlock()
  30. err = prepareLayer(&infop, layerId, layers)
  31. if err != nil {
  32. err = makeErrorf(err, title, "layerId=%s flavour=%d", layerId, info.Flavour)
  33. logrus.Error(err)
  34. return err
  35. }
  36. logrus.Debugf(title+"succeeded flavour=%d layerId=%s", info.Flavour, layerId)
  37. return nil
  38. }