Skip to content

Commit a3240b1

Browse files
committed
Add Engine interface for read_all_available and write_all_available
1 parent befbfac commit a3240b1

File tree

4 files changed

+47
-7
lines changed

4 files changed

+47
-7
lines changed

src/engine/engine.rs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,10 @@ use devicemapper::{Bytes, Sectors};
1919

2020
use crate::{
2121
engine::{
22-
structures::{AllLockReadGuard, AllLockWriteGuard, SomeLockReadGuard, SomeLockWriteGuard},
22+
structures::{
23+
AllLockReadAvailableGuard, AllLockReadGuard, AllLockWriteAvailableGuard,
24+
AllLockWriteGuard, SomeLockReadGuard, SomeLockWriteGuard,
25+
},
2326
types::{
2427
ActionAvailability, BlockDevTier, Clevis, CreateAction, DeleteAction, DevUuid,
2528
EncryptionInfo, FilesystemUuid, GrowAction, InputEncryptionInfo, IntegritySpec, Key,
@@ -506,9 +509,17 @@ pub trait Engine: Debug + Report + Send + Sync {
506509
/// Get all pools belonging to this engine.
507510
async fn pools(&self) -> AllLockReadGuard<PoolUuid, dyn Pool>;
508511

512+
/// Get all pools belonging to this engine that are currently available and will not block on
513+
/// locking.
514+
async fn available_pools(&self) -> Option<AllLockReadAvailableGuard<PoolUuid, dyn Pool>>;
515+
509516
/// Get mutable references to all pools belonging to this engine.
510517
async fn pools_mut(&self) -> AllLockWriteGuard<PoolUuid, dyn Pool>;
511518

519+
/// Get mutable references to all pools belonging to this engine that are currently available
520+
/// and will not block on locking.
521+
async fn available_pools_mut(&self) -> Option<AllLockWriteAvailableGuard<PoolUuid, dyn Pool>>;
522+
512523
/// Get the UUIDs of all pools that experienced an event.
513524
async fn get_events(&self) -> StratisResult<HashSet<PoolUuid>>;
514525

src/engine/sim_engine/engine.rs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,9 @@ use crate::{
2020
shared::{create_pool_idempotent_or_err, validate_name, validate_paths},
2121
sim_engine::{keys::SimKeyActions, pool::SimPool},
2222
structures::{
23-
AllLockReadGuard, AllLockWriteGuard, AllOrSomeLock, Lockable, SomeLockReadGuard,
24-
SomeLockWriteGuard, Table,
23+
AllLockReadAvailableGuard, AllLockReadGuard, AllLockWriteAvailableGuard,
24+
AllLockWriteGuard, AllOrSomeLock, Lockable, SomeLockReadGuard, SomeLockWriteGuard,
25+
Table,
2526
},
2627
types::{
2728
CreateAction, DeleteAction, DevUuid, EncryptionInfo, Features, FilesystemUuid,
@@ -301,10 +302,18 @@ impl Engine for SimEngine {
301302
self.pools.read_all().await.into_dyn()
302303
}
303304

305+
async fn available_pools(&self) -> Option<AllLockReadAvailableGuard<PoolUuid, dyn Pool>> {
306+
self.pools.read_all_available().await.map(|l| l.into_dyn())
307+
}
308+
304309
async fn pools_mut(&self) -> AllLockWriteGuard<PoolUuid, dyn Pool> {
305310
self.pools.write_all().await.into_dyn()
306311
}
307312

313+
async fn available_pools_mut(&self) -> Option<AllLockWriteAvailableGuard<PoolUuid, dyn Pool>> {
314+
self.pools.write_all_available().await.map(|l| l.into_dyn())
315+
}
316+
308317
async fn get_events(&self) -> StratisResult<HashSet<PoolUuid>> {
309318
Ok(HashSet::new())
310319
}

src/engine/strat_engine/engine.rs

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,9 @@ use crate::{
3434
pool::{v1, v2, AnyPool},
3535
},
3636
structures::{
37-
AllLockReadGuard, AllLockWriteGuard, AllOrSomeLock, Lockable, SomeLockReadGuard,
38-
SomeLockWriteGuard, Table,
37+
AllLockReadAvailableGuard, AllLockReadGuard, AllLockWriteAvailableGuard,
38+
AllLockWriteGuard, AllOrSomeLock, Lockable, SomeLockReadGuard, SomeLockWriteGuard,
39+
Table,
3940
},
4041
types::{
4142
CreateAction, DeleteAction, DevUuid, FilesystemUuid, InputEncryptionInfo,
@@ -202,10 +203,20 @@ impl StratEngine {
202203
self.pools.read_all().await
203204
}
204205

206+
pub async fn available_pools(&self) -> Option<AllLockReadAvailableGuard<PoolUuid, AnyPool>> {
207+
self.pools.read_all_available().await
208+
}
209+
205210
pub async fn pools_mut(&self) -> AllLockWriteGuard<PoolUuid, AnyPool> {
206211
self.pools.write_all().await
207212
}
208213

214+
pub async fn available_pools_mut(
215+
&self,
216+
) -> Option<AllLockWriteAvailableGuard<PoolUuid, AnyPool>> {
217+
self.pools.write_all_available().await
218+
}
219+
209220
fn spawn_pool_check_handling(
210221
joins: &mut PoolJoinHandles,
211222
mut guard: SomeLockWriteGuard<PoolUuid, AnyPool>,
@@ -720,10 +731,18 @@ impl Engine for StratEngine {
720731
self.pools().await.into_dyn()
721732
}
722733

734+
async fn available_pools(&self) -> Option<AllLockReadAvailableGuard<PoolUuid, dyn Pool>> {
735+
self.available_pools().await.map(|l| l.into_dyn())
736+
}
737+
723738
async fn pools_mut(&self) -> AllLockWriteGuard<PoolUuid, dyn Pool> {
724739
self.pools_mut().await.into_dyn()
725740
}
726741

742+
async fn available_pools_mut(&self) -> Option<AllLockWriteAvailableGuard<PoolUuid, dyn Pool>> {
743+
self.available_pools_mut().await.map(|l| l.into_dyn())
744+
}
745+
727746
async fn get_events(&self) -> StratisResult<HashSet<PoolUuid>> {
728747
let device_list: HashMap<_, _> = get_dm()
729748
.list_devices()?

src/engine/structures/mod.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,9 @@ mod table;
77

88
pub use self::{
99
lock::{
10-
AllLockReadGuard, AllLockWriteGuard, AllOrSomeLock, ExclusiveGuard, Lockable, SharedGuard,
11-
SomeLockReadGuard, SomeLockWriteGuard,
10+
AllLockReadAvailableGuard, AllLockReadGuard, AllLockWriteAvailableGuard, AllLockWriteGuard,
11+
AllOrSomeLock, ExclusiveGuard, Lockable, SharedGuard, SomeLockReadGuard,
12+
SomeLockWriteGuard,
1213
},
1314
table::Table,
1415
};

0 commit comments

Comments
 (0)