mirror of
https://gitlab.freedesktop.org/NetworkManager/NetworkManager.git
synced 2026-01-14 11:20:28 +01:00
initrd: wait for bootdev or all devices if rd.neednet=1
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
(cherry picked from commit f114e16fdd)
This commit is contained in:
parent
e2830af77a
commit
98ccd2a10e
3 changed files with 104 additions and 3 deletions
|
|
@ -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)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
@ -1255,6 +1274,56 @@ test_bootif_ip (void)
|
|||
g_assert (!nm_setting_ip_config_get_ignore_auto_dns (s_ip6));
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
|
|
@ -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 ();
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue