Linux filesystem development
 help / color / mirror / Atom feed
* [PATCH v5] erofs: accept source file descriptor via fsconfig
@ 2026-07-28 16:05 Giuseppe Scrivano
  2026-07-29  1:40 ` Gao Xiang
                   ` (2 more replies)
  0 siblings, 3 replies; 9+ messages in thread
From: Giuseppe Scrivano @ 2026-07-28 16:05 UTC (permalink / raw)
  To: linux-erofs; +Cc: cyphar, hsiangkao, linux-fsdevel, gscrivan

Allow userspace to pass an already-opened file descriptor as the mount
source instead of a path string.  This is useful for tools that already
hold an fd to the image, such as composefs reusing an existing erofs
backing file.

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
---
v4: https://lore.kernel.org/linux-fsdevel/20260717134147.1602735-1-gscrivan@redhat.com/
v3: https://lore.kernel.org/linux-fsdevel/20260714154917.489993-1-gscrivan@redhat.com/
v2: https://lore.kernel.org/linux-fsdevel/20260711071137.4130824-1-gscrivan@redhat.com/
v1: https://lore.kernel.org/linux-fsdevel/ak5GfvVfWLJU1EwK@debian/

 Documentation/filesystems/erofs.rst | 15 ++++++
 fs/erofs/super.c                    | 73 ++++++++++++++++++++++++-----
 2 files changed, 77 insertions(+), 11 deletions(-)

diff --git a/Documentation/filesystems/erofs.rst b/Documentation/filesystems/erofs.rst
index 4230884fb359..774e8b236d09 100644
--- a/Documentation/filesystems/erofs.rst
+++ b/Documentation/filesystems/erofs.rst
@@ -139,6 +139,21 @@ inode_share            Enable inode page sharing for this filesystem.  Inodes wi
                        page cache.
 ===================    =========================================================
 
+File-backed mounts
+==================
+
+When CONFIG_EROFS_FS_BACKED_BY_FILE is enabled, EROFS file-backed images
+can be mounted directly without a loopback block device.  The backing file
+can be given either as a path, or as an already-opened file descriptor.
+
+When a file descriptor is used, the kernel resolves its path and records it
+so that /proc/mounts and similar interfaces can still report the mount
+source.
+
+Only regular files are accepted as backing files; to mount an image that
+resides on a block device, use the traditional block device mount path
+instead.
+
 Sysfs Entries
 =============
 
