Skip to content

data: reload VMs when the volume they are stored on is mounted - #8189

Open
tomrobbo wants to merge 1 commit into
utmapp:mainfrom
tomrobbo:fix/reload-unavailable-vms
Open

tomrobbo wants to merge 1 commit into
utmapp:mainfrom
tomrobbo:fix/reload-unavailable-vms

Conversation

@tomrobbo

Copy link
Copy Markdown

A VM stored on an external drive is listed as unavailable if the drive isn't connected when UTM launches, and it stays unavailable after the drive is connected until UTM is relaunched. The package bookmark is only resolved when the registry is loaded, and nothing refreshes the VM list when a volume is mounted.

This refreshes the VM list on macOS when a volume is mounted or unmounted, and resolves the bookmark of each unavailable VM again so it loads from the newly mounted volume. Resolution uses .withoutMounting and .withoutUI, so an unavailable VM on a disconnected network share doesn't trigger a mount attempt or a prompt on every refresh.

An unloaded VMData compares equal to a loaded one with the same registry entry, so the list didn't compare as changed when a VM became available or unavailable, and the library never redrew. The refresh now tracks availability changes, so the list updates in both directions.

Part of #7364. This covers the first request (unavailable VMs on removable media are never rechecked). It reacts to the volume being mounted instead of retrying on a timer, so no setting is needed. The second request, limiting UTM to a single instance, isn't part of this change.

Tests

Added four tests to UTMDataListTests:

  • a VM whose volume comes back is loaded by the next refresh, and the list is published
  • a VM loaded at launch whose volume is ejected becomes unavailable, and the list is published
  • a mount notification triggers the refresh by itself (macOS)
  • a bundle that comes back but can't be loaded stays unavailable and keeps its row (error path)

The first three fail with the fix reverted (git revert --no-commit) and pass with it restored. The error-path test passes both ways. All 16 tests in UTMDataListTests pass, and Tests/Static/run_all.sh reports no problems.

Testing: Tested by a human on macOS 27.2.1, MacBook Pro (Apple M4 Max), with a VM stored on a Samsung T7 USB SSD.

  • Before (UTM 5.0.8): launched UTM with the drive unplugged, and the VM was shown as unavailable. Plugged the drive in, and the VM stayed unavailable.
  • After (this branch, unsigned local build): plugging the drive in made the VM available within a few seconds. Ejecting it showed the VM as unavailable again. A VM with no network adapter, stored on the drive, started and booted to the UEFI shell after an eject and reconnect. The unsigned build can't start VMs that use Shared networking, so the start test used a VM without networking.
  • Not tested: network shares, iOS/visionOS.

The author acknowledges that this change has been tested and/or reviewed by a human in accordance with UTM's AI contribution guidelines.

A VM stored on an external drive is shown as unavailable if the drive is
not connected when UTM launches. It stays unavailable after the drive is
connected, because the package bookmark is only resolved when the
registry is loaded and nothing refreshes the VM list when a volume is
mounted. The VM only becomes available again after relaunching UTM.

Refresh the VM list when a volume is mounted or unmounted, and resolve
the bookmark of each unavailable VM again so it can be loaded from the
newly mounted volume. Resolution does not mount volumes or show UI, so
an unavailable VM on a disconnected network share does not prompt on
every refresh.

An unloaded VMData compares equal to a loaded one with the same registry
entry, so the list did not compare as changed when a VM became available
or unavailable and was never published. Track availability changes
explicitly so the list updates in both directions.

Addresses the first part of utmapp#7364. Limiting UTM to a single instance,
the issue's second request, is not part of this change.

Assisted-by: Claude:claude-opus-5-5
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant