dragonball: add kernel config.

It is used for holding guest kernel configuration information.

Fixes: #4257

Signed-off-by: Liu Jiang <gerry@linux.alibaba.com>
Signed-off-by: wllenyj <wllenyj@linux.alibaba.com>
Signed-off-by: Chao Wu <chaowu@linux.alibaba.com>
This commit is contained in:
wllenyj 2022-05-05 16:24:45 +08:00 committed by Chao Wu
parent 6850ef99ae
commit c1c1e5152a
3 changed files with 71 additions and 0 deletions

View File

@ -21,6 +21,7 @@ dbs-utils = "0.1.0"
kvm-bindings = "0.5.0"
kvm-ioctls = "0.11.0"
libc = "0.2.39"
linux-loader = "0.4.0"
log = "0.4.14"
nix = "0.23.1"
serde = "1.0.27"

View File

@ -0,0 +1,67 @@
// Copyright (C) 2022 Alibaba Cloud. All rights reserved.
// SPDX-License-Identifier: Apache-2.0
use std::fs::File;
/// Structure to hold guest kernel configuration information.
pub struct KernelConfigInfo {
/// The descriptor to the kernel file.
kernel_file: File,
/// The descriptor to the initrd file, if there is one
initrd_file: Option<File>,
/// The commandline for guest kernel.
cmdline: linux_loader::cmdline::Cmdline,
}
impl KernelConfigInfo {
/// Create a KernelConfigInfo instance.
pub fn new(
kernel_file: File,
initrd_file: Option<File>,
cmdline: linux_loader::cmdline::Cmdline,
) -> Self {
KernelConfigInfo {
kernel_file,
initrd_file,
cmdline,
}
}
/// Get a mutable reference to the kernel file.
pub fn kernel_file_mut(&mut self) -> &mut File {
&mut self.kernel_file
}
/// Get a mutable reference to the initrd file.
pub fn initrd_file_mut(&mut self) -> Option<&mut File> {
self.initrd_file.as_mut()
}
/// Get a shared reference to the guest kernel boot parameter object.
pub fn kernel_cmdline(&self) -> &linux_loader::cmdline::Cmdline {
&self.cmdline
}
/// Get a mutable reference to the guest kernel boot parameter object.
pub fn kernel_cmdline_mut(&mut self) -> &mut linux_loader::cmdline::Cmdline {
&mut self.cmdline
}
}
#[cfg(test)]
mod tests {
use super::*;
use vmm_sys_util::tempfile::TempFile;
#[test]
fn test_kernel_config_info() {
let kernel = TempFile::new().unwrap();
let initrd = TempFile::new().unwrap();
let mut cmdline = linux_loader::cmdline::Cmdline::new(1024);
cmdline.insert_str("ro").unwrap();
let mut info = KernelConfigInfo::new(kernel.into_file(), Some(initrd.into_file()), cmdline);
assert_eq!(info.cmdline.as_str(), "ro");
assert!(info.initrd_file_mut().is_some());
}
}

View File

@ -3,6 +3,9 @@
use serde_derive::{Deserialize, Serialize};
mod kernel_config;
pub use self::kernel_config::KernelConfigInfo;
/// Configuration information for user defined NUMA nodes.
#[derive(Clone, Debug, Default, Serialize, Deserialize, PartialEq)]
pub struct NumaRegionInfo {