* [PATCH v3] erofs: accept source file descriptor via fsconfig
@ 2026-07-14 15:48 Giuseppe Scrivano
2026-07-17 3:42 ` Gao Xiang
0 siblings, 1 reply; 4+ messages in thread
From: Giuseppe Scrivano @ 2026-07-14 15:48 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>
---
v2: https://lore.kernel.org/linux-fsdevel/20260711071137.4130824-1-gscrivan@redhat.com/
v1: https://lore.kernel.org/linux-fsdevel/ak5GfvVfWLJU1EwK@debian/
fs/erofs/super.c | 87 ++++++++++++++++++++++++++++++++++++------------
1 file changed, 65 insertions(+), 22 deletions(-)
diff --git a/fs/erofs/super.c b/fs/erofs/super.c
index 86fa5c6a0c70..d7baf9f34dc0 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,14 +790,18 @@ static int erofs_fc_fill_super(struct super_block *sb, struct fs_context *fc)
static int erofs_fc_get_tree(struct fs_context *fc)
{
- int ret;
+ struct erofs_sb_info *sbi = fc->s_fs_info;
+ struct file *file = sbi->dif0.file;
- 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 (!IS_ENABLED(CONFIG_EROFS_FS_BACKED_BY_FILE) || !file) {
+ int ret;
+
+ 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)
+ return ret;
if (!fc->source)
return invalf(fc, "No source specified");
@@ -767,12 +809,13 @@ static int erofs_fc_get_tree(struct fs_context *fc)
if (IS_ERR(file))
return PTR_ERR(file);
sbi->dif0.file = file;
-
- if (S_ISREG(file_inode(sbi->dif0.file)->i_mode) &&
- sbi->dif0.file->f_mapping->a_ops->read_folio)
- return get_tree_nodev(fc, erofs_fc_fill_super);
}
- return ret;
+ if (!S_ISREG(file_inode(file)->i_mode) ||
+ !file->f_mapping->a_ops->read_folio) {
+ errorfc(fc, "source is unsupported");
+ return -EINVAL;
+ }
+ return get_tree_nodev(fc, erofs_fc_fill_super);
}
static int erofs_fc_reconfigure(struct fs_context *fc)
--
2.55.0
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH v3] erofs: accept source file descriptor via fsconfig
2026-07-14 15:48 [PATCH v3] erofs: accept source file descriptor via fsconfig Giuseppe Scrivano
@ 2026-07-17 3:42 ` Gao Xiang
2026-07-17 8:28 ` Giuseppe Scrivano
0 siblings, 1 reply; 4+ messages in thread
From: Gao Xiang @ 2026-07-17 3:42 UTC (permalink / raw)
To: Giuseppe Scrivano, linux-erofs; +Cc: cyphar, linux-fsdevel
Hi Giuseppe,
On 2026/7/14 23:48, 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>
Use the current erofs-utils testsuite, the following tests seems skipped incorrectly.
[Error 22] Invalid argument
SKIP: erofs/008
[Error 22] Invalid argument
SKIP: erofs/009
[Error 22] Invalid argument
SKIP: erofs/010
[Error 22] Invalid argument
SKIP: erofs/011
[Error 22] Invalid argument
SKIP: erofs/017
[Error 22] Invalid argument
SKIP: erofs/018
And the kernel message shows:
[ 116.477816] erofs: source is unsupported
...
git://git.kernel.org/pub/scm/linux/kernel/git/xiang/erofs-utils.git -b experimental-tests
$ sudo make check
Thanks,
Gao Xiang
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH v3] erofs: accept source file descriptor via fsconfig
2026-07-17 3:42 ` Gao Xiang
@ 2026-07-17 8:28 ` Giuseppe Scrivano
2026-07-17 8:37 ` Gao Xiang
0 siblings, 1 reply; 4+ messages in thread
From: Giuseppe Scrivano @ 2026-07-17 8:28 UTC (permalink / raw)
To: Gao Xiang; +Cc: linux-erofs, cyphar, linux-fsdevel
Gao Xiang <hsiangkao@linux.alibaba.com> writes:
> Hi Giuseppe,
>
> On 2026/7/14 23:48, 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>
>
> Use the current erofs-utils testsuite, the following tests seems skipped incorrectly.
>
> [Error 22] Invalid argument
> SKIP: erofs/008
> [Error 22] Invalid argument
> SKIP: erofs/009
> [Error 22] Invalid argument
> SKIP: erofs/010
> [Error 22] Invalid argument
> SKIP: erofs/011
>
> [Error 22] Invalid argument
> SKIP: erofs/017
> [Error 22] Invalid argument
> SKIP: erofs/018
>
> And the kernel message shows:
> [ 116.477816] erofs: source is unsupported
> ...
>
> git://git.kernel.org/pub/scm/linux/kernel/git/xiang/erofs-utils.git -b experimental-tests
> $ sudo make check
>
> Thanks,
> Gao Xiang
it seems to be caused by the different error returned by erofs_fc_get_tree.
Would you be fine if I amend this on top of v3?
Thanks,
Giuseppe
diff --git a/fs/erofs/super.c b/fs/erofs/super.c
index d7baf9f34dc0..829ae530d7ca 100644
--- a/fs/erofs/super.c
+++ b/fs/erofs/super.c
@@ -791,17 +791,22 @@ 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;
- struct file *file = sbi->dif0.file;
+ int ret;
- if (!IS_ENABLED(CONFIG_EROFS_FS_BACKED_BY_FILE) || !file) {
- int ret;
+ if (IS_ENABLED(CONFIG_EROFS_FS_BACKED_BY_FILE) && sbi->dif0.file) {
+ 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)
- return ret;
+ 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 file *file;
if (!fc->source)
return invalf(fc, "No source specified");
@@ -809,13 +814,12 @@ static int erofs_fc_get_tree(struct fs_context *fc)
if (IS_ERR(file))
return PTR_ERR(file);
sbi->dif0.file = file;
+
+ if (S_ISREG(file_inode(sbi->dif0.file)->i_mode) &&
+ sbi->dif0.file->f_mapping->a_ops->read_folio)
+ return get_tree_nodev(fc, erofs_fc_fill_super);
}
- if (!S_ISREG(file_inode(file)->i_mode) ||
- !file->f_mapping->a_ops->read_folio) {
- errorfc(fc, "source is unsupported");
- return -EINVAL;
- }
- return get_tree_nodev(fc, erofs_fc_fill_super);
+ return ret;
}
static int erofs_fc_reconfigure(struct fs_context *fc)
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH v3] erofs: accept source file descriptor via fsconfig
2026-07-17 8:28 ` Giuseppe Scrivano
@ 2026-07-17 8:37 ` Gao Xiang
0 siblings, 0 replies; 4+ messages in thread
From: Gao Xiang @ 2026-07-17 8:37 UTC (permalink / raw)
To: Giuseppe Scrivano; +Cc: linux-erofs, cyphar, linux-fsdevel
On 2026/7/17 16:28, Giuseppe Scrivano wrote:
> Gao Xiang <hsiangkao@linux.alibaba.com> writes:
>
>> Hi Giuseppe,
>>
>> On 2026/7/14 23:48, 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>
>>
>> Use the current erofs-utils testsuite, the following tests seems skipped incorrectly.
>>
>> [Error 22] Invalid argument
>> SKIP: erofs/008
>> [Error 22] Invalid argument
>> SKIP: erofs/009
>> [Error 22] Invalid argument
>> SKIP: erofs/010
>> [Error 22] Invalid argument
>> SKIP: erofs/011
>>
>> [Error 22] Invalid argument
>> SKIP: erofs/017
>> [Error 22] Invalid argument
>> SKIP: erofs/018
>>
>> And the kernel message shows:
>> [ 116.477816] erofs: source is unsupported
>> ...
>>
>> git://git.kernel.org/pub/scm/linux/kernel/git/xiang/erofs-utils.git -b experimental-tests
>> $ sudo make check
>>
>> Thanks,
>> Gao Xiang
>
> it seems to be caused by the different error returned by erofs_fc_get_tree.
>
> Would you be fine if I amend this on top of v3?
I think you could just send out the diff from the baseline
since it might be harder to follow an incremental diff here.
But anyway, new versions are always welcome, I will play
with them when I am availble.
Thanks,
Gao Xiang
>
> Thanks,
> Giuseppe
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2026-07-17 8:37 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-07-14 15:48 [PATCH v3] erofs: accept source file descriptor via fsconfig Giuseppe Scrivano
2026-07-17 3:42 ` Gao Xiang
2026-07-17 8:28 ` Giuseppe Scrivano
2026-07-17 8:37 ` Gao Xiang
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.