attach.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. // AttachLayerStorageFilter sets up the layer storage filter on a writable
  11. // container layer.
  12. //
  13. // `layerPath` is a path to a directory the writable layer is mounted. If the
  14. // path does not end in a `\` the platform will append it automatically.
  15. //
  16. // `layerData` is the parent read-only layer data.
  17. func AttachLayerStorageFilter(ctx context.Context, layerPath string, layerData LayerData) (err error) {
  18. title := "hcsshim::AttachLayerStorageFilter"
  19. ctx, span := oc.StartSpan(ctx, title) //nolint:ineffassign,staticcheck
  20. defer span.End()
  21. defer func() { oc.SetSpanStatus(span, err) }()
  22. span.AddAttributes(
  23. trace.StringAttribute("layerPath", layerPath),
  24. )
  25. bytes, err := json.Marshal(layerData)
  26. if err != nil {
  27. return err
  28. }
  29. err = hcsAttachLayerStorageFilter(layerPath, string(bytes))
  30. if err != nil {
  31. return errors.Wrap(err, "failed to attach layer storage filter")
  32. }
  33. return nil
  34. }