From 35377a347511744714a46baabd29efe4c50151aa Mon Sep 17 00:00:00 2001 From: Andrew Malchuk Date: Fri, 1 Dec 2023 19:56:58 +0400 Subject: [PATCH] Fix the filesystem corruption on Linux VMs (#675) * Use NVMe drive, cached mode and full synchronization mode on Linux * Inline getting storage device attachment --- Sources/tart/VM.swift | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/Sources/tart/VM.swift b/Sources/tart/VM.swift index 0fdef36..149bb0c 100644 --- a/Sources/tart/VM.swift +++ b/Sources/tart/VM.swift @@ -326,9 +326,18 @@ class VM: NSObject, VZVirtualMachineDelegate, ObservableObject { } // Storage - var devices: [VZStorageDeviceConfiguration] = [ - VZVirtioBlockDeviceConfiguration(attachment: try VZDiskImageStorageDeviceAttachment(url: diskURL, readOnly: false)) - ] + let attachment: VZDiskImageStorageDeviceAttachment = vmConfig.os == .linux ? + // Use "cached" caching mode for virtio drive to prevent fs corruption on linux + try VZDiskImageStorageDeviceAttachment(url: diskURL, readOnly: false, cachingMode: .cached, synchronizationMode: .full) : + try VZDiskImageStorageDeviceAttachment(url: diskURL, readOnly: false) + + var device: VZStorageDeviceConfiguration + if #available(macOS 14, *), vmConfig.os == .linux { + device = VZNVMExpressControllerDeviceConfiguration(attachment: attachment) + } else { + device = VZVirtioBlockDeviceConfiguration(attachment: attachment) + } + var devices: [VZStorageDeviceConfiguration] = [device] devices.append(contentsOf: additionalStorageDevices) configuration.storageDevices = devices