getlayermountpath.go 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. package wclayer
  2. import (
  3. "context"
  4. "syscall"
  5. "github.com/Microsoft/hcsshim/internal/hcserror"
  6. "github.com/Microsoft/hcsshim/internal/log"
  7. "github.com/Microsoft/hcsshim/internal/oc"
  8. "go.opencensus.io/trace"
  9. )
  10. // GetLayerMountPath will look for a mounted layer with the given path and return
  11. // the path at which that layer can be accessed. This path may be a volume path
  12. // if the layer is a mounted read-write layer, otherwise it is expected to be the
  13. // folder path at which the layer is stored.
  14. func GetLayerMountPath(ctx context.Context, path string) (_ string, err error) {
  15. title := "hcsshim::GetLayerMountPath"
  16. ctx, span := trace.StartSpan(ctx, title)
  17. defer span.End()
  18. defer func() { oc.SetSpanStatus(span, err) }()
  19. span.AddAttributes(trace.StringAttribute("path", path))
  20. var mountPathLength uintptr
  21. mountPathLength = 0
  22. // Call the procedure itself.
  23. log.G(ctx).Debug("Calling proc (1)")
  24. err = getLayerMountPath(&stdDriverInfo, path, &mountPathLength, nil)
  25. if err != nil {
  26. return "", hcserror.New(err, title+" - failed", "(first call)")
  27. }
  28. // Allocate a mount path of the returned length.
  29. if mountPathLength == 0 {
  30. return "", nil
  31. }
  32. mountPathp := make([]uint16, mountPathLength)
  33. mountPathp[0] = 0
  34. // Call the procedure again
  35. log.G(ctx).Debug("Calling proc (2)")
  36. err = getLayerMountPath(&stdDriverInfo, path, &mountPathLength, &mountPathp[0])
  37. if err != nil {
  38. return "", hcserror.New(err, title+" - failed", "(second call)")
  39. }
  40. mountPath := syscall.UTF16ToString(mountPathp[0:])
  41. span.AddAttributes(trace.StringAttribute("mountPath", mountPath))
  42. return mountPath, nil
  43. }