33//
44// SPDX-License-Identifier: MPL-2.0
55
6- use std:: collections:: HashMap ;
6+ use std:: { collections:: HashMap , path :: PathBuf } ;
77
88use disks:: BlockDevice ;
99use log:: { debug, info, trace, warn} ;
1010use partitioning:: {
1111 planner:: { Planner , PARTITION_ALIGNMENT } ,
1212 strategy:: { AllocationStrategy , PartitionRequest , SizeRequirement , Strategy } ,
1313} ;
14+ use types:: { Filesystem , PartitionRole } ;
1415
1516use crate :: { commands:: Command , Constraints , StrategyDefinition } ;
1617
@@ -27,6 +28,12 @@ pub struct Provisioner {
2728pub struct Plan < ' a > {
2829 pub strategy : & ' a StrategyDefinition ,
2930 pub device_assignments : HashMap < String , DevicePlan < ' a > > ,
31+
32+ // Global mount points
33+ pub role_mounts : HashMap < PartitionRole , PathBuf > ,
34+
35+ // Filesystems to be formatted
36+ pub filesystems : HashMap < PathBuf , Filesystem > ,
3037}
3138
3239#[ derive( Debug , Clone ) ]
@@ -172,18 +179,36 @@ impl Provisioner {
172179 }
173180 }
174181
182+ let mut role_mounts = HashMap :: new ( ) ;
183+ let mut filesystems = HashMap :: new ( ) ;
184+
175185 // OK lets now apply any mutations to the device assignments
176186 for ( disk_name, device_plan) in device_assignments. iter_mut ( ) {
177187 debug ! ( "Applying device plan for disk {}" , disk_name) ;
178188 if let Err ( e) = device_plan. strategy . apply ( & mut device_plan. planner ) {
179189 warn ! ( "Failed to apply strategy for disk {}: {:?}" , disk_name, e) ;
180190 }
191+ for region in device_plan. planner . current_layout ( ) . iter ( ) {
192+ if let Some ( id) = region. partition_id {
193+ let device_path = device_plan. device . partition_path ( id as usize ) ;
194+ if let Some ( attributes) = region. attributes . as_ref ( ) {
195+ if let Some ( role) = attributes. role . as_ref ( ) {
196+ role_mounts. insert ( role. clone ( ) , device_path. clone ( ) ) ;
197+ }
198+ if let Some ( fs) = attributes. filesystem . as_ref ( ) {
199+ filesystems. insert ( device_path, fs. clone ( ) ) ;
200+ }
201+ }
202+ }
203+ }
181204 }
182205
183206 // All commands processed successfully - create a plan
184207 debug ! ( "Creating final plan for strategy {}" , strategy. name) ;
185208 plans. push ( Plan {
186209 strategy,
210+ role_mounts,
211+ filesystems,
187212 device_assignments : device_assignments. clone ( ) ,
188213 } ) ;
189214 }
0 commit comments