Merge branch '10236-disable-event-listening'
[arvados.git] / services / fuse / arvados_fuse / command.py
index ae0c920966f83988da35844f30fef5af8ac9c977..3f89732bea25dcd1ca546fbef126227e9e0a9256 100644 (file)
@@ -77,6 +77,8 @@ class ArgumentParser(argparse.ArgumentParser):
         self.add_argument('--file-cache', type=int, help="File data cache size, in bytes (default 256MiB)", default=256*1024*1024)
         self.add_argument('--directory-cache', type=int, help="Directory data cache size, in bytes (default 128MiB)", default=128*1024*1024)
 
+        self.add_argument('--disable-event-listening', action='store_true', help="Don't subscribe to events on the API server", dest="disable_event_listening", default=False)
+
         self.add_argument('--read-only', action='store_false', help="Mount will be read only (default)", dest="enable_write", default=False)
         self.add_argument('--read-write', action='store_true', help="Mount will be read-write", dest="enable_write", default=False)
 
@@ -95,6 +97,7 @@ class Mount(object):
     def __init__(self, args, logger=logging.getLogger('arvados.arv-mount')):
         self.logger = logger
         self.args = args
+        self.listen_for_events = False
 
         self.args.mountpoint = os.path.realpath(self.args.mountpoint)
         if self.args.logfile:
@@ -110,12 +113,13 @@ class Mount(object):
 
     def __enter__(self):
         llfuse.init(self.operations, self.args.mountpoint, self._fuse_options())
-        if self.args.mode != 'by_pdh':
+        if self.listen_for_events and not self.args.disable_event_listening:
             self.operations.listen_for_events()
         self.llfuse_thread = threading.Thread(None, lambda: self._llfuse_main())
         self.llfuse_thread.daemon = True
         self.llfuse_thread.start()
         self.operations.initlock.wait()
+        return self
 
     def __exit__(self, exc_type, exc_value, traceback):
         subprocess.call(["fusermount", "-u", "-z", self.args.mountpoint])
@@ -123,9 +127,8 @@ class Mount(object):
         if self.llfuse_thread.is_alive():
             self.logger.warning("Mount.__exit__:"
                                 " llfuse thread still alive %fs after umount"
-                                " -- resorting to operations.destroy()",
+                                " -- abandoning and exiting anyway",
                                 self.args.unmount_timeout)
-            self.operations.destroy()
 
     def run(self):
         if self.args.exec_args:
@@ -241,7 +244,9 @@ class Mount(object):
             mount_readme = True
 
         if dir_class is not None:
-            self.operations.inodes.add_entry(dir_class(*dir_args))
+            ent = dir_class(*dir_args)
+            self.operations.inodes.add_entry(ent)
+            self.listen_for_events = ent.want_event_subscribe()
             return
 
         e = self.operations.inodes.add_entry(Directory(
@@ -271,6 +276,7 @@ class Mount(object):
         if name in ['', '.', '..'] or '/' in name:
             sys.exit("Mount point '{}' is not supported.".format(name))
         tld._entries[name] = self.operations.inodes.add_entry(ent)
+        self.listen_for_events = (self.listen_for_events or ent.want_event_subscribe())
 
     def _readme_text(self, api_host, user_email):
         return '''
@@ -326,7 +332,8 @@ From here, the following directories are available:
                 self.daemon_ctx.open()
 
             # Subscribe to change events from API server
-            self.operations.listen_for_events()
+            if self.listen_for_events and not self.args.disable_event_listening:
+                self.operations.listen_for_events()
 
             self._llfuse_main()
         except Exception as e: