@@ -19,6 +19,7 @@ import (
1919 "github.com/docker/docker/quota"
2020 "github.com/docker/docker/volume"
2121 "github.com/pkg/errors"
22+ "github.com/sirupsen/logrus"
2223)
2324
2425const (
3637 // This name is used to create the bind directory, so we need to avoid characters that
3738 // would make the path to escape the root directory.
3839 volumeNameRegex = names .RestrictedNamePattern
40+
41+ _ volume.LiveRestorer = (* localVolume )(nil )
3942)
4043
4144type activeMount struct {
@@ -297,14 +300,17 @@ func (v *localVolume) CachedPath() string {
297300func (v * localVolume ) Mount (id string ) (string , error ) {
298301 v .m .Lock ()
299302 defer v .m .Unlock ()
303+ logger := log .G (context .TODO ()).WithField ("volume" , v .name )
300304 if v .needsMount () {
301305 if ! v .active .mounted {
306+ logger .Debug ("Mounting volume" )
302307 if err := v .mount (); err != nil {
303308 return "" , errdefs .System (err )
304309 }
305310 v .active .mounted = true
306311 }
307312 v .active .count ++
313+ logger .WithField ("active mounts" , v .active ).Debug ("Decremented active mount count" )
308314 }
309315 if err := v .postMount (); err != nil {
310316 return "" , err
@@ -317,19 +323,22 @@ func (v *localVolume) Mount(id string) (string, error) {
317323func (v * localVolume ) Unmount (id string ) error {
318324 v .m .Lock ()
319325 defer v .m .Unlock ()
326+ logger := log .G (context .TODO ()).WithField ("volume" , v .name )
320327
321328 // Always decrement the count, even if the unmount fails
322329 // Essentially docker doesn't care if this fails, it will send an error, but
323330 // ultimately there's nothing that can be done. If we don't decrement the count
324331 // this volume can never be removed until a daemon restart occurs.
325332 if v .needsMount () {
326333 v .active .count --
334+ logger .WithField ("active mounts" , v .active ).Debug ("Decremented active mount count" )
327335 }
328336
329337 if v .active .count > 0 {
330338 return nil
331339 }
332340
341+ logger .Debug ("Unmounting volume" )
333342 return v .unmount ()
334343}
335344
@@ -370,6 +379,24 @@ func (v *localVolume) saveOpts() error {
370379 return nil
371380}
372381
382+ // LiveRestoreVolume restores reference counts for mounts
383+ // It is assumed that the volume is already mounted since this is only called for active, live-restored containers.
384+ func (v * localVolume ) LiveRestoreVolume (ctx context.Context , _ string ) error {
385+ v .m .Lock ()
386+ defer v .m .Unlock ()
387+
388+ if ! v .needsMount () {
389+ return nil
390+ }
391+ v .active .count ++
392+ v .active .mounted = true
393+ log .G (ctx ).WithFields (logrus.Fields {
394+ "volume" : v .name ,
395+ "active mounts" : v .active ,
396+ }).Debugf ("Live restored volume" )
397+ return nil
398+ }
399+
373400// getAddress finds out address/hostname from options
374401func getAddress (opts string ) string {
375402 for _ , opt := range strings .Split (opts , "," ) {
0 commit comments