github.com/Prakhar-Agarwal-byte/moby@v0.0.0-20231027092010-a14e3e8ab87e/daemon/containerd/mount.go (about)

     1  package containerd
     2  
     3  import (
     4  	"context"
     5  	"fmt"
     6  
     7  	"github.com/Prakhar-Agarwal-byte/moby/container"
     8  	"github.com/containerd/log"
     9  )
    10  
    11  // Mount mounts the container filesystem in a temporary location, use defer imageService.Unmount
    12  // to unmount the filesystem when calling this
    13  func (i *ImageService) Mount(ctx context.Context, container *container.Container) error {
    14  	snapshotter := i.client.SnapshotService(container.Driver)
    15  	mounts, err := snapshotter.Mounts(ctx, container.ID)
    16  	if err != nil {
    17  		return err
    18  	}
    19  
    20  	var root string
    21  	if root, err = i.refCountMounter.Mount(mounts, container.ID); err != nil {
    22  		return fmt.Errorf("failed to mount %s: %w", root, err)
    23  	}
    24  
    25  	log.G(ctx).WithField("container", container.ID).Debugf("container mounted via snapshotter: %v", root)
    26  
    27  	container.BaseFS = root
    28  	return nil
    29  }
    30  
    31  // Unmount unmounts the container base filesystem
    32  func (i *ImageService) Unmount(ctx context.Context, container *container.Container) error {
    33  	root := container.BaseFS
    34  
    35  	if err := i.refCountMounter.Unmount(root); err != nil {
    36  		log.G(ctx).WithField("container", container.ID).WithError(err).Error("error unmounting container")
    37  		return fmt.Errorf("failed to unmount %s: %w", root, err)
    38  	}
    39  
    40  	return nil
    41  }