From eca7bd270562f3d314319c50b6fd77daa3c57a3d Mon Sep 17 00:00:00 2001 From: Julio Montes Date: Thu, 10 Oct 2019 20:44:07 +0000 Subject: [PATCH] virtcontainers: unmount host mounts if container can't be created Mount points, like `resolv.conf` and `hostname` are left in the host when the cgroup creation fails. Use `unmountHostMounts()` and `bindUnmountContainerRootfs()` in the rollback function that is called when container's creation fails. fixes #2108 Signed-off-by: Julio Montes --- virtcontainers/container.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/virtcontainers/container.go b/virtcontainers/container.go index 20b96a585c..be4f043ced 100644 --- a/virtcontainers/container.go +++ b/virtcontainers/container.go @@ -857,6 +857,12 @@ func (c *Container) rollbackFailingContainerCreation() { if err := c.removeDrive(); err != nil { c.Logger().WithError(err).Error("rollback failed removeDrive()") } + if err := c.unmountHostMounts(); err != nil { + c.Logger().WithError(err).Error("rollback failed unmountHostMounts()") + } + if err := bindUnmountContainerRootfs(c.ctx, kataHostSharedDir(), c.sandbox.id, c.id); err != nil { + c.Logger().WithError(err).Error("rollback failed bindUnmountContainerRootfs()") + } } func (c *Container) checkBlockDeviceSupport() bool {