mirror of
https://github.com/containers/podman.git
synced 2025-05-20 08:36:23 +08:00
libpod: add execSessionNoCopy
To avoid creating an expensive deep copy, create an internal function to access the exec session. [NO TESTS NEEDED] Signed-off-by: Valentin Rothberg <rothberg@redhat.com>
This commit is contained in:
@ -774,9 +774,9 @@ func (c *Container) ExecSessions() ([]string, error) {
|
|||||||
return ids, nil
|
return ids, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// ExecSession retrieves detailed information on a single active exec session in
|
// execSessionNoCopy returns the associated exec session to id.
|
||||||
// a container
|
// Note that the session is not a deep copy.
|
||||||
func (c *Container) ExecSession(id string) (*ExecSession, error) {
|
func (c *Container) execSessionNoCopy(id string) (*ExecSession, error) {
|
||||||
if !c.batched {
|
if !c.batched {
|
||||||
c.lock.Lock()
|
c.lock.Lock()
|
||||||
defer c.lock.Unlock()
|
defer c.lock.Unlock()
|
||||||
@ -791,6 +791,17 @@ func (c *Container) ExecSession(id string) (*ExecSession, error) {
|
|||||||
return nil, errors.Wrapf(define.ErrNoSuchExecSession, "no exec session with ID %s found in container %s", id, c.ID())
|
return nil, errors.Wrapf(define.ErrNoSuchExecSession, "no exec session with ID %s found in container %s", id, c.ID())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return session, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// ExecSession retrieves detailed information on a single active exec session in
|
||||||
|
// a container
|
||||||
|
func (c *Container) ExecSession(id string) (*ExecSession, error) {
|
||||||
|
session, err := c.execSessionNoCopy(id)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
returnSession := new(ExecSession)
|
returnSession := new(ExecSession)
|
||||||
if err := JSONDeepCopy(session, returnSession); err != nil {
|
if err := JSONDeepCopy(session, returnSession); err != nil {
|
||||||
return nil, errors.Wrapf(err, "error copying contents of container %s exec session %s", c.ID(), session.ID())
|
return nil, errors.Wrapf(err, "error copying contents of container %s exec session %s", c.ID(), session.ID())
|
||||||
|
@ -747,7 +747,7 @@ func (c *Container) Exec(config *ExecConfig, streams *define.AttachStreams, resi
|
|||||||
return -1, err
|
return -1, err
|
||||||
}
|
}
|
||||||
|
|
||||||
session, err := c.ExecSession(sessionID)
|
session, err := c.execSessionNoCopy(sessionID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if errors.Cause(err) == define.ErrNoSuchExecSession {
|
if errors.Cause(err) == define.ErrNoSuchExecSession {
|
||||||
// TODO: If a proper Context is ever plumbed in here, we
|
// TODO: If a proper Context is ever plumbed in here, we
|
||||||
|
Reference in New Issue
Block a user