From b6f8ecb3301f2800fcff0747b3cb1be2433dbbbe Mon Sep 17 00:00:00 2001 From: Dan Williams Date: Thu, 17 Jan 2013 15:44:30 -0600 Subject: [PATCH] core: handle slave deactivation more gracefully Two things: 1) When the slave was deactivated, nm_device_deactivate() runs before the master gets the slave's state-changed signal, and thus priv->master is cleared long before nm_device_notify_enslaved() is called. Which would trigger the g_assert (priv->master). 2) If the slave is already deactivated, there's no point in re-queueing a state change to deactivated. So just assert that priv->master is valid if the slave is going to be enslaved, but if the slave is being released, ignore NULL priv->master which we don't use anyway. Also ignore redundant state changes. --- src/nm-device.c | 34 ++++++++++++++++++---------------- 1 file changed, 18 insertions(+), 16 deletions(-) diff --git a/src/nm-device.c b/src/nm-device.c index 32079aa5c3..37f3da45d1 100644 --- a/src/nm-device.c +++ b/src/nm-device.c @@ -1017,9 +1017,8 @@ nm_device_slave_notify_enslaved (NMDevice *dev, NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE (dev); NMConnection *connection = nm_device_get_connection (dev); - g_assert (priv->master); - if (enslaved) { + g_assert (priv->master); g_warn_if_fail (priv->enslaved == FALSE); g_warn_if_fail (priv->state == NM_DEVICE_STATE_IP_CONFIG); @@ -1039,22 +1038,25 @@ nm_device_slave_notify_enslaved (NMDevice *dev, NMDeviceState new_state = NM_DEVICE_STATE_DISCONNECTED; NMDeviceStateReason reason = NM_DEVICE_STATE_REASON_NONE; - if (master_failed) { - new_state = NM_DEVICE_STATE_FAILED; - reason = NM_DEVICE_STATE_REASON_DEPENDENCY_FAILED; + if ( priv->state > NM_DEVICE_STATE_DISCONNECTED + && priv->state <= NM_DEVICE_STATE_ACTIVATED) { + if (master_failed) { + new_state = NM_DEVICE_STATE_FAILED; + reason = NM_DEVICE_STATE_REASON_DEPENDENCY_FAILED; - nm_log_warn (LOGD_DEVICE, - "Activation (%s) connection '%s' master failed", - nm_device_get_iface (dev), - nm_connection_get_id (connection)); - } else { - nm_log_dbg (LOGD_DEVICE, - "Activation (%s) connection '%s' master deactivated", - nm_device_get_iface (dev), - nm_connection_get_id (connection)); + nm_log_warn (LOGD_DEVICE, + "Activation (%s) connection '%s' master failed", + nm_device_get_iface (dev), + nm_connection_get_id (connection)); + } else { + nm_log_dbg (LOGD_DEVICE, + "Activation (%s) connection '%s' master deactivated", + nm_device_get_iface (dev), + nm_connection_get_id (connection)); + } + + nm_device_queue_state (dev, new_state, reason); } - - nm_device_queue_state (dev, new_state, reason); } }