From 1b04f879321038707c5162fed1632d17db608cd3 Mon Sep 17 00:00:00 2001 From: Mark Hurenkamp Date: Fri, 27 Dec 2024 18:49:40 +0100 Subject: [PATCH] fix sata for q35 --- README.md | 2 +- src/config/storage/sata.rs | 54 ++++++++++++++++++++++++++------ src/config/system/chipset/q35.rs | 2 ++ 3 files changed, 47 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index 9c56a86..bc5134a 100644 --- a/README.md +++ b/README.md @@ -298,7 +298,7 @@ current one. - Multiple operating systems: - ~~Windows~~ - ~~Linux~~ - - macOS + - ~~macOS~~ - Multiple gpu options (from fast to slow): - ~~passthrough-gpu~~ - ~~virtio-vga-gl~~ diff --git a/src/config/storage/sata.rs b/src/config/storage/sata.rs index 130e972..b70bfae 100644 --- a/src/config/storage/sata.rs +++ b/src/config/storage/sata.rs @@ -13,6 +13,7 @@ pub enum SataDeviceType { #[derive(Serialize, Deserialize, PartialEq, Debug, Clone)] pub struct Sata { + // device_type: SataDeviceType, #[serde(default)] discard: Option, @@ -37,7 +38,7 @@ impl Sata { required_value_getter!(cache("cache"): String = "none".to_string()); required_value_getter!(format("format"): String = "raw".to_string()); required_value_getter!(detect_zeroes("detect-zeroes"): String = "unmap".to_string()); - required_value_getter!(bus("bus"): String = "sata.0".to_string()); + required_value_getter!(bus("bus"): String = "ahci0.0".to_string()); required_value_getter!(rotation_rate("rotation_rate"): u8 = 1); required_value_getter!(unit("unit"): String = "0".to_string()); required_value_getter!(media("media"): String = "cdrom".to_string()); @@ -49,11 +50,11 @@ impl Sata { SataDeviceType::Ssd => "ssd".to_string(), } } - fn id(&self, index: usize) -> String { - format!(",id=sata{}", index) + fn drive_id(&self, index: usize) -> String { + format!("drive-sata{}", index) } - fn drive(&self, index: usize) -> String { - format!(",drive=drive-sata{}", index) + fn device_id(&self, index: usize) -> String { + format!("sata{}", index) } fn get_media(&self) -> String { match &self.device_type { @@ -67,8 +68,8 @@ impl Sata { impl StoragePayload for Sata { fn get_drive_options(&self, index: usize) -> Vec { vec![format!( - "id=drive-sata{}{}{}{}{}{}", - index, + "id={}{}{}{}{}{}", + self.drive_id(index), self.discard(), self.format(), self.cache(), @@ -79,11 +80,11 @@ impl StoragePayload for Sata { fn get_device_options(&self, index: usize) -> Vec { vec![format!( - "sata-{}{}{}{}{}", + "ide-{},id={},drive={}{}{}", self.device_type(), + self.device_id(index), + self.drive_id(index), self.bus(), - self.drive(index), - self.id(index), self.unit(), )] } @@ -215,4 +216,37 @@ mod tests { assert_eq!(from_yaml.get_qemu_args(5), expected); } + + #[derive(Serialize)] + struct Config { + controller: Vec, + } + #[derive(Serialize)] + struct Controller { + model: String, + bus: String, + devices: Vec, + } + + #[derive(Serialize)] + struct Device { + device_type: String, + file: String, + } + + #[test] + fn test() { + let config = Config { + controller: vec![Controller { + model: "sata".to_string(), + bus: "ahci0.0".to_string(), + devices: vec![Device { + device_type: "hd".to_string(), + file: "some_file".to_string(), + }], + }], + }; + let converted = serde_yaml::to_string(&config).unwrap(); + println!("{}", converted); + } } diff --git a/src/config/system/chipset/q35.rs b/src/config/system/chipset/q35.rs index 48dc317..8ef779a 100644 --- a/src/config/system/chipset/q35.rs +++ b/src/config/system/chipset/q35.rs @@ -1,5 +1,6 @@ use crate::config::system::chipset::Chipset; use crate::config::types::QemuDevice; +use colored::Colorize; use serde::Deserialize; const PVE_CONFIG_FILE: &str = "/usr/share/ezkvm/pve-q35-4.0.cfg"; @@ -27,6 +28,7 @@ impl QemuDevice for Q35 { "-device qemu-xhci,p2=15,p3=15,id=xhci,bus=pci.1,addr=0x1b".to_string(), "-iscsi initiator-name=iqn.1993-08.org.debian:01:39407ad058b".to_string(), "-device pvscsi,id=scsihw0,bus=pci.0,addr=0x5".to_string(), + "-device ahci,id=ahci0,multifunction=on,bus=pci.0,addr=0x7".to_string(), ] } }