summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Haller <thaller@redhat.com>2016-04-20 11:28:38 +0200
committerThomas Haller <thaller@redhat.com>2016-04-20 12:09:40 +0200
commit9c323261ea15fb8162c9ce3f7db39e8049b0f5f8 (patch)
tree55f6dd3a169af9587b6a51149978665b20a0848f
parent8f7029d132d81f8d454cccfeb8381001bf405fa9 (diff)
downloadNetworkManager-9c323261ea15fb8162c9ce3f7db39e8049b0f5f8.tar.gz
platform: use nm_utils_new_infiniband_name()
-rw-r--r--src/platform/nm-fake-platform.c8
-rw-r--r--src/platform/nm-linux-platform.c23
-rw-r--r--src/platform/nm-platform.c4
3 files changed, 18 insertions, 17 deletions
diff --git a/src/platform/nm-fake-platform.c b/src/platform/nm-fake-platform.c
index 7b54507696..b0d4411507 100644
--- a/src/platform/nm-fake-platform.c
+++ b/src/platform/nm-fake-platform.c
@@ -709,12 +709,13 @@ static gboolean
infiniband_partition_add (NMPlatform *platform, int parent, int p_key, const NMPlatformLink **out_link)
{
NMFakePlatformLink *device, *parent_device;
- gs_free char *name = NULL;
+ char name[IFNAMSIZ];
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);
+ nm_utils_new_infiniband_name (name, parent_device->link.name, p_key);
+
if (!link_add (platform, name, NM_LINK_TYPE_INFINIBAND, NULL, 0, out_link))
return FALSE;
@@ -726,7 +727,6 @@ infiniband_partition_add (NMPlatform *platform, int parent, int p_key, const NMP
device->lnk->lnk_infiniband.p_key = p_key;
device->lnk->lnk_infiniband.mode = "datagram";
device->link.parent = parent;
-
return TRUE;
}
@@ -739,7 +739,7 @@ infiniband_partition_delete (NMPlatform *platform, int parent, int p_key)
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);
+ nm_utils_new_infiniband_name (name, parent_device->link.name, p_key);
return link_delete (platform, nm_platform_link_get_ifindex (platform, name));
}
diff --git a/src/platform/nm-linux-platform.c b/src/platform/nm-linux-platform.c
index ab2c440f0d..529d1dd2d1 100644
--- a/src/platform/nm-linux-platform.c
+++ b/src/platform/nm-linux-platform.c
@@ -5100,7 +5100,7 @@ link_release (NMPlatform *platform, int master, int slave)
/******************************************************************/
static gboolean
-_infiniband_partition_action (NMPlatform *platform, int parent, int p_key, const char *action, char **ifname)
+_infiniband_partition_action (NMPlatform *platform, int parent, int p_key, const char *action, char *out_partition_name)
{
NMLinuxPlatformPrivate *priv = NM_LINUX_PLATFORM_GET_PRIVATE (platform);
const NMPObject *obj_parent;
@@ -5110,10 +5110,13 @@ _infiniband_partition_action (NMPlatform *platform, int parent, int p_key, const
nm_assert (p_key > 0 && p_key <= 0xffff && p_key != 0x8000);
obj_parent = nmp_cache_lookup_link (priv->cache, parent);
- if (!obj_parent || !obj_parent->link.name[0])
- g_return_val_if_reached (FALSE);
+ if (!obj_parent || !obj_parent->link.name[0]) {
+ errno = ENOENT;
+ return FALSE;
+ }
- *ifname = g_strdup_printf ("%s.%04x", obj_parent->link.name, p_key);
+ if (out_partition_name)
+ nm_utils_new_infiniband_name (out_partition_name, obj_parent->link.name, p_key);
path = g_strdup_printf ("/sys/class/net/%s/%s",
NM_ASSERT_VALID_PATH_COMPONENT (obj_parent->link.name),
@@ -5128,15 +5131,15 @@ static gboolean
infiniband_partition_add (NMPlatform *platform, int parent, int p_key, const NMPlatformLink **out_link)
{
const NMPObject *obj;
- gs_free char *ifname = NULL;
+ char name[IFNAMSIZ];
- if (!_infiniband_partition_action (platform, parent, p_key, "create_child", &ifname))
+ if (!_infiniband_partition_action (platform, parent, p_key, "create_child", name))
return FALSE;
- do_request_link (platform, 0, ifname);
+ do_request_link (platform, 0, name);
obj = nmp_cache_lookup_link_full (NM_LINUX_PLATFORM_GET_PRIVATE (platform)->cache,
- 0, ifname, FALSE, NM_LINK_TYPE_INFINIBAND, NULL, NULL);
+ 0, name, FALSE, NM_LINK_TYPE_INFINIBAND, NULL, NULL);
if (out_link)
*out_link = obj ? &obj->link : NULL;
return !!obj;
@@ -5145,9 +5148,7 @@ infiniband_partition_add (NMPlatform *platform, int parent, int p_key, const NMP
static gboolean
infiniband_partition_delete (NMPlatform *platform, int parent, int p_key)
{
- gs_free char *ifname = NULL;
-
- if (!_infiniband_partition_action (platform, parent, p_key, "delete_child", &ifname)) {
+ if (!_infiniband_partition_action (platform, parent, p_key, "delete_child", NULL)) {
if (errno != ENODEV)
return FALSE;
}
diff --git a/src/platform/nm-platform.c b/src/platform/nm-platform.c
index 43532ebf3e..58c54cb9af 100644
--- a/src/platform/nm-platform.c
+++ b/src/platform/nm-platform.c
@@ -1895,7 +1895,7 @@ _infiniband_add_add_or_delete (NMPlatform *self,
gboolean add,
const NMPlatformLink **out_link)
{
- gs_free char *name = NULL;
+ char name[IFNAMSIZ];
const NMPlatformLink *parent_link;
NMPlatformError plerr;
@@ -1915,7 +1915,7 @@ _infiniband_add_add_or_delete (NMPlatform *self,
if (parent_link->type != NM_LINK_TYPE_INFINIBAND)
return NM_PLATFORM_ERROR_WRONG_TYPE;
- name = g_strdup_printf ("%s.%04x", parent_link->name, p_key);
+ nm_utils_new_infiniband_name (name, parent_link->name, p_key);
if (add) {
plerr = _link_add_check_existing (self, name, NM_LINK_TYPE_INFINIBAND, out_link);