[tracker-miners/wip/carlosg/fanotify-fallback: 2/2] libtracker-miner: Make FANotify monitor a subclass of GLib monitor




commit 28142bdb5e3b96e0e7328322f3a880d97a6cdca0
Author: Carlos Garnacho <carlosg gnome org>
Date:   Mon Feb 14 00:37:41 2022 +0100

    libtracker-miner: Make FANotify monitor a subclass of GLib monitor
    
    And fallback into GLib for the situations that FANotify cannot set
    up a mark despite being detected at runtime.
    
    Unfortunately, a growingly common situation for this are btrfs
    subvolumes. These are currently problematic with FANotify due to
    filesystem ID mismatches, thus EXDEV is currently returned. See
    https://lore.kernel.org/all/CAOQ4uxjt2+BECu60aisZs_D6pgHK3VbBjju6hzmvG=Ls88UqUA mail gmail com/
    for a description of the problem.
    
    Hopefully this situation will be resolved at some point, in the
    mean time, transparently fallback to the old situation for users
    of btrfs.
    
    Closes: https://gitlab.gnome.org/GNOME/tracker-miners/-/issues/212

 src/libtracker-miner/tracker-monitor-fanotify.c | 46 +++++++++++++++++++++----
 src/libtracker-miner/tracker-monitor-fanotify.h |  4 +--
 src/libtracker-miner/tracker-monitor-glib.c     |  4 ---
 src/libtracker-miner/tracker-monitor-glib.h     | 10 ++++--
 4 files changed, 49 insertions(+), 15 deletions(-)
---
diff --git a/src/libtracker-miner/tracker-monitor-fanotify.c b/src/libtracker-miner/tracker-monitor-fanotify.c
index 9ccd7379e..86f7878ef 100644
--- a/src/libtracker-miner/tracker-monitor-fanotify.c
+++ b/src/libtracker-miner/tracker-monitor-fanotify.c
@@ -104,10 +104,12 @@ enum {
        PROP_IGNORED,
 };
 
+static GInitableIface *initable_parent_iface = NULL;
+
 static void tracker_monitor_fanotify_initable_iface_init (GInitableIface *iface);
 
 G_DEFINE_TYPE_WITH_CODE (TrackerMonitorFanotify, tracker_monitor_fanotify,
-                         TRACKER_TYPE_MONITOR,
+                         TRACKER_TYPE_MONITOR_GLIB,
                          G_IMPLEMENT_INTERFACE (G_TYPE_INITABLE,
                                                 tracker_monitor_fanotify_initable_iface_init))
 
@@ -446,7 +448,7 @@ tracker_monitor_fanotify_initable_init (GInitable     *initable,
                               initable, NULL);
        g_source_attach (monitor->source, NULL);
 
-       return TRUE;
+       return initable_parent_iface->init (initable, cancellable, error);
 }
 
 static void
@@ -482,11 +484,16 @@ tracker_monitor_fanotify_set_enabled (TrackerMonitor *object,
                files = g_list_remove (files, file);
                g_object_unref (file);
        }
+
+       TRACKER_MONITOR_CLASS (tracker_monitor_fanotify_parent_class)->set_enabled (object,
+                                                                                    enabled);
 }
 
 static void
 tracker_monitor_fanotify_initable_iface_init (GInitableIface *iface)
 {
+       initable_parent_iface = g_type_interface_peek_parent (iface);
+
        iface->init = tracker_monitor_fanotify_initable_init;
 }
 
@@ -678,8 +685,13 @@ tracker_monitor_fanotify_add (TrackerMonitor *object,
 
        if (monitor->enabled) {
                data = monitored_file_new (monitor, file);
-               if (!data)
-                       return FALSE;
+               if (!data) {
+                       /* If we cannot create fanotify handles (e.g. EXDEV on
+                        * btrfs), fall back to inotify.
+                        */
+                       return TRACKER_MONITOR_CLASS (tracker_monitor_fanotify_parent_class)->add (object,
+                                                                                                  file);
+               }
 
                g_hash_table_insert (monitor->monitored_dirs, g_object_ref (data->file), data);
                g_hash_table_insert (monitor->handles, data->handle_bytes, data);
@@ -705,7 +717,11 @@ tracker_monitor_fanotify_remove (TrackerMonitor *object,
                                                   g_hash_table_size (monitor->monitored_dirs) - 1));
        }
 
