initialize.go 1.1 KB

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