Add specific types for Required and Optional DeviceNodes
Docker-DCO-1.1-Signed-off-by: Michael Crosby <michael@crosbymichael.com> (github: crosbymichael)
| ... | ... |
@@ -101,9 +101,9 @@ func (d *driver) setPrivileged(container *libcontainer.Container) (err error) {
|
| 101 | 101 |
container.Cgroups.DeviceAccess = true |
| 102 | 102 |
|
| 103 | 103 |
delete(container.Context, "restrictions") |
| 104 |
- delete(container.DeviceNodes, "additional") |
|
| 105 | 104 |
|
| 106 |
- if container.DeviceNodes["required"], err = nodes.GetHostDeviceNodes(); err != nil {
|
|
| 105 |
+ container.OptionalDeviceNodes = nil |
|
| 106 |
+ if container.RequiredDeviceNodes, err = nodes.GetHostDeviceNodes(); err != nil {
|
|
| 107 | 107 |
return err |
| 108 | 108 |
} |
| 109 | 109 |
|
| ... | ... |
@@ -33,11 +33,9 @@ func New() *libcontainer.Container {
|
| 33 | 33 |
Parent: "docker", |
| 34 | 34 |
DeviceAccess: false, |
| 35 | 35 |
}, |
| 36 |
- Context: libcontainer.Context{},
|
|
| 37 |
- DeviceNodes: map[string][]string{
|
|
| 38 |
- "required": nodes.DefaultNodes, |
|
| 39 |
- "additional": {"fuse"},
|
|
| 40 |
- }, |
|
| 36 |
+ Context: libcontainer.Context{},
|
|
| 37 |
+ RequiredDeviceNodes: nodes.DefaultNodes, |
|
| 38 |
+ OptionalDeviceNodes: []string{"fuse"},
|
|
| 41 | 39 |
} |
| 42 | 40 |
if apparmor.IsEnabled() {
|
| 43 | 41 |
container.Context["apparmor_profile"] = "docker-default" |
| ... | ... |
@@ -43,7 +43,7 @@ type Container struct {
|
| 43 | 43 |
// All capbilities not specified will be dropped from the processes capability mask |
| 44 | 44 |
Capabilities []string `json:"capabilities,omitempty"` |
| 45 | 45 |
|
| 46 |
- // Networks specifies the container's network stop to be created |
|
| 46 |
+ // Networks specifies the container's network setup to be created |
|
| 47 | 47 |
Networks []*Network `json:"networks,omitempty"` |
| 48 | 48 |
|
| 49 | 49 |
// Cgroups specifies specific cgroup settings for the various subsystems that the container is |
| ... | ... |
@@ -60,14 +60,13 @@ type Container struct {
|
| 60 | 60 |
// rootfs and mount namespace if specified |
| 61 | 61 |
Mounts Mounts `json:"mounts,omitempty"` |
| 62 | 62 |
|
| 63 |
- // DeviceNodes are a list of 'required' and 'additional' nodes that will be mknod into the container's |
|
| 64 |
- // rootfs at /dev |
|
| 65 |
- // |
|
| 66 |
- // Required device nodes will return an error if the host system does not have this device available |
|
| 67 |
- // |
|
| 68 |
- // Additional device nodes are created but no error is returned if the host system does not have the |
|
| 69 |
- // device avaliable for use by the container |
|
| 70 |
- DeviceNodes map[string][]string `json:"device_nodes,omitempty"` |
|
| 63 |
+ // RequiredDeviceNodes are a list of device nodes that will be mknod into the container's rootfs at /dev |
|
| 64 |
+ // If the host system does not support the device that the container requests an error is returned |
|
| 65 |
+ RequiredDeviceNodes []string `json:"required_device_nodes,omitempty"` |
|
| 66 |
+ |
|
| 67 |
+ // OptionalDeviceNodes are a list of device nodes that will be mknod into the container's rootfs at /dev |
|
| 68 |
+ // If the host system does not support the device that the container requests the error is ignored |
|
| 69 |
+ OptionalDeviceNodes []string `json:"optional_device_nodes,omitempty"` |
|
| 71 | 70 |
} |
| 72 | 71 |
|
| 73 | 72 |
// Network defines configuration for a container's networking stack |
| ... | ... |
@@ -44,14 +44,12 @@ |
| 44 | 44 |
"type": "devtmpfs" |
| 45 | 45 |
} |
| 46 | 46 |
], |
| 47 |
- "device_nodes": {
|
|
| 48 |
- "required": [ |
|
| 49 |
- "null", |
|
| 50 |
- "zero", |
|
| 51 |
- "full", |
|
| 52 |
- "random", |
|
| 53 |
- "urandom", |
|
| 54 |
- "tty" |
|
| 55 |
- ] |
|
| 56 |
- } |
|
| 47 |
+ "required_device_nodes": [ |
|
| 48 |
+ "null", |
|
| 49 |
+ "zero", |
|
| 50 |
+ "full", |
|
| 51 |
+ "random", |
|
| 52 |
+ "urandom", |
|
| 53 |
+ "tty" |
|
| 54 |
+ ] |
|
| 57 | 55 |
} |
| ... | ... |
@@ -65,7 +65,7 @@ func TestContainerJsonFormat(t *testing.T) {
|
| 65 | 65 |
} |
| 66 | 66 |
|
| 67 | 67 |
for _, n := range nodes.DefaultNodes {
|
| 68 |
- if !contains(n, container.DeviceNodes["required"]) {
|
|
| 68 |
+ if !contains(n, container.RequiredDeviceNodes) {
|
|
| 69 | 69 |
t.Logf("devices should contain %s", n)
|
| 70 | 70 |
t.Fail() |
| 71 | 71 |
} |
| ... | ... |
@@ -48,11 +48,11 @@ func InitializeMountNamespace(rootfs, console string, container *libcontainer.Co |
| 48 | 48 |
if err := setupBindmounts(rootfs, container.Mounts); err != nil {
|
| 49 | 49 |
return fmt.Errorf("bind mounts %s", err)
|
| 50 | 50 |
} |
| 51 |
- if err := nodes.CopyN(rootfs, container.DeviceNodes["required"], true); err != nil {
|
|
| 51 |
+ if err := nodes.CopyN(rootfs, container.RequiredDeviceNodes, true); err != nil {
|
|
| 52 | 52 |
return fmt.Errorf("copy required dev nodes %s", err)
|
| 53 | 53 |
} |
| 54 |
- if err := nodes.CopyN(rootfs, container.DeviceNodes["additional"], false); err != nil {
|
|
| 55 |
- return fmt.Errorf("copy additional dev nodes %s", err)
|
|
| 54 |
+ if err := nodes.CopyN(rootfs, container.OptionalDeviceNodes, false); err != nil {
|
|
| 55 |
+ return fmt.Errorf("copy optional dev nodes %s", err)
|
|
| 56 | 56 |
} |
| 57 | 57 |
if err := SetupPtmx(rootfs, console, container.Context["mount_label"]); err != nil {
|
| 58 | 58 |
return err |