daemon/daemon_windows.go
8fb0ca2c
 package daemon
 
 import (
4352da78
 	"encoding/json"
 	"errors"
8fb0ca2c
 	"fmt"
557c7cb8
 	"os"
4352da78
 	"path/filepath"
 	"runtime"
 	"strings"
8fb0ca2c
 
a5879bb8
 	"github.com/Sirupsen/logrus"
6bb0d181
 	"github.com/docker/docker/container"
8fb0ca2c
 	"github.com/docker/docker/daemon/graphdriver"
4352da78
 	"github.com/docker/docker/dockerversion"
 	"github.com/docker/docker/image"
 	"github.com/docker/docker/layer"
2655954c
 	"github.com/docker/docker/reference"
907407d0
 	containertypes "github.com/docker/engine-api/types/container"
abd72d40
 	// register the windows graph driver
4352da78
 	"github.com/docker/docker/daemon/graphdriver/windows"
557c7cb8
 	"github.com/docker/docker/pkg/idtools"
805dd0ee
 	"github.com/docker/docker/pkg/system"
8fb0ca2c
 	"github.com/docker/libnetwork"
0fbfa144
 	blkiodev "github.com/opencontainers/runc/libcontainer/configs"
8fb0ca2c
 )
 
10d30c64
 const (
abd72d40
 	defaultVirtualSwitch = "Virtual Switch"
10d30c64
 	platformSupported    = true
a5879bb8
 	windowsMinCPUShares  = 1
90eac6b4
 	windowsMaxCPUShares  = 10000
10d30c64
 )
e0ec0cc1
 
7ac4232e
 func getBlkioWeightDevices(config *containertypes.HostConfig) ([]*blkiodev.WeightDevice, error) {
0fbfa144
 	return nil, nil
 }
 
7ac4232e
 func parseSecurityOpt(container *container.Container, config *containertypes.HostConfig) error {
8fb0ca2c
 	return nil
 }
 
7ac4232e
 func getBlkioReadIOpsDevices(config *containertypes.HostConfig) ([]*blkiodev.ThrottleDevice, error) {
843084b0
 	return nil, nil
 }
 
7ac4232e
 func getBlkioWriteIOpsDevices(config *containertypes.HostConfig) ([]*blkiodev.ThrottleDevice, error) {
843084b0
 	return nil, nil
 }
 
7ac4232e
 func getBlkioReadBpsDevices(config *containertypes.HostConfig) ([]*blkiodev.ThrottleDevice, error) {
3f15a055
 	return nil, nil
 }
 
7ac4232e
 func getBlkioWriteBpsDevices(config *containertypes.HostConfig) ([]*blkiodev.ThrottleDevice, error) {
3f15a055
 	return nil, nil
 }
 
442b4562
 func setupInitLayer(initLayer string, rootUID, rootGID int) error {
8fb0ca2c
 	return nil
 }
 
 func checkKernel() error {
 	return nil
 }
 
3fea79bf
 // adaptContainerSettings is called during container creation to modify any
 // settings necessary in the HostConfig structure.
7ac4232e
 func (daemon *Daemon) adaptContainerSettings(hostConfig *containertypes.HostConfig, adjustCPUShares bool) error {
608b3db5
 	if hostConfig == nil {
4089b4e4
 		return nil
608b3db5
 	}
 
a5879bb8
 	if hostConfig.CPUShares < 0 {
 		logrus.Warnf("Changing requested CPUShares of %d to minimum allowed of %d", hostConfig.CPUShares, windowsMinCPUShares)
 		hostConfig.CPUShares = windowsMinCPUShares
 	} else if hostConfig.CPUShares > windowsMaxCPUShares {
 		logrus.Warnf("Changing requested CPUShares of %d to maximum allowed of %d", hostConfig.CPUShares, windowsMaxCPUShares)
 		hostConfig.CPUShares = windowsMaxCPUShares
 	}
4089b4e4
 
 	return nil
7e0dfbf4
 }
 
3fea79bf
 // verifyPlatformContainerSettings performs platform-specific validation of the
 // hostconfig and config structures.
7ac4232e
 func verifyPlatformContainerSettings(daemon *Daemon, hostConfig *containertypes.HostConfig, config *containertypes.Config) ([]string, error) {
8fb0ca2c
 	return nil, nil
 }
 
6934594a
 // verifyDaemonSettings performs validation of daemon config struct
 func verifyDaemonSettings(config *Config) error {
8fb0ca2c
 	return nil
 }
 
62a75fca
 // checkSystem validates platform-specific requirements
8fb0ca2c
 func checkSystem() error {
 	// Validate the OS version. Note that docker.exe must be manifested for this
 	// call to return the correct version.
805dd0ee
 	osv, err := system.GetOSVersion()
8fb0ca2c
 	if err != nil {
805dd0ee
 		return err
8fb0ca2c
 	}
805dd0ee
 	if osv.MajorVersion < 10 {
8fb0ca2c
 		return fmt.Errorf("This version of Windows does not support the docker daemon")
 	}
122568b3
 	if osv.Build < 10586 {
 		return fmt.Errorf("The Windows daemon requires Windows Server 2016 Technical Preview 4, build 10586 or later")
 	}
8fb0ca2c
 	return nil
 }
 
 // configureKernelSecuritySupport configures and validate security support for the kernel
 func configureKernelSecuritySupport(config *Config, driverName string) error {
 	return nil
 }
 
