erofs: accept source file descriptor via fsconfig
Subsystems (3)
PATCH v4 1/1 erofs: accept source file descriptor via fsconfig
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.
---
v3: https://lore.kernel.org/linux-fsdevel/[email protected]/
v2: https://lore.kernel.org/linux-fsdevel/[email protected]/
v1: https://lore.kernel.org/linux-fsdevel/ak5GfvVfWLJU1EwK@debian/
fs/erofs/super.c | 73 ++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 62 insertions(+), 11 deletions(-)
fs/erofs/super.c +62 -11
@@ -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)
Signature · 1 line
2.55.0
Quoted 7 lines · Giuseppe Scrivano
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 <[email protected]>---
Looks good and tested:
I wonder if Aleksa and Christian have more comments since anyway it touches fc->source, but I will queue for the next cycle if there is no other opinion.
Thanks,
Gao Xiang
Christian Brauner
maintainerQuoted 56 lines
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 <[email protected]>fs/erofs/super.c +16
-10@@ -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;
fs/erofs/super.c static bool erofs_fc_set_dax_mode(struct fs_context *fc, unsigned int mode) · line 455
Quoted 10 lines
fs/erofs/super.c +10
-0+ +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: {
Afaict this is just fsparam_file_or_string()?
fs/erofs/super.c static bool erofs_fc_set_dax_mode(struct fs_context *fc, unsigned int mode) · line 466
Quoted 11 lines
fs/erofs/super.c +11
-0+ 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 ;
Hm, hm, hm... How is that reliable? So iirc this is then passed to:
static int erofs_fc_get_tree(struct fs_context *fc)
{
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) {
struct erofs_sb_info *sbi = fc->s_fs_info;
struct file *file;
if (!fc->source)
return invalf(fc, "No source specified");
file = filp_open(fc->source, O_RDONLY | O_LARGEFILE, 0);
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;
}which then reopens the file or looks up the block device. So the only way this is _vaguely_ (and really _very vaguely_) safe is if userspace keeps at least the file descriptor open until the filesystem has been mounted.
If they close it before this means you can mount something completely different. The other thing is even if they keep the fd open someone could just rename the damn thing and fc->source ends up pointing somwhere completely different. The could switch namespaces as well in some circumstances and then it points again into wherever.
I've played with that fd idea before. The only way to make this work correctly is if you plumb this down into get_tree_nodev()
Hi Christian,
Quoted 108 lines · Christian Brauner
Quoted 56 lines
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 <[email protected]>fs/erofs/super.c +16
-10@@ -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;fs/erofs/super.c static bool erofs_fc_set_dax_mode(struct fs_context *fc, unsigned int mode) · line 455
Quoted 10 lines
fs/erofs/super.c +10
-0+ +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: {Afaict this is just
fsparam_file_or_string()?fs/erofs/super.c static bool erofs_fc_set_dax_mode(struct fs_context *fc, unsigned int mode) · line 466
Quoted 11 lines
fs/erofs/super.c +11
-0+ 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 ;Hm, hm, hm... How is that reliable? So iirc this is then passed to:
static int
erofs_fc_get_tree(struct fs_context *fc){ 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) { struct erofs_sb_info *sbi = fc->s_fs_info; struct file *file; if (!fc->source) return invalf(fc, "No source specified"); file = filp_open(fc->source, O_RDONLY | O_LARGEFILE, 0); 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; }
Quoted 4 lines
which then reopens the file or looks up the block device. So the only way this is _vaguely_ (and really
_veryvaguely_) safe is if userspace keeps at least the file descriptor open until the filesystem has been mounted.
I'm not quite sure if I catched the point, I think Giuseppe's patch here tried to record file into sbi->dif0.file (which indicates the primary "device" later.)
And if sbi->dif0.file is set up by erofs_fc_parse_source(), erofs_fc_get_tree() will just use sbi->dif0.file instead of fc->source according to this patch.
The reason why fc->source is set was discussed in the thread of the previous version suggested by Aleksa.
Quoted 9 lines
If they close it before this means you can mount something completely different. The other thing is even if they keep the fd open someone could just rename the damn thing and
fc->sourceends up pointing somwhere completely different. The could switch namespaces as well in some circumstances and then it points again into wherever.I've played with that fd idea before. The only way to make this work correctly is if you plumb this down into
get_tree_nodev()
fc->source in this case has no use in erofs_fc_get_tree() (fc->source is just used for mountinfo for example), sbi->dif0.file works instead I hope I don't misunderstand something.
Thanks,
Gao Xiang
Quoted 1 line
Christian Brauner
maintainerQuoted 7 lines
I'm not quite sure if I catched the point, I think Giuseppe's patch here tried to record
fileintosbi->dif0.file(which indicates the primary "device" later.)And if
sbi->dif0.fileis set up byerofs_fc_parse_source(),erofs_fc_get_tree()will just usesbi->dif0.fileinstead offc->sourceaccording to this patch.
Oh, so you only do it for file-backed mounts. Do you only allow regular files or do you also support block devices with CONFIG_EROFS_FS_BACKED_BY_FILE?
Do you document the expected behavior for the file you're consuming? Meaning, are concurrent modifications supported and what type of behavior does this exhibit?
Quoted 10 lines
The reason why
fc->sourceis set was discussed in the thread of the previous version suggested by Aleksa.Quoted 7 lines
If they close it before this means you can mount something completely different. The other thing is even if they keep the fd open someone could just rename the damn thing and
fc->sourceends up pointing somwhere completely different. The could switch namespaces as well in some circumstances and then it points again into wherever.
Quoted 6 lines
Quoted 2 lines
I've played with that fd idea before. The only way to make this work correctly is if you plumb this down into
get_tree_nodev()
fc->sourcein this case has no use inerofs_fc_get_tree()(fc->sourceis just used for mountinfo for example),sbi->dif0.fileworks instead I hope I don't misunderstand something.
No, I misunderstood this.
Hi Christian,
Quoted 11 lines · Christian Brauner
Quoted 7 lines
I'm not quite sure if I catched the point, I think Giuseppe's patch here tried to record
fileintosbi->dif0.file(which indicates the primary "device" later.)And if
sbi->dif0.fileis set up byerofs_fc_parse_source(),erofs_fc_get_tree()will just usesbi->dif0.fileinstead offc->sourceaccording to this patch.Oh, so you only do it for file-backed mounts. Do you only allow regular files or do you also support block devices with
CONFIG_EROFS_FS_BACKED_BY_FILE?
Block devices with CONFIG_EROFS_FS_BACKED_BY_FILE are supported, but with only fc->source (not this way.)
That is the limitation I see in Giuseppe's patch. I'd hoped bdev-backed mounts could work the same way, but that would require changes to the VFS flow.
Since this is a side improvement, I think it's fine as long as it's documented somewhere, and I do hope Giuseppe can at least address the documentation.
I'd also like to make sure the way fc->source is filled out of fd passing follows common practice, so that if fd-based bdev-backed mounts land in the VFS later, they can keep the same fc->source convention, otherwise it will cause a userspace behavior change.
Quoted 4 lines
Do you document the expected behavior for the file you're consuming? Meaning, are concurrent modifications supported and what type of behavior does this exhibit?
As I perhaps mentioned, EROFS itself (or many EROFS) won't do any modification to the underlayfs bdev or files by design so the standard behavior is the blob devices / files won't get any change. Beyond that, both the on-disk format and the implementation are designed to tolerate unexpected external modifications (or storage media damage). Even in the worst case, where the underlying storage (block device or backing filesystem) is malicious, corrupted on-disk (meta)data will not lead to the kind of complex, hard-to-resolve inconsistencies you see in general-purpose writable filesystems, whose ondisk/in-memory cached metadata is much harder to reconcile.
I'm not sure whether you'll agree, but I want to emphasize that again this is one of EROFS core design goals: the on-disk and implementation design ensure that. If there is any human bug, it will be addressed and fixed as long as it discloses: it won't be hard to fixed.
But if you really want to avoid concurrent modifications or keep the image golden, I think dmverity or fsverify should be enforced to ensure the filesystem won't be modified unexpectedly or expectedly.
Quoted 11 lines
Quoted 11 lines
The reason why
fc->sourceis set was discussed in the thread of the previous version suggested by Aleksa.Quoted 7 lines
If they close it before this means you can mount something completely different. The other thing is even if they keep the fd open someone could just rename the damn thing and
fc->sourceends up pointing somwhere completely different. The could switch namespaces as well in some circumstances and then it points again into wherever.
Quoted 8 lines
Quoted 6 lines
Quoted 2 lines
I've played with that fd idea before. The only way to make this work correctly is if you plumb this down into
get_tree_nodev()
fc->sourcein this case has no use inerofs_fc_get_tree()(fc->sourceis just used for mountinfo for example),sbi->dif0.fileworks instead I hope I don't misunderstand something.No, I misunderstood this.
Thanks,
Gao Xiang
Quoted 18 lines · Gao Xiang
Hi Christian,
Quoted 11 lines · Christian Brauner
Quoted 7 lines
I'm not quite sure if I catched the point, I think Giuseppe's patch here tried to record
fileintosbi->dif0.file(which indicates the primary "device" later.)And if
sbi->dif0.fileis set up byerofs_fc_parse_source(),erofs_fc_get_tree()will just usesbi->dif0.fileinstead offc->sourceaccording to this patch.Oh, so you only do it for file-backed mounts. Do you only allow regular
files or do you also support block devices withCONFIG_EROFS_FS_BACKED_BY_FILE?Block devices with
CONFIG_EROFS_FS_BACKED_BY_FILEare supported, but with onlyfc->source(not this way.)
Quoted 7 lines
That is the limitation I see in Giuseppe's patch. I'd hoped bdev-backed mounts could work the same way, but that would require changes to the VFS flow.
Since this is a side improvement, I think it's fine as long as it's documented somewhere, and I do hope Giuseppe can at least address the documentation.
would something like the following be enough?
Documentation/filesystems/erofs.rst +23 -0
@@ -139,6 +139,29 @@ 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 can mount filesystem +images stored as regular files directly, without requiring a loopback block +device. The source can be specified either by path or by passing an +already-opened file descriptor via ``fsconfig(fd, FSCONFIG_SET_FD, "source", +NULL, source_fd)``. Only regular files are accepted; block devices must use +the standard block device mount path. + +The backing file content must remain stable for the lifetime of the mount. +EROFS never writes to it, but concurrent modifications by other processes lead +to undefined behavior. + +Ioctls +====== + +``EROFS_IOC_GET_SOURCE_FD`` + Return a read-only file descriptor (``O_CLOEXEC``) for the backing file of a + file-backed mount. Returns ``-ENOENT`` on block-device-backed mounts. + Requires ``CAP_SYS_ADMIN`` in the initial user namespace (returns ``-EPERM`` + otherwise). + Sysfs Entries =============
Regards,
Giuseppe
Quoted 53 lines
I'd also like to make sure the way
fc->sourceis filled out of fd passing follows common practice, so that if fd-based bdev-backed mounts land in the VFS later, they can keep the samefc->sourceconvention, otherwise it will cause a userspace behavior change.Quoted 3 lines
Do you document the expected behavior for the file you're consuming? Meaning, are concurrent modifications supported and what type of behavior does this exhibit?
As I perhaps mentioned, EROFS itself (or many EROFS) won't do any modification to the underlayfs bdev or files by design so the standard behavior is the blob devices / files won't get any change. Beyond that, both the on-disk format and the implementation are designed to tolerate unexpected external modifications (or storage media damage). Even in the worst case, where the underlying storage (block device or backing filesystem) is malicious, corrupted on-disk (meta)data will not lead to the kind of complex, hard-to-resolve inconsistencies you see in general-purpose writable filesystems, whose ondisk/in-memory cached metadata is much harder to reconcile.
I'm not sure whether you'll agree, but I want to emphasize that again this is one of EROFS core design goals: the on-disk and implementation design ensure that. If there is any human bug, it will be addressed and fixed as long as it discloses: it won't be hard to fixed.
But if you really want to avoid concurrent modifications or keep the image golden, I think dmverity or fsverify should be enforced to ensure the filesystem won't be modified unexpectedly or expectedly.
Quoted 11 lines
Quoted 11 lines
The reason why
fc->sourceis set was discussed in the thread of the previous version suggested by Aleksa.Quoted 7 lines
If they close it before this means you can mount something completely different. The other thing is even if they keep the fd open someone could just rename the damn thing and
fc->sourceends up pointing somwhere completely different. The could switch namespaces as well in some circumstances and then it points again into wherever.Quoted 7 lines
Quoted 6 lines
Quoted 2 lines
I've played with that fd idea before. The only way to make this work correctly is if you plumb this down into
get_tree_nodev()
fc->sourcein this case has no use inerofs_fc_get_tree()(fc->sourceis just used for mountinfo for example),sbi->dif0.fileworks instead I hope I don't misunderstand something.No, I misunderstood this.
Thanks,
Gao Xiang
Hi Giuseppe,
Quoted 36 lines · Giuseppe Scrivano
Quoted 18 lines · Gao Xiang
Hi Christian,
Quoted 11 lines · Christian Brauner
Quoted 7 lines
I'm not quite sure if I catched the point, I think Giuseppe's patch here tried to record
fileintosbi->dif0.file(which indicates the primary "device" later.)And if
sbi->dif0.fileis set up byerofs_fc_parse_source(),erofs_fc_get_tree()will just usesbi->dif0.fileinstead offc->sourceaccording to this patch.Oh, so you only do it for file-backed mounts. Do you only allow regular
files or do you also support block devices withCONFIG_EROFS_FS_BACKED_BY_FILE?Block devices with
CONFIG_EROFS_FS_BACKED_BY_FILEare supported, but with onlyfc->source(not this way.)Quoted 7 lines
That is the limitation I see in Giuseppe's patch. I'd hoped bdev-backed mounts could work the same way, but that would require changes to the VFS flow.
Since this is a side improvement, I think it's fine as long as it's documented somewhere, and I do hope Giuseppe can at least address the documentation.
would something like the following be enough?
Documentation/filesystems/erofs.rst +0
-0@@ -139,6 +139,29 @@ inode_share Enable inode page sharing for this filesystem. Inodes wi page cache.
Documentation/filesystems/erofs.rst inode_share Enable inode page sharing for this filesystem. Inodes wi · line 149
Quoted 10 lines
Documentation/filesystems/erofs.rst +8
-0=================== ========================================================= +File-backed mounts +================== + +When ``CONFIG_EROFS_FS_BACKED_BY_FILE`` is enabled, EROFS can mount filesystem +images stored as regular files directly, without requiring a loopback block +device. The source can be specified either by path or by passing an +already-opened file descriptor via ``fsconfig(fd, FSCONFIG_SET_FD, "source", +NULL, source_fd)``. Only regular files are accepted; block devices must use
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 via ``fsconfig(fd, FSCONFIG_SET_FD, "source", NULL, source_fd)``.
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.
It's just my own sketch of this; you could just fold this into this patch with modification (I'm not quite good at English.)
Also it lacks how fc->source is filled when source_fd is specified, we may need to document here as well (and hopefully vfs maintainers can ack on this so it can be stable.)
Documentation/filesystems/erofs.rst inode_share Enable inode page sharing for this filesystem. Inodes wi · line 154
Quoted 6 lines
Documentation/filesystems/erofs.rst +5
-0+the standard block device mount path. + +The backing file content must remain stable for the lifetime of the mount. +EROFS never writes to it, but concurrent modifications by other processes lead +to undefined behavior.
Yes, I explained to Christian but I don't think it should be included in this patch, maybe we need to document this as a new section in a seperate patch later (possibly as a formal security model.)
Documentation/filesystems/erofs.rst inode_share Enable inode page sharing for this filesystem. Inodes wi · line 163
Quoted 9 lines
Documentation/filesystems/erofs.rst +9
-0+ +Ioctls +====== + +``EROFS_IOC_GET_SOURCE_FD`` + Return a read-only file descriptor (``O_CLOEXEC``) for the backing file of a + file-backed mount. Returns ``-ENOENT`` on block-device-backed mounts. + Requires ``CAP_SYS_ADMIN`` in the initial user namespace (returns ``-EPERM`` + otherwise).
I hope document this part in the corresponding patch but I guess we have to get a consensus between filesystems first.
Thanks,
Gao Xiang