Skip to content

Commit 32c4010

Browse files
committed
style(vm): format lifecycle extension changes
Signed-off-by: Patrick Riel <priel@nvidia.com>
1 parent 202b4b1 commit 32c4010

2 files changed

Lines changed: 19 additions & 50 deletions

File tree

crates/openshell-driver-vm/src/driver.rs

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
// SPDX-FileCopyrightText: Copyright (c) 2025-2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
22
// SPDX-License-Identifier: Apache-2.0
33

4+
use crate::gpu::{
5+
GpuInventory, SubnetAllocator, allocate_vsock_cid, mac_from_sandbox_id, tap_device_name,
6+
};
47
use crate::lifecycle::{
58
BackendFeature, GuestInitDropin, LaunchAbortReason, LaunchPlan, LifecycleExtensionRegistry,
69
RestoreContext, extension_state_dir,
710
};
8-
use crate::gpu::{
9-
GpuInventory, SubnetAllocator, allocate_vsock_cid, mac_from_sandbox_id, tap_device_name,
10-
};
1111
use crate::rootfs::{
1212
clone_or_copy_sparse_file, create_ext4_image_from_dir_with_size, create_rootfs_image_from_dir,
1313
extract_rootfs_archive_to, prepare_sandbox_rootfs_from_image_root, sandbox_guest_init_path,
@@ -919,9 +919,7 @@ impl VmDriver {
919919
sandbox: sandbox.clone(),
920920
state_dir: state_dir.clone(),
921921
};
922-
self.lifecycle_extensions
923-
.after_restore(&persisted)
924-
.await;
922+
self.lifecycle_extensions.after_restore(&persisted).await;
925923
}
926924
tokio::spawn({
927925
let driver = self.clone();
@@ -1162,11 +1160,7 @@ impl VmDriver {
11621160
sandbox: sandbox.clone(),
11631161
state_dir: state_dir.clone(),
11641162
};
1165-
if let Err(err) = self
1166-
.lifecycle_extensions
1167-
.before_restore(&persisted)
1168-
.await
1169-
{
1163+
if let Err(err) = self.lifecycle_extensions.before_restore(&persisted).await {
11701164
warn!(
11711165
sandbox_id = %sandbox.id,
11721166
sandbox_name = %sandbox.name,
@@ -4566,7 +4560,9 @@ fn write_guest_init_dropin_manifest(
45664560
let guest_path = overlay_upper_path(GUEST_INIT_DROPIN_MANIFEST);
45674561
let contents = render_guest_init_dropin_manifest(dropins);
45684562
write_rootfs_image_file(overlay_disk, &guest_path, &contents).map_err(|err| {
4569-
Status::internal(format!("write VM guest init drop-in manifest failed: {err}"))
4563+
Status::internal(format!(
4564+
"write VM guest init drop-in manifest failed: {err}"
4565+
))
45704566
})?;
45714567
set_rootfs_image_file_mode(overlay_disk, &guest_path, 0o644).map_err(|err| {
45724568
Status::internal(format!(
@@ -6377,8 +6373,8 @@ mod tests {
63776373
}
63786374

63796375
use crate::lifecycle::{
6380-
BackendFeature, LaunchPlan, LifecycleError, LifecycleExtension,
6381-
LifecycleExtensionRegistry, LifecycleResult,
6376+
BackendFeature, LaunchPlan, LifecycleError, LifecycleExtension, LifecycleExtensionRegistry,
6377+
LifecycleResult,
63826378
};
63836379
use crate::runtime::VmBackend;
63846380

crates/openshell-driver-vm/src/lifecycle.rs

Lines changed: 9 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -247,10 +247,7 @@ impl LaunchPlan {
247247
}
248248
}
249249

250-
pub fn require_backend_features(
251-
&mut self,
252-
features: impl IntoIterator<Item = BackendFeature>,
253-
) {
250+
pub fn require_backend_features(&mut self, features: impl IntoIterator<Item = BackendFeature>) {
254251
for feature in features {
255252
self.require_backend_feature(feature);
256253
}
@@ -412,11 +409,7 @@ pub trait LifecycleExtension: std::fmt::Debug + Send + Sync {
412409
///
413410
/// Invoked in reverse registration order. Errors are logged but do not
414411
/// propagate.
415-
async fn after_delete(
416-
&self,
417-
_sandbox: &Sandbox,
418-
_state_dir: &Path,
419-
) -> LifecycleResult<()> {
412+
async fn after_delete(&self, _sandbox: &Sandbox, _state_dir: &Path) -> LifecycleResult<()> {
420413
Ok(())
421414
}
422415

@@ -426,10 +419,7 @@ pub trait LifecycleExtension: std::fmt::Debug + Send + Sync {
426419
/// Returning an error causes the driver to skip restoring this
427420
/// sandbox; the persisted state is left on disk for operator
428421
/// inspection.
429-
async fn before_restore(
430-
&self,
431-
_sandbox: &RestoreContext,
432-
) -> LifecycleResult<()> {
422+
async fn before_restore(&self, _sandbox: &RestoreContext) -> LifecycleResult<()> {
433423
Ok(())
434424
}
435425

@@ -439,10 +429,7 @@ pub trait LifecycleExtension: std::fmt::Debug + Send + Sync {
439429
/// Only invoked when restore succeeds. If the restore fails partway
440430
/// through, [`after_launch_failed`](Self::after_launch_failed)
441431
/// runs instead.
442-
async fn after_restore(
443-
&self,
444-
_sandbox: &RestoreContext,
445-
) -> LifecycleResult<()> {
432+
async fn after_restore(&self, _sandbox: &RestoreContext) -> LifecycleResult<()> {
446433
Ok(())
447434
}
448435
}
@@ -558,9 +545,7 @@ impl LifecycleExtensionRegistry {
558545
.iter()
559546
.filter(|ext| match ext.activation() {
560547
ExtensionActivation::Global => true,
561-
ExtensionActivation::OnRequest { key } => {
562-
sandbox_requested_extension(sandbox, key)
563-
}
548+
ExtensionActivation::OnRequest { key } => sandbox_requested_extension(sandbox, key),
564549
})
565550
.collect()
566551
}
@@ -649,10 +634,7 @@ impl LifecycleExtensionRegistry {
649634
}
650635
}
651636

652-
pub async fn before_restore(
653-
&self,
654-
sandbox: &RestoreContext,
655-
) -> LifecycleResult<()> {
637+
pub async fn before_restore(&self, sandbox: &RestoreContext) -> LifecycleResult<()> {
656638
for ext in self.active_for(&sandbox.sandbox) {
657639
ext.before_restore(sandbox).await?;
658640
}
@@ -752,9 +734,7 @@ fn validate_extension_name(name: &str) -> LifecycleResult<()> {
752734
Ok(())
753735
}
754736

755-
fn validate_descriptor_strings(
756-
descriptor: &ExtensionDescriptor,
757-
) -> LifecycleResult<()> {
737+
fn validate_descriptor_strings(descriptor: &ExtensionDescriptor) -> LifecycleResult<()> {
758738
for value in descriptor
759739
.provides
760740
.kernel_profiles
@@ -932,11 +912,7 @@ mod tests {
932912
Ok(())
933913
}
934914

935-
async fn after_delete(
936-
&self,
937-
_sandbox: &Sandbox,
938-
_state_dir: &Path,
939-
) -> LifecycleResult<()> {
915+
async fn after_delete(&self, _sandbox: &Sandbox, _state_dir: &Path) -> LifecycleResult<()> {
940916
self.calls
941917
.lock()
942918
.unwrap()
@@ -1040,10 +1016,7 @@ mod tests {
10401016
.configure_launch(&sandbox, &PathBuf::from("/tmp/state"), &mut plan)
10411017
.await
10421018
.expect_err("scripted failure should propagate");
1043-
assert!(
1044-
err.message()
1045-
.contains("scripted configure_launch failure")
1046-
);
1019+
assert!(err.message().contains("scripted configure_launch failure"));
10471020

10481021
assert_eq!(ext_a.calls(), vec!["a:configure_launch"]);
10491022
assert_eq!(ext_fail.calls(), vec!["boom:configure_launch"]);

0 commit comments

Comments
 (0)