Add --no-pivot option for containers on ramdisk
This adds a `--no-pivot` cli flag to runc so that a container's rootfs can be located ontop of ramdisk/tmpfs and not fail because you cannot pivot root. This should be a cli flag and not part of the spec because this is a detail of the host/runtime environment and not an attribute of a container. Signed-off-by: Michael Crosby <crosbymichael@gmail.com>
This commit is contained in:
parent
8fa5343b00
commit
12bd4cffd0
|
@ -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 {
|
||||
|
@ -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,
|
||||
},
|
||||
|
@ -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
|
||||
}
|
||||
|
|
11
restore.go
11
restore.go
|
@ -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")
|
||||
|
@ -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)
|
||||
}
|
||||
|
|
4
start.go
4
start.go
|
@ -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")
|
||||
|
|
7
utils.go
7
utils.go
|
@ -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
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue