Skip to content

fix(qemu): drop native mounts with missing host source before VM start - #5134

Open
amanyadav2022 wants to merge 1 commit into
canonical:mainfrom
amanyadav2022:fix/native-mount-missing-source
Open

fix(qemu): drop native mounts with missing host source before VM start#5134
amanyadav2022 wants to merge 1 commit into
canonical:mainfrom
amanyadav2022:fix/native-mount-missing-source

Conversation

@amanyadav2022

Copy link
Copy Markdown

Description

Fixes an issue where a Multipass instance fails to start entirely if a previously-configured native mount's host source directory has since become unavailable (e.g. deleted, or on removable/network storage that's no longer connected).

Root cause

QemuMountHandler's constructor validates that a mount's source directory exists — but only once, when the handler is first constructed. QemuVirtualMachine::mount_args is persisted as JSON metadata and reloaded on every QemuVirtualMachine construction, so a stale entry can survive across VM stop/start cycles and even full daemon restarts without ever being re-validated.

QemuVirtualMachine::initialize_vm_process() passes mount_args directly into the QEMU process spec with no re-check, so a mount whose source has vanished still gets included as a -virtfs argument on every subsequent start — causing the QEMU process itself to fail at launch, rather than the VM simply starting without that one mount.

Fix

initialize_vm_process() now filters mount_args immediately before building the QEMU process spec, dropping any entry whose source no longer exists on disk and logging a warning for each removal. The VM then starts normally, minus the invalid mount, instead of failing to boot.

As a side effect, on a normal (non-suspended) start, the filtered mount_args is what gets persisted back via update_metadata_for, so the stale entry is also cleaned from the daemon's saved metadata after one successful start — not just skipped for a single boot.

Related Issue(s)

Closes #4957

Testing

  • Added QemuBackend.startRemovesMountsWithMissingSource in tests/unit/qemu/test_qemu_backend.cpp, covering: a mount with a valid source is preserved and reaches the actual QEMU process arguments; a mount with a missing source is dropped with the expected warning logged; the VM starts successfully in both cases.
  • Ran the full existing QemuBackend and QemuMountHandler test suites locally (59 tests) — all pass, no regressions.
  • Built and tested on native Ubuntu 24.04 (WSL2).

Known scope / limitations

  • This checks exists() only, not full accessibility/directory-type, unlike the stricter check in the MountHandler base constructor. This covers the reported scenario (source deleted) but not, e.g., a source that still exists but became unreadable or was replaced by a file.
  • On resume-from-suspend specifically, the filter still runs correctly (VM resumes fine), but that code path doesn't call update_metadata_for, so the metadata self-cleanup described above only applies to normal starts, not suspend/resume.

Additional Notes

This is my first contribution to Multipass. Happy to adjust scope or approach based on feedback if there's a preferred pattern for this I've missed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant