浏览代码

Merge pull request #26650 from Microsoft/jjh/firststart

Windows: OCI remove first start
Brian Goff 8 年之前
父节点
当前提交
bc60f5af84

+ 1 - 0
daemon/monitor.go

@@ -90,6 +90,7 @@ func (daemon *Daemon) StateChanged(id string, e libcontainerd.StateInfo) error {
 		// Container is already locked in this case
 		// Container is already locked in this case
 		c.SetRunning(int(e.Pid), e.State == libcontainerd.StateStart)
 		c.SetRunning(int(e.Pid), e.State == libcontainerd.StateStart)
 		c.HasBeenManuallyStopped = false
 		c.HasBeenManuallyStopped = false
+		c.HasBeenStartedBefore = true
 		if err := c.ToDisk(); err != nil {
 		if err := c.ToDisk(); err != nil {
 			c.Reset(false)
 			c.Reset(false)
 			return err
 			return err

+ 0 - 3
daemon/oci_windows.go

@@ -78,9 +78,6 @@ func (daemon *Daemon) createSpec(c *container.Container) (*libcontainerd.Spec, e
 	s.Root.Path = c.BaseFS
 	s.Root.Path = c.BaseFS
 	s.Root.Readonly = c.HostConfig.ReadonlyRootfs
 	s.Root.Readonly = c.HostConfig.ReadonlyRootfs
 
 
-	// In s.Windows
-	s.Windows.FirstStart = !c.HasBeenStartedBefore
-
 	// s.Windows.LayerFolder.
 	// s.Windows.LayerFolder.
 	m, err := c.RWLayer.Metadata()
 	m, err := c.RWLayer.Metadata()
 	if err != nil {
 	if err != nil {

+ 3 - 1
daemon/start_windows.go

@@ -6,5 +6,7 @@ import (
 )
 )
 
 
 func (daemon *Daemon) getLibcontainerdCreateOptions(container *container.Container) (*[]libcontainerd.CreateOption, error) {
 func (daemon *Daemon) getLibcontainerdCreateOptions(container *container.Container) (*[]libcontainerd.CreateOption, error) {
-	return &[]libcontainerd.CreateOption{}, nil
+	createOptions := []libcontainerd.CreateOption{}
+	createOptions = append(createOptions, &libcontainerd.FlushOption{IgnoreFlushesDuringBoot: !container.HasBeenStartedBefore})
+	return &createOptions, nil
 }
 }

+ 8 - 5
libcontainerd/client_windows.go

@@ -41,12 +41,11 @@ func (clnt *client) Create(containerID string, checkpoint string, checkpointDir
 	logrus.Debugln("libcontainerd: client.Create() with spec", spec)
 	logrus.Debugln("libcontainerd: client.Create() with spec", spec)
 
 
 	configuration := &hcsshim.ContainerConfig{
 	configuration := &hcsshim.ContainerConfig{
-		SystemType: "Container",
-		Name:       containerID,
-		Owner:      defaultOwner,
-
+		SystemType:              "Container",
+		Name:                    containerID,
+		Owner:                   defaultOwner,
 		VolumePath:              spec.Root.Path,
 		VolumePath:              spec.Root.Path,
-		IgnoreFlushesDuringBoot: spec.Windows.FirstStart,
+		IgnoreFlushesDuringBoot: false,
 		LayerFolderPath:         spec.Windows.LayerFolder,
 		LayerFolderPath:         spec.Windows.LayerFolder,
 		HostName:                spec.Hostname,
 		HostName:                spec.Hostname,
 	}
 	}
@@ -106,6 +105,10 @@ func (clnt *client) Create(containerID string, checkpoint string, checkpointDir
 			configuration.Servicing = s.IsServicing
 			configuration.Servicing = s.IsServicing
 			break
 			break
 		}
 		}
+		if s, ok := option.(*FlushOption); ok {
+			configuration.IgnoreFlushesDuringBoot = s.IgnoreFlushesDuringBoot
+			break
+		}
 	}
 	}
 
 
 	for _, layerPath := range spec.Windows.LayerPaths {
 	for _, layerPath := range spec.Windows.LayerPaths {

+ 7 - 0
libcontainerd/types_windows.go

@@ -38,6 +38,13 @@ type ServicingOption struct {
 	IsServicing bool
 	IsServicing bool
 }
 }
 
 
+// FlushOption is an empty CreateOption that signifies if the container should be
+// started with flushes ignored until boot has completed. This is an optimisation
+// for first boot of a container.
+type FlushOption struct {
+	IgnoreFlushesDuringBoot bool
+}
+
 // Checkpoint holds the details of a checkpoint (not supported in windows)
 // Checkpoint holds the details of a checkpoint (not supported in windows)
 type Checkpoint struct {
 type Checkpoint struct {
 	Name string
 	Name string

+ 5 - 0
libcontainerd/utils_windows.go

@@ -23,6 +23,11 @@ func (s *ServicingOption) Apply(interface{}) error {
 	return nil
 	return nil
 }
 }
 
 
+// Apply for the flush option is a no-op.
+func (s *FlushOption) Apply(interface{}) error {
+	return nil
+}
+
 // buildFromVersion takes an image version string and returns the Windows build
 // buildFromVersion takes an image version string and returns the Windows build
 // number. It returns 0 if the build number is not present.
 // number. It returns 0 if the build number is not present.
 func buildFromVersion(osver string) int {
 func buildFromVersion(osver string) int {

+ 0 - 2
libcontainerd/windowsoci/oci_windows.go

@@ -39,8 +39,6 @@ type Windows struct {
 	Resources *Resources `json:"resources,omitempty"`
 	Resources *Resources `json:"resources,omitempty"`
 	// Networking contains the platform specific network settings for the container.
 	// Networking contains the platform specific network settings for the container.
 	Networking *Networking `json:"networking,omitempty"`
 	Networking *Networking `json:"networking,omitempty"`
-	// FirstStart is used for an optimization on first boot of Windows
-	FirstStart bool `json:"first_start,omitempty"`
 	// LayerFolder is the path to the current layer folder
 	// LayerFolder is the path to the current layer folder
 	LayerFolder string `json:"layer_folder,omitempty"`
 	LayerFolder string `json:"layer_folder,omitempty"`
 	// Layer paths of the parent layers
 	// Layer paths of the parent layers