summaryrefslogtreecommitdiff
path: root/libpod
diff options
context:
space:
mode:
authorMiloslav Trmač <mitr@redhat.com>2018-07-25 04:24:43 +0200
committerAtomic Bot <atomic-devel@projectatomic.io>2018-07-26 20:47:31 +0000
commit2322f272c4ee9fb4f38aff2f6442b0d9f9ce1ad1 (patch)
treeb05938e199e4293981621cfea995ac624618adfe /libpod
parenteba6bf0018157e9594f43f1d2baeee3f56eb9cef (diff)
downloadpodman-2322f272c4ee9fb4f38aff2f6442b0d9f9ce1ad1.tar.gz
podman-2322f272c4ee9fb4f38aff2f6442b0d9f9ce1ad1.tar.bz2
podman-2322f272c4ee9fb4f38aff2f6442b0d9f9ce1ad1.zip
Use the Linux version BoltState.getContainerFromDB on all platforms.
This just muves the Linux implementation, unchanged, to the platform-agnostic file. Should not change behavior on Linux. On non-Linux platforms, reading containers from BoltDB now works (and rejects containers with namespace data). The checkRuntimeConfig validation ensures that each BoltDB database is only used on one platform, so network namespaces should never exist in non-Linux BoltDB files. Signed-off-by: Miloslav Trmač <mitr@redhat.com> Closes: #1115 Approved by: rhatdan
Diffstat (limited to 'libpod')
-rw-r--r--libpod/boltdb_state_internal.go52
-rw-r--r--libpod/boltdb_state_linux.go59
-rw-r--r--libpod/boltdb_state_unsupported.go5
3 files changed, 52 insertions, 64 deletions
diff --git a/libpod/boltdb_state_internal.go b/libpod/boltdb_state_internal.go
index 4687ed697..01ebae78f 100644
--- a/libpod/boltdb_state_internal.go
+++ b/libpod/boltdb_state_internal.go
@@ -237,6 +237,58 @@ func getRuntimeConfigBucket(tx *bolt.Tx) (*bolt.Bucket, error) {
return bkt, nil
}
+func (s *BoltState) getContainerFromDB(id []byte, ctr *Container, ctrsBkt *bolt.Bucket) error {
+ valid := true
+ ctrBkt := ctrsBkt.Bucket(id)
+ if ctrBkt == nil {
+ return errors.Wrapf(ErrNoSuchCtr, "container %s not found in DB", string(id))
+ }
+
+ if s.namespaceBytes != nil {
+ ctrNamespaceBytes := ctrBkt.Get(namespaceKey)
+ if !bytes.Equal(s.namespaceBytes, ctrNamespaceBytes) {
+ return errors.Wrapf(ErrNSMismatch, "cannot retrieve container %s as it is part of namespace %q and we are in namespace %q", string(id), string(ctrNamespaceBytes), s.namespace)
+ }
+ }
+
+ configBytes := ctrBkt.Get(configKey)
+ if configBytes == nil {
+ return errors.Wrapf(ErrInternal, "container %s missing config key in DB", string(id))
+ }
+
+ stateBytes := ctrBkt.Get(stateKey)
+ if stateBytes == nil {
+ return errors.Wrapf(ErrInternal, "container %s missing state key in DB", string(id))
+ }
+
+ netNSBytes := ctrBkt.Get(netNSKey)
+
+ if err := json.Unmarshal(configBytes, ctr.config); err != nil {
+ return errors.Wrapf(err, "error unmarshalling container %s config", string(id))
+ }
+
+ if err := json.Unmarshal(stateBytes, ctr.state); err != nil {
+ return errors.Wrapf(err, "error unmarshalling container %s state", string(id))
+ }
+
+ if !parseNetNSBoltData(ctr, netNSBytes) {
+ valid = false
+ }
+
+ // Get the lock
+ lockPath := filepath.Join(s.lockDir, string(id))
+ lock, err := storage.GetLockfile(lockPath)
+ if err != nil {
+ return errors.Wrapf(err, "error retrieving lockfile for container %s", string(id))
+ }
+ ctr.lock = lock
+
+ ctr.runtime = s.runtime
+ ctr.valid = valid
+
+ return nil
+}
+
func (s *BoltState) getPodFromDB(id []byte, pod *Pod, podBkt *bolt.Bucket) error {
podDB := podBkt.Bucket(id)
if podDB == nil {
diff --git a/libpod/boltdb_state_linux.go b/libpod/boltdb_state_linux.go
index 9c0e2b348..9238d22fe 100644
--- a/libpod/boltdb_state_linux.go
+++ b/libpod/boltdb_state_linux.go
@@ -3,13 +3,6 @@
package libpod
import (
- "bytes"
- "encoding/json"
- "path/filepath"
-
- "github.com/boltdb/bolt"
- "github.com/containers/storage"
- "github.com/pkg/errors"
"github.com/sirupsen/logrus"
)
@@ -30,55 +23,3 @@ func parseNetNSBoltData(ctr *Container, netNSBytes []byte) bool {
}
return true
}
-
-func (s *BoltState) getContainerFromDB(id []byte, ctr *Container, ctrsBkt *bolt.Bucket) error {
- valid := true
- ctrBkt := ctrsBkt.Bucket(id)
- if ctrBkt == nil {
- return errors.Wrapf(ErrNoSuchCtr, "container %s not found in DB", string(id))
- }
-
- if s.namespaceBytes != nil {
- ctrNamespaceBytes := ctrBkt.Get(namespaceKey)
- if !bytes.Equal(s.namespaceBytes, ctrNamespaceBytes) {
- return errors.Wrapf(ErrNSMismatch, "cannot retrieve container %s as it is part of namespace %q and we are in namespace %q", string(id), string(ctrNamespaceBytes), s.namespace)
- }
- }
-
- configBytes := ctrBkt.Get(configKey)
- if configBytes == nil {
- return errors.Wrapf(ErrInternal, "container %s missing config key in DB", string(id))
- }
-
- stateBytes := ctrBkt.Get(stateKey)
- if stateBytes == nil {
- return errors.Wrapf(ErrInternal, "container %s missing state key in DB", string(id))
- }
-
- netNSBytes := ctrBkt.Get(netNSKey)
-
- if err := json.Unmarshal(configBytes, ctr.config); err != nil {
- return errors.Wrapf(err, "error unmarshalling container %s config", string(id))
- }
-
- if err := json.Unmarshal(stateBytes, ctr.state); err != nil {
- return errors.Wrapf(err, "error unmarshalling container %s state", string(id))
- }
-
- if !parseNetNSBoltData(ctr, netNSBytes) {
- valid = false
- }
-
- // Get the lock
- lockPath := filepath.Join(s.lockDir, string(id))
- lock, err := storage.GetLockfile(lockPath)
- if err != nil {
- return errors.Wrapf(err, "error retrieving lockfile for container %s", string(id))
- }
- ctr.lock = lock
-
- ctr.runtime = s.runtime
- ctr.valid = valid
-
- return nil
-}
diff --git a/libpod/boltdb_state_unsupported.go b/libpod/boltdb_state_unsupported.go
index f6faaa378..960faa911 100644
--- a/libpod/boltdb_state_unsupported.go
+++ b/libpod/boltdb_state_unsupported.go
@@ -3,7 +3,6 @@
package libpod
import (
- "github.com/boltdb/bolt"
"github.com/sirupsen/logrus"
)
@@ -16,7 +15,3 @@ func parseNetNSBoltData(ctr *Container, netNSBytes []byte) bool {
}
return true
}
-
-func (s *BoltState) getContainerFromDB(id []byte, ctr *Container, ctrsBkt *bolt.Bucket) error {
- return ErrNotImplemented
-}