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

Subscribers

People subscribed via source and target branches