Add overlay cleanup

Updates overlay remove to simply remove the reference, adds
a cleanup method for discarding the directory.
Updates snapshot create to setup the directory structure while
in the transaction, to prevent cleanup from removing directories
which are part of a create.

Signed-off-by: Derek McGowan <derek@mcgstyle.net>
This commit is contained in:
Derek McGowan
2017-11-16 11:53:10 -08:00
parent eed3b1c804
commit 14d402e289
3 changed files with 125 additions and 49 deletions

View File

@@ -597,14 +597,23 @@ func validateSnapshot(info *snapshots.Info) error {
return nil
}
type cleaner interface {
Cleanup(ctx context.Context) error
}
func (s *snapshotter) garbageCollect(ctx context.Context) (d time.Duration, err error) {
s.l.Lock()
t1 := time.Now()
defer func() {
s.l.Unlock()
if err == nil {
if c, ok := s.Snapshotter.(cleaner); ok {
err = c.Cleanup(ctx)
}
}
if err == nil {
d = time.Now().Sub(t1)
}
s.l.Unlock()
}()
seen := map[string]struct{}{}