Skip to content

Commit 4460b93

Browse files
committed
Apple Virtualization: only update shared directories if they changed to avoid unnecessary virtiofs reconnections
For Apple Virtualization, only update shared directories if they changed to avoid unnecessary virtiofs reconnections. Although this issue existed prior to v4.5.4, following v4.5.4, UTM introduced dynamic resolution. Resizing the window with dynamic resolution is one repeatable way to cause a registry update. updateConfigFromRegistry() updates the shared directories on every call, causing the virtiofs to reconnect. As the virtiofs disconnects and reconnects, file and directory handles on the share are invalidated causing guest application errors. To reproduce bug: - Apple Virtualization, Linux guest, Dynamic resolution enabled - Open terminal - $ cd {shared_directory} - Resize the window - $ ls - Result: ls: cannot open directory '.': No such file or directory
1 parent 4bacaa9 commit 4460b93

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

Services/UTMAppleVirtualMachine.swift

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -968,7 +968,18 @@ extension UTMAppleVirtualMachine {
968968
}
969969

970970
@MainActor func updateConfigFromRegistry() {
971-
config.sharedDirectories = registryEntry.sharedDirectories.map({ UTMAppleConfigurationSharedDirectory(directoryURL: $0.url, isReadOnly: $0.isReadOnly )})
971+
// Only update shared directories if they actually changed to avoid unnecessary virtiofs reconnections
972+
let newShares = registryEntry.sharedDirectories.map({ UTMAppleConfigurationSharedDirectory(directoryURL: $0.url, isReadOnly: $0.isReadOnly )})
973+
974+
let sharesChanged = newShares.count != config.sharedDirectories.count ||
975+
zip(newShares, config.sharedDirectories).contains { new, old in
976+
new.directoryURL != old.directoryURL || new.isReadOnly != old.isReadOnly
977+
}
978+
979+
if sharesChanged {
980+
config.sharedDirectories = newShares
981+
}
982+
972983
for i in config.drives.indices {
973984
let id = config.drives[i].id
974985
if config.drives[i].isExternal {

0 commit comments

Comments
 (0)