core: earlier software capability detection

We need to know whether we can create interfaces of any given
NMDevice subclass or not.  So don't rely on just the NMPlatformLink
for that information, because we won't have a platform link for
software devices before we create them.

(cherry picked from commit d4e0a1e8cc)
This commit is contained in:
Dan Williams 2014-09-24 17:46:15 -05:00 committed by Thomas Haller
parent dee7f89b62
commit 2236cc5eb8
6 changed files with 39 additions and 21 deletions

View file

@ -64,7 +64,7 @@ enum {
static NMDeviceCapabilities
get_generic_capabilities (NMDevice *dev)
{
return NM_DEVICE_CAP_CARRIER_DETECT;
return NM_DEVICE_CAP_CARRIER_DETECT | NM_DEVICE_CAP_IS_SOFTWARE;
}
static gboolean

View file

@ -62,7 +62,7 @@ enum {
static NMDeviceCapabilities
get_generic_capabilities (NMDevice *dev)
{
return NM_DEVICE_CAP_CARRIER_DETECT;
return NM_DEVICE_CAP_CARRIER_DETECT | NM_DEVICE_CAP_IS_SOFTWARE;
}
static gboolean

View file

@ -44,12 +44,15 @@ G_DEFINE_TYPE (NMDeviceInfiniband, nm_device_infiniband, NM_TYPE_DEVICE)
#define NM_DEVICE_INFINIBAND_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NM_TYPE_DEVICE_INFINIBAND, NMDeviceInfinibandPrivate))
#define NM_DEVICE_INFINIBAND_IS_PARTITION "is-partition"
typedef struct {
int dummy;
gboolean is_partition;
} NMDeviceInfinibandPrivate;
enum {
PROP_0,
PROP_IS_PARTITION,
LAST_PROP
};
@ -62,7 +65,12 @@ nm_device_infiniband_init (NMDeviceInfiniband * self)
static NMDeviceCapabilities
get_generic_capabilities (NMDevice *dev)
{
return NM_DEVICE_CAP_CARRIER_DETECT;
guint32 caps = NM_DEVICE_CAP_CARRIER_DETECT;
if (NM_DEVICE_INFINIBAND_GET_PRIVATE (dev)->is_partition)
caps |= NM_DEVICE_CAP_IS_SOFTWARE;
return caps;
}
static NMActStageReturn
@ -243,6 +251,9 @@ get_property (GObject *object, guint prop_id,
GValue *value, GParamSpec *pspec)
{
switch (prop_id) {
case PROP_IS_PARTITION:
g_value_set_boolean (value, NM_DEVICE_INFINIBAND_GET_PRIVATE (object)->is_partition);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
@ -254,6 +265,9 @@ set_property (GObject *object, guint prop_id,
const GValue *value, GParamSpec *pspec)
{
switch (prop_id) {
case PROP_IS_PARTITION:
NM_DEVICE_INFINIBAND_GET_PRIVATE (object)->is_partition = g_value_get_boolean (value);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
@ -281,6 +295,12 @@ nm_device_infiniband_class_init (NMDeviceInfinibandClass *klass)
parent_class->ip4_config_pre_commit = ip4_config_pre_commit;
/* properties */
g_object_class_install_property
(object_class, PROP_IS_PARTITION,
g_param_spec_boolean (NM_DEVICE_INFINIBAND_IS_PARTITION, "", "",
FALSE,
G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY |
G_PARAM_STATIC_STRINGS));
nm_dbus_manager_register_exported_type (nm_dbus_manager_get (),
G_TYPE_FROM_CLASS (klass),
@ -299,6 +319,7 @@ new_link (NMDeviceFactory *factory, NMPlatformLink *plink, gboolean *out_ignore,
NM_DEVICE_PLATFORM_DEVICE, plink,
NM_DEVICE_TYPE_DESC, "InfiniBand",
NM_DEVICE_DEVICE_TYPE, NM_DEVICE_TYPE_INFINIBAND,
NM_DEVICE_INFINIBAND_IS_PARTITION, (plink->parent > 0),
NULL);
}
@ -342,6 +363,7 @@ create_virtual_device_for_connection (NMDeviceFactory *factory,
NM_DEVICE_DRIVER, nm_device_get_driver (parent),
NM_DEVICE_TYPE_DESC, "InfiniBand",
NM_DEVICE_DEVICE_TYPE, NM_DEVICE_TYPE_INFINIBAND,
NM_DEVICE_INFINIBAND_IS_PARTITION, TRUE,
NULL);
}

View file

@ -77,7 +77,7 @@ static NMDeviceCapabilities
get_generic_capabilities (NMDevice *dev)
{
/* We assume VLAN interfaces always support carrier detect */
return NM_DEVICE_CAP_CARRIER_DETECT;
return NM_DEVICE_CAP_CARRIER_DETECT | NM_DEVICE_CAP_IS_SOFTWARE;
}
static gboolean

View file

@ -185,7 +185,6 @@ typedef struct {
char * path;
char * iface; /* may change, could be renamed by user */
int ifindex;
gboolean is_software;
char * ip_iface;
int ip_ifindex;
NMDeviceType type;
@ -538,9 +537,7 @@ nm_device_get_ifindex (NMDevice *self)
gboolean
nm_device_is_software (NMDevice *self)
{
NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE (self);
return priv->is_software;
return NM_FLAGS_HAS (NM_DEVICE_GET_PRIVATE (self)->capabilities, NM_DEVICE_CAP_IS_SOFTWARE);
}
const char *
@ -1057,7 +1054,7 @@ nm_device_finish_init (NMDevice *self)
nm_device_enslave_slave (priv->master, self, NULL);
if (priv->ifindex > 0) {
if (priv->platform_link_initialized || (priv->is_nm_owned && priv->is_software)) {
if (priv->platform_link_initialized || (priv->is_nm_owned && nm_device_is_software (self))) {
nm_platform_link_get_unmanaged (NM_PLATFORM_GET, priv->ifindex, &platform_unmanaged);
nm_device_set_initial_unmanaged_flag (self, NM_UNMANAGED_DEFAULT, platform_unmanaged);
} else {
@ -8434,6 +8431,12 @@ constructor (GType type,
priv->capabilities |= NM_DEVICE_GET_CLASS (self)->get_generic_capabilities (self);
if (priv->ifindex > 0) {
priv->physical_port_id = nm_platform_link_get_physical_port_id (NM_PLATFORM_GET, priv->ifindex);
priv->dev_id = nm_platform_link_get_dev_id (NM_PLATFORM_GET, priv->ifindex);
if (nm_platform_link_is_software (NM_PLATFORM_GET, priv->ifindex))
priv->capabilities |= NM_DEVICE_CAP_IS_SOFTWARE;
priv->mtu = nm_platform_link_get_mtu (NM_PLATFORM_GET, priv->ifindex);
nm_platform_link_get_driver_info (NM_PLATFORM_GET,
priv->ifindex,
NULL,
@ -8441,6 +8444,9 @@ constructor (GType type,
&priv->firmware_version);
}
if (NM_DEVICE_GET_CLASS (self)->get_generic_capabilities)
priv->capabilities |= NM_DEVICE_GET_CLASS (self)->get_generic_capabilities (self);
/* Watch for external IP config changes */
platform = nm_platform_get ();
g_signal_connect (platform, NM_PLATFORM_SIGNAL_IP4_ADDRESS_CHANGED, G_CALLBACK (device_ip_changed), self);
@ -8517,16 +8523,6 @@ constructed (GObject *object)
priv->carrier = TRUE;
}
if (priv->ifindex > 0) {
priv->is_software = nm_platform_link_is_software (NM_PLATFORM_GET, priv->ifindex);
priv->physical_port_id = nm_platform_link_get_physical_port_id (NM_PLATFORM_GET, priv->ifindex);
priv->dev_id = nm_platform_link_get_dev_id (NM_PLATFORM_GET, priv->ifindex);
priv->mtu = nm_platform_link_get_mtu (NM_PLATFORM_GET, priv->ifindex);
}
/* Indicate software device in capabilities. */
if (priv->is_software)
priv->capabilities |= NM_DEVICE_CAP_IS_SOFTWARE;
/* Enslave ourselves */
master = nm_platform_link_get_master (NM_PLATFORM_GET, priv->ifindex);
if (master)

View file

@ -74,7 +74,7 @@ static gboolean teamd_start (NMDevice *device, NMSettingTeam *s_team);
static NMDeviceCapabilities
get_generic_capabilities (NMDevice *device)
{
return NM_DEVICE_CAP_CARRIER_DETECT;
return NM_DEVICE_CAP_CARRIER_DETECT | NM_DEVICE_CAP_IS_SOFTWARE;
}
static gboolean