Hi,
The regex pattern is used to extract the "addr=" option in mount
options, nfs service would always
append that even if the user didn't specify it manually.
Some example (I updated the sed command line and will be included in v2 patch):
On a test machine (v6):
$ findmnt -k -f -n -r -o OPTIONS
ibm-x3650m4-01-vm-02.lab.eng.bos.redhat.com:/mnt/testarea/nfs
rw,relatime,vers=4.2,rsize=524288,wsize=524288,namlen=255,hard,proto=tcp6,timeo=600,retrans=2,sec=sys,clientaddr=2620:52:0:1040:5054:ff:fe2d:af2,local_lock=none,addr=2620:52:0:102f:5054:1ff:fe3c:e12a
$ findmnt -k -f -n -r -o OPTIONS
ibm-x3650m4-01-vm-02.lab.eng.bos.redhat.com:/mnt/testarea/nfs | sed -n
's/.*,addr=\([0-9a-f:\.]*\).*/\1/p'
2620:52:0:102f:5054:1ff:fe3c:e12a
On VM (v4):
$ findmnt -k -f -n -r -o OPTIONS vm-host:/srv/nfs
rw,relatime,vers=4.2,rsize=1048576,wsize=1048576,namlen=255,hard,proto=tcp,timeo=600,retrans=2,sec=sys,clientaddr=192.168.122.176,local_lock=none,addr=192.168.122.1
$ findmnt -k -f -n -r -o OPTIONS vm-host:/srv/nfs | sed -n
's/.*,addr=\([0-9a-f:\.]*\).*/\1/p'
192.168.122.1
Will output empty string on non-match:
$ echo "rw,relatime,vers=4.2,rsize=524288,wsize=524288" | sed -n
's/.*,addr=\([0-9a-f:\.]*\).*/\1/p'
(no output)
After a second thought, although I think this patch is on the right approach.
but it may fail some condition previous won't fail.
kdumpctl decides which network stack (v4 or v6) to be enabled in second kernel
only according to the target address type, if kdumpctl follows nfs
service, and prefer
the IPv6 address, but the host only have IPv4 DNS server available,
then in the second
kernel the hostname will be unresolvable because only IPv6 network is enabled.
And kdump will fail, previous it will just work becasue kdumpctl
prefering IPv4 address.
Previous behavior is also not correct either, it fails if kdumpclt
selected the preferred
IPv4 address but there is only IPv6 DNS server available.
But I think previous behavior may just worked on most systems, now
IPv4 is still more
widely used.
Things won't go wrong if the target is specified by IP rather than hostname,
So the real problem is kdumpctl not ensuring the network stack
required to access DNS
server is enabled. Currently, we are blindly copying first kernel's
resolv.conf to second
kernel, will be better to check address type of DNS servers as well
and enable requird
network if needed. But that part is currently not doable yet. Dracut
only support single network config
cmdline, the cmdline only accept very simple dual stack configuration
(with no interface specified,
no static IP, let dracut select the interface and everything
automatically), but kdumpctl have to
deal with a lot of complex configurations, like kdumpctl will always
choose only the right interface
to enable and use static IP if that's how it is configured in first
kernel. So currently not doable with
Dracut. Need to do some other improves/reworks to get this part right.
The new dracut network-manager module works with multiple cmdline, but
not yet usable
in Fedora.
Anyway, that's a separate problem, maybe it shouldn't block this patch
from being merged.
On Mon, Nov 19, 2018 at 4:55 PM Dave Young <dyoung(a)redhat.com> wrote:
On 11/15/18 at 02:20pm, Kairui Song wrote:
> When using nfs target, kdumpctl will manually resolve nfs server's
> hostname. But the problem is nfs service may select another address if
> the server have multiple address. eg. nfs will try IPv6 first, then
> failover to IPv4.
>
> It's hard to tell if the NFS server is serving nfs service on it's
> IPv6 or IPv4 interface or both, things may get even more complex if
> the host have multiple address or there are some special routing
> rules. Blindly use IPv4 / IPv6 may have poteintial risk. So use the
> working address reported by nfs service, which should always work.
> ---
> dracut-module-setup.sh | 12 ++++++++++--
> kdump-lib.sh | 10 +++++++++-
> mkdumprd | 5 ++---
> 3 files changed, 21 insertions(+), 6 deletions(-)
>
> diff --git a/dracut-module-setup.sh b/dracut-module-setup.sh
> index 7499678..2637c29 100755
> --- a/dracut-module-setup.sh
> +++ b/dracut-module-setup.sh
> @@ -479,7 +479,7 @@ adjust_bind_mount_path()
>
> #install kdump.conf and what user specifies in kdump.conf
> kdump_install_conf() {
> - local _opt _val _pdev
> + local _opt _val _pdev _addr
> sed -ne '/^#/!p' /etc/kdump.conf > ${initdir}/tmp/$$-kdump.conf
>
> while read _opt _val;
> @@ -498,7 +498,15 @@ kdump_install_conf() {
> adjust_bind_mount_path "$_val"
> fi
> ;;
> - ssh|nfs)
> + nfs)
> + _addr=$(get_mount_options_from_target "$_val" | sed
's/.*,addr=\([0-9a-f:\.]*\).*/\1/')
Kairui, can you give an example of above input and output?
> + if [[ -n "$_addr" ]]; then
> + kdump_install_net "$_addr"
> + else
> + kdump_install_net "$_val"
> + fi
> + ;;
> + ssh)
> kdump_install_net "$_val"
> ;;
> dracut_args)
> diff --git a/kdump-lib.sh b/kdump-lib.sh
> index 6acab8c..8b4e360 100755
> --- a/kdump-lib.sh
> +++ b/kdump-lib.sh
> @@ -236,11 +236,19 @@ get_target_from_path()
> echo $_target
> }
>
> -get_fs_type_from_target()
> +get_fs_type_from_target()
> {
> echo $(findmnt -k -f -n -r -o FSTYPE $1)
> }
>
> +get_mount_options_from_target()
> +{
> + local _options
> + [[ -e /etc/fstab ]] && _options=$(findmnt --fstab -f -n -r -o OPTIONS
$1)
> + [ -z "$_options" ] && _options=$(findmnt -k -f -n -r -o
OPTIONS $1)
> + echo $_options
> +}
> +
> # input: device path
> # output: the general mount point
> # find the general mount point, not the bind mounted point in atomic
> diff --git a/mkdumprd b/mkdumprd
> index 078f988..9c59fef 100644
> --- a/mkdumprd
> +++ b/mkdumprd
> @@ -96,9 +96,8 @@ to_mount() {
> _target="/kdumproot/$_target"
> fi
>
> - _fstype=$(findmnt -k -f -n -r -o FSTYPE $_dev)
> - [[ -e /etc/fstab ]] && _options=$(findmnt --fstab -f -n -r -o OPTIONS
$_dev)
> - [ -z "$_options" ] && _options=$(findmnt -k -f -n -r -o
OPTIONS $_dev)
> + _fstype=$(get_fs_type_from_target $_dev)
> + _options=$(get_mount_options_from_target $_dev)
> # with 'noauto' in fstab nfs and non-root disk mount will fail in 2nd
> # kernel, filter it out here.
> _options=$(echo $_options | sed 's/\bnoauto\b//')
> --
> 2.17.1
>
--
Best Regards,
Kairui Song