openvmm: virtiofs: aggregate synthetic root st_nlink counts single-file shares as subdirectories
Maintainers usually reply within 1 day
Nobody has claimed this yet.
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 72/100
Research direction
Read vm/devices/virtio/virtiofs/src/aggregate.rs: synthetic_root_nlink (L256) feeds both synthetic_root_attr and synthetic_root_statx, and write_child_entry (L416) already shows how to distinguish a file share (volume.exposed_file().is_some()) from a directory share. Count only directory children in the link total, then extend the existing microvm-aggregate tests in that file to assert nlink 3 for one directory plus one file share, and run cargo test -p virtiofs.
Written by the indexing model from the issue text.
Description
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
- Construct a microVM aggregate via
VirtioFs::new_microvm_aggregatewith one directory share (MicroVmAggregateChild::new("work", ...)) and one single-file share (MicroVmAggregateChild::new_file("seed", ...)). - Query
Fuse::get_attr(&fs, &request(FUSE_ROOT_ID), 0, 0)andFuse::get_statx(&fs, &request(FUSE_ROOT_ID), ...). - Observe
nlink == 4instead of3.
Related: #1617, #1598, #1624.
- Dominant language
- Rust
- Stars
- 831
- Forks
- 56
- Avg merge
- 13h 37m
- Merged PRs (30d)
- 571
Getting set up
- No Dockerfile or Docker Compose file
- Has a pull request template
- No contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from microsoft/nvx
-
area: ci
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
Maintainers usually reply within 1 day
-
area: ci
Difficulty 1/5 Under an hour Newbie friendliness 90/100
Maintainers usually reply within 1 day
-
area: openvmm
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
microsoft/nvx#1628 · 1 comment ·
Maintainers usually reply within 1 day
-
area: openvmm
Difficulty 2/5 1-3 hours Newbie friendliness 80/100
microsoft/nvx#1629 · 1 comment ·
Maintainers usually reply within 1 day
-
area: openvmm
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
microsoft/nvx#1631 · 1 comment ·
Maintainers usually reply within 1 day
Similar issues
-
good first issue help wanted
Difficulty 1/5 Under an hour Newbie friendliness 87/100
Maintainers usually reply within 1 day
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
jolars/panache#627 · 1 comment ·
Maintainers usually reply within 1 day
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 84/100
swc-project/swc-next-issues#490 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
oxc-project/tsrs#1010 ·
Maintainers usually reply within 1 day
-
Link is deadOpen
Difficulty 1/5 Under an hour Newbie friendliness 63/100
nicholas-ochoa/OpenSC2K#104 ·