summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDan Williams <dcbw@redhat.com>2014-09-08 10:15:02 -0500
committerDan Williams <dcbw@redhat.com>2014-09-11 12:50:16 -0500
commit1553b3e2230d55765cf345e2b00c366009091b4e (patch)
treed3c9089256f5aa7701a7b1634bb01c7d1471627a
parent097eb3a6af1f91324e75db04ac0422099fba1fc0 (diff)
bond: port to internal device factory
-rw-r--r--src/Makefile.am2
-rw-r--r--src/devices/nm-device-bond.c99
-rw-r--r--src/devices/nm-device-bond.h14
-rw-r--r--src/nm-manager.c8
-rw-r--r--src/tests/Makefile.am2
5 files changed, 63 insertions, 62 deletions
diff --git a/src/Makefile.am b/src/Makefile.am
index 3e0424de03..759d8765c4 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -63,6 +63,7 @@ NetworkManager_LDADD = libNetworkManager.la
noinst_LTLIBRARIES = libNetworkManager.la
nm_device_sources = \
+ devices/nm-device-bond.c \
devices/nm-device-bridge.c \
devices/nm-device-ethernet.c \
devices/nm-device-infiniband.c \
@@ -85,7 +86,6 @@ nm_sources = \
$(nm_device_headers) \
devices/nm-device.c \
devices/nm-device.h \
- devices/nm-device-bond.c \
devices/nm-device-ethernet-utils.c \
devices/nm-device-ethernet-utils.h \
devices/nm-device-factory.c \
diff --git a/src/devices/nm-device-bond.c b/src/devices/nm-device-bond.c
index d2a0712851..40151d4722 100644
--- a/src/devices/nm-device-bond.c
+++ b/src/devices/nm-device-bond.c
@@ -36,6 +36,7 @@
#include "nm-dbus-glib-types.h"
#include "nm-dbus-manager.h"
#include "nm-enum-types.h"
+#include "nm-device-factory.h"
#include "nm-device-bond-glue.h"
@@ -454,47 +455,6 @@ release_slave (NMDevice *device,
/******************************************************************/
-NMDevice *
-nm_device_bond_new (NMPlatformLink *platform_device)
-{
- g_return_val_if_fail (platform_device != NULL, NULL);
-
- return (NMDevice *) g_object_new (NM_TYPE_DEVICE_BOND,
- NM_DEVICE_PLATFORM_DEVICE, platform_device,
- NM_DEVICE_DRIVER, "bonding",
- NM_DEVICE_TYPE_DESC, "Bond",
- NM_DEVICE_DEVICE_TYPE, NM_DEVICE_TYPE_BOND,
- NM_DEVICE_IS_MASTER, TRUE,
- NULL);
-}
-
-NMDevice *
-nm_device_bond_new_for_connection (NMConnection *connection)
-{
- const char *iface;
-
- g_return_val_if_fail (connection != NULL, NULL);
-
- iface = nm_connection_get_interface_name (connection);
- g_return_val_if_fail (iface != NULL, NULL);
-
- if ( !nm_platform_bond_add (iface)
- && nm_platform_get_error () != 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 ());
- return NULL;
- }
-
- return (NMDevice *) g_object_new (NM_TYPE_DEVICE_BOND,
- NM_DEVICE_IFACE, iface,
- NM_DEVICE_DRIVER, "bonding",
- NM_DEVICE_TYPE_DESC, "Bond",
- NM_DEVICE_DEVICE_TYPE, NM_DEVICE_TYPE_BOND,
- NM_DEVICE_IS_MASTER, TRUE,
- NULL);
-}
-
static void
nm_device_bond_init (NMDeviceBond * self)
{
@@ -575,3 +535,60 @@ nm_device_bond_class_init (NMDeviceBondClass *klass)
dbus_g_error_domain_register (NM_BOND_ERROR, NULL, NM_TYPE_BOND_ERROR);
}
+
+/*************************************************************/
+
+#define NM_TYPE_BOND_FACTORY (nm_bond_factory_get_type ())
+#define NM_BOND_FACTORY(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), NM_TYPE_BOND_FACTORY, NMBondFactory))
+
+static NMDevice *
+new_link (NMDeviceFactory *factory, NMPlatformLink *plink, GError **error)
+{
+ if (plink->type == NM_LINK_TYPE_BOND) {
+ return (NMDevice *) g_object_new (NM_TYPE_DEVICE_BOND,
+ NM_DEVICE_PLATFORM_DEVICE, plink,
+ NM_DEVICE_DRIVER, "bonding",
+ NM_DEVICE_TYPE_DESC, "Bond",
+ NM_DEVICE_DEVICE_TYPE, NM_DEVICE_TYPE_BOND,
+ NM_DEVICE_IS_MASTER, TRUE,
+ NULL);
+ }
+ return NULL;
+}
+
+static NMDevice *
+create_virtual_device_for_connection (NMDeviceFactory *factory,
+ NMConnection *connection,
+ NMDevice *parent,
+ GError **error)
+{
+ const char *iface;
+
+ if (!nm_connection_is_type (connection, NM_SETTING_BOND_SETTING_NAME))
+ return NULL;
+
+ iface = nm_connection_get_interface_name (connection);
+ g_return_val_if_fail (iface != NULL, NULL);
+
+ if ( !nm_platform_bond_add (iface)
+ && nm_platform_get_error () != 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 ());
+ return NULL;
+ }
+
+ return (NMDevice *) g_object_new (NM_TYPE_DEVICE_BOND,
+ NM_DEVICE_IFACE, iface,
+ NM_DEVICE_DRIVER, "bonding",
+ NM_DEVICE_TYPE_DESC, "Bond",
+ NM_DEVICE_DEVICE_TYPE, NM_DEVICE_TYPE_BOND,
+ NM_DEVICE_IS_MASTER, TRUE,
+ NULL);
+}
+
+DEFINE_DEVICE_FACTORY_INTERNAL(BOND, Bond, bond,
+ 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-bond.h b/src/devices/nm-device-bond.h
index 216589387a..ed1c023434 100644
--- a/src/devices/nm-device-bond.h
+++ b/src/devices/nm-device-bond.h
@@ -42,21 +42,11 @@ typedef enum {
#define NM_DEVICE_BOND_SLAVES "slaves"
-typedef struct {
- NMDevice parent;
-} NMDeviceBond;
-
-typedef struct {
- NMDeviceClass parent;
-
-} NMDeviceBondClass;
-
+typedef NMDevice NMDeviceBond;
+typedef NMDeviceClass NMDeviceBondClass;
GType nm_device_bond_get_type (void);
-NMDevice *nm_device_bond_new (NMPlatformLink *platform_device);
-NMDevice *nm_device_bond_new_for_connection (NMConnection *connection);
-
G_END_DECLS
#endif /* NM_DEVICE_BOND_H */
diff --git a/src/nm-manager.c b/src/nm-manager.c
index c360062656..774abee390 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-bond.h"
#include "nm-device-vlan.h"
#include "nm-device-generic.h"
#include "nm-device-tun.h"
@@ -1049,9 +1048,7 @@ system_create_virtual_device (NMManager *self, NMConnection *connection)
nm_owned = !nm_platform_link_exists (iface);
- if (nm_connection_is_type (connection, NM_SETTING_BOND_SETTING_NAME)) {
- device = nm_device_bond_new_for_connection (connection);
- } else if (nm_connection_is_type (connection, NM_SETTING_VLAN_SETTING_NAME)) {
+ if (nm_connection_is_type (connection, NM_SETTING_VLAN_SETTING_NAME)) {
device = nm_device_vlan_new_for_connection (connection, parent);
} else {
for (iter = priv->factories; iter; iter = iter->next) {
@@ -2120,9 +2117,6 @@ platform_link_added (NMManager *self,
NMDevice *parent;
switch (plink->type) {
- case NM_LINK_TYPE_BOND:
- device = nm_device_bond_new (plink);
- break;
case NM_LINK_TYPE_VLAN:
/* Have to find the parent device */
if (nm_platform_vlan_get_info (ifindex, &parent_ifindex, NULL)) {
diff --git a/src/tests/Makefile.am b/src/tests/Makefile.am
index 635829db15..5761aeb505 100644
--- a/src/tests/Makefile.am
+++ b/src/tests/Makefile.am
@@ -99,7 +99,7 @@ TESTS = \
if ENABLE_TESTS
check-local:
- @for t in bridge ethernet infiniband veth; do \
+ @for t in bond bridge 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 \