Skip to content

Commit

Permalink
feat(io-engine): listen on IPv6 unspecified by default
Browse files Browse the repository at this point in the history
Signed-off-by: Mike Beaumont <[email protected]>
  • Loading branch information
michaelbeaumont committed Sep 21, 2024
1 parent 1c537b7 commit b25fd2b
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 73 deletions.
10 changes: 7 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,11 @@ 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 = if let Some(deprecated_endpoint) = args.grpc_endpoint {
grpc::endpoint_from_str(args.grpc_endpoint.clone(), args.grpc_port)
} else {
std::net::SocketAddr::new(args.grpc_ip, args.grpc_port)
};
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 +159,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 +170,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
49 changes: 10 additions & 39 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')]
#[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 grpc_endpoint: Option<String>,
#[clap(default_value_t = 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 @@ -308,43 +315,7 @@ impl MayastorFeatures {
/// Defaults are redefined here in case of using it during tests
impl Default for MayastorCliArgs {
fn default() -> Self {
Self {
grpc_endpoint: grpc::default_endpoint().to_string(),
ps_endpoint: None,
ps_timeout: Duration::from_secs(10),
ps_retries: 30,
node_name: None,
env_context: None,
reactor_mask: "0x1".into(),
mem_size: 0,
rpc_address: "/var/tmp/mayastor.sock".to_string(),
no_pci: true,
log_components: vec![],
log_format: None,
mayastor_config: None,
ptpl_dir: None,
pool_config: None,
hugedir: None,
core_list: None,
bdev_io_ctx_pool_size: 65535,
nvme_ctl_io_ctx_pool_size: 65535,
registration_endpoint: None,
nvmf_tgt_interface: None,
nvmf_tgt_crdt: [0; TARGET_CRDT_LEN],
api_versions: vec![ApiVersion::V0, ApiVersion::V1],
diagnose_stack: None,
reactor_freeze_detection: false,
reactor_freeze_timeout: None,
skip_sig_handler: false,
enable_io_all_thrd_nexus_channels: false,
events_url: None,
enable_nexus_channel_debug: false,
lvm: false,
snap_rebuild: false,
developer_delay: false,
rdma: false,
bs_cluster_unmap: false,
}
Self::parse_from(std::iter::empty())
}
}

Expand Down
33 changes: 2 additions & 31 deletions io-engine/src/grpc/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -216,41 +216,12 @@ 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: String, port: u16) -> std::net::SocketAddr {
(if endpoint.contains(':') {
endpoint
} else {
format!("{}:{}", endpoint, default_port())
format!("{}:{}", endpoint, port)
})
.parse()
.expect("Invalid gRPC endpoint")
Expand Down

0 comments on commit b25fd2b

Please sign in to comment.