Przeglądaj źródła

Merge pull request #35614 from mlaventure/remove-exec-bypid

Remove ByPid from ExecCommands
Michael Crosby 7 lat temu
rodzic
commit
edbf7d8ed4
3 zmienionych plików z 4 dodań i 31 usunięć
  1. 0 9
      daemon/exec.go
  2. 2 21
      daemon/exec/exec.go
  3. 2 1
      daemon/monitor.go

+ 0 - 9
daemon/exec.go

@@ -31,14 +31,6 @@ func (d *Daemon) registerExecCommand(container *container.Container, config *exe
 	d.execCommands.Add(config.ID, config)
 	d.execCommands.Add(config.ID, config)
 }
 }
 
 
-func (d *Daemon) registerExecPidUnlocked(container *container.Container, config *exec.Config) {
-	logrus.Debugf("registering pid %v for exec %v", config.Pid, config.ID)
-	// Storing execs in container in order to kill them gracefully whenever the container is stopped or removed.
-	container.ExecCommands.SetPidUnlocked(config.ID, config.Pid)
-	// Storing execs in daemon for easy access via Engine API.
-	d.execCommands.SetPidUnlocked(config.ID, config.Pid)
-}
-
 // ExecExists looks up the exec instance and returns a bool if it exists or not.
 // ExecExists looks up the exec instance and returns a bool if it exists or not.
 // It will also return the error produced by `getConfig`
 // It will also return the error produced by `getConfig`
 func (d *Daemon) ExecExists(name string) (bool, error) {
 func (d *Daemon) ExecExists(name string) (bool, error) {
@@ -253,7 +245,6 @@ func (d *Daemon) ContainerExecStart(ctx context.Context, name string, stdin io.R
 		return translateContainerdStartErr(ec.Entrypoint, ec.SetExitCode, err)
 		return translateContainerdStartErr(ec.Entrypoint, ec.SetExitCode, err)
 	}
 	}
 	ec.Pid = systemPid
 	ec.Pid = systemPid
-	d.registerExecPidUnlocked(c, ec)
 	c.ExecCommands.Unlock()
 	c.ExecCommands.Unlock()
 	ec.Unlock()
 	ec.Unlock()
 
 

+ 2 - 21
daemon/exec/exec.go

@@ -88,16 +88,14 @@ func (c *Config) SetExitCode(code int) {
 
 
 // Store keeps track of the exec configurations.
 // Store keeps track of the exec configurations.
 type Store struct {
 type Store struct {
-	byID  map[string]*Config
-	byPid map[int]*Config
+	byID map[string]*Config
 	sync.RWMutex
 	sync.RWMutex
 }
 }
 
 
 // NewStore initializes a new exec store.
 // NewStore initializes a new exec store.
 func NewStore() *Store {
 func NewStore() *Store {
 	return &Store{
 	return &Store{
-		byID:  make(map[string]*Config),
-		byPid: make(map[int]*Config),
+		byID: make(map[string]*Config),
 	}
 	}
 }
 }
 
 
@@ -119,14 +117,6 @@ func (e *Store) Add(id string, Config *Config) {
 	e.Unlock()
 	e.Unlock()
 }
 }
 
 
-// SetPidUnlocked adds an association between a Pid and a config, it does not
-// synchronized with other operations.
-func (e *Store) SetPidUnlocked(id string, pid int) {
-	if config, ok := e.byID[id]; ok {
-		e.byPid[pid] = config
-	}
-}
-
 // Get returns an exec configuration by its id.
 // Get returns an exec configuration by its id.
 func (e *Store) Get(id string) *Config {
 func (e *Store) Get(id string) *Config {
 	e.RLock()
 	e.RLock()
@@ -135,18 +125,9 @@ func (e *Store) Get(id string) *Config {
 	return res
 	return res
 }
 }
 
 
-// ByPid returns an exec configuration by its pid.
-func (e *Store) ByPid(pid int) *Config {
-	e.RLock()
-	res := e.byPid[pid]
-	e.RUnlock()
-	return res
-}
-
 // Delete removes an exec configuration from the store.
 // Delete removes an exec configuration from the store.
 func (e *Store) Delete(id string, pid int) {
 func (e *Store) Delete(id string, pid int) {
 	e.Lock()
 	e.Lock()
-	delete(e.byPid, pid)
 	delete(e.byID, id)
 	delete(e.byID, id)
 	e.Unlock()
 	e.Unlock()
 }
 }

+ 2 - 1
daemon/monitor.go

@@ -112,7 +112,7 @@ func (daemon *Daemon) ProcessEvent(id string, e libcontainerd.EventType, ei libc
 			return daemon.postRunProcessing(c, ei)
 			return daemon.postRunProcessing(c, ei)
 		}
 		}
 
 
-		if execConfig := c.ExecCommands.ByPid(int(ei.Pid)); execConfig != nil {
+		if execConfig := c.ExecCommands.Get(ei.ProcessID); execConfig != nil {
 			ec := int(ei.ExitCode)
 			ec := int(ei.ExitCode)
 			execConfig.Lock()
 			execConfig.Lock()
 			defer execConfig.Unlock()
 			defer execConfig.Unlock()
@@ -129,6 +129,7 @@ func (daemon *Daemon) ProcessEvent(id string, e libcontainerd.EventType, ei libc
 		} else {
 		} else {
 			logrus.WithFields(logrus.Fields{
 			logrus.WithFields(logrus.Fields{
 				"container": c.ID,
 				"container": c.ID,
+				"exec-id":   ei.ProcessID,
 				"exec-pid":  ei.Pid,
 				"exec-pid":  ei.Pid,
 			}).Warnf("Ignoring Exit Event, no such exec command found")
 			}).Warnf("Ignoring Exit Event, no such exec command found")
 		}
 		}