ryantimwilson / rpms / systemd

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