mirror of
https://gitlab.freedesktop.org/NetworkManager/NetworkManager.git
synced 2026-01-07 05:30:17 +01:00
device: implement slave property in parent device class
Instead of reimplementing the slave property in bond, bridge and team, just add the property to the parent class. It's not that the parent class would be agnostic to the master/slave implementation, all the slaves are known to the every device type implementation. Also, the derived class doesn't know the correct time when to invoke the notify-changed for the slaves property. E.g. it should be only invoked after nm_device_slave_notify_enslave() when other components also consider the slave as enslaved. Later this will be fixed so that the SLAVES property correspond to what other master/slave related properties say.
This commit is contained in:
parent
f9404d36fd
commit
9a8d9a0d85
8 changed files with 38 additions and 161 deletions
|
|
@ -46,13 +46,6 @@ typedef struct {
|
|||
int dummy;
|
||||
} NMDeviceBondPrivate;
|
||||
|
||||
enum {
|
||||
PROP_0,
|
||||
PROP_SLAVES,
|
||||
|
||||
LAST_PROP
|
||||
};
|
||||
|
||||
/******************************************************************/
|
||||
|
||||
static NMDeviceCapabilities
|
||||
|
|
@ -415,7 +408,7 @@ enslave_slave (NMDevice *device,
|
|||
} else
|
||||
_LOGI (LOGD_BOND, "bond slave %s was enslaved", slave_iface);
|
||||
|
||||
g_object_notify (G_OBJECT (device), NM_DEVICE_BOND_SLAVES);
|
||||
g_object_notify (G_OBJECT (device), NM_DEVICE_SLAVES);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
|
|
@ -444,7 +437,7 @@ release_slave (NMDevice *device,
|
|||
nm_device_get_ip_iface (slave));
|
||||
}
|
||||
|
||||
g_object_notify (G_OBJECT (device), NM_DEVICE_BOND_SLAVES);
|
||||
g_object_notify (G_OBJECT (device), NM_DEVICE_SLAVES);
|
||||
|
||||
if (configure) {
|
||||
/* Kernel bonding code "closes" the slave when releasing it, (which clears
|
||||
|
|
@ -488,36 +481,6 @@ nm_device_bond_init (NMDeviceBond * self)
|
|||
{
|
||||
}
|
||||
|
||||
static void
|
||||
get_property (GObject *object, guint prop_id,
|
||||
GValue *value, GParamSpec *pspec)
|
||||
{
|
||||
GSList *list;
|
||||
|
||||
switch (prop_id) {
|
||||
break;
|
||||
case PROP_SLAVES:
|
||||
list = nm_device_master_get_slaves (NM_DEVICE (object));
|
||||
nm_utils_g_value_set_object_path_array (value, list, NULL, NULL);
|
||||
g_slist_free (list);
|
||||
break;
|
||||
default:
|
||||
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
set_property (GObject *object, guint prop_id,
|
||||
const GValue *value, GParamSpec *pspec)
|
||||
{
|
||||
switch (prop_id) {
|
||||
default:
|
||||
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
nm_device_bond_class_init (NMDeviceBondClass *klass)
|
||||
{
|
||||
|
|
@ -528,10 +491,6 @@ nm_device_bond_class_init (NMDeviceBondClass *klass)
|
|||
|
||||
NM_DEVICE_CLASS_DECLARE_TYPES (klass, NM_SETTING_BOND_SETTING_NAME, NM_LINK_TYPE_BOND)
|
||||
|
||||
/* virtual methods */
|
||||
object_class->get_property = get_property;
|
||||
object_class->set_property = set_property;
|
||||
|
||||
parent_class->get_generic_capabilities = get_generic_capabilities;
|
||||
parent_class->is_available = is_available;
|
||||
parent_class->check_connection_compatible = check_connection_compatible;
|
||||
|
|
@ -547,14 +506,6 @@ nm_device_bond_class_init (NMDeviceBondClass *klass)
|
|||
parent_class->enslave_slave = enslave_slave;
|
||||
parent_class->release_slave = release_slave;
|
||||
|
||||
/* properties */
|
||||
g_object_class_install_property
|
||||
(object_class, PROP_SLAVES,
|
||||
g_param_spec_boxed (NM_DEVICE_BOND_SLAVES, "", "",
|
||||
G_TYPE_STRV,
|
||||
G_PARAM_READABLE |
|
||||
G_PARAM_STATIC_STRINGS));
|
||||
|
||||
nm_exported_object_class_add_interface (NM_EXPORTED_OBJECT_CLASS (klass),
|
||||
NMDBUS_TYPE_DEVICE_BOND_SKELETON,
|
||||
NULL);
|
||||
|
|
|
|||
|
|
@ -32,8 +32,6 @@ G_BEGIN_DECLS
|
|||
#define NM_IS_DEVICE_BOND_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), NM_TYPE_DEVICE_BOND))
|
||||
#define NM_DEVICE_BOND_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), NM_TYPE_DEVICE_BOND, NMDeviceBondClass))
|
||||
|
||||
#define NM_DEVICE_BOND_SLAVES "slaves"
|
||||
|
||||
typedef NMDevice NMDeviceBond;
|
||||
typedef NMDeviceClass NMDeviceBondClass;
|
||||
|
||||
|
|
|
|||
|
|
@ -44,13 +44,6 @@ typedef struct {
|
|||
int dummy;
|
||||
} NMDeviceBridgePrivate;
|
||||
|
||||
enum {
|
||||
PROP_0,
|
||||
PROP_SLAVES,
|
||||
|
||||
LAST_PROP
|
||||
};
|
||||
|
||||
/******************************************************************/
|
||||
|
||||
static NMDeviceCapabilities
|
||||
|
|
@ -351,7 +344,7 @@ enslave_slave (NMDevice *device,
|
|||
nm_device_get_ip_iface (slave));
|
||||
}
|
||||
|
||||
g_object_notify (G_OBJECT (device), NM_DEVICE_BRIDGE_SLAVES);
|
||||
g_object_notify (G_OBJECT (device), NM_DEVICE_SLAVES);
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
|
@ -381,7 +374,7 @@ release_slave (NMDevice *device,
|
|||
nm_device_get_ip_iface (slave));
|
||||
}
|
||||
|
||||
g_object_notify (G_OBJECT (device), NM_DEVICE_BRIDGE_SLAVES);
|
||||
g_object_notify (G_OBJECT (device), NM_DEVICE_SLAVES);
|
||||
}
|
||||
|
||||
static gboolean
|
||||
|
|
@ -436,36 +429,6 @@ nm_device_bridge_init (NMDeviceBridge * self)
|
|||
{
|
||||
}
|
||||
|
||||
static void
|
||||
get_property (GObject *object, guint prop_id,
|
||||
GValue *value, GParamSpec *pspec)
|
||||
{
|
||||
GSList *list;
|
||||
|
||||
switch (prop_id) {
|
||||
break;
|
||||
case PROP_SLAVES:
|
||||
list = nm_device_master_get_slaves (NM_DEVICE (object));
|
||||
nm_utils_g_value_set_object_path_array (value, list, NULL, NULL);
|
||||
g_slist_free (list);
|
||||
break;
|
||||
default:
|
||||
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
set_property (GObject *object, guint prop_id,
|
||||
const GValue *value, GParamSpec *pspec)
|
||||
{
|
||||
switch (prop_id) {
|
||||
default:
|
||||
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
nm_device_bridge_class_init (NMDeviceBridgeClass *klass)
|
||||
{
|
||||
|
|
@ -476,10 +439,6 @@ nm_device_bridge_class_init (NMDeviceBridgeClass *klass)
|
|||
|
||||
NM_DEVICE_CLASS_DECLARE_TYPES (klass, NM_SETTING_BRIDGE_SETTING_NAME, NM_LINK_TYPE_BRIDGE)
|
||||
|
||||
/* virtual methods */
|
||||
object_class->get_property = get_property;
|
||||
object_class->set_property = set_property;
|
||||
|
||||
parent_class->get_generic_capabilities = get_generic_capabilities;
|
||||
parent_class->is_available = is_available;
|
||||
parent_class->check_connection_compatible = check_connection_compatible;
|
||||
|
|
@ -494,14 +453,6 @@ nm_device_bridge_class_init (NMDeviceBridgeClass *klass)
|
|||
parent_class->enslave_slave = enslave_slave;
|
||||
parent_class->release_slave = release_slave;
|
||||
|
||||
/* properties */
|
||||
g_object_class_install_property
|
||||
(object_class, PROP_SLAVES,
|
||||
g_param_spec_boxed (NM_DEVICE_BRIDGE_SLAVES, "", "",
|
||||
G_TYPE_STRV,
|
||||
G_PARAM_READABLE |
|
||||
G_PARAM_STATIC_STRINGS));
|
||||
|
||||
nm_exported_object_class_add_interface (NM_EXPORTED_OBJECT_CLASS (klass),
|
||||
NMDBUS_TYPE_DEVICE_BRIDGE_SKELETON,
|
||||
NULL);
|
||||
|
|
|
|||
|
|
@ -33,8 +33,6 @@ G_BEGIN_DECLS
|
|||
#define NM_IS_DEVICE_BRIDGE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), NM_TYPE_DEVICE_BRIDGE))
|
||||
#define NM_DEVICE_BRIDGE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), NM_TYPE_DEVICE_BRIDGE, NMDeviceBridgeClass))
|
||||
|
||||
#define NM_DEVICE_BRIDGE_SLAVES "slaves"
|
||||
|
||||
typedef NMDevice NMDeviceBridge;
|
||||
typedef NMDeviceClass NMDeviceBridgeClass;
|
||||
|
||||
|
|
|
|||
|
|
@ -130,6 +130,7 @@ enum {
|
|||
PROP_METERED,
|
||||
PROP_LLDP_NEIGHBORS,
|
||||
PROP_REAL,
|
||||
PROP_SLAVES,
|
||||
LAST_PROP
|
||||
};
|
||||
|
||||
|
|
@ -2187,7 +2188,7 @@ nm_device_master_add_slave (NMDevice *self, NMDevice *slave, gboolean configure)
|
|||
*
|
||||
* Returns: any slaves of which @self is the master. Caller owns returned list.
|
||||
*/
|
||||
GSList *
|
||||
static GSList *
|
||||
nm_device_master_get_slaves (NMDevice *self)
|
||||
{
|
||||
NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE (self);
|
||||
|
|
@ -10399,6 +10400,24 @@ get_property (GObject *object, guint prop_id,
|
|||
case PROP_REAL:
|
||||
g_value_set_boolean (value, priv->real);
|
||||
break;
|
||||
case PROP_SLAVES: {
|
||||
GSList *slave_iter;
|
||||
char **slave_list;
|
||||
guint i;
|
||||
|
||||
slave_list = g_new (char *, g_slist_length (priv->slaves) + 1);
|
||||
for (slave_iter = priv->slaves, i = 0; slave_iter; slave_iter = slave_iter->next) {
|
||||
SlaveInfo *info = slave_iter->data;
|
||||
const char *path;
|
||||
|
||||
path = nm_exported_object_get_path ((NMExportedObject *) info->slave);
|
||||
if (path)
|
||||
slave_list[i++] = g_strdup (path);
|
||||
}
|
||||
slave_list[i] = NULL;
|
||||
g_value_take_boxed (value, slave_list);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
||||
break;
|
||||
|
|
@ -10698,6 +10717,13 @@ nm_device_class_init (NMDeviceClass *klass)
|
|||
G_PARAM_READABLE |
|
||||
G_PARAM_STATIC_STRINGS));
|
||||
|
||||
g_object_class_install_property
|
||||
(object_class, PROP_SLAVES,
|
||||
g_param_spec_boxed (NM_DEVICE_SLAVES, "", "",
|
||||
G_TYPE_STRV,
|
||||
G_PARAM_READABLE |
|
||||
G_PARAM_STATIC_STRINGS));
|
||||
|
||||
/* Signals */
|
||||
signals[STATE_CHANGED] =
|
||||
g_signal_new ("state-changed",
|
||||
|
|
|
|||
|
|
@ -61,6 +61,11 @@
|
|||
#define NM_DEVICE_LLDP_NEIGHBORS "lldp-neighbors"
|
||||
#define NM_DEVICE_REAL "real"
|
||||
|
||||
/* the "slaves" property is internal in the parent class, but exposed
|
||||
* by the derived classes NMDeviceBond, NMDeviceBridge and NMDeviceTeam.
|
||||
* It is thus important that the property name matches. */
|
||||
#define NM_DEVICE_SLAVES "slaves" /* partially internal */
|
||||
|
||||
#define NM_DEVICE_TYPE_DESC "type-desc" /* Internal only */
|
||||
#define NM_DEVICE_RFKILL_TYPE "rfkill-type" /* Internal only */
|
||||
#define NM_DEVICE_IFINDEX "ifindex" /* Internal only */
|
||||
|
|
@ -387,7 +392,6 @@ void nm_device_replace_vpn6_config (NMDevice *dev,
|
|||
void nm_device_capture_initial_config (NMDevice *dev);
|
||||
|
||||
/* Master */
|
||||
GSList * nm_device_master_get_slaves (NMDevice *dev);
|
||||
gboolean nm_device_is_master (NMDevice *dev);
|
||||
|
||||
/* Slave */
|
||||
|
|
|
|||
|
|
@ -54,13 +54,6 @@ typedef struct {
|
|||
guint teamd_dbus_watch;
|
||||
} NMDeviceTeamPrivate;
|
||||
|
||||
enum {
|
||||
PROP_0,
|
||||
PROP_SLAVES,
|
||||
|
||||
LAST_PROP
|
||||
};
|
||||
|
||||
static gboolean teamd_start (NMDevice *device, NMSettingTeam *s_team);
|
||||
|
||||
/******************************************************************/
|
||||
|
|
@ -644,7 +637,7 @@ enslave_slave (NMDevice *device,
|
|||
} else
|
||||
_LOGI (LOGD_TEAM, "team port %s was enslaved", slave_iface);
|
||||
|
||||
g_object_notify (G_OBJECT (device), NM_DEVICE_TEAM_SLAVES);
|
||||
g_object_notify (G_OBJECT (device), NM_DEVICE_SLAVES);
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
|
@ -669,7 +662,7 @@ release_slave (NMDevice *device,
|
|||
} else
|
||||
_LOGI (LOGD_TEAM, "team port %s was released", nm_device_get_ip_iface (slave));
|
||||
|
||||
g_object_notify (G_OBJECT (device), NM_DEVICE_TEAM_SLAVES);
|
||||
g_object_notify (G_OBJECT (device), NM_DEVICE_SLAVES);
|
||||
|
||||
if (configure) {
|
||||
/* Kernel team code "closes" the port when releasing it, (which clears
|
||||
|
|
@ -745,36 +738,6 @@ constructed (GObject *object)
|
|||
g_free (tmp_str);
|
||||
}
|
||||
|
||||
static void
|
||||
get_property (GObject *object, guint prop_id,
|
||||
GValue *value, GParamSpec *pspec)
|
||||
{
|
||||
GSList *list;
|
||||
|
||||
switch (prop_id) {
|
||||
break;
|
||||
case PROP_SLAVES:
|
||||
list = nm_device_master_get_slaves (NM_DEVICE (object));
|
||||
nm_utils_g_value_set_object_path_array (value, list, NULL, NULL);
|
||||
g_slist_free (list);
|
||||
break;
|
||||
default:
|
||||
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
set_property (GObject *object, guint prop_id,
|
||||
const GValue *value, GParamSpec *pspec)
|
||||
{
|
||||
switch (prop_id) {
|
||||
default:
|
||||
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
dispose (GObject *object)
|
||||
{
|
||||
|
|
@ -801,10 +764,7 @@ nm_device_team_class_init (NMDeviceTeamClass *klass)
|
|||
|
||||
NM_DEVICE_CLASS_DECLARE_TYPES (klass, NM_SETTING_TEAM_SETTING_NAME, NM_LINK_TYPE_TEAM)
|
||||
|
||||
/* virtual methods */
|
||||
object_class->constructed = constructed;
|
||||
object_class->get_property = get_property;
|
||||
object_class->set_property = set_property;
|
||||
object_class->dispose = dispose;
|
||||
|
||||
parent_class->create_and_realize = create_and_realize;
|
||||
|
|
@ -822,15 +782,6 @@ nm_device_team_class_init (NMDeviceTeamClass *klass)
|
|||
parent_class->enslave_slave = enslave_slave;
|
||||
parent_class->release_slave = release_slave;
|
||||
|
||||
/* properties */
|
||||
g_object_class_install_property
|
||||
(object_class, PROP_SLAVES,
|
||||
g_param_spec_boxed (NM_DEVICE_TEAM_SLAVES, "", "",
|
||||
G_TYPE_STRV,
|
||||
G_PARAM_READABLE |
|
||||
G_PARAM_STATIC_STRINGS));
|
||||
|
||||
|
||||
nm_exported_object_class_add_interface (NM_EXPORTED_OBJECT_CLASS (klass),
|
||||
NMDBUS_TYPE_DEVICE_TEAM_SKELETON,
|
||||
NULL);
|
||||
|
|
|
|||
|
|
@ -32,8 +32,6 @@ G_BEGIN_DECLS
|
|||
#define NM_IS_DEVICE_TEAM_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), NM_TYPE_DEVICE_TEAM))
|
||||
#define NM_DEVICE_TEAM_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), NM_TYPE_DEVICE_TEAM, NMDeviceTeamClass))
|
||||
|
||||
#define NM_DEVICE_TEAM_SLAVES "slaves"
|
||||
|
||||
typedef NMDevice NMDeviceTeam;
|
||||
typedef NMDeviceClass NMDeviceTeamClass;
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue