From b3659d296dbf13d3b02b07a8f708baccc9615aca Mon Sep 17 00:00:00 2001 From: Derek McGowan Date: Tue, 7 Nov 2017 23:20:23 -0800 Subject: [PATCH] Fix not found caused by race to remove snapshot Remapped snapshots are not currently referenced by any root allowing clean up of the snapshot. Check for not found on prepare to account for cleanup after stat. Signed-off-by: Derek McGowan --- spec_opts_unix.go | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/spec_opts_unix.go b/spec_opts_unix.go index 337095cfa..01d5121d4 100644 --- a/spec_opts_unix.go +++ b/spec_opts_unix.go @@ -16,6 +16,7 @@ import ( "github.com/containerd/containerd/containers" "github.com/containerd/containerd/content" + "github.com/containerd/containerd/errdefs" "github.com/containerd/containerd/fs" "github.com/containerd/containerd/images" "github.com/containerd/containerd/namespaces" @@ -260,12 +261,13 @@ func withRemappedSnapshotBase(id string, i Image, uid, gid uint32, readonly bool usernsID = fmt.Sprintf("%s-%d-%d", parent, uid, gid) ) if _, err := snapshotter.Stat(ctx, usernsID); err == nil { - if _, err := snapshotter.Prepare(ctx, id, usernsID); err != nil { + if _, err := snapshotter.Prepare(ctx, id, usernsID); err == nil { + c.SnapshotKey = id + c.Image = i.Name() + return nil + } else if !errdefs.IsNotFound(err) { return err } - c.SnapshotKey = id - c.Image = i.Name() - return nil } mounts, err := snapshotter.Prepare(ctx, usernsID+"-remap", parent) if err != nil {