@@ -28,7 +28,7 @@ use spdk_rs::{
28
28
29
29
use std:: {
30
30
convert:: TryFrom ,
31
- fmt:: { Debug , Display } ,
31
+ fmt:: { Debug , Display , Formatter } ,
32
32
mem:: zeroed,
33
33
ptr:: null_mut,
34
34
str:: FromStr ,
@@ -84,6 +84,26 @@ impl GetOpts for NexusOpts {
84
84
/// Must be equal to the size of `spdk_nvmf_target_opts.crdt`.
85
85
pub const TARGET_CRDT_LEN : usize = 3 ;
86
86
87
+ #[ derive( Clone , Default , Debug , PartialEq , Serialize , Deserialize ) ]
88
+ pub enum NvmfTgtTransport {
89
+ Rdma ,
90
+ #[ default]
91
+ Tcp ,
92
+ }
93
+
94
+ impl Display for NvmfTgtTransport {
95
+ fn fmt ( & self , f : & mut Formatter < ' _ > ) -> std:: fmt:: Result {
96
+ write ! (
97
+ f,
98
+ "{}" ,
99
+ match self {
100
+ NvmfTgtTransport :: Rdma => "rdma" ,
101
+ NvmfTgtTransport :: Tcp => "tcp" ,
102
+ }
103
+ )
104
+ }
105
+ }
106
+
87
107
#[ derive( Debug , Clone , PartialEq , Serialize , Deserialize ) ]
88
108
#[ serde( default , deny_unknown_fields) ]
89
109
pub struct NvmfTgtConfig {
@@ -94,11 +114,13 @@ pub struct NvmfTgtConfig {
94
114
/// NVMF target Command Retry Delay in x100 ms.
95
115
pub crdt : [ u16 ; TARGET_CRDT_LEN ] ,
96
116
/// TCP transport options
97
- pub opts : NvmfTcpTransportOpts ,
117
+ pub opts_tcp : NvmfTcpTransportOpts ,
98
118
/// NVMF target interface (ip, mac, name or subnet).
99
119
pub interface : Option < String > ,
100
120
/// Enable RDMA for NVMF target or not
101
121
pub rdma : Option < bool > ,
122
+ /// RDMA transport options
123
+ pub opts_rdma : NvmfRdmaTransportOpts ,
102
124
}
103
125
104
126
impl From < NvmfTgtConfig > for Box < spdk_nvmf_target_opts > {
@@ -121,9 +143,10 @@ impl Default for NvmfTgtConfig {
121
143
name : "mayastor_target" . to_string ( ) ,
122
144
max_namespaces : 2048 ,
123
145
crdt : args. nvmf_tgt_crdt ,
124
- opts : NvmfTcpTransportOpts :: default ( ) ,
146
+ opts_tcp : NvmfTcpTransportOpts :: default ( ) ,
125
147
interface : None ,
126
148
rdma : None ,
149
+ opts_rdma : NvmfRdmaTransportOpts :: default ( ) ,
127
150
}
128
151
}
129
152
}
@@ -164,6 +187,36 @@ pub struct NvmfTcpTransportOpts {
164
187
zcopy : bool ,
165
188
}
166
189
190
+ /// Settings for the RDMA transport
191
+ #[ derive( Debug , Clone , Copy , PartialEq , Serialize , Deserialize ) ]
192
+ #[ serde( default , deny_unknown_fields) ]
193
+ pub struct NvmfRdmaTransportOpts {
194
+ /// max queue depth
195
+ max_queue_depth : u16 ,
196
+ /// max qpairs per controller
197
+ max_qpairs_per_ctrl : u16 ,
198
+ /// encapsulated data size
199
+ in_capsule_data_size : u32 ,
200
+ /// max IO size
201
+ max_io_size : u32 ,
202
+ /// IO unit size
203
+ io_unit_size : u32 ,
204
+ /// max admin queue depth per admin queue
205
+ max_aq_depth : u32 ,
206
+ /// num of shared buffers
207
+ num_shared_buf : u32 ,
208
+ /// cache size
209
+ buf_cache_size : u32 ,
210
+ /// dif
211
+ dif_insert_or_strip : bool ,
212
+ /// abort execution timeout
213
+ abort_timeout_sec : u32 ,
214
+ /// acceptor poll rate, microseconds
215
+ acceptor_poll_rate : u32 ,
216
+ /// Use zero-copy operations if the underlying bdev supports them
217
+ zcopy : bool ,
218
+ }
219
+
167
220
/// try to read an env variable or returns the default when not found
168
221
fn try_from_env < T > ( name : & str , default : T ) -> T
169
222
where
@@ -277,6 +330,29 @@ impl Default for NvmfTcpTransportOpts {
277
330
}
278
331
}
279
332
333
+ // todo: Tune the defaults by experiments or recommendations, if required.
334
+ impl Default for NvmfRdmaTransportOpts {
335
+ fn default ( ) -> Self {
336
+ Self {
337
+ max_queue_depth : try_from_env ( "NVMF_RDMA_MAX_QUEUE_DEPTH" , 128 ) ,
338
+ in_capsule_data_size : 8192 ,
339
+ max_io_size : 131_072 ,
340
+ io_unit_size : 8192 ,
341
+ max_qpairs_per_ctrl : try_from_env (
342
+ "NVMF_RDMA_MAX_QPAIRS_PER_CTRL" ,
343
+ 32 ,
344
+ ) ,
345
+ num_shared_buf : try_from_env ( "NVMF_RDMA_NUM_SHARED_BUF" , 2047 ) ,
346
+ buf_cache_size : try_from_env ( "NVMF_RDMA_BUF_CACHE_SIZE" , 64 ) ,
347
+ dif_insert_or_strip : false ,
348
+ max_aq_depth : 32 ,
349
+ abort_timeout_sec : 1 ,
350
+ acceptor_poll_rate : try_from_env ( "NVMF_ACCEPTOR_POLL_RATE" , 10_000 ) ,
351
+ zcopy : try_from_env ( "NVMF_ZCOPY" , 1 ) == 1 ,
352
+ }
353
+ }
354
+ }
355
+
280
356
/// we cannot add derives for YAML to these structs directly, so we need to
281
357
/// copy them. The upside though, is that if the FFI structures change, we will
282
358
/// know about it during compile time.
@@ -304,6 +380,30 @@ impl From<NvmfTcpTransportOpts> for spdk_nvmf_transport_opts {
304
380
}
305
381
}
306
382
383
+ impl From < NvmfRdmaTransportOpts > for spdk_nvmf_transport_opts {
384
+ fn from ( o : NvmfRdmaTransportOpts ) -> Self {
385
+ Self {
386
+ max_queue_depth : o. max_queue_depth ,
387
+ max_qpairs_per_ctrlr : o. max_qpairs_per_ctrl ,
388
+ in_capsule_data_size : o. in_capsule_data_size ,
389
+ max_io_size : o. max_io_size ,
390
+ io_unit_size : o. io_unit_size ,
391
+ max_aq_depth : o. max_aq_depth ,
392
+ num_shared_buffers : o. num_shared_buf ,
393
+ buf_cache_size : o. buf_cache_size ,
394
+ dif_insert_or_strip : o. dif_insert_or_strip ,
395
+ reserved29 : Default :: default ( ) ,
396
+ abort_timeout_sec : o. abort_timeout_sec ,
397
+ association_timeout : 120000 ,
398
+ transport_specific : std:: ptr:: null ( ) ,
399
+ opts_size : std:: mem:: size_of :: < spdk_nvmf_transport_opts > ( ) as u64 ,
400
+ acceptor_poll_rate : o. acceptor_poll_rate ,
401
+ zcopy : o. zcopy ,
402
+ reserved61 : Default :: default ( ) ,
403
+ }
404
+ }
405
+ }
406
+
307
407
/// generic settings for the NVMe bdev (all our replicas)
308
408
#[ derive( Debug , PartialEq , Serialize , Deserialize ) ]
309
409
#[ serde( default , deny_unknown_fields) ]
0 commit comments