Remove dependency on tar2vhd for LCOW differ
This change no longer requires the use of a UtlityVM on Windows to convert the layer tar to an ext4 vhd for LCOW. This has a significant performance boost that makes linux/amd64 layer extraction comparable to native Linux performance. Signed-off-by: Justin Terry (VM) <juterry@microsoft.com>
This commit is contained in:
@@ -21,10 +21,11 @@ package lcow
|
||||
import (
|
||||
"context"
|
||||
"io"
|
||||
"os/exec"
|
||||
"os"
|
||||
"path"
|
||||
"time"
|
||||
|
||||
"github.com/Microsoft/hcsshim/ext4/tar2ext4"
|
||||
"github.com/containerd/containerd/archive/compression"
|
||||
"github.com/containerd/containerd/content"
|
||||
"github.com/containerd/containerd/diff"
|
||||
@@ -40,6 +41,11 @@ import (
|
||||
"github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
const (
|
||||
// maxLcowVhdSizeGB is the max size in GB of any layer
|
||||
maxLcowVhdSizeGB = 128 * 1024 * 1024 * 1024
|
||||
)
|
||||
|
||||
func init() {
|
||||
plugin.Register(&plugin.Registration{
|
||||
Type: plugin.DiffPlugin,
|
||||
@@ -131,15 +137,22 @@ func (s windowsLcowDiff) Apply(ctx context.Context, desc ocispec.Descriptor, mou
|
||||
r: io.TeeReader(rdr, digester.Hash()),
|
||||
}
|
||||
|
||||
cmd := exec.Command(
|
||||
"runhcs.exe",
|
||||
"tar2vhd",
|
||||
"--scratchpath", path.Join(layer, "sandbox.vhdx"), // TODO: JTERRY75 when the snapshotter changes this to be scratch.vhdx update it here too.
|
||||
"--destpath", path.Join(layer, "layer.vhd"))
|
||||
layerPath := path.Join(layer, "layer.vhd")
|
||||
outFile, err := os.Create(layerPath)
|
||||
if err != nil {
|
||||
return emptyDesc, err
|
||||
}
|
||||
defer outFile.Close()
|
||||
defer func() {
|
||||
if err != nil {
|
||||
outFile.Close()
|
||||
os.Remove(layerPath)
|
||||
}
|
||||
}()
|
||||
|
||||
cmd.Stdin = rc
|
||||
if bytes, err := cmd.CombinedOutput(); err != nil {
|
||||
return emptyDesc, errors.Wrapf(err, "failed to exec runhcs.exe tar2vhd: %s", string(bytes))
|
||||
err = tar2ext4.Convert(rc, outFile, tar2ext4.ConvertWhiteout, tar2ext4.AppendVhdFooter, tar2ext4.MaximumDiskSize(maxLcowVhdSizeGB))
|
||||
if err != nil {
|
||||
return emptyDesc, errors.Wrapf(err, "failed to convert tar to ext4 vhd")
|
||||
}
|
||||
|
||||
return ocispec.Descriptor{
|
||||
|
Reference in New Issue
Block a user