Skip to content

Commit

Permalink
Merge pull request #710 from crosbymichael/no-pivot
Browse files Browse the repository at this point in the history
Add --no-pivot option for containers on ramdisk
  • Loading branch information
LK4D4 committed Mar 30, 2016
2 parents 0a5293f + 12bd4cf commit 2441732
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 7 deletions.
19 changes: 14 additions & 5 deletions libcontainer/specconv/spec_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,9 +158,16 @@ var allowedDevices = []*configs.Device{
},
}

type CreateOpts struct {
CgroupName string
UseSystemdCgroup bool
NoPivotRoot bool
Spec *specs.Spec
}

// CreateLibcontainerConfig creates a new libcontainer configuration from a
// given specification and a cgroup name
func CreateLibcontainerConfig(cgroupName string, useSystemdCgroup bool, spec *specs.Spec) (*configs.Config, error) {
func CreateLibcontainerConfig(opts *CreateOpts) (*configs.Config, error) {
// runc's cwd will always be the bundle path
rcwd, err := os.Getwd()
if err != nil {
Expand All @@ -170,14 +177,16 @@ func CreateLibcontainerConfig(cgroupName string, useSystemdCgroup bool, spec *sp
if err != nil {
return nil, err
}
spec := opts.Spec
rootfsPath := spec.Root.Path
if !filepath.IsAbs(rootfsPath) {
rootfsPath = filepath.Join(cwd, rootfsPath)
}
config := &configs.Config{
Rootfs: rootfsPath,
Readonlyfs: spec.Root.Readonly,
Hostname: spec.Hostname,
Rootfs: rootfsPath,
NoPivotRoot: opts.NoPivotRoot,
Readonlyfs: spec.Root.Readonly,
Hostname: spec.Hostname,
Labels: []string{
"bundle=" + cwd,
},
Expand Down Expand Up @@ -211,7 +220,7 @@ func CreateLibcontainerConfig(cgroupName string, useSystemdCgroup bool, spec *sp
if err := setupUserNamespace(spec, config); err != nil {
return nil, err
}
c, err := createCgroupConfig(cgroupName, useSystemdCgroup, spec)
c, err := createCgroupConfig(opts.CgroupName, opts.UseSystemdCgroup, spec)
if err != nil {
return nil, err
}
Expand Down
11 changes: 10 additions & 1 deletion restore.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,10 @@ using the runc checkpoint command.`,
Name: "no-subreaper",
Usage: "disable the use of the subreaper used to reap reparented processes",
},
cli.BoolFlag{
Name: "no-pivot",
Usage: "do not use pivot root to jail process inside rootfs. This should be used whenever the rootfs is on top of a ramdisk",
},
},
Action: func(context *cli.Context) {
imagePath := context.String("image-path")
Expand All @@ -93,7 +97,12 @@ using the runc checkpoint command.`,
if err != nil {
fatal(err)
}
config, err := specconv.CreateLibcontainerConfig(id, context.GlobalBool("systemd-cgroup"), spec)
config, err := specconv.CreateLibcontainerConfig(&specconv.CreateOpts{
CgroupName: id,
UseSystemdCgroup: context.GlobalBool("systemd-cgroup"),
NoPivotRoot: context.Bool("no-pivot"),
Spec: spec,
})
if err != nil {
fatal(err)
}
Expand Down
4 changes: 4 additions & 0 deletions start.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,10 @@ command(s) that get executed on start, edit the args parameter of the spec. See
Name: "no-subreaper",
Usage: "disable the use of the subreaper used to reap reparented processes",
},
cli.BoolFlag{
Name: "no-pivot",
Usage: "do not use pivot root to jail process inside rootfs. This should be used whenever the rootfs is on top of a ramdisk",
},
},
Action: func(context *cli.Context) {
bundle := context.String("bundle")
Expand Down
7 changes: 6 additions & 1 deletion utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,12 @@ func createPidFile(path string, process *libcontainer.Process) error {
}

func createContainer(context *cli.Context, id string, spec *specs.Spec) (libcontainer.Container, error) {
config, err := specconv.CreateLibcontainerConfig(id, context.GlobalBool("systemd-cgroup"), spec)
config, err := specconv.CreateLibcontainerConfig(&specconv.CreateOpts{
CgroupName: id,
UseSystemdCgroup: context.GlobalBool("systemd-cgroup"),
NoPivotRoot: context.Bool("no-pivot"),
Spec: spec,
})
if err != nil {
return nil, err
}
Expand Down

0 comments on commit 2441732

Please sign in to comment.