mirror of
https://chromium.googlesource.com/crosvm/crosvm
synced 2024-11-28 17:44:10 +00:00
crosvm: config: Make --pmem-ext2 Linux specific flag
Although ext2 crate works only on Linux, --pmem-ext2 was exposed on Windows platform. So, we make this flag available only on Linux family. BUG=b:329359333 TEST=run crosvm with `--pmem-ext2 /path/to/crosvm/ext2/src/` Change-Id: I25ee0c27727dce04efa803a69085f24020f17c68 Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/5633330 Reviewed-by: Junichi Uekawa <uekawa@chromium.org> Commit-Queue: Keiichi Watanabe <keiichiw@chromium.org>
This commit is contained in:
parent
35d59da127
commit
e2522638fd
5 changed files with 32 additions and 26 deletions
|
@ -4,7 +4,7 @@
|
|||
|
||||
//! This crate provides a logic for creating an ext2 filesystem on memory.
|
||||
|
||||
#![cfg(target_os = "linux")]
|
||||
#![cfg(any(target_os = "android", target_os = "linux"))]
|
||||
#![deny(missing_docs)]
|
||||
|
||||
mod arena;
|
||||
|
|
|
@ -9,6 +9,7 @@ cfg_if::cfg_if! {
|
|||
|
||||
use crate::crosvm::sys::config::VfioOption;
|
||||
use crate::crosvm::sys::config::SharedDir;
|
||||
use crate::crosvm::sys::config::PmemExt2Option;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -94,7 +95,6 @@ use crate::crosvm::config::HypervisorKind;
|
|||
use crate::crosvm::config::InputDeviceOption;
|
||||
use crate::crosvm::config::IrqChipKind;
|
||||
use crate::crosvm::config::MemOptions;
|
||||
use crate::crosvm::config::PmemExt2Option;
|
||||
use crate::crosvm::config::TouchDeviceOption;
|
||||
use crate::crosvm::config::VhostUserFrontendOption;
|
||||
use crate::crosvm::config::VhostUserFsOption;
|
||||
|
@ -1838,6 +1838,7 @@ pub struct RunCommand {
|
|||
/// path to a disk image
|
||||
pmem_device: Vec<DiskOption>,
|
||||
|
||||
#[cfg(any(target_os = "android", target_os = "linux"))]
|
||||
#[argh(option, arg_name = "PATH")]
|
||||
#[serde(default)]
|
||||
#[merge(strategy = append)]
|
||||
|
@ -2898,7 +2899,10 @@ impl TryFrom<RunCommand> for super::config::Config {
|
|||
}
|
||||
}
|
||||
|
||||
cfg.pmem_ext2 = cmd.pmem_ext2;
|
||||
#[cfg(any(target_os = "android", target_os = "linux"))]
|
||||
{
|
||||
cfg.pmem_ext2 = cmd.pmem_ext2;
|
||||
}
|
||||
|
||||
#[cfg(feature = "pvclock")]
|
||||
{
|
||||
|
|
|
@ -386,12 +386,6 @@ pub struct FileBackedMappingParameters {
|
|||
pub align: bool,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Serialize, Deserialize, PartialEq, Eq, serde_keyvalue::FromKeyValues)]
|
||||
#[serde(deny_unknown_fields, rename_all = "kebab-case")]
|
||||
pub struct PmemExt2Option {
|
||||
pub path: PathBuf,
|
||||
}
|
||||
|
||||
fn parse_hex_or_decimal(maybe_hex_string: &str) -> Result<u64, String> {
|
||||
// Parse string starting with 0x as hex and others as numbers.
|
||||
if let Some(hex_string) = maybe_hex_string.strip_prefix("0x") {
|
||||
|
@ -801,7 +795,8 @@ pub struct Config {
|
|||
#[cfg(feature = "plugin")]
|
||||
pub plugin_mounts: Vec<crate::crosvm::plugin::BindMount>,
|
||||
pub plugin_root: Option<PathBuf>,
|
||||
pub pmem_ext2: Vec<PmemExt2Option>,
|
||||
#[cfg(any(target_os = "android", target_os = "linux"))]
|
||||
pub pmem_ext2: Vec<crate::crosvm::sys::config::PmemExt2Option>,
|
||||
pub pmems: Vec<PmemOption>,
|
||||
#[cfg(feature = "process-invariants")]
|
||||
pub process_invariants_data_handle: Option<u64>,
|
||||
|
@ -1023,6 +1018,7 @@ impl Default for Config {
|
|||
#[cfg(feature = "plugin")]
|
||||
plugin_mounts: Vec::new(),
|
||||
plugin_root: None,
|
||||
#[cfg(any(target_os = "android", target_os = "linux"))]
|
||||
pmem_ext2: Vec::new(),
|
||||
pmems: Vec::new(),
|
||||
#[cfg(feature = "process-invariants")]
|
||||
|
@ -2416,19 +2412,4 @@ mod tests {
|
|||
.unwrap_err()
|
||||
.contains("swap-interval parameter can only be set for writable pmem device"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn parse_pmem_ext2() {
|
||||
let config: Config = crate::crosvm::cmdline::RunCommand::from_args(
|
||||
&[],
|
||||
&["--pmem-ext2", "/path/to/dir", "/dev/null"],
|
||||
)
|
||||
.unwrap()
|
||||
.try_into()
|
||||
.unwrap();
|
||||
|
||||
let opt = config.pmem_ext2.first().unwrap();
|
||||
|
||||
assert_eq!(opt.path, PathBuf::from("/path/to/dir"));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -220,6 +220,12 @@ impl FromStr for SharedDir {
|
|||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Serialize, Deserialize, PartialEq, Eq, serde_keyvalue::FromKeyValues)]
|
||||
#[serde(deny_unknown_fields, rename_all = "kebab-case")]
|
||||
pub struct PmemExt2Option {
|
||||
pub path: PathBuf,
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use std::path::Path;
|
||||
|
@ -761,4 +767,19 @@ mod tests {
|
|||
.use_dax
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn parse_pmem_ext2() {
|
||||
let config: Config = crate::crosvm::cmdline::RunCommand::from_args(
|
||||
&[],
|
||||
&["--pmem-ext2", "/path/to/dir", "/dev/null"],
|
||||
)
|
||||
.unwrap()
|
||||
.try_into()
|
||||
.unwrap();
|
||||
|
||||
let opt = config.pmem_ext2.first().unwrap();
|
||||
|
||||
assert_eq!(opt.path, PathBuf::from("/path/to/dir"));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -88,10 +88,10 @@ use sync::Mutex;
|
|||
use vm_control::api::VmMemoryClient;
|
||||
use vm_memory::GuestAddress;
|
||||
|
||||
use crate::crosvm::config::PmemExt2Option;
|
||||
use crate::crosvm::config::PmemOption;
|
||||
use crate::crosvm::config::VhostUserFrontendOption;
|
||||
use crate::crosvm::config::VhostUserFsOption;
|
||||
use crate::crosvm::sys::config::PmemExt2Option;
|
||||
|
||||
pub enum TaggedControlTube {
|
||||
Fs(Tube),
|
||||
|
|
Loading…
Reference in a new issue