mirror of
https://github.com/asterinas/asterinas.git
synced 2025-06-28 20:03:22 +00:00
Enhance OSDK performance by using size and modified time instead of sha256sum
This commit is contained in:
committed by
Tate, Hongliang Tian
parent
9d82ac8958
commit
ea1874aa46
66
osdk/Cargo.lock
generated
66
osdk/Cargo.lock
generated
@ -138,15 +138,6 @@ version = "2.6.0"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "b048fb63fd8b5923fc5aa7b340d8e156aec7ec02f0c78fa8a6ddc2613f6f71de"
|
checksum = "b048fb63fd8b5923fc5aa7b340d8e156aec7ec02f0c78fa8a6ddc2613f6f71de"
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "block-buffer"
|
|
||||||
version = "0.10.4"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "3078c7629b62d3f0439517fa394996acacc5cbc91c5a20d8c658e77abd503a71"
|
|
||||||
dependencies = [
|
|
||||||
"generic-array",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "bstr"
|
name = "bstr"
|
||||||
version = "1.9.1"
|
version = "1.9.1"
|
||||||
@ -202,7 +193,6 @@ dependencies = [
|
|||||||
"rev_buf_reader",
|
"rev_buf_reader",
|
||||||
"serde",
|
"serde",
|
||||||
"serde_json",
|
"serde_json",
|
||||||
"sha2",
|
|
||||||
"shlex",
|
"shlex",
|
||||||
"syn",
|
"syn",
|
||||||
"toml",
|
"toml",
|
||||||
@ -311,15 +301,6 @@ dependencies = [
|
|||||||
"memchr",
|
"memchr",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "cpufeatures"
|
|
||||||
version = "0.2.12"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "53fe5e26ff1b7aef8bca9c6080520cfb8d9333c7568e1829cef191a9723e5504"
|
|
||||||
dependencies = [
|
|
||||||
"libc",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "crc32fast"
|
name = "crc32fast"
|
||||||
version = "1.4.2"
|
version = "1.4.2"
|
||||||
@ -344,16 +325,6 @@ version = "0.8.20"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "22ec99545bb0ed0ea7bb9b8e1e9122ea386ff8a48c0922e43f36d45ab09e0e80"
|
checksum = "22ec99545bb0ed0ea7bb9b8e1e9122ea386ff8a48c0922e43f36d45ab09e0e80"
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "crypto-common"
|
|
||||||
version = "0.1.6"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "1bfb12502f3fc46cca1bb51ac28df9d618d813cdc3d2f25b9fe775a34af26bb3"
|
|
||||||
dependencies = [
|
|
||||||
"generic-array",
|
|
||||||
"typenum",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "dary_heap"
|
name = "dary_heap"
|
||||||
version = "0.3.6"
|
version = "0.3.6"
|
||||||
@ -380,16 +351,6 @@ version = "0.4.0"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "6184e33543162437515c2e2b48714794e37845ec9851711914eec9d308f6ebe8"
|
checksum = "6184e33543162437515c2e2b48714794e37845ec9851711914eec9d308f6ebe8"
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "digest"
|
|
||||||
version = "0.10.7"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "9ed9a281f7bc9b7576e61468ba615a66a5c8cfdff42420a70aa82701a3b1e292"
|
|
||||||
dependencies = [
|
|
||||||
"block-buffer",
|
|
||||||
"crypto-common",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "doc-comment"
|
name = "doc-comment"
|
||||||
version = "0.3.3"
|
version = "0.3.3"
|
||||||
@ -431,16 +392,6 @@ version = "1.0.1"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5"
|
checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5"
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "generic-array"
|
|
||||||
version = "0.14.7"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "85649ca51fd72272d7821adaf274ad91c288277713d9c18820d8499a7ff69e9a"
|
|
||||||
dependencies = [
|
|
||||||
"typenum",
|
|
||||||
"version_check",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "getrandom"
|
name = "getrandom"
|
||||||
version = "0.2.15"
|
version = "0.2.15"
|
||||||
@ -871,17 +822,6 @@ dependencies = [
|
|||||||
"serde",
|
"serde",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "sha2"
|
|
||||||
version = "0.10.8"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "793db75ad2bcafc3ffa7c68b215fee268f537982cd901d132f89c6343f3a3dc8"
|
|
||||||
dependencies = [
|
|
||||||
"cfg-if",
|
|
||||||
"cpufeatures",
|
|
||||||
"digest",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "shlex"
|
name = "shlex"
|
||||||
version = "1.3.0"
|
version = "1.3.0"
|
||||||
@ -958,12 +898,6 @@ dependencies = [
|
|||||||
"winnow",
|
"winnow",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "typenum"
|
|
||||||
version = "1.17.0"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "42ff0bf0c66b8238c6f3b578df37d0b7848e55df8577b3f74f92a69acceeb825"
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "unicode-ident"
|
name = "unicode-ident"
|
||||||
version = "1.0.12"
|
version = "1.0.12"
|
||||||
|
@ -23,7 +23,6 @@ regex = "1.10.4"
|
|||||||
rev_buf_reader = "0.3.0"
|
rev_buf_reader = "0.3.0"
|
||||||
serde = { version = "1.0.195", features = ["derive"] }
|
serde = { version = "1.0.195", features = ["derive"] }
|
||||||
serde_json = "1.0.111"
|
serde_json = "1.0.111"
|
||||||
sha2 = "0.10.8"
|
|
||||||
shlex = "1.3.0"
|
shlex = "1.3.0"
|
||||||
syn = { version = "2.0.52", features = ["extra-traits", "full", "parsing", "printing"] }
|
syn = { version = "2.0.52", features = ["extra-traits", "full", "parsing", "printing"] }
|
||||||
toml = { version = "0.8.8", features = ["preserve_order"] }
|
toml = { version = "0.8.8", features = ["preserve_order"] }
|
||||||
|
@ -1,6 +1,10 @@
|
|||||||
// SPDX-License-Identifier: MPL-2.0
|
// SPDX-License-Identifier: MPL-2.0
|
||||||
|
|
||||||
use std::path::{Path, PathBuf};
|
use std::{
|
||||||
|
os::unix::fs::MetadataExt,
|
||||||
|
path::{Path, PathBuf},
|
||||||
|
time::SystemTime,
|
||||||
|
};
|
||||||
|
|
||||||
use super::file::BundleFile;
|
use super::file::BundleFile;
|
||||||
use crate::{arch::Arch, util::hard_link_or_copy};
|
use crate::{arch::Arch, util::hard_link_or_copy};
|
||||||
@ -11,7 +15,8 @@ pub struct AsterBin {
|
|||||||
arch: Arch,
|
arch: Arch,
|
||||||
typ: AsterBinType,
|
typ: AsterBinType,
|
||||||
version: String,
|
version: String,
|
||||||
sha256sum: String,
|
modified_time: SystemTime,
|
||||||
|
size: u64,
|
||||||
stripped: bool,
|
stripped: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -41,8 +46,12 @@ impl BundleFile for AsterBin {
|
|||||||
&self.path
|
&self.path
|
||||||
}
|
}
|
||||||
|
|
||||||
fn sha256sum(&self) -> &String {
|
fn modified_time(&self) -> &SystemTime {
|
||||||
&self.sha256sum
|
&self.modified_time
|
||||||
|
}
|
||||||
|
|
||||||
|
fn size(&self) -> &u64 {
|
||||||
|
&self.size
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -59,11 +68,13 @@ impl AsterBin {
|
|||||||
arch,
|
arch,
|
||||||
typ,
|
typ,
|
||||||
version,
|
version,
|
||||||
sha256sum: String::new(),
|
modified_time: SystemTime::UNIX_EPOCH,
|
||||||
|
size: 0,
|
||||||
stripped,
|
stripped,
|
||||||
};
|
};
|
||||||
Self {
|
Self {
|
||||||
sha256sum: created.calculate_sha256sum(),
|
modified_time: created.get_modified_time(),
|
||||||
|
size: created.get_size(),
|
||||||
..created
|
..created
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -84,13 +95,15 @@ impl AsterBin {
|
|||||||
pub fn copy_to(self, base: impl AsRef<Path>) -> Self {
|
pub fn copy_to(self, base: impl AsRef<Path>) -> Self {
|
||||||
let file_name = self.path.file_name().unwrap();
|
let file_name = self.path.file_name().unwrap();
|
||||||
let copied_path = base.as_ref().join(file_name);
|
let copied_path = base.as_ref().join(file_name);
|
||||||
hard_link_or_copy(&self.path, copied_path).unwrap();
|
hard_link_or_copy(&self.path, &copied_path).unwrap();
|
||||||
|
let copied_metadata = copied_path.metadata().unwrap();
|
||||||
Self {
|
Self {
|
||||||
path: PathBuf::from(file_name),
|
path: PathBuf::from(file_name),
|
||||||
arch: self.arch,
|
arch: self.arch,
|
||||||
typ: self.typ,
|
typ: self.typ,
|
||||||
version: self.version,
|
version: self.version,
|
||||||
sha256sum: self.sha256sum,
|
modified_time: copied_metadata.modified().unwrap(),
|
||||||
|
size: copied_metadata.size(),
|
||||||
stripped: self.stripped,
|
stripped: self.stripped,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,36 +1,39 @@
|
|||||||
// SPDX-License-Identifier: MPL-2.0
|
// SPDX-License-Identifier: MPL-2.0
|
||||||
|
|
||||||
use std::{
|
use std::{
|
||||||
fs, io,
|
os::unix::fs::MetadataExt,
|
||||||
path::{Path, PathBuf},
|
path::{Path, PathBuf},
|
||||||
|
time::SystemTime,
|
||||||
};
|
};
|
||||||
|
|
||||||
use sha2::{Digest, Sha256};
|
|
||||||
|
|
||||||
use crate::util::hard_link_or_copy;
|
use crate::util::hard_link_or_copy;
|
||||||
|
|
||||||
/// A trait for files in a bundle. The file in a bundle should have it's digest and be validatable.
|
/// A trait for files in a bundle. The file in a bundle should have its modified time and be validatable.
|
||||||
pub trait BundleFile {
|
pub trait BundleFile {
|
||||||
fn path(&self) -> &PathBuf;
|
fn path(&self) -> &PathBuf;
|
||||||
|
|
||||||
fn sha256sum(&self) -> &String;
|
fn modified_time(&self) -> &SystemTime;
|
||||||
|
|
||||||
fn calculate_sha256sum(&self) -> String {
|
fn size(&self) -> &u64;
|
||||||
let mut file = fs::File::open(self.path()).unwrap();
|
|
||||||
let mut hasher = Sha256::new();
|
fn get_modified_time(&self) -> SystemTime {
|
||||||
let _n = io::copy(&mut file, &mut hasher).unwrap();
|
self.path().metadata().unwrap().modified().unwrap()
|
||||||
format!("{:x}", hasher.finalize())
|
}
|
||||||
|
|
||||||
|
fn get_size(&self) -> u64 {
|
||||||
|
self.path().metadata().unwrap().size()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn validate(&self) -> bool {
|
fn validate(&self) -> bool {
|
||||||
self.sha256sum() == &self.calculate_sha256sum()
|
self.size() == &self.get_size() && self.modified_time() >= &self.get_modified_time()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
|
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
|
||||||
pub struct Initramfs {
|
pub struct Initramfs {
|
||||||
path: PathBuf,
|
path: PathBuf,
|
||||||
sha256sum: String,
|
modified_time: SystemTime,
|
||||||
|
size: u64,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl BundleFile for Initramfs {
|
impl BundleFile for Initramfs {
|
||||||
@ -38,8 +41,12 @@ impl BundleFile for Initramfs {
|
|||||||
&self.path
|
&self.path
|
||||||
}
|
}
|
||||||
|
|
||||||
fn sha256sum(&self) -> &String {
|
fn modified_time(&self) -> &SystemTime {
|
||||||
&self.sha256sum
|
&self.modified_time
|
||||||
|
}
|
||||||
|
|
||||||
|
fn size(&self) -> &u64 {
|
||||||
|
&self.size
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -47,10 +54,12 @@ impl Initramfs {
|
|||||||
pub fn new(path: impl AsRef<Path>) -> Self {
|
pub fn new(path: impl AsRef<Path>) -> Self {
|
||||||
let created = Self {
|
let created = Self {
|
||||||
path: path.as_ref().to_path_buf(),
|
path: path.as_ref().to_path_buf(),
|
||||||
sha256sum: String::new(),
|
modified_time: SystemTime::UNIX_EPOCH,
|
||||||
|
size: 0,
|
||||||
};
|
};
|
||||||
Self {
|
Self {
|
||||||
sha256sum: created.calculate_sha256sum(),
|
modified_time: created.get_modified_time(),
|
||||||
|
size: created.get_size(),
|
||||||
..created
|
..created
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -59,9 +68,10 @@ impl Initramfs {
|
|||||||
pub fn copy_to(self, base: impl AsRef<Path>) -> Self {
|
pub fn copy_to(self, base: impl AsRef<Path>) -> Self {
|
||||||
let name = self.path.file_name().unwrap();
|
let name = self.path.file_name().unwrap();
|
||||||
let dest = base.as_ref().join(name);
|
let dest = base.as_ref().join(name);
|
||||||
hard_link_or_copy(&self.path, dest).unwrap();
|
hard_link_or_copy(&self.path, &dest).unwrap();
|
||||||
Self {
|
Self {
|
||||||
path: PathBuf::from(name),
|
path: PathBuf::from(name),
|
||||||
|
modified_time: dest.metadata().unwrap().modified().unwrap(),
|
||||||
..self
|
..self
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -168,7 +168,9 @@ impl Bundle {
|
|||||||
match (&self.manifest.initramfs, &config_action.boot.initramfs) {
|
match (&self.manifest.initramfs, &config_action.boot.initramfs) {
|
||||||
(Some(initramfs), Some(initramfs_path)) => {
|
(Some(initramfs), Some(initramfs_path)) => {
|
||||||
let config_initramfs = Initramfs::new(initramfs_path);
|
let config_initramfs = Initramfs::new(initramfs_path);
|
||||||
if initramfs.sha256sum() != config_initramfs.sha256sum() {
|
if initramfs.size() != config_initramfs.size()
|
||||||
|
|| initramfs.modified_time() < config_initramfs.modified_time()
|
||||||
|
{
|
||||||
return Err(initramfs_err);
|
return Err(initramfs_err);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,10 @@
|
|||||||
// SPDX-License-Identifier: MPL-2.0
|
// SPDX-License-Identifier: MPL-2.0
|
||||||
|
|
||||||
use std::path::{Path, PathBuf};
|
use std::{
|
||||||
|
os::unix::fs::MetadataExt,
|
||||||
|
path::{Path, PathBuf},
|
||||||
|
time::SystemTime,
|
||||||
|
};
|
||||||
|
|
||||||
use crate::util::hard_link_or_copy;
|
use crate::util::hard_link_or_copy;
|
||||||
|
|
||||||
@ -11,7 +15,8 @@ pub struct AsterVmImage {
|
|||||||
path: PathBuf,
|
path: PathBuf,
|
||||||
typ: AsterVmImageType,
|
typ: AsterVmImageType,
|
||||||
aster_version: String,
|
aster_version: String,
|
||||||
sha256sum: String,
|
modified_time: SystemTime,
|
||||||
|
size: u64,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
|
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
|
||||||
@ -35,8 +40,12 @@ impl BundleFile for AsterVmImage {
|
|||||||
&self.path
|
&self.path
|
||||||
}
|
}
|
||||||
|
|
||||||
fn sha256sum(&self) -> &String {
|
fn modified_time(&self) -> &SystemTime {
|
||||||
&self.sha256sum
|
&self.modified_time
|
||||||
|
}
|
||||||
|
|
||||||
|
fn size(&self) -> &u64 {
|
||||||
|
&self.size
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -46,10 +55,12 @@ impl AsterVmImage {
|
|||||||
path: path.as_ref().to_path_buf(),
|
path: path.as_ref().to_path_buf(),
|
||||||
typ,
|
typ,
|
||||||
aster_version,
|
aster_version,
|
||||||
sha256sum: String::new(),
|
modified_time: SystemTime::UNIX_EPOCH,
|
||||||
|
size: 0,
|
||||||
};
|
};
|
||||||
Self {
|
Self {
|
||||||
sha256sum: created.calculate_sha256sum(),
|
modified_time: created.get_modified_time(),
|
||||||
|
size: created.get_size(),
|
||||||
..created
|
..created
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -62,12 +73,14 @@ impl AsterVmImage {
|
|||||||
pub fn copy_to(self, base: impl AsRef<Path>) -> Self {
|
pub fn copy_to(self, base: impl AsRef<Path>) -> Self {
|
||||||
let file_name = self.path.file_name().unwrap();
|
let file_name = self.path.file_name().unwrap();
|
||||||
let copied_path = base.as_ref().join(file_name);
|
let copied_path = base.as_ref().join(file_name);
|
||||||
hard_link_or_copy(&self.path, copied_path).unwrap();
|
hard_link_or_copy(&self.path, &copied_path).unwrap();
|
||||||
|
let copied_metadata = copied_path.metadata().unwrap();
|
||||||
Self {
|
Self {
|
||||||
path: PathBuf::from(file_name),
|
path: PathBuf::from(file_name),
|
||||||
typ: self.typ,
|
typ: self.typ,
|
||||||
aster_version: self.aster_version,
|
aster_version: self.aster_version,
|
||||||
sha256sum: self.sha256sum,
|
modified_time: copied_metadata.modified().unwrap(),
|
||||||
|
size: copied_metadata.size(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -140,7 +140,7 @@ pub fn do_cached_build(
|
|||||||
|
|
||||||
// Check the existing bundle's reusability
|
// Check the existing bundle's reusability
|
||||||
if let Some(existing_bundle) = get_reusable_existing_bundle(&bundle_path, config, action) {
|
if let Some(existing_bundle) = get_reusable_existing_bundle(&bundle_path, config, action) {
|
||||||
if get_last_modified_time(aster_elf.path()) < existing_bundle.last_modified_time() {
|
if aster_elf.modified_time() < &existing_bundle.last_modified_time() {
|
||||||
info!("Reusing existing bundle: aster_elf is unchanged");
|
info!("Reusing existing bundle: aster_elf is unchanged");
|
||||||
return existing_bundle;
|
return existing_bundle;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user