diff options
author | Dan Williams <dcbw@redhat.com> | 2014-10-06 09:37:34 -0500 |
---|---|---|
committer | Dan Williams <dcbw@redhat.com> | 2014-12-11 10:07:42 -0600 |
commit | 18613d30bf928b3ab18279dcaa93537571274ced (patch) | |
tree | 389959c25c14488421f85771b2baf3bd353435c2 | |
parent | b3295cc9548b02c3ea41100d2c0b0efd1809bba1 (diff) | |
download | NetworkManager-18613d30bf928b3ab18279dcaa93537571274ced.tar.gz |
platform: move InfiniBand property reading into the platform
-rw-r--r-- | src/devices/nm-device-infiniband.c | 14 | ||||
-rw-r--r-- | src/platform/nm-fake-platform.c | 38 | ||||
-rw-r--r-- | src/platform/nm-linux-platform.c | 109 | ||||
-rw-r--r-- | src/platform/nm-platform.c | 14 | ||||
-rw-r--r-- | src/platform/nm-platform.h | 6 |
5 files changed, 165 insertions, 16 deletions
diff --git a/src/devices/nm-device-infiniband.c b/src/devices/nm-device-infiniband.c index ae4ae2dab8..912da36c42 100644 --- a/src/devices/nm-device-infiniband.c +++ b/src/devices/nm-device-infiniband.c @@ -218,8 +218,8 @@ update_connection (NMDevice *device, NMConnection *connection) { NMSettingInfiniband *s_infiniband = nm_connection_get_setting_infiniband (connection); const char *mac = nm_device_get_hw_address (device); - char *mode_path, *contents = NULL; const char *transport_mode = "datagram"; + int ifindex; if (!s_infiniband) { s_infiniband = (NMSettingInfiniband *) nm_setting_infiniband_new (); @@ -229,16 +229,10 @@ update_connection (NMDevice *device, NMConnection *connection) if (mac && !nm_utils_hwaddr_matches (mac, -1, NULL, INFINIBAND_ALEN)) g_object_set (s_infiniband, NM_SETTING_INFINIBAND_MAC_ADDRESS, mac, NULL); - mode_path = g_strdup_printf ("/sys/class/net/%s/mode", - ASSERT_VALID_PATH_COMPONENT (nm_device_get_iface (device))); - contents = nm_platform_sysctl_get (mode_path); - g_free (mode_path); - if (contents) { - if (strstr (contents, "datagram")) + ifindex = nm_device_get_ifindex (device); + if (ifindex > 0) { + if (!nm_platform_infiniband_get_info (ifindex, NULL, NULL, &transport_mode)) transport_mode = "datagram"; - else if (strstr (contents, "connected")) - transport_mode = "connected"; - g_free (contents); } g_object_set (G_OBJECT (s_infiniband), NM_SETTING_INFINIBAND_TRANSPORT_MODE, transport_mode, NULL); } diff --git a/src/platform/nm-fake-platform.c b/src/platform/nm-fake-platform.c index 45b1508ba9..ae62ac6ccd 100644 --- a/src/platform/nm-fake-platform.c +++ b/src/platform/nm-fake-platform.c @@ -47,6 +47,7 @@ typedef struct { char *udi; GBytes *address; int vlan_id; + int ib_p_key; } NMFakePlatformLink; #define NM_FAKE_PLATFORM_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NM_TYPE_FAKE_PLATFORM, NMFakePlatformPrivate)) @@ -677,18 +678,42 @@ vlan_set_egress_map (NMPlatform *platform, int ifindex, int from, int to) static gboolean infiniband_partition_add (NMPlatform *platform, int parent, int p_key, NMPlatformLink *out_link) { - NMFakePlatformLink *parent_device; - char *name; - gboolean success; + NMFakePlatformLink *device, *parent_device; + gs_free char *name = NULL; parent_device = link_get (platform, parent); g_return_val_if_fail (parent_device != NULL, FALSE); name = g_strdup_printf ("%s.%04x", parent_device->link.name, p_key); - success = link_add (platform, name, NM_LINK_TYPE_INFINIBAND, NULL, 0, out_link); - g_free (name); + if (!link_add (platform, name, NM_LINK_TYPE_INFINIBAND, NULL, 0, out_link)) + return FALSE; + + device = link_get (platform, link_get_ifindex (platform, name)); + g_return_val_if_fail (device, FALSE); + + device->ib_p_key = p_key; + device->link.parent = parent; - return success; + return TRUE; +} + +static gboolean +infiniband_get_info (NMPlatform *platform, int ifindex, int *parent, int *p_key, const char **mode) +{ + NMFakePlatformLink *device; + + device = link_get (platform, ifindex); + g_return_val_if_fail (device, FALSE); + g_return_val_if_fail (device->link.type == NM_LINK_TYPE_INFINIBAND, FALSE); + + if (parent) + *parent = device->link.parent; + if (p_key) + *p_key = device->ib_p_key; + if (mode) + *mode = "datagram"; + + return TRUE; } static gboolean @@ -1377,6 +1402,7 @@ nm_fake_platform_class_init (NMFakePlatformClass *klass) platform_class->vlan_set_egress_map = vlan_set_egress_map; platform_class->infiniband_partition_add = infiniband_partition_add; + platform_class->infiniband_get_info = infiniband_get_info; platform_class->veth_get_properties = veth_get_properties; platform_class->tun_get_properties = tun_get_properties; diff --git a/src/platform/nm-linux-platform.c b/src/platform/nm-linux-platform.c index 4d8f36cac9..35c51431a8 100644 --- a/src/platform/nm-linux-platform.c +++ b/src/platform/nm-linux-platform.c @@ -3024,6 +3024,114 @@ infiniband_partition_add (NMPlatform *platform, int parent, int p_key, NMPlatfor return success; } +typedef struct { + int p_key; + const char *mode; +} IpoibInfo; + +/* IFLA_IPOIB_* were introduced in the 3.7 kernel, but the kernel headers + * we're building against might not have those properties even though the + * running kernel might. + */ +#define IFLA_IPOIB_UNSPEC 0 +#define IFLA_IPOIB_PKEY 1 +#define IFLA_IPOIB_MODE 2 +#define IFLA_IPOIB_UMCAST 3 +#undef IFLA_IPOIB_MAX +#define IFLA_IPOIB_MAX IFLA_IPOIB_UMCAST + +#define IPOIB_MODE_DATAGRAM 0 /* using unreliable datagram QPs */ +#define IPOIB_MODE_CONNECTED 1 /* using connected QPs */ + +static const struct nla_policy infiniband_info_policy[IFLA_IPOIB_MAX + 1] = { + [IFLA_IPOIB_PKEY] = { .type = NLA_U16 }, + [IFLA_IPOIB_MODE] = { .type = NLA_U16 }, + [IFLA_IPOIB_UMCAST] = { .type = NLA_U16 }, +}; + +static int +infiniband_info_data_parser (struct nlattr *info_data, gpointer parser_data) +{ + IpoibInfo *info = parser_data; + struct nlattr *tb[IFLA_MACVLAN_MAX + 1]; + int err; + + err = nla_parse_nested (tb, IFLA_IPOIB_MAX, info_data, + (struct nla_policy *) infiniband_info_policy); + if (err < 0) + return err; + if (!tb[IFLA_IPOIB_PKEY] || !tb[IFLA_IPOIB_MODE]) + return -EINVAL; + + info->p_key = nla_get_u16 (tb[IFLA_IPOIB_PKEY]); + + switch (nla_get_u16 (tb[IFLA_IPOIB_MODE])) { + case IPOIB_MODE_DATAGRAM: + info->mode = "datagram"; + break; + case IPOIB_MODE_CONNECTED: + info->mode = "connected"; + break; + default: + return -NLE_PARSE_ERR; + } + + return 0; +} + +static gboolean +infiniband_get_info (NMPlatform *platform, int ifindex, int *parent, int *p_key, const char **mode) +{ + NMLinuxPlatformPrivate *priv = NM_LINUX_PLATFORM_GET_PRIVATE (platform); + auto_nl_object struct rtnl_link *rtnllink = NULL; + IpoibInfo info = { -1, NULL }; + + rtnllink = link_get (platform, ifindex); + if (!rtnllink) + return FALSE; + + if (parent) + *parent = rtnl_link_get_link (rtnllink); + + if (nm_rtnl_link_parse_info_data (priv->nlh, + ifindex, + infiniband_info_data_parser, + &info)) { + const char *iface = rtnl_link_get_name (rtnllink); + char *path, *contents = NULL; + + path = g_strdup_printf ("/sys/class/net/%s/mode", ASSERT_VALID_PATH_COMPONENT (iface)); + contents = nm_platform_sysctl_get (path); + g_free (path); + if (!contents) + return FALSE; + + if (strstr (contents, "datagram")) + info.mode = "datagram"; + else if (strstr (contents, "connected")) + info.mode = "connected"; + g_free (contents); + + path = g_strdup_printf ("/sys/class/net/%s/pkey", ASSERT_VALID_PATH_COMPONENT (iface)); + contents = nm_platform_sysctl_get (path); + g_free (path); + if (!contents) + return FALSE; + + info.p_key = (int) nm_utils_ascii_str_to_int64 (contents, 16, 0, 0xFFFF, -1); + g_free (contents); + + if (info.p_key < 0) + return FALSE; + } + + if (p_key) + *p_key = info.p_key; + if (mode) + *mode = info.mode; + return TRUE; +} + static gboolean veth_get_properties (NMPlatform *platform, int ifindex, NMPlatformVethProperties *props) { @@ -4621,6 +4729,7 @@ nm_linux_platform_class_init (NMLinuxPlatformClass *klass) platform_class->vlan_set_egress_map = vlan_set_egress_map; platform_class->infiniband_partition_add = infiniband_partition_add; + platform_class->infiniband_get_info = infiniband_get_info; platform_class->veth_get_properties = veth_get_properties; platform_class->tun_get_properties = tun_get_properties; diff --git a/src/platform/nm-platform.c b/src/platform/nm-platform.c index c5ed11e3d1..74931c73e5 100644 --- a/src/platform/nm-platform.c +++ b/src/platform/nm-platform.c @@ -1366,6 +1366,20 @@ nm_platform_infiniband_partition_add (int parent, int p_key, NMPlatformLink *out } gboolean +nm_platform_infiniband_get_info (int ifindex, + int *parent, + int *p_key, + const char **mode) +{ + reset_error (); + + g_return_val_if_fail (ifindex > 0, FALSE); + g_return_val_if_fail (klass->infiniband_partition_add, FALSE); + + return klass->infiniband_get_info (platform, ifindex, parent, p_key, mode); +} + +gboolean nm_platform_veth_get_properties (int ifindex, NMPlatformVethProperties *props) { reset_error (); diff --git a/src/platform/nm-platform.h b/src/platform/nm-platform.h index dcf558c064..8f7abd3c04 100644 --- a/src/platform/nm-platform.h +++ b/src/platform/nm-platform.h @@ -401,6 +401,11 @@ typedef struct { gboolean (*vlan_set_egress_map) (NMPlatform *, int ifindex, int from, int to); gboolean (*infiniband_partition_add) (NMPlatform *, int parent, int p_key, NMPlatformLink *out_link); + gboolean (*infiniband_get_info) (NMPlatform *, + int ifindex, + int *parent, + int *p_key, + const char **mode); gboolean (*veth_get_properties) (NMPlatform *, int ifindex, NMPlatformVethProperties *properties); gboolean (*tun_get_properties) (NMPlatform *, int ifindex, NMPlatformTunProperties *properties); @@ -552,6 +557,7 @@ gboolean nm_platform_vlan_set_ingress_map (int ifindex, int from, int to); gboolean nm_platform_vlan_set_egress_map (int ifindex, int from, int to); gboolean nm_platform_infiniband_partition_add (int parent, int p_key, NMPlatformLink *out_link); +gboolean nm_platform_infiniband_get_info (int ifindex, int *parent, int *p_key, const char **mode); gboolean nm_platform_veth_get_properties (int ifindex, NMPlatformVethProperties *properties); gboolean nm_platform_tun_get_properties (int ifindex, NMPlatformTunProperties *properties); |