2018-09-05 14:54:38 -04:00
|
|
|
package wclayer
|
2018-03-19 18:57:30 -04:00
|
|
|
|
|
|
|
import (
|
2020-05-09 11:16:54 -04:00
|
|
|
"context"
|
2018-03-19 18:57:30 -04:00
|
|
|
"syscall"
|
|
|
|
|
2018-09-05 14:54:38 -04:00
|
|
|
"github.com/Microsoft/hcsshim/internal/hcserror"
|
2020-05-09 11:16:54 -04:00
|
|
|
"github.com/Microsoft/hcsshim/internal/log"
|
|
|
|
"github.com/Microsoft/hcsshim/internal/oc"
|
|
|
|
"go.opencensus.io/trace"
|
2018-03-19 18:57:30 -04:00
|
|
|
)
|
|
|
|
|
2018-09-05 14:54:38 -04:00
|
|
|
// GetLayerMountPath will look for a mounted layer with the given path and return
|
2018-03-19 18:57:30 -04:00
|
|
|
// the path at which that layer can be accessed. This path may be a volume path
|
|
|
|
// if the layer is a mounted read-write layer, otherwise it is expected to be the
|
|
|
|
// folder path at which the layer is stored.
|
2020-05-09 11:16:54 -04:00
|
|
|
func GetLayerMountPath(ctx context.Context, path string) (_ string, err error) {
|
2019-02-28 13:16:30 -05:00
|
|
|
title := "hcsshim::GetLayerMountPath"
|
2020-05-09 11:16:54 -04:00
|
|
|
ctx, span := trace.StartSpan(ctx, title)
|
|
|
|
defer span.End()
|
|
|
|
defer func() { oc.SetSpanStatus(span, err) }()
|
|
|
|
span.AddAttributes(trace.StringAttribute("path", path))
|
2018-03-19 18:57:30 -04:00
|
|
|
|
|
|
|
var mountPathLength uintptr
|
|
|
|
mountPathLength = 0
|
|
|
|
|
|
|
|
// Call the procedure itself.
|
2020-05-09 11:16:54 -04:00
|
|
|
log.G(ctx).Debug("Calling proc (1)")
|
2019-02-28 13:16:30 -05:00
|
|
|
err = getLayerMountPath(&stdDriverInfo, path, &mountPathLength, nil)
|
2018-03-19 18:57:30 -04:00
|
|
|
if err != nil {
|
2019-02-28 13:16:30 -05:00
|
|
|
return "", hcserror.New(err, title+" - failed", "(first call)")
|
2018-03-19 18:57:30 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
// Allocate a mount path of the returned length.
|
|
|
|
if mountPathLength == 0 {
|
|
|
|
return "", nil
|
|
|
|
}
|
|
|
|
mountPathp := make([]uint16, mountPathLength)
|
|
|
|
mountPathp[0] = 0
|
|
|
|
|
|
|
|
// Call the procedure again
|
2020-05-09 11:16:54 -04:00
|
|
|
log.G(ctx).Debug("Calling proc (2)")
|
2018-09-05 14:54:38 -04:00
|
|
|
err = getLayerMountPath(&stdDriverInfo, path, &mountPathLength, &mountPathp[0])
|
2018-03-19 18:57:30 -04:00
|
|
|
if err != nil {
|
2019-02-28 13:16:30 -05:00
|
|
|
return "", hcserror.New(err, title+" - failed", "(second call)")
|
2018-03-19 18:57:30 -04:00
|
|
|
}
|
|
|
|
|
2018-09-05 14:54:38 -04:00
|
|
|
mountPath := syscall.UTF16ToString(mountPathp[0:])
|
2020-05-09 11:16:54 -04:00
|
|
|
span.AddAttributes(trace.StringAttribute("mountPath", mountPath))
|
2018-09-05 14:54:38 -04:00
|
|
|
return mountPath, nil
|
2018-03-19 18:57:30 -04:00
|
|
|
}
|