openvmm: virtiofs: aggregate synthetic root st_nlink counts single-file shares as subdirectories

オープン 初心者向け
#1,632 コメント 1 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 1 日以内に返信

まだ誰も着手していません。

評価

難易度
2/5
見積もり時間
1〜3時間
初心者へのやさしさ
72/100
issue の種類
バグ
明瞭さ
明確に書かれている
活発さ
活発
技術スタック
rust
領域
backend

調査の方向性

vm/devices/virtio/virtiofs/src/aggregate.rs を読んでください。synthetic_root_nlink(L256)は synthetic_root_attr と synthetic_root_statx の両方に渡され、write_child_entry(L416)はファイル共有(volume.exposed_file().is_some())とディレクトリ共有を区別する方法をすでに示しています。リンク総数にはディレクトリの子だけを数え、次にそのファイル内の既存の microvm-aggregate テストを拡張して、1 つのディレクトリと 1 つのファイル共有に対して nlink 3 をアサートし、cargo test -p virtiofs を実行してください。

索引モデルが issue の本文から書いたものです。

説明

area: openvmm

Summary

On a microVM aggregate mount (VirtioFs::new_microvm_aggregate) configured with one or more single-file child shares (MicroVmAggregateChild::new_file), FUSE_GETATTR and FUSE_STATX on the synthetic root (FUSE_ROOT_ID) report nlink = 2 + entries.len(), counting every attached child regardless of whether it exposes a directory or a regular file. Under POSIX stat(2) directory link-count semantics, a directory's st_nlink is 2 plus one per subdirectory (..), whereas regular-file entries do not increment their parent directory's link count. Found by testing.

Root Cause

In vm/devices/virtio/virtiofs/src/aggregate.rs#L256-L264, VirtioFs::synthetic_root_nlink—used by both synthetic_root_attr and synthetic_root_statx—sums all registered aggregate entries indiscriminately:

    fn synthetic_root_nlink(&self) -> u32 {
        let child_count = self
            .inner
            .aggregate()
            .map_or(0, |aggregate| aggregate.registry.read().entries.len());
        u32::try_from(child_count)
            .unwrap_or(u32::MAX)
            .saturating_add(2)
    }

Meanwhile, plain READDIR in VirtioFs::write_child_entry correctly distinguishes single-file shares (volume.exposed_file().is_some(), emitted as lx::DT_REG) from directory shares (lx::DT_DIR), creating an inconsistency between st_nlink and the directory entries emitted by READDIR / READDIRPLUS.

Consequence

Guest utilities that rely on POSIX directory link-count invariants (such as find, fts, and backup/traversal tools applying the st_nlink - 2 leaf-directory optimization) observe a larger subdirectory count on the mount root than the number of DT_DIR entries actually present when single-file shares are attached.

Reproduction

  1. Construct a microVM aggregate via VirtioFs::new_microvm_aggregate with one directory share (MicroVmAggregateChild::new("work", ...)) and one single-file share (MicroVmAggregateChild::new_file("seed", ...)).
  2. Query Fuse::get_attr(&fs, &request(FUSE_ROOT_ID), 0, 0) and Fuse::get_statx(&fs, &request(FUSE_ROOT_ID), ...).
  3. Observe nlink == 4 instead of 3.

Related: #1617, #1598, #1624.

主要言語
Rust
スター
848
フォーク
63
平均マージ
13時間 37分
マージ済み PR(30日)
571

環境構築

  • Dockerfile・Docker Compose ファイルなし
  • プルリクエストのテンプレートあり
  • コントリビューションガイドなし

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

microsoft/nvx のほかの issue

microsoft/nvx の issue をすべて見る

似ている issue

Rust の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。