diff --git a/daemon/oci_windows.go b/daemon/oci_windows.go index 6279d7dd20..baa6ae0b91 100644 --- a/daemon/oci_windows.go +++ b/daemon/oci_windows.go @@ -332,6 +332,30 @@ func (daemon *Daemon) createSpecWindowsFields(c *container.Container, s *specs.S s.Windows.CredentialSpec = cs } + // Do we have any assigned devices? + if len(c.HostConfig.Devices) > 0 { + if isHyperV { + return errors.New("device assignment is not supported for HyperV containers") + } + if system.GetOSVersion().Build < 17763 { + return errors.New("device assignment requires Windows builds RS5 (17763+) or later") + } + for _, deviceMapping := range c.HostConfig.Devices { + srcParts := strings.SplitN(deviceMapping.PathOnHost, "/", 2) + if len(srcParts) != 2 { + return errors.New("invalid device assignment path") + } + if srcParts[0] != "class" { + return errors.Errorf("invalid device assignment type: '%s' should be 'class'", srcParts[0]) + } + wd := specs.WindowsDevice{ + ID: srcParts[1], + IDType: srcParts[0], + } + s.Windows.Devices = append(s.Windows.Devices, wd) + } + } + return nil } diff --git a/libcontainerd/client_local_windows.go b/libcontainerd/client_local_windows.go index 80b7f4c879..3eab7c604a 100644 --- a/libcontainerd/client_local_windows.go +++ b/libcontainerd/client_local_windows.go @@ -326,6 +326,19 @@ func (c *client) createWindows(id string, spec *specs.Spec, runtimeOptions inter } configuration.MappedPipes = mps + if len(spec.Windows.Devices) > 0 { + // Add any device assignments + if configuration.HvPartition { + return errors.New("device assignment is not supported for HyperV containers") + } + if system.GetOSVersion().Build < 17763 { // RS5 + return errors.New("device assignment requires Windows builds RS5 (17763+) or later") + } + for _, d := range spec.Windows.Devices { + configuration.AssignedDevices = append(configuration.AssignedDevices, hcsshim.AssignedDevice{InterfaceClassGUID: d.ID}) + } + } + hcsContainer, err := hcsshim.CreateContainer(id, configuration) if err != nil { return err diff --git a/vendor.conf b/vendor.conf index 149bfba557..4fe6d645ec 100644 --- a/vendor.conf +++ b/vendor.conf @@ -1,6 +1,6 @@ # the following lines are in sorted order, FYI github.com/Azure/go-ansiterm d6e3b3328b783f23731bc4d058875b0371ff8109 -github.com/Microsoft/hcsshim v0.7.12 +github.com/Microsoft/hcsshim v0.7.12-1 github.com/Microsoft/go-winio v0.4.11 github.com/docker/libtrust 9cbd2a1374f46905c68a4eb3694a130610adc62a github.com/go-check/check 4ed411733c5785b40214c70bce814c3a3a689609 https://github.com/cpuguy83/check.git diff --git a/vendor/github.com/Microsoft/hcsshim/interface.go b/vendor/github.com/Microsoft/hcsshim/interface.go index 2724624fd5..5b91e0cc55 100644 --- a/vendor/github.com/Microsoft/hcsshim/interface.go +++ b/vendor/github.com/Microsoft/hcsshim/interface.go @@ -17,6 +17,11 @@ type MappedPipe = schema1.MappedPipe type HvRuntime = schema1.HvRuntime type MappedVirtualDisk = schema1.MappedVirtualDisk +// AssignedDevice represents a device that has been directly assigned to a container +// +// NOTE: Support added in RS5 +type AssignedDevice = schema1.AssignedDevice + // ContainerConfig is used as both the input of CreateContainer // and to convert the parameters to JSON for passing onto the HCS type ContainerConfig = schema1.ContainerConfig