Skip to content

Commit

Permalink
fix sata for q35
Browse files Browse the repository at this point in the history
  • Loading branch information
hurenkam committed Dec 27, 2024
1 parent 365c66d commit 1b04f87
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 11 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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~~
Expand Down
54 changes: 44 additions & 10 deletions src/config/storage/sata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ pub enum SataDeviceType {

#[derive(Serialize, Deserialize, PartialEq, Debug, Clone)]
pub struct Sata {
//
device_type: SataDeviceType,
#[serde(default)]
discard: Option<String>,
Expand All @@ -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());
Expand All @@ -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 {
Expand All @@ -67,8 +68,8 @@ impl Sata {
impl StoragePayload for Sata {
fn get_drive_options(&self, index: usize) -> Vec<String> {
vec![format!(
"id=drive-sata{}{}{}{}{}{}",
index,
"id={}{}{}{}{}{}",
self.drive_id(index),
self.discard(),
self.format(),
self.cache(),
Expand All @@ -79,11 +80,11 @@ impl StoragePayload for Sata {

fn get_device_options(&self, index: usize) -> Vec<String> {
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(),
)]
}
Expand Down Expand Up @@ -215,4 +216,37 @@ mod tests {

assert_eq!(from_yaml.get_qemu_args(5), expected);
}

#[derive(Serialize)]
struct Config {
controller: Vec<Controller>,
}
#[derive(Serialize)]
struct Controller {
model: String,
bus: String,
devices: Vec<Device>,
}

#[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);
}
}
2 changes: 2 additions & 0 deletions src/config/system/chipset/q35.rs
Original file line number Diff line number Diff line change
@@ -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";
Expand Down Expand Up @@ -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(),
]
}
}
Expand Down

0 comments on commit 1b04f87

Please sign in to comment.