diff --git a/fs/erofs/super.c b/fs/erofs/super.c
index 86fa5c6a0c70..558041011398 100644
--- a/fs/erofs/super.c
+++ b/fs/erofs/super.c
@@ -386,6 +386,7 @@ static void erofs_default_options(struct erofs_sb_info *sbi)
 enum {
 	Opt_user_xattr, Opt_acl, Opt_cache_strategy, Opt_dax, Opt_dax_enum,
 	Opt_device, Opt_domain_id, Opt_directio, Opt_fsoffset, Opt_inode_share,
+	Opt_source,
 };
 
 static const struct constant_table erofs_param_cache_strategy[] = {
@@ -402,17 +403,18 @@ static const struct constant_table erofs_dax_param_enums[] = {
 };
 
 static const struct fs_parameter_spec erofs_fs_parameters[] = {
-	fsparam_flag_no("user_xattr",	Opt_user_xattr),
-	fsparam_flag_no("acl",		Opt_acl),
-	fsparam_enum("cache_strategy",	Opt_cache_strategy,
+	fsparam_flag_no("user_xattr",		Opt_user_xattr),
+	fsparam_flag_no("acl",			Opt_acl),
+	fsparam_enum("cache_strategy",		Opt_cache_strategy,
 		     erofs_param_cache_strategy),
-	fsparam_flag("dax",             Opt_dax),
-	fsparam_enum("dax",		Opt_dax_enum, erofs_dax_param_enums),
-	fsparam_string("device",	Opt_device),
-	fsparam_string("domain_id",	Opt_domain_id),
-	fsparam_flag_no("directio",	Opt_directio),
-	fsparam_u64("fsoffset",		Opt_fsoffset),
-	fsparam_flag("inode_share",	Opt_inode_share),
+	fsparam_flag("dax",			Opt_dax),
+	fsparam_enum("dax",			Opt_dax_enum, erofs_dax_param_enums),
+	fsparam_string("device",		Opt_device),
+	fsparam_string("domain_id",		Opt_domain_id),
+	fsparam_flag_no("directio",		Opt_directio),
+	fsparam_u64("fsoffset",			Opt_fsoffset),
+	fsparam_flag("inode_share",		Opt_inode_share),
+	fsparam_file_or_string("source",	Opt_source),
 	{}
 };
 
@@ -437,6 +439,40 @@ static bool erofs_fc_set_dax_mode(struct fs_context *fc, unsigned int mode)
 	return false;
 }
 
+static int erofs_fc_parse_source(struct fs_context *fc,
+				 struct fs_parameter *param)
+{
+	struct erofs_sb_info *sbi = fc->s_fs_info;
+
+	if (fc->source || sbi->dif0.file)
+		return invalf(fc, "Multiple sources");
+
+	switch (param->type) {
+	case fs_value_is_string:
+		fc->source = param->string;
+		param->string = NULL;
+		return 0;
+	case fs_value_is_file: {
+		char *buf __free(kfree) = kmalloc(PATH_MAX, GFP_KERNEL);
+		char *p;
+
+		if (!buf)
+			return -ENOMEM;
+		p = file_path(param->file, buf, PATH_MAX);
+		if (IS_ERR(p))
+			return PTR_ERR(p);
+		fc->source = kstrdup(p, GFP_KERNEL);
+		if (!fc->source)
+			return -ENOMEM;
+		sbi->dif0.file = no_free_ptr(param->file);
+		return 0;
+	}
+	default:
+		WARN_ON_ONCE(true);
+		return -EINVAL;
+	}
+}
+
 static int erofs_fc_parse_param(struct fs_context *fc,
 				struct fs_parameter *param)
 {
@@ -524,6 +560,8 @@ static int erofs_fc_parse_param(struct fs_context *fc,
 		else
 			set_opt(&sbi->opt, INODE_SHARE);
 		break;
+	case Opt_source:
+		return erofs_fc_parse_source(fc, param);
 	}
 	return 0;
 }
@@ -752,13 +790,26 @@ static int erofs_fc_fill_super(struct super_block *sb, struct fs_context *fc)
 
 static int erofs_fc_get_tree(struct fs_context *fc)
 {
+	struct erofs_sb_info *sbi = fc->s_fs_info;
 	int ret;
 
+	if (sbi->dif0.file) {
+		if (!IS_ENABLED(CONFIG_EROFS_FS_BACKED_BY_FILE)) {
+			errorfc(fc, "source fd option not supported");
+			return -EINVAL;
+		}
+		if (!S_ISREG(file_inode(sbi->dif0.file)->i_mode) ||
+		    !sbi->dif0.file->f_mapping->a_ops->read_folio) {
+			errorfc(fc, "source is unsupported");
+			return -EINVAL;
+		}
+		return get_tree_nodev(fc, erofs_fc_fill_super);
+	}
+
 	ret = get_tree_bdev_flags(fc, erofs_fc_fill_super,
 		IS_ENABLED(CONFIG_EROFS_FS_BACKED_BY_FILE) ?
 			GET_TREE_BDEV_QUIET_LOOKUP : 0);
 	if (IS_ENABLED(CONFIG_EROFS_FS_BACKED_BY_FILE) && ret == -ENOTBLK) {
-		struct erofs_sb_info *sbi = fc->s_fs_info;
 		struct file *file;
 
 		if (!fc->source)
-- 
2.55.0


^ permalink raw reply related	[flat|nested] 9+ messages in thread

* Re: [PATCH v5] erofs: accept source file descriptor via fsconfig
  2026-07-28 16:05 [PATCH v5] erofs: accept source file descriptor via fsconfig Giuseppe Scrivano
@ 2026-07-29  1:40 ` Gao Xiang
  2026-07-29  9:57   ` Jan Kara
  2026-07-30  9:45 ` Christian Brauner
  2026-08-03 11:24 ` Chao Yu
  2 siblings, 1 reply; 9+ messages in thread
From: Gao Xiang @ 2026-07-29  1:40 UTC (permalink / raw)
  To: Giuseppe Scrivano
  Cc: linux-erofs, cyphar, linux-fsdevel, Christian Brauner, Jan Kara

On Tue, Jul 28, 2026 at 06:05:32PM +0200, Giuseppe Scrivano wrote:
> Allow userspace to pass an already-opened file descriptor as the mount
> source instead of a path string.  This is useful for tools that already
> hold an fd to the image, such as composefs reusing an existing erofs
> backing file.
> 
> Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
> ---
> v4: https://lore.kernel.org/linux-fsdevel/20260717134147.1602735-1-gscrivan@redhat.com/
> v3: https://lore.kernel.org/linux-fsdevel/20260714154917.489993-1-gscrivan@redhat.com/
> v2: https://lore.kernel.org/linux-fsdevel/20260711071137.4130824-1-gscrivan@redhat.com/
> v1: https://lore.kernel.org/linux-fsdevel/ak5GfvVfWLJU1EwK@debian/
> 
>  Documentation/filesystems/erofs.rst | 15 ++++++
>  fs/erofs/super.c                    | 73 ++++++++++++++++++++++++-----
>  2 files changed, 77 insertions(+), 11 deletions(-)
> 
> diff --git a/Documentation/filesystems/erofs.rst b/Documentation/filesystems/erofs.rst
> index 4230884fb359..774e8b236d09 100644
> --- a/Documentation/filesystems/erofs.rst
> +++ b/Documentation/filesystems/erofs.rst
> @@ -139,6 +139,21 @@ inode_share            Enable inode page sharing for this filesystem.  Inodes wi
>                         page cache.
>  ===================    =========================================================
>  
> +File-backed mounts
> +==================
> +
> +When CONFIG_EROFS_FS_BACKED_BY_FILE is enabled, EROFS file-backed images
> +can be mounted directly without a loopback block device.  The backing file
> +can be given either as a path, or as an already-opened file descriptor.
> +
> +When a file descriptor is used, the kernel resolves its path and records it
> +so that /proc/mounts and similar interfaces can still report the mount
> +source.
> +
> +Only regular files are accepted as backing files; to mount an image that
> +resides on a block device, use the traditional block device mount path
> +instead.

Reviewed-by: Gao Xiang <xiang@kernel.org>

Hi Christian, Jan, could you ack this (`fc->source` filling when
`source_fd` is used) if possible? I wish this behavior can be
consistent even vfs source_fd is implemented later.

Thanks,
Gao Xiang

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH v5] erofs: accept source file descriptor via fsconfig
  2026-07-29  1:40 ` Gao Xiang
@ 2026-07-29  9:57   ` Jan Kara
  2026-07-29 20:19     ` Gao Xiang
  0 siblings, 1 reply; 9+ messages in thread
From: Jan Kara @ 2026-07-29  9:57 UTC (permalink / raw)
  To: Gao Xiang
  Cc: Giuseppe Scrivano, linux-erofs, cyphar, linux-fsdevel,
	Christian Brauner, Jan Kara

On Wed 29-07-26 09:40:50, Gao Xiang wrote:
> On Tue, Jul 28, 2026 at 06:05:32PM +0200, Giuseppe Scrivano wrote:
> > Allow userspace to pass an already-opened file descriptor as the mount
> > source instead of a path string.  This is useful for tools that already
> > hold an fd to the image, such as composefs reusing an existing erofs
> > backing file.
> > 
> > Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
> > ---
> > v4: https://lore.kernel.org/linux-fsdevel/20260717134147.1602735-1-gscrivan@redhat.com/
> > v3: https://lore.kernel.org/linux-fsdevel/20260714154917.489993-1-gscrivan@redhat.com/
> > v2: https://lore.kernel.org/linux-fsdevel/20260711071137.4130824-1-gscrivan@redhat.com/
> > v1: https://lore.kernel.org/linux-fsdevel/ak5GfvVfWLJU1EwK@debian/
> > 
> >  Documentation/filesystems/erofs.rst | 15 ++++++
> >  fs/erofs/super.c                    | 73 ++++++++++++++++++++++++-----
> >  2 files changed, 77 insertions(+), 11 deletions(-)
> > 
> > diff --git a/Documentation/filesystems/erofs.rst b/Documentation/filesystems/erofs.rst
> > index 4230884fb359..774e8b236d09 100644
> > --- a/Documentation/filesystems/erofs.rst
> > +++ b/Documentation/filesystems/erofs.rst
> > @@ -139,6 +139,21 @@ inode_share            Enable inode page sharing for this filesystem.  Inodes wi
> >                         page cache.
> >  ===================    =========================================================
> >  
> > +File-backed mounts
> > +==================
> > +
> > +When CONFIG_EROFS_FS_BACKED_BY_FILE is enabled, EROFS file-backed images
> > +can be mounted directly without a loopback block device.  The backing file
> > +can be given either as a path, or as an already-opened file descriptor.
> > +
> > +When a file descriptor is used, the kernel resolves its path and records it
> > +so that /proc/mounts and similar interfaces can still report the mount
> > +source.
> > +
> > +Only regular files are accepted as backing files; to mount an image that
> > +resides on a block device, use the traditional block device mount path
> > +instead.
> 
> Reviewed-by: Gao Xiang <xiang@kernel.org>
> 
> Hi Christian, Jan, could you ack this (`fc->source` filling when
> `source_fd` is used) if possible?

Whenever I see a use of d_path() (or file_path() in this case) I'm a bit
watchful because its result is inherently racy and unsafe. But in this case
the result is only used for alloc_vfsmnt() which uses it for mnt_devname so
in the worst case we'll get an unreliable path in /proc/mounts or similar.
I guess that's acceptable. So feel free to add:

Acked-by: Jan Kara <jack@suse.cz>

								Honza
-- 
Jan Kara <jack@suse.com>
SUSE Labs, CR

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH v5] erofs: accept source file descriptor via fsconfig
  2026-07-29  9:57   ` Jan Kara
@ 2026-07-29 20:19     ` Gao Xiang
  0 siblings, 0 replies; 9+ messages in thread
From: Gao Xiang @ 2026-07-29 20:19 UTC (permalink / raw)
  To: Jan Kara
  Cc: Gao Xiang, Giuseppe Scrivano, linux-erofs, cyphar, linux-fsdevel,
	Christian Brauner

Hi Jan,

On Wed, Jul 29, 2026 at 11:57:25AM +0200, Jan Kara wrote:
> On Wed 29-07-26 09:40:50, Gao Xiang wrote:
> > On Tue, Jul 28, 2026 at 06:05:32PM +0200, Giuseppe Scrivano wrote:
> > > Allow userspace to pass an already-opened file descriptor as the mount
> > > source instead of a path string.  This is useful for tools that already
> > > hold an fd to the image, such as composefs reusing an existing erofs
> > > backing file.
> > > 
> > > Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
> > > ---
> > > v4: https://lore.kernel.org/linux-fsdevel/20260717134147.1602735-1-gscrivan@redhat.com/
> > > v3: https://lore.kernel.org/linux-fsdevel/20260714154917.489993-1-gscrivan@redhat.com/
> > > v2: https://lore.kernel.org/linux-fsdevel/20260711071137.4130824-1-gscrivan@redhat.com/
> > > v1: https://lore.kernel.org/linux-fsdevel/ak5GfvVfWLJU1EwK@debian/
> > > 
> > >  Documentation/filesystems/erofs.rst | 15 ++++++
> > >  fs/erofs/super.c                    | 73 ++++++++++++++++++++++++-----
> > >  2 files changed, 77 insertions(+), 11 deletions(-)
> > > 
> > > diff --git a/Documentation/filesystems/erofs.rst b/Documentation/filesystems/erofs.rst
> > > index 4230884fb359..774e8b236d09 100644
> > > --- a/Documentation/filesystems/erofs.rst
> > > +++ b/Documentation/filesystems/erofs.rst
> > > @@ -139,6 +139,21 @@ inode_share            Enable inode page sharing for this filesystem.  Inodes wi
> > >                         page cache.
> > >  ===================    =========================================================
> > >  
> > > +File-backed mounts
> > > +==================
> > > +
> > > +When CONFIG_EROFS_FS_BACKED_BY_FILE is enabled, EROFS file-backed images
> > > +can be mounted directly without a loopback block device.  The backing file
> > > +can be given either as a path, or as an already-opened file descriptor.
> > > +
> > > +When a file descriptor is used, the kernel resolves its path and records it
> > > +so that /proc/mounts and similar interfaces can still report the mount
> > > +source.
> > > +
> > > +Only regular files are accepted as backing files; to mount an image that
> > > +resides on a block device, use the traditional block device mount path
> > > +instead.
> > 
> > Reviewed-by: Gao Xiang <xiang@kernel.org>
> > 
> > Hi Christian, Jan, could you ack this (`fc->source` filling when
> > `source_fd` is used) if possible?
> 
> Whenever I see a use of d_path() (or file_path() in this case) I'm a bit
> watchful because its result is inherently racy and unsafe. But in this case
> the result is only used for alloc_vfsmnt() which uses it for mnt_devname so
> in the worst case we'll get an unreliable path in /proc/mounts or similar.
> I guess that's acceptable. So feel free to add:

Thanks for your reply and comment.  Yeah, the result of d_path() can become
outdated later since it only uses seqcounts to ensure that within the process,
but here I also think "mnt_devname" usage doesn't really matter (but I hope
filling like this is fine and stable in the long term.)

> 
> Acked-by: Jan Kara <jack@suse.cz>

Thanks!

Thanks,
Gao Xiang

> 
> 								Honza
> -- 
> Jan Kara <jack@suse.com>
> SUSE Labs, CR
> 

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH v5] erofs: accept source file descriptor via fsconfig
  2026-07-28 16:05 [PATCH v5] erofs: accept source file descriptor via fsconfig Giuseppe Scrivano
  2026-07-29  1:40 ` Gao Xiang
@ 2026-07-30  9:45 ` Christian Brauner
  2026-08-03 11:24 ` Chao Yu
  2 siblings, 0 replies; 9+ messages in thread
From: Christian Brauner @ 2026-07-30  9:45 UTC (permalink / raw)
  To: Giuseppe Scrivano; +Cc: linux-erofs, cyphar, hsiangkao, linux-fsdevel

Hi Giuseppe,

> Allow userspace to pass an already-opened file descriptor as the mount
> source instead of a path string.  This is useful for tools that already
> hold an fd to the image, such as composefs reusing an existing erofs
> backing file.
> 
> Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>

Acked-by: Christian Brauner (Amutable) <brauner@kernel.org>

-- 


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH v5] erofs: accept source file descriptor via fsconfig
  2026-07-28 16:05 [PATCH v5] erofs: accept source file descriptor via fsconfig Giuseppe Scrivano
  2026-07-29  1:40 ` Gao Xiang
  2026-07-30  9:45 ` Christian Brauner
@ 2026-08-03 11:24 ` Chao Yu
  2026-08-03 12:01   ` Giuseppe Scrivano
  2 siblings, 1 reply; 9+ messages in thread
From: Chao Yu @ 2026-08-03 11:24 UTC (permalink / raw)
  To: Giuseppe Scrivano, linux-erofs; +Cc: chao, cyphar, hsiangkao, linux-fsdevel

On 7/29/26 00:05, Giuseppe Scrivano wrote:
> Allow userspace to pass an already-opened file descriptor as the mount
> source instead of a path string.  This is useful for tools that already
> hold an fd to the image, such as composefs reusing an existing erofs
> backing file.
> 
> Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
> ---
> v4: https://lore.kernel.org/linux-fsdevel/20260717134147.1602735-1-gscrivan@redhat.com/
> v3: https://lore.kernel.org/linux-fsdevel/20260714154917.489993-1-gscrivan@redhat.com/
> v2: https://lore.kernel.org/linux-fsdevel/20260711071137.4130824-1-gscrivan@redhat.com/
> v1: https://lore.kernel.org/linux-fsdevel/ak5GfvVfWLJU1EwK@debian/
> 
>   Documentation/filesystems/erofs.rst | 15 ++++++
>   fs/erofs/super.c                    | 73 ++++++++++++++++++++++++-----
>   2 files changed, 77 insertions(+), 11 deletions(-)
> 
> diff --git a/Documentation/filesystems/erofs.rst b/Documentation/filesystems/erofs.rst
> index 4230884fb359..774e8b236d09 100644
> --- a/Documentation/filesystems/erofs.rst
> +++ b/Documentation/filesystems/erofs.rst
> @@ -139,6 +139,21 @@ inode_share            Enable inode page sharing for this filesystem.  Inodes wi
>                          page cache.
>   ===================    =========================================================
>   
> +File-backed mounts
> +==================
> +
> +When CONFIG_EROFS_FS_BACKED_BY_FILE is enabled, EROFS file-backed images
> +can be mounted directly without a loopback block device.  The backing file
> +can be given either as a path, or as an already-opened file descriptor.
> +
> +When a file descriptor is used, the kernel resolves its path and records it
> +so that /proc/mounts and similar interfaces can still report the mount
> +source.
> +
> +Only regular files are accepted as backing files; to mount an image that
> +resides on a block device, use the traditional block device mount path
> +instead.

Do we need to add an entry to describe the new mount option source= in
"Mount options" section in erofs.rst?

Thanks,

> +
>   Sysfs Entries
>   =============
>   
> diff --git a/fs/erofs/super.c b/fs/erofs/super.c
> index 86fa5c6a0c70..558041011398 100644
> --- a/fs/erofs/super.c
> +++ b/fs/erofs/super.c
> @@ -386,6 +386,7 @@ static void erofs_default_options(struct erofs_sb_info *sbi)
>   enum {
>   	Opt_user_xattr, Opt_acl, Opt_cache_strategy, Opt_dax, Opt_dax_enum,
>   	Opt_device, Opt_domain_id, Opt_directio, Opt_fsoffset, Opt_inode_share,
> +	Opt_source,
>   };
>   
>   static const struct constant_table erofs_param_cache_strategy[] = {
> @@ -402,17 +403,18 @@ static const struct constant_table erofs_dax_param_enums[] = {
>   };
>   
>   static const struct fs_parameter_spec erofs_fs_parameters[] = {
> -	fsparam_flag_no("user_xattr",	Opt_user_xattr),
> -	fsparam_flag_no("acl",		Opt_acl),
> -	fsparam_enum("cache_strategy",	Opt_cache_strategy,
> +	fsparam_flag_no("user_xattr",		Opt_user_xattr),
> +	fsparam_flag_no("acl",			Opt_acl),
> +	fsparam_enum("cache_strategy",		Opt_cache_strategy,
>   		     erofs_param_cache_strategy),
> -	fsparam_flag("dax",             Opt_dax),
> -	fsparam_enum("dax",		Opt_dax_enum, erofs_dax_param_enums),
> -	fsparam_string("device",	Opt_device),
> -	fsparam_string("domain_id",	Opt_domain_id),
> -	fsparam_flag_no("directio",	Opt_directio),
> -	fsparam_u64("fsoffset",		Opt_fsoffset),
> -	fsparam_flag("inode_share",	Opt_inode_share),
> +	fsparam_flag("dax",			Opt_dax),
> +	fsparam_enum("dax",			Opt_dax_enum, erofs_dax_param_enums),
> +	fsparam_string("device",		Opt_device),
> +	fsparam_string("domain_id",		Opt_domain_id),
> +	fsparam_flag_no("directio",		Opt_directio),
> +	fsparam_u64("fsoffset",			Opt_fsoffset),
> +	fsparam_flag("inode_share",		Opt_inode_share),
> +	fsparam_file_or_string("source",	Opt_source),
>   	{}
>   };
>   
> @@ -437,6 +439,40 @@ static bool erofs_fc_set_dax_mode(struct fs_context *fc, unsigned int mode)
>   	return false;
>   }
>   
> +static int erofs_fc_parse_source(struct fs_context *fc,
> +				 struct fs_parameter *param)
> +{
> +	struct erofs_sb_info *sbi = fc->s_fs_info;
> +
> +	if (fc->source || sbi->dif0.file)
> +		return invalf(fc, "Multiple sources");
> +
> +	switch (param->type) {
> +	case fs_value_is_string:
> +		fc->source = param->string;
> +		param->string = NULL;
> +		return 0;
> +	case fs_value_is_file: {
> +		char *buf __free(kfree) = kmalloc(PATH_MAX, GFP_KERNEL);
> +		char *p;
> +
> +		if (!buf)
> +			return -ENOMEM;
> +		p = file_path(param->file, buf, PATH_MAX);
> +		if (IS_ERR(p))
> +			return PTR_ERR(p);
> +		fc->source = kstrdup(p, GFP_KERNEL);
> +		if (!fc->source)
> +			return -ENOMEM;
> +		sbi->dif0.file = no_free_ptr(param->file);
> +		return 0;
> +	}
> +	default:
> +		WARN_ON_ONCE(true);
> +		return -EINVAL;
> +	}
> +}
> +
>   static int erofs_fc_parse_param(struct fs_context *fc,
>   				struct fs_parameter *param)
>   {
> @@ -524,6 +560,8 @@ static int erofs_fc_parse_param(struct fs_context *fc,
>   		else
>   			set_opt(&sbi->opt, INODE_SHARE);
>   		break;
> +	case Opt_source:
> +		return erofs_fc_parse_source(fc, param);
>   	}
>   	return 0;
>   }
> @@ -752,13 +790,26 @@ static int erofs_fc_fill_super(struct super_block *sb, struct fs_context *fc)
>   
>   static int erofs_fc_get_tree(struct fs_context *fc)
>   {
> +	struct erofs_sb_info *sbi = fc->s_fs_info;
>   	int ret;
>   
> +	if (sbi->dif0.file) {
> +		if (!IS_ENABLED(CONFIG_EROFS_FS_BACKED_BY_FILE)) {
> +			errorfc(fc, "source fd option not supported");
> +			return -EINVAL;
> +		}
> +		if (!S_ISREG(file_inode(sbi->dif0.file)->i_mode) ||
> +		    !sbi->dif0.file->f_mapping->a_ops->read_folio) {
> +			errorfc(fc, "source is unsupported");
> +			return -EINVAL;
> +		}
> +		return get_tree_nodev(fc, erofs_fc_fill_super);
> +	}
> +
>   	ret = get_tree_bdev_flags(fc, erofs_fc_fill_super,
>   		IS_ENABLED(CONFIG_EROFS_FS_BACKED_BY_FILE) ?
>   			GET_TREE_BDEV_QUIET_LOOKUP : 0);
>   	if (IS_ENABLED(CONFIG_EROFS_FS_BACKED_BY_FILE) && ret == -ENOTBLK) {
> -		struct erofs_sb_info *sbi = fc->s_fs_info;
>   		struct file *file;
>   
>   		if (!fc->source)


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH v5] erofs: accept source file descriptor via fsconfig
  2026-08-03 11:24 ` Chao Yu
@ 2026-08-03 12:01   ` Giuseppe Scrivano
  2026-08-03 23:37     ` Gao Xiang
  0 siblings, 1 reply; 9+ messages in thread
From: Giuseppe Scrivano @ 2026-08-03 12:01 UTC (permalink / raw)
  To: Chao Yu; +Cc: linux-erofs, cyphar, hsiangkao, linux-fsdevel

Chao Yu <chao@kernel.org> writes:

> On 7/29/26 00:05, Giuseppe Scrivano wrote:
>> Allow userspace to pass an already-opened file descriptor as the mount
>> source instead of a path string.  This is useful for tools that already
>> hold an fd to the image, such as composefs reusing an existing erofs
>> backing file.
>> Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
>> ---
>> v4: https://lore.kernel.org/linux-fsdevel/20260717134147.1602735-1-gscrivan@redhat.com/
>> v3: https://lore.kernel.org/linux-fsdevel/20260714154917.489993-1-gscrivan@redhat.com/
>> v2: https://lore.kernel.org/linux-fsdevel/20260711071137.4130824-1-gscrivan@redhat.com/
>> v1: https://lore.kernel.org/linux-fsdevel/ak5GfvVfWLJU1EwK@debian/
>>   Documentation/filesystems/erofs.rst | 15 ++++++
>>   fs/erofs/super.c                    | 73 ++++++++++++++++++++++++-----
>>   2 files changed, 77 insertions(+), 11 deletions(-)
>> diff --git a/Documentation/filesystems/erofs.rst
>> b/Documentation/filesystems/erofs.rst
>> index 4230884fb359..774e8b236d09 100644
>> --- a/Documentation/filesystems/erofs.rst
>> +++ b/Documentation/filesystems/erofs.rst
>> @@ -139,6 +139,21 @@ inode_share            Enable inode page sharing for this filesystem.  Inodes wi
>>                          page cache.
>>   ===================    =========================================================
>>   +File-backed mounts
>> +==================
>> +
>> +When CONFIG_EROFS_FS_BACKED_BY_FILE is enabled, EROFS file-backed images
>> +can be mounted directly without a loopback block device.  The backing file
>> +can be given either as a path, or as an already-opened file descriptor.
>> +
>> +When a file descriptor is used, the kernel resolves its path and records it
>> +so that /proc/mounts and similar interfaces can still report the mount
>> +source.
>> +
>> +Only regular files are accepted as backing files; to mount an image that
>> +resides on a block device, use the traditional block device mount path
>> +instead.
>
> Do we need to add an entry to describe the new mount option source= in
> "Mount options" section in erofs.rst?
>
> Thanks,

I've another patch "erofs: reuse superblock for file-backed mounts" that
also touches erofs.rst and it is currently based on top of this version.
I wonder what is your preferred way to handle them.

Will maintainers deal with conflicts or do I need to submit them as a
single series?

Do you prefer a new submission v6 with the following fixup?

diff --git a/Documentation/filesystems/erofs.rst b/Documentation/filesystems/erofs.rst
index c972a869f3e9..49c4e7dbc5d6 100644
--- a/Documentation/filesystems/erofs.rst
+++ b/Documentation/filesystems/erofs.rst
@@ -137,6 +137,8 @@ fsoffset=%llu          Specify block-aligned filesystem offset for the primary d
 inode_share            Enable inode page sharing for this filesystem.  Inodes with
                        identical content within the same domain ID can share the
                        page cache.
+source=%s              (For file-backed mounts) Specify the backing image as a path
+                       or as an already-opened file descriptor.

Thanks,
Giuseppe


^ permalink raw reply related	[flat|nested] 9+ messages in thread

* Re: [PATCH v5] erofs: accept source file descriptor via fsconfig
  2026-08-03 12:01   ` Giuseppe Scrivano
@ 2026-08-03 23:37     ` Gao Xiang
  2026-08-04  6:06       ` Giuseppe Scrivano
  0 siblings, 1 reply; 9+ messages in thread
From: Gao Xiang @ 2026-08-03 23:37 UTC (permalink / raw)
  To: Giuseppe Scrivano; +Cc: Chao Yu, linux-erofs, cyphar, hsiangkao, linux-fsdevel

On Mon, Aug 03, 2026 at 02:01:41PM +0200, Giuseppe Scrivano wrote:
> Chao Yu <chao@kernel.org> writes:
> 
> > On 7/29/26 00:05, Giuseppe Scrivano wrote:
> >> Allow userspace to pass an already-opened file descriptor as the mount
> >> source instead of a path string.  This is useful for tools that already
> >> hold an fd to the image, such as composefs reusing an existing erofs
> >> backing file.
> >> Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
> >> ---
> >> v4: https://lore.kernel.org/linux-fsdevel/20260717134147.1602735-1-gscrivan@redhat.com/
> >> v3: https://lore.kernel.org/linux-fsdevel/20260714154917.489993-1-gscrivan@redhat.com/
> >> v2: https://lore.kernel.org/linux-fsdevel/20260711071137.4130824-1-gscrivan@redhat.com/
> >> v1: https://lore.kernel.org/linux-fsdevel/ak5GfvVfWLJU1EwK@debian/
> >>   Documentation/filesystems/erofs.rst | 15 ++++++
> >>   fs/erofs/super.c                    | 73 ++++++++++++++++++++++++-----
> >>   2 files changed, 77 insertions(+), 11 deletions(-)
> >> diff --git a/Documentation/filesystems/erofs.rst
> >> b/Documentation/filesystems/erofs.rst
> >> index 4230884fb359..774e8b236d09 100644
> >> --- a/Documentation/filesystems/erofs.rst
> >> +++ b/Documentation/filesystems/erofs.rst
> >> @@ -139,6 +139,21 @@ inode_share            Enable inode page sharing for this filesystem.  Inodes wi
> >>                          page cache.
> >>   ===================    =========================================================
> >>   +File-backed mounts
> >> +==================
> >> +
> >> +When CONFIG_EROFS_FS_BACKED_BY_FILE is enabled, EROFS file-backed images
> >> +can be mounted directly without a loopback block device.  The backing file
> >> +can be given either as a path, or as an already-opened file descriptor.
> >> +
> >> +When a file descriptor is used, the kernel resolves its path and records it
> >> +so that /proc/mounts and similar interfaces can still report the mount
> >> +source.
> >> +
> >> +Only regular files are accepted as backing files; to mount an image that
> >> +resides on a block device, use the traditional block device mount path
> >> +instead.
> >
> > Do we need to add an entry to describe the new mount option source= in
> > "Mount options" section in erofs.rst?
> >
> > Thanks,
> 
> I've another patch "erofs: reuse superblock for file-backed mounts" that
> also touches erofs.rst and it is currently based on top of this version.
> I wonder what is your preferred way to handle them.

EROFS dev branch usually has a small number of patches. Since Chao gave
a new suggestion, I think a v6 is needed (but you could add all
previous reviewed-by:).

And "erofs: reuse superblock for file-backed mounts" needs to be rebased
too, I will find time to play with it this week (or you could add a
testcase in erofs-utils experimental-tests if you have time.)

> 
> Will maintainers deal with conflicts or do I need to submit them as a
> single series?
> 
> Do you prefer a new submission v6 with the following fixup?
> 
> diff --git a/Documentation/filesystems/erofs.rst b/Documentation/filesystems/erofs.rst
> index c972a869f3e9..49c4e7dbc5d6 100644
> --- a/Documentation/filesystems/erofs.rst
> +++ b/Documentation/filesystems/erofs.rst
> @@ -137,6 +137,8 @@ fsoffset=%llu          Specify block-aligned filesystem offset for the primary d
>  inode_share            Enable inode page sharing for this filesystem.  Inodes with
>                         identical content within the same domain ID can share the
>                         page cache.
> +source=%s              (For file-backed mounts) Specify the backing image as a path
> +                       or as an already-opened file descriptor.

Not quite sure "an already-opened file descriptor" is "%s", but I'm fine
since it's quite a minor one (it's unneeded to nitpick the
documentation).

Thanks,
Gao Xiang


> 
> Thanks,
> Giuseppe
> 
> 

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH v5] erofs: accept source file descriptor via fsconfig
  2026-08-03 23:37     ` Gao Xiang
@ 2026-08-04  6:06       ` Giuseppe Scrivano
  0 siblings, 0 replies; 9+ messages in thread
From: Giuseppe Scrivano @ 2026-08-04  6:06 UTC (permalink / raw)
  To: Chao Yu; +Cc: linux-erofs, cyphar, hsiangkao, linux-fsdevel

Gao Xiang <hsiangkao@gmx.com> writes:

> On Mon, Aug 03, 2026 at 02:01:41PM +0200, Giuseppe Scrivano wrote:
>> Chao Yu <chao@kernel.org> writes:
>> 
>> > On 7/29/26 00:05, Giuseppe Scrivano wrote:
>> >> Allow userspace to pass an already-opened file descriptor as the mount
>> >> source instead of a path string.  This is useful for tools that already
>> >> hold an fd to the image, such as composefs reusing an existing erofs
>> >> backing file.
>> >> Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
>> >> ---
>> >> v4: https://lore.kernel.org/linux-fsdevel/20260717134147.1602735-1-gscrivan@redhat.com/
>> >> v3: https://lore.kernel.org/linux-fsdevel/20260714154917.489993-1-gscrivan@redhat.com/
>> >> v2: https://lore.kernel.org/linux-fsdevel/20260711071137.4130824-1-gscrivan@redhat.com/
>> >> v1: https://lore.kernel.org/linux-fsdevel/ak5GfvVfWLJU1EwK@debian/
>> >>   Documentation/filesystems/erofs.rst | 15 ++++++
>> >>   fs/erofs/super.c                    | 73 ++++++++++++++++++++++++-----
>> >>   2 files changed, 77 insertions(+), 11 deletions(-)
>> >> diff --git a/Documentation/filesystems/erofs.rst
>> >> b/Documentation/filesystems/erofs.rst
>> >> index 4230884fb359..774e8b236d09 100644
>> >> --- a/Documentation/filesystems/erofs.rst
>> >> +++ b/Documentation/filesystems/erofs.rst
>> >> @@ -139,6 +139,21 @@ inode_share            Enable inode page sharing for this filesystem.  Inodes wi
>> >>                          page cache.
>> >>   ===================    =========================================================
>> >>   +File-backed mounts
>> >> +==================
>> >> +
>> >> +When CONFIG_EROFS_FS_BACKED_BY_FILE is enabled, EROFS file-backed images
>> >> +can be mounted directly without a loopback block device.  The backing file
>> >> +can be given either as a path, or as an already-opened file descriptor.
>> >> +
>> >> +When a file descriptor is used, the kernel resolves its path and records it
>> >> +so that /proc/mounts and similar interfaces can still report the mount
>> >> +source.
>> >> +
>> >> +Only regular files are accepted as backing files; to mount an image that
>> >> +resides on a block device, use the traditional block device mount path
>> >> +instead.
>> >
>> > Do we need to add an entry to describe the new mount option source= in
>> > "Mount options" section in erofs.rst?
>> >
>> > Thanks,
>> 
>> I've another patch "erofs: reuse superblock for file-backed mounts" that
>> also touches erofs.rst and it is currently based on top of this version.
>> I wonder what is your preferred way to handle them.
>
> EROFS dev branch usually has a small number of patches. Since Chao gave
> a new suggestion, I think a v6 is needed (but you could add all
> previous reviewed-by:).
>
> And "erofs: reuse superblock for file-backed mounts" needs to be rebased
> too, I will find time to play with it this week (or you could add a
> testcase in erofs-utils experimental-tests if you have time.)
>
>> 
>> Will maintainers deal with conflicts or do I need to submit them as a
>> single series?
>> 
>> Do you prefer a new submission v6 with the following fixup?
>> 
>> diff --git a/Documentation/filesystems/erofs.rst b/Documentation/filesystems/erofs.rst
>> index c972a869f3e9..49c4e7dbc5d6 100644
>> --- a/Documentation/filesystems/erofs.rst
>> +++ b/Documentation/filesystems/erofs.rst
>> @@ -137,6 +137,8 @@ fsoffset=%llu          Specify block-aligned filesystem offset for the primary d
>>  inode_share            Enable inode page sharing for this filesystem.  Inodes with
>>                         identical content within the same domain ID can share the
>>                         page cache.
>> +source=%s              (For file-backed mounts) Specify the backing image as a path
>> +                       or as an already-opened file descriptor.
>
> Not quite sure "an already-opened file descriptor" is "%s", but I'm fine
> since it's quite a minor one (it's unneeded to nitpick the
> documentation).

thanks, I've sent v6 as well as the rebase of "erofs: reuse superblock
for file-backed mounts" on top of it.

Regards,
Giuseppe


^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2026-08-04  6:06 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-07-28 16:05 [PATCH v5] erofs: accept source file descriptor via fsconfig Giuseppe Scrivano
2026-07-29  1:40 ` Gao Xiang
2026-07-29  9:57   ` Jan Kara
2026-07-29 20:19     ` Gao Xiang
2026-07-30  9:45 ` Christian Brauner
2026-08-03 11:24 ` Chao Yu
2026-08-03 12:01   ` Giuseppe Scrivano
2026-08-03 23:37     ` Gao Xiang
2026-08-04  6:06       ` Giuseppe Scrivano

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox