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

Improves logging for the chroot2 utility and introduces EVE_CONTAINER_NO_POWEROFF mode #3628

Merged
merged 6 commits into from
Nov 28, 2023

Conversation

rouming
Copy link
Contributor

@rouming rouming commented Nov 25, 2023

PR improves logging for the chroot2 utility by printing possible parameters. There is a customer container, which provides invalid WORKDIR in its environment, so that chdir() fails. EVE considers this as fatal (which is ok), but does not print what exact directory does not exist, which is nasty. This PR improves that by err() libc call.

PR propagates an error from to a chroot2 caller and init-initrd scripts prints the exit value. Valid expectations are that init (process which is executed by the following execvp() call) never exits, if it does - return an exit status. It is possible to get 0 (success) of a chroot2 execution status iif a spawned child process returned 0. If a child process was terminated by a signal or coredumped (same as terminated by a SIGSEGV), the chroot2 returns -1 (255).

The last few commits introduce EVE_CONTAINER_NO_POWEROFF flag. If container's init script misbehaves and exits, it becomes very difficult to debug such a container, because VM shuts down immediately by explicit poweroff call. The EVE_CONTAINER_NO_POWEROFF can be set in the application environment variables on the controller side and instead of calling /sbin/poweroff, init-initrd sleeps infinitely, waiting for attention from a developer.

CC: @jsfakian

Copy link

codecov bot commented Nov 25, 2023

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (9589a8e) 19.37% compared to head (4c9ca80) 19.36%.
Report is 2 commits behind head on master.

❗ Current head 4c9ca80 differs from pull request most recent head 9a7c625. Consider uploading reports for the commit 9a7c625 to get more accurate results

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #3628      +/-   ##
==========================================
- Coverage   19.37%   19.36%   -0.01%     
==========================================
  Files         232      232              
  Lines       50551    50551              
==========================================
- Hits         9796     9791       -5     
- Misses      40045    40050       +5     
  Partials      710      710              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

pkg/xen-tools/initrd/chroot2.c Outdated Show resolved Hide resolved
pkg/xen-tools/initrd/chroot2.c Show resolved Hide resolved
@rouming rouming force-pushed the chroot2-more-logging branch from dd60173 to 3b128fa Compare November 27, 2023 10:56
@github-actions github-actions bot requested a review from rene November 27, 2023 10:57
Patch improves logging for fatal error path printing all
arguments out.

Signed-off-by: Roman Penyaev <r.peniaev@gmail.com>
@rouming rouming force-pushed the chroot2-more-logging branch from 3b128fa to 4897866 Compare November 27, 2023 11:03
@rouming rouming changed the title Improves logging for the chroot2 utility Improves logging for the chroot2 utility and introduces EVE_CONTAINER_NO_POWEROFF mode Nov 27, 2023
@rouming rouming force-pushed the chroot2-more-logging branch from 4897866 to 45761c9 Compare November 27, 2023 11:47
@rouming
Copy link
Contributor Author

rouming commented Nov 27, 2023

Difference to previous version:

  • Add EVE_CONTAINER_NO_POWEROFF for easy debugging

@rouming rouming force-pushed the chroot2-more-logging branch from 45761c9 to 4ff689a Compare November 27, 2023 12:27
Copy link
Contributor

@rene rene left a comment

Choose a reason for hiding this comment

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

LGTM

@shjala
Copy link
Member

shjala commented Nov 27, 2023

LGTM.

return 0;
child_pid = wait(&wstatus);
if (child_pid < 0)
err(-1, "waitpid() failed:");
Copy link
Member

Choose a reason for hiding this comment

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

The error message is outdated.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Indeed, thanks.

Copy link
Member

Choose a reason for hiding this comment

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

And do you intentionally leave the semicolon at the end? It's not critical at all, but just in case...

@OhmSpectator
Copy link
Member

Except for one typo, it looks fine to me.
I would only suggest adding info on how and where to set the new variable: EVE_CONTAINER_NO_POWEROFF. It is not obvious at all how the init-initrd script is started and how to parameterise it.

@rouming
Copy link
Contributor Author

rouming commented Nov 27, 2023

Except for one typo, it looks fine to me. I would only suggest adding info on how and where to set the new variable: EVE_CONTAINER_NO_POWEROFF. It is not obvious at all how the init-initrd script is started and how to parameterise it.

The last commit covers that in the DEBUGGING doc

Wait for a child exit status and returns it to a caller of a chroor2
caller.

Valid expectations are that init (process which is executed by the
following execvp() call) never exits, if it does - return an exit
status. It is possible to get 0 (success) of a chroot2 execution
status iif a spawned child process returned 0. If a child process
was terminated by a signal or coredumped (same as terminated by
a SIGSEGV), the chroot2 returns -1 (255).

Also patch replaces waitpid() on wait() for simplicity, since
chroot2 starts only one child there is no reason to specify
what child do we wait, wait() call waits for any child and is
similar in this context.

Signed-off-by: Roman Penyaev <r.peniaev@gmail.com>
…ation

Output all warnings and treat them as errors. This make chroot2.c and
hacf.c compilation more strict.

Signed-off-by: Roman Penyaev <r.peniaev@gmail.com>
Add an explicit echo which warns about power off of the whole VM.

Signed-off-by: Roman Penyaev <r.peniaev@gmail.com>
…F is set

If container's init script misbehaves and exits, it becomes very difficult
to debug such a container, because VM shuts down immediately by explicit
poweroff call.

This patch introduces an EVE_CONTAINER_NO_POWEROFF flag, which can be
set in the application environment variables on the controller side
and instead of calling /sbin/poweroff init-initrd sleeps infinitely,
waiting for attention from a developer.

Signed-off-by: Roman Penyaev <r.peniaev@gmail.com>
@OhmSpectator
Copy link
Member

The last commit covers that in the DEBUGGING doc

I saw this change, but it only says

If EVE_CONTAINER_NO_POWEROFF=1 environment variable is set on the controller side.

I'm confused. What exactly does it mean, "is set on the controller side"?

@rouming
Copy link
Contributor Author

rouming commented Nov 27, 2023

The last commit covers that in the DEBUGGING doc

I saw this change, but it only says

If EVE_CONTAINER_NO_POWEROFF=1 environment variable is set on the controller side.

I'm confused. What exactly does it mean, "is set on the controller side"?

This is the "Add Custom Config Template" section of the edge application. Environment comes with the app config.

@OhmSpectator
Copy link
Member

This is the "Add Custom Config Template" section of the edge application. Environment comes with the app config.

Thanks, now I get it!

docs/DEBUGGING.md Outdated Show resolved Hide resolved
…ariable

A few lines in the doc never hurts.

Signed-off-by: Roman Penyaev <r.peniaev@gmail.com>
Copy link
Contributor

@eriknordmark eriknordmark left a comment

Choose a reason for hiding this comment

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

LGTM

@eriknordmark eriknordmark merged commit eccdcb6 into lf-edge:master Nov 28, 2023
32 of 41 checks passed
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.

5 participants