-       return g_hash_table_remove (monitor->monitored_dirs, file);
+       if (g_hash_table_remove (monitor->monitored_dirs, file))
+               return TRUE;
+
+       return TRACKER_MONITOR_CLASS (tracker_monitor_fanotify_parent_class)->remove (object,
+                                                                                     file);
 }
 
 /* If @is_strict is %TRUE, return %TRUE iff @file is a child of @prefix.
@@ -732,6 +748,12 @@ tracker_monitor_fanotify_remove_recursively (TrackerMonitor *object,
        GFile *f;
        gchar *uri;
 
+       if (!g_hash_table_contains (monitor->monitored_dirs, file)) {
+               return TRACKER_MONITOR_CLASS (tracker_monitor_fanotify_parent_class)->remove_recursively 
(object,
+                                                                                                         
file,
+                                                                                                         
only_children);
+       }
+
        g_hash_table_iter_init (&iter, monitor->monitored_dirs);
        while (g_hash_table_iter_next (&iter, (gpointer *) &f, (gpointer *) &data)) {
                if (!file_has_maybe_strict_prefix (f, file, only_children))
@@ -768,6 +790,12 @@ tracker_monitor_fanotify_move (TrackerMonitor *object,
        GList *files = NULL;
        GFile *f;
 
+       if (!g_hash_table_contains (monitor->monitored_dirs, old_file)) {
+               return TRACKER_MONITOR_CLASS (tracker_monitor_fanotify_parent_class)->move (object,
+                                                                                           old_file,
+                                                                                           new_file);
+       }
+
        old_prefix = g_file_get_path (old_file);
 
        /* Find out which subdirectories should have a file monitor added */
@@ -835,7 +863,12 @@ tracker_monitor_fanotify_is_watched (TrackerMonitor *object,
        if (!monitor->enabled)
                return FALSE;
 
-       return g_hash_table_contains (monitor->monitored_dirs, file);
+       if (g_hash_table_contains (monitor->monitored_dirs, file)) {
+               return TRUE;
+       } else {
+               return TRACKER_MONITOR_CLASS (tracker_monitor_fanotify_parent_class)->is_watched (object,
+                                                                                                 file);
+       }
 }
 
 static guint
@@ -845,6 +878,7 @@ tracker_monitor_fanotify_get_count (TrackerMonitor *object)
        guint count;
 
        count = g_hash_table_size (monitor->monitored_dirs);
+       count += TRACKER_MONITOR_CLASS (tracker_monitor_fanotify_parent_class)->get_count (object);
 
        return count;
 }
diff --git a/src/libtracker-miner/tracker-monitor-fanotify.h b/src/libtracker-miner/tracker-monitor-fanotify.h
index 8885c8c3a..b0ecec423 100644
--- a/src/libtracker-miner/tracker-monitor-fanotify.h
+++ b/src/libtracker-miner/tracker-monitor-fanotify.h
@@ -29,14 +29,14 @@
 #include <glib-object.h>
 #include <gio/gio.h>
 
-#include "tracker-monitor.h"
+#include "tracker-monitor-glib.h"
 
 G_BEGIN_DECLS
 
 #define TRACKER_TYPE_MONITOR_FANOTIFY (tracker_monitor_fanotify_get_type ())
 G_DECLARE_FINAL_TYPE (TrackerMonitorFanotify, tracker_monitor_fanotify,
                       TRACKER, MONITOR_FANOTIFY,
-                      TrackerMonitor)
+                      TrackerMonitorGlib)
 
 G_END_DECLS
 
diff --git a/src/libtracker-miner/tracker-monitor-glib.c b/src/libtracker-miner/tracker-monitor-glib.c
index d89eb080c..3d7b571ef 100644
--- a/src/libtracker-miner/tracker-monitor-glib.c
+++ b/src/libtracker-miner/tracker-monitor-glib.c
@@ -64,10 +64,6 @@ struct TrackerMonitorGlibPrivate {
        } thread;
 };
 
-struct _TrackerMonitorGlib {
-       TrackerMonitor parent_instance;
-};
-
 typedef struct {
        GFile    *file;
        gchar    *file_uri;
diff --git a/src/libtracker-miner/tracker-monitor-glib.h b/src/libtracker-miner/tracker-monitor-glib.h
index b72eaeef2..455f749e4 100644
--- a/src/libtracker-miner/tracker-monitor-glib.h
+++ b/src/libtracker-miner/tracker-monitor-glib.h
@@ -34,9 +34,13 @@
 G_BEGIN_DECLS
 
 #define TRACKER_TYPE_MONITOR_GLIB (tracker_monitor_glib_get_type ())
-G_DECLARE_FINAL_TYPE (TrackerMonitorGlib, tracker_monitor_glib,
-                      TRACKER, MONITOR_GLIB,
-                      TrackerMonitor)
+G_DECLARE_DERIVABLE_TYPE (TrackerMonitorGlib, tracker_monitor_glib,
+                          TRACKER, MONITOR_GLIB,
+                          TrackerMonitor)
+
+struct _TrackerMonitorGlibClass {
+       TrackerMonitorClass parent_class;
+};
 
 G_END_DECLS
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]