Determining the PID of a FUSE Daemon based on the /proc/mounts

26 Nov 2024

I am toying with a trivial Passthrough FUSE file system [1] mounted at /some-path/fusey-files, the PID of the FUSE daemon is 1234. and I wanted to programmatically find out (using /proc or /sys or some other kernel interface such as ioctl) that this mount is backed by the FUSE daemon running at PID 1234? What I have found so far is hacky and imprecise, and I feel like the FUSE module in the kernel must have this information, and I am just missing something.

Issue

First, the /proc/pid/mountinfo or df doesn’t say the name of the process running the FUSE daemon. It just says the name of the fs-type (in this case Passthrough) which is implementing my FUSE class in Python.

Passthrough    982862268 492790372 440071564  53% /some-path/fusey-files

Hacky Solutions

Solution 1

Another hacky way I found was to look at which processes in the system have opened /dev/fuse, but this method will run into trouble if I have more than 1 FUSE daemon. Since multiple FUSE daemons are allowed to run and both will open /dev/fuse there must be some way for the kernel to multiplex the request to the right daemon, just wondering if that information is exposed.

Solution 2

Use extend attributes of a file/dir to return this information from the FUSE daemon to the use of the file. This should be trivial to do as the FUSE daemon can easily get its own PID. However, this seems very ugly.

Why do I need this info?

I am building a tool that parses existing kernel interfaces (such as /proc/ and /sys) to find out which process depends on which resources (e.g., memory, files, sockets). A file from an in-kernel file-system only depends on the kernel, but a file from a FUSE-mounted file system would depend on the kernel and the process running the FUSE daemon.

If anyone knows how to solve this, do ping me. This was also posted here [2]

[1] https://github.com/sid-agrawal/OSmosis/blob/cellulos/scripts/proc/passthrough.py

[2] https://sourceforge.net/p/fuse/mailman/message/58842020/