NetworkManager/SOURCES/1019-initrd-generate-infiniband-connections-rh1883173.patch
2021-09-09 22:46:23 +00:00

149 lines
5.6 KiB
Diff

From 566ef706015f01481f9e559c74ea89fc47d9cb6e Mon Sep 17 00:00:00 2001
From: Beniamino Galvani <bgalvani@redhat.com>
Date: Thu, 15 Oct 2020 09:44:52 +0200
Subject: [PATCH] initrd: generate infiniband connections
Generate infiniband connections based on the interface name or MAC
address length.
https://bugzilla.redhat.com/show_bug.cgi?id=1883173
(cherry picked from commit 317171ed6ed4560bb54191a13f71e1daec7f1ea4)
(cherry picked from commit f091730ebc98342036615176738030cbcd4b3d73)
(cherry picked from commit 7665d9b29e1d977e23d3f9b5016cb385938592f2)
---
src/initrd/nmi-cmdline-reader.c | 30 ++++++++++----
src/initrd/tests/test-cmdline-reader.c | 54 ++++++++++++++++++++++++++
2 files changed, 76 insertions(+), 8 deletions(-)
diff --git a/src/initrd/nmi-cmdline-reader.c b/src/initrd/nmi-cmdline-reader.c
index ee3dab2574..257ba3d7ae 100644
--- a/src/initrd/nmi-cmdline-reader.c
+++ b/src/initrd/nmi-cmdline-reader.c
@@ -121,12 +121,21 @@ reader_create_connection (Reader *reader,
NM_SETTING_CONNECTION_MULTI_CONNECT, multi_connect,
NULL);
- if (mac) {
- setting = nm_setting_wired_new ();
+ if (nm_streq0 (type_name, NM_SETTING_INFINIBAND_SETTING_NAME)) {
+ setting = nm_setting_infiniband_new ();
nm_connection_add_setting (connection, setting);
- g_object_set (setting,
- NM_SETTING_WIRED_MAC_ADDRESS, mac,
- NULL);
+ g_object_set (setting, NM_SETTING_INFINIBAND_TRANSPORT_MODE, "datagram", NULL);
+ }
+
+ if (mac) {
+ if (nm_streq0 (type_name, NM_SETTING_INFINIBAND_SETTING_NAME)) {
+ setting = (NMSetting *) nm_connection_get_setting_infiniband (connection);
+ g_object_set (setting, NM_SETTING_INFINIBAND_MAC_ADDRESS, mac, NULL);
+ } else {
+ setting = nm_setting_wired_new ();
+ nm_connection_add_setting (connection, setting);
+ g_object_set (setting, NM_SETTING_WIRED_MAC_ADDRESS, mac, NULL);
+ }
}
return connection;
@@ -166,7 +175,7 @@ reader_get_connection (Reader *reader,
if (nm_utils_is_valid_iface_name (iface_spec, NULL))
ifname = iface_spec;
else {
- mac = nm_utils_hwaddr_canonical (iface_spec, ETH_ALEN);
+ mac = nm_utils_hwaddr_canonical (iface_spec, -1);
if (!mac)
_LOGW (LOGD_CORE, "invalid interface '%s'", iface_spec);
}
@@ -206,8 +215,13 @@ reader_get_connection (Reader *reader,
if (!create_if_missing)
return NULL;
- if (!type_name)
- type_name = NM_SETTING_WIRED_SETTING_NAME;
+ if (!type_name) {
+ if ( NM_STR_HAS_PREFIX (ifname, "ib")
+ || (mac && nm_utils_hwaddr_valid (mac, INFINIBAND_ALEN)))
+ type_name = NM_SETTING_INFINIBAND_SETTING_NAME;
+ else
+ type_name = NM_SETTING_WIRED_SETTING_NAME;
+ }
connection = reader_create_connection (reader, ifname ?: mac,
ifname ?: (mac ?: "Wired Connection"),
diff --git a/src/initrd/tests/test-cmdline-reader.c b/src/initrd/tests/test-cmdline-reader.c
index d67f599337..d6966023a9 100644
--- a/src/initrd/tests/test-cmdline-reader.c
+++ b/src/initrd/tests/test-cmdline-reader.c
@@ -1600,6 +1600,58 @@ test_dhcp_vendor_class_id (void)
g_assert (nm_setting_ip4_config_get_dhcp_vendor_class_identifier (s_ip4) == NULL);
}
+static void
+test_infiniband_iface (void)
+{
+ gs_unref_hashtable GHashTable *connections = NULL;
+ const char *const *ARGV = NM_MAKE_STRV ("ip=ib1:dhcp");
+ NMConnection *connection;
+ NMSettingInfiniband *s_ib;
+ gs_free char *hostname = NULL;
+
+ connections = nmi_cmdline_reader_parse (TEST_INITRD_DIR "/sysfs", ARGV, &hostname);
+ g_assert (connections);
+ g_assert_cmpint (g_hash_table_size (connections), ==, 1);
+ g_assert_cmpstr (hostname, ==, NULL);
+
+ connection = g_hash_table_lookup (connections, "ib1");
+ g_assert (connection);
+ nmtst_assert_connection_verifies_without_normalization (connection);
+ g_assert_cmpstr (nm_connection_get_connection_type (connection),
+ ==,
+ NM_SETTING_INFINIBAND_SETTING_NAME);
+ s_ib = nm_connection_get_setting_infiniband (connection);
+ g_assert (s_ib);
+}
+
+static void
+test_infiniband_mac (void)
+{
+ gs_unref_hashtable GHashTable *connections = NULL;
+ const char *const *ARGV = NM_MAKE_STRV("ip=00-11-22-33-44-55-66-77-88-99-aa-bb-cc-dd-ee-ff-00-11-22-33:dhcp");
+ NMConnection *connection;
+ NMSettingInfiniband *s_ib;
+ gs_free char *hostname = NULL;
+
+ connections = nmi_cmdline_reader_parse (TEST_INITRD_DIR "/sysfs", ARGV, &hostname);
+ g_assert (connections);
+ g_assert_cmpint (g_hash_table_size (connections), ==, 1);
+ g_assert_cmpstr (hostname, ==, NULL);
+
+ connection = g_hash_table_lookup (connections, "00:11:22:33:44:55:66:77:88:99:AA:BB:CC:DD:EE:FF:00:11:22:33");
+ g_assert (connection);
+ nmtst_assert_connection_verifies_without_normalization (connection);
+ g_assert_cmpstr (nm_connection_get_connection_type (connection),
+ ==,
+ NM_SETTING_INFINIBAND_SETTING_NAME);
+ g_assert_cmpstr (nm_connection_get_interface_name (connection), ==, NULL);
+ s_ib = nm_connection_get_setting_infiniband (connection);
+ g_assert (s_ib);
+ g_assert_cmpstr (nm_setting_infiniband_get_mac_address (s_ib),
+ ==,
+ "00:11:22:33:44:55:66:77:88:99:AA:BB:CC:DD:EE:FF:00:11:22:33");
+}
+
NMTST_DEFINE ();
int main (int argc, char **argv)
@@ -1639,6 +1691,8 @@ int main (int argc, char **argv)
g_test_add_func ("/initrd/cmdline/bootif/off", test_bootif_off);
g_test_add_func ("/initrd/cmdline/neednet", test_neednet);
g_test_add_func ("/initrd/cmdline/dhcp/vendor_class_id", test_dhcp_vendor_class_id);
+ g_test_add_func("/initrd/cmdline/infiniband/iface", test_infiniband_iface);
+ g_test_add_func("/initrd/cmdline/infiniband/mac", test_infiniband_mac);
return g_test_run ();
}
--
2.26.2