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

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