c9328c6c
 func isBridgeNetworkDisabled(config *Config) bool {
8fb0ca2c
 	return false
 }
 
139ea5b7
 func (daemon *Daemon) initNetworkController(config *Config) (libnetwork.NetworkController, error) {
e0ec0cc1
 	// Set the name of the virtual switch if not specified by -b on daemon start
c446fd20
 	if config.bridgeConfig.VirtualSwitchName == "" {
 		config.bridgeConfig.VirtualSwitchName = defaultVirtualSwitch
e0ec0cc1
 	}
8fb0ca2c
 	return nil, nil
 }
c5e6a4b3
 
abd72d40
 // registerLinks sets up links between containers and writes the
b2771b44
 // configuration out for persistence. As of Windows TP4, links are not supported.
7ac4232e
 func (daemon *Daemon) registerLinks(container *container.Container, hostConfig *containertypes.HostConfig) error {
c5e6a4b3
 	return nil
 }
47c56e43
 
c8291f71
 func (daemon *Daemon) cleanupMounts() error {
 	return nil
 }
3a497650
 
557c7cb8
 func setupRemappedRoot(config *Config) ([]idtools.IDMap, []idtools.IDMap, error) {
 	return nil, nil, nil
 }
 
 func setupDaemonRoot(config *Config, rootDir string, rootUID, rootGID int) error {
 	config.Root = rootDir
 	// Create the root directory if it doesn't exists
 	if err := system.MkdirAll(config.Root, 0700); err != nil && !os.IsExist(err) {
 		return err
 	}
 	return nil
 }
 
3a497650
 // conditionalMountOnStart is a platform specific helper function during the
 // container start to call mount.
6bb0d181
 func (daemon *Daemon) conditionalMountOnStart(container *container.Container) error {
3a497650
 	// We do not mount if a Hyper-V container
6bb0d181
 	if !container.HostConfig.Isolation.IsHyperV() {
3a497650
 		if err := daemon.Mount(container); err != nil {
 			return err
 		}
 	}
 	return nil
 }
 
 // conditionalUnmountOnCleanup is a platform specific helper function called
 // during the cleanup of a container to unmount.
6bb0d181
 func (daemon *Daemon) conditionalUnmountOnCleanup(container *container.Container) {
3a497650
 	// We do not unmount if a Hyper-V container
6bb0d181
 	if !container.HostConfig.Isolation.IsHyperV() {
4352da78
 		daemon.Unmount(container)
 	}
 }
 
f5916b10
 func restoreCustomImage(is image.Store, ls layer.Store, rs reference.Store) error {
 	type graphDriverStore interface {
 		GraphDriver() graphdriver.Driver
 	}
 
 	gds, ok := ls.(graphDriverStore)
 	if !ok {
 		return nil
 	}
 
 	driver := gds.GraphDriver()
 	wd, ok := driver.(*windows.Driver)
 	if !ok {
 		return nil
 	}
 
 	imageInfos, err := wd.GetCustomImageInfos()
 	if err != nil {
 		return err
 	}
 
 	// Convert imageData to valid image configuration
 	for i := range imageInfos {
 		name := strings.ToLower(imageInfos[i].Name)
 
 		type registrar interface {
 			RegisterDiffID(graphID string, size int64) (layer.Layer, error)
 		}
 		r, ok := ls.(registrar)
 		if !ok {
 			return errors.New("Layerstore doesn't support RegisterDiffID")
 		}
 		if _, err := r.RegisterDiffID(imageInfos[i].ID, imageInfos[i].Size); err != nil {
 			return err
 		}
 		// layer is intentionally not released
 
 		rootFS := image.NewRootFS()
 		rootFS.BaseLayer = filepath.Base(imageInfos[i].Path)
 
 		// Create history for base layer
 		config, err := json.Marshal(&image.Image{
 			V1Image: image.V1Image{
 				DockerVersion: dockerversion.Version,
 				Architecture:  runtime.GOARCH,
 				OS:            runtime.GOOS,
 				Created:       imageInfos[i].CreatedTime,
 			},
 			RootFS:  rootFS,
 			History: []image.History{},
 		})
 
 		named, err := reference.ParseNamed(name)
4352da78
 		if err != nil {
 			return err
3a497650
 		}
4352da78
 
f5916b10
 		ref, err := reference.WithTag(named, imageInfos[i].Version)
 		if err != nil {
 			return err
4352da78
 		}
 
f5916b10
 		id, err := is.Create(config)
 		if err != nil {
 			return err
 		}
 
 		if err := rs.AddTag(ref, id, true); err != nil {
 			return err
 		}
4352da78
 
f5916b10
 		logrus.Debugf("Registered base layer %s as %s", ref, id)
 	}
4352da78
 	return nil
3a497650
 }