From 763e3726493c122d9722e0e294634ae8d78c426b Mon Sep 17 00:00:00 2001 From: Matthew Heon Date: Thu, 9 Nov 2017 13:51:20 -0500 Subject: Wire SQL backed state into rest of libpod Signed-off-by: Matthew Heon --- libpod/runtime_ctr.go | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) (limited to 'libpod/runtime_ctr.go') diff --git a/libpod/runtime_ctr.go b/libpod/runtime_ctr.go index b23c65287..a8a5b789d 100644 --- a/libpod/runtime_ctr.go +++ b/libpod/runtime_ctr.go @@ -95,17 +95,21 @@ func (r *Runtime) RemoveContainer(c *Container, force bool) error { return ErrCtrRemoved } - // TODO check container status and unmount storage - // TODO check that no other containers depend on this container's - // namespaces - status, err := c.State() - if err != nil { + // Update the container to get current state + if err := r.state.UpdateContainer(c); err != nil { return err } - // A container cannot be removed if it is running - if status == ContainerStateRunning { - return errors.Wrapf(ErrCtrStateInvalid, "cannot remove container %s as it is running", c.ID()) + // Check that the container's in a good state to be removed + if !(c.state.State == ContainerStateConfigured || + c.state.State == ContainerStateCreated || + c.state.State == ContainerStateStopped) { + return errors.Wrapf(ErrCtrStateInvalid, "cannot remove container %s as it is running or paused", c.ID()) + } + + // Stop the container's storage + if err := c.teardownStorage(); err != nil { + return err } if err := r.state.RemoveContainer(c); err != nil { -- cgit v1.2.3-54-g00ecf From 12f19ca013bad5382eec72abf4cf2d5d7c71d3a5 Mon Sep 17 00:00:00 2001 From: Matthew Heon Date: Thu, 9 Nov 2017 15:27:33 -0500 Subject: Resolve another segfault This one cleans up after container creation fails Signed-off-by: Matthew Heon --- libpod/runtime_ctr.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'libpod/runtime_ctr.go') diff --git a/libpod/runtime_ctr.go b/libpod/runtime_ctr.go index a8a5b789d..aa8ff7d88 100644 --- a/libpod/runtime_ctr.go +++ b/libpod/runtime_ctr.go @@ -19,14 +19,14 @@ type CtrCreateOption func(*Container) error type ContainerFilter func(*Container) bool // NewContainer creates a new container from a given OCI config -func (r *Runtime) NewContainer(spec *spec.Spec, options ...CtrCreateOption) (ctr *Container, err error) { +func (r *Runtime) NewContainer(spec *spec.Spec, options ...CtrCreateOption) (c *Container, err error) { r.lock.Lock() defer r.lock.Unlock() if !r.valid { return nil, ErrRuntimeStopped } - ctr, err = newContainer(spec) + ctr, err := newContainer(spec) if err != nil { return nil, err } @@ -60,7 +60,7 @@ func (r *Runtime) NewContainer(spec *spec.Spec, options ...CtrCreateOption) (ctr } } defer func() { - if err != nil { + if err != nil && ctr.pod != nil { if err2 := ctr.pod.removeContainer(ctr); err2 != nil { logrus.Errorf("Error removing partially-created container from pod %s: %s", ctr.pod.ID(), err2) } -- cgit v1.2.3-54-g00ecf