Skip to content
This repository was archived by the owner on Dec 13, 2018. It is now read-only.

Commit 5fc19e8

Browse files
committed
Rename Fs fields to fs
Signed-off-by: Michael Crosby <[email protected]>
1 parent e48806d commit 5fc19e8

24 files changed

+266
-196
lines changed

Diff for: PRINCIPLES.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ In the design and development of libcontainer we try to follow these principles:
88
* Less code is better.
99
* Fewer components are better. Do you really need to add one more class?
1010
* 50 lines of straightforward, readable code is better than 10 lines of magic that nobody can understand.
11-
* Don't do later what you can do now. "//FIXME: refactor" is not acceptable in new code.
11+
* Don't do later what you can do now. "//TODO: refactor" is not acceptable in new code.
1212
* When hesitating between two options, choose the one that is easier to reverse.
1313
* "No" is temporary; "Yes" is forever. If you're not sure about a new feature, say no. You can change your mind later.
1414
* Containers must be portable to the greatest possible number of machines. Be suspicious of any change which makes machines less interchangeable.

Diff for: cgroups/fs/apply_raw.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ func (m *Manager) Apply(pid int) error {
8383
if err := sys.Set(d); err != nil {
8484
return err
8585
}
86-
// FIXME: Apply should, ideally, be reentrant or be broken up into a separate
86+
// TODO: Apply should, ideally, be reentrant or be broken up into a separate
8787
// create and join phase so that the cgroup hierarchy for a container can be
8888
// created then join consists of writing the process pids to cgroup.procs
8989
p, err := d.path(name)

Diff for: configs/config.go

+7-7
Original file line numberDiff line numberDiff line change
@@ -26,22 +26,22 @@ type Config struct {
2626
// This is required when using read only root filesystems. In these cases, a read/writeable path can be (bind) mounted somewhere inside the root filesystem to act as pivot.
2727
PivotDir string `json:"pivot_dir,omitempty"`
2828

29-
// ReadonlyFs will remount the container's rootfs as readonly where only externally mounted
30-
// bind mounts are writtable
31-
ReadonlyFs bool `json:"readonly_fs,omitempty"`
29+
// Path to a directory containing the container's root filesystem.
30+
Rootfs string `json:"rootfs,omitempty"`
31+
32+
// Readonlyfs will remount the container's rootfs as readonly where only externally mounted
33+
// bind mounts are writtable.
34+
Readonlyfs bool `json:"readonlyfs,omitempty"`
3235

3336
// Mounts specify additional source and destination paths that will be mounted inside the container's
3437
// rootfs and mount namespace if specified
3538
Mounts []*Mount `json:"mounts,omitempty"`
3639

3740
// The device nodes that should be automatically created within the container upon container start. Note, make sure that the node is marked as allowed in the cgroup as well!
38-
DeviceNodes []*Device `json:"device_nodes,omitempty"`
41+
Devices []*Device `json:"devices,omitempty"`
3942

4043
MountLabel string `json:"mount_label,omitempty"`
4144

42-
// Pathname to container's root filesystem
43-
RootFs string `json:"root_fs,omitempty"`
44-
4545
// Hostname optionally sets the container's hostname if provided
4646
Hostname string `json:"hostname,omitempty"`
4747

Diff for: configs/config_test.go

+67-1
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ func TestConfigJsonFormat(t *testing.T) {
114114
}
115115

116116
for _, d := range DefaultSimpleDevices {
117-
if !containsDevice(d, container.DeviceNodes) {
117+
if !containsDevice(d, container.Devices) {
118118
t.Logf("expected device configuration for %s", d.Path)
119119
t.Fail()
120120
}
@@ -163,3 +163,69 @@ func TestRemoveNamespace(t *testing.T) {
163163
t.Fatalf("namespaces should have 0 items but reports %d", len(ns))
164164
}
165165
}
166+
167+
func TestHostUIDNoUSERNS(t *testing.T) {
168+
config := &Config{
169+
Namespaces: Namespaces{},
170+
}
171+
uid, err := config.HostUID()
172+
if err != nil {
173+
t.Fatal(err)
174+
}
175+
if uid != 0 {
176+
t.Fatal("expected uid 0 with no USERNS but received %d", uid)
177+
}
178+
}
179+
180+
func TestHostUIDWithUSERNS(t *testing.T) {
181+
config := &Config{
182+
Namespaces: Namespaces{{Type: NEWUSER}},
183+
UidMappings: []IDMap{
184+
{
185+
ContainerID: 0,
186+
HostID: 1000,
187+
Size: 1,
188+
},
189+
},
190+
}
191+
uid, err := config.HostUID()
192+
if err != nil {
193+
t.Fatal(err)
194+
}
195+
if uid != 1000 {
196+
t.Fatal("expected uid 1000 with no USERNS but received %d", uid)
197+
}
198+
}
199+
200+
func TestHostGIDNoUSERNS(t *testing.T) {
201+
config := &Config{
202+
Namespaces: Namespaces{},
203+
}
204+
uid, err := config.HostGID()
205+
if err != nil {
206+
t.Fatal(err)
207+
}
208+
if uid != 0 {
209+
t.Fatal("expected gid 0 with no USERNS but received %d", uid)
210+
}
211+
}
212+
213+
func TestHostGIDWithUSERNS(t *testing.T) {
214+
config := &Config{
215+
Namespaces: Namespaces{{Type: NEWUSER}},
216+
GidMappings: []IDMap{
217+
{
218+
ContainerID: 0,
219+
HostID: 1000,
220+
Size: 1,
221+
},
222+
},
223+
}
224+
uid, err := config.HostGID()
225+
if err != nil {
226+
t.Fatal(err)
227+
}
228+
if uid != 1000 {
229+
t.Fatal("expected gid 1000 with no USERNS but received %d", uid)
230+
}
231+
}

Diff for: configs/device.go

+17-7
Original file line numberDiff line numberDiff line change
@@ -10,19 +10,29 @@ const (
1010
)
1111

1212
type Device struct {
13+
// Device type, block, char, etc.
1314
Type rune `json:"type,omitempty"`
14-
// It is fine if this is an empty string in the case that you are using Wildcards
15+
16+
// Path to the device.
1517
Path string `json:"path,omitempty"`
16-
// Use the wildcard constant for wildcards.
18+
19+
// Major is the device's major number.
1720
Major int64 `json:"major,omitempty"`
18-
// Use the wildcard constant for wildcards.
21+
22+
// Minor is the device's minor number.
1923
Minor int64 `json:"minor,omitempty"`
20-
// Typically just "rwm"
24+
25+
// Cgroup permissions format, rwm.
2126
Permissions string `json:"permissions,omitempty"`
22-
// The permission bits of the file's mode
27+
28+
// FileMode permission bits for the device.
2329
FileMode os.FileMode `json:"file_mode,omitempty"`
24-
Uid uint32 `json:"uid,omitempty"`
25-
Gid uint32 `json:"gid,omitempty"`
30+
31+
// Uid of the device.
32+
Uid uint32 `json:"uid,omitempty"`
33+
34+
// Gid of the device.
35+
Gid uint32 `json:"gid,omitempty"`
2636
}
2737

2838
func (d *Device) CgroupString() string {

Diff for: configs/mount.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ func (m *Mount) bindMount(rootfs, mountLabel string) error {
5252
return err
5353
}
5454

55-
// FIXME: (crosbymichael) This does not belong here and should be done a layer above
55+
// TODO: (crosbymichael) This does not belong here and should be done a layer above
5656
dest, err = symlink.FollowSymlinkInScope(dest, rootfs)
5757
if err != nil {
5858
return err
@@ -94,7 +94,7 @@ func (m *Mount) tmpfsMount(rootfs, mountLabel string) error {
9494
dest = filepath.Join(rootfs, m.Destination)
9595
)
9696

97-
// FIXME: (crosbymichael) This does not belong here and should be done a layer above
97+
// TODO: (crosbymichael) This does not belong here and should be done a layer above
9898
if dest, err = symlink.FollowSymlinkInScope(dest, rootfs); err != nil {
9999
return err
100100
}

Diff for: configs/network.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,12 @@ type Network struct {
2020
// Address contains the IPv4 and mask to set on the network interface
2121
Address string `json:"address,omitempty"`
2222

23-
// IPv6Address contains the IPv6 and mask to set on the network interface
24-
IPv6Address string `json:"ipv6_address,omitempty"`
25-
2623
// Gateway sets the gateway address that is used as the default for the interface
2724
Gateway string `json:"gateway,omitempty"`
2825

26+
// IPv6Address contains the IPv6 and mask to set on the network interface
27+
IPv6Address string `json:"ipv6_address,omitempty"`
28+
2929
// IPv6Gateway sets the ipv6 gateway address that is used as the default for the interface
3030
IPv6Gateway string `json:"ipv6_gateway,omitempty"`
3131

Diff for: devices/devices.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -60,10 +60,10 @@ func DeviceFromPath(path, permissions string) (*configs.Device, error) {
6060
}
6161

6262
func HostDevices() ([]*configs.Device, error) {
63-
return getDeviceNodes("/dev")
63+
return getDevices("/dev")
6464
}
6565

66-
func getDeviceNodes(path string) ([]*configs.Device, error) {
66+
func getDevices(path string) ([]*configs.Device, error) {
6767
files, err := ioutilReadDir(path)
6868
if err != nil {
6969
return nil, err
@@ -76,7 +76,7 @@ func getDeviceNodes(path string) ([]*configs.Device, error) {
7676
case "pts", "shm", "fd", "mqueue":
7777
continue
7878
default:
79-
sub, err := getDeviceNodes(filepath.Join(path, f.Name()))
79+
sub, err := getDevices(filepath.Join(path, f.Name()))
8080
if err != nil {
8181
return nil, err
8282
}

Diff for: integration/exec_test.go

+8-8
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ func testExecPS(t *testing.T, userns bool) {
2727
return
2828
}
2929

30-
rootfs, err := newRootFs()
30+
rootfs, err := newRootfs()
3131
if err != nil {
3232
t.Fatal(err)
3333
}
@@ -65,7 +65,7 @@ func TestIPCPrivate(t *testing.T) {
6565
return
6666
}
6767

68-
rootfs, err := newRootFs()
68+
rootfs, err := newRootfs()
6969
if err != nil {
7070
t.Fatal(err)
7171
}
@@ -96,7 +96,7 @@ func TestIPCHost(t *testing.T) {
9696
return
9797
}
9898

99-
rootfs, err := newRootFs()
99+
rootfs, err := newRootfs()
100100
if err != nil {
101101
t.Fatal(err)
102102
}
@@ -128,7 +128,7 @@ func TestIPCJoinPath(t *testing.T) {
128128
return
129129
}
130130

131-
rootfs, err := newRootFs()
131+
rootfs, err := newRootfs()
132132
if err != nil {
133133
t.Fatal(err)
134134
}
@@ -161,7 +161,7 @@ func TestIPCBadPath(t *testing.T) {
161161
return
162162
}
163163

164-
rootfs, err := newRootFs()
164+
rootfs, err := newRootfs()
165165
if err != nil {
166166
t.Fatal(err)
167167
}
@@ -181,7 +181,7 @@ func TestRlimit(t *testing.T) {
181181
return
182182
}
183183

184-
rootfs, err := newRootFs()
184+
rootfs, err := newRootfs()
185185
if err != nil {
186186
t.Fatal(err)
187187
}
@@ -232,7 +232,7 @@ func TestEnter(t *testing.T) {
232232
}
233233
defer os.RemoveAll(root)
234234

235-
rootfs, err := newRootFs()
235+
rootfs, err := newRootfs()
236236
if err != nil {
237237
t.Fatal(err)
238238
}
@@ -335,7 +335,7 @@ func TestFreeze(t *testing.T) {
335335
}
336336
defer os.RemoveAll(root)
337337

338-
rootfs, err := newRootFs()
338+
rootfs, err := newRootfs()
339339
if err != nil {
340340
t.Fatal(err)
341341
}

Diff for: integration/template_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import (
1212
// and the default setup for devices
1313
func newTemplateConfig(rootfs string) *configs.Config {
1414
return &configs.Config{
15-
RootFs: rootfs,
15+
Rootfs: rootfs,
1616
Capabilities: []string{
1717
"CHOWN",
1818
"DAC_OVERRIDE",
@@ -43,7 +43,7 @@ func newTemplateConfig(rootfs string) *configs.Config {
4343
AllowedDevices: configs.DefaultAllowedDevices,
4444
},
4545

46-
DeviceNodes: configs.DefaultAutoCreatedDevices,
46+
Devices: configs.DefaultAutoCreatedDevices,
4747
Hostname: "integration",
4848
Env: []string{
4949
"HOME=/root",

Diff for: integration/utils_test.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ type stdBuffers struct {
2929
}
3030

3131
func writeConfig(config *configs.Config) error {
32-
f, err := os.OpenFile(filepath.Join(config.RootFs, "container.json"), os.O_CREATE|os.O_RDWR|os.O_TRUNC, 0700)
32+
f, err := os.OpenFile(filepath.Join(config.Rootfs, "container.json"), os.O_CREATE|os.O_RDWR|os.O_TRUNC, 0700)
3333
if err != nil {
3434
return err
3535
}
@@ -51,8 +51,8 @@ func loadConfig() (*configs.Config, error) {
5151
return container, nil
5252
}
5353

54-
// newRootFs creates a new tmp directory and copies the busybox root filesystem
55-
func newRootFs() (string, error) {
54+
// newRootfs creates a new tmp directory and copies the busybox root filesystem
55+
func newRootfs() (string, error) {
5656
dir, err := ioutil.TempDir("", "")
5757
if err != nil {
5858
return "", err

0 commit comments

Comments
 (0)