diff options
author | Pavel Zhukov <pavel@zhukoff.net> | 2022-02-05 21:33:22 +0100 |
---|---|---|
committer | Richard Purdie <richard.purdie@linuxfoundation.org> | 2022-02-07 10:08:59 +0000 |
commit | 8b569369961d80e27c0aa711c761ee8da0692fc3 (patch) | |
tree | d787ca56698ccec8a89e1f76d350fde37e8f9b19 | |
parent | d366a1a2234421dc988d20ee30f8b7ccc87b21e3 (diff) | |
download | poky-8b569369961d80e27c0aa711c761ee8da0692fc3.tar.gz |
systemd: enable KeepConfiguration= when running on network filesystem
This fix boot from NFS for systemd enabled systems. Previously
systemd-networkd dropped network configuration on exit from initrd even
if there're NFS mount.
[YOCTO #14708]
(From OE-Core rev: afb6b1625a43d64eba090f0f4c5e231d87df7833)
Signed-off-by: Pavel Zhukov <pavel.zhukov@huawei.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
-rw-r--r-- | meta/recipes-core/systemd/systemd/0029-network-enable-KeepConfiguration-when-running-on-net.patch | 253 | ||||
-rw-r--r-- | meta/recipes-core/systemd/systemd_250.3.bb | 1 |
2 files changed, 254 insertions, 0 deletions
diff --git a/meta/recipes-core/systemd/systemd/0029-network-enable-KeepConfiguration-when-running-on-net.patch b/meta/recipes-core/systemd/systemd/0029-network-enable-KeepConfiguration-when-running-on-net.patch new file mode 100644 index 0000000000..782b9645cb --- /dev/null +++ b/meta/recipes-core/systemd/systemd/0029-network-enable-KeepConfiguration-when-running-on-net.patch | |||
@@ -0,0 +1,253 @@ | |||
1 | From 6f4e84126aaa4e26cb6865b054ea5ddebd3906e5 Mon Sep 17 00:00:00 2001 | ||
2 | From: Yu Watanabe <watanabe.yu+github@gmail.com> | ||
3 | Date: Thu, 3 Feb 2022 12:14:19 +0900 | ||
4 | Subject: [PATCH] network: enable KeepConfiguration= when running on network | ||
5 | filesystem | ||
6 | Cc: pavel@zhukoff.net | ||
7 | |||
8 | Upstream-Status: Submitted [https://github.com/systemd/systemd/pull/22383] | ||
9 | [YOCTO #14708] | ||
10 | |||
11 | network-generator: rename DHCP_TYPE_DHCP -> DHCP_TYPE_DHCP4 | ||
12 | |||
13 | To emphasize this is DHCPv4. No behavior is changed. | ||
14 | |||
15 | stat-util: introduce path_is_network_fs() | ||
16 | |||
17 | network: enable KeepConfiguration= when running on network filesystem | ||
18 | |||
19 | Also, set KeepConfiguration=dhcp-on-stop by default when running in | ||
20 | initrd. | ||
21 | |||
22 | Fixes #21967. | ||
23 | --- | ||
24 | man/systemd.network.xml | 6 +++-- | ||
25 | src/basic/stat-util.c | 9 +++++++ | ||
26 | src/basic/stat-util.h | 1 + | ||
27 | src/network/generator/network-generator.c | 4 ++-- | ||
28 | src/network/generator/network-generator.h | 2 +- | ||
29 | src/network/networkd-manager.c | 29 +++++++++++++++++++++++ | ||
30 | src/network/networkd-manager.h | 2 ++ | ||
31 | src/network/networkd-network.c | 12 ++++++---- | ||
32 | src/network/test-networkd-conf.c | 5 ++++ | ||
33 | 9 files changed, 60 insertions(+), 10 deletions(-) | ||
34 | |||
35 | diff --git a/man/systemd.network.xml b/man/systemd.network.xml | ||
36 | index af431e4f2c..f90cff4cd6 100644 | ||
37 | --- a/man/systemd.network.xml | ||
38 | +++ b/man/systemd.network.xml | ||
39 | @@ -944,8 +944,10 @@ Table=1234</programlisting></para> | ||
40 | lease expires. This is contrary to the DHCP specification, but may be the best choice if, | ||
41 | e.g., the root filesystem relies on this connection. The setting <literal>dhcp</literal> | ||
42 | implies <literal>dhcp-on-stop</literal>, and <literal>yes</literal> implies | ||
43 | - <literal>dhcp</literal> and <literal>static</literal>. Defaults to <literal>no</literal>. | ||
44 | - </para> | ||
45 | + <literal>dhcp</literal> and <literal>static</literal>. Defaults to | ||
46 | + <literal>dhcp-on-stop</literal> when <command>systemd-networkd</command> is running in | ||
47 | + initrd, <literal>yes</literal> when the root filesystem is a network filesystem, and | ||
48 | + <literal>no</literal> otherwise.</para> | ||
49 | </listitem> | ||
50 | </varlistentry> | ||
51 | </variablelist> | ||
52 | diff --git a/src/basic/stat-util.c b/src/basic/stat-util.c | ||
53 | index efac7b002e..c2269844f8 100644 | ||
54 | --- a/src/basic/stat-util.c | ||
55 | +++ b/src/basic/stat-util.c | ||
56 | @@ -249,6 +249,15 @@ int path_is_temporary_fs(const char *path) { | ||
57 | return is_temporary_fs(&s); | ||
58 | } | ||
59 | |||
60 | +int path_is_network_fs(const char *path) { | ||
61 | + struct statfs s; | ||
62 | + | ||
63 | + if (statfs(path, &s) < 0) | ||
64 | + return -errno; | ||
65 | + | ||
66 | + return is_network_fs(&s); | ||
67 | +} | ||
68 | + | ||
69 | int stat_verify_regular(const struct stat *st) { | ||
70 | assert(st); | ||
71 | |||
72 | diff --git a/src/basic/stat-util.h b/src/basic/stat-util.h | ||
73 | index a566114f7c..f7d2f12aa9 100644 | ||
74 | --- a/src/basic/stat-util.h | ||
75 | +++ b/src/basic/stat-util.h | ||
76 | @@ -53,6 +53,7 @@ int fd_is_temporary_fs(int fd); | ||
77 | int fd_is_network_fs(int fd); | ||
78 | |||
79 | int path_is_temporary_fs(const char *path); | ||
80 | +int path_is_network_fs(const char *path); | ||
81 | |||
82 | /* Because statfs.t_type can be int on some architectures, we have to cast | ||
83 | * the const magic to the type, otherwise the compiler warns about | ||
84 | diff --git a/src/network/generator/network-generator.c b/src/network/generator/network-generator.c | ||
85 | index c081ec673c..063ad08d80 100644 | ||
86 | --- a/src/network/generator/network-generator.c | ||
87 | +++ b/src/network/generator/network-generator.c | ||
88 | @@ -47,7 +47,7 @@ static const char * const dracut_dhcp_type_table[_DHCP_TYPE_MAX] = { | ||
89 | [DHCP_TYPE_OFF] = "off", | ||
90 | [DHCP_TYPE_ON] = "on", | ||
91 | [DHCP_TYPE_ANY] = "any", | ||
92 | - [DHCP_TYPE_DHCP] = "dhcp", | ||
93 | + [DHCP_TYPE_DHCP4] = "dhcp", | ||
94 | [DHCP_TYPE_DHCP6] = "dhcp6", | ||
95 | [DHCP_TYPE_AUTO6] = "auto6", | ||
96 | [DHCP_TYPE_EITHER6] = "either6", | ||
97 | @@ -62,7 +62,7 @@ static const char * const networkd_dhcp_type_table[_DHCP_TYPE_MAX] = { | ||
98 | [DHCP_TYPE_OFF] = "no", | ||
99 | [DHCP_TYPE_ON] = "yes", | ||
100 | [DHCP_TYPE_ANY] = "yes", | ||
101 | - [DHCP_TYPE_DHCP] = "ipv4", | ||
102 | + [DHCP_TYPE_DHCP4] = "ipv4", | ||
103 | [DHCP_TYPE_DHCP6] = "ipv6", | ||
104 | [DHCP_TYPE_AUTO6] = "no", /* TODO: enable other setting? */ | ||
105 | [DHCP_TYPE_EITHER6] = "ipv6", /* TODO: enable other setting? */ | ||
106 | diff --git a/src/network/generator/network-generator.h b/src/network/generator/network-generator.h | ||
107 | index dd0a58738b..0e0da2a57a 100644 | ||
108 | --- a/src/network/generator/network-generator.h | ||
109 | +++ b/src/network/generator/network-generator.h | ||
110 | @@ -13,7 +13,7 @@ typedef enum DHCPType { | ||
111 | DHCP_TYPE_OFF, | ||
112 | DHCP_TYPE_ON, | ||
113 | DHCP_TYPE_ANY, | ||
114 | - DHCP_TYPE_DHCP, | ||
115 | + DHCP_TYPE_DHCP4, | ||
116 | DHCP_TYPE_DHCP6, | ||
117 | DHCP_TYPE_AUTO6, | ||
118 | DHCP_TYPE_EITHER6, | ||
119 | diff --git a/src/network/networkd-manager.c b/src/network/networkd-manager.c | ||
120 | index 7e89366ae8..3261f289e9 100644 | ||
121 | --- a/src/network/networkd-manager.c | ||
122 | +++ b/src/network/networkd-manager.c | ||
123 | @@ -398,6 +398,30 @@ static int signal_restart_callback(sd_event_source *s, const struct signalfd_sig | ||
124 | return sd_event_exit(sd_event_source_get_event(s), 0); | ||
125 | } | ||
126 | |||
127 | +static int manager_set_keep_configuration(Manager *m) { | ||
128 | + int r; | ||
129 | + | ||
130 | + assert(m); | ||
131 | + | ||
132 | + if (in_initrd()) { | ||
133 | + log_debug("Running in initrd, keep DHCPv4 addresses on stopping networkd by default."); | ||
134 | + m->keep_configuration = KEEP_CONFIGURATION_DHCP_ON_STOP; | ||
135 | + return 0; | ||
136 | + } | ||
137 | + | ||
138 | + r = path_is_network_fs("/"); | ||
139 | + if (r < 0) | ||
140 | + return log_error_errno(r, "Failed to detect if root is network filesystem: %m"); | ||
141 | + if (r == 0) { | ||
142 | + m->keep_configuration = _KEEP_CONFIGURATION_INVALID; | ||
143 | + return 0; | ||
144 | + } | ||
145 | + | ||
146 | + log_debug("Running on network filesystem, enabling KeepConfiguration= by default."); | ||
147 | + m->keep_configuration = KEEP_CONFIGURATION_YES; | ||
148 | + return 0; | ||
149 | +} | ||
150 | + | ||
151 | int manager_setup(Manager *m) { | ||
152 | int r; | ||
153 | |||
154 | @@ -453,6 +477,10 @@ int manager_setup(Manager *m) { | ||
155 | if (r < 0) | ||
156 | return r; | ||
157 | |||
158 | + r = manager_set_keep_configuration(m); | ||
159 | + if (r < 0) | ||
160 | + return r; | ||
161 | + | ||
162 | m->state_file = strdup("/run/systemd/netif/state"); | ||
163 | if (!m->state_file) | ||
164 | return -ENOMEM; | ||
165 | @@ -468,6 +496,7 @@ int manager_new(Manager **ret, bool test_mode) { | ||
166 | return -ENOMEM; | ||
167 | |||
168 | *m = (Manager) { | ||
169 | + .keep_configuration = _KEEP_CONFIGURATION_INVALID, | ||
170 | .test_mode = test_mode, | ||
171 | .speed_meter_interval_usec = SPEED_METER_DEFAULT_TIME_INTERVAL, | ||
172 | .online_state = _LINK_ONLINE_STATE_INVALID, | ||
173 | diff --git a/src/network/networkd-manager.h b/src/network/networkd-manager.h | ||
174 | index 36313589a3..86de529124 100644 | ||
175 | --- a/src/network/networkd-manager.h | ||
176 | +++ b/src/network/networkd-manager.h | ||
177 | @@ -28,6 +28,8 @@ struct Manager { | ||
178 | Hashmap *polkit_registry; | ||
179 | int ethtool_fd; | ||
180 | |||
181 | + KeepConfiguration keep_configuration; | ||
182 | + | ||
183 | bool test_mode; | ||
184 | bool enumerating; | ||
185 | bool dirty; | ||
186 | diff --git a/src/network/networkd-network.c b/src/network/networkd-network.c | ||
187 | index 3142be471f..edcd68d616 100644 | ||
188 | --- a/src/network/networkd-network.c | ||
189 | +++ b/src/network/networkd-network.c | ||
190 | @@ -124,6 +124,7 @@ int network_verify(Network *network) { | ||
191 | int r; | ||
192 | |||
193 | assert(network); | ||
194 | + assert(network->manager); | ||
195 | assert(network->filename); | ||
196 | |||
197 | if (net_match_is_empty(&network->match) && !network->conditions) | ||
198 | @@ -248,10 +249,11 @@ int network_verify(Network *network) { | ||
199 | } | ||
200 | |||
201 | if (network->dhcp_critical >= 0) { | ||
202 | - if (network->keep_configuration >= 0) | ||
203 | - log_warning("%s: Both KeepConfiguration= and deprecated CriticalConnection= are set. " | ||
204 | - "Ignoring CriticalConnection=.", network->filename); | ||
205 | - else if (network->dhcp_critical) | ||
206 | + if (network->keep_configuration >= 0) { | ||
207 | + if (network->manager->keep_configuration < 0) | ||
208 | + log_warning("%s: Both KeepConfiguration= and deprecated CriticalConnection= are set. " | ||
209 | + "Ignoring CriticalConnection=.", network->filename); | ||
210 | + } else if (network->dhcp_critical) | ||
211 | /* CriticalConnection=yes also preserve foreign static configurations. */ | ||
212 | network->keep_configuration = KEEP_CONFIGURATION_YES; | ||
213 | else | ||
214 | @@ -386,7 +388,7 @@ int network_load_one(Manager *manager, OrderedHashmap **networks, const char *fi | ||
215 | .allmulticast = -1, | ||
216 | .promiscuous = -1, | ||
217 | |||
218 | - .keep_configuration = _KEEP_CONFIGURATION_INVALID, | ||
219 | + .keep_configuration = manager->keep_configuration, | ||
220 | |||
221 | .dhcp_duid.type = _DUID_TYPE_INVALID, | ||
222 | .dhcp_critical = -1, | ||
223 | diff --git a/src/network/test-networkd-conf.c b/src/network/test-networkd-conf.c | ||
224 | index 4b00a98086..5f1328e39c 100644 | ||
225 | --- a/src/network/test-networkd-conf.c | ||
226 | +++ b/src/network/test-networkd-conf.c | ||
227 | @@ -6,6 +6,7 @@ | ||
228 | #include "net-condition.h" | ||
229 | #include "networkd-address.h" | ||
230 | #include "networkd-conf.h" | ||
231 | +#include "networkd-manager.h" | ||
232 | #include "networkd-network.h" | ||
233 | #include "strv.h" | ||
234 | |||
235 | @@ -166,11 +167,15 @@ static void test_config_parse_ether_addr(void) { | ||
236 | } | ||
237 | |||
238 | static void test_config_parse_address_one(const char *rvalue, int family, unsigned n_addresses, const union in_addr_union *u, unsigned char prefixlen) { | ||
239 | + _cleanup_(manager_freep) Manager *manager = NULL; | ||
240 | _cleanup_(network_unrefp) Network *network = NULL; | ||
241 | |||
242 | + assert_se(manager_new(&manager, /* test_mode = */ true) >= 0); | ||
243 | assert_se(network = new0(Network, 1)); | ||
244 | network->n_ref = 1; | ||
245 | + network->manager = manager; | ||
246 | assert_se(network->filename = strdup("hogehoge.network")); | ||
247 | + | ||
248 | assert_se(config_parse_match_ifnames("network", "filename", 1, "section", 1, "Name", 0, "*", &network->match.ifname, network) == 0); | ||
249 | assert_se(config_parse_address("network", "filename", 1, "section", 1, "Address", 0, rvalue, network, network) == 0); | ||
250 | assert_se(ordered_hashmap_size(network->addresses_by_section) == 1); | ||
251 | -- | ||
252 | 2.34.1 | ||
253 | |||
diff --git a/meta/recipes-core/systemd/systemd_250.3.bb b/meta/recipes-core/systemd/systemd_250.3.bb index 7851c4c16a..0fe5fb7976 100644 --- a/meta/recipes-core/systemd/systemd_250.3.bb +++ b/meta/recipes-core/systemd/systemd_250.3.bb | |||
@@ -26,6 +26,7 @@ SRC_URI += "file://touchscreen.rules \ | |||
26 | file://0001-systemd.pc.in-use-ROOTPREFIX-without-suffixed-slash.patch \ | 26 | file://0001-systemd.pc.in-use-ROOTPREFIX-without-suffixed-slash.patch \ |
27 | file://0001-test-parse-argument-Include-signal.h.patch \ | 27 | file://0001-test-parse-argument-Include-signal.h.patch \ |
28 | file://0001-mkdir-allow-to-create-directory-whose-path-contains-.patch \ | 28 | file://0001-mkdir-allow-to-create-directory-whose-path-contains-.patch \ |
29 | file://0029-network-enable-KeepConfiguration-when-running-on-net.patch \ | ||
29 | " | 30 | " |
30 | 31 | ||
31 | # patches needed by musl | 32 | # patches needed by musl |