libnm: use nm_net_devname_infiniband() for virtual interface-name of infiniband
In nm_setting_infiniband_get_virtual_interface_name(), no longer try to detect whether the cached value is still up to date. Instead, as we now have a fix sized buffer for the name, just always generate the name on every call. It's simpler.
This commit is contained in:
@@ -1066,6 +1066,8 @@ write_infiniband_setting(NMConnection *connection,
|
|||||||
svSetValueStr(ifcfg, "PHYSDEV", parent);
|
svSetValueStr(ifcfg, "PHYSDEV", parent);
|
||||||
|
|
||||||
if (parent && nm_connection_get_interface_name(connection)) {
|
if (parent && nm_connection_get_interface_name(connection)) {
|
||||||
|
char name[NM_IFNAMSIZ];
|
||||||
|
|
||||||
/* The connection.interface-name depends on the p-key. Also,
|
/* The connection.interface-name depends on the p-key. Also,
|
||||||
* nm_connection_normalize() will automatically adjust the
|
* nm_connection_normalize() will automatically adjust the
|
||||||
* interface-name to match the p-key.
|
* interface-name to match the p-key.
|
||||||
@@ -1073,8 +1075,8 @@ write_infiniband_setting(NMConnection *connection,
|
|||||||
* As we patched the p-key above, also anticipate that change, and
|
* As we patched the p-key above, also anticipate that change, and
|
||||||
* don't write a DEVICE= to the file, which would we normalize
|
* don't write a DEVICE= to the file, which would we normalize
|
||||||
* differently, when reading it back. */
|
* differently, when reading it back. */
|
||||||
*out_interface_name =
|
nm_net_devname_infiniband(name, parent, p_key);
|
||||||
nm_setting_infiniband_create_virtual_interface_name(parent, p_key);
|
*out_interface_name = g_strdup(name);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -36,9 +36,7 @@ typedef struct {
|
|||||||
char *mac_address;
|
char *mac_address;
|
||||||
char *transport_mode;
|
char *transport_mode;
|
||||||
char *parent;
|
char *parent;
|
||||||
char *virtual_iface_name;
|
char virtual_iface_name[NM_IFNAMSIZ];
|
||||||
gsize virtual_iface_name_parent_length;
|
|
||||||
gint32 virtual_iface_name_p_key;
|
|
||||||
gint32 p_key;
|
gint32 p_key;
|
||||||
guint32 mtu;
|
guint32 mtu;
|
||||||
} NMSettingInfinibandPrivate;
|
} NMSettingInfinibandPrivate;
|
||||||
@@ -145,17 +143,6 @@ nm_setting_infiniband_get_parent(NMSettingInfiniband *setting)
|
|||||||
return NM_SETTING_INFINIBAND_GET_PRIVATE(setting)->parent;
|
return NM_SETTING_INFINIBAND_GET_PRIVATE(setting)->parent;
|
||||||
}
|
}
|
||||||
|
|
||||||
char *
|
|
||||||
nm_setting_infiniband_create_virtual_interface_name(const char *parent, int p_key)
|
|
||||||
{
|
|
||||||
char *s;
|
|
||||||
|
|
||||||
s = g_strdup_printf("%s.%04x", parent, (guint) p_key);
|
|
||||||
if (strlen(s) >= NM_IFNAMSIZ)
|
|
||||||
s[NM_IFNAMSIZ - 1] = '\0';
|
|
||||||
return s;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* nm_setting_infiniband_get_virtual_interface_name:
|
* nm_setting_infiniband_get_virtual_interface_name:
|
||||||
* @setting: the #NMSettingInfiniband
|
* @setting: the #NMSettingInfiniband
|
||||||
@@ -170,25 +157,11 @@ const char *
|
|||||||
nm_setting_infiniband_get_virtual_interface_name(NMSettingInfiniband *setting)
|
nm_setting_infiniband_get_virtual_interface_name(NMSettingInfiniband *setting)
|
||||||
{
|
{
|
||||||
NMSettingInfinibandPrivate *priv = NM_SETTING_INFINIBAND_GET_PRIVATE(setting);
|
NMSettingInfinibandPrivate *priv = NM_SETTING_INFINIBAND_GET_PRIVATE(setting);
|
||||||
gsize len;
|
|
||||||
|
|
||||||
if (priv->p_key == -1 || !priv->parent) {
|
if (priv->p_key == -1 || !priv->parent)
|
||||||
nm_clear_g_free(&priv->virtual_iface_name);
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
|
||||||
|
|
||||||
len = strlen(priv->parent);
|
return nm_net_devname_infiniband(priv->virtual_iface_name, priv->parent, priv->p_key);
|
||||||
if (!priv->virtual_iface_name || priv->virtual_iface_name_p_key != priv->p_key
|
|
||||||
|| priv->virtual_iface_name_parent_length != len
|
|
||||||
|| memcmp(priv->parent, priv->virtual_iface_name, len) != 0) {
|
|
||||||
priv->virtual_iface_name_p_key = priv->p_key;
|
|
||||||
priv->virtual_iface_name_parent_length = len;
|
|
||||||
g_free(priv->virtual_iface_name);
|
|
||||||
priv->virtual_iface_name =
|
|
||||||
nm_setting_infiniband_create_virtual_interface_name(priv->parent, priv->p_key);
|
|
||||||
}
|
|
||||||
|
|
||||||
return priv->virtual_iface_name;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static gboolean
|
static gboolean
|
||||||
@@ -352,16 +325,6 @@ nm_setting_infiniband_new(void)
|
|||||||
return g_object_new(NM_TYPE_SETTING_INFINIBAND, NULL);
|
return g_object_new(NM_TYPE_SETTING_INFINIBAND, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
|
||||||
finalize(GObject *object)
|
|
||||||
{
|
|
||||||
NMSettingInfinibandPrivate *priv = NM_SETTING_INFINIBAND_GET_PRIVATE(object);
|
|
||||||
|
|
||||||
g_free(priv->virtual_iface_name);
|
|
||||||
|
|
||||||
G_OBJECT_CLASS(nm_setting_infiniband_parent_class)->finalize(object);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
static void
|
||||||
nm_setting_infiniband_class_init(NMSettingInfinibandClass *klass)
|
nm_setting_infiniband_class_init(NMSettingInfinibandClass *klass)
|
||||||
{
|
{
|
||||||
@@ -373,7 +336,6 @@ nm_setting_infiniband_class_init(NMSettingInfinibandClass *klass)
|
|||||||
|
|
||||||
object_class->get_property = _nm_setting_property_get_property_direct;
|
object_class->get_property = _nm_setting_property_get_property_direct;
|
||||||
object_class->set_property = _nm_setting_property_set_property_direct;
|
object_class->set_property = _nm_setting_property_set_property_direct;
|
||||||
object_class->finalize = finalize;
|
|
||||||
|
|
||||||
setting_class->verify = verify;
|
setting_class->verify = verify;
|
||||||
|
|
||||||
|
@@ -6258,10 +6258,12 @@ test_connection_normalize_infiniband(void)
|
|||||||
#define iface_name(parent, p_key, expected) \
|
#define iface_name(parent, p_key, expected) \
|
||||||
G_STMT_START \
|
G_STMT_START \
|
||||||
{ \
|
{ \
|
||||||
gs_free char *_s = nm_setting_infiniband_create_virtual_interface_name((parent), (p_key)); \
|
char _name[NM_IFNAMSIZ]; \
|
||||||
\
|
\
|
||||||
g_assert(nm_utils_ifname_valid_kernel(_s, NULL)); \
|
nm_net_devname_infiniband(_name, (parent), (p_key)); \
|
||||||
g_assert_cmpstr(_s, ==, (expected)); \
|
\
|
||||||
|
g_assert(nm_utils_ifname_valid_kernel(_name, NULL)); \
|
||||||
|
g_assert_cmpstr(_name, ==, (expected)); \
|
||||||
} \
|
} \
|
||||||
G_STMT_END
|
G_STMT_END
|
||||||
|
|
||||||
|
@@ -323,8 +323,6 @@ typedef gpointer (*NMUtilsCopyFunc)(gpointer);
|
|||||||
const char **
|
const char **
|
||||||
_nm_ip_address_get_attribute_names(const NMIPAddress *addr, gboolean sorted, guint *out_length);
|
_nm_ip_address_get_attribute_names(const NMIPAddress *addr, gboolean sorted, guint *out_length);
|
||||||
|
|
||||||
char *nm_setting_infiniband_create_virtual_interface_name(const char *parent, int p_key);
|
|
||||||
|
|
||||||
#define NM_SETTING_WIRED_S390_OPTION_MAX_LEN 200u
|
#define NM_SETTING_WIRED_S390_OPTION_MAX_LEN 200u
|
||||||
|
|
||||||
void _nm_setting_wired_clear_s390_options(NMSettingWired *setting);
|
void _nm_setting_wired_clear_s390_options(NMSettingWired *setting);
|
||||||
|
Reference in New Issue
Block a user