@@ -15,13 +15,14 @@ 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:: {
2021 get_bootloader, get_composefs_status, get_container_manifest_and_config, get_imginfo,
2122 ImgConfigManifest ,
2223 } ,
2324 } ,
24- cli:: UpgradeOpts ,
25+ cli:: { SoftRebootMode , UpgradeOpts } ,
2526 composefs_consts:: { STATE_DIR_RELATIVE , TYPE1_ENT_PATH_STAGED , USER_CFG_STAGED } ,
2627 spec:: { Bootloader , Host , ImageReference } ,
2728 store:: { BootedComposefs , ComposefsRepository , Storage } ,
@@ -208,13 +209,21 @@ pub(crate) fn validate_update(
208209 Ok ( UpdateAction :: Proceed )
209210}
210211
212+ /// This is just an intersection of SwitchOpts and UpgradeOpts
213+ pub ( crate ) struct DoUpgradeOpts {
214+ pub ( crate ) apply : bool ,
215+ pub ( crate ) soft_reboot : Option < SoftRebootMode > ,
216+ }
217+
211218/// Performs the Update or Switch operation
212219#[ context( "Performing Upgrade Operation" ) ]
213220pub ( crate ) async fn do_upgrade (
214221 storage : & Storage ,
222+ booted_cfs : & BootedComposefs ,
215223 host : & Host ,
216224 imgref : & ImageReference ,
217225 img_manifest_config : & ImgConfigManifest ,
226+ opts : & DoUpgradeOpts ,
218227) -> Result < ( ) > {
219228 start_finalize_stated_svc ( ) ?;
220229
@@ -254,7 +263,7 @@ pub(crate) async fn do_upgrade(
254263
255264 write_composefs_state (
256265 & Utf8PathBuf :: from ( "/sysroot" ) ,
257- id,
266+ & id,
258267 imgref,
259268 true ,
260269 boot_type,
@@ -263,6 +272,14 @@ pub(crate) async fn do_upgrade(
263272 )
264273 . await ?;
265274
275+ if opts. apply {
276+ return crate :: reboot:: reboot ( ) ;
277+ }
278+
279+ if opts. soft_reboot . is_some ( ) {
280+ prepare_soft_reboot_composefs ( storage, booted_cfs, & id. to_hex ( ) , true ) . await ?;
281+ }
282+
266283 Ok ( ( ) )
267284}
268285
@@ -299,6 +316,11 @@ pub(crate) async fn upgrade_composefs(
299316 // Or if we have another staged deployment with a different image
300317 let staged_image = host. status . staged . as_ref ( ) . and_then ( |i| i. image . as_ref ( ) ) ;
301318
319+ let do_upgrade_opts = DoUpgradeOpts {
320+ soft_reboot : opts. soft_reboot ,
321+ apply : opts. apply ,
322+ } ;
323+
302324 if let Some ( staged_image) = staged_image {
303325 // We have a staged image and it has the same digest as the currently booted image's latest
304326 // digest
@@ -337,7 +359,15 @@ pub(crate) async fn upgrade_composefs(
337359 }
338360
339361 UpdateAction :: Proceed => {
340- return do_upgrade ( storage, & host, booted_imgref, & img_config) . await ;
362+ return do_upgrade (
363+ storage,
364+ composefs,
365+ & host,
366+ booted_imgref,
367+ & img_config,
368+ & do_upgrade_opts,
369+ )
370+ . await ;
341371 }
342372
343373 UpdateAction :: UpdateOrigin => {
@@ -365,7 +395,15 @@ pub(crate) async fn upgrade_composefs(
365395 }
366396
367397 UpdateAction :: Proceed => {
368- return do_upgrade ( storage, & host, booted_imgref, & img_config) . await ;
398+ return do_upgrade (
399+ storage,
400+ composefs,
401+ & host,
402+ booted_imgref,
403+ & img_config,
404+ & do_upgrade_opts,
405+ )
406+ . await ;
369407 }
370408
371409 UpdateAction :: UpdateOrigin => {
@@ -382,11 +420,15 @@ pub(crate) async fn upgrade_composefs(
382420 return Ok ( ( ) ) ;
383421 }
384422
385- do_upgrade ( storage, & host, booted_imgref, & img_config) . await ?;
386-
387- if opts. apply {
388- return crate :: reboot:: reboot ( ) ;
389- }
423+ do_upgrade (
424+ storage,
425+ composefs,
426+ & host,
427+ booted_imgref,
428+ & img_config,
429+ & do_upgrade_opts,
430+ )
431+ . await ?;
390432
391433 Ok ( ( ) )
392434}
0 commit comments