device: transform NM_DEVICE_IS_MASTER gobject property to field in NMDeviceClass

We don't need this flexibility of having a full fledged GObject
property for is-master. The property value only depends on the
device's class.
This commit is contained in:
Thomas Haller 2017-06-01 23:08:30 +02:00
parent c3aa52530c
commit c79a97657b
5 changed files with 19 additions and 25 deletions

View file

@ -613,6 +613,7 @@ reapply_connection (NMDevice *device, NMConnection *con_old, NMConnection *con_n
static void
nm_device_bond_init (NMDeviceBond * self)
{
nm_assert (nm_device_is_master (NM_DEVICE (self)));
}
static void
@ -622,6 +623,7 @@ nm_device_bond_class_init (NMDeviceBondClass *klass)
NM_DEVICE_CLASS_DECLARE_TYPES (klass, NM_SETTING_BOND_SETTING_NAME, NM_LINK_TYPE_BOND)
parent_class->is_master = TRUE;
parent_class->get_generic_capabilities = get_generic_capabilities;
parent_class->is_available = is_available;
parent_class->check_connection_compatible = check_connection_compatible;
@ -662,7 +664,6 @@ create_device (NMDeviceFactory *factory,
NM_DEVICE_TYPE_DESC, "Bond",
NM_DEVICE_DEVICE_TYPE, NM_DEVICE_TYPE_BOND,
NM_DEVICE_LINK_TYPE, NM_LINK_TYPE_BOND,
NM_DEVICE_IS_MASTER, TRUE,
NULL);
}

View file

@ -494,6 +494,7 @@ create_and_realize (NMDevice *device,
static void
nm_device_bridge_init (NMDeviceBridge * self)
{
nm_assert (nm_device_is_master (NM_DEVICE (self)));
}
static void
@ -503,6 +504,7 @@ nm_device_bridge_class_init (NMDeviceBridgeClass *klass)
NM_DEVICE_CLASS_DECLARE_TYPES (klass, NM_SETTING_BRIDGE_SETTING_NAME, NM_LINK_TYPE_BRIDGE)
parent_class->is_master = TRUE;
parent_class->get_generic_capabilities = get_generic_capabilities;
parent_class->is_available = is_available;
parent_class->check_connection_compatible = check_connection_compatible;
@ -543,7 +545,6 @@ create_device (NMDeviceFactory *factory,
NM_DEVICE_TYPE_DESC, "Bridge",
NM_DEVICE_DEVICE_TYPE, NM_DEVICE_TYPE_BRIDGE,
NM_DEVICE_LINK_TYPE, NM_LINK_TYPE_BRIDGE,
NM_DEVICE_IS_MASTER, TRUE,
NULL);
}

View file

