teknoraver / rpms / systemd

Forked from rpms/systemd 3 months ago
Clone

Blame SOURCES/0212-mount-simplify-proc-self-mountinfo-handler.patch

4fbe94
From daf63a3c6c6cd241017bdf9a26c7b1caf744e69b Mon Sep 17 00:00:00 2001
4fbe94
From: Lennart Poettering <lennart@poettering.net>
4fbe94
Date: Wed, 17 Jul 2019 14:53:07 +0200
4fbe94
Subject: [PATCH] mount: simplify /proc/self/mountinfo handler
4fbe94
4fbe94
Our IO handler is only installed for one fd, hence there's no reason to
4fbe94
conditionalize on it again.
4fbe94
4fbe94
Also, split out the draining into a helper function of its own.
4fbe94
4fbe94
(cherry picked from commit fcd8e119c28be19ffbc5227089cf4d3b8ba60238)
4fbe94
4fbe94
Conflicts:
4fbe94
	src/core/mount.c
4fbe94
4fbe94
Related: #1696178
4fbe94
---
4fbe94
 src/core/mount.c | 48 ++++++++++++++++++++++++++----------------------
4fbe94
 1 file changed, 26 insertions(+), 22 deletions(-)
4fbe94
4fbe94
diff --git a/src/core/mount.c b/src/core/mount.c
4fbe94
index 16229d4af1..85b07375e2 100644
4fbe94
--- a/src/core/mount.c
4fbe94
+++ b/src/core/mount.c
4fbe94
@@ -1758,6 +1758,29 @@ fail:
4fbe94
         mount_shutdown(m);
4fbe94
 }
4fbe94
 
4fbe94
+static int drain_libmount(Manager *m) {
4fbe94
+        bool rescan = false;
4fbe94
+        int r;
4fbe94
+
4fbe94
+        assert(m);
4fbe94
+
4fbe94
+        /* Drain all events and verify that the event is valid.
4fbe94
+         *
4fbe94
+         * Note that libmount also monitors /run/mount mkdir if the directory does not exist yet. The mkdir
4fbe94
+         * may generate event which is irrelevant for us.
4fbe94
+         *
4fbe94
+         * error: r < 0; valid: r == 0, false positive: r == 1 */
4fbe94
+        do {
4fbe94
+                r = mnt_monitor_next_change(m->mount_monitor, NULL, NULL);
4fbe94
+                if (r < 0)
4fbe94
+                        return log_error_errno(r, "Failed to drain libmount events: %m");
4fbe94
+                if (r == 0)
4fbe94
+                        rescan = true;
4fbe94
+        } while (r == 0);
4fbe94
+
4fbe94
+        return rescan;
4fbe94
+}
4fbe94
+
4fbe94
 static int mount_dispatch_io(sd_event_source *source, int fd, uint32_t revents, void *userdata) {
4fbe94
         _cleanup_set_free_ Set *around = NULL, *gone = NULL;
4fbe94
         Manager *m = userdata;
4fbe94
@@ -1769,28 +1792,9 @@ static int mount_dispatch_io(sd_event_source *source, int fd, uint32_t revents,
4fbe94
         assert(m);
4fbe94
         assert(revents & EPOLLIN);
4fbe94
 
4fbe94
-        if (fd == mnt_monitor_get_fd(m->mount_monitor)) {
4fbe94
-                bool rescan = false;
4fbe94
-
4fbe94
-                /* Drain all events and verify that the event is valid.
4fbe94
-                 *
4fbe94
-                 * Note that libmount also monitors /run/mount mkdir if the
4fbe94
-                 * directory does not exist yet. The mkdir may generate event
4fbe94
-                 * which is irrelevant for us.
4fbe94
-                 *
4fbe94
-                 * error: r < 0; valid: r == 0, false positive: rc == 1 */
4fbe94
-                do {
4fbe94
-                        r = mnt_monitor_next_change(m->mount_monitor, NULL, NULL);
4fbe94
-                        if (r == 0)
4fbe94
-                                rescan = true;
4fbe94
-                        else if (r < 0)
4fbe94
-                                return log_error_errno(r, "Failed to drain libmount events");
4fbe94
-                } while (r == 0);
4fbe94
-
4fbe94
-                log_debug("libmount event [rescan: %s]", yes_no(rescan));
4fbe94
-                if (!rescan)
4fbe94
-                        return 0;
4fbe94
-        }
4fbe94
+        r = drain_libmount(m);
4fbe94
+        if (r <= 0)
4fbe94
+                return r;
4fbe94
 
4fbe94
         r = mount_load_proc_self_mountinfo(m, true);
4fbe94
         if (r < 0) {