summaryrefslogtreecommitdiff
path: root/libpod/boltdb_state_linux.go
diff options
context:
space:
mode:
Diffstat (limited to 'libpod/boltdb_state_linux.go')
-rw-r--r--libpod/boltdb_state_linux.go50
1 files changed, 37 insertions, 13 deletions
diff --git a/libpod/boltdb_state_linux.go b/libpod/boltdb_state_linux.go
index 9238d22fe..fce3a1b1e 100644
--- a/libpod/boltdb_state_linux.go
+++ b/libpod/boltdb_state_linux.go
@@ -6,20 +6,44 @@ import (
"github.com/sirupsen/logrus"
)
-// parseNetNSBoltData sets ctr.state.NetNS, if any, from netNSBytes.
-// Returns true if the data is valid.
-func parseNetNSBoltData(ctr *Container, netNSBytes []byte) bool {
- // The container may not have a network namespace, so it's OK if this is
- // nil
- if netNSBytes != nil {
- nsPath := string(netNSBytes)
- netNS, err := joinNetNS(nsPath)
- if err == nil {
- ctr.state.NetNS = netNS
+// replaceNetNS handle network namespace transitions after updating a
+// container's state.
+func replaceNetNS(netNSPath string, ctr *Container, newState *containerState) error {
+ if netNSPath != "" {
+ // Check if the container's old state has a good netns
+ if ctr.state.NetNS != nil && netNSPath == ctr.state.NetNS.Path() {
+ newState.NetNS = ctr.state.NetNS
} else {
- logrus.Errorf("error joining network namespace for container %s", ctr.ID())
- return false
+ // Close the existing namespace.
+ // Whoever removed it from the database already tore it down.
+ if err := ctr.runtime.closeNetNS(ctr); err != nil {
+ return err
+ }
+
+ // Open the new network namespace
+ ns, err := joinNetNS(netNSPath)
+ if err == nil {
+ newState.NetNS = ns
+ } else {
+ logrus.Errorf("error joining network namespace for container %s", ctr.ID())
+ ctr.valid = false
+ }
+ }
+ } else {
+ // The container no longer has a network namespace
+ // Close the old one, whoever removed it from the DB should have
+ // cleaned it up already.
+ if err := ctr.runtime.closeNetNS(ctr); err != nil {
+ return err
}
}
- return true
+ return nil
+}
+
+// getNetNSPath retrieves the netns path to be stored in the database
+func getNetNSPath(ctr *Container) string {
+ if ctr.state.NetNS != nil {
+ return ctr.state.NetNS.Path()
+ }
+ return ""
}