mirror of
https://github.com/kata-containers/kata-containers.git
synced 2025-09-25 18:53:44 +00:00
Merge pull request #9639 from emanuellima1/rng-impl
runtime-rs: Add RNG to QEMU cmdline
This commit is contained in:
@@ -1212,6 +1212,63 @@ impl ToQemuParams for Rtc {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Debug)]
|
||||||
|
struct ObjectRngRandom {
|
||||||
|
// id is the device ID
|
||||||
|
id: String,
|
||||||
|
|
||||||
|
// filename is the entropy source on the host
|
||||||
|
filename: String,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl ObjectRngRandom {
|
||||||
|
fn new() -> ObjectRngRandom {
|
||||||
|
ObjectRngRandom {
|
||||||
|
id: "rng0".to_owned(),
|
||||||
|
filename: "/dev/urandom".to_owned(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[async_trait]
|
||||||
|
impl ToQemuParams for ObjectRngRandom {
|
||||||
|
async fn qemu_params(&self) -> Result<Vec<String>> {
|
||||||
|
let mut object_params = Vec::new();
|
||||||
|
|
||||||
|
object_params.push("rng-random".to_owned());
|
||||||
|
object_params.push(format!("id={}", self.id));
|
||||||
|
object_params.push(format!("filename={}", self.filename));
|
||||||
|
|
||||||
|
Ok(vec!["-object".to_owned(), object_params.join(",")])
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug)]
|
||||||
|
struct DeviceRng {
|
||||||
|
// transport is the virtio transport for this device.
|
||||||
|
transport: String,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl DeviceRng {
|
||||||
|
fn new() -> DeviceRng {
|
||||||
|
DeviceRng {
|
||||||
|
transport: "virtio-rng-pci".to_owned(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[async_trait]
|
||||||
|
impl ToQemuParams for DeviceRng {
|
||||||
|
async fn qemu_params(&self) -> Result<Vec<String>> {
|
||||||
|
let mut device_params = Vec::new();
|
||||||
|
|
||||||
|
device_params.push(self.transport.clone());
|
||||||
|
device_params.push(format!("rng={}", "rng0".to_owned()));
|
||||||
|
|
||||||
|
Ok(vec!["-device".to_owned(), device_params.join(",")])
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
struct DeviceIntelIommu {
|
struct DeviceIntelIommu {
|
||||||
intremap: bool,
|
intremap: bool,
|
||||||
@@ -1432,6 +1489,10 @@ impl<'a> QemuCmdLine<'a> {
|
|||||||
|
|
||||||
qemu_cmd_line.add_rtc();
|
qemu_cmd_line.add_rtc();
|
||||||
|
|
||||||
|
if qemu_cmd_line.bus_type() != VirtioBusType::Ccw {
|
||||||
|
qemu_cmd_line.add_rng();
|
||||||
|
}
|
||||||
|
|
||||||
Ok(qemu_cmd_line)
|
Ok(qemu_cmd_line)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1447,6 +1508,14 @@ impl<'a> QemuCmdLine<'a> {
|
|||||||
self.devices.push(Box::new(rtc));
|
self.devices.push(Box::new(rtc));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn add_rng(&mut self) {
|
||||||
|
let rng_object = ObjectRngRandom::new();
|
||||||
|
let rng_device = DeviceRng::new();
|
||||||
|
|
||||||
|
self.devices.push(Box::new(rng_object));
|
||||||
|
self.devices.push(Box::new(rng_device));
|
||||||
|
}
|
||||||
|
|
||||||
fn bus_type(&self) -> VirtioBusType {
|
fn bus_type(&self) -> VirtioBusType {
|
||||||
if self.config.machine_info.machine_type.contains("-ccw-") {
|
if self.config.machine_info.machine_type.contains("-ccw-") {
|
||||||
VirtioBusType::Ccw
|
VirtioBusType::Ccw
|
||||||
|
Reference in New Issue
Block a user