Merge branch '3198-inode-cache' into 3198-writable-fuse, fix tests.
[arvados.git] / services / fuse / bin / arv-mount
index e07860d6b9c167ceebd4ef4642cb8c7c6da23761..5a3e0215388a3077b78a117e9064ff0acc8984a9 100755 (executable)
@@ -9,13 +9,17 @@ import signal
 import subprocess
 import time
 
+import arvados.commands._util as arv_cmd
 from arvados_fuse import *
+from arvados.safeapi import ThreadSafeApiCache
+import arvados.keep
 
 logger = logging.getLogger('arvados.arv-mount')
 
 if __name__ == '__main__':
     # Handle command line parameters
     parser = argparse.ArgumentParser(
+        parents=[arv_cmd.retry_opt],
         description='''Mount Keep data under the local filesystem.  Default mode is --home''',
         epilog="""
 Note: When using the --exec feature, you must either specify the
@@ -41,6 +45,11 @@ with "--".
     parser.add_argument('--debug', action='store_true', help="""Debug mode""")
     parser.add_argument('--logfile', help="""Write debug logs and errors to the specified file (default stderr).""")
     parser.add_argument('--foreground', action='store_true', help="""Run in foreground (default is to daemonize unless --exec specified)""", default=False)
+    parser.add_argument('--encoding', type=str, help="Character encoding to use for filesystem, default is utf-8 (see Python codec registry for list of available encodings)", default="utf-8")
+
+    parser.add_argument('--file-cache', type=int, help="File data cache size, in bytes (default 256MiB)", default=256*1024*1024)
+    parser.add_argument('--directory-cache', type=int, help="Directory data cache size, in bytes (default 128MiB)", default=128*1024*1024)
+
     parser.add_argument('--exec', type=str, nargs=argparse.REMAINDER,
                         dest="exec_args", metavar=('command', 'args', '...', '--'),
                         help="""Mount, run a command, then unmount and exit""")
@@ -77,32 +86,51 @@ with "--".
 
     try:
         # Create the request handler
-        operations = Operations(os.getuid(), os.getgid())
-        api = SafeApi(arvados.config)
-
-        usr = api.users().current().execute()
+        operations = Operations(os.getuid(),
+                                os.getgid(),
+                                encoding=args.encoding,
+                                inode_cache=InodeCache(cap=args.directory_cache))
+        api = ThreadSafeApiCache(apiconfig=arvados.config.settings(),
+                                  keep_params={"block_cache": arvados.keep.KeepBlockCache(args.file_cache)})
+
+        usr = api.users().current().execute(num_retries=args.retries)
         now = time.time()
+        dir_class = None
+        dir_args = [llfuse.ROOT_INODE, operations.inodes, api, args.retries]
         if args.by_id:
             # Set up the request handler with the 'magic directory' at the root
-            operations.inodes.add_entry(MagicDirectory(llfuse.ROOT_INODE, operations.inodes, api))
+            dir_class = MagicDirectory
         elif args.by_tag:
-            operations.inodes.add_entry(TagsDirectory(llfuse.ROOT_INODE, operations.inodes, api))
+            dir_class = TagsDirectory
         elif args.shared:
-            operations.inodes.add_entry(SharedDirectory(llfuse.ROOT_INODE, operations.inodes, api, usr))
+            dir_class = SharedDirectory
+            dir_args.append(usr)
         elif args.home:
-            operations.inodes.add_entry(ProjectDirectory(llfuse.ROOT_INODE, operations.inodes, api, usr))
-        elif args.collection != None:
+            dir_class = ProjectDirectory
+            dir_args.append(usr)
+            dir_args.append(True)
+        elif args.collection is not None:
             # Set up the request handler with the collection at the root
-            operations.inodes.add_entry(CollectionDirectory(llfuse.ROOT_INODE, operations.inodes, api, args.collection))
-        elif args.project != None:
-            operations.inodes.add_entry(ProjectDirectory(llfuse.ROOT_INODE, operations.inodes, api, api.groups().get(uuid=args.project).execute()))
+            dir_class = CollectionDirectory
+            dir_args.append(args.collection)
+        elif args.project is not None:
+            dir_class = ProjectDirectory
+            dir_args.append(api.groups().get(uuid=args.project).execute(
+                    num_retries=args.retries))
+
+        if dir_class is not None:
+            operations.inodes.add_entry(dir_class(*dir_args))
         else:
-            e = operations.inodes.add_entry(Directory(llfuse.ROOT_INODE))
+            e = operations.inodes.add_entry(Directory(llfuse.ROOT_INODE, operations.inodes))
+            dir_args[0] = e.inode
+
+            e._entries['by_id'] = operations.inodes.add_entry(MagicDirectory(*dir_args))
+            e._entries['by_tag'] = operations.inodes.add_entry(TagsDirectory(*dir_args))
 
-            e._entries['home'] = operations.inodes.add_entry(ProjectDirectory(e.inode, operations.inodes, api, usr))
-            e._entries['shared'] = operations.inodes.add_entry(SharedDirectory(e.inode, operations.inodes, api, usr))
-            e._entries['by_tag'] = operations.inodes.add_entry(TagsDirectory(e.inode, operations.inodes, api))
-            e._entries['by_id'] = operations.inodes.add_entry(MagicDirectory(e.inode, operations.inodes, api))
+            dir_args.append(usr)
+            dir_args.append(True)
+            e._entries['home'] = operations.inodes.add_entry(ProjectDirectory(*dir_args))
+            e._entries['shared'] = operations.inodes.add_entry(SharedDirectory(*dir_args))
 
             text = '''
 Welcome to Arvados!  This directory provides file system access to files and objects