Skip to content

Commit

Permalink
Merge #1356
Browse files Browse the repository at this point in the history
1356: feat(pool): pool committed size r=tiagolobocastro a=dsavitskiy



Co-authored-by: Dmitry Savitskiy <[email protected]>
  • Loading branch information
mayastor-bors and dsavitskiy committed Apr 14, 2023
2 parents aebfd87 + 38f8d38 commit 3767314
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 1 deletion.
15 changes: 15 additions & 0 deletions io-engine-tests/src/pool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ pub use super::compose::rpc::v1::pool::Pool;
use super::{
compose::rpc::v1::{
pool::{CreatePoolRequest, ListPoolOptions},
replica::{ListReplicaOptions, Replica},
SharedRpcHandle,
Status,
},
Expand Down Expand Up @@ -91,6 +92,20 @@ impl PoolBuilder {
Status::new(Code::NotFound, format!("Pool '{uuid}' not found"))
})
}

pub async fn get_replicas(&self) -> Result<Vec<Replica>, Status> {
self.rpc()
.borrow_mut()
.replica
.list_replicas(ListReplicaOptions {
name: None,
poolname: None,
uuid: None,
pooluuid: self.uuid.clone(),
})
.await
.map(|r| r.into_inner().replicas)
}
}

pub async fn list_pools(rpc: SharedRpcHandle) -> Result<Vec<Pool>, Status> {
Expand Down
1 change: 1 addition & 0 deletions io-engine/src/grpc/v1/pool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ impl From<Lvs> for Pool {
state: PoolState::PoolOnline.into(),
capacity: l.capacity(),
used: l.used(),
committed: l.committed(),
pooltype: PoolType::Lvs as i32,
}
}
Expand Down
6 changes: 6 additions & 0 deletions io-engine/src/lvs/lvs_store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,12 @@ impl Lvs {
self.capacity() - self.available()
}

/// returns committed size
pub fn committed(&self) -> u64 {
self.lvols()
.map_or(0, |vols| vols.fold(0, |acc, r| acc + r.size()))
}

/// returns the base bdev of this lvs
pub fn base_bdev(&self) -> UntypedBdev {
let p =
Expand Down
11 changes: 11 additions & 0 deletions io-engine/tests/nexus_thin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -127,4 +127,15 @@ async fn nexus_thin_create_2() {
.with_replica(&t.repl_1_thin);

nex_0.create().await.unwrap();

// Check pool committed size.
let total_capacity = t
.pool_0
.get_replicas()
.await
.unwrap()
.into_iter()
.fold(0, |acc, r| acc + r.size);
let p = t.pool_0.get_pool().await.unwrap();
assert_eq!(p.committed, total_capacity);
}
2 changes: 1 addition & 1 deletion rpc/mayastor-api

0 comments on commit 3767314

Please sign in to comment.