Skip to content

Commit 507599e

Browse files
committed
provisioning: Expose the roles/filesystems for mounts + formatting
Signed-off-by: Ikey Doherty <[email protected]>
1 parent d77144a commit 507599e

File tree

15 files changed

+87
-22
lines changed

15 files changed

+87
-22
lines changed

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/disktester/src/main.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,14 @@ fn apply_partitioning(whence: &Path) -> Result<(), Box<dyn std::error::Error>> {
5858
disk_writer.write()?;
5959
}
6060

61+
for (device, fs) in plan.filesystems.iter() {
62+
eprintln!("To format: {:?} with {:?}", device, fs);
63+
}
64+
65+
for (role, device) in plan.role_mounts.iter() {
66+
eprintln!("To mount: {:?} as {:?} (`{}`)", device, role, role.as_path());
67+
}
68+
6169
Ok(())
6270
}
6371

crates/partitioning/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ description = "A library for working directly with partitions"
66

77
[dependencies]
88
disks = { path = "../disks" }
9+
types = { path = "../types" }
910
thiserror.workspace = true
1011
log.workspace = true
1112
gpt.workspace = true

crates/partitioning/src/attributes.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
// SPDX-License-Identifier: MPL-2.0
44

55
use gpt::partition_types;
6+
use types::{Filesystem, PartitionRole};
67
use uuid::Uuid;
78

89
/// Represents the table attributes of a GPT partition
@@ -51,4 +52,6 @@ impl TableAttributes {
5152
#[derive(Debug, Clone)]
5253
pub struct PartitionAttributes {
5354
pub table: TableAttributes,
55+
pub role: Option<PartitionRole>,
56+
pub filesystem: Option<Filesystem>,
5457
}

crates/partitioning/src/planner.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,8 @@ pub struct Region {
9292

9393
/// The partition ID of this region if it represents a partition
9494
pub partition_id: Option<u32>,
95+
96+
pub attributes: Option<PartitionAttributes>,
9597
}
9698

9799
/// partitions aligned to 1MiB boundaries. This helps ensure optimal
@@ -109,6 +111,7 @@ impl Region {
109111
start,
110112
end,
111113
partition_id: None,
114+
attributes: None,
112115
}
113116
}
114117

@@ -319,14 +322,15 @@ impl Planner {
319322
start,
320323
end,
321324
partition_id,
322-
..
325+
attributes,
323326
} = change
324327
{
325328
debug!("Adding partition {}..{} (ID: {})", start, end, partition_id);
326329
layout.push(Region {
327330
start: *start,
328331
end: *end,
329332
partition_id: Some(*partition_id),
333+
attributes: attributes.clone(),
330334
});
331335
}
332336
}

crates/provisioning/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ miette = { workspace = true, features = ["fancy"] }
99
[dependencies]
1010
disks = { path = "../disks" }
1111
partitioning = { path = "../partitioning" }
12+
types = { path = "../types" }
1213
kdl = { workspace = true, features = ["span"] }
1314
miette = { workspace = true }
1415
itertools = { workspace = true }

crates/provisioning/src/commands/create_partition.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ impl Command {
4343
name: self.partition_type.as_ref().map(|p| p.to_string()),
4444
uuid: None,
4545
}),
46+
role: self.role.clone(),
47+
filesystem: self.filesystem.clone(),
4648
}
4749
}
4850
}

crates/provisioning/src/lib.rs

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,18 +11,11 @@ use miette::{Diagnostic, NamedSource, Severity};
1111
mod provisioner;
1212
pub use provisioner::*;
1313

14-
mod errors;
15-
pub use errors::*;
16-
17-
mod helpers;
18-
use helpers::*;
19-
20-
mod types;
21-
pub use types::*;
22-
2314
mod commands;
2415
use commands::*;
2516

17+
pub use types::*;
18+
2619
/// Command evaluation context
2720
pub struct Context<'a> {
2821
/// The node being parsed

crates/provisioning/src/provisioner.rs

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,15 @@
33
//
44
// SPDX-License-Identifier: MPL-2.0
55

6-
use std::collections::HashMap;
6+
use std::{collections::HashMap, path::PathBuf};
77

88
use disks::BlockDevice;
99
use log::{debug, info, trace, warn};
1010
use partitioning::{
1111
planner::{Planner, PARTITION_ALIGNMENT},
1212
strategy::{AllocationStrategy, PartitionRequest, SizeRequirement, Strategy},
1313
};
14+
use types::{Filesystem, PartitionRole};
1415

1516
use crate::{commands::Command, Constraints, StrategyDefinition};
1617

@@ -27,6 +28,12 @@ pub struct Provisioner {
2728
pub 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
}

crates/types/Cargo.toml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
[package]
2+
name = "types"
3+
version = "0.1.0"
4+
edition = "2021"
5+
6+
[dependencies]
7+
kdl.workspace = true
8+
thiserror.workspace = true
9+
miette.workspace = true
10+
gpt.workspace = true
11+
uuid.workspace = true

0 commit comments

Comments
 (0)