Skip to content

Commit

Permalink
fix image stats
Browse files Browse the repository at this point in the history
  • Loading branch information
Virv12 committed Jan 20, 2024
1 parent e29ebaf commit d79fdd6
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 7 deletions.
8 changes: 4 additions & 4 deletions pixie-server/src/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ fn atomic_write(path: &Path, data: &[u8]) -> Result<()> {
Ok(())
}

fn get_image_disk_size(image: &Image) -> u64 {
fn get_image_csize(image: &Image) -> u64 {
let mut chunks: Vec<_> = image
.disk
.iter()
Expand Down Expand Up @@ -119,7 +119,7 @@ impl State {
}
let content = fs::read(&path)?;
let image = postcard::from_bytes::<Image>(&content)?;
let csize = get_image_disk_size(&image);
let csize = get_image_csize(&image);
let mut size = 0;
for chunk in image.disk {
size += chunk.size as u64;
Expand Down Expand Up @@ -200,8 +200,8 @@ impl State {
let path = self.storage_dir.join("images").join(&name);
let data = postcard::to_allocvec(&image)?;

let size = get_image_disk_size(&image);
let csize = image.disk.iter().map(|chunk| chunk.csize as u64).sum();
let size = image.disk.iter().map(|chunk| chunk.size as u64).sum();
let csize = get_image_csize(&image);

self.image_stats.send_modify(|image_stats| {
let mut chunk_stats = self.chunk_stats.lock().unwrap();
Expand Down
3 changes: 0 additions & 3 deletions pixie-uefi/src/pull.rs
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,6 @@ pub async fn pull(os: UefiOS, server_addr: Address, image: String, chunks_port:
let mut found = None;
let mut buf = vec![0; size];
for &offset in &pos {
os.schedule().await;
disk.read(offset as u64, &mut buf).await.unwrap();
if blake3::hash(&buf).as_bytes() == &hash {
found = Some(offset);
Expand All @@ -213,7 +212,6 @@ pub async fn pull(os: UefiOS, server_addr: Address, image: String, chunks_port:
if let Some(found) = found {
for &offset in &pos {
if offset != found {
os.schedule().await;
disk.write(offset as u64, &buf).await.unwrap();
}
}
Expand Down Expand Up @@ -265,7 +263,6 @@ pub async fn pull(os: UefiOS, server_addr: Address, image: String, chunks_port:
let task2 = async {
while let Some((pos, data)) = rx.recv().await {
for offset in pos {
os.schedule().await;
disk.write(offset as u64, &data).await?;
}

Expand Down

0 comments on commit d79fdd6

Please sign in to comment.