Skip to content

Commit 020a1e6

Browse files
author
mayastor-bors
committed
Try #1743:
2 parents 247f269 + ec1b6ec commit 020a1e6

File tree

6 files changed

+30
-43
lines changed

6 files changed

+30
-43
lines changed

io-engine/src/bin/io-engine.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ macro_rules! print_feature {
5858

5959
io_engine::CPS_INIT!();
6060
fn start_tokio_runtime(args: &MayastorCliArgs) {
61-
let grpc_address = grpc::endpoint(args.grpc_endpoint.clone());
61+
let grpc_socket_addr = args.grpc_endpoint();
6262
let registration_addr = args.registration_endpoint.clone();
6363
let rpc_address = args.rpc_address.clone();
6464
let api_versions = args.api_versions.clone();
@@ -155,7 +155,7 @@ fn start_tokio_runtime(args: &MayastorCliArgs) {
155155
grpc::MayastorGrpcServer::run(
156156
&node_name,
157157
&node_nqn,
158-
grpc_address,
158+
grpc_socket_addr,
159159
rpc_address,
160160
api_versions.clone(),
161161
)
@@ -166,7 +166,7 @@ fn start_tokio_runtime(args: &MayastorCliArgs) {
166166
Registration::init(
167167
&node_name,
168168
&node_nqn,
169-
&grpc_address.to_string(),
169+
&grpc_socket_addr.to_string(),
170170
registration_addr,
171171
api_versions,
172172
);

io-engine/src/bin/nvmet.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ const NEXUS: &str = "nexus-e1e27668-fbe1-4c8a-9108-513f6e44d342";
2727
fn start_tokio_runtime(args: &MayastorCliArgs) {
2828
let node_name = grpc::node_name(&args.node_name);
2929
let node_nqn = args.make_hostnqn();
30-
let grpc_endpoint = grpc::endpoint(args.grpc_endpoint.clone());
30+
let grpc_endpoint = args.grpc_endpoint();
3131
let rpc_address = args.rpc_address.clone();
3232
let api_versions = args.api_versions.clone();
3333

io-engine/src/core/env.rs

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -137,9 +137,16 @@ fn parse_crdt(src: &str) -> Result<[u16; TARGET_CRDT_LEN], String> {
137137
version = version_info_str!(),
138138
)]
139139
pub struct MayastorCliArgs {
140-
#[clap(short = 'g', default_value = grpc::default_endpoint_str())]
140+
#[clap(short = 'g', long = "grpc-endpoint")]
141+
#[deprecated = "Use grpc_ip and grpc_port instead"]
141142
/// IP address and port (optional) for the gRPC server to listen on.
142-
pub grpc_endpoint: String,
143+
pub deprecated_grpc_endpoint: Option<String>,
144+
#[clap(default_value_t = std::net::IpAddr::V6(std::net::Ipv6Addr::UNSPECIFIED))]
145+
/// IP address for the gRPC server to listen on.
146+
pub grpc_ip: std::net::IpAddr,
147+
#[clap(default_value_t = 10124)]
148+
/// Port for the gRPC server to listen on.
149+
pub grpc_port: u16,
143150
#[clap(short = 'R')]
144151
/// Registration grpc endpoint
145152
pub registration_endpoint: Option<Uri>,
@@ -308,8 +315,11 @@ impl MayastorFeatures {
308315
/// Defaults are redefined here in case of using it during tests
309316
impl Default for MayastorCliArgs {
310317
fn default() -> Self {
318+
#[allow(deprecated)]
311319
Self {
312-
grpc_endpoint: grpc::default_endpoint().to_string(),
320+
deprecated_grpc_endpoint: None,
321+
grpc_ip: std::net::IpAddr::V6(std::net::Ipv6Addr::UNSPECIFIED),
322+
grpc_port: 10124,
313323
ps_endpoint: None,
314324
ps_timeout: Duration::from_secs(10),
315325
ps_retries: 30,
@@ -353,6 +363,15 @@ impl MayastorCliArgs {
353363
pub fn make_hostnqn(&self) -> Option<String> {
354364
make_hostnqn(self.node_name.as_ref())
355365
}
366+
367+
pub fn grpc_endpoint(&self) -> std::net::SocketAddr {
368+
#[allow(deprecated)]
369+
if let Some(deprecated_endpoint) = &self.deprecated_grpc_endpoint {
370+
grpc::endpoint_from_str(deprecated_endpoint, self.grpc_port)
371+
} else {
372+
std::net::SocketAddr::new(self.grpc_ip, self.grpc_port)
373+
}
374+
}
356375
}
357376

358377
/// Global exit code of the program, initially set to -1 to capture double
@@ -586,7 +605,7 @@ static MAYASTOR_DEFAULT_ENV: OnceCell<parking_lot::Mutex<MayastorEnvironment>> =
586605
impl MayastorEnvironment {
587606
pub fn new(args: MayastorCliArgs) -> Self {
588607
Self {
589-
grpc_endpoint: Some(grpc::endpoint(args.grpc_endpoint)),
608+
grpc_endpoint: Some(args.grpc_endpoint()),
590609
registration_endpoint: args.registration_endpoint,
591610
ps_endpoint: args.ps_endpoint,
592611
ps_timeout: args.ps_timeout,

io-engine/src/grpc/mod.rs

Lines changed: 3 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -216,43 +216,13 @@ pub async fn acquire_subsystem_lock<'a>(
216216
}
217217
}
218218

219-
macro_rules! default_ip {
220-
() => {
221-
"0.0.0.0"
222-
};
223-
}
224-
225-
macro_rules! default_port {
226-
() => {
227-
10124
228-
};
229-
}
230-
231-
/// Default server port
232-
pub fn default_port() -> u16 {
233-
default_port!()
234-
}
235-
236-
/// Default endpoint - ip:port
237-
pub fn default_endpoint_str() -> &'static str {
238-
concat!(default_ip!(), ":", default_port!())
239-
}
240-
241-
/// Default endpoint - ip:port
242-
pub fn default_endpoint() -> std::net::SocketAddr {
243-
default_endpoint_str()
244-
.parse()
245-
.expect("Expected a valid endpoint")
246-
}
247-
248219
/// If endpoint is missing a port number then add the default one.
249-
pub fn endpoint(endpoint: String) -> std::net::SocketAddr {
220+
pub fn endpoint_from_str(endpoint: &str, port: u16) -> std::net::SocketAddr {
250221
(if endpoint.contains(':') {
251-
endpoint
222+
endpoint.parse()
252223
} else {
253-
format!("{}:{}", endpoint, default_port())
224+
format!("{}:{}", endpoint, port).parse()
254225
})
255-
.parse()
256226
.expect("Invalid gRPC endpoint")
257227
}
258228

io-engine/tests/nexus_add_remove.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,6 @@ async fn nexus_add_remove() {
250250
log_components: vec!["all".into()],
251251
reactor_mask: "0x3".to_string(),
252252
no_pci: true,
253-
grpc_endpoint: "0.0.0.0".to_string(),
254253
..Default::default()
255254
});
256255

io-engine/tests/nexus_children_add_remove.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ pub fn mayastor() -> &'static MayastorTest<'static> {
3535
MayastorTest::new(MayastorCliArgs {
3636
reactor_mask: "0x2".to_string(),
3737
no_pci: true,
38-
grpc_endpoint: "0.0.0.0".to_string(),
3938
..Default::default()
4039
})
4140
})

0 commit comments

Comments
 (0)