Skip to content

Commit

Permalink
Merge #1743
Browse files Browse the repository at this point in the history
1743: feat(io-engine): listen on IPv6 unspecified by default r=dsharma-dc a=michaelbeaumont

Not able to fully build/test this because of SPDK issues yet but looks good in editor.

I removed the indirection with macros and strings, not sure if there was a particular need for that.

See #1731. This will need changes to the helm chart after being merged.

Co-authored-by: Mike Beaumont <[email protected]>
  • Loading branch information
mayastor-bors and michaelbeaumont committed Oct 7, 2024
2 parents 4d97caa + ec1b6ec commit a2a75d9
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 43 deletions.
6 changes: 3 additions & 3 deletions io-engine/src/bin/io-engine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ macro_rules! print_feature {

io_engine::CPS_INIT!();
fn start_tokio_runtime(args: &MayastorCliArgs) {
let grpc_address = grpc::endpoint(args.grpc_endpoint.clone());
let grpc_socket_addr = args.grpc_endpoint();
let registration_addr = args.registration_endpoint.clone();
let rpc_address = args.rpc_address.clone();
let api_versions = args.api_versions.clone();
Expand Down Expand Up @@ -155,7 +155,7 @@ fn start_tokio_runtime(args: &MayastorCliArgs) {
grpc::MayastorGrpcServer::run(
&node_name,
&node_nqn,
grpc_address,
grpc_socket_addr,
rpc_address,
api_versions.clone(),
)
Expand All @@ -166,7 +166,7 @@ fn start_tokio_runtime(args: &MayastorCliArgs) {
Registration::init(
&node_name,
&node_nqn,
&grpc_address.to_string(),
&grpc_socket_addr.to_string(),
registration_addr,
api_versions,
);
Expand Down
2 changes: 1 addition & 1 deletion io-engine/src/bin/nvmet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ const NEXUS: &str = "nexus-e1e27668-fbe1-4c8a-9108-513f6e44d342";
fn start_tokio_runtime(args: &MayastorCliArgs) {
let node_name = grpc::node_name(&args.node_name);
let node_nqn = args.make_hostnqn();
let grpc_endpoint = grpc::endpoint(args.grpc_endpoint.clone());
let grpc_endpoint = args.grpc_endpoint();
let rpc_address = args.rpc_address.clone();
let api_versions = args.api_versions.clone();

Expand Down
27 changes: 23 additions & 4 deletions io-engine/src/core/env.rs
Original file line number Diff line number Diff line change
Expand Up @@ -137,9 +137,16 @@ fn parse_crdt(src: &str) -> Result<[u16; TARGET_CRDT_LEN], String> {
version = version_info_str!(),
)]
pub struct MayastorCliArgs {
#[clap(short = 'g', default_value = grpc::default_endpoint_str())]
#[clap(short = 'g', long = "grpc-endpoint")]
#[deprecated = "Use grpc_ip and grpc_port instead"]
/// IP address and port (optional) for the gRPC server to listen on.
pub grpc_endpoint: String,
pub deprecated_grpc_endpoint: Option<String>,
#[clap(default_value_t = std::net::IpAddr::V6(std::net::Ipv6Addr::UNSPECIFIED))]
/// IP address for the gRPC server to listen on.
pub grpc_ip: std::net::IpAddr,
#[clap(default_value_t = 10124)]
/// Port for the gRPC server to listen on.
pub grpc_port: u16,
#[clap(short = 'R')]
/// Registration grpc endpoint
pub registration_endpoint: Option<Uri>,
Expand Down Expand Up @@ -310,8 +317,11 @@ impl MayastorFeatures {
/// Defaults are redefined here in case of using it during tests
impl Default for MayastorCliArgs {
fn default() -> Self {
#[allow(deprecated)]
Self {
grpc_endpoint: grpc::default_endpoint().to_string(),
deprecated_grpc_endpoint: None,
grpc_ip: std::net::IpAddr::V6(std::net::Ipv6Addr::UNSPECIFIED),
grpc_port: 10124,
ps_endpoint: None,
ps_timeout: Duration::from_secs(10),
ps_retries: 30,
Expand Down Expand Up @@ -355,6 +365,15 @@ impl MayastorCliArgs {
pub fn make_hostnqn(&self) -> Option<String> {
make_hostnqn(self.node_name.as_ref())
}

pub fn grpc_endpoint(&self) -> std::net::SocketAddr {
#[allow(deprecated)]
if let Some(deprecated_endpoint) = &self.deprecated_grpc_endpoint {
grpc::endpoint_from_str(deprecated_endpoint, self.grpc_port)
} else {
std::net::SocketAddr::new(self.grpc_ip, self.grpc_port)
}
}
}

/// Global exit code of the program, initially set to -1 to capture double
Expand Down Expand Up @@ -588,7 +607,7 @@ static MAYASTOR_DEFAULT_ENV: OnceCell<parking_lot::Mutex<MayastorEnvironment>> =
impl MayastorEnvironment {
pub fn new(args: MayastorCliArgs) -> Self {
Self {
grpc_endpoint: Some(grpc::endpoint(args.grpc_endpoint)),
grpc_endpoint: Some(args.grpc_endpoint()),
registration_endpoint: args.registration_endpoint,
ps_endpoint: args.ps_endpoint,
ps_timeout: args.ps_timeout,
Expand Down
36 changes: 3 additions & 33 deletions io-engine/src/grpc/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -216,43 +216,13 @@ pub async fn acquire_subsystem_lock<'a>(
}
}

macro_rules! default_ip {
() => {
"0.0.0.0"
};
}

macro_rules! default_port {
() => {
10124
};
}

/// Default server port
pub fn default_port() -> u16 {
default_port!()
}

/// Default endpoint - ip:port
pub fn default_endpoint_str() -> &'static str {
concat!(default_ip!(), ":", default_port!())
}

/// Default endpoint - ip:port
pub fn default_endpoint() -> std::net::SocketAddr {
default_endpoint_str()
.parse()
.expect("Expected a valid endpoint")
}

/// If endpoint is missing a port number then add the default one.
pub fn endpoint(endpoint: String) -> std::net::SocketAddr {
pub fn endpoint_from_str(endpoint: &str, port: u16) -> std::net::SocketAddr {
(if endpoint.contains(':') {
endpoint
endpoint.parse()
} else {
format!("{}:{}", endpoint, default_port())
format!("{}:{}", endpoint, port).parse()
})
.parse()
.expect("Invalid gRPC endpoint")
}

Expand Down
1 change: 0 additions & 1 deletion io-engine/tests/nexus_add_remove.rs
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,6 @@ async fn nexus_add_remove() {
log_components: vec!["all".into()],
reactor_mask: "0x3".to_string(),
no_pci: true,
grpc_endpoint: "0.0.0.0".to_string(),
..Default::default()
});

Expand Down
1 change: 0 additions & 1 deletion io-engine/tests/nexus_children_add_remove.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ pub fn mayastor() -> &'static MayastorTest<'static> {
MayastorTest::new(MayastorCliArgs {
reactor_mask: "0x2".to_string(),
no_pci: true,
grpc_endpoint: "0.0.0.0".to_string(),
..Default::default()
})
})
Expand Down

0 comments on commit a2a75d9

Please sign in to comment.