Skip to content

Commit a6d2595

Browse files
authored
Merge pull request moby#51885 from thaJeztah/daemon_volume_cleanups
daemon: daemon.registerMountPoints: use switch statement
2 parents bc5c70a + e8f088c commit a6d2595

File tree

1 file changed

+13
-16
lines changed

1 file changed

+13
-16
lines changed

daemon/volumes.go

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,8 @@ func (daemon *Daemon) registerMountPoints(ctr *container.Container, defaultReadO
204204
return duplicateMountPointError(cfg.Target)
205205
}
206206

207-
if mp.Type == mounttypes.TypeVolume {
207+
switch mp.Type {
208+
case mounttypes.TypeVolume:
208209
var v *volumetypes.Volume
209210
if cfg.VolumeOptions != nil {
210211
var driverOpts map[string]string
@@ -234,9 +235,7 @@ func (daemon *Daemon) registerMountPoints(ctr *container.Container, defaultReadO
234235
if mp.Driver == volume.DefaultDriverName {
235236
setBindModeIfNull(mp)
236237
}
237-
}
238-
239-
if mp.Type == mounttypes.TypeBind {
238+
case mounttypes.TypeBind:
240239
if cfg.BindOptions == nil || !cfg.BindOptions.CreateMountpoint {
241240
mp.SkipMountpointCreation = true
242241
}
@@ -247,33 +246,29 @@ func (daemon *Daemon) registerMountPoints(ctr *container.Container, defaultReadO
247246
}
248247
mp.Spec.BindOptions.ReadOnlyNonRecursive = true
249248
}
250-
}
251-
252-
if mp.Type == mounttypes.TypeImage {
249+
case mounttypes.TypeImage:
253250
img, err := daemon.imageService.GetImage(ctx, mp.Source, imagebackend.GetImageOpts{})
254251
if err != nil {
255252
return err
256253
}
257254

258-
rwLayerOpts := &layer.CreateRWLayerOpts{
259-
StorageOpt: ctr.HostConfig.StorageOpt,
260-
}
261-
262255
// Hash the source and destination to create a safe, unique identifier for each mount point and container.
263256
// This makes sure that the same image can be mounted multiple times with different destinations.
264257
// We hash it so that the snapshot name is friendly to the underlying filesystem and doesn't exceed path length limits.
265258
destHash := sha256.Sum256([]byte(ctr.ID + "-src=" + mp.Source + "-dst=" + mp.Destination))
266259
layerName := hex.EncodeToString(destHash[:])
267-
layer, err := daemon.imageService.CreateLayerFromImage(img, layerName, rwLayerOpts)
260+
imgLayer, err := daemon.imageService.CreateLayerFromImage(img, layerName, &layer.CreateRWLayerOpts{
261+
StorageOpt: ctr.HostConfig.StorageOpt,
262+
})
268263
if err != nil {
269264
return err
270265
}
271-
metadata, err := layer.Metadata()
266+
metadata, err := imgLayer.Metadata()
272267
if err != nil {
273268
return err
274269
}
275270

276-
path, err := layer.Mount("")
271+
srcPath, err := imgLayer.Mount("")
277272
if err != nil {
278273
return err
279274
}
@@ -284,9 +279,11 @@ func (daemon *Daemon) registerMountPoints(ctr *container.Container, defaultReadO
284279

285280
mp.Name = mp.Spec.Source
286281
mp.Spec.Source = img.ID().String()
287-
mp.Source = path
288-
mp.Layer = layer
282+
mp.Source = srcPath
283+
mp.Layer = imgLayer
289284
mp.RW = false
285+
case mounttypes.TypeTmpfs, mounttypes.TypeCluster, mounttypes.TypeNamedPipe:
286+
// nothing to do
290287
}
291288

292289
binds[mp.Destination] = true

0 commit comments

Comments
 (0)