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

Enter cgroups as part of NsEnter #143

Merged
merged 6 commits into from
Aug 14, 2014
Merged

Conversation

vishh
Copy link
Contributor

@vishh vishh commented Aug 5, 2014

Fixes #145

@vishh
Copy link
Contributor Author

vishh commented Aug 5, 2014

Ping @crosbymichael @vmarmol

"github.com/docker/libcontainer/label"
"github.com/docker/libcontainer/system"
)

// ExecIn uses an existing pid and joins the pid's namespaces with the new command.
func ExecIn(container *libcontainer.Config, state *libcontainer.State, args []string) error {
// Enter cgroups.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Im not sure this is correct. Shouldn't our parent place the child's PID into the cgroups?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since we're exec()ing I think its fine. We'd be having the waitpid() parent waiting for the child in the namespace also in the cgroups which I think is fine, the overhead is to that container anyways.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good point @crosbymichael. In the case of ExecIn() this is fine. But in the case of 'docker exec', this is not desirable since we will end up moving docker into user container.
May be I could made docker fork+exec dockerinit with a 'cgenter option', which will then enter the cgroups and then exec itself as 'nsenter'.

@vishh
Copy link
Contributor Author

vishh commented Aug 6, 2014

PTAL @vmarmol @crosbymichael

@@ -86,7 +86,7 @@ void nsenter()
}
int found_nsenter = 0;
for (c = 0; c < argc; ++c) {
if (strcmp(argv[c], kNsEnter) == 0) {
if (strncmp(argv[c], kNsEnter, strlen(kNsEnter)) == 0) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think these are equivalent since strcmp will do the equivalent of strlen() with kNsEnter

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

@vmarmol
Copy link
Contributor

vmarmol commented Aug 6, 2014

Just two nits, else looks good :)

@vmarmol
Copy link
Contributor

vmarmol commented Aug 6, 2014

LGTM thanks for the fix @vishh!

@vishh
Copy link
Contributor Author

vishh commented Aug 8, 2014

Ping @crosbymichael

@crosbymichael
Copy link
Contributor

This does not work on systemd The paths are incorrect

@crosbymichael
Copy link
Contributor

Maybe for systemd and the fs implementation we need to store the paths in the container's state so that is is trivial to add more processes to the existing groups and ensure that the paths are properly cleaned up after, even if the container's parent process is SIGKILLed we can look at the state on disk and cleanup the cgroups.

@vishh
Copy link
Contributor Author

vishh commented Aug 13, 2014

@crosbymichael I updated the patch as per your suggestion. PTAL

@@ -18,6 +18,9 @@ type State struct {

// Network runtime state.
NetworkState network.NetworkState `json:"network_state,omitempty"`

// Path to all the cgroup dirs.
CgroupPaths []string `json:"cgroup_paths,omitempty"`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do you think about making this a map with the subsystem and then the path. So it would look like:

{
    "cgroup_paths": {
         "devices": "/sys/fs/cgroup/devices/dockcer...."
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That sounds useful.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok, lets do that

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

Docker-DCO-1.1-Signed-off-by: Vishnu Kannan <vishnuk@google.com> (github: vishh)
Docker-DCO-1.1-Signed-off-by: Vishnu Kannan <vishnuk@google.com> (github: vishh)
…ering cgroups and will be useful for

cleanups too in the future.
Docker-DCO-1.1-Signed-off-by: Vishnu Kannan <vishnuk@google.com> (github: vishh)
… path as value.

Docker-DCO-1.1-Signed-off-by: Vishnu Kannan <vishnuk@google.com> (github: vishh)
@crosbymichael
Copy link
Contributor

Looking good so far:

{
    "cgroup_paths": {
        "blkio": "/sys/fs/cgroup/blkio/system.slice/docker-docker-koye.scope",
        "cpu": "/sys/fs/cgroup/cpu,cpuacct/system.slice/docker-docker-koye.scope",
        "cpuacct": "/sys/fs/cgroup/cpu,cpuacct/system.slice/docker-docker-koye.scope",
        "cpuset": "/sys/fs/cgroup/cpuset/system.slice/docker-docker-koye.scope",
        "devices": "/sys/fs/cgroup/devices/system.slice/docker-docker-koye.scope",
        "freezer": "/sys/fs/cgroup/freezer/system.slice/docker-docker-koye.scope",
        "memory": "/sys/fs/cgroup/memory/system.slice/docker-docker-koye.scope",
        "perf_event": "/sys/fs/cgroup/perf_event/system.slice/docker-docker-koye.scope"
    },
    "init_pid": 28718,
    "init_start_time": "646736",
    "network_state": {}
}

Michael Crosby and others added 2 commits August 13, 2014 18:16
The current paths for the different systemd cgroup subsystems that
systemd manages and that we have to manage are very inconsistent.  This
patch cleans up those differences and allows consistent paths to be
used.

Signed-off-by: Michael Crosby <michael@docker.com>
@crosbymichael
Copy link
Contributor

LGTM

ping @vmarmol @mrunalp @rjnagal

@vmarmol
Copy link
Contributor

vmarmol commented Aug 14, 2014

LGTM, merging.

vmarmol added a commit that referenced this pull request Aug 14, 2014
Enter cgroups as part of NsEnter
@vmarmol vmarmol merged commit 29363e2 into docker-archive:master Aug 14, 2014
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants