snapshotter: avoid snapshot removal race

Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
docker-18.09
Tonis Tiigi 2018-04-30 10:40:52 -07:00
parent 2af19a8847
commit d7f8a4e1a4
1 changed files with 10 additions and 1 deletions

View File

@ -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) {