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 6 times, most recently 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
@kolyshkin kolyshkin added this to the 1.3.0 milestone Jan 18, 2025
Copy link
Member

@rata rata left a comment

Choose a reason for hiding this comment

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

@kolyshkin thanks for tackling this, very nice cleanups!

Do we want to backport this to 1.2?

Left some minor questions, this mostly LGTM.

tests/integration/scheduler.bats Outdated Show resolved Hide resolved
tests/integration/scheduler.bats Show resolved Hide resolved
@kolyshkin
Copy link
Contributor Author

Do we want to backport this to 1.2?

My view here is, unless someone will report this, let's view these as improvements rather than bug fixes -- thus no backport.

@kolyshkin
Copy link
Contributor Author

Do we want to backport this to 1.2?

My view here is, unless someone will report this, let's view these as improvements rather than bug fixes -- thus no backport.

Another reason is, for backporting I'd do it differently (minimal set of fixes rather than what I did here, helping the future me to figure out this mess)

@kolyshkin kolyshkin force-pushed the per-process-properties branch from 8bab6ac to bad011e Compare January 30, 2025 04:57
@kolyshkin kolyshkin requested a review from rata January 31, 2025 05:27
Copy link
Member

@rata rata left a comment

Choose a reason for hiding this comment

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

LGTM, thanks!

@kolyshkin kolyshkin modified the milestones: 1.3.0, 1.3.0-rc.1 Feb 7, 2025
@kolyshkin
Copy link
Contributor Author

kolyshkin commented Feb 7, 2025

Oh my, this needs a manual rebase since #3999 is merged.

Update: rebased

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 <[email protected]>
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 <[email protected]>
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 <[email protected]>
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 <[email protected]>
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 <[email protected]>
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 <[email protected]>
@kolyshkin kolyshkin force-pushed the per-process-properties branch from bad011e to 7e26176 Compare February 7, 2025 03:25
Copy link
Member

@rata rata left a comment

Choose a reason for hiding this comment

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

Still LGTM :)

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.

2 participants