winfsp / cgofuse

Cross-platform FUSE library for Go - Works on Windows, macOS, Linux, FreeBSD, NetBSD, OpenBSD
https://winfsp.dev
MIT License
514 stars 82 forks source link

Can't remount after unmount in the same process #21

Closed ncw closed 6 years ago

ncw commented 6 years ago

This is probably me doing something stupid, so apologies in advance!

In the new rclone tests I'm writing, I'm running the tests multiple times with different cache modes.

This involves unmounting then remounting in the same process.

However I get this error The service cmount.test has failed to run (Status=c000010e) which I don't understand! AFAICT it means "driver not loaded" which doesn't make things any clearer.

I tried putting a 5 second pause after the unmount before remounting but no joy.

If I try unmounting and remounting on the command line (with a new rclone process each time) it all seems to work fine.

So maybe cgofuse is unloading WinFSP on unmount, but isn't able to reload it again on mount for some reason?

Any ideas?

[successful test output snipped]
The service cmount.test has been stopped.
2017/11/17 13:19:04 DEBUG : host.Unmount succeeded
2017/11/17 13:19:09 Waiting for umount
2017/11/17 13:19:09 Finished test run with cache mode off
2017/11/17 13:19:09 Starting test run with cache mode minimal
2017/11/17 13:19:09 mount "Local file system at \\\\?\\C:\\Users\\Dev\\AppData\\Local\\Temp\\rclone540012982" "E:"
2017/11/17 13:19:09 DEBUG : Local file system at \\?\C:\Users\Dev\AppData\Local\Temp\rclone540012982: Mounting on "E:"
2017/11/17 13:19:09 DEBUG : vfs cache root is "C:\\Users\\Dev\\AppData\\Local\\rclone\\vfs\\local\\C\\Users\\Dev\\AppData\\Local\\Temp\\rclone540012982"
2017/11/17 13:19:09 DEBUG : Local file system at \\?\C:\Users\Dev\AppData\Local\Temp\rclone540012982: Mounting with options: ["-o" "fsname=local:\\\\?\\C:\\Users\\Dev\\AppData\\Local\\Temp\\rclone540012982" "-o" "subtype=rclone" "-o" "max_readahead=131072" "-o" "atomic_o_trunc" "-o" "uid=-1" "-o" "gid=-1" "--FileSystemName=rclone"]
The service cmount.test has failed to run (Status=c000010e).
2017/11/17 13:19:09 ERROR : Local file system at \\?\C:\Users\Dev\AppData\Local\Temp\rclone540012982: Mount failed
2017/11/17 13:19:09 mount failed: mount stopped before calling Init: mount failed
billziss-gh commented 6 years ago

I believe you have hit an inherent limitation of the WinFsp-FUSE layer: you can only have one file system per process. The reason is explained below.

There is no such limitation in the core WinFsp layer. You can have as many file systems as you want in a process either simultaneously or one after another. However file systems in Windows need to often be run as services and for this reason the core WinFsp layer also provides an API to facilitate this.

The WinFsp-FUSE layer uses both the file system and service API's. This way a WinFsp-FUSE file system can easily become a Windows service. There is a problem: once a Windows process starts acting as a service and then stops being a service, it cannot become a service again (this is true of the WinFsp Service API, although I do not remember if this is an inherent limitation of the Windows Service API).

You see where I am going with this. Having FUSE file systems being able to act as Windows services is valuable. The downside is that you can only have one FUSE file system per process.

So this is not a limitation of cgofuse, but rather a limitation of the WinFsp-FUSE layer. However it is not a limitation that I can fix as FUSE file systems would lose the "free" ability to act as Windows services.

ncw commented 6 years ago

I see, thanks for explaining that.

I'll stop beating my head against that particular wall then and think of a work-around ;-)

It is just for the test suite in rclone - it isn't something that regular users will do so a work-around is fine!

billziss-gh commented 5 years ago

BTW, the latest version of WinFsp should now support multiple FUSE file systems in the same process.

WinFsp 2018.2 B2