mirror of
https://github.com/moby/moby.git
synced 2026-08-13 17:06:44 +00:00
Merge pull request #51885 from thaJeztah/daemon_volume_cleanups
daemon: daemon.registerMountPoints: use switch statement
This commit is contained in:
@@ -204,7 +204,8 @@ func (daemon *Daemon) registerMountPoints(ctr *container.Container, defaultReadO
|
||||
return duplicateMountPointError(cfg.Target)
|
||||
}
|
||||
|
||||
if mp.Type == mounttypes.TypeVolume {
|
||||
switch mp.Type {
|
||||
case mounttypes.TypeVolume:
|
||||
var v *volumetypes.Volume
|
||||
if cfg.VolumeOptions != nil {
|
||||
var driverOpts map[string]string
|
||||
@@ -234,9 +235,7 @@ func (daemon *Daemon) registerMountPoints(ctr *container.Container, defaultReadO
|
||||
if mp.Driver == volume.DefaultDriverName {
|
||||
setBindModeIfNull(mp)
|
||||
}
|
||||
}
|
||||
|
||||
if mp.Type == mounttypes.TypeBind {
|
||||
case mounttypes.TypeBind:
|
||||
if cfg.BindOptions == nil || !cfg.BindOptions.CreateMountpoint {
|
||||
mp.SkipMountpointCreation = true
|
||||
}
|
||||
@@ -247,33 +246,29 @@ func (daemon *Daemon) registerMountPoints(ctr *container.Container, defaultReadO
|
||||
}
|
||||
mp.Spec.BindOptions.ReadOnlyNonRecursive = true
|
||||
}
|
||||
}
|
||||
|
||||
if mp.Type == mounttypes.TypeImage {
|
||||
case mounttypes.TypeImage:
|
||||
img, err := daemon.imageService.GetImage(ctx, mp.Source, imagebackend.GetImageOpts{})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
rwLayerOpts := &layer.CreateRWLayerOpts{
|
||||
StorageOpt: ctr.HostConfig.StorageOpt,
|
||||
}
|
||||
|
||||
// Hash the source and destination to create a safe, unique identifier for each mount point and container.
|
||||
// This makes sure that the same image can be mounted multiple times with different destinations.
|
||||
// We hash it so that the snapshot name is friendly to the underlying filesystem and doesn't exceed path length limits.
|
||||
destHash := sha256.Sum256([]byte(ctr.ID + "-src=" + mp.Source + "-dst=" + mp.Destination))
|
||||
layerName := hex.EncodeToString(destHash[:])
|
||||
layer, err := daemon.imageService.CreateLayerFromImage(img, layerName, rwLayerOpts)
|
||||
imgLayer, err := daemon.imageService.CreateLayerFromImage(img, layerName, &layer.CreateRWLayerOpts{
|
||||
StorageOpt: ctr.HostConfig.StorageOpt,
|
||||
})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
metadata, err := layer.Metadata()
|
||||
metadata, err := imgLayer.Metadata()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
path, err := layer.Mount("")
|
||||
srcPath, err := imgLayer.Mount("")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -284,9 +279,11 @@ func (daemon *Daemon) registerMountPoints(ctr *container.Container, defaultReadO
|
||||
|
||||
mp.Name = mp.Spec.Source
|
||||
mp.Spec.Source = img.ID().String()
|
||||
mp.Source = path
|
||||
mp.Layer = layer
|
||||
mp.Source = srcPath
|
||||
mp.Layer = imgLayer
|
||||
mp.RW = false
|
||||
case mounttypes.TypeTmpfs, mounttypes.TypeCluster, mounttypes.TypeNamedPipe:
|
||||
// nothing to do
|
||||
}
|
||||
|
||||
binds[mp.Destination] = true
|
||||
|
||||
Reference in New Issue
Block a user