Skip to content

Commit ed308ea

Browse files
committed
Unmount rootfs with separate Remove() in bundle
This ensures that a container does not have a mounted rootfs in the bundle directory before RemoveAll is called. Having the rootfs removed first with a Remove ensures that the directory is not mounted and empty before the bundle directory is removed. Signed-off-by: Michael Crosby <crosbymichael@gmail.com>
1 parent 40f54dc commit ed308ea

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

runtime/v2/bundle.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import (
2424
"path/filepath"
2525

2626
"github.com/containerd/containerd/identifiers"
27+
"github.com/containerd/containerd/mount"
2728
"github.com/containerd/containerd/namespaces"
2829
"github.com/pkg/errors"
2930
)
@@ -116,6 +117,13 @@ type Bundle struct {
116117
// Delete a bundle atomically
117118
func (b *Bundle) Delete() error {
118119
work, werr := os.Readlink(filepath.Join(b.Path, "work"))
120+
rootfs := filepath.Join(b.Path, "rootfs")
121+
if err := mount.UnmountAll(rootfs, 0); err != nil {
122+
return errors.Wrapf(err, "unmount rootfs %s", rootfs)
123+
}
124+
if err := os.Remove(rootfs); err != nil && os.IsNotExist(err) {
125+
return errors.Wrap(err, "failed to remove bundle rootfs")
126+
}
119127
err := atomicDelete(b.Path)
120128
if err == nil {
121129
if werr == nil {

0 commit comments

Comments
 (0)