@@ -15,10 +15,11 @@ use crate::{
1515 boot:: { setup_composefs_bls_boot, setup_composefs_uki_boot, BootSetupType , BootType } ,
1616 repo:: { get_imgref, pull_composefs_repo} ,
1717 service:: start_finalize_stated_svc,
18+ soft_reboot:: prepare_soft_reboot_composefs,
1819 state:: write_composefs_state,
1920 status:: { get_bootloader, get_composefs_status, get_container_manifest_and_config} ,
2021 } ,
21- cli:: UpgradeOpts ,
22+ cli:: { SoftRebootMode , UpgradeOpts } ,
2223 composefs_consts:: { STATE_DIR_RELATIVE , TYPE1_ENT_PATH_STAGED , USER_CFG_STAGED } ,
2324 spec:: { Bootloader , Host , ImageReference } ,
2425 store:: { BootedComposefs , ComposefsRepository , Storage } ,
@@ -205,12 +206,20 @@ pub(crate) fn validate_update(
205206 Ok ( UpdateAction :: Proceed )
206207}
207208
209+ /// This is just an intersection of SwitchOpts and UpgradeOpts
210+ pub ( crate ) struct DoUpgradeOpts {
211+ pub ( crate ) apply : bool ,
212+ pub ( crate ) soft_reboot : Option < SoftRebootMode > ,
213+ }
214+
208215/// Performs the Update or Switch operation
209216#[ context( "Performing Upgrade Operation" ) ]
210217pub ( crate ) async fn do_upgrade (
211218 storage : & Storage ,
219+ booted_cfs : & BootedComposefs ,
212220 host : & Host ,
213221 imgref : & ImageReference ,
222+ opts : & DoUpgradeOpts ,
214223) -> Result < ( ) > {
215224 start_finalize_stated_svc ( ) ?;
216225
@@ -250,13 +259,21 @@ pub(crate) async fn do_upgrade(
250259
251260 write_composefs_state (
252261 & Utf8PathBuf :: from ( "/sysroot" ) ,
253- id,
262+ & id,
254263 imgref,
255264 true ,
256265 boot_type,
257266 boot_digest,
258267 ) ?;
259268
269+ if opts. apply {
270+ return crate :: reboot:: reboot ( ) ;
271+ }
272+
273+ if opts. soft_reboot . is_some ( ) {
274+ prepare_soft_reboot_composefs ( storage, booted_cfs, & id. to_hex ( ) , true ) . await ?;
275+ }
276+
260277 Ok ( ( ) )
261278}
262279
@@ -285,6 +302,11 @@ pub(crate) async fn upgrade_composefs(
285302 // Or if we have another staged deployment with a different image
286303 let staged_image = host. status . staged . as_ref ( ) . and_then ( |i| i. image . as_ref ( ) ) ;
287304
305+ let do_upgrade_opts = DoUpgradeOpts {
306+ soft_reboot : opts. soft_reboot ,
307+ apply : opts. apply ,
308+ } ;
309+
288310 if let Some ( staged_image) = staged_image {
289311 // We have a staged image and it has the same digest as the currently booted image's latest
290312 // digest
@@ -325,7 +347,8 @@ pub(crate) async fn upgrade_composefs(
325347 }
326348
327349 UpdateAction :: Proceed => {
328- return do_upgrade ( storage, & host, booted_imgref) . await ;
350+ return do_upgrade ( storage, composefs, & host, booted_imgref, & do_upgrade_opts)
351+ . await ;
329352 }
330353
331354 UpdateAction :: UpdateOrigin => {
@@ -353,7 +376,8 @@ pub(crate) async fn upgrade_composefs(
353376 }
354377
355378 UpdateAction :: Proceed => {
356- return do_upgrade ( storage, & host, booted_imgref) . await ;
379+ return do_upgrade ( storage, composefs, & host, booted_imgref, & do_upgrade_opts)
380+ . await ;
357381 }
358382
359383 UpdateAction :: UpdateOrigin => {
@@ -390,11 +414,7 @@ pub(crate) async fn upgrade_composefs(
390414 return Ok ( ( ) ) ;
391415 }
392416
393- do_upgrade ( storage, & host, booted_imgref) . await ?;
394-
395- if opts. apply {
396- return crate :: reboot:: reboot ( ) ;
397- }
417+ do_upgrade ( storage, composefs, & host, booted_imgref, & do_upgrade_opts) . await ?;
398418
399419 Ok ( ( ) )
400420}
0 commit comments