Browse code

Daemon.createContainerOSSpecificSettings - remove redundant param

Also:
- remove the hostConfig param from Daemon.createContainerVolumesOS.
- rename var container -> ctr

Signed-off-by: Rob Murray <rob.murray@docker.com>

Rob Murray authored on 2025/11/14 21:15:21
Showing 3 changed files
... ...
@@ -246,7 +246,7 @@ func (daemon *Daemon) create(ctx context.Context, daemonCfg *config.Config, opts
246 246
 	if err := daemon.registerLinks(ctr); err != nil {
247 247
 		return nil, err
248 248
 	}
249
-	if err := daemon.createContainerOSSpecificSettings(ctx, ctr, opts.params.HostConfig); err != nil {
249
+	if err := daemon.createContainerOSSpecificSettings(ctx, ctr); err != nil {
250 250
 		return nil, err
251 251
 	}
252 252
 
... ...
@@ -264,7 +264,7 @@ func (daemon *Daemon) create(ctx context.Context, daemonCfg *config.Config, opts
264 264
 	if err := daemon.registerMountPoints(ctr, opts.params.DefaultReadOnlyNonRecursive); err != nil {
265 265
 		return nil, err
266 266
 	}
267
-	if err := daemon.createContainerVolumesOS(ctx, ctr, opts.params.Config, opts.params.HostConfig); err != nil {
267
+	if err := daemon.createContainerVolumesOS(ctx, ctr, opts.params.Config); err != nil {
268 268
 		return nil, err
269 269
 	}
270 270
 
... ...
@@ -22,27 +22,25 @@ import (
22 22
 )
23 23
 
24 24
 // createContainerOSSpecificSettings performs host-OS specific container create functionality
25
-func (daemon *Daemon) createContainerOSSpecificSettings(ctx context.Context, container *container.Container, hostConfig *containertypes.HostConfig) error {
25
+func (daemon *Daemon) createContainerOSSpecificSettings(ctx context.Context, ctr *container.Container) error {
26 26
 	// Set the default masked and readonly paths with regard to the host config options if they are not set.
27
-	if hostConfig.MaskedPaths == nil && !hostConfig.Privileged {
28
-		hostConfig.MaskedPaths = oci.DefaultSpec().Linux.MaskedPaths // Set it to the default if nil
29
-		container.HostConfig.MaskedPaths = hostConfig.MaskedPaths
27
+	if ctr.HostConfig.MaskedPaths == nil && !ctr.HostConfig.Privileged {
28
+		ctr.HostConfig.MaskedPaths = oci.DefaultSpec().Linux.MaskedPaths // Set it to the default if nil
30 29
 	}
31
-	if hostConfig.ReadonlyPaths == nil && !hostConfig.Privileged {
32
-		hostConfig.ReadonlyPaths = oci.DefaultSpec().Linux.ReadonlyPaths // Set it to the default if nil
33
-		container.HostConfig.ReadonlyPaths = hostConfig.ReadonlyPaths
30
+	if ctr.HostConfig.ReadonlyPaths == nil && !ctr.HostConfig.Privileged {
31
+		ctr.HostConfig.ReadonlyPaths = oci.DefaultSpec().Linux.ReadonlyPaths // Set it to the default if nil
34 32
 	}
35 33
 	return nil
36 34
 }
37 35
 
38 36
 // createContainerVolumesOS performs host-OS specific volume creation
39
-func (daemon *Daemon) createContainerVolumesOS(ctx context.Context, container *container.Container, config *containertypes.Config, hostConfig *containertypes.HostConfig) error {
40
-	if err := daemon.Mount(container); err != nil {
37
+func (daemon *Daemon) createContainerVolumesOS(ctx context.Context, ctr *container.Container, config *containertypes.Config) error {
38
+	if err := daemon.Mount(ctr); err != nil {
41 39
 		return err
42 40
 	}
43
-	defer daemon.Unmount(container)
41
+	defer daemon.Unmount(ctr)
44 42
 
45
-	if err := container.SetupWorkingDirectory(daemon.idMapping.RootPair()); err != nil {
43
+	if err := ctr.SetupWorkingDirectory(daemon.idMapping.RootPair()); err != nil {
46 44
 		return err
47 45
 	}
48 46
 
... ...
@@ -51,12 +49,12 @@ func (daemon *Daemon) createContainerVolumesOS(ctx context.Context, container *c
51 51
 
52 52
 		// Skip volumes for which we already have something mounted on that
53 53
 		// destination because of a --volume-from.
54
-		if container.HasMountFor(destination) {
55
-			log.G(ctx).WithField("container", container.ID).WithField("destination", spec).Debug("mountpoint already exists, skipping anonymous volume")
54
+		if ctr.HasMountFor(destination) {
55
+			log.G(ctx).WithField("container", ctr.ID).WithField("destination", spec).Debug("mountpoint already exists, skipping anonymous volume")
56 56
 			// Not an error, this could easily have come from the image config.
57 57
 			continue
58 58
 		}
59
-		path, err := container.GetResourcePath(destination)
59
+		path, err := ctr.GetResourcePath(destination)
60 60
 		if err != nil {
61 61
 			return err
62 62
 		}
... ...
@@ -66,18 +64,18 @@ func (daemon *Daemon) createContainerVolumesOS(ctx context.Context, container *c
66 66
 			return fmt.Errorf("cannot mount volume over existing file, file exists %s", path)
67 67
 		}
68 68
 
69
-		v, err := daemon.volumes.Create(context.TODO(), "", hostConfig.VolumeDriver, volumeopts.WithCreateReference(container.ID))
69
+		v, err := daemon.volumes.Create(context.TODO(), "", ctr.HostConfig.VolumeDriver, volumeopts.WithCreateReference(ctr.ID))
70 70
 		if err != nil {
71 71
 			return err
72 72
 		}
73 73
 
74
-		if err := label.Relabel(v.Mountpoint, container.MountLabel, true); err != nil {
74
+		if err := label.Relabel(v.Mountpoint, ctr.MountLabel, true); err != nil {
75 75
 			return err
76 76
 		}
77 77
 
78
-		container.AddMountPointWithVolume(destination, &volumeWrapper{v: v, s: daemon.volumes}, true)
78
+		ctr.AddMountPointWithVolume(destination, &volumeWrapper{v: v, s: daemon.volumes}, true)
79 79
 	}
80
-	return daemon.populateVolumes(ctx, container)
80
+	return daemon.populateVolumes(ctx, ctr)
81 81
 }
82 82
 
83 83
 // populateVolumes copies data from the container's rootfs into the volume for non-binds.
... ...
@@ -11,35 +11,33 @@ import (
11 11
 )
12 12
 
13 13
 // createContainerOSSpecificSettings performs host-OS specific container create functionality
14
-func (daemon *Daemon) createContainerOSSpecificSettings(ctx context.Context, container *container.Container, hostConfig *containertypes.HostConfig) error {
15
-	if containertypes.Isolation.IsDefault(hostConfig.Isolation) {
14
+func (daemon *Daemon) createContainerOSSpecificSettings(ctx context.Context, ctr *container.Container) error {
15
+	if containertypes.Isolation.IsDefault(ctr.HostConfig.Isolation) {
16 16
 		// Make sure the host config has the default daemon isolation if not specified by caller.
17
-		hostConfig.Isolation = daemon.defaultIsolation
17
+		ctr.HostConfig.Isolation = daemon.defaultIsolation
18 18
 	}
19 19
 	return nil
20 20
 }
21 21
 
22 22
 // createContainerVolumesOS performs host-OS specific volume creation
23
-func (daemon *Daemon) createContainerVolumesOS(ctx context.Context, container *container.Container, config *containertypes.Config, hostConfig *containertypes.HostConfig) error {
23
+func (daemon *Daemon) createContainerVolumesOS(ctx context.Context, ctr *container.Container, config *containertypes.Config) error {
24 24
 	parser := volumemounts.NewParser()
25 25
 	for spec := range config.Volumes {
26 26
 
27
-		mp, err := parser.ParseMountRaw(spec, hostConfig.VolumeDriver)
27
+		mp, err := parser.ParseMountRaw(spec, ctr.HostConfig.VolumeDriver)
28 28
 		if err != nil {
29 29
 			return fmt.Errorf("Unrecognised volume spec: %v", err)
30 30
 		}
31 31
 
32 32
 		// Skip volumes for which we already have something mounted on that
33 33
 		// destination because of a --volume-from.
34
-		if container.IsDestinationMounted(mp.Destination) {
34
+		if ctr.IsDestinationMounted(mp.Destination) {
35 35
 			continue
36 36
 		}
37 37
 
38
-		volumeDriver := hostConfig.VolumeDriver
39
-
40 38
 		// Create the volume in the volume driver. If it doesn't exist,
41 39
 		// a new one will be created.
42
-		v, err := daemon.volumes.Create(ctx, "", volumeDriver, volumeopts.WithCreateReference(container.ID))
40
+		v, err := daemon.volumes.Create(ctx, "", ctr.HostConfig.VolumeDriver, volumeopts.WithCreateReference(ctr.ID))
43 41
 		if err != nil {
44 42
 			return err
45 43
 		}
... ...
@@ -75,7 +73,7 @@ func (daemon *Daemon) createContainerVolumesOS(ctx context.Context, container *c
75 75
 		//	}
76 76
 
77 77
 		// Add it to container.MountPoints
78
-		container.AddMountPointWithVolume(mp.Destination, &volumeWrapper{v: v, s: daemon.volumes}, mp.RW)
78
+		ctr.AddMountPointWithVolume(mp.Destination, &volumeWrapper{v: v, s: daemon.volumes}, mp.RW)
79 79
 	}
80 80
 	return nil
81 81
 }