Re: [PATCH v4] erofs: accept source file descriptor via fsconfig

Gao Xiang <[email protected]> Tue, 28 Jul 2026 20:33:52 +0800
Newsgroups org.ozlabs.lists.linux-erofs,org.kernel.vger.linux-fsdevel
Message-ID <[email protected]>
Hi Giuseppe,

On 2026/7/27 16:01, Giuseppe Scrivano wrote:
> Gao Xiang <[email protected]> writes:
> 
>> Hi Christian,
>>
>> On 2026/7/23 22:46, Christian Brauner wrote:
>>>> 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.
>>> 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.
> 
> would something like the following be enough?
> 
> diff --git a/Documentation/filesystems/erofs.rst b/Documentation/filesystems/erofs.rst
> index 4230884fb359..768e1d43dfcc 100644
> --- a/Documentation/filesystems/erofs.rst
> +++ b/Documentation/filesystems/erofs.rst
> @@ -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


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.)

> +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.)

> +
> +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