Merge ~alfonsosanchezbeato/snappy-hwe-snaps/+git/network-manager:fix-udev-detect into ~snappy-hwe-team/snappy-hwe-snaps/+git/network-manager:snap-20

Proposed by Alfonso Sanchez-Beato
Status: Merged
Approved by: Alfonso Sanchez-Beato
Approved revision: d084e6fd49660f25ee28dd7820c52279585f7ca9
Merged at revision: 58f8d9915301d74ca03e9c6c41fa553dc4bd9ce6
Proposed branch: ~alfonsosanchezbeato/snappy-hwe-snaps/+git/network-manager:fix-udev-detect
Merge into: ~snappy-hwe-team/snappy-hwe-snaps/+git/network-manager:snap-20
Diff against target: 93 lines (+76/-0)
2 files modified
snap-patch/networkmanager/0004-platform-use-also-statvfs-to-check-for-udevd.patch (+72/-0)
tests/main/debug-config-option/task.yaml (+4/-0)
Reviewer Review Type Date Requested Status
System Enablement Bot continuous-integration Approve
Review via email: mp+391889@code.launchpad.net

Commit message

Add patch to use udev even when confined

[PATCH] platform: use also statvfs() to check for udevd

Check whether or not there is a running udevd by using statvfs() on
"/sys" and use access() as a fallback. This is in line with what is
done by systemd [1] and helps in case NM is not really running in a
container but has been confined by a MAC so it does not have full
access to sysfs (access() returns EACCES). Fixes LP:#1712918,
LP:#1893184.

Upstream:
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/commit/9c8275bedcc98d789fa83d2817b9e8ff58f3e7b6

[1] https://github.com/systemd/systemd/blob/v246/src/basic/stat-util.c#L132

Description of the change

Add patch to use udev even when confined

[PATCH] platform: use also statvfs() to check for udevd

Check whether or not there is a running udevd by using statvfs() on
"/sys" and use access() as a fallback. This is in line with what is
done by systemd [1] and helps in case NM is not really running in a
container but has been confined by a MAC so it does not have full
access to sysfs (access() returns EACCES). Fixes LP:#1712918,
LP:#1893184.

Upstream:
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/commit/9c8275bedcc98d789fa83d2817b9e8ff58f3e7b6

[1] https://github.com/systemd/systemd/blob/v246/src/basic/stat-util.c#L132

To post a comment you must log in.
Revision history for this message
System Enablement Bot (system-enablement-ci-bot) wrote :
review: Approve (continuous-integration)
Revision history for this message
System Enablement Bot (system-enablement-ci-bot) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
System Enablement Bot (system-enablement-ci-bot) wrote :
review: Approve (continuous-integration)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/snap-patch/networkmanager/0004-platform-use-also-statvfs-to-check-for-udevd.patch b/snap-patch/networkmanager/0004-platform-use-also-statvfs-to-check-for-udevd.patch
2new file mode 100644
3index 0000000..63e63b2
4--- /dev/null
5+++ b/snap-patch/networkmanager/0004-platform-use-also-statvfs-to-check-for-udevd.patch
6@@ -0,0 +1,72 @@
7+From 78f82d0c6a0c2da1cc4d110d366fadb348e143d1 Mon Sep 17 00:00:00 2001
8+From: =?UTF-8?q?Alfonso=20S=C3=A1nchez-Beato?=
9+ <alfonso.sanchez-beato@canonical.com>
10+Date: Tue, 6 Oct 2020 18:30:11 +0200
11+Subject: [PATCH] platform: use also statvfs() to check for udevd
12+
13+Check whether or not there is a running udevd by using statvfs() on
14+"/sys" and use access() as a fallback. This is in line with what is
15+done by systemd [1] and helps in case NM is not really running in a
16+container but has been confined by a MAC so it does not have full
17+access to sysfs (access() returns EACCES). Fixes LP:#1712918,
18+LP:#1893184.
19+
20+Upstream: https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/commit/9c8275bedcc98d789fa83d2817b9e8ff58f3e7b6
21+
22+[1] https://github.com/systemd/systemd/blob/v246/src/basic/stat-util.c#L132
23+---
24+ src/platform/nm-linux-platform.c | 25 ++++++++++++++++++++++++-
25+ 1 file changed, 24 insertions(+), 1 deletion(-)
26+
27+diff --git a/src/platform/nm-linux-platform.c b/src/platform/nm-linux-platform.c
28+index 7abe4dfc8..2188caa9b 100644
29+--- a/src/platform/nm-linux-platform.c
30++++ b/src/platform/nm-linux-platform.c
31+@@ -26,6 +26,7 @@
32+ #include <poll.h>
33+ #include <sys/ioctl.h>
34+ #include <sys/socket.h>
35++#include <sys/statvfs.h>
36+ #include <unistd.h>
37+
38+ #include "nm-std-aux/unaligned.h"
39+@@ -9182,13 +9183,35 @@ constructed (GObject *_object)
40+ }
41+ }
42+
43++/* Similar to systemd's path_is_read_only_fs(), at
44++ * https://github.com/systemd/systemd/blob/v246/src/basic/stat-util.c#L132 */
45++static int
46++path_is_read_only_fs(const char *path)
47++{
48++ struct statvfs st;
49++
50++ if (statvfs (path, &st) < 0)
51++ return -errno;
52++
53++ if (st.f_flag & ST_RDONLY)
54++ return TRUE;
55++
56++ /* On NFS, statvfs() might not reflect whether we can actually
57++ * write to the remote share. Let's try again with
58++ * access(W_OK) which is more reliable, at least sometimes. */
59++ if (access (path, W_OK) < 0 && errno == EROFS)
60++ return TRUE;
61++
62++ return FALSE;
63++}
64++
65+ NMPlatform *
66+ nm_linux_platform_new (gboolean log_with_ptr, gboolean netns_support)
67+ {
68+ gboolean use_udev = FALSE;
69+
70+ if ( nmp_netns_is_initial ()
71+- && access ("/sys", W_OK) == 0)
72++ && path_is_read_only_fs ("/sys") == FALSE)
73+ use_udev = TRUE;
74+
75+ return g_object_new (NM_TYPE_LINUX_PLATFORM,
76+--
77+2.25.1
78+
79diff --git a/tests/main/debug-config-option/task.yaml b/tests/main/debug-config-option/task.yaml
80index 3ffa20e..56faafc 100644
81--- a/tests/main/debug-config-option/task.yaml
82+++ b/tests/main/debug-config-option/task.yaml
83@@ -18,6 +18,10 @@ execute: |
84 test -f /var/snap/network-manager/current/.debug_enabled
85 network-manager.nmcli g log | MATCH "^DEBUG"
86
87+ # Check that we are using udev (it is a debug only trace)
88+ sleep 10
89+ journalctl --no-pager -u snap.network-manager.networkmanager.service | MATCH 'use udev'
90+
91 snap set network-manager debug.enable=false
92 test "$(snap get network-manager debug.enable)" = "false"
93 # NM will create the file after being re-started by the hook, wait a bit

Subscribers

People subscribed via source and target branches