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

Aperta Adatta ai principianti
#1,632 1 commento 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
2/5
Tempo stimato
1-3 ore
Idoneità per principianti
72/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
rust
Ambito
backend

Direzione di ricerca

Leggi vm/devices/virtio/virtiofs/src/aggregate.rs: synthetic_root_nlink (L256) alimenta sia synthetic_root_attr sia synthetic_root_statx, e write_child_entry (L416) mostra già come distinguere una condivisione di file (volume.exposed_file().is_some()) da una condivisione di directory. Conta solo i figli di directory nel totale dei link, poi estendi i test microvm-aggregate esistenti in quel file per verificare che nlink sia 3 per una directory più una condivisione di file, ed esegui cargo test -p virtiofs.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

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.

Lingua principale
Rust
Stelle
848
Fork
63
Merge medio
13h 37m
PR unite (30g)
571

Preparare l'ambiente

  • Nessun Dockerfile né file Docker Compose
  • Ha un modello di pull request
  • Nessuna guida per i contributori

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di microsoft/nvx

Tutte le issue di microsoft/nvx

Issue simili

Altre issue su Rust

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.