Merge commit '3b735dd9330e0989f51a76771c3303031154154e' into 21158-wf-page-list
[arvados.git] / lib / mount / command.go
index 86a9085bda46fc69a517ba2be5faf7ea14688394..7ab518faee78a8ab20305b91132cacadc26cfddf 100644 (file)
@@ -9,18 +9,22 @@ import (
        "io"
        "log"
        "net/http"
+
+       // pprof is only imported to register its HTTP handlers
        _ "net/http/pprof"
        "os"
 
+       "git.arvados.org/arvados.git/lib/cmd"
        "git.arvados.org/arvados.git/sdk/go/arvados"
        "git.arvados.org/arvados.git/sdk/go/arvadosclient"
        "git.arvados.org/arvados.git/sdk/go/keepclient"
        "github.com/arvados/cgofuse/fuse"
+       "github.com/ghodss/yaml"
 )
 
-var Command = &cmd{}
+var Command = &mountCommand{}
 
-type cmd struct {
+type mountCommand struct {
        // ready, if non-nil, will be closed when the mount is
        // initialized.  If ready is non-nil, it RunCommand() should
        // not be called more than once, or when ready is already
@@ -35,17 +39,15 @@ type cmd struct {
 //
 // The "-d" fuse option (and perhaps other features) ignores the
 // stderr argument and prints to os.Stderr instead.
-func (c *cmd) RunCommand(prog string, args []string, stdin io.Reader, stdout, stderr io.Writer) int {
+func (c *mountCommand) RunCommand(prog string, args []string, stdin io.Reader, stdout, stderr io.Writer) int {
        logger := log.New(stderr, prog+" ", 0)
        flags := flag.NewFlagSet(prog, flag.ContinueOnError)
        ro := flags.Bool("ro", false, "read-only")
        experimental := flags.Bool("experimental", false, "acknowledge this is an experimental command, and should not be used in production (required)")
-       blockCache := flags.Int("block-cache", 4, "read cache size (number of 64MiB blocks)")
+       cacheSizeStr := flags.String("cache-size", "0", "cache size as percent of home filesystem size (\"5%\") or size (\"10GiB\") or 0 for automatic")
        pprof := flags.String("pprof", "", "serve Go profile data at `[addr]:port`")
-       err := flags.Parse(args)
-       if err != nil {
-               logger.Print(err)
-               return 2
+       if ok, code := cmd.ParseFlags(flags, prog, args, "[FUSE mount options]", stderr); !ok {
+               return code
        }
        if !*experimental {
                logger.Printf("error: experimental command %q used without --experimental flag", prog)
@@ -58,6 +60,10 @@ func (c *cmd) RunCommand(prog string, args []string, stdin io.Reader, stdout, st
        }
 
        client := arvados.NewClientFromEnv()
+       if err := yaml.Unmarshal([]byte(*cacheSizeStr), &client.DiskCacheSize); err != nil {
+               logger.Printf("error parsing -cache-size argument: %s", err)
+               return 2
+       }
        ac, err := arvadosclient.New(client)
        if err != nil {
                logger.Print(err)
@@ -68,7 +74,6 @@ func (c *cmd) RunCommand(prog string, args []string, stdin io.Reader, stdout, st
                logger.Print(err)
                return 1
        }
-       kc.BlockCache = &keepclient.BlockCache{MaxBlocks: *blockCache}
        host := fuse.NewFileSystemHost(&keepFS{
                Client:     client,
                KeepClient: kc,