github.com/rish1988/moby@v25.0.2+incompatible/daemon/images/mount.go (about)

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