Skip to content

Commit

Permalink
Merge pull request moby#21943 from Microsoft/jstarks/utilityvm
Browse files Browse the repository at this point in the history
Windows: support embedded utility VM images
  • Loading branch information
LK4D4 committed Apr 12, 2016
2 parents 8cb511b + c70f153 commit 7b5a684
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 28 deletions.
48 changes: 33 additions & 15 deletions daemon/oci_windows.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
package daemon

import (
"errors"
"fmt"
"os"
"path/filepath"
"syscall"

"github.com/docker/docker/container"
Expand Down Expand Up @@ -47,21 +50,6 @@ func (daemon *Daemon) createSpec(c *container.Container) (*libcontainerd.Spec, e
})
}

// Are we going to run as a Hyper-V container?
hv := false
if c.HostConfig.Isolation.IsDefault() {
// Container is set to use the default, so take the default from the daemon configuration
hv = daemon.defaultIsolation.IsHyperV()
} else {
// Container is requesting an isolation mode. Honour it.
hv = c.HostConfig.Isolation.IsHyperV()
}
if hv {
// TODO We don't yet have the ImagePath hooked up. But set to
// something non-nil to pickup in libcontainerd.
s.Windows.HvRuntime = &windowsoci.HvRuntime{}
}

// In s.Process
s.Process.Args = append([]string{c.Path}, c.Args...)
if !c.Config.ArgsEscaped {
Expand Down Expand Up @@ -109,6 +97,36 @@ func (daemon *Daemon) createSpec(c *container.Container) (*libcontainerd.Spec, e
}
s.Windows.LayerPaths = layerPaths

// Are we going to run as a Hyper-V container?
hv := false
if c.HostConfig.Isolation.IsDefault() {
// Container is set to use the default, so take the default from the daemon configuration
hv = daemon.defaultIsolation.IsHyperV()
} else {
// Container is requesting an isolation mode. Honour it.
hv = c.HostConfig.Isolation.IsHyperV()
}
if hv {
hvr := &windowsoci.HvRuntime{}
if img.RootFS != nil && img.RootFS.Type == image.TypeLayers {
// For TP5, the utility VM is part of the base layer.
// TODO-jstarks: Add support for separate utility VM images
// once it is decided how they can be stored.
uvmpath := filepath.Join(layerPaths[len(layerPaths)-1], "UtilityVM")
_, err = os.Stat(uvmpath)
if err != nil {
if os.IsNotExist(err) {
err = errors.New("container image does not contain a utility VM")
}
return nil, err
}

hvr.ImagePath = uvmpath
}

s.Windows.HvRuntime = hvr
}

// In s.Windows.Networking
// Connect all the libnetwork allocated networks to the container
var epList []string
Expand Down
2 changes: 1 addition & 1 deletion hack/vendor.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ source 'hack/.vendor-helpers.sh'

# the following lines are in sorted order, FYI
clone git github.com/Azure/go-ansiterm 70b2c90b260171e829f1ebd7c17f600c11858dbe
clone git github.com/Microsoft/hcsshim v0.2.0
clone git github.com/Microsoft/hcsshim v0.2.1
clone git github.com/Microsoft/go-winio v0.3.0
clone git github.com/Sirupsen/logrus v0.9.0 # logrus is a common dependency among multiple deps
clone git github.com/docker/libtrust 9cbd2a1374f46905c68a4eb3694a130610adc62a
Expand Down
19 changes: 11 additions & 8 deletions libcontainerd/client_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,10 @@ type mappedDir struct {
ReadOnly bool
}

type hvRuntime struct {
ImagePath string `json:",omitempty"`
}

// TODO Windows: @darrenstahlmsft Add ProcessorCount
type containerInit struct {
SystemType string // HCS requires this to be hard-coded to "Container"
Expand All @@ -91,6 +95,7 @@ type containerInit struct {
SandboxPath string // Location of unmounted sandbox (used for Hyper-V containers)
HvPartition bool // True if it a Hyper-V Container
EndpointList []string // List of networking endpoints to be attached to container
HvRuntime *hvRuntime // Hyper-V container settings
}

// defaultOwner is a tag passed to HCS to allow it to differentiate between
Expand Down Expand Up @@ -145,14 +150,12 @@ func (clnt *client) Create(containerID string, spec Spec, options ...CreateOptio
}
}

cu.HvPartition = (spec.Windows.HvRuntime != nil)

// TODO Windows @jhowardmsft. FIXME post TP5.
// if spec.Windows.HvRuntime != nil {
// if spec.WIndows.HVRuntime.ImagePath != "" {
// cu.TBD = spec.Windows.HvRuntime.ImagePath
// }
// }
if spec.Windows.HvRuntime != nil {
cu.HvPartition = true
cu.HvRuntime = &hvRuntime{
ImagePath: spec.Windows.HvRuntime.ImagePath,
}
}

if cu.HvPartition {
cu.SandboxPath = filepath.Dir(spec.Windows.LayerFolder)
Expand Down
20 changes: 16 additions & 4 deletions vendor/src/github.com/Microsoft/hcsshim/baselayer.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,11 @@ import (
)

type baseLayerWriter struct {
root string
f *os.File
bw *winio.BackupFileWriter
err error
root string
f *os.File
bw *winio.BackupFileWriter
err error
hasUtilityVM bool
}

func (w *baseLayerWriter) closeCurrentFile() error {
Expand Down Expand Up @@ -44,6 +45,10 @@ func (w *baseLayerWriter) Add(name string, fileInfo *winio.FileBasicInfo) (err e
return err
}

if filepath.ToSlash(name) == `UtilityVM/Files` {
w.hasUtilityVM = true
}

path := filepath.Join(w.root, name)
path, err = makeLongAbsPath(path)
if err != nil {
Expand Down Expand Up @@ -139,6 +144,13 @@ func (w *baseLayerWriter) Close() error {
if err != nil {
return err
}

if w.hasUtilityVM {
err = ProcessUtilityVMImage(filepath.Join(w.root, "UtilityVM"))
if err != nil {
return err
}
}
}
return w.err
}

0 comments on commit 7b5a684

Please sign in to comment.