Skip to content

[DO NOT REVIEW] virtiofs: keep node names when renaming a name onto itself - #5206

Merged
Pedro Henrique Penna (ppenna) merged 1 commit into
feature/microvm/devfrom
copilot/nvx-issue-1610-rename-self
Nov 22, 2026
Merged

Pedro Henrique Penna (ppenna) merged 1 commit into
feature/microvm/devfrom
copilot/nvx-issue-1610-rename-self

Conversation

@ppenna

@ppenna Pedro Henrique Penna (ppenna) commented Nov 21, 2026 •

Copy link
Copy Markdown
Contributor

Refs microsoft/nvx#1610.

NVX pins the head of this branch, so this is a prerequisite of the NVX change that pins it, and it lands by fast-forwarding feature/microvm/dev to that exact commit, not with the merge button, which squashes.

What and why

Each virtio-fs node keeps the volume-relative names, or aliases, through which the guest has reached its object, and a primary path among them that its operations use. VirtioFs::rename tracks a rename that is not an exchange as a move: after the host rename, InodeMap::remove_alias_prefix(new_path) drops the names at and below the destination, which the host replaced, and InodeMap::rename_alias_prefix(old_path, new_path) then rewrites those at and below the source under the destination. The microVM alias preflight, InodeMap::preflight_microvm_rename, models the same two steps.

When the guest renames a name onto itself, with the same parent and name, the host rename succeeds without changing anything, as POSIX requires (Linux renameat2 returns 0; the Windows host renames the name to itself). But both paths are then one name, so the first step dropped the names at and below it from every node of the volume, and the second found nothing left to rewrite:

  • a node that the guest knew only through those names was left with none, so save_microvm_state, and so a microVM snapshot, failed with inode has no bounded reopenable aliases, and on a volume that deduplicates nodes by path, rebuild_dedup_keys stopped finding the node;
  • a node with another hard link kept only the other name, and once the guest removed that one, the node's requests failed with ENOENT, although the renamed name still reached its object.

A Linux guest never sends such a request: its VFS completes a rename whose two names reach one inode itself (vfs_rename returns 0 when source == target, before it calls the filesystem). Only a guest that sends FUSE_RENAME directly reaches this path, but OpenVMM does not trust the guest, so its state must stay consistent for any request; the regression test therefore drives the FUSE server directly, and no microVM scenario can reproduce the defect.

The fix: after the same writability checks, a rename whose source and destination are one name returns the host's result directly, and changes no names and skips the alias preflight, since nothing changes. It still goes to the host, so the host fails it as it fails any other rename: with ENOENT for a missing name, and with EEXIST under RENAME_NOREPLACE on Linux (EINVAL on Windows, which rejects every rename flag). The exchange of a name with itself, which the previous code already left unchanged, takes the same path. No saved state, protocol, ABI, or format, and no version of any of them, changes.

Kept from the issue's suggested fix: skipping the preflight and the name updates while still calling the host. Changed: the check returns the host's result in one place rather than in two, and the regression test also covers nodes below a renamed directory, a hard-linked file, and a snapshot taken right after the rename.

