Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(lvm): add support for replica operations backed by lvm volume #1011

Closed
wants to merge 8 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

46 changes: 39 additions & 7 deletions mayastor/src/bin/mayastor-client/pool_cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use byte_unit::Byte;
use clap::{App, AppSettings, Arg, ArgMatches, SubCommand};
use colored_json::ToColoredJson;
use snafu::ResultExt;
use tonic::Status;
use tonic::{Code, Status};

pub fn subcommands<'a, 'b>() -> App<'a, 'b> {
let create = SubCommand::with_name("create")
Expand All @@ -21,10 +21,18 @@ pub fn subcommands<'a, 'b>() -> App<'a, 'b> {
)
.arg(
Arg::with_name("disk")
.required(true)
.required(false)
.multiple(true)
.index(2)
.help("Disk device files"),
)
.arg(
Arg::with_name("pooltype")
.short("t")
.help("the type of the pool")
.required(false)
.possible_values(&["lvs", "lvm"])
.default_value("lvs"),
);
let destroy = SubCommand::with_name("destroy")
.about("Destroy storage pool")
Expand Down Expand Up @@ -73,17 +81,20 @@ async fn create(
.to_owned();
let disks = matches
.values_of("disk")
.ok_or_else(|| Error::MissingValue {
field: "disk".to_string(),
})?
.map(|dev| dev.to_owned())
.map(|values| values.collect::<Vec<_>>())
.unwrap_or_default()
.iter()
.map(|disk| disk.to_string())
.collect();
let pooltype =
parse_pooltype(matches.value_of("pooltype")).context(GrpcStatus)?;

let response = ctx
.client
.create_pool(rpc::CreatePoolRequest {
name: name.clone(),
disks,
pooltype,
})
.await
.context(GrpcStatus)?;
Expand Down Expand Up @@ -178,8 +189,10 @@ async fn list(
let cap = Byte::from_bytes(p.capacity.into());
let used = Byte::from_bytes(p.used.into());
let state = pool_state_to_str(p.state);
let pooltype = pooltype_to_str(p.pooltype);
vec![
p.name.clone(),
pooltype.to_string(),
state.to_string(),
ctx.units(cap),
ctx.units(used),
Expand All @@ -188,7 +201,7 @@ async fn list(
})
.collect();
ctx.print_list(
vec!["NAME", "STATE", ">CAPACITY", ">USED", "DISKS"],
vec!["NAME", "TYPE", "STATE", ">CAPACITY", ">USED", "DISKS"],
table,
);
}
Expand All @@ -205,3 +218,22 @@ fn pool_state_to_str(idx: i32) -> &'static str {
rpc::PoolState::PoolFaulted => "faulted",
}
}

pub(crate) fn pooltype_to_str(idx: i32) -> &'static str {
match rpc::PoolType::from_i32(idx).unwrap() {
rpc::PoolType::Lvs => "lvs",
rpc::PoolType::Lvm => "lvm",
}
}

pub(crate) fn parse_pooltype(ptype: Option<&str>) -> Result<i32, Status> {
match ptype {
None => Ok(rpc::PoolType::Lvs as i32),
Some("lvs") => Ok(rpc::PoolType::Lvs as i32),
Some("lvm") => Ok(rpc::PoolType::Lvm as i32),
Some(_) => Err(Status::new(
Code::Internal,
"Invalid value of pool type".to_owned(),
)),
}
}
17 changes: 15 additions & 2 deletions mayastor/src/bin/mayastor-client/replica_cli.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use crate::{
context::{Context, OutputFormat},
parse_size,
pool_cli::{parse_pooltype, pooltype_to_str},
Error,
GrpcStatus,
};
Expand Down Expand Up @@ -44,7 +45,14 @@ pub fn subcommands<'a, 'b>() -> App<'a, 'b> {
.short("t")
.long("thin")
.takes_value(false)
.help("Whether replica is thin provisioned (default false)"));
.help("Whether replica is thin provisioned (default false)"))
.arg(
Arg::with_name("pooltype")
.long("type")
.required(false)
.possible_values(&["lvs", "lvm"])
.default_value("lvs")
.help("type of the pool"));

let create_v2 = SubCommand::with_name("create2")
.about("Create replica on pool")
Expand Down Expand Up @@ -168,12 +176,15 @@ async fn replica_create(
let thin = matches.is_present("thin");
let share = parse_replica_protocol(matches.value_of("protocol"))
.context(GrpcStatus)?;
let pooltype = parse_pooltype(matches.value_of("pooltype"))
.context(GrpcStatus)?;

let rq = rpc::CreateReplicaRequest {
uuid: name.clone(),
pool,
thin,
share,
pooltype,
size: size.get_bytes() as u64,
};
let response = ctx.client.create_replica(rq).await.context(GrpcStatus)?;
Expand Down Expand Up @@ -327,8 +338,10 @@ async fn replica_list(
.map(|r| {
let proto = replica_protocol_to_str(r.share);
let size = ctx.units(Byte::from_bytes(r.size.into()));
let pooltype = pooltype_to_str(r.pooltype);
vec![
r.pool.clone(),
pooltype.to_string(),
r.uuid.clone(),
r.thin.to_string(),
proto.to_string(),
Expand All @@ -338,7 +351,7 @@ async fn replica_list(
})
.collect();
ctx.print_list(
vec!["POOL", "NAME", ">THIN", ">SHARE", ">SIZE", "URI"],
vec!["POOL", "TYPE", "NAME", ">THIN", ">SHARE", ">SIZE", "URI"],
table,
);
}
Expand Down
3 changes: 3 additions & 0 deletions mayastor/src/core/env.rs
Original file line number Diff line number Diff line change
Expand Up @@ -142,8 +142,11 @@ impl MayastorFeatures {
Err(_) => false,
};

let lvm = matches!(std::env::var("LVM_ENABLE"), Ok(s) if s == "1");

MayastorFeatures {
asymmetric_namespace_access: ana,
lvm,
}
}

Expand Down
2 changes: 2 additions & 0 deletions mayastor/src/core/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -299,4 +299,6 @@ pub static MWQ: once_cell::sync::Lazy<MayastorWorkQueue<Command>> =
#[derive(Debug, Clone)]
pub struct MayastorFeatures {
pub asymmetric_namespace_access: bool,
/// when set to true, support for lvm pools and volumes is enabled
pub lvm: bool,
}
Loading