Skip to content

Mounting using AutoFS doesn't work #3246

Closed

Description

@ScuttleSE

Output of rclone version

rclone v1.47.0

  • os/arch: linux/amd64
  • go version: go1.12.3

Describe the issue

I have been trying to add a few rclone-mounts to my autofs configuration without success

Mounting the drive using the exact commandline that autofs uses works though, so something is weird...

handle_packet_missing_indirect: token 20, name TeamDrive-Archive, request pid 3291
attempting to mount entry /media/GoogleTest/TeamDrive-Archive
lookup_mount: lookup(file): looking up TeamDrive-Archive
lookup_mount: lookup(file): TeamDrive-Archive -> -fstype=fuse,config=/home/scuttle/.config/rclone/rclone.conf	:rclonefs\#dom-td01\:
parse_mount: parse(sun): expanded entry: -fstype=fuse,config=/home/scuttle/.config/rclone/rclone.conf	:rclonefs\#dom-td01\:
parse_mount: parse(sun): gathered options: fstype=fuse,config=/home/scuttle/.config/rclone/rclone.conf
parse_mount: parse(sun): dequote(":rclonefs\#dom-td01\:") -> :rclonefs#dom-td01:
parse_mount: parse(sun): core of entry: options=fstype=fuse,config=/home/scuttle/.config/rclone/rclone.conf, loc=:rclonefs#dom-td01:
sun_mount: parse(sun): mounting root /media/GoogleTest, mountpoint TeamDrive-Archive, what rclonefs#dom-td01:, fstype fuse, options config=/home/scuttle/.config/rclone/rclone.conf
do_mount: rclonefs#dom-td01: /media/GoogleTest/TeamDrive-Archive type fuse options config=/home/scuttle/.config/rclone/rclone.conf using module generic
mount_mount: mount(generic): calling mkdir_path /media/GoogleTest/TeamDrive-Archive
mount_mount: mount(generic): calling mount -t fuse -o config=/home/scuttle/.config/rclone/rclone.conf rclonefs#dom-td01: /media/GoogleTest/TeamDrive-Archive

Just running "mount -t fuse -o config=/home/scuttle/.config/rclone/rclone.conf rclonefs#dom-td01: /media/GoogleTest/TeamDrive-Archive" mounts the folder just fine, but when automount tries it, it just hangs on that last line

