From db820aff681831fb7e759eec4dd6abe5d44baeed Mon Sep 17 00:00:00 2001 From: Bruce Leidl Date: Sun, 6 Jan 2019 18:05:05 -0500 Subject: [PATCH] Rename modules image to kernel image and add some extra metadata --- citadel-image/src/build.rs | 3 +++ citadel-image/src/config.rs | 12 +++++++++--- citadel-install/src/installer.rs | 12 ++++++------ citadel-mount/src/main.rs | 12 ++++++------ libcitadel/src/config.rs | 8 ++++++++ libcitadel/src/header.rs | 4 ++++ libcitadel/src/resource.rs | 28 ++++++++++++++++++++-------- 7 files changed, 56 insertions(+), 23 deletions(-) diff --git a/citadel-image/src/build.rs b/citadel-image/src/build.rs index fa4418e..8948a34 100644 --- a/citadel-image/src/build.rs +++ b/citadel-image/src/build.rs @@ -176,6 +176,9 @@ impl UpdateBuilder { if let Some(kv) = self.config.kernel_version() { writeln!(v, "kernel-version = \"{}\"", kv)?; } + if let Some(kid) = self.config.kernel_id() { + writeln!(v, "kernel-id = \"{}\"", kid)?; + } writeln!(v, "channel = \"{}\"", self.config.channel())?; writeln!(v, "version = {}", self.config.version())?; writeln!(v, "nblocks = {}", self.nblocks.unwrap())?; diff --git a/citadel-image/src/config.rs b/citadel-image/src/config.rs index 80bf89f..54a509a 100644 --- a/citadel-image/src/config.rs +++ b/citadel-image/src/config.rs @@ -15,6 +15,8 @@ pub struct BuildConfig { source: String, #[serde(rename = "kernel-version")] kernel_version: Option, + #[serde(rename = "kernel-id")] + kernel_id: Option, #[serde(skip)] basedir: PathBuf, @@ -57,7 +59,7 @@ impl BuildConfig { fn validate(&self) -> Result<()> { let itype = self.image_type.as_str(); - if itype != "extra" && itype != "rootfs" && itype != "modules" { + if itype != "extra" && itype != "rootfs" && itype != "kernel" { bail!("Invalid image type '{}'", self.image_type); }; let src = Path::new(&self.source); @@ -67,8 +69,8 @@ impl BuildConfig { src.display() ); } - if self.image_type == "modules" && self.kernel_version.is_none() { - bail!("Cannot build 'modules' image without kernel-version field"); + if self.image_type == "kernel" && self.kernel_version.is_none() { + bail!("Cannot build 'kernel' image without kernel-version field"); } Ok(()) @@ -90,6 +92,10 @@ impl BuildConfig { self.kernel_version.as_ref().map(|s| s.as_str()) } + pub fn kernel_id(&self) -> Option<&str> { + self.kernel_id.as_ref().map(|s| s.as_str()) + } + pub fn version(&self) -> usize { self.version } diff --git a/citadel-install/src/installer.rs b/citadel-install/src/installer.rs index 022b3cd..a87d50b 100644 --- a/citadel-install/src/installer.rs +++ b/citadel-install/src/installer.rs @@ -77,10 +77,10 @@ impl Installer { MKFS_VFAT,MKFS_BTRFS,LSBLK,BTRFS,MOUNT,UMOUNT,CHOWN,TAR,XZ,CITADEL_IMAGE, ]; - let modules_img = self.modules_imagename(); + let kernel_img = self.kernel_imagename(); let artifacts = vec![ "bootx64.efi", "bzImage", - modules_img.as_str(), EXTRA_IMAGE_NAME, + kernel_img.as_str(), EXTRA_IMAGE_NAME, ]; if self.target_device.is_empty() { @@ -371,16 +371,16 @@ impl Installer { self.copy_artifact(EXTRA_IMAGE_NAME, &resources)?; - let modules = self.modules_imagename(); - self.copy_artifact(&modules, &resources)?; + let kernel_img = self.kernel_imagename(); + self.copy_artifact(&kernel_img, &resources)?; Ok(()) } - fn modules_imagename(&self) -> String { + fn kernel_imagename(&self) -> String { let utsname = util::uname(); let v = utsname.release().split("-").collect::>(); - format!("citadel-modules-{}.img", v[0]) + format!("citadel-kernel-{}.img", v[0]) } fn target_partition(&self, num: usize) -> String { diff --git a/citadel-mount/src/main.rs b/citadel-mount/src/main.rs index 1a6947b..230a2cc 100644 --- a/citadel-mount/src/main.rs +++ b/citadel-mount/src/main.rs @@ -18,13 +18,13 @@ use rootfs::Rootfs; /// mount command supports 4 subcommands /// /// citadel-mount rootfs -/// citadel-mount modules +/// citadel-mount kernel /// citadel-mount extra /// citadel-mount copy-artifacts /// /// 'rootfs' creates the /dev/mapper/rootfs device which will be mounted as root filesystem /// -/// 'modules' mounts a resource bundle containing kernel modules +/// 'kernel' mounts a resource bundle containing kernel modules /// 'extra' mounts a resource bundle containing extra files /// /// 'copy-artifacts' searches for a boot partition containing an /images @@ -42,7 +42,7 @@ fn main() { args.next(); let result = match args.next() { Some(ref s) if s == "rootfs" => mount_rootfs(), - Some(ref s) if s == "modules" => mount_modules(), + Some(ref s) if s == "kernel" => mount_kernel(), Some(ref s) if s == "extra" => mount_extra(), _ => Err(format_err!("Bad or missing argument")), }; @@ -59,9 +59,9 @@ fn mount_rootfs() -> Result<()> { rootfs.setup() } -fn mount_modules() -> Result<()> { - info!("citadel-mount modules"); - let mut image = ResourceImage::find("modules")?; +fn mount_kernel() -> Result<()> { + info!("citadel-mount kernel"); + let mut image = ResourceImage::find("kernel")?; image.mount()?; Ok(()) } diff --git a/libcitadel/src/config.rs b/libcitadel/src/config.rs index fb18433..c5cfd68 100644 --- a/libcitadel/src/config.rs +++ b/libcitadel/src/config.rs @@ -88,6 +88,14 @@ impl OsRelease { OsRelease::get_int_value("CITADEL_ROOTFS_VERSION") } + pub fn citadel_kernel_version() -> Option<&'static str> { + OsRelease::get_value("CITADEL_KERNEL_VERSION") + } + + pub fn citadel_kernel_id() -> Option<&'static str> { + OsRelease::get_value("CITADEL_KERNEL_ID") + } + fn _get_value(&self, key: &str) -> Option<&str> { self.vars.get(key).map(|v| v.as_str()) } diff --git a/libcitadel/src/header.rs b/libcitadel/src/header.rs index b802a1b..426e0a5 100644 --- a/libcitadel/src/header.rs +++ b/libcitadel/src/header.rs @@ -294,6 +294,8 @@ struct MetaInfoToml { channel: String, #[serde(rename = "kernel-version")] kernel_version: Option, + #[serde(rename = "kernel-id")] + kernel_id: Option, version: u32, #[serde(rename = "base-version")] base_version: Option, @@ -340,6 +342,8 @@ impl MetaInfo { pub fn kernel_version(&self) -> Option<&str> { self.toml().kernel_version.as_ref().map(|s| s.as_str()) } + pub fn kernel_id(&self) -> Option<&str> { self.toml().kernel_id.as_ref().map(|s| s.as_str()) } + pub fn version(&self) -> u32 { self.toml().version } diff --git a/libcitadel/src/resource.rs b/libcitadel/src/resource.rs index 0ed845d..b0c9d24 100644 --- a/libcitadel/src/resource.rs +++ b/libcitadel/src/resource.rs @@ -3,7 +3,7 @@ use std::ffi::OsStr; use std::io::{self,Seek,SeekFrom}; use std::path::{Path, PathBuf}; -use {CommandLine,ImageHeader,MetaInfo,Result,Partition,Mount,verity,util}; +use {CommandLine,OsRelease,ImageHeader,MetaInfo,Result,Partition,Mount,verity,util}; use failure::ResultExt; @@ -437,23 +437,25 @@ fn current_kernel_version() -> String { // fn all_matching_images(dir: &Path, image_type: &str, channel: Option<&str>) -> Result> { let kernel_version = current_kernel_version(); - let kv = if image_type == "modules" { + let kv = if image_type == "kernel" { Some(kernel_version.as_str()) } else { None }; + let kernel_id = OsRelease::citadel_kernel_id(); + let mut v = Vec::new(); for entry in fs::read_dir(dir)? { - maybe_add_dir_entry(entry?, image_type, channel, kv, &mut v)?; + maybe_add_dir_entry(entry?, image_type, channel, kv, kernel_id, &mut v)?; } Ok(v) } // Examine a directory entry to determine if it is a resource image which -// matches a given channel and image_type. If the image_type is "modules" -// then also match the kernel-version field. If channel is None then don't -// consider the channel in the match. +// matches a given channel and image_type. If the image_type is "kernel" +// then also match the kernel-version and kernel-id fields. If channel +// is None then don't consider the channel in the match. // // If the entry is a match, then instantiate a ResourceImage and add it to // the images vector. @@ -461,6 +463,7 @@ fn maybe_add_dir_entry(entry: DirEntry, image_type: &str, channel: Option<&str>, kernel_version: Option<&str>, + kernel_id: Option<&str>, images: &mut Vec) -> Result<()> { let path = entry.path(); @@ -486,8 +489,17 @@ fn maybe_add_dir_entry(entry: DirEntry, } } - if metainfo.image_type() == image_type && metainfo.kernel_version() == kernel_version { - images.push(ResourceImage::new(&path, header, metainfo)); + if image_type != metainfo.image_type() { + return Ok(()) } + + if image_type == "kernel" { + if metainfo.kernel_version() != kernel_version || metainfo.kernel_id() != kernel_id { + return Ok(()); + } + } + + images.push(ResourceImage::new(&path, header, metainfo)); + Ok(()) }