k3s/vendor/github.com/Microsoft/hcsshim/internal/wclayer/getlayermountpath.go

51 lines
1.6 KiB
Go
Raw Normal View History

2019-01-12 04:58:27 +00:00
package wclayer
import (
2020-08-10 17:43:49 +00:00
"context"
2019-01-12 04:58:27 +00:00
"syscall"
"github.com/Microsoft/hcsshim/internal/hcserror"
2020-08-10 17:43:49 +00:00
"github.com/Microsoft/hcsshim/internal/log"
"github.com/Microsoft/hcsshim/internal/oc"
"go.opencensus.io/trace"
2019-01-12 04:58:27 +00:00
)
// GetLayerMountPath will look for a mounted layer with the given path and return
// 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-08-10 17:43:49 +00:00
func GetLayerMountPath(ctx context.Context, path string) (_ string, err error) {
2019-07-10 00:29:38 +00:00
title := "hcsshim::GetLayerMountPath"
2020-08-10 17:43:49 +00:00
ctx, span := trace.StartSpan(ctx, title)
defer span.End()
defer func() { oc.SetSpanStatus(span, err) }()
span.AddAttributes(trace.StringAttribute("path", path))
2019-01-12 04:58:27 +00:00
var mountPathLength uintptr = 0
2019-01-12 04:58:27 +00:00
// Call the procedure itself.
2020-08-10 17:43:49 +00:00
log.G(ctx).Debug("Calling proc (1)")
2019-07-10 00:29:38 +00:00
err = getLayerMountPath(&stdDriverInfo, path, &mountPathLength, nil)
2019-01-12 04:58:27 +00:00
if err != nil {
2019-07-10 00:29:38 +00:00
return "", hcserror.New(err, title+" - failed", "(first call)")
2019-01-12 04:58:27 +00: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-08-10 17:43:49 +00:00
log.G(ctx).Debug("Calling proc (2)")
2019-01-12 04:58:27 +00:00
err = getLayerMountPath(&stdDriverInfo, path, &mountPathLength, &mountPathp[0])
if err != nil {
2019-07-10 00:29:38 +00:00
return "", hcserror.New(err, title+" - failed", "(second call)")
2019-01-12 04:58:27 +00:00
}
mountPath := syscall.UTF16ToString(mountPathp[0:])
2020-08-10 17:43:49 +00:00
span.AddAttributes(trace.StringAttribute("mountPath", mountPath))
2019-01-12 04:58:27 +00:00
return mountPath, nil
}