Activity

  1. ScuttleSE commented on Jun 5, 2019

    @ScuttleSE
    Author
  2. ncw commented on Jun 6, 2019

    @ncw
    Member

    I suggest you add the --log-file option or the --syslog option to the rclone invocation so you can see any errors and post them here - thanks!

  3. ScuttleSE commented on Jun 7, 2019

    @ScuttleSE
    Author

    This is what the rclone-log showed:

    2019/06/07 06:54:10 DEBUG : rclone: Version "v1.47.0" starting with parameters ["rclone" "-vvvv" "--log-file=/tmp/autofs.rclone" "mount" "--config=/home/scuttle/.config/rclone/rclone.conf" "--allow-other" "--default-permissions" "--max-read-ahead=16M" "[email protected]" "dom-01:" "/media/GoogleTest/[email protected]"]
    2019/06/07 06:54:10 DEBUG : Using config file from "/home/scuttle/.config/rclone/rclone.conf"
    2019/06/07 06:54:10 DEBUG : Google drive root '': Mounting on "/media/GoogleTest/[email protected]"
    2019/06/07 06:54:11 DEBUG : Adding path "vfs/forget" to remote control registry
    2019/06/07 06:54:11 DEBUG : Adding path "vfs/refresh" to remote control registry
    2019/06/07 06:54:11 DEBUG : Adding path "vfs/poll-interval" to remote control registry
    2019/06/07 06:54:11 DEBUG : : Root: 
    2019/06/07 06:54:11 DEBUG : : >Root: node=/, err=<nil>
    
  4. ScuttleSE commented on Jun 7, 2019

    @ScuttleSE
    Author

    Tried adding --daemon to the commandline as suggested here: https://forum.rclone.org/t/issues-with-rclone-mount-root-node-err-nil/6749

    Still not working, but I got another set of messages in the log

    2019/06/07 09:46:13 DEBUG : rclone: Version "v1.47.0" starting with parameters ["rclone" "-vvvv" "--log-file=/tmp/autofs.rclone" "mount" "--config=/home/scuttle/.config/rclone/rclone.conf" "--allow-other" "--daemon" "--default-permissions" "--max-read-ahead=16M" "[email protected]" "dom-01:" "/media/GoogleTest/[email protected]"]
    2019/06/07 09:46:13 DEBUG : Using config file from "/home/scuttle/.config/rclone/rclone.conf"
    2019/06/07 09:46:13 DEBUG : rclone: Version "v1.47.0" finishing with parameters ["rclone" "-vvvv" "--log-file=/tmp/autofs.rclone" "mount" "--config=/home/scuttle/.config/rclone/rclone.conf" "--allow-other" "--daemon" "--default-permissions" "--max-read-ahead=16M" "[email protected]" "dom-01:" "/media/GoogleTest/[email protected]"]
    2019/06/07 09:46:13 DEBUG : rclone: Version "v1.47.0" starting with parameters ["rclone" "-vvvv" "--log-file=/tmp/autofs.rclone" "mount" "--config=/home/scuttle/.config/rclone/rclone.conf" "--allow-other" "--daemon" "--default-permissions" "--max-read-ahead=16M" "[email protected]" "dom-01:" "/media/GoogleTest/[email protected]"]
    2019/06/07 09:46:13 DEBUG : Using config file from "/home/scuttle/.config/rclone/rclone.conf"
    
  5. ncw commented on Jun 7, 2019

    @ncw
    Member

    There are no obvious errors in there... The first one looks like it is working.

    So the symptoms are that

    • you ls the automounted directory
    • rclone appears to have mounted the directory (can you check in another terminal)
    • however your ls hangs due to some automounter interaction?

    So do we think what is wrong is some interaction between automount and rclone?

    Adding --daemon was a good idea.

  6. ScuttleSE commented on Jun 7, 2019

    @ScuttleSE
    Author

    Yes

    The folder never gets mounted, but if I run the commandline from the rclone-log it mounts it just fine.

  7. ncw commented on Jun 7, 2019

    @ncw
    Member

    The folder never gets mounted,

    Can you check from another terminal that isn't hung to see if the folder did get mounted or not?

  8. ScuttleSE commented on Jun 7, 2019

    @ScuttleSE
    Author

    Same as the first terminal. the ls-command just hangs

    No additional lines in the rclone logfile

  9. ncw commented on Jun 7, 2019

    @ncw
    Member

    If you look at mount or cat /proc/mounts is it mounted in there?

  10. ScuttleSE commented on Jun 7, 2019

    @ScuttleSE
    Author

    Nope, doesn't show up in either.
    Other autofs mounts do show up.

  11. ScuttleSE commented on Jun 7, 2019

    @ScuttleSE
    Author

    Here's the rclone.conf btw

    [dom-01]
    type = drive
    client_id =
    client_secret =
    scope = drive
    root_folder_id =
    service_account_file = /home/scuttle/.config/rclone/dom/rclone-01.json
    
  12. ncw commented on Jun 7, 2019

    @ncw
    Member

    What you could try is when it has locked up, find the rclone PID then kill -QUIT pid.

    This will cause rclone to emit a stack trace of exactly what it is up to to the log file. Hopefully that will give us a clue!

  13. ScuttleSE commented on Jun 7, 2019

    @ScuttleSE
    Author

    Hm, kill -QUIT didn't kill the process so I had some issues getting it... but this ended up in the logfile after a few tries

    One thing that was interesting was that if I did kill -9 on the rclone process, it would start another one with the same command line arguments, but the "mount" still won't work

    PC=0x55dc0f5528d1 m=7 sigcode=0
    
    goroutine 0 [idle]:
    runtime.futex(0xc000128148, 0x80, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x7f9282ba0d20, 0x55dc0f4fe075, ...)
    	/usr/lib/go/src/runtime/sys_linux_amd64.s:535 +0x21
    runtime.futexsleep(0xc000128148, 0x7f9200000000, 0xffffffffffffffff)
    	/usr/lib/go/src/runtime/os_linux.go:46 +0x4b
    runtime.notesleep(0xc000128148)
    	/usr/lib/go/src/runtime/lock_futex.go:151 +0xa5
    runtime.stopm()
    	/usr/lib/go/src/runtime/proc.go:1936 +0xc5
    runtime.findrunnable(0xc000040500, 0x0)
    	/usr/lib/go/src/runtime/proc.go:2399 +0x550
    runtime.schedule()
    	/usr/lib/go/src/runtime/proc.go:2525 +0x220
    runtime.park_m(0xc000001c80)
    	/usr/lib/go/src/runtime/proc.go:2605 +0xa7
    runtime.mcall(0x800000)
    	/usr/lib/go/src/runtime/asm_amd64.s:299 +0x53
    
    goroutine 1 [syscall]:
    syscall.Syscall6(0x101, 0xffffffffffffff9c, 0xc000293770, 0x80000, 0x0, 0x0, 0x0, 0x7ffe8109cd8f, 0xc000136a80, 0xc0001b6380)
    	/usr/lib/go/src/syscall/asm_linux_amd64.s:44 +0x5
    syscall.openat(0xffffffffffffff9c, 0x7ffe8109cd97, 0x26, 0x80000, 0xc000000000, 0x12, 0x55dc10157bed, 0x12)
    	/usr/lib/go/src/syscall/zsyscall_linux_amd64.go:68 +0xc2
    syscall.Open(...)
    	/usr/lib/go/src/syscall/syscall_linux.go:138
    os.openFileNolog(0x7ffe8109cd97, 0x26, 0x0, 0x55dc00000000, 0xc000391cb8, 0x4e445cd8, 0xff438e3aedf6b969)
    	/usr/lib/go/src/os/file_unix.go:201 +0x93
    os.OpenFile(0x7ffe8109cd97, 0x26, 0x0, 0x55dc00000000, 0x5, 0x55dc10147527, 0xc0001e6950)
    	/usr/lib/go/src/os/file.go:284 +0x61
    os.Open(...)
    	/usr/lib/go/src/os/file.go:265
    github.com/ncw/rclone/cmd/mountlib.checkMountEmpty(0x7ffe8109cd97, 0x26, 0x0, 0x0)
    	/build/rclone/src/rclone-1.47.0/.gopath/src/github.com/ncw/rclone/cmd/mountlib/mount.go:43 +0x61
    github.com/ncw/rclone/cmd/mountlib.NewMountCommand.func1(0xc0003b0280, 0xc000422dc0, 0x2, 0xa)
    	/build/rclone/src/rclone-1.47.0/.gopath/src/github.com/ncw/rclone/cmd/mountlib/mount.go:263 +0x452
    github.com/ncw/rclone/vendor/github.com/spf13/cobra.(*Command).execute(0xc0003b0280, 0xc000422c80, 0xa, 0xa, 0xc0003b0280, 0xc000422c80)
    	/build/rclone/src/rclone-1.47.0/.gopath/src/github.com/ncw/rclone/vendor/github.com/spf13/cobra/command.go:766 +0x2b0
    github.com/ncw/rclone/vendor/github.com/spf13/cobra.(*Command).ExecuteC(0x55dc1138e840, 0xc000391f88, 0x55dc0f4f9021, 0xc0000a0058)
    	/build/rclone/src/rclone-1.47.0/.gopath/src/github.com/ncw/rclone/vendor/github.com/spf13/cobra/command.go:852 +0x2ee
    github.com/ncw/rclone/vendor/github.com/spf13/cobra.(*Command).Execute(...)
    	/build/rclone/src/rclone-1.47.0/.gopath/src/github.com/ncw/rclone/vendor/github.com/spf13/cobra/command.go:800
    github.com/ncw/rclone/cmd.Main()
    	/build/rclone/src/rclone-1.47.0/.gopath/src/github.com/ncw/rclone/cmd/cmd.go:488 +0x49
    main.main()
    	/build/rclone/src/rclone-1.47.0/.gopath/src/github.com/ncw/rclone/rclone.go:13 +0x22
    
    goroutine 5 [syscall]:
    os/signal.signal_recv(0x0)
    	/usr/lib/go/src/runtime/sigqueue.go:139 +0x9e
    os/signal.loop()
    	/usr/lib/go/src/os/signal/signal_unix.go:23 +0x24
    created by os/signal.init.0
    	/usr/lib/go/src/os/signal/signal_unix.go:29 +0x43
    
    rax    0xca
    rbx    0xc000128000
    rcx    0x55dc0f5528d3
    rdx    0x0
    rdi    0xc000128148
    rsi    0x80
    rbp    0x7f9282ba0ce8
    rsp    0x7f9282ba0ca0
    r8     0x0
    r9     0x0
    r10    0x0
    r11    0x286
    r12    0x5
    r13    0x7f927bbe2a7f
    r14    0x7f9282ba1700
    r15    0x0
    rip    0x55dc0f5528d1
    rflags 0x286
    cs     0x33
    fs     0x0
    gs     0x0
    
  14. ncw commented on Jun 7, 2019

    @ncw
    Member

    Ah, that makes sense. rclone is blocked on github.com/ncw/rclone/cmd/mountlib.checkMountEmpty - it is listing the mountpoint to see if it is empty. This is likely to cause some recursion or other funkiness with autofs.

    If you add the --allow-non-empty flag it will skip that check - perhaps that will make it work!

  15. ncw commented on Jun 7, 2019

    @ncw
    Member

    Assuming that does work, I wonder if there is some way rclone could detect it is being run from autofs (maybe an environment variable) and turn that check off automatically?

  16. 38 remaining items

  17. ScuttleSE commented on Jul 28, 2021

    @ScuttleSE
    Author

    @ScuttleSE @karagian
    please give my fix a try:

    So, I must admit I've been a bit out of the loop here for a while. Right now I have rclone working with autofs, no extra patches, what should I test? :)

  18. ivandeex commented on Jul 28, 2021

    @ivandeex
    Member

    @ScuttleSE

    So, I must admit I've been a bit out of the loop here for a while. Right now I have rclone working with autofs, no extra patches.

    I would like to understand your situation.
    Did you do something special to make it work?
    What is your OS, rclone version, autofs config?
    If this is not an issue for you, let's close out this ticket. I'd then open another ticket where I'd describe my case.
    At any rate the patch fixes my case.

    what should I test? :)

    I'm interested to know that it does not break your case. If you take your working rclone+autofs environment and replace rclone with patched one, will it still work?

  19. ScuttleSE commented on Jul 28, 2021

    @ScuttleSE
    Author

    Well, back when the bug was originally opened, there were some minor adjustments, but right now it looks like this:

    Autofs:
    Music -fstype=fuse.rclonefs,config=/home/scuttle/.config/rclone/rclone.conf,allow-other,default-permissions,allow-non-empty,max-read-ahead=16M,uid=1000,gid=1000

    Rclonefs:

    #!/bin/bash
    remote=$1
    mountpoint=$2
    shift 2
    
    # Process -o parameters
    while getopts :o: opts; do
        case $opts in
            o)
                params=${OPTARG//,/ }
                for param in $params; do
                    if [ "$param" == "rw"   ]; then continue; fi
                    if [ "$param" == "ro"   ]; then continue; fi
                    if [ "$param" == "dev"  ]; then continue; fi
                    if [ "$param" == "suid" ]; then continue; fi
                    if [ "$param" == "exec" ]; then continue; fi
                    if [ "$param" == "auto" ]; then continue; fi
                    if [ "$param" == "nodev" ]; then continue; fi
                    if [ "$param" == "nosuid" ]; then continue; fi
                    if [ "$param" == "noexec" ]; then continue; fi
                    if [ "$param" == "noauto" ]; then continue; fi
                    if [[ $param == x-systemd.* ]]; then continue; fi
                    trans="$trans --$param"
                done
                ;;
            \?)
                echo "Invalid option: -$OPTARG"
                ;;
        esac
    done
    
    # exec rclone
    trans="$trans $remote $mountpoint"
    # NOTE: do not try "mount --daemon" here, it does not play well with systemd automount, use '&'!
    # NOTE: mount is suid and ignores pre-set PATHs -> specify explicitely
    PATH=$PATH rclone mount $trans </dev/null >/dev/null 2>/dev/null &
    
    # WARNING: this will loop forever if remote is actually empty!
    until [ "`ls -l $mountpoint`" != 'total 0' ]; do
        sleep 1
    done
    

    The mount:

    [music]
    type = drive
    scope = drive
    service_account_file = /home/scuttle/.config/rclone/serviceaccounts01/009.json
    team_drive = XXXXXXXXXXXXXXX
    
    

    Tried the new binary, and works fine that one too

    scuttle@ranma ~ (master)> rclone version
    rclone v1.56.0
    - os/version: arch rolling (64 bit)
    - os/kernel: 5.13.5-arch1-1 (x86_64)
    - os/type: linux
    - os/arch: amd64
    - go/version: go1.16.6
    - go/linking: dynamic
    - go/tags: none
    
    
  20. ivandeex commented on Jul 28, 2021

    @ivandeex
    Member

    @ScuttleSE
    Thanks a lot for checking amd confirming that my patch works in your environment.

    I see now: you avoid --daemon using the & in wrapper (note that this won't apply setsid, cc @ncw)

    This solution almost replicates case 1 from above #3246 (comment):

    I don't use the --daemon flag. The wrapper runs rclone mount ... & i.e. backgrounds it, then polls /proc/mounts until the mount establishes. This method works fine both with systemd mount and automount.

    Two minor differences:

    1. instead of systemd automount you use the autofs daemon,
    2. instead of polling /proc/mounts for the mount (it's linux-only) you poll mountpoint directory for files (works on BSD too but can get stuck if the mounted fs is empty).

    @ncw

    The original case reported here can work fine without my patch. I am solving slightly different case. In fact, I do three things:

    1. Let autofs (systemd or classic) work with rclone --daemon so wrapper can avoid & and just exec rclone
    2. Move the mount readiness check from wrapper into rclone (under flag --daemon-wait-timeout or whatever name you aporove), so it can use more robust ProcFS method on Linux with a fallback for BSD
    3. Prevent double-unmount of autofs hooks. This problem can be seen only when autofs idle timeout kicks in. @ScuttleSE did not experience this!

    My patch leaves the wrapper with only one function: translation of -o opt=val mount options into --opt=val rclone flags.
    If I find a way to use cobra for that (e.g. triggered by executable name /sbin/mount.rclone expected by /bin/mount), we can get rid of the wrapper completely!

    @ncw @ScuttleSE

    I propose to close out this ticket. I can open another one as in fact I'm solving a different problem.

  21. karagian commented on Jul 28, 2021

    @karagian

    Hi and thanks for looking into this @ivandeex , but I must admin that rclone with autofs was working fine, that was not the problem.
    The reason this issue was reopened was these last lines in the wrapper script that will loop forever if the remote is empty! I saw your changes and it should work almost fine. My only objection is when ${mountpoint} contains spaces, in which case that grep will fail. I just propose using ${mountpoint// /\\040} istead of just ${mountpoint} there

  22. ivandeex commented on Jul 28, 2021

    @ivandeex
    Member

    @karagian

    I just propose using ${mountpoint// /\040} istead of just ${mountpoint} there

    Hit Edit on the wiki page and add your change. You don't need an issue for that.
    https://github.com/rclone/rclone/wiki/rclone-mount-helper-script

  23. karagian commented on Jul 28, 2021

    @karagian

    Oh ok.. can anyone edit that? Isn't it dangerous?

  24. ivandeex commented on Jul 28, 2021

    @ivandeex
    Member

    Oh ok.. can anyone edit that? Isn't it dangerous?

    Yes, any github user.
    No, we'll fix after you if anything.

  25. karagian commented on Jul 28, 2021

    @karagian

    ok done :)

  26. ivandeex commented on Jul 28, 2021

    @ivandeex
    Member

    @ncw

    Let's close this ticket.

    I will open another PR with ultimate goal to get rid of shell wrappers so rclone like sshfs can work natively with mount and autofs!

    ln -s /usr/bin/rclone /sbin/mount.rclone
    mount -t rclone remote:path /mnt/remote -o vfs-mode=full ...
    

    My last open task is to teach cobra translate -o xxx into rclone flags...

  27. ivandeex commented on Jul 28, 2021

    @ivandeex
    Member

    @ncw

    setsid

    I found discussion about setsid in the good old sshfs project. It works fine as a mount helper (if you symlink it as /sbin/mount.sshfs) and fully supports autofs so we could use it as a primer. They wanted to add setsid() right after fork() in the child - libfuse/sshfs#141. In the end they don't call it by default, only if they need to read a string from stdin - https://github.com/libfuse/sshfs/blob/master/sshfs.c#L1200.

    Again, we don't fork() like sshfs. We run an independent rclone process which does not inherit anything from the "parent" rclone. We just run it with the same cli flags and environment, just let it know its role via a special environment var.

    autofs hooks

    Here is how /proc/mounts looks when an autofs mountpoint is idle - our path has a autofs pseudo-mount attached:

    systemd-1 /mnt/rc/jotta autofs rw,relatime,fd=95,pgrp=1,timeout=30,minproto=5,maxproto=5,direct,pipe_ino=20267 0 0
    

    autofs attaches a pseudo-mount to the path, the kernel catches accesses there and sends event records to a pipe which autofs daemon acquired from it. autofs calls poll() on the pipe and handles the records.

    Here is how it looks after autofs detects access and invokes rclone to do the mount - two mounts now attached on the path:

    systemd-1 /mnt/rc/jotta autofs rw,relatime,fd=95,pgrp=1,timeout=30,minproto=5,maxproto=5,direct,pipe_ino=20267 0 0
    jotta: /mnt/rc/jotta fuse.rclone rw,nosuid,nodev,relatime,user_id=0,group_id=0,allow_other 0 0
    

    If we don't access active mount for a long time, autofs triggers idle event and unmounts the rclone mount, but the autofs pseudo-mount stays (the picture returns to the former state above).

    systemd: Unmounting rclone mount evan...
    systemd: Unmounted rclone mount evan.
    

    The unmount triggers FUSE which returns a error code on a go channel in rclone. rclone exits and calls atexit with umount(mountPoint). This would be correct if rclone finished due to ^C or SIGINT when autofs pseudo-mount wasn't there. However, if it exits after external unmount, it should not unmount the remaining autofs pseudo-mount (in fact, it's an access hook).

    Here is what happens if rclone by mistake unmounts autofs hooks:

    systemd: Unmounted rclone mount evan.
    systemd: mnt-rc-evan.automount: Got invalid poll event 16 on pipe (fd=49)
    systemd: mnt-rc-evan.automount: Failed with result 'resources'.
    

    When we unmounted the path hooks, kernel sent an event for it to the autofs daemon (systemd in my case) who got angry, marked the automount unit as failed and suspended checking for path access on /mnt/remote until I run systemctl restart mnt-remote.automount.

  28. ScuttleSE commented on Jul 29, 2021

    @ScuttleSE
    Author

    Hm, just wanted to add... none of my idle autofs-mounts shows up in /proc/mounts, they only show up there when they are actually mounted. No matter if it's a rclone-mount or a regular filesystem mount

  29. ncw commented on Jul 29, 2021

    @ncw
    Member

    @ivandeex - thank you for the explanation :-)

    Again, we don't fork() like sshfs. We run an independent rclone process which does not inherit anything from the "parent" rclone. We just run it with the same cli flags and environment, just let it know its role via a special environment var.

    Yes if we don't fork, we don't need to call setsid - that seems obvious now.

    The unmount triggers FUSE which returns a error code on a go channel in rclone. rclone exits and calls atexit with umount(mountPoint). This would be correct if rclone finished due to ^C or SIGINT when autofs pseudo-mount wasn't there. However, if it exits after external unmount, it should not unmount the remaining autofs pseudo-mount (in fact, it's an access hook).

    Gotcha.

  30. ivandeex commented on Jul 29, 2021

    @ivandeex
    Member

    Hm, just wanted to add... none of my idle autofs-mounts shows up in /proc/mounts, they only show up there when they are actually mounted. No matter if it's a rclone-mount or a regular filesystem mount

    Thank you. It explains why you don't hit the unmount bug.
    Looks like the pseudo-mount abstraction is used only by systemd automounter while the Autofs daemon uses an alternative kernel mechanism for that. I will mention it when I submit final patch for rclone.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions