How can I get the process ID of the driver of a FUSE filesystem?For example, I currently have two SSHFS filesystems mounted on a Linux machine:$ grep sshfs /proc/mountshost:dir1 /home/gilles/net/dir1 fuse.sshfs rw,nosuid,nodev,relatime,user_id=1000,group_id=1000 0 0host:dir2 /home/gilles/net/dir2 fuse.sshfs rw,nosuid,nodev,relatime,user_id=1000,group_id=1000 0 0$ pidof sshfs15031 15007How can I know which of 15007 and 15031 is dir1 and which is dir2? Ideally I'd like to automate that, i.e. run somecommand /home/gilles/net/dir1 and have it display 15007 (or 15031, or not a FUSE mount point, as appropriate). Note that I'm looking for a generic answer, not an answer that's specific to SSHFS, like tracking which host and port the sshfs processes are connected to, and what files the server-side process has open which might not even be possible at all due to connection sharing. I'm primarily interested in a Linux answer, but a generic answer that works on all systems that support FUSE would be ideal.Why I want to know: to trace its operation, to kill it in case of problems, etc.
Find what process implements a FUSE filesystem
process;fuse
I don't think it's possible. Here's why. I took the naive approach, which was to add the pid of the process opening /dev/fuse to the meta data that fuse creates at mount time, struct fuse_conn. I then used that information to display a pid= field in the mount command. The patch is really simple:diff --git a/fs/fuse/fuse_i.h b/fs/fuse/fuse_i.hindex 7354dc1..32b05ca 100644--- a/fs/fuse/fuse_i.h+++ b/fs/fuse/fuse_i.h@@ -402,6 +402,9 @@ struct fuse_conn {        /** The group id for this mount */        kgid_t group_id;+       /** The pid mounting process */+       pid_t pid;+        /** The fuse mount flags for this mount */        unsigned flags;diff --git a/fs/fuse/inode.c b/fs/fuse/inode.cindex e8799c1..23a27be 100644--- a/fs/fuse/inode.c+++ b/fs/fuse/inode.c@@ -554,6 +554,7 @@ static int fuse_show_options(struct seq_file *m, struct dentry *root)        struct super_block *sb = root->d_sb;        struct fuse_conn *fc = get_fuse_conn_super(sb);+       seq_printf(m, ,pid=%u, fc->pid);        seq_printf(m, ,user_id=%u, from_kuid_munged(&init_user_ns, fc->user_id));        seq_printf(m, ,group_id=%u, from_kgid_munged(&init_user_ns, fc->group_id));        if (fc->flags & FUSE_DEFAULT_PERMISSIONS)@@ -1042,6 +1043,7 @@ static int fuse_fill_super(struct super_block *sb, void *data, int silent)        fc->release = fuse_free_conn;        fc->flags = d.flags;+       fc->pid = current->pid;        fc->user_id = d.user_id;        fc->group_id = d.group_id;        fc->max_read = max_t(unsigned, 4096, d.max_read);def@fractal [6:37] ~/p/linux -- masterI booted the kernel, mounted sshfs, ran mount:root@192.168.1.1:/tmp on /root/tmp type fuse.sshfs (rw,nosuid,nodev,relatime,pid=1549,user_id=0,group_id=0)Success? Unfortunately, not:root      1552  0.0  0.0  45152   332 ?        Ssl  13:39   0:00 sshfs root@192.168.1.1:/tmp tmp                                                                Then I realized: the remaining sshfs process is a child of the one that created the mount. It inherited from the fd. As fuse is implemented, we could have a multitude of processes inheriting from the fd. We could have the fd passed around in UNIX sockets, completely out of the original process tree.We can obtain the 'who owns this TCP port' information, because sockets have this meta data, and simply parsing /proc tells us that information. Unfortunately, the fuse fd is a regular fd on /dev/fuse. Unless that fd somehow becomes special, I don't see how this can be implemented.