Skip to content

Commit 8407c80

Browse files
mayastor-borsabhilashshetty04
andcommitted
Merge #1903
1903: proto changes for pool expansion r=abhilashshetty04 a=abhilashshetty04 Co-authored-by: Abhilash Shetty <[email protected]>
2 parents c2efa24 + 97a2e29 commit 8407c80

File tree

12 files changed

+142
-77
lines changed

12 files changed

+142
-77
lines changed

io-engine-tests/src/pool.rs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -212,20 +212,17 @@ impl PoolBuilderRpc {
212212
.map(|r| r.into_inner())
213213
}
214214

215-
pub async fn grow(&mut self) -> Result<(Pool, Pool), Status> {
215+
pub async fn grow(&mut self) -> Result<Pool, Status> {
216216
self.rpc()
217217
.lock()
218218
.await
219219
.pool
220-
.grow_pool(GrowPoolRequest {
220+
.grow_pool_v2(GrowPoolRequest {
221221
name: self.name(),
222222
uuid: Some(self.uuid()),
223223
})
224224
.await
225-
.map(|r| {
226-
let t = r.into_inner();
227-
(t.previous_pool.unwrap(), t.current_pool.unwrap())
228-
})
225+
.map(|r| (r.into_inner()))
229226
}
230227

231228
pub async fn get_pool(&self) -> Result<Pool, Status> {

io-engine/examples/lvs-eval/main.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ pub struct CliArgs {
3333
pub thin: bool,
3434
/// MD reservation ratio.
3535
#[clap(short = 'M')]
36-
pub md_resv_ratio: Option<f32>,
36+
pub max_expansion: Option<String>,
3737
/// Use extent table.
3838
#[clap(short = 'E')]
3939
pub use_extent_table: Option<bool>,
@@ -133,7 +133,7 @@ async fn create_lvs(args: &CliArgs) -> Lvs {
133133
uuid: Some(POOL_UUID.to_string()),
134134
cluster_size: args.cluster_size.map(|sz| sz * 1024 * 1024),
135135
md_args: Some(PoolMetadataArgs {
136-
md_resv_ratio: args.md_resv_ratio,
136+
max_expansion: args.max_expansion.clone(),
137137
}),
138138
backend: Default::default(),
139139
enc_key: None,

io-engine/src/bin/io-engine-client/v1/pool_cli.rs

Lines changed: 54 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,10 @@ pub fn subcommands() -> Command {
3434
.help("SPDK cluster size"),
3535
)
3636
.arg(
37-
Arg::new("md-resv-ratio")
38-
.long("md-resv-ratio")
37+
Arg::new("max-expansion")
38+
.long("max-expansion")
3939
.required(false)
40-
.help("Metadata reservation ratio"),
40+
.help("Max expected expansion in factor or absolute size"),
4141
)
4242
.arg(
4343
Arg::new("disk")
@@ -184,8 +184,8 @@ pub fn subcommands() -> Command {
184184
.default_value(PoolType::Lvs.as_ref()),
185185
);
186186

187-
let grow = Command::new("grow")
188-
.about("Grow a storage pool to fill the entire underlying device")
187+
let expand = Command::new("expand")
188+
.about("Expand a storage pool to span the entire underlying device")
189189
.arg(
190190
Arg::new("name")
191191
.required(true)
@@ -230,7 +230,7 @@ pub fn subcommands() -> Command {
230230
.subcommand(import)
231231
.subcommand(destroy)
232232
.subcommand(export)
233-
.subcommand(grow)
233+
.subcommand(expand)
234234
.subcommand(list)
235235
}
236236

@@ -240,7 +240,7 @@ pub async fn handler(ctx: Context, matches: &ArgMatches) -> crate::Result<()> {
240240
("import", args) => import(ctx, args).await,
241241
("destroy", args) => destroy(ctx, args).await,
242242
("export", args) => export(ctx, args).await,
243-
("grow", args) => grow(ctx, args).await,
243+
("expand", args) => expand(ctx, args).await,
244244
("list", args) => list(ctx, args).await,
245245
(cmd, _) => {
246246
Err(Status::not_found(format!("command {cmd} does not exist"))).context(GrpcStatus)
@@ -297,8 +297,8 @@ async fn create(mut ctx: Context, matches: &ArgMatches) -> crate::Result<()> {
297297
None => None,
298298
};
299299

300-
let md_resv_ratio = match matches.get_one::<String>("md-resv-ratio") {
301-
Some(s) => match s.parse::<f32>() {
300+
let max_expansion = match matches.get_one::<String>("max-expansion") {
301+
Some(s) => match s.parse::<String>() {
302302
Ok(v) => Some(v),
303303
Err(err) => {
304304
return Err(Status::invalid_argument(format!(
@@ -336,7 +336,10 @@ async fn create(mut ctx: Context, matches: &ArgMatches) -> crate::Result<()> {
336336
disks: disks_list,
337337
pooltype: v1rpc::pool::PoolType::from(pooltype) as i32,
338338
cluster_size,
339-
md_args: Some(v1rpc::pool::PoolMetadataArgs { md_resv_ratio }),
339+
md_args: Some(v1rpc::pool::PoolMetadataArgs {
340+
md_resv_ratio: None,
341+
max_expansion,
342+
}),
340343
encryption: enc_msg,
341344
})
342345
.await
@@ -537,7 +540,7 @@ async fn export(mut ctx: Context, matches: &ArgMatches) -> crate::Result<()> {
537540
Ok(())
538541
}
539542

540-
async fn grow(mut ctx: Context, matches: &ArgMatches) -> crate::Result<()> {
543+
async fn expand(mut ctx: Context, matches: &ArgMatches) -> crate::Result<()> {
541544
let name = matches
542545
.get_one::<String>("name")
543546
.ok_or_else(|| ClientError::MissingValue {
@@ -546,24 +549,55 @@ async fn grow(mut ctx: Context, matches: &ArgMatches) -> crate::Result<()> {
546549
.to_owned();
547550
let uuid = matches.get_one::<String>("uuid").cloned();
548551

549-
let response = ctx
552+
let pooltype = matches
553+
.get_one::<String>("type")
554+
.map(|s| PoolType::from_str(s.as_str()))
555+
.transpose()
556+
.map_err(|e| Status::invalid_argument(e.to_string()))
557+
.context(GrpcStatus)?;
558+
559+
let list_response = ctx
560+
.v1
561+
.pool
562+
.list_pools(v1rpc::pool::ListPoolOptions {
563+
name: Some(name.clone()),
564+
pooltype: pooltype.map(|pooltype| v1rpc::pool::PoolTypeValue {
565+
value: v1rpc::pool::PoolType::from(pooltype) as i32,
566+
}),
567+
uuid: None,
568+
})
569+
.await
570+
.context(GrpcStatus)?;
571+
572+
if list_response.get_ref().pools.is_empty() {
573+
return Err(ClientError::GrpcStatus {
574+
source: Status::not_found(format!("Pool {name} not found")),
575+
backtrace: None,
576+
});
577+
}
578+
579+
let pool = &list_response.get_ref().pools[0];
580+
let previous_capacity = pool.capacity;
581+
582+
let grow_response = ctx
550583
.v1
551584
.pool
552-
.grow_pool(v1rpc::pool::GrowPoolRequest {
585+
.grow_pool_v2(v1rpc::pool::GrowPoolRequest {
553586
name: name.clone(),
554587
uuid,
555588
})
556589
.await
557590
.context(GrpcStatus)?;
558591

559-
let old_cap = response.get_ref().previous_pool.as_ref().unwrap().capacity;
560-
let new_cap = response.get_ref().current_pool.as_ref().unwrap().capacity;
592+
let pool = &grow_response.get_ref();
593+
let current_capacity = pool.capacity;
561594

562-
if old_cap == new_cap {
563-
println!("Pool capacity did not change: {new_cap} bytes");
564-
} else {
565-
println!("Pool capacity was {old_cap}, now {new_cap} bytes");
566-
}
595+
match ctx.output {
596+
OutputFormat::Json => {}
597+
OutputFormat::Default => {
598+
println!("pool expanded from {previous_capacity} to {current_capacity}");
599+
}
600+
};
567601

568602
Ok(())
569603
}

io-engine/src/grpc/v0/mayastor_grpc.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,7 @@ impl From<LvsError> for tonic::Status {
250250
LvsError::SetProperty { .. } => Status::data_loss(e.to_string()),
251251
LvsError::WipeFailed { source } => source.into(),
252252
LvsError::ResourceLockFailed { .. } => Status::aborted(e.to_string()),
253+
LvsError::MaxExpansionParse { .. } => Status::invalid_argument(e.to_string()),
253254
_ => Status::internal(e.verbose()),
254255
}
255256
}

io-engine/src/grpc/v1/pool.rs

Lines changed: 12 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ use std::{
2424
ops::Deref,
2525
panic::AssertUnwindSafe,
2626
};
27-
use tonic::{Request, Status};
27+
use tonic::{Code, Request, Status};
2828

2929
pub type PoolCreateEncryptionParams = create_pool_request::Encryption;
3030
pub type PoolImportEncryptionParams = import_pool_request::Encryption;
@@ -260,7 +260,7 @@ impl TryFrom<CreatePoolRequest> for PoolArgs {
260260
impl From<PoolMetadataArgs> for pool_backend::PoolMetadataArgs {
261261
fn from(params: PoolMetadataArgs) -> Self {
262262
Self {
263-
md_resv_ratio: params.md_resv_ratio,
263+
max_expansion: params.max_expansion,
264264
}
265265
}
266266
}
@@ -448,6 +448,7 @@ impl From<&dyn PoolOps> for Pool {
448448
disk_capacity: value.disk_capacity(),
449449
md_info: value.md_props().map(|md| md.into()),
450450
encrypted: Some(value.encrypted()),
451+
max_expandable_size: value.max_expandable_size(),
451452
}
452453
}
453454
}
@@ -709,39 +710,26 @@ impl PoolRpc for PoolService {
709710
.await
710711
}
711712

713+
async fn grow_pool(&self, _request: Request<GrowPoolRequest>) -> GrpcResult<GrowPoolResponse> {
714+
Err(Status::new(
715+
Code::Unimplemented,
716+
"grow_pool is deprecated. Please use grow_pool_v2",
717+
))
718+
}
719+
712720
#[named]
713-
async fn grow_pool(&self, request: Request<GrowPoolRequest>) -> GrpcResult<GrowPoolResponse> {
721+
async fn grow_pool_v2(&self, request: Request<GrowPoolRequest>) -> GrpcResult<Pool> {
714722
self.locked(
715723
GrpcClientContext::new(&request, function_name!()),
716724
async move {
717725
crate::spdk_submit!(async move {
718726
info!("{:?}", request.get_ref());
719727

720728
let pool = GrpcPoolFactory::finder(request.into_inner()).await?;
721-
722-
let previous_pool = Pool::from(pool.as_ops());
723729
pool.grow().await?;
724730
let current_pool = Pool::from(pool.as_ops());
725731

726-
if current_pool.capacity == previous_pool.capacity {
727-
info!(
728-
"Grow pool '{p}': capacity did not change: {sz} bytes",
729-
p = current_pool.name,
730-
sz = current_pool.capacity,
731-
);
732-
} else {
733-
info!(
734-
"Grow pool '{p}': pool capacity has changed from {a} to {b} bytes",
735-
p = current_pool.name,
736-
a = previous_pool.capacity,
737-
b = current_pool.capacity
738-
);
739-
}
740-
741-
Ok(GrowPoolResponse {
742-
previous_pool: Some(previous_pool),
743-
current_pool: Some(current_pool),
744-
})
732+
Ok(current_pool)
745733
})
746734
},
747735
)

io-engine/src/lvm/mod.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -325,6 +325,10 @@ impl IPoolProps for VolumeGroup {
325325
fn encrypted(&self) -> bool {
326326
false
327327
}
328+
329+
fn max_expandable_size(&self) -> Option<u64> {
330+
None
331+
}
328332
}
329333

330334
/// A factory instance which implements LVM specific `PoolFactory`.

io-engine/src/lvs/lvs_error.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,10 @@ pub enum LvsError {
262262
ResourceLockFailed {
263263
msg: String,
264264
},
265+
#[snafu(display("{msg}"))]
266+
MaxExpansionParse {
267+
msg: String,
268+
},
265269
}
266270

267271
/// Map CoreError to errno code.
@@ -297,6 +301,7 @@ impl ToErrno for LvsError {
297301
Self::CloneConfigFailed { .. } => Errno::EINVAL,
298302
Self::WipeFailed { .. } => Errno::EINVAL,
299303
Self::ResourceLockFailed { .. } => Errno::EBUSY,
304+
Self::MaxExpansionParse { .. } => Errno::EINVAL,
300305
}
301306
}
302307
}

0 commit comments

Comments
 (0)