-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Summary: The default PCI bus can only handle a limited number of devices, which is not enough to test machines with large disk arrays. Add PCI bridge support for such use case and attach disks to their bridge instead. This is same as what antlir1 VM did, just that I only realized why the default setting is not enough after encountering the specific test. This requires an update to our initrd host config as it changes the location of root disks. Test Plan: `metalos/imaging_initrd/vmtest` covers all disk related stuff pretty well. Differential Revision: D49851480 fbshipit-source-id: 84e2dbb72b67a08570d67dd138b8a7bfb70ac34c
- Loading branch information
1 parent
84eff44
commit 4863a72
Showing
4 changed files
with
121 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,6 +8,7 @@ | |
mod disk; | ||
mod isolation; | ||
mod net; | ||
mod pci; | ||
mod runtime; | ||
mod share; | ||
mod ssh; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
/* | ||
* Copyright (c) Meta Platforms, Inc. and affiliates. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
|
||
use std::ffi::OsString; | ||
|
||
use thiserror::Error; | ||
|
||
pub(crate) const DEVICE_PER_BRIDGE: usize = 32; | ||
|
||
/// PCI Bridge. Each bridge can attach 32 devices | ||
#[derive(Debug, Clone)] | ||
pub(crate) struct PCIBridge { | ||
/// The ID of the bridge, starting from 0 | ||
id: usize, | ||
/// Chassis ID | ||
chassis_id: u8, | ||
} | ||
|
||
#[derive(Error, Debug)] | ||
pub(crate) enum PCIBridgeError { | ||
#[error("Chassis ID must fit into a u8. Got: {0}")] | ||
ChassisIDExceededError(usize), | ||
} | ||
type Result<T> = std::result::Result<T, PCIBridgeError>; | ||
|
||
impl PCIBridge { | ||
pub(crate) fn new(id: usize, chassis_id: usize) -> Result<Self> { | ||
let chassis_id = chassis_id | ||
.try_into() | ||
.map_err(|_| PCIBridgeError::ChassisIDExceededError(chassis_id))?; | ||
Ok(Self { id, chassis_id }) | ||
} | ||
|
||
/// Name of the bridge other devices can use to attach to | ||
pub(crate) fn name(&self) -> String { | ||
format!("pci{}", self.id) | ||
} | ||
|
||
/// Qemu arguments to create the bridge | ||
pub(crate) fn qemu_args(&self) -> Vec<OsString> { | ||
vec![ | ||
"-device".into(), | ||
format!( | ||
"pci-bridge,id={},chassis_nr={}", | ||
self.name(), | ||
self.chassis_id | ||
) | ||
.into(), | ||
] | ||
} | ||
} | ||
|
||
#[cfg(test)] | ||
mod test { | ||
use std::ffi::OsStr; | ||
|
||
use super::*; | ||
|
||
#[test] | ||
fn test_pcibridge() { | ||
assert!(PCIBridge::new(1, 10000000).is_err()); | ||
|
||
let bridge = PCIBridge::new(0, 1).expect("failed to create PCI bridge"); | ||
assert_eq!(bridge.name(), "pci0"); | ||
assert_eq!( | ||
&bridge.qemu_args().join(OsStr::new(" ")), | ||
"-device pci-bridge,id=pci0,chassis_nr=1", | ||
) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters