@@ -35,6 +35,7 @@ use std::{
35
35
} ;
36
36
37
37
use crate :: core:: MayastorEnvironment ;
38
+ use strum_macros:: { AsRefStr , EnumString , EnumVariantNames } ;
38
39
39
40
pub trait GetOpts {
40
41
fn get ( & self ) -> Self ;
@@ -84,6 +85,54 @@ impl GetOpts for NexusOpts {
84
85
/// Must be equal to the size of `spdk_nvmf_target_opts.crdt`.
85
86
pub const TARGET_CRDT_LEN : usize = 3 ;
86
87
88
+ #[ derive( Clone , Default , EnumString , EnumVariantNames , AsRefStr ) ]
89
+ #[ strum( serialize_all = "lowercase" ) ]
90
+ pub enum NvmfTgtTransport {
91
+ Rdma ,
92
+ #[ default]
93
+ Tcp ,
94
+ }
95
+
96
+ impl NvmfTransportOpts {
97
+ /// Tweak a few opts more suited for rdma.
98
+ fn for_rdma ( mut self ) -> Self {
99
+ self . in_capsule_data_size = try_from_env (
100
+ "NVMF_RDMA_IN_CAPSULE_DATA_SIZE" ,
101
+ self . in_capsule_data_size ,
102
+ ) ;
103
+ self . io_unit_size = try_from_env ( "NVMF_RDMA_IO_UNIT_SIZE" , 8192 ) ; // SPDK_NVMF_RDMA_MIN_IO_BUFFER_SIZE
104
+ self . data_wr_pool_size =
105
+ try_from_env ( "NVMF_RDMA_DATA_WR_POOL_SIZE" , 4095 ) ; // SPDK_NVMF_RDMA_DEFAULT_DATA_WR_POOL_SIZE
106
+ self . num_shared_buf =
107
+ try_from_env ( "NVMF_RDMA_NUM_SHARED_BUF" , self . num_shared_buf ) ;
108
+ self
109
+ }
110
+ }
111
+
112
+ impl Default for NvmfTransportOpts {
113
+ fn default ( ) -> Self {
114
+ Self {
115
+ max_queue_depth : try_from_env ( "NVMF_TCP_MAX_QUEUE_DEPTH" , 32 ) ,
116
+ in_capsule_data_size : 4096 ,
117
+ max_io_size : 131_072 ,
118
+ io_unit_size : 131_072 ,
119
+ max_qpairs_per_ctrl : try_from_env (
120
+ "NVMF_TCP_MAX_QPAIRS_PER_CTRL" ,
121
+ 32 ,
122
+ ) ,
123
+ num_shared_buf : try_from_env ( "NVMF_TCP_NUM_SHARED_BUF" , 2047 ) ,
124
+ buf_cache_size : try_from_env ( "NVMF_TCP_BUF_CACHE_SIZE" , 64 ) ,
125
+ dif_insert_or_strip : false ,
126
+ max_aq_depth : 32 ,
127
+ abort_timeout_sec : 1 ,
128
+ acceptor_poll_rate : try_from_env ( "NVMF_ACCEPTOR_POLL_RATE" , 10_000 ) ,
129
+ zcopy : try_from_env ( "NVMF_ZCOPY" , 1 ) == 1 ,
130
+ ack_timeout : try_from_env ( "NVMF_ACK_TIMEOUT" , 0 ) ,
131
+ data_wr_pool_size : 0 ,
132
+ }
133
+ }
134
+ }
135
+
87
136
#[ derive( Debug , Clone , PartialEq , Serialize , Deserialize ) ]
88
137
#[ serde( default , deny_unknown_fields) ]
89
138
pub struct NvmfTgtConfig {
@@ -94,11 +143,13 @@ pub struct NvmfTgtConfig {
94
143
/// NVMF target Command Retry Delay in x100 ms.
95
144
pub crdt : [ u16 ; TARGET_CRDT_LEN ] ,
96
145
/// TCP transport options
97
- pub opts : NvmfTcpTransportOpts ,
146
+ pub opts_tcp : NvmfTransportOpts ,
98
147
/// NVMF target interface (ip, mac, name or subnet).
99
148
pub interface : Option < String > ,
100
149
/// Enable RDMA for NVMF target or not
101
150
pub rdma : Option < bool > ,
151
+ /// RDMA transport options.
152
+ pub opts_rdma : NvmfTransportOpts ,
102
153
}
103
154
104
155
impl From < NvmfTgtConfig > for Box < spdk_nvmf_target_opts > {
@@ -126,9 +177,10 @@ impl Default for NvmfTgtConfig {
126
177
name : "mayastor_target" . to_string ( ) ,
127
178
max_namespaces : 2048 ,
128
179
crdt : args. nvmf_tgt_crdt ,
129
- opts : NvmfTcpTransportOpts :: default ( ) ,
180
+ opts_tcp : NvmfTransportOpts :: default ( ) ,
130
181
interface : None ,
131
182
rdma : None ,
183
+ opts_rdma : NvmfTransportOpts :: default ( ) . for_rdma ( ) ,
132
184
}
133
185
}
134
186
}
@@ -139,10 +191,10 @@ impl GetOpts for NvmfTgtConfig {
139
191
}
140
192
}
141
193
142
- /// Settings for the TCP transport
194
+ /// Nvmf settings for the transports
143
195
#[ derive( Debug , Clone , Copy , PartialEq , Serialize , Deserialize ) ]
144
196
#[ serde( default , deny_unknown_fields) ]
145
- pub struct NvmfTcpTransportOpts {
197
+ pub struct NvmfTransportOpts {
146
198
/// max queue depth
147
199
max_queue_depth : u16 ,
148
200
/// max qpairs per controller
@@ -264,35 +316,11 @@ where
264
316
}
265
317
}
266
318
267
- impl Default for NvmfTcpTransportOpts {
268
- fn default ( ) -> Self {
269
- Self {
270
- max_queue_depth : try_from_env ( "NVMF_TCP_MAX_QUEUE_DEPTH" , 32 ) ,
271
- in_capsule_data_size : 4096 ,
272
- max_io_size : 131_072 ,
273
- io_unit_size : 131_072 ,
274
- max_qpairs_per_ctrl : try_from_env (
275
- "NVMF_TCP_MAX_QPAIRS_PER_CTRL" ,
276
- 32 ,
277
- ) ,
278
- num_shared_buf : try_from_env ( "NVMF_TCP_NUM_SHARED_BUF" , 2047 ) ,
279
- buf_cache_size : try_from_env ( "NVMF_TCP_BUF_CACHE_SIZE" , 64 ) ,
280
- dif_insert_or_strip : false ,
281
- max_aq_depth : 32 ,
282
- abort_timeout_sec : 1 ,
283
- acceptor_poll_rate : try_from_env ( "NVMF_ACCEPTOR_POLL_RATE" , 10_000 ) ,
284
- zcopy : try_from_env ( "NVMF_ZCOPY" , 1 ) == 1 ,
285
- ack_timeout : try_from_env ( "NVMF_ACK_TIMEOUT" , 0 ) ,
286
- data_wr_pool_size : try_from_env ( "NVMF_DATA_WR_POOL_SIZE" , 0 ) ,
287
- }
288
- }
289
- }
290
-
291
319
/// we cannot add derives for YAML to these structs directly, so we need to
292
320
/// copy them. The upside though, is that if the FFI structures change, we will
293
321
/// know about it during compile time.
294
- impl From < NvmfTcpTransportOpts > for spdk_nvmf_transport_opts {
295
- fn from ( o : NvmfTcpTransportOpts ) -> Self {
322
+ impl From < NvmfTransportOpts > for spdk_nvmf_transport_opts {
323
+ fn from ( o : NvmfTransportOpts ) -> Self {
296
324
struct_size_init ! (
297
325
Self {
298
326
max_queue_depth: o. max_queue_depth,
0 commit comments