aboutsummaryrefslogtreecommitdiff
path: root/vendor/github.com/Microsoft/hcsshim/internal/wclayer/exportlayer.go
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/github.com/Microsoft/hcsshim/internal/wclayer/exportlayer.go')
-rw-r--r--vendor/github.com/Microsoft/hcsshim/internal/wclayer/exportlayer.go60
1 files changed, 39 insertions, 21 deletions
diff --git a/vendor/github.com/Microsoft/hcsshim/internal/wclayer/exportlayer.go b/vendor/github.com/Microsoft/hcsshim/internal/wclayer/exportlayer.go
index 0425b3395..09f0de1a4 100644
--- a/vendor/github.com/Microsoft/hcsshim/internal/wclayer/exportlayer.go
+++ b/vendor/github.com/Microsoft/hcsshim/internal/wclayer/exportlayer.go
@@ -1,12 +1,15 @@
package wclayer
import (
+ "context"
"io/ioutil"
"os"
+ "strings"
"github.com/Microsoft/go-winio"
"github.com/Microsoft/hcsshim/internal/hcserror"
- "github.com/sirupsen/logrus"
+ "github.com/Microsoft/hcsshim/internal/oc"
+ "go.opencensus.io/trace"
)
// ExportLayer will create a folder at exportFolderPath and fill that folder with
@@ -14,24 +17,18 @@ import (
// format includes any metadata required for later importing the layer (using
// ImportLayer), and requires the full list of parent layer paths in order to
// perform the export.
-func ExportLayer(path string, exportFolderPath string, parentLayerPaths []string) (err error) {
+func ExportLayer(ctx context.Context, path string, exportFolderPath string, parentLayerPaths []string) (err error) {
title := "hcsshim::ExportLayer"
- fields := logrus.Fields{
- "path": path,
- "exportFolderPath": exportFolderPath,
- }
- logrus.WithFields(fields).Debug(title)
- defer func() {
- if err != nil {
- fields[logrus.ErrorKey] = err
- logrus.WithFields(fields).Error(err)
- } else {
- logrus.WithFields(fields).Debug(title + " - succeeded")
- }
- }()
+ ctx, span := trace.StartSpan(ctx, title)
+ defer span.End()
+ defer func() { oc.SetSpanStatus(span, err) }()
+ span.AddAttributes(
+ trace.StringAttribute("path", path),
+ trace.StringAttribute("exportFolderPath", exportFolderPath),
+ trace.StringAttribute("parentLayerPaths", strings.Join(parentLayerPaths, ", ")))
// Generate layer descriptors
- layers, err := layerPathsToDescriptors(parentLayerPaths)
+ layers, err := layerPathsToDescriptors(ctx, parentLayerPaths)
if err != nil {
return err
}
@@ -52,25 +49,46 @@ type LayerReader interface {
// NewLayerReader returns a new layer reader for reading the contents of an on-disk layer.
// The caller must have taken the SeBackupPrivilege privilege
// to call this and any methods on the resulting LayerReader.
-func NewLayerReader(path string, parentLayerPaths []string) (LayerReader, error) {
+func NewLayerReader(ctx context.Context, path string, parentLayerPaths []string) (_ LayerReader, err error) {
+ ctx, span := trace.StartSpan(ctx, "hcsshim::NewLayerReader")
+ defer func() {
+ if err != nil {
+ oc.SetSpanStatus(span, err)
+ span.End()
+ }
+ }()
+ span.AddAttributes(
+ trace.StringAttribute("path", path),
+ trace.StringAttribute("parentLayerPaths", strings.Join(parentLayerPaths, ", ")))
+
exportPath, err := ioutil.TempDir("", "hcs")
if err != nil {
return nil, err
}
- err = ExportLayer(path, exportPath, parentLayerPaths)
+ err = ExportLayer(ctx, path, exportPath, parentLayerPaths)
if err != nil {
os.RemoveAll(exportPath)
return nil, err
}
- return &legacyLayerReaderWrapper{newLegacyLayerReader(exportPath)}, nil
+ return &legacyLayerReaderWrapper{
+ ctx: ctx,
+ s: span,
+ legacyLayerReader: newLegacyLayerReader(exportPath),
+ }, nil
}
type legacyLayerReaderWrapper struct {
+ ctx context.Context
+ s *trace.Span
+
*legacyLayerReader
}
-func (r *legacyLayerReaderWrapper) Close() error {
- err := r.legacyLayerReader.Close()
+func (r *legacyLayerReaderWrapper) Close() (err error) {
+ defer r.s.End()
+ defer func() { oc.SetSpanStatus(r.s, err) }()
+
+ err = r.legacyLayerReader.Close()
os.RemoveAll(r.root)
return err
}