Commit 33d0cff3 authored by Dan Williams's avatar Dan Williams

core: use active connection dependency master instead of manually setting it

We already have the master device kept in the active connection, so
we can just use that instead of having the Policy determine and set
it manually.  This also should allow slaves to auto-activate their
master connections if the master is able to activate.
parent 9146d4e8
......@@ -37,7 +37,7 @@
<property name="Vpn" type="b" access="read">
<tp:docstring>Whether this active connection is also a VPN connection.</tp:docstring>
</property>
<property name="Master" type="s" access="read">
<property name="Master" type="o" access="read">
<tp:docstring>The path to the master device if the connection is a slave.</tp:docstring>
</property>
......
......@@ -504,10 +504,16 @@ get_property (GObject *object, guint prop_id,
GValue *value, GParamSpec *pspec)
{
NMActRequestPrivate *priv = NM_ACT_REQUEST_GET_PRIVATE (object);
NMDevice *master;
switch (prop_id) {
case PROP_MASTER:
g_value_set_string (value, nm_device_get_master_path (priv->device));
if (priv->dep && NM_IS_ACT_REQUEST (priv->dep)) {
master = NM_DEVICE (nm_act_request_get_device (NM_ACT_REQUEST (priv->dep)));
g_assert (master);
g_value_set_boxed (value, nm_device_get_path (master));
} else
g_value_set_boxed (value, "/");
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
......
......@@ -353,11 +353,11 @@ nm_active_connection_class_init (NMActiveConnectionClass *vpn_class)
G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
g_object_class_install_property (object_class, PROP_MASTER,
g_param_spec_string (NM_ACTIVE_CONNECTION_MASTER,
"Master",
"Path of master device",
NULL,
G_PARAM_READABLE));
g_param_spec_boxed (NM_ACTIVE_CONNECTION_MASTER,
"Master",
"Path of master device",
DBUS_TYPE_G_OBJECT_PATH,
G_PARAM_READABLE));
/* Signals */
signals[PROPERTIES_CHANGED] =
......
......@@ -585,38 +585,6 @@ nm_device_get_type_desc (NMDevice *self)
return NM_DEVICE_GET_PRIVATE (self)->type_desc;
}
NMDevice *
nm_device_get_master (NMDevice *self)
{
g_return_val_if_fail (self != NULL, NULL);
return NM_DEVICE_GET_PRIVATE (self)->master;
}
const char *
nm_device_get_master_path (NMDevice *self)
{
g_return_val_if_fail (self != NULL, NULL);
if (NM_DEVICE_GET_PRIVATE (self)->master)
return nm_device_get_path (NM_DEVICE_GET_PRIVATE (self)->master);
return NULL;
}
void
nm_device_set_master (NMDevice *self, NMDevice *master)
{
NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE(self);
if (priv->master)
g_object_unref (priv->master);
priv->master = master ? g_object_ref (master) : NULL;
if (priv->act_request)
g_object_notify (G_OBJECT (priv->act_request), NM_ACTIVE_CONNECTION_MASTER);
}
/**
* nm_device_enslave_slave:
* @dev: the master device
......@@ -3736,9 +3704,6 @@ finalize (GObject *object)
if (priv->dhcp_anycast_address)
g_byte_array_free (priv->dhcp_anycast_address, TRUE);
/* release master reference it still exists */
nm_device_set_master (self, NULL);
G_OBJECT_CLASS (nm_device_parent_class)->finalize (object);
}
......
......@@ -191,10 +191,6 @@ NMDHCP6Config * nm_device_get_dhcp6_config (NMDevice *dev);
NMIP4Config * nm_device_get_ip4_config (NMDevice *dev);
NMIP6Config * nm_device_get_ip6_config (NMDevice *dev);
NMDevice * nm_device_get_master (NMDevice *self);
const char *nm_device_get_master_path (NMDevice *self);
void nm_device_set_master (NMDevice *self, NMDevice *master);
gboolean nm_device_enslave_slave (NMDevice *dev, NMDevice *slave);
gboolean nm_device_release_slave (NMDevice *dev, NMDevice *slave);
......
......@@ -728,39 +728,6 @@ activate_data_free (ActivateData *data)
g_free (data);
}
static gboolean
check_master_dependency (NMManager *manager, NMDevice *device, NMConnection *connection)
{
NMSettingConnection *s_con;
NMDevice *master_device;
const char *master;
NMActRequest *req;
s_con = nm_connection_get_setting_connection (connection);
g_assert (s_con);
master = nm_setting_connection_get_master (s_con);
/* no master defined, proceed with activation */
if (!master)
return TRUE;
master_device = nm_manager_get_device_by_master (manager, master, NULL);
/* If master device is not yet present, postpone activation until later */
if (!master_device)
return FALSE;
/* Make all slaves wait for the master connection to activate. */
req = nm_device_get_act_request (master_device);
if (!req || !nm_act_request_get_connection (req))
return FALSE;
nm_device_set_master (device, master_device);
return TRUE;
}
static gboolean
auto_activate_device (gpointer user_data)
{
......@@ -817,12 +784,6 @@ auto_activate_device (gpointer user_data)
if (best_connection) {
GError *error = NULL;
if (!check_master_dependency (data->policy->manager, data->device, best_connection)) {
nm_log_info (LOGD_DEVICE, "Connection '%s' auto-activation postponed: master not available",
nm_connection_get_id (best_connection));
goto postpone;
}
nm_log_info (LOGD_DEVICE, "Auto-activating connection '%s'.",
nm_connection_get_id (best_connection));
if (!nm_manager_activate_connection (policy->manager,
......@@ -839,7 +800,6 @@ auto_activate_device (gpointer user_data)
}
}
postpone:
g_slist_free (connections);
out:
......
......@@ -107,6 +107,7 @@ enum {
PROP_0,
PROP_VPN_STATE,
PROP_BANNER,
PROP_MASTER = 2000,
LAST_PROP
};
......@@ -1170,6 +1171,9 @@ get_property (GObject *object, guint prop_id,
case PROP_BANNER:
g_value_set_string (value, priv->banner ? priv->banner : "");
break;
case PROP_MASTER:
g_value_set_boxed (value, nm_device_get_path (priv->parent_dev));
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
......@@ -1189,6 +1193,8 @@ nm_vpn_connection_class_init (NMVPNConnectionClass *connection_class)
object_class->dispose = dispose;
object_class->finalize = finalize;
g_object_class_override_property (object_class, PROP_MASTER, NM_ACTIVE_CONNECTION_MASTER);
/* properties */
g_object_class_install_property (object_class, PROP_VPN_STATE,
g_param_spec_uint (NM_VPN_CONNECTION_VPN_STATE,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment