diff options
author | Dan Williams <dcbw@redhat.com> | 2015-04-07 12:04:36 -0500 |
---|---|---|
committer | Thomas Haller <thaller@redhat.com> | 2015-04-29 10:12:21 +0200 |
commit | 1fc4a04ee2de610e5519edb6b686888004d32993 (patch) | |
tree | 0374beb4d10fc51bc6ccea5a206cbd3751335dfd | |
parent | 887b73ca83bad32889a04e8b8cd833058e9b39b2 (diff) | |
download | NetworkManager-1fc4a04ee2de610e5519edb6b686888004d32993.tar.gz |
fixup! core: let device plugins advertise supported link and setting types
Always return either a device or an error from
nm_device_factory_create_virtual_device_for_connection()
-rw-r--r-- | src/devices/nm-device-bond.c | 18 | ||||
-rw-r--r-- | src/devices/nm-device-bridge.c | 18 | ||||
-rw-r--r-- | src/devices/nm-device-factory.c | 35 | ||||
-rw-r--r-- | src/devices/nm-device-infiniband.c | 16 | ||||
-rw-r--r-- | src/devices/nm-device-vlan.c | 24 | ||||
-rw-r--r-- | src/devices/team/nm-device-team.c | 16 | ||||
-rw-r--r-- | src/devices/team/nm-team-factory.c | 4 | ||||
-rw-r--r-- | src/nm-manager.c | 16 |
8 files changed, 78 insertions, 69 deletions
diff --git a/src/devices/nm-device-bond.c b/src/devices/nm-device-bond.c index 9f4b4eef18..df40d2a4f0 100644 --- a/src/devices/nm-device-bond.c +++ b/src/devices/nm-device-bond.c @@ -573,19 +573,17 @@ create_virtual_device_for_connection (NMDeviceFactory *factory, NMDevice *parent, GError **error) { - const char *iface; - - if (!nm_connection_is_type (connection, NM_SETTING_BOND_SETTING_NAME)) - return NULL; + const char *iface = nm_connection_get_interface_name (connection); - iface = nm_connection_get_interface_name (connection); - g_return_val_if_fail (iface != NULL, NULL); + g_assert (iface); if ( !nm_platform_bond_add (NM_PLATFORM_GET, iface) - && nm_platform_get_error (NM_PLATFORM_GET) != NM_PLATFORM_ERROR_EXISTS) { - nm_log_warn (LOGD_DEVICE | LOGD_BOND, "(%s): failed to create bonding master interface for '%s': %s", - iface, nm_connection_get_id (connection), - nm_platform_get_error_msg (NM_PLATFORM_GET)); + && nm_platform_get_error (NM_PLATFORM_GET) != NM_PLATFORM_ERROR_EXISTS) { + g_set_error (error, NM_DEVICE_ERROR, NM_DEVICE_ERROR_CREATION_FAILED, + "Failed to create bond interface '%s' for '%s': %s", + iface, + nm_connection_get_id (connection), + nm_platform_get_error_msg (NM_PLATFORM_GET)); return NULL; } diff --git a/src/devices/nm-device-bridge.c b/src/devices/nm-device-bridge.c index 2e09e99a1a..b052a62993 100644 --- a/src/devices/nm-device-bridge.c +++ b/src/devices/nm-device-bridge.c @@ -497,21 +497,15 @@ create_virtual_device_for_connection (NMDeviceFactory *factory, NMDevice *parent, GError **error) { - const char *iface; + const char *iface = nm_connection_get_interface_name (connection); NMSettingBridge *s_bridge; const char *mac_address_str; guint8 mac_address[NM_UTILS_HWADDR_LEN_MAX]; - if (!nm_connection_is_type (connection, NM_SETTING_BRIDGE_SETTING_NAME)) - return NULL; - - g_return_val_if_fail (connection != NULL, NULL); - - iface = nm_connection_get_interface_name (connection); - g_return_val_if_fail (iface != NULL, NULL); + g_assert (iface); s_bridge = nm_connection_get_setting_bridge (connection); - g_return_val_if_fail (s_bridge, NULL); + g_assert (s_bridge); mac_address_str = nm_setting_bridge_get_mac_address (s_bridge); if (mac_address_str) { @@ -524,8 +518,10 @@ create_virtual_device_for_connection (NMDeviceFactory *factory, mac_address_str ? mac_address : NULL, mac_address_str ? ETH_ALEN : 0) && nm_platform_get_error (NM_PLATFORM_GET) != NM_PLATFORM_ERROR_EXISTS) { - nm_log_warn (LOGD_DEVICE | LOGD_BRIDGE, "(%s): failed to create bridge master interface for '%s': %s", - iface, nm_connection_get_id (connection), + g_set_error (error, NM_DEVICE_ERROR, NM_DEVICE_ERROR_CREATION_FAILED, + "Failed to create bridge interface '%s' for '%s': %s", + iface, + nm_connection_get_id (connection), nm_platform_get_error_msg (NM_PLATFORM_GET)); return NULL; } diff --git a/src/devices/nm-device-factory.c b/src/devices/nm-device-factory.c index eb5a25d37f..84e4ce7398 100644 --- a/src/devices/nm-device-factory.c +++ b/src/devices/nm-device-factory.c @@ -141,15 +141,40 @@ nm_device_factory_create_virtual_device_for_connection (NMDeviceFactory *factory GError **error) { NMDeviceFactory *interface; + const char **setting_types = NULL; + gboolean found = FALSE; + int i; g_return_val_if_fail (factory, NULL); g_return_val_if_fail (connection, NULL); g_return_val_if_fail (!error || !*error, NULL); + /* Ensure the factory can create interfaces for this connection */ + nm_device_factory_get_supported_types (factory, NULL, &setting_types); + for (i = 0; setting_types && setting_types[i]; i++) { + if (nm_connection_is_type (connection, setting_types[i])) { + found = TRUE; + break; + } + } + + if (!found) { + g_set_error (error, NM_DEVICE_ERROR, NM_DEVICE_ERROR_INCOMPATIBLE_CONNECTION, + "Device factory %s does not support connection type %s", + G_OBJECT_TYPE_NAME (factory), + nm_connection_get_connection_type (connection)); + return NULL; + } + interface = NM_DEVICE_FACTORY_GET_INTERFACE (factory); - if (interface->create_virtual_device_for_connection) - return interface->create_virtual_device_for_connection (factory, connection, parent, error); - return NULL; + if (!interface->create_virtual_device_for_connection) { + g_set_error (error, NM_MANAGER_ERROR, NM_MANAGER_ERROR_FAILED, + "Device factory %s cannot create virtual devices", + G_OBJECT_TYPE_NAME (factory)); + return NULL; + } + + return interface->create_virtual_device_for_connection (factory, connection, parent, error); } /*******************************************************************/ @@ -350,9 +375,9 @@ _add_factory (NMDeviceFactory *factory, } g_object_set_data_full (G_OBJECT (factory), PLUGIN_PATH_TAG, g_strdup (path), g_free); - for (i = 0; link_types[i] > NM_LINK_TYPE_UNKNOWN; i++) + for (i = 0; link_types && link_types[i] > NM_LINK_TYPE_UNKNOWN; i++) g_hash_table_insert (factories_by_link, GUINT_TO_POINTER (link_types[i]), g_object_ref (factory)); - for (i = 0; setting_types[i]; i++) + for (i = 0; setting_types && setting_types[i]; i++) g_hash_table_insert (factories_by_setting, (char *) setting_types[i], g_object_ref (factory)); callback (factory, user_data); diff --git a/src/devices/nm-device-infiniband.c b/src/devices/nm-device-infiniband.c index 6d40c5b075..2b97c2f328 100644 --- a/src/devices/nm-device-infiniband.c +++ b/src/devices/nm-device-infiniband.c @@ -315,23 +315,27 @@ create_virtual_device_for_connection (NMDeviceFactory *factory, int p_key, parent_ifindex; const char *iface; - if (!nm_connection_is_type (connection, NM_SETTING_INFINIBAND_SETTING_NAME)) + if (!NM_IS_DEVICE_INFINIBAND (parent)) { + g_set_error (error, NM_DEVICE_ERROR, NM_DEVICE_ERROR_CREATION_FAILED, + "Parent interface %s must be an InfiniBand interface", + nm_device_get_iface (parent)); return NULL; - - g_return_val_if_fail (NM_IS_DEVICE_INFINIBAND (parent), NULL); + } s_infiniband = nm_connection_get_setting_infiniband (connection); iface = nm_setting_infiniband_get_virtual_interface_name (s_infiniband); - g_return_val_if_fail (iface != NULL, NULL); + g_assert (iface); parent_ifindex = nm_device_get_ifindex (parent); p_key = nm_setting_infiniband_get_p_key (s_infiniband); if ( !nm_platform_infiniband_partition_add (NM_PLATFORM_GET, parent_ifindex, p_key) && nm_platform_get_error (NM_PLATFORM_GET) != NM_PLATFORM_ERROR_EXISTS) { - nm_log_warn (LOGD_DEVICE | LOGD_INFINIBAND, "(%s): failed to add InfiniBand P_Key interface for '%s': %s", - iface, nm_connection_get_id (connection), + g_set_error (error, NM_DEVICE_ERROR, NM_DEVICE_ERROR_CREATION_FAILED, + "Failed to create InfiniBand P_Key interface '%s' for '%s': %s", + iface, + nm_connection_get_id (connection), nm_platform_get_error_msg (NM_PLATFORM_GET)); return NULL; } diff --git a/src/devices/nm-device-vlan.c b/src/devices/nm-device-vlan.c index 7102496dac..c83be3f479 100644 --- a/src/devices/nm-device-vlan.c +++ b/src/devices/nm-device-vlan.c @@ -40,6 +40,7 @@ #include "nm-device-factory.h" #include "nm-manager.h" #include "nm-core-internal.h" +#include "gsystem-local-alloc.h" #include "nm-device-vlan-glue.h" @@ -706,15 +707,16 @@ create_virtual_device_for_connection (NMDeviceFactory *factory, { NMDevice *device; NMSettingVlan *s_vlan; - char *iface; + gs_free char *iface = NULL; - if (!nm_connection_is_type (connection, NM_SETTING_VLAN_SETTING_NAME)) + if (!NM_IS_DEVICE (parent)) { + g_set_error_literal (error, NM_DEVICE_ERROR, NM_DEVICE_ERROR_CREATION_FAILED, + "VLAN interfaces must have parents"); return NULL; - - g_return_val_if_fail (NM_IS_DEVICE (parent), NULL); + } s_vlan = nm_connection_get_setting_vlan (connection); - g_return_val_if_fail (s_vlan != NULL, NULL); + g_assert (s_vlan); iface = g_strdup (nm_connection_get_interface_name (connection)); if (!iface) { @@ -728,9 +730,11 @@ create_virtual_device_for_connection (NMDeviceFactory *factory, nm_setting_vlan_get_id (s_vlan), nm_setting_vlan_get_flags (s_vlan)) && nm_platform_get_error (NM_PLATFORM_GET) != NM_PLATFORM_ERROR_EXISTS) { - nm_log_warn (LOGD_DEVICE | LOGD_VLAN, "(%s) failed to add VLAN interface for '%s'", - iface, nm_connection_get_id (connection)); - g_free (iface); + g_set_error (error, NM_DEVICE_ERROR, NM_DEVICE_ERROR_CREATION_FAILED, + "Failed to create VLAN interface '%s' for '%s': %s", + iface, + nm_connection_get_id (connection), + nm_platform_get_error_msg (NM_PLATFORM_GET)); return NULL; } @@ -741,8 +745,10 @@ create_virtual_device_for_connection (NMDeviceFactory *factory, NM_DEVICE_TYPE_DESC, "VLAN", NM_DEVICE_DEVICE_TYPE, NM_DEVICE_TYPE_VLAN, NULL); - g_free (iface); if (NM_DEVICE_VLAN_GET_PRIVATE (device)->invalid) { + g_set_error (error, NM_DEVICE_ERROR, NM_DEVICE_ERROR_CREATION_FAILED, + "Failed to create VLAN interface '%s' for '%s': initialization failed", + iface, nm_connection_get_id (connection)); g_object_unref (device); device = NULL; } diff --git a/src/devices/team/nm-device-team.c b/src/devices/team/nm-device-team.c index 6b58014393..77a74db21d 100644 --- a/src/devices/team/nm-device-team.c +++ b/src/devices/team/nm-device-team.c @@ -690,20 +690,16 @@ nm_device_team_new (NMPlatformLink *platform_device) NMDevice * nm_device_team_new_for_connection (NMConnection *connection, GError **error) { - const char *iface; - - g_return_val_if_fail (connection != NULL, NULL); + const char *iface = nm_connection_get_interface_name (connection); - iface = nm_connection_get_interface_name (connection); - g_return_val_if_fail (iface != NULL, NULL); + g_assert (iface); if ( !nm_platform_team_add (NM_PLATFORM_GET, iface) && nm_platform_get_error (NM_PLATFORM_GET) != NM_PLATFORM_ERROR_EXISTS) { - g_set_error (error, - NM_DEVICE_ERROR, - NM_DEVICE_ERROR_CREATION_FAILED, - "failed to create team master interface '%s' for connection '%s': %s", - iface, nm_connection_get_id (connection), + g_set_error (error, NM_DEVICE_ERROR, NM_DEVICE_ERROR_CREATION_FAILED, + "Failed to create team master interface '%s' for '%s': %s", + iface, + nm_connection_get_id (connection), nm_platform_get_error_msg (NM_PLATFORM_GET)); return NULL; } diff --git a/src/devices/team/nm-team-factory.c b/src/devices/team/nm-team-factory.c index 575b4a60e8..1d3e961778 100644 --- a/src/devices/team/nm-team-factory.c +++ b/src/devices/team/nm-team-factory.c @@ -61,9 +61,7 @@ create_virtual_device_for_connection (NMDeviceFactory *factory, NMDevice *parent, GError **error) { - if (nm_connection_is_type (connection, NM_SETTING_TEAM_SETTING_NAME)) - return nm_device_team_new_for_connection (connection, error); - return NULL; + return nm_device_team_new_for_connection (connection, error); } NM_DEVICE_FACTORY_DECLARE_TYPES ( diff --git a/src/nm-manager.c b/src/nm-manager.c index 93ec84a112..88efec5ec9 100644 --- a/src/nm-manager.c +++ b/src/nm-manager.c @@ -1034,7 +1034,6 @@ system_create_virtual_device (NMManager *self, NMConnection *connection, GError { NMManagerPrivate *priv = NM_MANAGER_GET_PRIVATE (self); NMDeviceFactory *factory; - GError *local_err = NULL; GSList *iter; char *iface = NULL; NMDevice *device = NULL, *parent = NULL; @@ -1095,9 +1094,8 @@ system_create_virtual_device (NMManager *self, NMConnection *connection, GError device = nm_device_factory_create_virtual_device_for_connection (factory, connection, parent, - &local_err); + error); if (device) { - g_assert_no_error (local_err); if (nm_owned) nm_device_set_nm_owned (device); @@ -1107,18 +1105,6 @@ system_create_virtual_device (NMManager *self, NMConnection *connection, GError add_device (self, device, !nm_owned); g_object_unref (device); - } else if (local_err) { - nm_log_err (LOGD_DEVICE, "(%s) failed to create virtual device: %s", - nm_connection_get_id (connection), local_err->message); - g_propagate_error (error, local_err); - } else { - nm_log_err (LOGD_DEVICE, "(%s) failed to create virtual device", - nm_connection_get_id (connection)); - g_set_error (error, - NM_MANAGER_ERROR, - NM_MANAGER_ERROR_FAILED, - "(%s) failed to create virtual device", - nm_connection_get_connection_type (connection)); } priv->ignore_link_added_cb--; |