From ec87f5ce21c45fc572e1230c5e89711b2d67e8ba Mon Sep 17 00:00:00 2001 From: Michael Tremer Date: Fri, 21 Sep 2018 22:58:01 +0100 Subject: [PATCH] Move creating port configurations into network-hotplug-rename This script is now actually creating a new configuration while it is holding the lock. Signed-off-by: Michael Tremer --- src/hooks/ports/ethernet | 5 ++++- src/udev/network-hotplug | 9 +-------- src/udev/network-hotplug-rename | 18 +++++++++++------- 3 files changed, 16 insertions(+), 16 deletions(-) diff --git a/src/hooks/ports/ethernet b/src/hooks/ports/ethernet index 18e9d57c..cdc3dec7 100644 --- a/src/hooks/ports/ethernet +++ b/src/hooks/ports/ethernet @@ -106,7 +106,10 @@ hook_new() { local port="${1}" assert isset port - local DEVICE="$(device_get_address "${port}")" + local device="${2}" + assert isset device + + local DEVICE="$(device_get_address "${device}")" if ! port_settings_write "${port}" ${HOOK_SETTINGS}; then log ERROR "Could not write settings for port ${port}" diff --git a/src/udev/network-hotplug b/src/udev/network-hotplug index c94fa2a5..af6c0df9 100644 --- a/src/udev/network-hotplug +++ b/src/udev/network-hotplug @@ -80,17 +80,10 @@ case "${SUBSYSTEM}" in if ! port_exists "${INTERFACE}"; then case "${ACTION}" in add) - TYPE="$(device_get_type "${INTERFACE}")" - - # If this is an Ethernet device, we will automatically create a new port - if [ "${TYPE}" = "ethernet" ]; then - port_new "ethernet" "${INTERFACE}" - exit $? - fi - log WARNING "Got to hotplug event for a port which does not exist: ${INTERFACE}" # Try to remove the device again + TYPE="$(device_get_type "${INTERFACE}")" case "${TYPE}" in bonding) bonding_remove "${INTERFACE}" diff --git a/src/udev/network-hotplug-rename b/src/udev/network-hotplug-rename index ec417b66..25091649 100644 --- a/src/udev/network-hotplug-rename +++ b/src/udev/network-hotplug-rename @@ -60,18 +60,22 @@ main() { for port in $(ports_get_all); do port_cmd hotplug_rename "${port}" "${INTERFACE}" &>/dev/null if [ $? -eq ${EXIT_TRUE} ]; then - echo "${port}" + print "${port}" exit ${EXIT_OK} fi done - # If no port configuration could be found, - # we search for the next unused name and return that. - port=$(port_find_free ${PORT_PATTERN}) - echo "${port}" + # Could not find a valid port configuration, creating a new one + port="$(port_find_free "${PORT_PATTERN}")" + assert isset port - log DEBUG "Could not find an existing port configuration for '${INTERFACE}'" - log DEBUG "Renaming interface '${INTERFACE}' to '${port}'" + # Create a new port configuration with the new name + if ! port_new "ethernet" "${port}" "${INTERFACE}"; then + log ERROR "Could not create new port configuration for ${INTERFACE}" + return ${EXIT_ERROR} + fi + + print "${port}" ;; esac -- 2.39.2