mount.go 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. package images
  2. import (
  3. "context"
  4. "fmt"
  5. "runtime"
  6. "github.com/containerd/log"
  7. "github.com/docker/docker/container"
  8. "github.com/pkg/errors"
  9. )
  10. // Mount sets container.BaseFS
  11. // (is it not set coming in? why is it unset?)
  12. func (i *ImageService) Mount(ctx context.Context, container *container.Container) error {
  13. if container.RWLayer == nil {
  14. return errors.New("RWLayer of container " + container.ID + " is unexpectedly nil")
  15. }
  16. dir, err := container.RWLayer.Mount(container.GetMountLabel())
  17. if err != nil {
  18. return err
  19. }
  20. log.G(ctx).WithField("container", container.ID).Debugf("container mounted via layerStore: %v", dir)
  21. if container.BaseFS != "" && container.BaseFS != dir {
  22. // The mount path reported by the graph driver should always be trusted on Windows, since the
  23. // volume path for a given mounted layer may change over time. This should only be an error
  24. // on non-Windows operating systems.
  25. if runtime.GOOS != "windows" {
  26. i.Unmount(ctx, container)
  27. return fmt.Errorf("Error: driver %s is returning inconsistent paths for container %s ('%s' then '%s')",
  28. i.StorageDriver(), container.ID, container.BaseFS, dir)
  29. }
  30. }
  31. container.BaseFS = dir // TODO: combine these fields
  32. return nil
  33. }
  34. // Unmount unsets the container base filesystem
  35. func (i *ImageService) Unmount(ctx context.Context, container *container.Container) error {
  36. if container.RWLayer == nil {
  37. return errors.New("RWLayer of container " + container.ID + " is unexpectedly nil")
  38. }
  39. if err := container.RWLayer.Unmount(); err != nil {
  40. log.G(ctx).WithField("container", container.ID).WithError(err).Error("error unmounting container")
  41. return err
  42. }
  43. return nil
  44. }