(
&self,
sandbox_id: &str,
image_ref: &str,
image_source: &str,
image_identity: &str,
bootstrap_root_disk: &Path,
staging_dir: &Path,
pa
| 2369 | |
| 2370 | #[allow(clippy::too_many_arguments)] |
| 2371 | async fn build_prepared_image_disk( |
| 2372 | &self, |
| 2373 | sandbox_id: &str, |
| 2374 | image_ref: &str, |
| 2375 | image_source: &str, |
| 2376 | image_identity: &str, |
| 2377 | bootstrap_root_disk: &Path, |
| 2378 | staging_dir: &Path, |
| 2379 | payload: &GuestImagePayload, |
| 2380 | ) -> Result<(), Status> { |
| 2381 | let cache_dir = image_cache_dir(&self.config.state_dir, image_identity); |
| 2382 | let image_path = image_cache_rootfs_image(&self.config.state_dir, image_identity); |
| 2383 | let prepared_image = staging_dir.join(IMAGE_CACHE_ROOTFS_IMAGE); |
| 2384 | tokio::fs::create_dir_all(&cache_dir).await.map_err(|err| { |
| 2385 | Status::internal(format!("create prepared image cache dir failed: {err}")) |
| 2386 | })?; |
| 2387 | |
| 2388 | let payload_for_size = payload.clone(); |
| 2389 | let min_size = self |
| 2390 | .config |
| 2391 | .overlay_disk_mib |
| 2392 | .checked_mul(1024 * 1024) |
| 2393 | .ok_or_else(|| Status::internal("prepared image disk size overflow"))?; |
| 2394 | let image_size = tokio::task::spawn_blocking(move || { |
| 2395 | prepared_image_disk_size_bytes(&payload_for_size, min_size) |
| 2396 | }) |
| 2397 | .await |
| 2398 | .map_err(|err| { |
| 2399 | Status::internal(format!("prepared image size calculation panicked: {err}")) |
| 2400 | })? |
| 2401 | .map_err(Status::internal)?; |
| 2402 | |
| 2403 | let payload_for_disk = payload.clone(); |
| 2404 | let prepared_image_for_disk = prepared_image.clone(); |
| 2405 | self.publish_vm_progress( |
| 2406 | sandbox_id, |
| 2407 | "CreatingRootDisk", |
| 2408 | "Formatting prepared VM image disk".to_string(), |
| 2409 | HashMap::from([ |
| 2410 | ("image_ref".to_string(), image_ref.to_string()), |
| 2411 | ("image_source".to_string(), image_source.to_string()), |
| 2412 | ("image_identity".to_string(), image_identity.to_string()), |
| 2413 | ]), |
| 2414 | ); |
| 2415 | tokio::task::spawn_blocking(move || { |
| 2416 | create_image_prep_disk(&prepared_image_for_disk, image_size, &payload_for_disk) |
| 2417 | }) |
| 2418 | .await |
| 2419 | .map_err(|err| Status::internal(format!("prepared image disk build panicked: {err}")))? |
| 2420 | .map_err(Status::failed_precondition)?; |
| 2421 | |
| 2422 | self.publish_vm_progress( |
| 2423 | sandbox_id, |
| 2424 | "PreparingRootfs", |
| 2425 | format!("Preparing VM image rootfs for \"{image_ref}\""), |
| 2426 | HashMap::from([ |
| 2427 | ("image_ref".to_string(), image_ref.to_string()), |
| 2428 | ("image_source".to_string(), image_source.to_string()), |
no test coverage detected