From b25fd2bbd2c5fa37d904289c9b6224937314ff95 Mon Sep 17 00:00:00 2001 From: Mike Beaumont Date: Sat, 21 Sep 2024 19:57:30 +0200 Subject: [PATCH] feat(io-engine): listen on IPv6 unspecified by default Signed-off-by: Mike Beaumont --- io-engine/src/bin/io-engine.rs | 10 ++++--- io-engine/src/core/env.rs | 49 +++++++--------------------------- io-engine/src/grpc/mod.rs | 33 ++--------------------- 3 files changed, 19 insertions(+), 73 deletions(-) diff --git a/io-engine/src/bin/io-engine.rs b/io-engine/src/bin/io-engine.rs index 9aaf54133..eddb3b4e5 100644 --- a/io-engine/src/bin/io-engine.rs +++ b/io-engine/src/bin/io-engine.rs @@ -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(); @@ -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(), ) @@ -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, ); diff --git a/io-engine/src/core/env.rs b/io-engine/src/core/env.rs index ed4c545f9..f82f162bf 100644 --- a/io-engine/src/core/env.rs +++ b/io-engine/src/core/env.rs @@ -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, + #[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, @@ -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()) } } diff --git a/io-engine/src/grpc/mod.rs b/io-engine/src/grpc/mod.rs index 70531a836..a6b903f33 100644 --- a/io-engine/src/grpc/mod.rs +++ b/io-engine/src/grpc/mod.rs @@ -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")