summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Haller <thaller@redhat.com>2015-06-15 15:19:28 +0200
committerThomas Haller <thaller@redhat.com>2015-06-17 11:44:16 +0200
commitb74e620f2d8d6f28b833607994fb35d13b792d9e (patch)
tree9fc9b7f4d01e612099e65c1e9aba92610e0ae122
parente7ee2fc139e40fd7e41945f14272727a25b11035 (diff)
downloadNetworkManager-b74e620f2d8d6f28b833607994fb35d13b792d9e.tar.gz
platform: expose GUdevDevice instance for platform links
-rw-r--r--src/devices/nm-device-ethernet.c21
-rw-r--r--src/platform/nm-linux-platform.c15
-rw-r--r--src/platform/nm-platform.c13
-rw-r--r--src/platform/nm-platform.h3
4 files changed, 38 insertions, 14 deletions
diff --git a/src/devices/nm-device-ethernet.c b/src/devices/nm-device-ethernet.c
index 70e9e70c47..82cab00fe3 100644
--- a/src/devices/nm-device-ethernet.c
+++ b/src/devices/nm-device-ethernet.c
@@ -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*
diff --git a/src/platform/nm-linux-platform.c b/src/platform/nm-linux-platform.c
index f00fdc226e..d12b87b6a4 100644
--- a/src/platform/nm-linux-platform.c
+++ b/src/platform/nm-linux-platform.c
@@ -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;
diff --git a/src/platform/nm-platform.c b/src/platform/nm-platform.c
index b5a2099012..0243fe8d94 100644
--- a/src/platform/nm-platform.c
+++ b/src/platform/nm-platform.c
@@ -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
diff --git a/src/platform/nm-platform.h b/src/platform/nm-platform.h
index fb9ed34fec..6bc9d42524 100644
--- a/src/platform/nm-platform.h
+++ b/src/platform/nm-platform.h
@@ -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);