platform: expose GUdevDevice instance for platform links

This commit is contained in:
Thomas Haller
2015-06-15 15:19:28 +02:00
parent e7ee2fc139
commit b74e620f2d
4 changed files with 38 additions and 14 deletions

View File

@@ -52,6 +52,7 @@
#include "nm-connection-provider.h"
#include "nm-device-factory.h"
#include "nm-core-internal.h"
#include "NetworkManagerUtils.h"
#include "nm-device-ethernet-glue.h"
@@ -151,28 +152,21 @@ static void
_update_s390_subchannels (NMDeviceEthernet *self)
{
NMDeviceEthernetPrivate *priv = NM_DEVICE_ETHERNET_GET_PRIVATE (self);
GUdevClient *client;
GUdevDevice *dev;
GUdevDevice *parent = NULL;
const char *parent_path, *item, *driver;
const char *subsystems[] = { "net", NULL };
const char *iface;
int ifindex;
GDir *dir;
GError *error = NULL;
client = g_udev_client_new (subsystems);
if (!client) {
_LOGW (LOGD_DEVICE | LOGD_HW, "failed to initialize GUdev client");
return;
}
iface = nm_device_get_iface (NM_DEVICE (self));
dev = iface ? g_udev_client_query_by_subsystem_and_name (client, "net", iface) : NULL;
ifindex = nm_device_get_ifindex (NM_DEVICE (self));
dev = (GUdevDevice *) nm_platform_link_get_udev_device (NM_PLATFORM_GET, ifindex);
if (!dev) {
_LOGW (LOGD_DEVICE | LOGD_HW, "failed to find device '%s' with udev",
iface ? iface : "(null)");
_LOGW (LOGD_DEVICE | LOGD_HW, "failed to find device %d '%s' with udev",
ifindex, str_if_set (nm_device_get_iface (NM_DEVICE (self)), "(null)"));
goto out;
}
g_object_ref (dev);
/* Try for the "ccwgroup" parent */
parent = g_udev_device_get_parent_with_subsystem (dev, "ccwgroup", NULL);
@@ -244,7 +238,6 @@ out:
g_object_unref (parent);
if (dev)
g_object_unref (dev);
g_object_unref (client);
}
static GObject*

View File

@@ -2969,6 +2969,20 @@ link_get_udi (NMPlatform *platform, int ifindex)
return g_udev_device_get_sysfs_path (obj->_link.udev.device);
}
static GObject *
link_get_udev_device (NMPlatform *platform, int ifindex)
{
const NMPObject *obj_cache;
/* we don't use cache_lookup_link() because this would return NULL
* if the link is not visible in libnl. For link_get_udev_device()
* we want to return whatever we have, even if the link itself
* appears invisible via other platform functions. */
obj_cache = nmp_cache_lookup_link (NM_LINUX_PLATFORM_GET_PRIVATE (platform)->cache, ifindex);
return obj_cache ? (GObject *) obj_cache->_link.udev.device : NULL;
}
static gboolean
link_get_user_ipv6ll_enabled (NMPlatform *platform, int ifindex)
{
@@ -4999,6 +5013,7 @@ nm_linux_platform_class_init (NMLinuxPlatformClass *klass)
platform_class->link_uses_arp = link_uses_arp;
platform_class->link_get_udi = link_get_udi;
platform_class->link_get_udev_device = link_get_udev_device;
platform_class->link_get_ipv6_token = link_get_ipv6_token;
platform_class->link_get_user_ipv6ll_enabled = link_get_user_ipv6ll_enabled;

View File

@@ -928,6 +928,19 @@ nm_platform_link_get_udi (NMPlatform *self, int ifindex)
return NULL;
}
GObject *
nm_platform_link_get_udev_device (NMPlatform *self, int ifindex)
{
_CHECK_SELF (self, klass, FALSE);
reset_error (self);
g_return_val_if_fail (ifindex >= 0, NULL);
if (klass->link_get_udev_device)
return klass->link_get_udev_device (self, ifindex);
return NULL;
}
/**
* nm_platform_link_get_user_ip6vll_enabled:
* @self: platform instance

View File

@@ -433,6 +433,7 @@ typedef struct {
gboolean (*link_uses_arp) (NMPlatform *, int ifindex);
const char *(*link_get_udi) (NMPlatform *self, int ifindex);
GObject *(*link_get_udev_device) (NMPlatform *self, int ifindex);
gboolean (*link_get_ipv6_token) (NMPlatform *, int ifindex, NMUtilsIPv6IfaceId *iid);
gboolean (*link_get_user_ipv6ll_enabled) (NMPlatform *, int ifindex);
@@ -624,6 +625,8 @@ gboolean nm_platform_link_uses_arp (NMPlatform *self, int ifindex);
gboolean nm_platform_link_get_ipv6_token (NMPlatform *self, int ifindex, NMUtilsIPv6IfaceId *iid);
const char *nm_platform_link_get_udi (NMPlatform *self, int ifindex);
GObject *nm_platform_link_get_udev_device (NMPlatform *self, int ifindex);
gboolean nm_platform_link_get_user_ipv6ll_enabled (NMPlatform *self, int ifindex);
gboolean nm_platform_link_set_user_ipv6ll_enabled (NMPlatform *self, int ifindex, gboolean enabled);