فهرست منبع

container: Remove Ghost state

container.Register() checks both IsRunning() and IsGhost(), but at
this point IsGhost() is always true if IsRunning() is true. For a
newly created container both are false, and for a restored-from-disk
container Daemon.load() sets Ghost to true if IsRunning is true. So we
just drop the IsGhost check.

This was the last call to IsGhost, so we remove It and all other
traces of the ghost state.

Docker-DCO-1.1-Signed-off-by: Alexander Larsson <alexl@redhat.com> (github: alexlarsson)
Alexander Larsson 11 سال پیش
والد
کامیت
cf997aa905
2فایلهای تغییر یافته به همراه22 افزوده شده و 49 حذف شده
  1. 22 30
      daemon/daemon.go
  2. 0 19
      daemon/state.go

+ 22 - 30
daemon/daemon.go

@@ -134,9 +134,6 @@ func (daemon *Daemon) load(id string) (*Container, error) {
 	if container.ID != id {
 	if container.ID != id {
 		return container, fmt.Errorf("Container %s is stored at %s", container.ID, id)
 		return container, fmt.Errorf("Container %s is stored at %s", container.ID, id)
 	}
 	}
-	if container.State.IsRunning() {
-		container.State.SetGhost(true)
-	}
 	return container, nil
 	return container, nil
 }
 }
 
 
@@ -171,35 +168,32 @@ func (daemon *Daemon) Register(container *Container) error {
 	//        if so, then we need to restart monitor and init a new lock
 	//        if so, then we need to restart monitor and init a new lock
 	// If the container is supposed to be running, make sure of it
 	// If the container is supposed to be running, make sure of it
 	if container.State.IsRunning() {
 	if container.State.IsRunning() {
-		if container.State.IsGhost() {
-			utils.Debugf("killing ghost %s", container.ID)
+		utils.Debugf("killing old running container %s", container.ID)
 
 
-			existingPid := container.State.Pid
-			container.State.SetGhost(false)
-			container.State.SetStopped(0)
+		existingPid := container.State.Pid
+		container.State.SetStopped(0)
 
 
-			// We only have to handle this for lxc because the other drivers will ensure that
-			// no ghost processes are left when docker dies
-			if container.ExecDriver == "" || strings.Contains(container.ExecDriver, "lxc") {
-				lxc.KillLxc(container.ID, 9)
-			} else {
-				// use the current driver and ensure that the container is dead x.x
-				cmd := &execdriver.Command{
-					ID: container.ID,
-				}
-				var err error
-				cmd.Process, err = os.FindProcess(existingPid)
-				if err != nil {
-					utils.Debugf("cannot find existing process for %d", existingPid)
-				}
-				daemon.execDriver.Terminate(cmd)
-			}
-			if err := container.Unmount(); err != nil {
-				utils.Debugf("ghost unmount error %s", err)
+		// We only have to handle this for lxc because the other drivers will ensure that
+		// no processes are left when docker dies
+		if container.ExecDriver == "" || strings.Contains(container.ExecDriver, "lxc") {
+			lxc.KillLxc(container.ID, 9)
+		} else {
+			// use the current driver and ensure that the container is dead x.x
+			cmd := &execdriver.Command{
+				ID: container.ID,
 			}
 			}
-			if err := container.ToDisk(); err != nil {
-				utils.Debugf("saving ghost state to disk %s", err)
+			var err error
+			cmd.Process, err = os.FindProcess(existingPid)
+			if err != nil {
+				utils.Debugf("cannot find existing process for %d", existingPid)
 			}
 			}
+			daemon.execDriver.Terminate(cmd)
+		}
+		if err := container.Unmount(); err != nil {
+			utils.Debugf("unmount error %s", err)
+		}
+		if err := container.ToDisk(); err != nil {
+			utils.Debugf("saving stopped state to disk %s", err)
 		}
 		}
 
 
 		info := daemon.execDriver.Info(container.ID)
 		info := daemon.execDriver.Info(container.ID)
@@ -211,8 +205,6 @@ func (daemon *Daemon) Register(container *Container) error {
 					utils.Debugf("restart unmount error %s", err)
 					utils.Debugf("restart unmount error %s", err)
 				}
 				}
 
 
-				container.State.SetGhost(false)
-				container.State.SetStopped(0)
 				if err := container.Start(); err != nil {
 				if err := container.Start(); err != nil {
 					return err
 					return err
 				}
 				}

+ 0 - 19
daemon/state.go

@@ -14,7 +14,6 @@ type State struct {
 	ExitCode   int
 	ExitCode   int
 	StartedAt  time.Time
 	StartedAt  time.Time
 	FinishedAt time.Time
 	FinishedAt time.Time
-	Ghost      bool
 }
 }
 
 
 // String returns a human-readable description of the state
 // String returns a human-readable description of the state
@@ -23,9 +22,6 @@ func (s *State) String() string {
 	defer s.RUnlock()
 	defer s.RUnlock()
 
 
 	if s.Running {
 	if s.Running {
-		if s.Ghost {
-			return fmt.Sprintf("Ghost")
-		}
 		return fmt.Sprintf("Up %s", utils.HumanDuration(time.Now().UTC().Sub(s.StartedAt)))
 		return fmt.Sprintf("Up %s", utils.HumanDuration(time.Now().UTC().Sub(s.StartedAt)))
 	}
 	}
 	if s.FinishedAt.IsZero() {
 	if s.FinishedAt.IsZero() {
@@ -41,13 +37,6 @@ func (s *State) IsRunning() bool {
 	return s.Running
 	return s.Running
 }
 }
 
 
-func (s *State) IsGhost() bool {
-	s.RLock()
-	defer s.RUnlock()
-
-	return s.Ghost
-}
-
 func (s *State) GetExitCode() int {
 func (s *State) GetExitCode() int {
 	s.RLock()
 	s.RLock()
 	defer s.RUnlock()
 	defer s.RUnlock()
@@ -55,19 +44,11 @@ func (s *State) GetExitCode() int {
 	return s.ExitCode
 	return s.ExitCode
 }
 }
 
 
-func (s *State) SetGhost(val bool) {
-	s.Lock()
-	defer s.Unlock()
-
-	s.Ghost = val
-}
-
 func (s *State) SetRunning(pid int) {
 func (s *State) SetRunning(pid int) {
 	s.Lock()
 	s.Lock()
 	defer s.Unlock()
 	defer s.Unlock()
 
 
 	s.Running = true
 	s.Running = true
-	s.Ghost = false
 	s.ExitCode = 0
 	s.ExitCode = 0
 	s.Pid = pid
 	s.Pid = pid
 	s.StartedAt = time.Now().UTC()
 	s.StartedAt = time.Now().UTC()