]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
mount: simplify /proc/self/mountinfo handler
authorLennart Poettering <lennart@poettering.net>
Wed, 17 Jul 2019 12:53:07 +0000 (14:53 +0200)
committerLennart Poettering <lennart@poettering.net>
Thu, 18 Jul 2019 15:03:10 +0000 (17:03 +0200)
Our IO handler is only installed for one fd, hence there's no reason to
conditionalize on it again.

Also, split out the draining into a helper function of its own.

src/core/mount.c

index e32db2bf630a489b1a9823c40dbfbebbbf9989c8..8638b878547d23ade3e0d1bbfe58d068da6b0ce8 100644 (file)
@@ -1751,6 +1751,29 @@ fail:
         mount_shutdown(m);
 }
 
+static int drain_libmount(Manager *m) {
+        bool rescan = false;
+        int r;
+
+        assert(m);
+
+        /* Drain all events and verify that the event is valid.
+         *
+         * Note that libmount also monitors /run/mount mkdir if the directory does not exist yet. The mkdir
+         * may generate event which is irrelevant for us.
+         *
+         * error: r < 0; valid: r == 0, false positive: r == 1 */
+        do {
+                r = mnt_monitor_next_change(m->mount_monitor, NULL, NULL);
+                if (r < 0)
+                        return log_error_errno(r, "Failed to drain libmount events: %m");
+                if (r == 0)
+                        rescan = true;
+        } while (r == 0);
+
+        return rescan;
+}
+
 static int mount_dispatch_io(sd_event_source *source, int fd, uint32_t revents, void *userdata) {
         _cleanup_set_free_free_ Set *around = NULL, *gone = NULL;
         Manager *m = userdata;
@@ -1762,28 +1785,9 @@ static int mount_dispatch_io(sd_event_source *source, int fd, uint32_t revents,
         assert(m);
         assert(revents & EPOLLIN);
 
-        if (fd == mnt_monitor_get_fd(m->mount_monitor)) {
-                bool rescan = false;
-
-                /* Drain all events and verify that the event is valid.
-                 *
-                 * Note that libmount also monitors /run/mount mkdir if the
-                 * directory does not exist yet. The mkdir may generate event
-                 * which is irrelevant for us.
-                 *
-                 * error: r < 0; valid: r == 0, false positive: rc == 1 */
-                do {
-                        r = mnt_monitor_next_change(m->mount_monitor, NULL, NULL);
-                        if (r == 0)
-                                rescan = true;
-                        else if (r < 0)
-                                return log_error_errno(r, "Failed to drain libmount events: %m");
-                } while (r == 0);
-
-                log_debug("libmount event [rescan: %s]", yes_no(rescan));
-                if (!rescan)
-                        return 0;
-        }
+        r = drain_libmount(m);
+        if (r <= 0)
+                return r;
 
         r = mount_load_proc_self_mountinfo(m, true);
         if (r < 0) {