attach.go 1.0 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. // AttachLayerStorageFilter sets up the layer storage filter on a writable
  10. // container layer.
  11. //
  12. // `layerPath` is a path to a directory the writable 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 AttachLayerStorageFilter(ctx context.Context, layerPath string, layerData LayerData) (err error) {
  17. title := "hcsshim.AttachLayerStorageFilter"
  18. ctx, span := trace.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. err = hcsAttachLayerStorageFilter(layerPath, string(bytes))
  29. if err != nil {
  30. return errors.Wrap(err, "failed to attach layer storage filter")
  31. }
  32. return nil
  33. }