On Fri, Apr 22, 2022 at 05:29:33PM +0200, Philipp Rudo wrote:
Hi Coiby,
On Sat, 2 Apr 2022 11:23:48 +0800
Coiby Xu <coxu(a)redhat.com> wrote:
> By default, NetworkManger will manage all the network interfaces and
> try to set interface IFF_UP to get carrier state. Regardless of whether
> the network interface is connected to a cable or not, the NIC driver
> will allocate memory resources for e.g. ring buffers when setting IFF_UP.
> This could be a waste of memory. For example it's found i40e consumes ~15GB
> on a power machine. On this machine, i40e manages four interfaces but only
> one interface is valid. This patch use "managed=false" to tell
> NetworkManager to not manage network interfaces that are not needed by
> kdump by putting /etc/NetworkManager/conf.d/10-kdump-netif.conf in the
> initramfs.
>
> Signed-off-by: Coiby Xu <coxu(a)redhat.com>
> ---
> dracut-module-setup.sh | 24 +++++++++++++++++++++++-
> 1 file changed, 23 insertions(+), 1 deletion(-)
>
> diff --git a/dracut-module-setup.sh b/dracut-module-setup.sh
> index 75f82af..d6ad3ba 100755
> --- a/dracut-module-setup.sh
> +++ b/dracut-module-setup.sh
> @@ -348,7 +348,7 @@ kdump_setup_ifname() {
>
> kdump_copy_nmconnection_file() {
> local _dev _nmconnection_file_path _nmconnection_name
_initrd_nmconnection_file_path
> - local _cloned_nmconnection_file_path _uniq_name _old_uuid _old_name _uuid
> + local _cloned_nmconnection_file_path _uniq_name _old_uuid _old_name _uuid
_per_mac
>
> _dev="$1"
>
> @@ -377,9 +377,31 @@ kdump_copy_nmconnection_file() {
> # user's custom value could overwrite it
> sed -i -E 's/(\[connection\])/\1\nwait-device-timeout=60000/'
"${initdir}/$_initrd_nmconnection_file_path"
>
> + _per_mac=$(kdump_get_perm_addr "$_dev")
> + if [[ "$_per_mac" != 'not set' ]]; then
> + echo -n "except:mac:$_per_mac," >>
"/tmp/$$-netif_allowlist"
I know that this way of handling temporary files is common in
dracut-modules-setup.sh. But personally I think it would be much better
if you create a temporary directory in install() and put all the files
in there. Then you only need a trap that removes the directory when
leaving install() instead of removing every file individually.
Thanks for the suggestion to simplify the implementation! I'll give it a
try.
> + else
> + echo -n "except:interface-name:$_dev," >>
"/tmp/$$-netif_allowlist"
> + fi
> +
> nmcli connection del "$_uuid"
> }
>
> +kdump_install_nm_netif_allowlist() {
> + local _netif_allowlist
> +
> + _netif_allowlist=$(cat "/tmp/$$-netif_allowlist")
> + cat <<- EOF > "/tmp/$$-10-kdump-netif.conf"
> + [device-others]
> + match-device=${_netif_allowlist}
Does that work when $$-netif_allowlist has multiple lines?
I don't think so. I have assumed ${_netif_allowlist} has only one line.
Thanks
Philipp
> + managed=false
> + EOF
> +
> + inst "/tmp/$$-10-kdump-netif.conf"
"/etc/NetworkManager/conf.d/10-kdump-netif.conf"
> + rm -f "/tmp/$$-10-kdump-netif.conf"
> + rm -f "/tmp/$$-netif_allowlist"
> +}
> +
> kdump_setup_bridge() {
> local _netdev=$1
> local _brif _dev _mac _kdumpdev
--
Best regards,
Coiby