From d7f8a4e1a4eaf8a2aa5d9286f74d0ab614adcee5 Mon Sep 17 00:00:00 2001 From: Tonis Tiigi Date: Mon, 30 Apr 2018 10:40:52 -0700 Subject: [PATCH] snapshotter: avoid snapshot removal race Signed-off-by: Tonis Tiigi --- snapshot/containerd/snapshotter.go | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/snapshot/containerd/snapshotter.go b/snapshot/containerd/snapshotter.go index e288ece4..6df93a67 100644 --- a/snapshot/containerd/snapshotter.go +++ b/snapshot/containerd/snapshotter.go @@ -29,7 +29,16 @@ type nsSnapshotter struct { func (s *nsSnapshotter) Stat(ctx context.Context, key string) (ctdsnapshot.Info, error) { ctx = namespaces.WithNamespace(ctx, s.ns) - return s.Snapshotter.Stat(ctx, key) + info, err := s.Snapshotter.Stat(ctx, key) + if err == nil { + if _, ok := info.Labels["labels.containerd.io/gc.root"]; !ok { + if err := addRootLabel()(&info); err != nil { + return info, err + } + return s.Update(ctx, info, "labels.containerd.io/gc.root") + } + } + return info, err } func (s *nsSnapshotter) Update(ctx context.Context, info ctdsnapshot.Info, fieldpaths ...string) (ctdsnapshot.Info, error) {