From e9a917d61922a6d98ab4ae97070292fbdb33a90b Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Fri, 2 Jun 2017 00:01:26 +0200 Subject: [PATCH] device: refactor how master device's set is_available() Previously, master device types like bridge, bond, and team would overwrite is_available() and check_connection_available() and always return TRUE. The device already expresses via nm_device_is_master() that it is of a master kind. Refactor the code, so, instead of having these device types overwrite is_available() and check_connection_available(), let the parents implementation react on nm_device_is_master(). There is no change in behavior at all. Instead, the knowledge how to treat a master device moves from the device implementation to the parent class. --- src/devices/nm-device-bond.c | 20 -------------------- src/devices/nm-device-bridge.c | 13 +++---------- src/devices/nm-device.c | 13 ++++++++++++- src/devices/team/nm-device-team.c | 20 -------------------- 4 files changed, 15 insertions(+), 51 deletions(-) diff --git a/src/devices/nm-device-bond.c b/src/devices/nm-device-bond.c index 73ce460a2e..f1db8eeacc 100644 --- a/src/devices/nm-device-bond.c +++ b/src/devices/nm-device-bond.c @@ -57,24 +57,6 @@ get_generic_capabilities (NMDevice *dev) return NM_DEVICE_CAP_CARRIER_DETECT | NM_DEVICE_CAP_IS_SOFTWARE; } -static gboolean -is_available (NMDevice *dev, NMDeviceCheckDevAvailableFlags flags) -{ - return TRUE; -} - -static gboolean -check_connection_available (NMDevice *device, - NMConnection *connection, - NMDeviceCheckConAvailableFlags flags, - const char *specific_object) -{ - /* Connections are always available because the carrier state is determined - * by the slave carrier states, not the bonds's state. - */ - return TRUE; -} - static gboolean check_connection_compatible (NMDevice *device, NMConnection *connection) { @@ -631,9 +613,7 @@ nm_device_bond_class_init (NMDeviceBondClass *klass) parent_class->is_master = TRUE; parent_class->get_generic_capabilities = get_generic_capabilities; - parent_class->is_available = is_available; parent_class->check_connection_compatible = check_connection_compatible; - parent_class->check_connection_available = check_connection_available; parent_class->complete_connection = complete_connection; parent_class->update_connection = update_connection; diff --git a/src/devices/nm-device-bridge.c b/src/devices/nm-device-bridge.c index 58400211b2..90950fdfcb 100644 --- a/src/devices/nm-device-bridge.c +++ b/src/devices/nm-device-bridge.c @@ -59,12 +59,6 @@ get_generic_capabilities (NMDevice *dev) return NM_DEVICE_CAP_CARRIER_DETECT | NM_DEVICE_CAP_IS_SOFTWARE; } -static gboolean -is_available (NMDevice *dev, NMDeviceCheckDevAvailableFlags flags) -{ - return TRUE; -} - static gboolean check_connection_available (NMDevice *device, NMConnection *connection, @@ -73,6 +67,9 @@ check_connection_available (NMDevice *device, { NMSettingBluetooth *s_bt; + if (!NM_DEVICE_CLASS (nm_device_bridge_parent_class)->check_connection_available (device, connection, flags, specific_object)) + return FALSE; + s_bt = _nm_connection_get_setting_bluetooth_for_nap (connection); if (s_bt) { return nm_bt_vtable_network_server @@ -80,9 +77,6 @@ check_connection_available (NMDevice *device, nm_setting_bluetooth_get_bdaddr (s_bt)); } - /* Connections are always available because the carrier state is determined - * by the bridge port carrier states, not the bridge's state. - */ return TRUE; } @@ -490,7 +484,6 @@ nm_device_bridge_class_init (NMDeviceBridgeClass *klass) parent_class->is_master = TRUE; parent_class->get_generic_capabilities = get_generic_capabilities; - parent_class->is_available = is_available; parent_class->check_connection_compatible = check_connection_compatible; parent_class->check_connection_available = check_connection_available; parent_class->complete_connection = complete_connection; diff --git a/src/devices/nm-device.c b/src/devices/nm-device.c index cc2e39f68b..c3469a8895 100644 --- a/src/devices/nm-device.c +++ b/src/devices/nm-device.c @@ -3790,12 +3790,17 @@ is_available (NMDevice *self, NMDeviceCheckDevAvailableFlags flags) { NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE (self); - if (priv->carrier || priv->ignore_carrier) + if ( priv->carrier + || priv->ignore_carrier) return TRUE; if (NM_FLAGS_HAS (flags, _NM_DEVICE_CHECK_DEV_AVAILABLE_IGNORE_CARRIER)) return TRUE; + /* master types are always available even without carrier. */ + if (nm_device_is_master (self)) + return TRUE; + return FALSE; } @@ -11681,6 +11686,12 @@ check_connection_available (NMDevice *self, return TRUE; } + /* master types are always available even without carrier. + * Making connection non-available would un-enslave slaves which + * is not desired. */ + if (nm_device_is_master (self)) + return TRUE; + return FALSE; } diff --git a/src/devices/team/nm-device-team.c b/src/devices/team/nm-device-team.c index 2986664105..aeb39ebf9e 100644 --- a/src/devices/team/nm-device-team.c +++ b/src/devices/team/nm-device-team.c @@ -83,24 +83,6 @@ get_generic_capabilities (NMDevice *device) return NM_DEVICE_CAP_CARRIER_DETECT | NM_DEVICE_CAP_IS_SOFTWARE; } -static gboolean -is_available (NMDevice *device, NMDeviceCheckDevAvailableFlags flags) -{ - return TRUE; -} - -static gboolean -check_connection_available (NMDevice *device, - NMConnection *connection, - NMDeviceCheckConAvailableFlags flags, - const char *specific_object) -{ - /* Connections are always available because the carrier state is determined - * by the team port carrier states, not the team's state. - */ - return TRUE; -} - static gboolean check_connection_compatible (NMDevice *device, NMConnection *connection) { @@ -890,9 +872,7 @@ nm_device_team_class_init (NMDeviceTeamClass *klass) parent_class->is_master = TRUE; parent_class->create_and_realize = create_and_realize; parent_class->get_generic_capabilities = get_generic_capabilities; - parent_class->is_available = is_available; parent_class->check_connection_compatible = check_connection_compatible; - parent_class->check_connection_available = check_connection_available; parent_class->complete_connection = complete_connection; parent_class->update_connection = update_connection; parent_class->master_update_slave_connection = master_update_slave_connection;