Skip to content

Commit

Permalink
fix virtio-pci-block device
Browse files Browse the repository at this point in the history
  • Loading branch information
hurenkam committed Dec 20, 2024
1 parent 668d670 commit 3a51f49
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 34 deletions.
29 changes: 23 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,9 @@ to run several VM's (which i initially created on my proxmox cloud server) on my

### Open issues: ###

- still depends on libvirt, mainly for networking
- still depends on some proxmox files (ovmf bios and qemu config file)
- still depends on libvirt to setup networking
- still depends on a proxmox config file (pve-q35-4.0.cfg)
- ~~still depends on proxmox ovmf rom files~~

## How does it work ##

Expand Down Expand Up @@ -100,6 +101,7 @@ That said, the Cargo.toml has been updated to work with some of the cargo packag
#### Building a debian/ubuntu package ####

To build a debian ezkvm package:

- install the cargo-dep package using cargo: `cargo install cargo-deb`
- create the package by running: `cargo dep`

Expand All @@ -108,6 +110,7 @@ You will find a debian package in the target/debian directory.
#### Building a fedora/opensuse package ####

To build an rpm ezkvm package:

- install the cargo-rpm package using cargo: `cargo install cargo-rpm`
- create the package by running: `cargo rpm`

Expand All @@ -117,6 +120,7 @@ And a source rpm package in the target/release/rpmbuild/SRPM directory.
#### Building an arch package ####

To build an arch ezkvm package:

- install the cargo-arch package using cargo: `cargo install cargo-arch`
- create the package by running: `cargo arch`

Expand All @@ -131,7 +135,7 @@ found in the repository, see above in the config section.
The application will also expect some files in /usr/share/ezkvm:

- pve-q35-4.0.cfg
- OVMF_CODE.secboot.4m.fd
- OVMF_CODE_4M.secboot.fd

These are files that i copied over from proxmox. In the future ezkvm should become
independent on these files, and either use the distro's defaults or a to be developed
Expand Down Expand Up @@ -179,6 +183,19 @@ setup permissions correctly. The ezkvm application can be used in two ways:
Note: If you use the 'gtk' ui option, the qemu process will still be started
as the normal user, as the ui won't start when executed with root permissions.

### OVMF files ###

For now, ezkvm depends on OVMF files to reside in /usr/share/ezkvm, but they
are not currently put there by the packages.
You can however easily link from there to the files from your distro's ovmf package,
or copy the ones from proxmox.
Note that I've made available a custom edk2-ovmf package for arch, since i noticed
that the recent builds don't support pvscsi, which is still used by several of
my VM's.
Beware that this may also be the case for your distro's package, so you might
want to copy the proxmox files, or build it yourself.
See my arch-edk2-ovmf repository for the custom arch build.

## Contributing ##

As of now I'm the only active user (that I'm aware of) of this tool, and
Expand Down Expand Up @@ -229,10 +246,10 @@ current one.
- ~~Add unit tests~~
- ~~Refactor config files and move them into config directory as done in poc branch~~
- ~~Merge other improvements from the poc branch into the stable branch~~
- Support for sdl UI
- ~~Support for sdl UI~~
- Support for vnc protocol
- Support 440fx
- Support seabios
- ~~Support seabios~~
- Run macos using ezkvm (and create an example config file for it)
- Restructure example config files to include at least:
- Multiple operating systems:
Expand Down Expand Up @@ -266,7 +283,7 @@ current one.

- Check out proxmox OVMF patches so that a compatible OVMF can be provided through ezkvm
- Create installers for popular distro's:
- Arch based distro's (since i develop on EndeavorOS)
- ~~Arch based distro's (since i develop on EndeavorOS)~~
- ~~Debian based distro's~~
- Others by popular demand (please submit a feature request)
- Add missing features by popular demand (please submit a feature request)
Expand Down
32 changes: 7 additions & 25 deletions src/config/storage/virtio_blk_pci.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,6 @@ pub struct VirtioBlkPci {
detect_zeroes: String,
#[serde(default = "VirtioBlkPci::bus_default")]
bus: String,
#[serde(default = "VirtioBlkPci::address_default")]
address: u8,
#[serde(default = "VirtioBlkPci::rotation_rate_default")]
rotation_rate: u8,
}

impl VirtioBlkPci {
Expand All @@ -27,8 +23,6 @@ impl VirtioBlkPci {
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 = "pci.0".to_string());
required_value_getter!(address("address"): u8 = 0x0a);
required_value_getter!(rotation_rate("rotation_rate"): u8 = 1);
}

#[typetag::deserialize(name = "virtio-blk-pci")]
Expand All @@ -46,12 +40,10 @@ impl StoragePayload for VirtioBlkPci {

fn get_device_options(&self, index: usize) -> Vec<String> {
vec![format!(
"virtio-blk-pci,drive=drive-virtio{},id=virtio{}{}{}{}",
"virtio-blk-pci,drive=drive-virtio{},id=virtio{}{}",
index,
index,
self.bus(),
self.address(),
self.rotation_rate()
)]
}
}
Expand All @@ -70,8 +62,6 @@ mod tests {
format: VirtioBlkPci::format_default(),
detect_zeroes: VirtioBlkPci::detect_zeroes_default(),
bus: VirtioBlkPci::bus_default(),
address: VirtioBlkPci::address_default(),
rotation_rate: 1,
};