Out of scope, handled separately: a rename between two hard links of one file (microsoft/nvx#1620), which also changes nothing on the host but names two different paths.

Tests

One unit test in virtiofs, microvm::exchange_tests::renaming_a_name_onto_itself_keeps_every_name, next to the RENAME_EXCHANGE tests, whose module doc now covers it: on a read-write microVM share, it renames a directory with nodes below it, a file in it, and a file with a second hard link each onto itself, and checks that:

  • every node keeps exactly its names, with its path among them;
  • a snapshot taken right away records those names and restores them;
  • the hard-linked file's node still reads the file once the guest removes the other link;
  • the host still fails a missing name with ENOENT, and RENAME_NOREPLACE with EEXIST on Linux and EINVAL on Windows.

Validation

cargo nextest run -p virtiofs at this head, and at its parent with the new test applied (the fix reverted):

Host Without the fix (at b51f9156c) With it
Windows 11, local fails: the renamed directory's node has no names left (aliases of node 2, left: {}, right: {"directory"}) 186 passed
nvx-mshv-test, Azure Linux 3.0 VM the same failure 192 passed

At this head, on both hosts, cargo check, cargo clippy --all-targets, and cargo doc --no-deps for virtiofs are clean, with no warning but the LNK4199 linker message that every linked artifact gets on the Windows machine, and one ignored test is skipped, as at the base. cargo xtask fmt --fix changes nothing. At the base, a scratch reproduction of the issue's steps showed the file's names going from out/existing to none while the host file stayed intact, and the save failing with inode has no bounded reopenable aliases.

A guest rename of a name onto itself, in the same directory, succeeds
on the host without changing anything, as POSIX requires, but it
dropped the names at and below that name from every node of the volume
(microsoft/nvx#1610). A node that the guest knew only through them was
left with no names, so a microVM save then failed with "inode has no
bounded reopenable aliases", and a volume that deduplicates nodes by
path stopped finding it. A node with another hard link kept only the
other name, and once the guest removed that one, the node's requests
failed with ENOENT although the renamed name still reached its object.

VirtioFs::rename tracks a rename that is not an exchange as a move: it
drops the names at and below the destination, which the host replaced,
and then rewrites those at and below the source under the destination.
When both are one name, the first step drops the names that the second
should keep. The microVM alias preflight models the same steps.

A rename whose source and destination are one name now changes no
names and skips the preflight. It still reaches the host after the
same writability checks, so the host fails it as it fails any other
rename: with ENOENT for a missing name, and with EEXIST under
RENAME_NOREPLACE on Linux.

renaming_a_name_onto_itself_keeps_every_name, in virtiofs' microVM
exchange tests, which now cover a rename of a name onto itself too,
renames a directory with nodes below it, a file in it, and a file with
a second hard link each onto itself. It checks that every node keeps
exactly its names, that a snapshot taken right away saves and restores
them, and that the hard-linked file's node still reads the file once
the guest removes the other link; and that the host still fails a
missing name with ENOENT, and RENAME_NOREPLACE with EEXIST on Linux
and EINVAL on Windows. Without the fix, at feature/microvm/dev
b51f915, it fails on Windows and on Linux (Azure Linux 3.0,
nvx-mshv-test), where the renamed directory's node has no names left;
with the fix, it and the package's other tests pass there.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@github-actions github-actions Bot added the release-nvx Targets a branch under feature/microvm/. label Nov 21, 2026
@ppenna
Pedro Henrique Penna (ppenna) merged commit 3288834 into feature/microvm/dev Nov 22, 2026
104 of 105 checks passed
syeedali pushed a commit to syeedali/nvx that referenced this pull request Nov 22, 2026
Map position 340, the commit of microsoft/openvmm#5206, which NVX now
pins at 32888344a, 214 commits past the mapped tip:

- 340, virtiofs: keep node names when renaming a name onto itself.
  VirtioFs::rename returns the host's result for a rename whose source
  and destination are one name, after the writability checks, without
  the microVM alias preflight or any change to the names. It tracked
  every rename that is not an exchange as a move, dropping the names at
  and below the destination before rewriting those of the source, so a
  rename of a name onto itself, which changes nothing on the host,
  dropped the names at and below that name from every node, after which
  saving a microVM failed.

Position 340 is a PR13 fixup. It fixes the name bookkeeping that PR13's
position 048 adds, and its test, in the microVM exchange tests that
position 166 adds, needs nothing that a later position adds, so it
folds into position 048, with its early return after the writability
checks that position 160 adds, and its test into position 166, as the
fold sentence after the DAG and the commit mapping say; the Scope, the
DAG, the dependency graph, the PR summary, and the commit mapping
record it with PR13. It skips the alias preflight of PR18's position
081, which modeled the same steps but never refused such a rename, so
it is no PR18 fixup. Upstream main, bf353460f, lacks the defect, since
it lacks the names of position 048, and replaying the commit there
conflicts in lib.rs, next to the names and checks of positions 048 and
160, and in the microVM's exchange_tests.rs, which upstream main lacks,
so it follows PR13 upstream.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
syeedali pushed a commit to syeedali/nvx that referenced this pull request Nov 22, 2026
OpenVMM's virtio-fs server answered FUSE_READDIR and FUSE_READDIRPLUS
on an aggregate's synthetic root with a reply buffer that it reserved
infallibly, with Vec::with_capacity, at whatever size the guest asked
for, so a guest that read the root with a size of u32::MAX made the
VMM reserve 4 GiB for one request, and a host that could not provide
it aborted the VMM with "memory allocation of 4294967295 bytes failed"
(microsoft#1598). The reads of every other directory, and every
other buffer that the guest sizes, are bounded at 1 MiB and reserved
fallibly.

Pin microsoft/openvmm ed2d7e3a15c9519fde09046ba6643f773c8285df, one
commit on 32888344a, the head of microsoft/openvmm#5206:

- virtiofs: bound the buffer of an aggregate root's directory read. A
  read of the synthetic root that asks for more than 1 MiB fails with
  E2BIG before anything is reserved, and the buffer is reserved with
  try_reserve_exact, failing with ENOMEM, as for every other directory.
  A read of 1 MiB still lists the whole root. Its test fails without
  the change on Windows and on Linux (nvx-kvm-test).

No saved state, protocol, ABI, or format, and no version of any of
them, changes. The protocol vectors and CPU profiles that nvx copies
are unchanged.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
syeedali pushed a commit to syeedali/nvx that referenced this pull request Nov 22, 2026
OpenVMM's virtio-fs server lists a microVM directory once, on the first
read of each handle, and keeps the listing for the handle's later reads
and for its saved state. A saved state holds at most 16,384 entries
and 4 MiB of names in the listings of all handles, but the server
checked only each listing's own bounds of 4,096 entries and 64 KiB of
names, across up to 4,096 handles (microsoft#1613). A guest that
kept five handles listing a directory of 4,094 files therefore failed
every capture of the VM with "saved directory entries exceed the
aggregate bound" until it released them, and its handles could pin
256 MiB of names in the VMM.

Pin microsoft/openvmm 5c82edac42ca480d546459e019860759a27c2211, one
commit on ed2d7e3a1, the head of microsoft/openvmm#5207, which stacks
on microsoft/openvmm#5206 and feature/microvm/dev b51f9156c:

- virtiofs: bound microVM directory snapshots in total when listing.
  The first read of a handle charges its listing to the totals of the
  attachment's listings, and fails with ENOSPC, keeping no listing,
  when the listings would then exceed them. A released handle returns
  its share, and a restore charges the listings that it restores in
  place of those of the handles that it replaces. Its tests fail
  without the change on Windows and on Linux (nvx-mshv-test).

No saved state, protocol, ABI, or format, and no version of any of
them, changes. The protocol vectors and CPU profiles that nvx copies
are unchanged.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

release-nvx Targets a branch under feature/microvm/.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant