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

switch-root: use MS_REC for /run, unless we are soft-rebooting #28497

Merged
merged 2 commits into from
Jul 24, 2023

Conversation

bluca
Copy link
Member

@bluca bluca commented Jul 22, 2023

There are applications that rely on mounts under /run surviving the
switch from initrd to rootfs, so use MS_REC unless we are soft
rebooting.

FIxes #28452

src/shared/switch-root.c Outdated Show resolved Hide resolved
src/core/main.c Outdated
@@ -1884,7 +1884,8 @@ static int do_reexecute(
if (switch_root_dir) {
r = switch_root(/* new_root= */ switch_root_dir,
/* old_root_after= */ NULL,
/* flags= */ objective == MANAGER_SWITCH_ROOT ? SWITCH_ROOT_DESTROY_OLD_ROOT : 0);
/* flags= */ (objective == MANAGER_SWITCH_ROOT ? SWITCH_ROOT_DESTROY_OLD_ROOT : 0) |
(objective == MANAGER_SOFT_REBOOT ? SWITCH_ROOT_NON_RECURSIVE_RUN : 0));
Copy link
Member

@yuwata yuwata Jul 23, 2023

Choose a reason for hiding this comment

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

We usually name things in positive, So, I'd like the following.

(objective == MANAGER_SWITCH_ROOT ? SWITCH_ROOT_DESTROY_OLD_ROOT | SWITCH_ROOT_RECURSIVE_RUN : 0)

Copy link
Member Author

Choose a reason for hiding this comment

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

that requires changing more places, so I'll leave it as-is

Copy link
Member

Choose a reason for hiding this comment

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

that requires changing more places, so I'll leave it as-is

More places? The enum is introduced by the commit. I do not think that's so many. Only three places in your patch.

Copy link
Member Author

Choose a reason for hiding this comment

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

switch_root() is used elsewhere too

Copy link
Member

Choose a reason for hiding this comment

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

I checked now, and it's used in exactly two places ;) So I think it'd be nicer to rework the flag to be positive. The definition of run_mount_flags below becomes much nicer with a positive option.

src/shared/switch-root.c Outdated Show resolved Hide resolved
@YHNdnzj YHNdnzj added good-to-merge/waiting-for-ci 👍 PR is good to merge, but CI hasn't passed at time of review. Please merge if you see CI has passed and removed please-review PR is ready for (re-)review by a maintainer labels Jul 23, 2023
@yuwata yuwata removed the good-to-merge/waiting-for-ci 👍 PR is good to merge, but CI hasn't passed at time of review. Please merge if you see CI has passed label Jul 23, 2023
@bluca bluca added good-to-merge/waiting-for-ci 👍 PR is good to merge, but CI hasn't passed at time of review. Please merge if you see CI has passed and removed good-to-merge/with-minor-suggestions labels Jul 23, 2023
Copy link
Member

@keszybz keszybz left a comment

Choose a reason for hiding this comment

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

This is pretty clear and should fix the issue. My vote in the naming bikeshed is to rename, but it's not terribly important. If you disagree, feel free to set back the flag back.

src/core/main.c Outdated
@@ -1884,7 +1884,8 @@ static int do_reexecute(
if (switch_root_dir) {
r = switch_root(/* new_root= */ switch_root_dir,
/* old_root_after= */ NULL,
/* flags= */ objective == MANAGER_SWITCH_ROOT ? SWITCH_ROOT_DESTROY_OLD_ROOT : 0);
/* flags= */ (objective == MANAGER_SWITCH_ROOT ? SWITCH_ROOT_DESTROY_OLD_ROOT : 0) |
(objective == MANAGER_SOFT_REBOOT ? SWITCH_ROOT_NON_RECURSIVE_RUN : 0));
Copy link
Member

Choose a reason for hiding this comment

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

I checked now, and it's used in exactly two places ;) So I think it'd be nicer to rework the flag to be positive. The definition of run_mount_flags below becomes much nicer with a positive option.

src/shared/switch-root.c Outdated Show resolved Hide resolved
@keszybz keszybz added good-to-merge/with-minor-suggestions and removed good-to-merge/waiting-for-ci 👍 PR is good to merge, but CI hasn't passed at time of review. Please merge if you see CI has passed labels Jul 24, 2023
bluca and others added 2 commits July 24, 2023 10:39
There are applications that rely on mounts under /run surviving the
switch from initrd to rootfs, so use MS_REC unless we are soft
rebooting.

Follow-up for 7c764d4

Fixes systemd#28452
Since 7c764d4 we bind mount certain directories during switch root
instead of moving the mount directly, and for /run we do this without
MS_REC. This, unfortunately, leaves all mounts under /run behind
in the old root, which breaks certain use cases.

See: systemd#28452
@bluca
Copy link
Member Author

bluca commented Jul 24, 2023

This is pretty clear and should fix the issue. My vote in the naming bikeshed is to rename, but it's not terribly important. If you disagree, feel free to set back the flag back.

I prefer to have a flag that is used when the non-default behaviour is needed - I have renamed it to SWITCH_ROOT_SKIP_RECURSIVE_RUN to make it clearer and more 'positive' - we got plenty of 'skip' flags around

@bluca bluca added good-to-merge/waiting-for-ci 👍 PR is good to merge, but CI hasn't passed at time of review. Please merge if you see CI has passed and removed util-lib good-to-merge/with-minor-suggestions labels Jul 24, 2023
@yuwata
Copy link
Member

yuwata commented Jul 24, 2023

This is pretty clear and should fix the issue. My vote in the naming bikeshed is to rename, but it's not terribly important. If you disagree, feel free to set back the flag back.

I prefer to have a flag that is used when the non-default behaviour is needed - I have renamed it to SWITCH_ROOT_SKIP_RECURSIVE_RUN to make it clearer and more 'positive' - we got plenty of 'skip' flags around

Sounds good to me.

@bluca bluca merged commit 2bfe726 into systemd:main Jul 24, 2023
41 of 48 checks passed
@bluca bluca deleted the run branch July 24, 2023 10:20
@github-actions github-actions bot removed the good-to-merge/waiting-for-ci 👍 PR is good to merge, but CI hasn't passed at time of review. Please merge if you see CI has passed label Jul 24, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

Successfully merging this pull request may close these issues.

systemd forgets mounts during transition from initrd
5 participants