diff --git a/pixie-server/src/http.rs b/pixie-server/src/http.rs index 9826e0d..68d3f3a 100644 --- a/pixie-server/src/http.rs +++ b/pixie-server/src/http.rs @@ -136,6 +136,26 @@ async fn image( Ok(format!("{updated} computer(s) affected\n").customize()) } +#[get("/admin/gc")] +async fn gc(state: Data) -> Result> { + let mut image_stats = state.image_stats.lock().await; + let mut chunk_stats = state.chunk_stats.lock().await; + let mut cnt = 0; + chunk_stats.retain(|k, v| { + if v.ref_cnt == 0 { + let path = state.storage_dir.join("chunks").join(hex::encode(k)); + fs::remove_file(path).unwrap(); + image_stats.total_csize -= v.csize; + image_stats.reclaimable -= v.csize; + cnt += 1; + false + } else { + true + } + }); + Ok(format!("Removed {} chunks\n", cnt)) +} + #[get("/admin/config")] async fn get_config(state: Data) -> Result { Ok(serde_json::to_string(&state.config)) @@ -188,6 +208,7 @@ pub async fn main(state: Arc) -> Result<()> { .app_data(data.clone()) .service(action) .service(image) + .service(gc) .service(get_config) .service(get_units) .service(get_hostmap) diff --git a/pixie-uefi/src/main.rs b/pixie-uefi/src/main.rs index 08d2bce..579df1e 100644 --- a/pixie-uefi/src/main.rs +++ b/pixie-uefi/src/main.rs @@ -38,7 +38,7 @@ async fn server_discover(os: UefiOS) -> Result
{ let msg = postcard::to_allocvec(&UdpRequest::Discover).unwrap(); loop { socket.send([255; 4], ACTION_PORT, &msg).await?; - os.sleep_us(10_000_000).await; + os.sleep_us(1_000_000).await; } }; @@ -91,7 +91,7 @@ async fn run(os: UefiOS) -> Result { let udp_socket = os.udp_bind(None).await.unwrap(); loop { udp_socket.send(server.ip, 4043, b"pixie").await.unwrap(); - os.sleep_us(1_000_000).await; + os.sleep_us(10_000_000).await; } }); diff --git a/pixie-web/src/main.rs b/pixie-web/src/main.rs index f7d87c5..13824a7 100644 --- a/pixie-web/src/main.rs +++ b/pixie-web/src/main.rs @@ -288,6 +288,12 @@ fn Images<'a, 'b, G: Html>(cx: Scope<'a>, images: &'a ReadSignal) -> tr { td { "Reclaimable" } td { (Bytes(images.get().reclaimable)) } + td { } + td { + button(id="reclaime", on:click=move |_| send_req("/admin/gc".into()) ) { + "Reclaim disk space" + } + } } } }