summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Haller <thaller@redhat.com>2014-06-19 08:42:35 +0200
committerThomas Haller <thaller@redhat.com>2014-06-27 13:27:01 +0200
commitdfe4b45f87a9302c55542848b102f07a6ddf50f3 (patch)
treeac2b172865d6023b28b92d7e82f148693711115e
parent4c206d0aaf094b16184e58a0b69f236896bc4eb9 (diff)
core: allow creation of virtual devices (software devices) via NMDeviceFactory
Signed-off-by: Thomas Haller <thaller@redhat.com>
-rw-r--r--src/devices/nm-device-factory.c17
-rw-r--r--src/devices/nm-device-factory.h22
-rw-r--r--src/nm-manager.c16
3 files changed, 55 insertions, 0 deletions
diff --git a/src/devices/nm-device-factory.c b/src/devices/nm-device-factory.c
index fc4d1c248a..5e84531135 100644
--- a/src/devices/nm-device-factory.c
+++ b/src/devices/nm-device-factory.c
@@ -104,3 +104,20 @@ nm_device_factory_new_link (NMDeviceFactory *factory,
return NULL;
}
+NMDevice *
+nm_device_factory_create_virtual_device_for_connection (NMDeviceFactory *factory,
+ NMConnection *connection,
+ GError **error)
+{
+ NMDeviceFactory *interface;
+
+ g_return_val_if_fail (factory, NULL);
+ g_return_val_if_fail (connection, NULL);
+ g_return_val_if_fail (!error || !*error, NULL);
+
+ interface = NM_DEVICE_FACTORY_GET_INTERFACE (factory);
+ if (interface->create_virtual_device_for_connection)
+ return interface->create_virtual_device_for_connection (factory, connection, error);
+ return NULL;
+}
+
diff --git a/src/devices/nm-device-factory.h b/src/devices/nm-device-factory.h
index f0e3dc1978..ef412c96d2 100644
--- a/src/devices/nm-device-factory.h
+++ b/src/devices/nm-device-factory.h
@@ -95,6 +95,24 @@ struct _NMDeviceFactory {
NMPlatformLink *plink,
GError **error);
+ /**
+ * create_virtual_device_for_connection:
+ * @factory: the #NMDeviceFactory
+ * @connection: the #NMConnection
+ * @error: a @GError in case of failure
+ *
+ * Virtual device types (such as team, bond, bridge) may need to be created.
+ * This function tries to create a device based on the given @connection.
+ *
+ * Returns: the newly created #NMDevice. If the factory does not support the
+ * connection type, it should return %NULL and leave @error unset. On error
+ * it should set @error and return %NULL.
+ */
+ NMDevice * (*create_virtual_device_for_connection) (NMDeviceFactory *factory,
+ NMConnection *connection,
+ GError **error);
+
+
/* Signals */
/**
@@ -128,6 +146,10 @@ NMDevice * nm_device_factory_new_link (NMDeviceFactory *factory,
NMPlatformLink *plink,
GError **error);
+NMDevice * nm_device_factory_create_virtual_device_for_connection (NMDeviceFactory *factory,
+ NMConnection *connection,
+ GError **error);
+
/* For use by implementations */
gboolean nm_device_factory_emit_component_added (NMDeviceFactory *factory,
GObject *component);
diff --git a/src/nm-manager.c b/src/nm-manager.c
index 052ccb7834..6c6176e6c1 100644
--- a/src/nm-manager.c
+++ b/src/nm-manager.c
@@ -1074,6 +1074,7 @@ static NMDevice *
system_create_virtual_device (NMManager *self, NMConnection *connection)
{
NMManagerPrivate *priv = NM_MANAGER_GET_PRIVATE (self);
+ GError *error = NULL;
GSList *iter;
char *iface = NULL;
NMDevice *device = NULL, *parent = NULL;
@@ -1110,6 +1111,21 @@ system_create_virtual_device (NMManager *self, NMConnection *connection)
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), connection, &error);
+
+ if (device || error) {
+ if (device)
+ g_assert_no_error (error);
+ else {
+ nm_log_err (LOGD_DEVICE, "(%s) failed to create virtual device: %s",
+ nm_connection_get_id (connection), error ? error->message : "(unknown error)");
+ g_clear_error (&error);
+ }
+ break;
+ }
+ }
}
if (device) {