diff options
author | Matthew Heon <matthew.heon@gmail.com> | 2018-02-23 15:28:56 -0500 |
---|---|---|
committer | Atomic Bot <atomic-devel@projectatomic.io> | 2018-03-01 21:17:50 +0000 |
commit | 2a0c949b9bab88f4e05d39b5e6d7db62bb39df11 (patch) | |
tree | 35c75dcf96b4d571c29daafb54c6bc0c4be29c41 /libpod/sql_state.go | |
parent | 920b66707ece354b8dbf00416b5a26abdee93a2f (diff) | |
download | podman-2a0c949b9bab88f4e05d39b5e6d7db62bb39df11.tar.gz podman-2a0c949b9bab88f4e05d39b5e6d7db62bb39df11.tar.bz2 podman-2a0c949b9bab88f4e05d39b5e6d7db62bb39df11.zip |
Add tracking for container exec sessions to DB
Signed-off-by: Matthew Heon <matthew.heon@gmail.com>
Closes: #412
Approved by: baude
Diffstat (limited to 'libpod/sql_state.go')
-rw-r--r-- | libpod/sql_state.go | 29 |
1 files changed, 23 insertions, 6 deletions
diff --git a/libpod/sql_state.go b/libpod/sql_state.go index cf759d836..abf48543f 100644 --- a/libpod/sql_state.go +++ b/libpod/sql_state.go @@ -14,7 +14,7 @@ import ( // DBSchema is the current DB schema version // Increments every time a change is made to the database's tables -const DBSchema = 11 +const DBSchema = 12 // SQLState is a state implementation backed by a persistent SQLite3 database type SQLState struct { @@ -102,7 +102,8 @@ func (s *SQLState) Refresh() (err error) { Pid=?, NetNSPath=?, IPAddress=?, - SubnetMask=?;` + SubnetMask=?, + ExecSessions=?;` if !s.valid { return ErrDBClosed @@ -132,7 +133,8 @@ func (s *SQLState) Refresh() (err error) { 0, "", "", - "") + "", + "{}") if err != nil { return errors.Wrapf(err, "error refreshing database state") } @@ -269,7 +271,8 @@ func (s *SQLState) UpdateContainer(ctr *Container) error { Pid, NetNSPath, IPAddress, - SubnetMask + SubnetMask, + ExecSessions FROM containerState WHERE ID=?;` var ( @@ -285,6 +288,7 @@ func (s *SQLState) UpdateContainer(ctr *Container) error { netNSPath string ipAddress string subnetMask string + execSessions string ) if !s.valid { @@ -308,7 +312,8 @@ func (s *SQLState) UpdateContainer(ctr *Container) error { &pid, &netNSPath, &ipAddress, - &subnetMask) + &subnetMask, + &execSessions) if err != nil { // The container may not exist in the database if err == sql.ErrNoRows { @@ -333,6 +338,11 @@ func (s *SQLState) UpdateContainer(ctr *Container) error { newState.IPAddress = ipAddress newState.SubnetMask = subnetMask + newState.ExecSessions = make(map[string]int) + if err := json.Unmarshal([]byte(execSessions), &newState.ExecSessions); err != nil { + return errors.Wrapf(err, "error parsing container %s exec sessions", ctr.ID()) + } + if newState.Mountpoint != "" { newState.Mounted = true } @@ -395,13 +405,19 @@ func (s *SQLState) SaveContainer(ctr *Container) (err error) { Pid=?, NetNSPath=?, IPAddress=?, - SubnetMask=? + SubnetMask=?, + ExecSessions=? WHERE Id=?;` if !ctr.valid { return ErrCtrRemoved } + execSessionsJSON, err := json.Marshal(ctr.state.ExecSessions) + if err != nil { + return errors.Wrapf(err, "error marshalling container %s exec sessions", ctr.ID()) + } + netNSPath := "" if ctr.state.NetNS != nil { netNSPath = ctr.state.NetNS.Path() @@ -439,6 +455,7 @@ func (s *SQLState) SaveContainer(ctr *Container) (err error) { netNSPath, ctr.state.IPAddress, ctr.state.SubnetMask, + execSessionsJSON, ctr.ID()) if err != nil { return errors.Wrapf(err, "error updating container %s state in database", ctr.ID()) |