Skip to content

Commit

Permalink
blsctl: Force Into<Kernel> for Legacykernel to interop
Browse files Browse the repository at this point in the history
Signed-off-by: Ikey Doherty <[email protected]>
  • Loading branch information
ikeycode committed Jun 9, 2024
1 parent 7597eb6 commit d4f2a17
Showing 1 changed file with 45 additions and 5 deletions.
50 changes: 45 additions & 5 deletions blsctl/src/legacy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,40 @@

//! Support for legacy schema (CBM days) kernel packaging
use std::{fs, path::Path};
use std::{
fs,
path::{Path, PathBuf},
};

use blsforme::kernel::{AuxilliaryFile, AuxilliaryKind, Kernel};

/// A discovery type: Will not be public forever.
#[derive(Debug)]
pub struct LegacyKernel {
struct LegacyKernel {
version: String,
path: PathBuf,
variant: String,
release: u64,
aux: Vec<AuxilliaryFile>,
}

impl From<LegacyKernel> for Kernel {
fn from(val: LegacyKernel) -> Self {
let (initrd, extras) = val
.aux
.into_iter()
.partition(|a| matches!(a.kind, AuxilliaryKind::InitRD));
Kernel {
version: val.version,
image: val.path,
initrd,
extras,
}
}
}

/// Why oh why did we invent this poxy scheme
pub fn discover_kernels_legacy(namespace: &str, root: impl AsRef<Path>) -> color_eyre::Result<Vec<LegacyKernel>> {
pub fn discover_kernels_legacy(namespace: &str, root: impl AsRef<Path>) -> color_eyre::Result<Vec<Kernel>> {
let root = root.as_ref().join("usr").join("lib").join("kernel");
let mut initial_kernels = vec![];

Expand All @@ -33,9 +55,11 @@ pub fn discover_kernels_legacy(namespace: &str, root: impl AsRef<Path>) -> color
if let Some((version, release)) = version.rfind('-').map(|i| version.split_at(i)) {
log::trace!("discovered vmlinuz: {file_name}");
initial_kernels.push(LegacyKernel {
path: item.path(),
version: version.into(),
variant: variant.into(),
release: release.chars().skip(1).collect::<String>().parse::<u64>()?,
aux: vec![],
})
}
}
Expand All @@ -45,7 +69,7 @@ pub fn discover_kernels_legacy(namespace: &str, root: impl AsRef<Path>) -> color
initial_kernels.sort_by_key(|k| k.release);
initial_kernels.reverse();

for kernel in initial_kernels.iter() {
for kernel in initial_kernels.iter_mut() {
let cmdline = root.join(format!(
"cmdline-{}-{}.{}",
&kernel.version, kernel.release, &kernel.variant
Expand All @@ -65,17 +89,33 @@ pub fn discover_kernels_legacy(namespace: &str, root: impl AsRef<Path>) -> color

if cmdline.exists() {
log::debug!("cmdline: {cmdline:?}");
kernel.aux.push(AuxilliaryFile {
path: cmdline,
kind: AuxilliaryKind::Cmdline,
})
}
if initrd.exists() {
log::debug!("initrd: {initrd:?}");
kernel.aux.push(AuxilliaryFile {
path: initrd,
kind: AuxilliaryKind::InitRD,
})
}
if config.exists() {
log::debug!("config: {config:?}");
kernel.aux.push(AuxilliaryFile {
path: config,
kind: AuxilliaryKind::Config,
})
}
if sysmap.exists() {
log::debug!("sysmap: {sysmap:?}");
kernel.aux.push(AuxilliaryFile {
path: sysmap,
kind: AuxilliaryKind::SystemMap,
})
}
}

Ok(initial_kernels)
Ok(initial_kernels.into_iter().map(|m| m.into()).collect())
}

0 comments on commit d4f2a17

Please sign in to comment.