summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDan Williams <dcbw@redhat.com>2014-09-05 16:07:43 -0500
committerDan Williams <dcbw@redhat.com>2014-09-11 12:50:16 -0500
commit6d190f92d5c040a9d05e61c8c006246bad1c132f (patch)
tree3a875d3688ed97a816364a09392658630034346e
parent2a55c450bdfdf92ee76002443fc919bf28aabbc9 (diff)
downloadNetworkManager-6d190f92d5c040a9d05e61c8c006246bad1c132f.tar.gz
infiniband: port to internal device factory
-rw-r--r--src/Makefile.am2
-rw-r--r--src/devices/nm-device-infiniband.c111
-rw-r--r--src/devices/nm-device-infiniband.h15
-rw-r--r--src/nm-manager.c6
-rw-r--r--src/tests/Makefile.am2
5 files changed, 68 insertions, 68 deletions
diff --git a/src/Makefile.am b/src/Makefile.am
index c2880b5cae..8477d3caae 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -64,6 +64,7 @@ noinst_LTLIBRARIES = libNetworkManager.la
nm_device_sources = \
devices/nm-device-ethernet.c \
+ devices/nm-device-infiniband.c \
devices/nm-device-veth.c \
$(NULL)
@@ -92,7 +93,6 @@ nm_sources = \
devices/nm-device-generic.c \
devices/nm-device-generic.h \
devices/nm-device-gre.c \
- devices/nm-device-infiniband.c \
devices/nm-device-logging.h \
devices/nm-device-macvlan.c \
devices/nm-device-private.h \
diff --git a/src/devices/nm-device-infiniband.c b/src/devices/nm-device-infiniband.c
index bbb12dff92..8101c3e12c 100644
--- a/src/devices/nm-device-infiniband.c
+++ b/src/devices/nm-device-infiniband.c
@@ -35,6 +35,7 @@
#include "nm-activation-request.h"
#include "nm-ip4-config.h"
#include "nm-platform.h"
+#include "nm-device-factory.h"
#include "nm-device-infiniband-glue.h"
@@ -69,53 +70,6 @@ nm_device_infiniband_init (NMDeviceInfiniband * self)
{
}
-NMDevice *
-nm_device_infiniband_new (NMPlatformLink *platform_device)
-{
- g_return_val_if_fail (platform_device != NULL, NULL);
-
- return (NMDevice *) g_object_new (NM_TYPE_DEVICE_INFINIBAND,
- NM_DEVICE_PLATFORM_DEVICE, platform_device,
- NM_DEVICE_TYPE_DESC, "InfiniBand",
- NM_DEVICE_DEVICE_TYPE, NM_DEVICE_TYPE_INFINIBAND,
- NULL);
-}
-
-NMDevice *
-nm_device_infiniband_new_partition (NMConnection *connection,
- NMDevice *parent)
-{
- NMSettingInfiniband *s_infiniband;
- int p_key, parent_ifindex;
- const char *iface;
-
- g_return_val_if_fail (connection != NULL, 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);
-
- parent_ifindex = nm_device_get_ifindex (parent);
- p_key = nm_setting_infiniband_get_p_key (s_infiniband);
-
- if ( !nm_platform_infiniband_partition_add (parent_ifindex, p_key)
- && nm_platform_get_error () != 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),
- nm_platform_get_error_msg ());
- return NULL;
- }
-
- return (NMDevice *) g_object_new (NM_TYPE_DEVICE_INFINIBAND,
- NM_DEVICE_IFACE, iface,
- NM_DEVICE_DRIVER, nm_device_get_driver (parent),
- NM_DEVICE_TYPE_DESC, "InfiniBand",
- NM_DEVICE_DEVICE_TYPE, NM_DEVICE_TYPE_INFINIBAND,
- NULL);
-}
-
static guint32
get_generic_capabilities (NMDevice *dev)
{
@@ -344,3 +298,66 @@ nm_device_infiniband_class_init (NMDeviceInfinibandClass *klass)
dbus_g_error_domain_register (NM_INFINIBAND_ERROR, NULL, NM_TYPE_INFINIBAND_ERROR);
}
+
+/*************************************************************/
+
+#define NM_TYPE_INFINIBAND_FACTORY (nm_infiniband_factory_get_type ())
+#define NM_INFINIBAND_FACTORY(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), NM_TYPE_INFINIBAND_FACTORY, NMInfinibandFactory))
+
+static NMDevice *
+new_link (NMDeviceFactory *factory, NMPlatformLink *plink, GError **error)
+{
+ if (plink->type == NM_LINK_TYPE_INFINIBAND) {
+ return (NMDevice *) g_object_new (NM_TYPE_DEVICE_INFINIBAND,
+ NM_DEVICE_PLATFORM_DEVICE, plink,
+ NM_DEVICE_TYPE_DESC, "InfiniBand",
+ NM_DEVICE_DEVICE_TYPE, NM_DEVICE_TYPE_INFINIBAND,
+ NULL);
+ }
+ return NULL;
+}
+
+static NMDevice *
+create_virtual_device_for_connection (NMDeviceFactory *factory,
+ NMConnection *connection,
+ NMDevice *parent,
+ GError **error)
+{
+ NMSettingInfiniband *s_infiniband;
+ int p_key, parent_ifindex;
+ const char *iface;
+
+ if (!nm_connection_is_type (connection, NM_SETTING_INFINIBAND_SETTING_NAME))
+ 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);
+
+ parent_ifindex = nm_device_get_ifindex (parent);
+ p_key = nm_setting_infiniband_get_p_key (s_infiniband);
+
+ if ( !nm_platform_infiniband_partition_add (parent_ifindex, p_key)
+ && nm_platform_get_error () != 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),
+ nm_platform_get_error_msg ());
+ return NULL;
+ }
+
+ return (NMDevice *) g_object_new (NM_TYPE_DEVICE_INFINIBAND,
+ NM_DEVICE_IFACE, iface,
+ NM_DEVICE_DRIVER, nm_device_get_driver (parent),
+ NM_DEVICE_TYPE_DESC, "InfiniBand",
+ NM_DEVICE_DEVICE_TYPE, NM_DEVICE_TYPE_INFINIBAND,
+ NULL);
+}
+
+DEFINE_DEVICE_FACTORY_INTERNAL(INFINIBAND, Infiniband, infiniband, \
+ factory_iface->new_link = new_link; \
+ factory_iface->create_virtual_device_for_connection = create_virtual_device_for_connection;
+ )
+
diff --git a/src/devices/nm-device-infiniband.h b/src/devices/nm-device-infiniband.h
index 032fbddf7b..e9b5be92ba 100644
--- a/src/devices/nm-device-infiniband.h
+++ b/src/devices/nm-device-infiniband.h
@@ -40,22 +40,11 @@ typedef enum {
NM_INFINIBAND_ERROR_CONNECTION_INCOMPATIBLE, /*< nick=ConnectionIncompatible >*/
} NMInfinibandError;
-typedef struct {
- NMDevice parent;
-} NMDeviceInfiniband;
-
-typedef struct {
- NMDeviceClass parent;
-
-} NMDeviceInfinibandClass;
-
+typedef NMDevice NMDeviceInfiniband;
+typedef NMDeviceClass NMDeviceInfinibandClass;
GType nm_device_infiniband_get_type (void);
-NMDevice *nm_device_infiniband_new (NMPlatformLink *platform_device);
-NMDevice *nm_device_infiniband_new_partition (NMConnection *connection,
- NMDevice *parent);
-
G_END_DECLS
#endif /* NM_DEVICE_INFINIBAND_H */
diff --git a/src/nm-manager.c b/src/nm-manager.c
index 1e278f0dfa..4fa996d0d8 100644
--- a/src/nm-manager.c
+++ b/src/nm-manager.c
@@ -39,7 +39,6 @@
#include "nm-dbus-manager.h"
#include "nm-vpn-manager.h"
#include "nm-device.h"
-#include "nm-device-infiniband.h"
#include "nm-device-bond.h"
#include "nm-device-bridge.h"
#include "nm-device-vlan.h"
@@ -1057,8 +1056,6 @@ system_create_virtual_device (NMManager *self, NMConnection *connection)
device = nm_device_bridge_new_for_connection (connection);
} else if (nm_connection_is_type (connection, NM_SETTING_VLAN_SETTING_NAME)) {
device = nm_device_vlan_new_for_connection (connection, parent);
- } else if (nm_connection_is_type (connection, NM_SETTING_INFINIBAND_SETTING_NAME)) {
- device = nm_device_infiniband_new_partition (connection, parent);
} else {
for (iter = priv->factories; iter; iter = iter->next) {
device = nm_device_factory_create_virtual_device_for_connection (NM_DEVICE_FACTORY (iter->data),
@@ -2126,9 +2123,6 @@ platform_link_added (NMManager *self,
NMDevice *parent;
switch (plink->type) {
- case NM_LINK_TYPE_INFINIBAND:
- device = nm_device_infiniband_new (plink);
- break;
case NM_LINK_TYPE_BOND:
device = nm_device_bond_new (plink);
break;
diff --git a/src/tests/Makefile.am b/src/tests/Makefile.am
index 70797b6229..9dbc44eec2 100644
--- a/src/tests/Makefile.am
+++ b/src/tests/Makefile.am
@@ -99,7 +99,7 @@ TESTS = \
if ENABLE_TESTS
check-local:
- @for t in ethernet veth; do \
+ @for t in ethernet infiniband veth; do \
# Ensure the device subclass factory registration constructors exist \
# which could inadvertently break if src/Makefile.am gets changed \
if ! LC_ALL=C nm $(top_builddir)/src/NetworkManager | LC_ALL=C grep -q "register_device_factory_internal_$$t" ; then \