Hi Philipp,
Thanks for carefully reviewing the patch!
On Mon, Aug 01, 2022 at 04:59:30PM +0200, Philipp Rudo wrote:
Hi Coiby,
On Tue, 21 Jun 2022 14:57:16 +0800
Coiby Xu <coxu(a)redhat.com> wrote:
> NetworkManager defaults to use keyfile i.e. .nmconnnection file but
> still supports reading ifcfg-* file [1]. Make use of
> "nmcli connection clone --temporary" to automatically convert a ifcfg-*
> file to a .nmconnection file.
>
> [1]
https://fedoraproject.org/wiki/Changes/NetworkManager_keyfile_instead_of_...
>
> Signed-off-by: Coiby Xu <coxu(a)redhat.com>
> ---
> dracut-module-setup.sh | 53 ++++++++++++++++++++++++++++++++++++++++++
> 1 file changed, 53 insertions(+)
>
> diff --git a/dracut-module-setup.sh b/dracut-module-setup.sh
> index 3dc597f..dba023d 100755
> --- a/dracut-module-setup.sh
> +++ b/dracut-module-setup.sh
> @@ -1,10 +1,20 @@
> #!/bin/bash
>
> +_DRACUT_KDUMP_NM_TMP_DIR="/tmp/$$-DRACUT_KDUMP_NM"
Why don't you use mktemp -d?
I just tried mktemp but found two issues,
- mktemp and cleanup somehow would be called 4 times (it seems dracut
source dracut-module-setup.sh many times)
- after running a network test, some of the temp folders are not
deleted
> +
> +cleanup() {
> + rm -rf $_DRACUT_KDUMP_NM_TMP_DIR
> +}
> +
> +trap 'ret=$?; cleanup; exit $ret;' EXIT
> +
> kdump_module_init() {
> if ! [[ -d "${initdir}/tmp" ]]; then
> mkdir -p "${initdir}/tmp"
> fi
>
> + mkdir -p "$_DRACUT_KDUMP_NM_TMP_DIR"
> +
> . /lib/kdump/kdump-lib.sh
> }
>
> @@ -346,6 +356,47 @@ kdump_setup_ifname() {
> echo "$_ifname"
> }
>
> +_clone_nmconnection() {
> + local _clone_output _name _unique_id
> +
> + _unique_id=$1
> + _name=$(nmcli --get-values connection.id connection show
"$_unique_id")
> + if _clone_output=$(nmcli connection clone --temporary "$_unique_id"
"$_name"); then
> + sed -E -n "s/.* \(.*\) cloned as.*\((.*)\)\.$/\1/p" <<<
"$_clone_output"
> + return 0
> + fi
> +
> + return 1
> +}
> +
> +# Clone NM connection profiles
> +#
> +# This function makes use of "nmcli clone" to automatically convert
ifcfg-*
> +# files to Networkmanager .nmconnection connection profiles.
> +clone_nmconnections() {
> + local _dev _cloned_nmconnection_file_path _tmp_nmconnection_file_path _old_uuid
_uuid
> +
> + for _dev in "${!nmconnection_map[@]}"; do
> + _nmconnection_file_path=${nmconnection_map[$_dev]}
> + _old_uuid=$(nmcli --get-values connection.uuid connection show
"$_nmconnection_file_path")
> +
> + if ! _uuid=$(_clone_nmconnection "$_old_uuid"); then
> + derror "Failed to clone $_old_uuid"
> + exit 1
> + fi
> +
> + _cloned_nmconnection_file_path=$(nmcli --get-values UUID,FILENAME connection
show | sed -n "s/^${_uuid}://p")
> + _tmp_nmconnection_file_path=$_DRACUT_KDUMP_NM_TMP_DIR/$(basename
"$_nmconnection_file_path")
> + cp "$_cloned_nmconnection_file_path"
"$_tmp_nmconnection_file_path"
> + # change uuid back to old value in case it's refered by other
connection
> + # profile e.g. connection.master could be tnterface name of the master
s/tnterface/interface/ ?
Thanks for catching this typo!
Thanks
Philipp
> + # device or UUID of the master connection.
> + sed -i -E "s/(^uuid=).*$/\1${_old_uuid}/g"
"$_tmp_nmconnection_file_path"
> + nmconnection_map[$_dev]=$_tmp_nmconnection_file_path
> + nmcli connection del "$_uuid" &> >(ddebug)
> + done
> +}
> +
> kdump_copy_nmconnection_file() {
> local _dev _nmconnection_file_path _nmconnection_name
_initrd_nmconnection_file_path
>
> @@ -551,6 +602,7 @@ kdump_install_net() {
> while IFS=: read -r _ifname _nmconn; do
> nmconnection_map[$_ifname]="$_nmconn"
> done <<< "$(nmcli -t -f device,filename connection show
--active)"
> + clone_nmconnections
>
> _destaddr=$(kdump_get_remote_ip "$1")
> _route=$(kdump_get_ip_route "$_destaddr")
> @@ -622,6 +674,7 @@ kdump_install_net() {
> echo "kdumpnic=$kdumpnic" >
"${initdir}/etc/cmdline.d/60kdumpnic.conf"
> echo "bootdev=$kdumpnic" >
"${initdir}/etc/cmdline.d/70bootdev.conf"
> fi
> +
> }
>
> # install etc/kdump/pre.d and /etc/kdump/post.d
--
Best regards,
Coiby