@ -188,7 +188,6 @@ NM_GOBJECT_PROPERTIES_DEFINE (NMDevice,
PROP_IFINDEX,
PROP_AVAILABLE_CONNECTIONS,
PROP_PHYSICAL_PORT_ID,
PROP_IS_MASTER,
PROP_MASTER,
PROP_PARENT,
PROP_HW_ADDRESS,
@ -451,7 +450,6 @@ typedef struct _NMDevicePrivate {
gulong master_ready_id;
/* slave management */
bool is_master;
CList slaves; /* list of SlaveInfo */
NMMetered metered;
@ -2192,7 +2190,7 @@ carrier_changed (NMDevice *self, gboolean carrier)
if (priv->ignore_carrier && !carrier)
return;
if (priv->is_master) {
if (nm_device_is_master (self)) {
/* Bridge/bond/team carrier does not affect its own activation,
* but when carrier comes on, if there are slaves waiting,
* it will restart them.
@ -3531,7 +3529,9 @@ nm_device_master_release_slaves (NMDevice *self)
gboolean
nm_device_is_master (NMDevice *self)
{
return NM_DEVICE_GET_PRIVATE (self)->is_master;
g_return_val_if_fail (NM_IS_DEVICE (self), FALSE);
return NM_DEVICE_GET_CLASS (self)->is_master;
}
/**
@ -4190,7 +4190,7 @@ nm_device_check_slave_connection_compatible (NMDevice *self, NMConnection *slave
priv = NM_DEVICE_GET_PRIVATE (self);
if (!priv->is_master)
if (!nm_device_is_master (self))
return FALSE;
/* All masters should have connection type set */
@ -6033,14 +6033,14 @@ act_stage3_ip4_config_start (NMDevice *self,
g_return_val_if_fail (connection, NM_ACT_STAGE_RETURN_FAILURE);
if ( connection_ip4_method_requires_carrier (connection, NULL)
&& priv->is_master
&& nm_device_is_master (self)
&& !priv->carrier) {
_LOGI (LOGD_IP4 | LOGD_DEVICE,
"IPv4 config waiting until carrier is on");
return NM_ACT_STAGE_RETURN_IP_WAIT;
}
if (priv->is_master && ip4_requires_slaves (connection)) {
if (nm_device_is_master (self) && ip4_requires_slaves (connection)) {
/* If the master has no ready slaves, and depends on slaves for
* a successful IPv4 attempt, then postpone IPv4 addressing.
*/
@ -7634,14 +7634,14 @@ act_stage3_ip6_config_start (NMDevice *self,
g_return_val_if_fail (connection, NM_ACT_STAGE_RETURN_FAILURE);
if ( connection_ip6_method_requires_carrier (connection, NULL)
&& priv->is_master
&& nm_device_is_master (self)
&& !priv->carrier) {
_LOGI (LOGD_IP6 | LOGD_DEVICE,
"IPv6 config waiting until carrier is on");
return NM_ACT_STAGE_RETURN_IP_WAIT;
}
if (priv->is_master && ip6_requires_slaves (connection)) {
if (nm_device_is_master (self) && ip6_requires_slaves (connection)) {
/* If the master has no ready slaves, and depends on slaves for
* a successful IPv6 attempt, then postpone IPv6 addressing.
*/
@ -13880,10 +13880,6 @@ set_property (GObject *object, guint prop_id,
/* construct-only */
priv->rfkill_type = g_value_get_uint (value);
break;
case PROP_IS_MASTER:
/* construct-only */
priv->is_master = g_value_get_boolean (value);
break;
case PROP_PERM_HW_ADDRESS:
/* construct-only */
priv->hw_addr_perm = g_value_dup_string (value);
@ -14018,9 +14014,6 @@ get_property (GObject *object, guint prop_id,
case PROP_PHYSICAL_PORT_ID:
g_value_set_string (value, priv->physical_port_id);
break;
case PROP_IS_MASTER:
g_value_set_boolean (value, priv->is_master);
break;
case PROP_MASTER:
g_value_set_object (value, nm_device_get_master (self));
break;
@ -14283,11 +14276,6 @@ nm_device_class_init (NMDeviceClass *klass)
NULL,
G_PARAM_READABLE |
G_PARAM_STATIC_STRINGS);
obj_properties[PROP_IS_MASTER] =
g_param_spec_boolean (NM_DEVICE_IS_MASTER, "", "",
FALSE,
G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY |
G_PARAM_STATIC_STRINGS);
obj_properties[PROP_MASTER] =
g_param_spec_object (NM_DEVICE_MASTER, "", "",
NM_TYPE_DEVICE,

View file

@ -120,7 +120,6 @@ nm_device_state_reason_check (NMDeviceStateReason reason)
#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 */
#define NM_DEVICE_IS_MASTER "is-master" /* Internal only */
#define NM_DEVICE_MASTER "master" /* Internal only */
#define NM_DEVICE_HAS_PENDING_ACTION "has-pending-action" /* Internal only */
@ -196,6 +195,10 @@ typedef struct {
const char *connection_type;
const NMLinkType *link_types;
/* Whether the device type is a master-type. This depends purely on the
* type (NMDeviceClass), not the actual device instance. */
bool is_master:1;
void (*state_changed) (NMDevice *device,
NMDeviceState new_state,
NMDeviceState old_state,

View file

@ -822,6 +822,7 @@ get_property (GObject *object, guint prop_id,
static void
nm_device_team_init (NMDeviceTeam * self)
{
nm_assert (nm_device_is_master (NM_DEVICE (self)));
}
static void
@ -854,7 +855,6 @@ nm_device_team_new (const char *iface)
NM_DEVICE_TYPE_DESC, "Team",
NM_DEVICE_DEVICE_TYPE, NM_DEVICE_TYPE_TEAM,
NM_DEVICE_LINK_TYPE, NM_LINK_TYPE_TEAM,
NM_DEVICE_IS_MASTER, TRUE,
NULL);
}
@ -887,6 +887,7 @@ nm_device_team_class_init (NMDeviceTeamClass *klass)
object_class->dispose = dispose;
object_class->get_property = get_property;
parent_class->is_master = TRUE;
parent_class->create_and_realize = create_and_realize;
parent_class->get_generic_capabilities = get_generic_capabilities;
parent_class->is_available = is_available;