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 compatibility with bootc systems #28

Closed
wants to merge 2 commits into from

Conversation

licliu
Copy link
Collaborator

@licliu licliu commented Jul 23, 2024

No description provided.

kdump-lib.sh Outdated Show resolved Hide resolved
@liutgnu
Copy link
Collaborator

liutgnu commented Jul 23, 2024

For the v2, ack

Comment on lines 103 to 117
get_mntpoint_from_target()
{
# --source is applied to ensure non-bind mount is returned
get_mount_info TARGET source "$1" -f
local SOURCE TARGET
findmnt -k --pairs -o SOURCE,TARGET "$1" | while read line; do
eval "$line"
# omit sources that are bind mounts i.e. they contain a [/path/to/subpath].
if [[ ! "$SOURCE" =~ \[ ]]; then
echo $TARGET
break
fi
done
Copy link
Collaborator

Choose a reason for hiding this comment

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

I really like to avoid 'eval' here. Especially as it's not necessary.
For me the following worked

while read _source _target; do
    ...
done < <(findmnt -k -n -o SOURCE,TARGET "$1")

Other than that the series looks fine to me.

Copy link
Contributor

Choose a reason for hiding this comment

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

That would fail if the source or target contained whitespace, which is pretty unlikely of course...but, still.

(OTOH, the real fix is to not write any nontrivial shell script at all...)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Hi @prudo1 , I think we can merge this first since it works well now. And we can make changes later to avoid code conflicts if we touch this code in the future.

@licliu licliu force-pushed the bootc-bind-mount-issue branch 2 times, most recently from d74a97d to 5527112 Compare August 15, 2024 03:55
@licliu
Copy link
Collaborator Author

licliu commented Aug 15, 2024

Hi @prudo1, I changed the code to avoid 'eval'. And shellcheck doesn't like done < <(program) so I still use pipe.

Comment on lines +1044 to +1045
# Disable ostree as we only need the physical root
systemctl -q --root "$initdir" mask ostree-prepare-root.service
Copy link
Contributor

Choose a reason for hiding this comment

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

If you do this, this means that the crash dump file will be written in the "real root" partition (/sysroot) and not in the actual location set in the configuration file.

Copy link
Contributor

Choose a reason for hiding this comment

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

I did test this. I think the reason it works is because the earlier code is resolving through the bind mount to the real sysroot target.

Copy link
Contributor

Choose a reason for hiding this comment

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

👍🏻 Looks good then

Comment on lines 105 to 112
local _source _target
# omit sources that are bind mounts i.e. they contain a [/path/to/subpath].
findmnt -k --pairs -o SOURCE,TARGET "$1" | while read -r line; do
_source="${line#SOURCE=\"}"
_source="${_source%%\" TARGET=*}"

_target="${line#*TARGET=\"}"
_target="${_target%%\"}"

Copy link
Collaborator

Choose a reason for hiding this comment

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

Hi Lichen,
a few nits here.

  1. shellcheck complains about the use of local as it's not POSIX compliant
  2. you can read multiple variables with read, i.e. you can drop line
  3. when you drop --pairs findmnt should omit the SOURCE= and TARGET= prefix as well as the quotation (please double check)

putting it all together this should simplify the code to a single line

findmnt -k -o SOURCE,TARGET "$1" | while read -r _source _target; do

Other than that the series looks fine

Copy link
Collaborator

Choose a reason for hiding this comment

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

Oups, missed the comment from @cgwalters above. He's right, that 3. would break if either _source or _target contains a space. So probably better to keep option --pairs.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Hi @prudo1 ,thanks for reviewing. I removed the local _source _target and use read -r _source _target now.
I keep --pairs becasue in my test, I need to handle cases when _source or _target contains a space.

There's comment here that `--source` somehow avoids bind
mounts, but that appears not to be the case in my
testing. I think we just happened to be lucky before
now with the `--first` picking the value we wanted.

Instead of using `--first` and hoping for the best,
parse the mounts and skip ones which are bind mounts
explicitly.

Signed-off-by: Colin Walters <walters@verbum.org>
Reviewed-by: Lichen Liu <lichliu@redhat.com>
In some images such as the recent fedora/rhel bootc base image,
the ostree dracut module is statically enabled:
https://gitlab.com/fedora/bootc/base-images/-/blob/40df0eb3827763039e4d17264968e37f850b70e5/tier-0/initramfs.yaml#L9

And also recently, we changed the ostree systemd unit
to enter emergency.target if it fails in:
ostreedev/ostree@05b3b66

These two things combine mean we'll fail before kdump gets
a chance to run.

For our use case we don't need ostree in the initrd.

I tried to override this with `--omit=ostree` in our dracut
invocation, but that causes an error (dracut doesn't let the
cmdline override static config).

For now, let's just mask the service in our initrd.

Signed-off-by: Colin Walters <walters@verbum.org>
Reviewed-by: Lichen Liu <lichliu@redhat.com>
Copy link
Member

@coiby coiby Sep 2, 2024

Choose a reason for hiding this comment

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

Unfortunately, this patch has several issues,

  1. it will cause the same regression as the previous RHEL-only commit will expr "X$_source" : 'X.*\[' will also match an IPv6 target specified in kdump.conf e.g. nfs [2203...]:/nfs_server
  2. The regex also matches brtfs subvol so it will return empty value for btrfs target
[root@localhost ~]# findmnt -k --pairs -o SOURCE,TARGET /dev/vda4
SOURCE="/dev/vda4[/root]" TARGET="/"
SOURCE="/dev/vda4[/home]" TARGET="/home"
SOURCE="/dev/vda4[/var]" TARGET="/var"
SOURCE="/dev/vda4[/var]" TARGET="/tt2"

I think a better way to to fix get_bind_mount_source is to check /proc/self/mountinfo,

[root@localhost ~]# mkdir /tt2
[root@localhost ~]# mount --bind /var /tt2

[root@localhost ~]# mkdir "/tt2 space"
[root@localhost ~]# mount --bind /var "/tt2 space"

[root@localhost ~]# grep tt2 /proc/self/mountinfo 
192 77 0:39 /var /tt2 rw,relatime shared:118 - btrfs /dev/vda4 rw,seclabel,compress=zstd:1,discard=async,space_cache=v2,subvolid=258,subvol=/var
488 77 0:39 /var /tt2\040space rw,relatime shared:118 - btrfs /dev/vda4 rw,seclabel,compress=zstd:1,discard=async,space_cache=v2,subvolid=258,subvol=/var

Another reason is changing get_mntpoint_from_target could bring regression as it's used on other places. Of course get_mntpoint_from_target is flawed to call findmnt with -f and this flaw can also been on non-composefs. Suppose we want to dump vmcore to /tt2/crash (/tt2 is bind mounted to /var), it returns / in this case,

[root@localhost ~]# findmnt -n -o source /tt2
/dev/vda4[/var]
[root@localhost ~]# findmnt -k --pairs -o SOURCE,TARGET /dev/vda4 
SOURCE="/dev/vda4" TARGET="/"
SOURCE="/dev/vda4[/var]" TARGET="/tt2"

Btw, The get_mntpoint_from_target names suggests it returns a mount point based on a target. But what it does is return a mount point based on a source. It should be renamed in order to not confuse readers.

Copy link
Member

Choose a reason for hiding this comment

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

To fix the regression first, I've created a centos-stream kdump-utils MR. But we need to fix the btrfs subvol issue.

Btw, there may be another problem with this PR. In this PR get_mntpoint_from_target no longer call get_mount_info which will fallback to find mount info in /etc/fstab and only call findmnt with -k argument. So this PR's get_mntpoint_from_target will not be able to make use of /etc/fstab and may cause problem for specifying a not-mounted target.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Hi @coiby , maybe we can use FSTYPE to handle this case.
For btrfs, it is in the Unsupported Dump targets and we have a fedora bug.
Maybe we can take this opportunity to refactor our code to handle different file systems.

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.

6 participants