core: allow creation of virtual devices (software devices) via NMDeviceFactory

Signed-off-by: Thomas Haller <thaller@redhat.com>
This commit is contained in:
Thomas Haller 2014-06-19 08:42:35 +02:00
parent 4c206d0aaf
commit dfe4b45f87
3 changed files with 55 additions and 0 deletions

View file

@ -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;
}

View file

@ -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);

View file

@ -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) {