summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBeniamino Galvani <bgalvani@redhat.com>2020-08-05 16:57:41 +0200
committerBeniamino Galvani <bgalvani@redhat.com>2020-08-06 16:52:35 +0200
commitf114e16fddf854d72a8b08318359569cd83245e3 (patch)
tree96b0bb4e1f2ac4f9e44196ed0469f0318402dc0a
parent0a006c04121a13221de585d3f778c5341f36b504 (diff)
downloadNetworkManager-bg/initrd-wait-rh1853348.tar.gz
initrd: wait for bootdev or all devices if rd.neednet=1bg/initrd-wait-rh1853348
The network-legacy dracut module waits for all ethernet devices if the command line contains rd.neednet=1. It also waits for the device specified by 'bootdev='. Do the same. https://bugzilla.redhat.com/show_bug.cgi?id=1853348
-rw-r--r--src/initrd/nm-initrd-generator.h2
-rw-r--r--src/initrd/nmi-cmdline-reader.c35
-rw-r--r--src/initrd/tests/test-cmdline-reader.c70
3 files changed, 104 insertions, 3 deletions
diff --git a/src/initrd/nm-initrd-generator.h b/src/initrd/nm-initrd-generator.h
index 9719992125..8e17f04555 100644
--- a/src/initrd/nm-initrd-generator.h
+++ b/src/initrd/nm-initrd-generator.h
@@ -9,6 +9,8 @@
#include "nm-connection.h"
#include "nm-utils.h"
+#define NMI_WAIT_DEVICE_TIMEOUT_MS 60000
+
static inline gboolean
guess_ip_address_family (const char *str)
{
diff --git a/src/initrd/nmi-cmdline-reader.c b/src/initrd/nmi-cmdline-reader.c
index 8ba6dbb827..85be9f132e 100644
--- a/src/initrd/nmi-cmdline-reader.c
+++ b/src/initrd/nmi-cmdline-reader.c
@@ -873,6 +873,30 @@ reader_add_nameservers (Reader *reader, GPtrArray *nameservers)
}
}
+static void
+connection_set_needed (NMConnection *connection)
+{
+ NMSettingConnection *s_con;
+
+ s_con = nm_connection_get_setting_connection (connection);
+ if (!nm_streq0 (nm_setting_connection_get_connection_type (s_con),
+ NM_SETTING_WIRED_SETTING_NAME))
+ return;
+
+ if (nm_str_is_empty (nm_setting_connection_get_interface_name (s_con)))
+ return;
+
+ g_object_set (s_con,
+ NM_SETTING_CONNECTION_WAIT_DEVICE_TIMEOUT, NMI_WAIT_DEVICE_TIMEOUT_MS,
+ NULL);
+}
+
+static void
+connection_set_needed_cb (gpointer key, gpointer value, gpointer user_data)
+{
+ connection_set_needed (value);
+}
+
GHashTable *
nmi_cmdline_reader_parse (const char *sysfs_dir, const char *const*argv, char **hostname)
{
@@ -1007,11 +1031,16 @@ nmi_cmdline_reader_parse (const char *sysfs_dir, const char *const*argv, char **
connection = reader_get_connection (reader, bootdev, NULL, TRUE);
reader->bootdev_connection = connection;
+ connection_set_needed (connection);
}
- if (neednet && g_hash_table_size (reader->hash) == 0) {
- /* Make sure there's some connection. */
- reader_get_default_connection (reader);
+ if (neednet) {
+ if (g_hash_table_size (reader->hash) == 0) {
+ /* Make sure there's some connection. */
+ reader_get_default_connection (reader);
+ }
+
+ g_hash_table_foreach (reader->hash, connection_set_needed_cb, NULL);
}
if (routes)
diff --git a/src/initrd/tests/test-cmdline-reader.c b/src/initrd/tests/test-cmdline-reader.c
index 074654d347..7787cf5ea0 100644
--- a/src/initrd/tests/test-cmdline-reader.c
+++ b/src/initrd/tests/test-cmdline-reader.c
@@ -49,6 +49,7 @@ test_auto (void)
g_assert_cmpstr (nm_setting_connection_get_id (s_con), ==, "Wired Connection");
g_assert_cmpint (nm_setting_connection_get_timestamp (s_con), ==, 0);
g_assert_cmpint (nm_setting_connection_get_multi_connect (s_con), ==, NM_CONNECTION_MULTI_CONNECT_MULTIPLE);
+ g_assert_cmpint (nm_setting_connection_get_wait_device_timeout (s_con), ==, -1);
g_assert (nm_setting_connection_get_autoconnect (s_con));
@@ -190,6 +191,7 @@ test_if_ip4_manual (void)
"ip=203.0.113.2::203.0.113.1:26:"
"hostname1.example.com:eth4");
NMConnection *connection;
+ NMSettingConnection *s_con;
NMSettingIPConfig *s_ip4;
NMSettingIPConfig *s_ip6;
NMIPAddress *ip_addr;
@@ -205,6 +207,10 @@ test_if_ip4_manual (void)
nmtst_assert_connection_verifies_without_normalization (connection);
g_assert_cmpstr (nm_connection_get_id (connection), ==, "eth3");
+ s_con = nm_connection_get_setting_connection (connection);
+ g_assert (s_con);
+ g_assert_cmpint (nm_setting_connection_get_wait_device_timeout (s_con), ==, -1);
+
s_ip4 = nm_connection_get_setting_ip4_config (connection);
g_assert (s_ip4);
g_assert_cmpstr (nm_setting_ip_config_get_method (s_ip4), ==, NM_SETTING_IP4_CONFIG_METHOD_MANUAL);
@@ -294,6 +300,7 @@ test_multiple_merge (void)
const char *const*ARGV = NM_MAKE_STRV ("ip=192.0.2.2:::::eth0",
"ip=[2001:db8::2]:::::eth0");
NMConnection *connection;
+ NMSettingConnection *s_con;
NMSettingWired *s_wired;
NMSettingIPConfig *s_ip4;
NMSettingIPConfig *s_ip6;
@@ -310,6 +317,10 @@ test_multiple_merge (void)
nmtst_assert_connection_verifies_without_normalization (connection);
g_assert_cmpstr (nm_connection_get_id (connection), ==, "eth0");
+ s_con = nm_connection_get_setting_connection (connection);
+ g_assert (s_con);
+ g_assert_cmpint (nm_setting_connection_get_wait_device_timeout (s_con), ==, -1);
+
s_wired = nm_connection_get_setting_wired (connection);
g_assert (s_wired);
@@ -341,6 +352,7 @@ test_multiple_bootdev (void)
"ip=eth4:dhcp",
"bootdev=eth4");
NMConnection *connection;
+ NMSettingConnection *s_con;
NMSettingIPConfig *s_ip4;
NMSettingIPConfig *s_ip6;
gs_free char *hostname = NULL;
@@ -352,12 +364,18 @@ test_multiple_bootdev (void)
connection = g_hash_table_lookup (connections, "eth3");
g_assert (connection);
+ s_con = nm_connection_get_setting_connection (connection);
+ g_assert (s_con);
+ g_assert_cmpint (nm_setting_connection_get_wait_device_timeout (s_con), ==, -1);
s_ip6 = nm_connection_get_setting_ip6_config (connection);
g_assert (s_ip6);
g_assert_cmpstr (nm_setting_ip_config_get_method (s_ip6), ==, NM_SETTING_IP6_CONFIG_METHOD_AUTO);
connection = g_hash_table_lookup (connections, "eth4");
g_assert (connection);
+ s_con = nm_connection_get_setting_connection (connection);
+ g_assert (s_con);
+ g_assert_cmpint (nm_setting_connection_get_wait_device_timeout (s_con), ==, NMI_WAIT_DEVICE_TIMEOUT_MS);
s_ip4 = nm_connection_get_setting_ip4_config (connection);
g_assert (s_ip4);
g_assert_cmpstr (nm_setting_ip_config_get_method (s_ip4), ==, NM_SETTING_IP4_CONFIG_METHOD_AUTO);
@@ -388,6 +406,7 @@ test_bootdev (void)
g_assert_cmpstr (nm_setting_connection_get_connection_type (s_con), ==, NM_SETTING_WIRED_SETTING_NAME);
g_assert_cmpstr (nm_setting_connection_get_id (s_con), ==, "ens3");
g_assert_cmpstr (nm_setting_connection_get_interface_name (s_con), ==, "ens3");
+ g_assert_cmpint (nm_setting_connection_get_wait_device_timeout(s_con), ==, NMI_WAIT_DEVICE_TIMEOUT_MS);
connection = g_hash_table_lookup (connections, "vlan2");
g_assert (connection);
@@ -1256,6 +1275,56 @@ test_bootif_ip (void)
}
static void
+test_neednet (void)
+{
+ gs_unref_hashtable GHashTable *connections = NULL;
+ const char *const*ARGV = NM_MAKE_STRV ("rd.neednet",
+ "ip=eno1:dhcp",
+ "ip=172.25.1.100::172.25.1.1:24::eno2",
+ "bridge=br0:eno3");
+ NMConnection *connection;
+ NMSettingConnection *s_con;
+ 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), ==, 4);
+ g_assert_cmpstr (hostname, ==, NULL);
+
+ connection = g_hash_table_lookup (connections, "eno1");
+ g_assert (connection);
+ nmtst_assert_connection_verifies_without_normalization (connection);
+ s_con = nm_connection_get_setting_connection (connection);
+ g_assert (s_con);
+ g_assert_cmpstr (nm_setting_connection_get_interface_name (s_con), ==, "eno1");
+ g_assert_cmpint (nm_setting_connection_get_wait_device_timeout (s_con), ==, NMI_WAIT_DEVICE_TIMEOUT_MS);
+
+ connection = g_hash_table_lookup (connections, "eno2");
+ g_assert (connection);
+ nmtst_assert_connection_verifies_without_normalization (connection);
+ s_con = nm_connection_get_setting_connection (connection);
+ g_assert (s_con);
+ g_assert_cmpstr (nm_setting_connection_get_interface_name (s_con), ==, "eno2");
+ g_assert_cmpint (nm_setting_connection_get_wait_device_timeout (s_con), ==, NMI_WAIT_DEVICE_TIMEOUT_MS);
+
+ connection = g_hash_table_lookup (connections, "eno3");
+ g_assert (connection);
+ nmtst_assert_connection_verifies_without_normalization (connection);
+ s_con = nm_connection_get_setting_connection (connection);
+ g_assert (s_con);
+ g_assert_cmpstr (nm_setting_connection_get_interface_name (s_con), ==, "eno3");
+ g_assert_cmpint (nm_setting_connection_get_wait_device_timeout (s_con), ==, NMI_WAIT_DEVICE_TIMEOUT_MS);
+
+ connection = g_hash_table_lookup (connections, "br0");
+ g_assert (connection);
+ nmtst_assert_connection_verifies_without_normalization (connection);
+ s_con = nm_connection_get_setting_connection (connection);
+ g_assert (s_con);
+ g_assert_cmpstr (nm_setting_connection_get_interface_name (s_con), ==, "br0");
+ g_assert_cmpint (nm_setting_connection_get_wait_device_timeout (s_con), ==, -1);
+}
+
+static void
test_bootif_no_ip (void)
{
gs_unref_hashtable GHashTable *connections = NULL;
@@ -1451,6 +1520,7 @@ int main (int argc, char **argv)
g_test_add_func ("/initrd/cmdline/bootif/no_ip", test_bootif_no_ip);
g_test_add_func ("/initrd/cmdline/bootif/hwtype", test_bootif_hwtype);
g_test_add_func ("/initrd/cmdline/bootif/off", test_bootif_off);
+ g_test_add_func ("/initrd/cmdline/neednet", test_neednet);
return g_test_run ();
}