createscratchlayer.go 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. package wclayer
  2. import (
  3. "github.com/Microsoft/hcsshim/internal/hcserror"
  4. "github.com/sirupsen/logrus"
  5. )
  6. // CreateScratchLayer creates and populates new read-write layer for use by a container.
  7. // This requires both the id of the direct parent layer, as well as the full list
  8. // of paths to all parent layers up to the base (and including the direct parent
  9. // whose id was provided).
  10. func CreateScratchLayer(path string, parentLayerPaths []string) (err error) {
  11. title := "hcsshim::CreateScratchLayer"
  12. fields := logrus.Fields{
  13. "path": path,
  14. }
  15. logrus.WithFields(fields).Debug(title)
  16. defer func() {
  17. if err != nil {
  18. fields[logrus.ErrorKey] = err
  19. logrus.WithFields(fields).Error(err)
  20. } else {
  21. logrus.WithFields(fields).Debug(title + " - succeeded")
  22. }
  23. }()
  24. // Generate layer descriptors
  25. layers, err := layerPathsToDescriptors(parentLayerPaths)
  26. if err != nil {
  27. return err
  28. }
  29. err = createSandboxLayer(&stdDriverInfo, path, 0, layers)
  30. if err != nil {
  31. return hcserror.New(err, title+" - failed", "")
  32. }
  33. return nil
  34. }