Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix process/config properties merging #4585

Open
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

kolyshkin
Copy link
Contributor

@kolyshkin kolyshkin commented Jan 8, 2025

runc exec (as well as libcontainer's container.Run/container.Start) has an interesting feature of deriving various process' properties from the runtime spec for container init (the Process entry in config.json aka spec).

This is mostly implemented via merging Config and Process properties into initConfig, which happens in libcontainer/container_linux.go, func newInitConfig. Note how initConfig fields are taken from c.config first (they are there from spec's Process) and then are overwritten by properties of a particular process being run. These initConfig fields are then used to set up various process attributes.

Alas, this functionality (of merging process and config properties) is

  • spread over the libcontainer code;
  • not well documented;
  • have a few bugs.

This PR is an attempt to improve the situation,

  • documenting the related data structures (first commit);
  • simplifying, unifying and documenting some of the merging code (intermediate commits);
  • fixing two actual bugs, related to process' IOPriority and Scheduler properties (last two commits).

@kolyshkin kolyshkin force-pushed the per-process-properties branch from a12d2da to ed015c7 Compare January 8, 2025 20:39
@kolyshkin kolyshkin force-pushed the per-process-properties branch 5 times, most recently from fa41079 to b39f21b Compare January 16, 2025 20:24
This is one of the dark corners of runc / libcontainer, so let's shed
some light on it.

initConfig is a structure which is filled in [mostly] by newInitConfig,
and one of its hidden aspects is it contains a process config which is
the result of merge between the container and the process configs.

Let's document how all this happens, where the fields are coming from,
which one has a preference, and how it all works.

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
They are passed in initConfig twice, so it does not make sense.

NB: the alternative to that would be to remove Config field from
initConfig, but it results in a much bigger patch and more maintenance
down the road.

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
In runtime-spec, capabilities property is optional, but
libcontainer/capabilities panics when New(nil) is called.

Because of this, there's a kludge in finalizeNamespace to ensure
capabilities.New is not called with nil argument, and there's a
TestProcessEmptyCaps to ensure runc won't panic.

Let's fix this at the source, allowing libct/cap to work with nil
capabilities.

(The caller is fixed by the next commit.)

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
For all other properties that are available in both Config and Process,
the merging is performed by newInitConfig.

Let's do the same for Capabilities for the sake of code uniformity.

Also, thanks to the previous commit, we no longer have to make sure we
do not call capabilities.New(nil).

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
Commit bfbd030 added IOPriority field into both Config and Process,
but forgot to add a mechanism to actually use Process.IOPriority.
As a result, runc exec does not set Process.IOPriority ever.

Fix it, and a test case (which fails before the fix).

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
Commit 770728e added Scheduler field into both Config and Process,
but forgot to add a mechanism to actually use Process.Scheduler.
As a result, runc exec does not set Process.Scheduler ever.

Fix it, and a test case (which fails before the fix).

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
@kolyshkin kolyshkin force-pushed the per-process-properties branch from b39f21b to 8bab6ac Compare January 16, 2025 22:39
@kolyshkin kolyshkin changed the title Fix process properties vs config properties Fix process/config properties merging Jan 16, 2025
@kolyshkin
Copy link
Contributor Author

ci / cross-i386 failure is unrelated and is being fixed by #4595

@kolyshkin kolyshkin marked this pull request as ready for review January 16, 2025 22:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant