mirror of
https://github.com/containers/podman.git
synced 2025-10-18 19:53:58 +08:00
Implement podman run option --cgroup-parent
Example: sudo /usr/local/bin/podman run --cgroup-parent=/zzz fedora cat /proc/self/cgroup Signed-off-by: Jhon Honce <jhonce@redhat.com> Closes: #370 Approved by: rhatdan
This commit is contained in:
@ -72,12 +72,17 @@ func runCmd(c *cli.Context) error {
|
|||||||
options = append(options, libpod.WithUser(createConfig.User))
|
options = append(options, libpod.WithUser(createConfig.User))
|
||||||
options = append(options, libpod.WithShmDir(createConfig.ShmDir))
|
options = append(options, libpod.WithShmDir(createConfig.ShmDir))
|
||||||
options = append(options, libpod.WithShmSize(createConfig.Resources.ShmSize))
|
options = append(options, libpod.WithShmSize(createConfig.Resources.ShmSize))
|
||||||
|
options = append(options, libpod.WithCgroupParent(createConfig.CgroupParent))
|
||||||
ctr, err := runtime.NewContainer(runtimeSpec, options...)
|
ctr, err := runtime.NewContainer(runtimeSpec, options...)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
logrus.Debug("new container created ", ctr.ID())
|
logrus.Debug("new container created ", ctr.ID())
|
||||||
|
|
||||||
|
p, _ := ctr.CGroupPath()("")
|
||||||
|
logrus.Debugf("createConfig.CgroupParent %v for %v", p, ctr.ID())
|
||||||
|
|
||||||
if err := ctr.Init(); err != nil {
|
if err := ctr.Init(); err != nil {
|
||||||
// This means the command did not exist
|
// This means the command did not exist
|
||||||
exitCode = 127
|
exitCode = 127
|
||||||
|
@ -38,7 +38,7 @@ const (
|
|||||||
)
|
)
|
||||||
|
|
||||||
// CgroupParent is the default prefix to a cgroup path in libpod
|
// CgroupParent is the default prefix to a cgroup path in libpod
|
||||||
var CgroupParent = "/libpod_parent"
|
var DefaultCgroupParent = "/libpod_parent"
|
||||||
|
|
||||||
// LinuxNS represents a Linux namespace
|
// LinuxNS represents a Linux namespace
|
||||||
type LinuxNS int
|
type LinuxNS int
|
||||||
|
@ -146,7 +146,7 @@ func newContainer(rspec *spec.Spec, lockDir string) (*Container, error) {
|
|||||||
ctr.config.CreatedTime = time.Now()
|
ctr.config.CreatedTime = time.Now()
|
||||||
|
|
||||||
ctr.config.ShmSize = DefaultShmSize
|
ctr.config.ShmSize = DefaultShmSize
|
||||||
ctr.config.CgroupParent = CgroupParent
|
ctr.config.CgroupParent = DefaultCgroupParent
|
||||||
|
|
||||||
// Path our lock file will reside at
|
// Path our lock file will reside at
|
||||||
lockPath := filepath.Join(lockDir, ctr.config.ID)
|
lockPath := filepath.Join(lockDir, ctr.config.ID)
|
||||||
|
@ -656,6 +656,7 @@ func WithLogPath(path string) CtrCreateOption {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// WithCgroupParent sets the Cgroup Parent of the new container
|
// WithCgroupParent sets the Cgroup Parent of the new container
|
||||||
|
// Default used if not overridden on command line
|
||||||
func WithCgroupParent(parent string) CtrCreateOption {
|
func WithCgroupParent(parent string) CtrCreateOption {
|
||||||
return func(ctr *Container) error {
|
return func(ctr *Container) error {
|
||||||
if ctr.valid {
|
if ctr.valid {
|
||||||
@ -663,7 +664,7 @@ func WithCgroupParent(parent string) CtrCreateOption {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if parent == "" {
|
if parent == "" {
|
||||||
return errors.Wrapf(ErrInvalidArg, "cgroup parent cannot be empty")
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
ctr.config.CgroupParent = parent
|
ctr.config.CgroupParent = parent
|
||||||
|
Reference in New Issue
Block a user