let yaml = r#"
Expand All @@ -85,16 +75,14 @@ mod tests {
vec!["id=drive-virtio0,format=raw,cache=none,detect-zeroes=unmap".to_string()];
assert_eq!(storage.get_drive_options(0), drive_args);

let device_args: Vec<String> = vec![
"virtio-blk-pci,drive=drive-virtio0,id=virtio0,bus=pci.0,address=10,rotation_rate=1"
.to_string(),
];
let device_args: Vec<String> =
vec!["virtio-blk-pci,drive=drive-virtio0,id=virtio0,bus=pci.0".to_string()];
assert_eq!(storage.get_device_options(0), device_args);

let from_yaml: StorageItem = serde_yaml::from_str(yaml).unwrap();
let expected: Vec<String> = vec![
"-drive file=default_file,if=none,aio=io_uring,id=drive-virtio5,format=raw,cache=none,detect-zeroes=unmap".to_string(),
"-device virtio-blk-pci,drive=drive-virtio5,id=virtio5,bus=pci.0,address=10,rotation_rate=1".to_string()
"-device virtio-blk-pci,drive=drive-virtio5,id=virtio5,bus=pci.0".to_string()
];

assert_eq!(from_yaml.get_qemu_args(5), expected);
Expand All @@ -108,8 +96,6 @@ mod tests {
format: "qcow2".to_string(),
detect_zeroes: "off".to_string(),
bus: "pci.2".to_string(),
address: 0xb,
rotation_rate: 3,
};

let yaml = r#"
Expand All @@ -121,8 +107,6 @@ mod tests {
format: "qcow2"
detect_zeroes: "off"
bus: "pci.2"
address: 11
rotation_rate: 3
extra_drive_options:
- "option_1"
Expand All @@ -140,16 +124,14 @@ mod tests {
];
assert_eq!(storage.get_drive_options(5), drive_args);

let device_args: Vec<String> = vec![
"virtio-blk-pci,drive=drive-virtio5,id=virtio5,bus=pci.2,address=11,rotation_rate=3"
.to_string(),
];
let device_args: Vec<String> =
vec!["virtio-blk-pci,drive=drive-virtio5,id=virtio5,bus=pci.2".to_string()];
assert_eq!(storage.get_device_options(5), device_args);

let from_yaml: StorageItem = serde_yaml::from_str(yaml).unwrap();
let expected: Vec<String> = vec![
"-drive file=valid_file,if=none,aio=io_uring,id=drive-virtio5,discard=on,format=qcow2,cache=write-back,detect-zeroes=off,option_1,option_2".to_string(),
"-device virtio-blk-pci,drive=drive-virtio5,id=virtio5,bus=pci.2,address=11,rotation_rate=3,bootindex=1,option_3".to_string()
"-device virtio-blk-pci,drive=drive-virtio5,id=virtio5,bus=pci.2,bootindex=1,option_3".to_string()
];

assert_eq!(from_yaml.get_qemu_args(5), expected);
Expand Down
18 changes: 15 additions & 3 deletions src/config/system.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ mod tests {
use super::*;
use crate::config::system::bios::SeaBios;
use crate::config::system::tpm::{NoTpm, SwTpm};
use bios::{OVMF,OVMFArch,OVMFSize};
use bios::OVMF;
use chipset::Q35;

#[test]
Expand Down Expand Up @@ -108,7 +108,13 @@ mod tests {

let expected = System::new(
Box::new(Q35::new()),
Box::new(OVMF::new("/dev/vm1/vm-108-efidisk".to_string(), Some("04d064c3-66a1-4aa7-9589-f8b3ecf91cd7".to_string()), None, None, OVMF::secure_boot_default())),
Box::new(OVMF::new(
"/dev/vm1/vm-108-efidisk".to_string(),
Some("04d064c3-66a1-4aa7-9589-f8b3ecf91cd7".to_string()),
None,
None,
OVMF::secure_boot_default(),
)),
Memory::new(16384, Some(false)),
Cpu::new(
"qemu64".to_string(),
Expand Down Expand Up @@ -136,7 +142,13 @@ mod tests {

let expected = System::new(
Box::new(Q35::new()),
Box::new(OVMF::new("/dev/vm1/vm-950-disk-0".to_string(), Some("c0e240a5-859a-4378-a2d9-95088f531142".to_string()), None, None, OVMF::secure_boot_default())),
Box::new(OVMF::new(
"/dev/vm1/vm-950-disk-0".to_string(),
Some("c0e240a5-859a-4378-a2d9-95088f531142".to_string()),
None,
None,
OVMF::secure_boot_default(),
)),
Memory::new(16384, Some(false)),
Cpu::new(
"qemu64".to_string(),
Expand Down

0 comments on commit 3a51f49

Please sign in to comment.