From: Chen Linxuan <chenlinxuan@uniontech.com>
This commit add fuse connection device id, open_flags and backing
files, to fdinfo of opened fuse files.
Related discussions can be found at links below.
Link: https://lore.kernel.org/all/CAOQ4uxgS3OUy9tpphAJKCQFRAn2zTERXXa0QN_KvP6ZOe2KVBw@mail.gmail.com/
Link: https://lore.kernel.org/all/CAOQ4uxgkg0uOuAWO2wOPNkMmD9wqd5wMX+gTfCT-zVHBC8CkZg@mail.gmail.com/
Cc: Amir Goldstein <amir73il@gmail.com>
Signed-off-by: Chen Linxuan <chenlinxuan@uniontech.com>
---
fs/fuse/file.c | 20 ++++++++++++++++++++
1 file changed, 20 insertions(+)
diff --git a/fs/fuse/file.c b/fs/fuse/file.c
index 754378dd9f7159f20fde6376962d45c4c706b868..1e54965780e9d625918c22a3dea48ba5a9a5ed1b 100644
--- a/fs/fuse/file.c
+++ b/fs/fuse/file.c
@@ -8,6 +8,8 @@
#include "fuse_i.h"
+#include "linux/idr.h"
+#include "linux/rcupdate.h"
#include <linux/pagemap.h>
#include <linux/slab.h>
#include <linux/kernel.h>
@@ -3392,6 +3394,21 @@ static ssize_t fuse_copy_file_range(struct file *src_file, loff_t src_off,
return ret;
}
+static void fuse_file_show_fdinfo(struct seq_file *seq, struct file *f)
+{
+ struct fuse_file *ff = f->private_data;
+ struct fuse_conn *fc = ff->fm->fc;
+ struct file *backing_file = fuse_file_passthrough(ff);
+
+ seq_printf(seq, "fuse conn:%u open_flags:%u\n", fc->dev, ff->open_flags);
+
+ if (backing_file) {
+ seq_puts(seq, "fuse backing_file: ");
+ seq_file_path(seq, backing_file, " \t\n\\");
+ seq_puts(seq, "\n");
+ }
+}
+
static const struct file_operations fuse_file_operations = {
.llseek = fuse_file_llseek,
.read_iter = fuse_file_read_iter,
@@ -3411,6 +3428,9 @@ static const struct file_operations fuse_file_operations = {
.poll = fuse_file_poll,
.fallocate = fuse_file_fallocate,
.copy_file_range = fuse_copy_file_range,
+#ifdef CONFIG_PROC_FS
+ .show_fdinfo = fuse_file_show_fdinfo,
+#endif
};
static const struct address_space_operations fuse_file_aops = {
--
2.43.0
On Fri, 9 May 2025 at 08:34, Chen Linxuan via B4 Relay
<devnull+chenlinxuan.uniontech.com@kernel.org> wrote:
> static const struct file_operations fuse_file_operations = {
> .llseek = fuse_file_llseek,
> .read_iter = fuse_file_read_iter,
> @@ -3411,6 +3428,9 @@ static const struct file_operations fuse_file_operations = {
> .poll = fuse_file_poll,
> .fallocate = fuse_file_fallocate,
> .copy_file_range = fuse_copy_file_range,
> +#ifdef CONFIG_PROC_FS
> + .show_fdinfo = fuse_file_show_fdinfo,
> +#endif
> };
The backing file mechanism is an internal implementation detail of
fuse and does not need to be displayed in the fuse file's fdinfo.
Currently we can only have one backing file per fuse file, but that
may well change in the future, as well as other details like offset
into the backing file (think FS_IOC_FIEMAP).
So NAK unless there's a very good use case for this.
Adding fdinfo for the /dev/fuse file is encouraged, it would be good
to be able to retrieve the connection number from the dev fd.
Thanks,
Miklos
On Fri, May 9, 2025 at 2:34 PM Chen Linxuan via B4 Relay
<devnull+chenlinxuan.uniontech.com@kernel.org> wrote:
>
> From: Chen Linxuan <chenlinxuan@uniontech.com>
>
> This commit add fuse connection device id, open_flags and backing
> files, to fdinfo of opened fuse files.
>
> Related discussions can be found at links below.
>
> Link: https://lore.kernel.org/all/CAOQ4uxgS3OUy9tpphAJKCQFRAn2zTERXXa0QN_KvP6ZOe2KVBw@mail.gmail.com/
> Link: https://lore.kernel.org/all/CAOQ4uxgkg0uOuAWO2wOPNkMmD9wqd5wMX+gTfCT-zVHBC8CkZg@mail.gmail.com/
> Cc: Amir Goldstein <amir73il@gmail.com>
> Signed-off-by: Chen Linxuan <chenlinxuan@uniontech.com>
> ---
> fs/fuse/file.c | 20 ++++++++++++++++++++
> 1 file changed, 20 insertions(+)
>
> diff --git a/fs/fuse/file.c b/fs/fuse/file.c
> index 754378dd9f7159f20fde6376962d45c4c706b868..1e54965780e9d625918c22a3dea48ba5a9a5ed1b 100644
> --- a/fs/fuse/file.c
> +++ b/fs/fuse/file.c
> @@ -8,6 +8,8 @@
>
> #include "fuse_i.h"
>
> +#include "linux/idr.h"
> +#include "linux/rcupdate.h"
> #include <linux/pagemap.h>
> #include <linux/slab.h>
> #include <linux/kernel.h>
> @@ -3392,6 +3394,21 @@ static ssize_t fuse_copy_file_range(struct file *src_file, loff_t src_off,
> return ret;
> }
>
> +static void fuse_file_show_fdinfo(struct seq_file *seq, struct file *f)
> +{
> + struct fuse_file *ff = f->private_data;
> + struct fuse_conn *fc = ff->fm->fc;
> + struct file *backing_file = fuse_file_passthrough(ff);
> +
> + seq_printf(seq, "fuse conn:%u open_flags:%u\n", fc->dev, ff->open_flags);
Note: The fc->dev is already accessible to userspace.
The mnt_id field in /proc/PID/fdinfo/FD references a mount,
which can be found in /proc/PID/mountinfo.
And this file includes the device ID.
> +
> + if (backing_file) {
> + seq_puts(seq, "fuse backing_file: ");
> + seq_file_path(seq, backing_file, " \t\n\\");
> + seq_puts(seq, "\n");
> + }
> +}
> +
> static const struct file_operations fuse_file_operations = {
> .llseek = fuse_file_llseek,
> .read_iter = fuse_file_read_iter,
> @@ -3411,6 +3428,9 @@ static const struct file_operations fuse_file_operations = {
> .poll = fuse_file_poll,
> .fallocate = fuse_file_fallocate,
> .copy_file_range = fuse_copy_file_range,
> +#ifdef CONFIG_PROC_FS
> + .show_fdinfo = fuse_file_show_fdinfo,
> +#endif
> };
>
> static const struct address_space_operations fuse_file_aops = {
>
> --
> 2.43.0
>
>
>
>
On Fri, May 9, 2025 at 8:40 AM Chen Linxuan <chenlinxuan@uniontech.com> wrote:
>
> On Fri, May 9, 2025 at 2:34 PM Chen Linxuan via B4 Relay
> <devnull+chenlinxuan.uniontech.com@kernel.org> wrote:
> >
> > From: Chen Linxuan <chenlinxuan@uniontech.com>
> >
> > This commit add fuse connection device id, open_flags and backing
> > files, to fdinfo of opened fuse files.
> >
> > Related discussions can be found at links below.
> >
> > Link: https://lore.kernel.org/all/CAOQ4uxgS3OUy9tpphAJKCQFRAn2zTERXXa0QN_KvP6ZOe2KVBw@mail.gmail.com/
> > Link: https://lore.kernel.org/all/CAOQ4uxgkg0uOuAWO2wOPNkMmD9wqd5wMX+gTfCT-zVHBC8CkZg@mail.gmail.com/
> > Cc: Amir Goldstein <amir73il@gmail.com>
> > Signed-off-by: Chen Linxuan <chenlinxuan@uniontech.com>
> > ---
> > fs/fuse/file.c | 20 ++++++++++++++++++++
> > 1 file changed, 20 insertions(+)
> >
> > diff --git a/fs/fuse/file.c b/fs/fuse/file.c
> > index 754378dd9f7159f20fde6376962d45c4c706b868..1e54965780e9d625918c22a3dea48ba5a9a5ed1b 100644
> > --- a/fs/fuse/file.c
> > +++ b/fs/fuse/file.c
> > @@ -8,6 +8,8 @@
> >
> > #include "fuse_i.h"
> >
> > +#include "linux/idr.h"
> > +#include "linux/rcupdate.h"
These are not needed.
> > #include <linux/pagemap.h>
> > #include <linux/slab.h>
> > #include <linux/kernel.h>
> > @@ -3392,6 +3394,21 @@ static ssize_t fuse_copy_file_range(struct file *src_file, loff_t src_off,
> > return ret;
> > }
> >
> > +static void fuse_file_show_fdinfo(struct seq_file *seq, struct file *f)
> > +{
> > + struct fuse_file *ff = f->private_data;
> > + struct fuse_conn *fc = ff->fm->fc;
> > + struct file *backing_file = fuse_file_passthrough(ff);
> > +
> > + seq_printf(seq, "fuse conn:%u open_flags:%u\n", fc->dev, ff->open_flags);
>
> Note: The fc->dev is already accessible to userspace.
> The mnt_id field in /proc/PID/fdinfo/FD references a mount,
> which can be found in /proc/PID/mountinfo.
>
> And this file includes the device ID.
>
True, but the direct reference to conn here does not hurt.
> > +
> > + if (backing_file) {
> > + seq_puts(seq, "fuse backing_file: ");
> > + seq_file_path(seq, backing_file, " \t\n\\");
> > + seq_puts(seq, "\n");
> > + }
> > +}
> > +
With unneeded includes fixed feel free to add:
Reviewed-by: Amir Goldstein <amir73il@gmail.com>
Please wait before posting v4 to give other developers and Miklos
a chance to review v3.
Thanks,
Amir.
© 2016 - 2026 Red Hat, Inc.