|
@@ -25,6 +25,7 @@ struct UTMAppleConfigurationDrive: UTMConfigurationDrive {
|
|
var sizeMib: Int = 0
|
|
var sizeMib: Int = 0
|
|
var isReadOnly: Bool
|
|
var isReadOnly: Bool
|
|
var isExternal: Bool
|
|
var isExternal: Bool
|
|
|
|
+ var isNvme: Bool
|
|
var imageURL: URL?
|
|
var imageURL: URL?
|
|
var imageName: String?
|
|
var imageName: String?
|
|
|
|
|
|
@@ -36,6 +37,7 @@ struct UTMAppleConfigurationDrive: UTMConfigurationDrive {
|
|
|
|
|
|
private enum CodingKeys: String, CodingKey {
|
|
private enum CodingKeys: String, CodingKey {
|
|
case isReadOnly = "ReadOnly"
|
|
case isReadOnly = "ReadOnly"
|
|
|
|
+ case isNvme = "Nvme"
|
|
case imageName = "ImageName"
|
|
case imageName = "ImageName"
|
|
case bookmark = "Bookmark" // legacy only
|
|
case bookmark = "Bookmark" // legacy only
|
|
case identifier = "Identifier"
|
|
case identifier = "Identifier"
|
|
@@ -55,12 +57,14 @@ struct UTMAppleConfigurationDrive: UTMConfigurationDrive {
|
|
sizeMib = newSize
|
|
sizeMib = newSize
|
|
isReadOnly = false
|
|
isReadOnly = false
|
|
isExternal = false
|
|
isExternal = false
|
|
|
|
+ isNvme = false
|
|
}
|
|
}
|
|
|
|
|
|
- init(existingURL url: URL?, isExternal: Bool = false) {
|
|
|
|
|
|
+ init(existingURL url: URL?, isExternal: Bool = false, isNvme: Bool = false) {
|
|
self.imageURL = url
|
|
self.imageURL = url
|
|
self.isReadOnly = isExternal
|
|
self.isReadOnly = isExternal
|
|
self.isExternal = isExternal
|
|
self.isExternal = isExternal
|
|
|
|
+ self.isNvme = isNvme
|
|
}
|
|
}
|
|
|
|
|
|
init(from decoder: Decoder) throws {
|
|
init(from decoder: Decoder) throws {
|
|
@@ -83,6 +87,7 @@ struct UTMAppleConfigurationDrive: UTMConfigurationDrive {
|
|
isExternal = true
|
|
isExternal = true
|
|
}
|
|
}
|
|
isReadOnly = try container.decodeIfPresent(Bool.self, forKey: .isReadOnly) ?? isExternal
|
|
isReadOnly = try container.decodeIfPresent(Bool.self, forKey: .isReadOnly) ?? isExternal
|
|
|
|
+ isNvme = try container.decodeIfPresent(Bool.self, forKey: .isNvme) ?? false
|
|
id = try container.decode(String.self, forKey: .identifier)
|
|
id = try container.decode(String.self, forKey: .identifier)
|
|
}
|
|
}
|
|
|
|
|
|
@@ -92,12 +97,18 @@ struct UTMAppleConfigurationDrive: UTMConfigurationDrive {
|
|
try container.encodeIfPresent(imageName, forKey: .imageName)
|
|
try container.encodeIfPresent(imageName, forKey: .imageName)
|
|
}
|
|
}
|
|
try container.encode(isReadOnly, forKey: .isReadOnly)
|
|
try container.encode(isReadOnly, forKey: .isReadOnly)
|
|
|
|
+ try container.encode(isNvme, forKey: .isNvme)
|
|
try container.encode(id, forKey: .identifier)
|
|
try container.encode(id, forKey: .identifier)
|
|
}
|
|
}
|
|
|
|
|
|
- func vzDiskImage() throws -> VZDiskImageStorageDeviceAttachment? {
|
|
|
|
|
|
+ func vzDiskImage(useFsWorkAround: Bool = false) throws -> VZDiskImageStorageDeviceAttachment? {
|
|
if let imageURL = imageURL {
|
|
if let imageURL = imageURL {
|
|
- return try VZDiskImageStorageDeviceAttachment(url: imageURL, readOnly: isReadOnly)
|
|
|
|
|
|
+ // Use cached caching mode for virtio drive to prevent fs corruption on linux when possible
|
|
|
|
+ if #available(macOS 12.0, *), !isNvme, useFsWorkAround {
|
|
|
|
+ return try VZDiskImageStorageDeviceAttachment(url: imageURL, readOnly: isReadOnly, cachingMode: .cached, synchronizationMode: .full)
|
|
|
|
+ } else {
|
|
|
|
+ return try VZDiskImageStorageDeviceAttachment(url: imageURL, readOnly: isReadOnly)
|
|
|
|
+ }
|
|
} else {
|
|
} else {
|
|
return nil
|
|
return nil
|
|
}
|
|
}
|
|
@@ -107,6 +118,7 @@ struct UTMAppleConfigurationDrive: UTMConfigurationDrive {
|
|
imageName?.hash(into: &hasher)
|
|
imageName?.hash(into: &hasher)
|
|
sizeMib.hash(into: &hasher)
|
|
sizeMib.hash(into: &hasher)
|
|
isReadOnly.hash(into: &hasher)
|
|
isReadOnly.hash(into: &hasher)
|
|
|
|
+ isNvme.hash(into: &hasher)
|
|
isExternal.hash(into: &hasher)
|
|
isExternal.hash(into: &hasher)
|
|
id.hash(into: &hasher)
|
|
id.hash(into: &hasher)
|
|
}
|
|
}
|
|
@@ -127,6 +139,7 @@ extension UTMAppleConfigurationDrive {
|
|
sizeMib = oldDrive.sizeMib
|
|
sizeMib = oldDrive.sizeMib
|
|
isReadOnly = oldDrive.isReadOnly
|
|
isReadOnly = oldDrive.isReadOnly
|
|
isExternal = oldDrive.isExternal
|
|
isExternal = oldDrive.isExternal
|
|
|
|
+ isNvme = false
|
|
imageURL = oldDrive.imageURL
|
|
imageURL = oldDrive.imageURL
|
|
}
|
|
}
|
|
}
|
|
}
|