@@ -827,15 +827,15 @@ fn soft_reboot_staged(sysroot: &SysrootLock) -> Result<()> {
827827
828828/// Perform a soft reboot for a rollback deployment
829829#[ context( "Soft reboot rollback deployment" ) ]
830- fn soft_reboot_rollback ( sysroot : & SysrootLock ) -> Result < ( ) > {
830+ fn soft_reboot_rollback ( booted_ostree : & BootedOstree < ' _ > ) -> Result < ( ) > {
831831 println ! ( "Rollback deployment is soft-reboot capable, preparing for soft-reboot..." ) ;
832832
833- let deployments_list = sysroot. deployments ( ) ;
833+ let deployments_list = booted_ostree . sysroot . deployments ( ) ;
834834 let target_deployment = deployments_list
835835 . first ( )
836836 . ok_or_else ( || anyhow:: anyhow!( "No rollback deployment found!" ) ) ?;
837837
838- prepare_soft_reboot ( sysroot, target_deployment)
838+ prepare_soft_reboot ( booted_ostree . sysroot , target_deployment)
839839}
840840
841841/// A few process changes that need to be made for writing.
@@ -1005,34 +1005,19 @@ pub(crate) fn imgref_for_switch(opts: &SwitchOpts) -> Result<ImageReference> {
10051005 return Ok ( target) ;
10061006}
10071007
1008- /// Implementation of the `bootc switch` CLI command.
1009- #[ context( "Switching" ) ]
1010- async fn switch ( opts : SwitchOpts ) -> Result < ( ) > {
1008+ /// Implementation of the `bootc switch` CLI command for ostree backend.
1009+ #[ context( "Switching (ostree)" ) ]
1010+ async fn switch_ostree (
1011+ opts : SwitchOpts ,
1012+ storage : & Storage ,
1013+ booted_ostree : & BootedOstree < ' _ > ,
1014+ ) -> Result < ( ) > {
10111015 let target = imgref_for_switch ( & opts) ?;
1012-
10131016 let prog: ProgressWriter = opts. progress . try_into ( ) ?;
1014-
1015- // If we're doing an in-place mutation, we shortcut most of the rest of the work here
1016- if opts. mutate_in_place {
1017- let deployid = {
1018- // Clone to pass into helper thread
1019- let target = target. clone ( ) ;
1020- let root = cap_std:: fs:: Dir :: open_ambient_dir ( "/" , cap_std:: ambient_authority ( ) ) ?;
1021- tokio:: task:: spawn_blocking ( move || {
1022- crate :: deploy:: switch_origin_inplace ( & root, & target)
1023- } )
1024- . await ??
1025- } ;
1026- println ! ( "Updated {deployid} to pull from {target}" ) ;
1027- return Ok ( ( ) ) ;
1028- }
1029-
10301017 let cancellable = gio:: Cancellable :: NONE ;
10311018
1032- let storage = & get_storage ( ) . await ?;
1033- let ostree = storage. get_ostree ( ) ?;
1034- let repo = & ostree. repo ( ) ;
1035- let ( booted_deployment, _deployments, host) = crate :: status:: get_status_require_booted ( ostree) ?;
1019+ let repo = & booted_ostree. repo ( ) ;
1020+ let ( _, host) = crate :: status:: get_status ( booted_ostree) ?;
10361021
10371022 let new_spec = {
10381023 let mut new_spec = host. spec . clone ( ) ;
@@ -1070,7 +1055,7 @@ async fn switch(opts: SwitchOpts) -> Result<()> {
10701055
10711056 if !opts. retain {
10721057 // By default, we prune the previous ostree ref so it will go away after later upgrades
1073- if let Some ( booted_origin) = booted_deployment . origin ( ) {
1058+ if let Some ( booted_origin) = booted_ostree . deployment . origin ( ) {
10741059 if let Some ( ostree_ref) = booted_origin. optional_string ( "origin" , "refspec" ) ? {
10751060 let ( remote, ostree_ref) =
10761061 ostree:: parse_refspec ( & ostree_ref) . context ( "Failed to parse ostree ref" ) ?;
@@ -1079,7 +1064,7 @@ async fn switch(opts: SwitchOpts) -> Result<()> {
10791064 }
10801065 }
10811066
1082- let stateroot = booted_deployment . osname ( ) ;
1067+ let stateroot = booted_ostree . stateroot ( ) ;
10831068 let from = MergeState :: from_stateroot ( storage, & stateroot) ?;
10841069 crate :: deploy:: stage ( storage, from, & fetched, & new_spec, prog. clone ( ) ) . await ?;
10851070
@@ -1088,12 +1073,8 @@ async fn switch(opts: SwitchOpts) -> Result<()> {
10881073 if opts. soft_reboot . is_some ( ) {
10891074 // At this point we have staged the deployment and the host definition has changed.
10901075 // We need the updated host status before we check if we can prepare the soft-reboot.
1091- let booted_ostree = BootedOstree {
1092- sysroot : ostree,
1093- deployment : booted_deployment. clone ( ) ,
1094- } ;
1095- let updated_host = crate :: status:: get_status ( & booted_ostree) ?. 1 ;
1096- handle_staged_soft_reboot ( & booted_ostree, opts. soft_reboot , & updated_host) ?;
1076+ let updated_host = crate :: status:: get_status ( booted_ostree) ?. 1 ;
1077+ handle_staged_soft_reboot ( booted_ostree, opts. soft_reboot , & updated_host) ?;
10971078 }
10981079
10991080 if opts. apply {
@@ -1103,36 +1084,85 @@ async fn switch(opts: SwitchOpts) -> Result<()> {
11031084 Ok ( ( ) )
11041085}
11051086
1106- /// Implementation of the `bootc rollback ` CLI command.
1107- #[ context( "Rollback " ) ]
1108- async fn rollback ( opts : & RollbackOpts ) -> Result < ( ) > {
1087+ /// Implementation of the `bootc switch ` CLI command.
1088+ #[ context( "Switching " ) ]
1089+ async fn switch ( opts : SwitchOpts ) -> Result < ( ) > {
11091090 let storage = & get_storage ( ) . await ?;
1110- let ostree = storage. get_ostree ( ) ?;
1091+ match storage. kind ( ) ? {
1092+ BootedStorageKind :: Ostree ( booted_ostree) => {
1093+ // If we're doing an in-place mutation, we shortcut most of the rest of the work here
1094+ if opts. mutate_in_place {
1095+ let target = imgref_for_switch ( & opts) ?;
1096+ let deployid = {
1097+ // Clone to pass into helper thread
1098+ let target = target. clone ( ) ;
1099+ let root =
1100+ cap_std:: fs:: Dir :: open_ambient_dir ( "/" , cap_std:: ambient_authority ( ) ) ?;
1101+ tokio:: task:: spawn_blocking ( move || {
1102+ crate :: deploy:: switch_origin_inplace ( & root, & target)
1103+ } )
1104+ . await ??
1105+ } ;
1106+ println ! ( "Updated {deployid} to pull from {target}" ) ;
1107+ return Ok ( ( ) ) ;
1108+ }
1109+ switch_ostree ( opts, storage, & booted_ostree) . await
1110+ }
1111+ BootedStorageKind :: Composefs ( _) => {
1112+ if opts. mutate_in_place {
1113+ anyhow:: bail!( "--mutate-in-place is not yet supported for composefs backend" ) ;
1114+ }
1115+ switch_composefs ( opts) . await
1116+ }
1117+ }
1118+ }
1119+
1120+ /// Implementation of the `bootc rollback` CLI command for ostree backend.
1121+ #[ context( "Rollback (ostree)" ) ]
1122+ async fn rollback_ostree (
1123+ opts : & RollbackOpts ,
1124+ storage : & Storage ,
1125+ booted_ostree : & BootedOstree < ' _ > ,
1126+ ) -> Result < ( ) > {
11111127 crate :: deploy:: rollback ( storage) . await ?;
11121128
11131129 if opts. soft_reboot . is_some ( ) {
11141130 // Get status of rollback deployment to check soft-reboot capability
1115- let host = crate :: status:: get_status_require_booted ( ostree ) ?. 2 ;
1131+ let host = crate :: status:: get_status ( booted_ostree ) ?. 1 ;
11161132
11171133 handle_soft_reboot (
11181134 opts. soft_reboot ,
11191135 host. status . rollback . as_ref ( ) ,
11201136 "rollback" ,
1121- || soft_reboot_rollback ( ostree ) ,
1137+ || soft_reboot_rollback ( booted_ostree ) ,
11221138 ) ?;
11231139 }
11241140
11251141 Ok ( ( ) )
11261142}
11271143
1128- /// Implementation of the `bootc edit ` CLI command.
1129- #[ context( "Editing spec " ) ]
1130- async fn edit ( opts : EditOpts ) -> Result < ( ) > {
1144+ /// Implementation of the `bootc rollback ` CLI command.
1145+ #[ context( "Rollback " ) ]
1146+ async fn rollback ( opts : & RollbackOpts ) -> Result < ( ) > {
11311147 let storage = & get_storage ( ) . await ?;
1132- let ostree = storage. get_ostree ( ) ?;
1133- let repo = & ostree. repo ( ) ;
1148+ match storage. kind ( ) ? {
1149+ BootedStorageKind :: Ostree ( booted_ostree) => {
1150+ rollback_ostree ( opts, storage, & booted_ostree) . await
1151+ }
1152+ BootedStorageKind :: Composefs ( _) => composefs_rollback ( ) . await ,
1153+ }
1154+ }
1155+
1156+ /// Implementation of the `bootc edit` CLI command for ostree backend.
1157+ #[ context( "Editing spec (ostree)" ) ]
1158+ async fn edit_ostree (
1159+ opts : EditOpts ,
1160+ storage : & Storage ,
1161+ booted_ostree : & BootedOstree < ' _ > ,
1162+ ) -> Result < ( ) > {
1163+ let repo = & booted_ostree. repo ( ) ;
1164+ let ( _, host) = crate :: status:: get_status ( booted_ostree) ?;
11341165
1135- let ( booted_deployment, _deployments, host) = crate :: status:: get_status_require_booted ( ostree) ?;
11361166 let new_host: Host = if let Some ( filename) = opts. filename {
11371167 let mut r = std:: io:: BufReader :: new ( std:: fs:: File :: open ( filename) ?) ;
11381168 serde_yaml:: from_reader ( & mut r) ?
@@ -1163,7 +1193,7 @@ async fn edit(opts: EditOpts) -> Result<()> {
11631193
11641194 // TODO gc old layers here
11651195
1166- let stateroot = booted_deployment . osname ( ) ;
1196+ let stateroot = booted_ostree . stateroot ( ) ;
11671197 let from = MergeState :: from_stateroot ( storage, & stateroot) ?;
11681198 crate :: deploy:: stage ( storage, from, & fetched, & new_spec, prog. clone ( ) ) . await ?;
11691199
@@ -1172,6 +1202,20 @@ async fn edit(opts: EditOpts) -> Result<()> {
11721202 Ok ( ( ) )
11731203}
11741204
1205+ /// Implementation of the `bootc edit` CLI command.
1206+ #[ context( "Editing spec" ) ]
1207+ async fn edit ( opts : EditOpts ) -> Result < ( ) > {
1208+ let storage = & get_storage ( ) . await ?;
1209+ match storage. kind ( ) ? {
1210+ BootedStorageKind :: Ostree ( booted_ostree) => {
1211+ edit_ostree ( opts, storage, & booted_ostree) . await
1212+ }
1213+ BootedStorageKind :: Composefs ( _) => {
1214+ anyhow:: bail!( "Edit is not yet supported for composefs backend" )
1215+ }
1216+ }
1217+ }
1218+
11751219/// Implementation of `bootc usroverlay`
11761220async fn usroverlay ( ) -> Result < ( ) > {
11771221 // This is just a pass-through today. At some point we may make this a libostree API
@@ -1277,24 +1321,12 @@ async fn run_from_opt(opt: Opt) -> Result<()> {
12771321 }
12781322 }
12791323 }
1280- Opt :: Switch ( opts) => {
1281- let storage = & get_storage ( ) . await ?;
1282- match storage. kind ( ) ? {
1283- BootedStorageKind :: Ostree ( _) => switch ( opts) . await ,
1284- BootedStorageKind :: Composefs ( _) => switch_composefs ( opts) . await ,
1285- }
1286- }
1324+ Opt :: Switch ( opts) => switch ( opts) . await ,
12871325 Opt :: Rollback ( opts) => {
1288- let storage = & get_storage ( ) . await ?;
1289- match storage. kind ( ) ? {
1290- BootedStorageKind :: Ostree ( _) => rollback ( & opts) . await ?,
1291- BootedStorageKind :: Composefs ( _) => composefs_rollback ( ) . await ?,
1292- }
1293-
1326+ rollback ( & opts) . await ?;
12941327 if opts. apply {
12951328 crate :: reboot:: reboot ( ) ?;
12961329 }
1297-
12981330 Ok ( ( ) )
12991331 }
13001332 Opt :: Edit ( opts) => edit ( opts) . await ,
0 commit comments