Skip to content

fix(fuse) support FUSE submounts and fix virtiofs mount semantics#1968

Open
xboHodx wants to merge 21 commits into
DragonOS-Community:masterfrom
xboHodx:kata-split/fuse-vfs
Open

fix(fuse) support FUSE submounts and fix virtiofs mount semantics#1968
xboHodx wants to merge 21 commits into
DragonOS-Community:masterfrom
xboHodx:kata-split/fuse-vfs

Conversation

@xboHodx

@xboHodx xboHodx commented Jun 7, 2026

Copy link
Copy Markdown
Contributor

主要改动

  • 为 virtiofs/FUSE 增加 FUSE_SUBMOUNTSFUSE_ATTR_SUBMOUNT 支持,在 lookup 到子挂载标记目录时自动创建 DragonOS 子挂载。
  • 扩展 FuseNode 状态:
    • 记录 lookup attr flags 与 generation;
    • 检测 nodeid 被复用时标记旧节点 stale;
    • stale 节点继续访问时返回 ESTALE
    • 避免对仍在使用的过期 inode 继续发起错误 FUSE 操作。
  • 调整 FUSE INIT 协商:
    • 普通 FUSE 与 virtiofs 使用不同 capability 请求;
    • virtiofs 额外请求 submount;
    • 只启用“本端请求且 daemon 回复支持”的 capability;
    • 暂不请求 FUSE_WRITEBACK_CACHE,避免语义不完整。
  • 修正 FUSE open/read/write/release 语义:
    • open 时按 Linux 语义过滤 O_CREAT/O_EXCL/O_NOCTTY
    • FUSE_ATOMIC_O_TRUNC 不支持时过滤 O_TRUNC
    • release/read/write 使用打开文件保存的原始 flags;
    • 正确支持 daemon 返回 fh=0
    • no-open 情况下 fsync 使用零 fh,不再跳过。
  • 为 FUSE regular file 接入 page cache fault/map_pages 路径,使 mmap 访问通过 inode read path 拉取数据。
  • 改进 VFS mount 层:
    • lookup 时穿越覆盖挂载,并触发 FUSE 子挂载自动挂载;
    • 对已打开文件操作固定委派到打开时解析出的 inode,避免后续 mount 覆盖改变已打开文件语义;
    • mount/bind/move 优先使用 mount namespace 中记录的真实挂载路径,避免 virtiofs/FUSE 返回 fuse:<nodeid> 之类 synthetic path 破坏路径重写。
  • 优化 virtiofs bridge 响应 buffer 大小,按 READ/READDIR/READDIRPLUS 请求长度分配响应缓冲。

测试

新增/扩展 FUSE dunitest 覆盖:

  • FuseExtended.OpenReturnsZeroFhIsValid
  • FuseExtended.NoOpenFsyncUsesZeroFh
  • FuseExtended.OpenFlagsMatchLinuxMask
  • FuseExtended.InitRequestsLinuxNoOpenSupport

同时扩展 simple FUSE test daemon,支持记录 open/read/write/fsync/release 的 fh、flags 和计数,用于验证 Linux 兼容行为。

@github-actions github-actions Bot added the ambiguous The title of PR/issue doesn't match the format label Jun 7, 2026
@xboHodx xboHodx force-pushed the kata-split/fuse-vfs branch 2 times, most recently from c3e8983 to b029c4e Compare June 11, 2026 05:19
@xboHodx xboHodx changed the title 【TBD】feat(fuse,vfs) fix(fuse) support FUSE submounts and fix virtiofs mount semantics Jun 11, 2026
@github-actions github-actions Bot removed the ambiguous The title of PR/issue doesn't match the format label Jun 11, 2026
@xboHodx xboHodx force-pushed the kata-split/fuse-vfs branch from 83398cc to b7eb76c Compare June 11, 2026 05:52
@xboHodx xboHodx changed the title fix(fuse) support FUSE submounts and fix virtiofs mount semantics 【TBD】fix(fuse) support FUSE submounts and fix virtiofs mount semantics Jun 11, 2026
@github-actions github-actions Bot added the ambiguous The title of PR/issue doesn't match the format label Jun 11, 2026
@xboHodx

xboHodx commented Jun 11, 2026

Copy link
Copy Markdown
Contributor Author

#1978

当前pr的临时修复

sys_mount 在解析 target 后,将解析出的 target_path 作为 mount_path_override 传给 mount_subtree_with_state(),避免在 FUSE/virtiofs 场景下通过 target_inode.absolute_path() 反查挂载点路径。

这可以修复一部分问题,尤其是避免把 fuse:<nodeid> 这类 synthetic path 写入 MountList。但它仍然没有改变 mount 拓扑依赖字符串路径的事实,只是减少了一处不可靠反查。

