From 6f3e86e906a8955d3dc3ddc2a6be51b17e7a097f Mon Sep 17 00:00:00 2001 From: Kenfe-Mickael Laventure Date: Mon, 27 Nov 2017 07:53:16 -0800 Subject: [PATCH] Remove ByPid from ExecCommands Signed-off-by: Kenfe-Mickael Laventure --- daemon/exec.go | 9 --------- daemon/exec/exec.go | 23 ++--------------------- daemon/monitor.go | 3 ++- 3 files changed, 4 insertions(+), 31 deletions(-) diff --git a/daemon/exec.go b/daemon/exec.go index afdfc9c2bf..01670faa5d 100644 --- a/daemon/exec.go +++ b/daemon/exec.go @@ -31,14 +31,6 @@ func (d *Daemon) registerExecCommand(container *container.Container, config *exe 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. // It will also return the error produced by `getConfig` 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) } ec.Pid = systemPid - d.registerExecPidUnlocked(c, ec) c.ExecCommands.Unlock() ec.Unlock() diff --git a/daemon/exec/exec.go b/daemon/exec/exec.go index 7aa2383e32..42aaa86b7b 100644 --- a/daemon/exec/exec.go +++ b/daemon/exec/exec.go @@ -88,16 +88,14 @@ func (c *Config) SetExitCode(code int) { // Store keeps track of the exec configurations. type Store struct { - byID map[string]*Config - byPid map[int]*Config + byID map[string]*Config sync.RWMutex } // NewStore initializes a new exec store. func NewStore() *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() } -// 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. func (e *Store) Get(id string) *Config { e.RLock() @@ -135,18 +125,9 @@ func (e *Store) Get(id string) *Config { 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. func (e *Store) Delete(id string, pid int) { e.Lock() - delete(e.byPid, pid) delete(e.byID, id) e.Unlock() } diff --git a/daemon/monitor.go b/daemon/monitor.go index c0a265dac5..56091ebbf2 100644 --- a/daemon/monitor.go +++ b/daemon/monitor.go @@ -108,7 +108,7 @@ func (daemon *Daemon) ProcessEvent(id string, e libcontainerd.EventType, ei libc 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) execConfig.Lock() defer execConfig.Unlock() @@ -125,6 +125,7 @@ func (daemon *Daemon) ProcessEvent(id string, e libcontainerd.EventType, ei libc } else { logrus.WithFields(logrus.Fields{ "container": c.ID, + "exec-id": ei.ProcessID, "exec-pid": ei.Pid, }).Warnf("Ignoring Exit Event, no such exec command found") }