| 306 | /// registration order**, so cleanup mirrors setup. |
| 307 | #[tonic::async_trait] |
| 308 | pub trait LifecycleExtension: std::fmt::Debug + Send + Sync { |
| 309 | fn name(&self) -> &str; |
| 310 | |
| 311 | /// Declare when this extension participates in a sandbox's lifecycle. |
| 312 | /// |
| 313 | /// Defaults to [`ExtensionActivation::Global`] (runs for every sandbox). |
| 314 | /// Override and return [`ExtensionActivation::OnRequest`] for an opt-in |
| 315 | /// extension that should only run when the sandbox carries the matching |
| 316 | /// request label. |
| 317 | fn activation(&self) -> ExtensionActivation { |
| 318 | ExtensionActivation::Global |
| 319 | } |
| 320 | |
| 321 | fn descriptor(&self) -> ExtensionDescriptor { |
| 322 | ExtensionDescriptor::new(self.name()) |
| 323 | } |
| 324 | |
| 325 | /// Contribute backend requirements and provisioning inputs to the plan |
| 326 | /// before the driver picks a backend. |
| 327 | /// |
| 328 | /// Use this hook to: |
| 329 | /// - Declare backend requirements with |
| 330 | /// [`LaunchPlan::require_backend`] or |
| 331 | /// [`LaunchPlan::require_backend_feature`]. |
| 332 | /// - Set [`LaunchPlan::kernel_profile`] or |
| 333 | /// [`LaunchPlan::kernel_image`]. |
| 334 | /// - Append [`LaunchPlan::guest_init_dropins`] entries. |
| 335 | /// |
| 336 | /// At this point [`LaunchPlan::backend`] is the driver's tentative |
| 337 | /// choice and may still change during backend resolution. Do not perform |
| 338 | /// host-side side effects here — defer them to |
| 339 | /// [`before_launch`](Self::before_launch). |
| 340 | async fn configure_launch( |
| 341 | &self, |
| 342 | _sandbox: &Sandbox, |
| 343 | _state_dir: &Path, |
| 344 | _plan: &mut LaunchPlan, |
| 345 | ) -> LifecycleResult<()> { |
| 346 | Ok(()) |
| 347 | } |
| 348 | |
| 349 | /// Perform host-side preparation with the resolved launch plan. |
| 350 | /// |
| 351 | /// At this point [`LaunchPlan::backend`], |
| 352 | /// [`LaunchPlan::required_backends`], and |
| 353 | /// [`LaunchPlan::required_backend_features`] are finalized and any |
| 354 | /// backend-specific host resources (subnet, tap, vsock) have been |
| 355 | /// allocated. This hook is the right place to bind PCI devices, set |
| 356 | /// up filesystem state, or otherwise prepare the host. |
| 357 | /// |
| 358 | /// Implementations MAY append entries to [`LaunchPlan::env`] to |
| 359 | /// inject additional guest environment variables, and MAY return an |
| 360 | /// error to abort the launch. Implementations MUST NOT change |
| 361 | /// [`LaunchPlan::backend`], [`LaunchPlan::required_backends`], or |
| 362 | /// [`LaunchPlan::required_backend_features`]; those changes are |
| 363 | /// ignored by the driver once `before_launch` is reached. |
| 364 | /// |
| 365 | /// If this hook performs allocations that must be released on failure |
nothing calls this directly
no outgoing calls
no test coverage detected