- Enhance the sys_mount implementation to support various mount operations including bind mounts and remounts, with improved handling of mount flags and target paths.
- Introduce new tests for FUSE to validate behavior with zero file handles, fsync operations without open, and correct handling of open flags in accordance with Linux standards.
- Update the simple filesystem structure to accommodate open file handles and flags, ensuring compatibility with the extended FUSE operations.
- Refactor FUSE daemon handling to track and validate file handle usage during open, read, write, and release operations, improving robustness and correctness of the FUSE interface.

Signed-off-by: xboHodx <2679933924@qq.com>
@xboHodx xboHodx force-pushed the kata-split/fuse-vfs branch from b7eb76c to 5177f9e Compare June 11, 2026 11:25
@xboHodx xboHodx changed the title 【TBD】fix(fuse) support FUSE submounts and fix virtiofs mount semantics fix(fuse) support FUSE submounts and fix virtiofs mount semantics Jun 11, 2026
@github-actions github-actions Bot removed the ambiguous The title of PR/issue doesn't match the format label Jun 11, 2026
@fslongjin

Copy link
Copy Markdown
Member

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 5177f9e70b

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread kernel/src/filesystem/fuse/inode.rs Outdated
fslongjin added 15 commits June 11, 2026 16:43
Signed-off-by: longjin <longjin@dragonos.org>
Signed-off-by: longjin <longjin@dragonos.org>
Signed-off-by: longjin <longjin@dragonos.org>
Signed-off-by: longjin <longjin@dragonos.org>
Signed-off-by: longjin <longjin@dragonos.org>
Signed-off-by: longjin <longjin@dragonos.org>
Signed-off-by: longjin <longjin@dragonos.org>
Signed-off-by: longjin <longjin@dragonos.org>
Signed-off-by: longjin <longjin@dragonos.org>
Signed-off-by: longjin <longjin@dragonos.org>
Signed-off-by: longjin <longjin@dragonos.org>
Signed-off-by: longjin <longjin@dragonos.org>
Signed-off-by: longjin <longjin@dragonos.org>
Signed-off-by: longjin <longjin@dragonos.org>
Signed-off-by: longjin <longjin@dragonos.org>
Signed-off-by: longjin <longjin@dragonos.org>
Signed-off-by: longjin <longjin@dragonos.org>
Signed-off-by: longjin <longjin@dragonos.org>
…, and direct I/O lock-owner

- Cache ENOSYS for FUSE_FLUSH, FUSE_FSYNC, FUSE_FSYNCDIR to avoid
  repeated round-trips when the daemon does not implement these ops
- Move FUSE_FLUSH from IndexNode::close to new flush_file(), called
  at fd-close time so errors propagate to userspace via close(2)
- Send FUSE_RELEASE asynchronously via request_nocreds_background to
  prevent close(2) from blocking on daemon release replies
- Add DroppedFd deferred-close mechanism: flush + posix-lock release
  happen after fd-table lock is dropped, fixing lock-ordering issues
- Pass lock_owner in FUSE_READ/FUSE_WRITE with FUSE_READ_LOCKOWNER /
  FUSE_WRITE_LOCKOWNER flags for direct I/O
- Add FuseOpenContext capturing request cred, lock owner, node
  generation, and writeback error cursor at open time
- Validate node generation on writeback writes to detect stale handles
- Add direct_io_lock per FuseNode and prepare_direct_io_range for
  cache invalidation before direct I/O writes
- Check and advance per-open writeback errors in fsync/flush paths
- Add dunitest coverage for ENOSYS caching, flush error propagation,
  and close semantics

Signed-off-by: longjin <longjin@dragonos.org>
@fslongjin fslongjin force-pushed the kata-split/fuse-vfs branch from 8bce03f to 8eb9d40 Compare June 12, 2026 15:38
@fslongjin

Copy link
Copy Markdown
Member

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 8eb9d407d6

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread kernel/src/filesystem/fuse/inode.rs Outdated
Comment thread kernel/src/filesystem/fuse/inode.rs Outdated
- Add request_with_cred to FuseConn so write requests carry the
  open-time credentials (pid/uid/gid) to the FUSE daemon, matching
  Linux semantics.
- Replace invalidate_read + update_clean_page with update_ready_page
  in the write path: instead of discarding the whole page cache on
  every write, merge written data into existing up-to-date pages so
  that overlapping mmap reads see the latest bytes.
- Acquire the page-cache invalidate-write lock around cached writes
  and wait for any in-flight writeback in the overlapping range
  before issuing the FUSE_WRITE to prevent stale writeback from
  overwriting newer data.
- Move invalidate_read into prepare_*_writeback_entry so that page
  faults are blocked during the state transition, not after the page
  contents have already been read.
- Add dunitest SharedMmapDirtyThenPwriteKeepsLatestData verifying
  that pwrite over a dirty mmap page updates the page cache and that
  the subsequent msync writes back the latest (pwrite) data.
- Extend the msync writeback test to assert that write requests
  carry the same pid as the preceding open.

Signed-off-by: longjin <longjin@dragonos.org>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants