initialize.go 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. package computestorage
  2. import (
  3. "context"
  4. "encoding/json"
  5. "github.com/Microsoft/hcsshim/internal/oc"
  6. "github.com/pkg/errors"
  7. "go.opencensus.io/trace"
  8. )
  9. // InitializeWritableLayer initializes a writable layer for a container.
  10. //
  11. // `layerPath` is a path to a directory the layer is mounted. If the
  12. // path does not end in a `\` the platform will append it automatically.
  13. //
  14. // `layerData` is the parent read-only layer data.
  15. func InitializeWritableLayer(ctx context.Context, layerPath string, layerData LayerData) (err error) {
  16. title := "hcsshim.InitializeWritableLayer"
  17. ctx, span := trace.StartSpan(ctx, title) //nolint:ineffassign,staticcheck
  18. defer span.End()
  19. defer func() { oc.SetSpanStatus(span, err) }()
  20. span.AddAttributes(
  21. trace.StringAttribute("layerPath", layerPath),
  22. )
  23. bytes, err := json.Marshal(layerData)
  24. if err != nil {
  25. return err
  26. }
  27. // Options are not used in the platform as of RS5
  28. err = hcsInitializeWritableLayer(layerPath, string(bytes), "")
  29. if err != nil {
  30. return errors.Wrap(err, "failed to intitialize container layer")
  31. }
  32. return nil
  33. }