From b09faad8779f5579b2f1c559edf7c0570e8d50ac Mon Sep 17 00:00:00 2001 From: Lukas Wunner Date: Mon, 6 Oct 2014 13:43:58 +0200 Subject: [PATCH 1/4] shutdown/shutdown.sh: loop over shutdown hooks until all succeed Up until now, _check_shutdown() returns true if at least one of the shutdown hooks succeeded. Change this to only return true if *all* succeeded. To prevent an infinite loop, introduce an upper bound of 40 iterations. --- modules.d/99shutdown/shutdown.sh | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/modules.d/99shutdown/shutdown.sh b/modules.d/99shutdown/shutdown.sh index 6e5e559f..98eab1d8 100755 --- a/modules.d/99shutdown/shutdown.sh +++ b/modules.d/99shutdown/shutdown.sh @@ -90,16 +90,19 @@ _check_shutdown() { ( . "$__f" $1 ) if [ $? -eq 0 ]; then rm -f -- $__f + else __s=0 fi done return $__s } -while _check_shutdown; do -: +_cnt=0 +while [ $_cnt -le 40 ]; do + _check_shutdown || break + _cnt=$(($_cnt+1)) done -_check_shutdown final +[ $_cnt -ge 40 ] && _check_shutdown final getarg 'rd.break=shutdown' && emergency_shell --shutdown shutdown "Break before shutdown" From 3947f07d93cde5e1cf0d788537e93b135d6c27b0 Mon Sep 17 00:00:00 2001 From: Harald Hoyer Date: Fri, 24 Oct 2014 15:47:24 +0200 Subject: [PATCH 2/4] ifcfg/write-ifcfg: only write DEVICE for non-kernel names Rename an interface to the kernel namespace is not allowed, so don't add DEVICE="", if HWADDR is given. --- modules.d/40network/net-lib.sh | 46 ++++++++++++++++++++++++- modules.d/45ifcfg/write-ifcfg.sh | 59 +++++++++++++++++++++----------- 2 files changed, 84 insertions(+), 21 deletions(-) diff --git a/modules.d/40network/net-lib.sh b/modules.d/40network/net-lib.sh index 8b5fbc64..48e70141 100755 --- a/modules.d/40network/net-lib.sh +++ b/modules.d/40network/net-lib.sh @@ -551,7 +551,19 @@ find_iface_with_link() { } is_persistent_ethernet_name() { - case "$1" in + local _netif="$1" + local _name_assign_type="0" + + [ -f "/sys/class/net/$_netif/name_assign_type" ] \ + && _name_assign_type=$(cat "/sys/class/net/$_netif/name_assign_type") + + # NET_NAME_ENUM 1 + [ "$_name_assign_type" = "1" ] && return 1 + + # NET_NAME_PREDICTABLE 2 + [ "$_name_assign_type" = "2" ] && return 0 + + case "$_netif" in # udev persistent interface names eno[0-9]|eno[0-9][0-9]|eno[0-9][0-9][0-9]*) ;; @@ -571,3 +583,35 @@ is_persistent_ethernet_name() { esac return 0 } + +is_kernel_ethernet_name() { + local _netif="$1" + local _name_assign_type="1" + + if [ -e "/sys/class/net/$_netif/name_assign_type" ]; then + _name_assign_type=$(cat "/sys/class/net/$_netif/name_assign_type") + + case "$_name_assign_type" in + 2|3|4) + # NET_NAME_PREDICTABLE 2 + # NET_NAME_USER 3 + # NET_NAME_RENAMED 4 + return 1 + ;; + 1|*) + # NET_NAME_ENUM 1 + return 0 + ;; + esac + fi + + # fallback to error prone manual name check + case "$_netif" in + eth[0-9]|eth[0-9][0-9]|eth[0-9][0-9][0-9]*) + return 0 + ;; + *) + return 1 + esac + +} diff --git a/modules.d/45ifcfg/write-ifcfg.sh b/modules.d/45ifcfg/write-ifcfg.sh index bb706f6f..3dcf3042 100755 --- a/modules.d/45ifcfg/write-ifcfg.sh +++ b/modules.d/45ifcfg/write-ifcfg.sh @@ -80,18 +80,41 @@ print_s390() { return 0 } +hw_bind() { + local _netif="$1" + local _macaddr="$2" + + [ -n "$_macaddr" ] \ + && echo "MACADDR=\"$_macaddr\"" + + print_s390 "$_netif" \ + && return 0 + + [ -n "$_macaddr" ] && return 0 + + is_persistent_ethernet_name "$_netif" && return 0 + + [ -f "/sys/class/net/$_netif/addr_assign_type" ] \ + && [ "$(cat "/sys/class/net/$_netif/addr_assign_type")" != "0" ] \ + && return 1 + + [ -f "/sys/class/net/$_netif/address" ] \ + || return 1 + + echo "HWADDR=\"$(cat /sys/class/net/$_netif/address)\"" +} + interface_bind() { - local netif="$1" - local macaddr="$2" - if ! print_s390 $netif; then - if [ -z "$macaddr" ] && \ - ! is_persistent_ethernet_name "$netif" && \ - [ -f /sys/class/net/$netif/addr_assign_type ] && \ - [ "$(cat /sys/class/net/$netif/addr_assign_type)" = "0" ] && \ - [ -f /sys/class/net/$netif/address ]; then - echo "HWADDR=\"$(cat /sys/class/net/$netif/address)\"" - fi + local _netif="$1" + local _macaddr="$2" + + # see, if we can bind it to some hw parms + if hw_bind "$_netif" "$_macaddr"; then + # only print out DEVICE, if it's user assigned + is_kernel_ethernet_name "$_netif" && return 0 fi + + echo "DEVICE=\"$_netif\"" } for netup in /tmp/net.*.did-setup ; do @@ -129,7 +152,8 @@ for netup in /tmp/net.*.did-setup ; do { echo "# Generated by dracut initrd" - echo "DEVICE=\"$netif\"" + echo "NAME=\"$netif\"" + interface_bind "$netif" "$macaddr" echo "ONBOOT=yes" echo "NETBOOT=yes" echo "UUID=\"$uuid\"" @@ -175,10 +199,7 @@ for netup in /tmp/net.*.did-setup ; do if [ -z "$bridge" ] && [ -z "$bond" ] && [ -z "$vlan" ]; then # standard interface { - [ -n "$macaddr" ] && echo "MACADDR=\"$macaddr\"" - interface_bind "$netif" "$macaddr" echo "TYPE=Ethernet" - echo "NAME=\"$netif\"" [ -n "$mtu" ] && echo "MTU=\"$mtu\"" } >> /tmp/ifcfg/ifcfg-$netif fi @@ -205,16 +226,15 @@ for netup in /tmp/net.*.did-setup ; do # write separate ifcfg file for the raw eth interface ( echo "# Generated by dracut initrd" - echo "DEVICE=\"$slave\"" + echo "NAME=\"$slave\"" echo "TYPE=Ethernet" echo "ONBOOT=yes" echo "NETBOOT=yes" echo "SLAVE=yes" echo "MASTER=\"$netif\"" - echo "NAME=\"$slave\"" echo "UUID=\"$(cat /proc/sys/kernel/random/uuid)\"" + unset macaddr [ -e /tmp/net.$slave.override ] && . /tmp/net.$slave.override - [ -n "$macaddr" ] && echo "MACADDR=\"$macaddr\"" interface_bind "$slave" "$macaddr" ) >> /tmp/ifcfg/ifcfg-$slave done @@ -230,15 +250,14 @@ for netup in /tmp/net.*.did-setup ; do # write separate ifcfg file for the raw eth interface ( echo "# Generated by dracut initrd" - echo "DEVICE=\"$slave\"" + echo "NAME=\"$slave\"" echo "TYPE=Ethernet" echo "ONBOOT=yes" echo "NETBOOT=yes" echo "BRIDGE=\"$bridgename\"" - echo "NAME=\"$slave\"" echo "UUID=\"$(cat /proc/sys/kernel/random/uuid)\"" + unset macaddr [ -e /tmp/net.$slave.override ] && . /tmp/net.$slave.override - [ -n "$macaddr" ] && echo "MACADDR=\"$macaddr\"" interface_bind "$slave" "$macaddr" ) >> /tmp/ifcfg/ifcfg-$slave done From 972d6b44ba54e44c01801614fb57e128604b4a12 Mon Sep 17 00:00:00 2001 From: Stefan Reimer Date: Tue, 28 Oct 2014 17:58:22 -0700 Subject: [PATCH 3/4] Fix location of dracut-install for local mode --- dracut-functions.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/dracut-functions.sh b/dracut-functions.sh index 1bcc3b43..3ad8d81e 100755 --- a/dracut-functions.sh +++ b/dracut-functions.sh @@ -741,8 +741,8 @@ if ! [[ $DRACUT_INSTALL ]]; then DRACUT_INSTALL=$(find_binary dracut-install) fi -if ! [[ $DRACUT_INSTALL ]] && [[ -x $dracutbasedir/dracut-install ]]; then - DRACUT_INSTALL=$dracutbasedir/dracut-install +if ! [[ $DRACUT_INSTALL ]] && [[ -x $dracutbasedir/install/dracut-install ]]; then + DRACUT_INSTALL=$dracutbasedir/install/dracut-install fi if ! [[ -x $DRACUT_INSTALL ]]; then From 2f0f1b0bbc0aae6b5f54c64d911eb6b09030798d Mon Sep 17 00:00:00 2001 From: Harald Hoyer Date: Wed, 29 Oct 2014 13:39:28 +0100 Subject: [PATCH 4/4] dracut-functions.sh: fixup for 34a1ec6 for non-local mode --- dracut-functions.sh | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/dracut-functions.sh b/dracut-functions.sh index 3ad8d81e..b43b7664 100755 --- a/dracut-functions.sh +++ b/dracut-functions.sh @@ -741,7 +741,9 @@ if ! [[ $DRACUT_INSTALL ]]; then DRACUT_INSTALL=$(find_binary dracut-install) fi -if ! [[ $DRACUT_INSTALL ]] && [[ -x $dracutbasedir/install/dracut-install ]]; then +if ! [[ $DRACUT_INSTALL ]] && [[ -x $dracutbasedir/dracut-install ]]; then + DRACUT_INSTALL=$dracutbasedir/dracut-install +elif ! [[ $DRACUT_INSTALL ]] && [[ -x $dracutbasedir/install/dracut-install ]]; then DRACUT_INSTALL=$dracutbasedir/install/dracut-install fi