]> git.proxmox.com Git - ceph.git/blame - ceph/src/spdk/scripts/rpc/nvmf.py
import 15.2.0 Octopus source
[ceph.git] / ceph / src / spdk / scripts / rpc / nvmf.py
CommitLineData
9f95a23c
TL
1def set_nvmf_target_max_subsystems(client,
2 max_subsystems=None):
11fdf7f2
TL
3 """Set NVMe-oF target options.
4
5 Args:
9f95a23c 6 max_subsystems: Maximum number of NVMe-oF subsystems (e.g. 1024)
11fdf7f2
TL
7
8 Returns:
9 True or False
10 """
11 params = {}
12
9f95a23c
TL
13 params['max_subsystems'] = max_subsystems
14 return client.call('set_nvmf_target_max_subsystems', params)
11fdf7f2
TL
15
16
17def set_nvmf_target_config(client,
18 acceptor_poll_rate=None,
19 conn_sched=None):
20 """Set NVMe-oF target subsystem configuration.
21
22 Args:
23 acceptor_poll_rate: Acceptor poll period in microseconds (optional)
24 conn_sched: Scheduling of incoming connections (optional)
25
26 Returns:
27 True or False
28 """
29 params = {}
30
31 if acceptor_poll_rate:
32 params['acceptor_poll_rate'] = acceptor_poll_rate
33 if conn_sched:
34 params['conn_sched'] = conn_sched
35 return client.call('set_nvmf_target_config', params)
36
37
38def nvmf_create_transport(client,
39 trtype,
40 max_queue_depth=None,
41 max_qpairs_per_ctrlr=None,
42 in_capsule_data_size=None,
43 max_io_size=None,
44 io_unit_size=None,
9f95a23c
TL
45 max_aq_depth=None,
46 num_shared_buffers=None,
47 buf_cache_size=None,
48 max_srq_depth=None,
49 no_srq=False):
11fdf7f2
TL
50 """NVMf Transport Create options.
51
52 Args:
53 trtype: Transport type (ex. RDMA)
54 max_queue_depth: Max number of outstanding I/O per queue (optional)
55 max_qpairs_per_ctrlr: Max number of SQ and CQ per controller (optional)
56 in_capsule_data_size: Maximum in-capsule data size in bytes (optional)
57 max_io_size: Maximum I/O data size in bytes (optional)
58 io_unit_size: I/O unit size in bytes (optional)
59 max_aq_depth: Max size admin quque per controller (optional)
9f95a23c
TL
60 num_shared_buffers: The number of pooled data buffers available to the transport (optional)
61 buf_cache_size: The number of shared buffers to reserve for each poll group (optional)
62 max_srq_depth: Max number of outstanding I/O per shared receive queue - RDMA specific (optional)
63 no_srq: Boolean flag to disable SRQ even for devices that support it - RDMA specific (optional)
11fdf7f2
TL
64
65 Returns:
66 True or False
67 """
68 params = {}
69
70 params['trtype'] = trtype
71 if max_queue_depth:
72 params['max_queue_depth'] = max_queue_depth
73 if max_qpairs_per_ctrlr:
74 params['max_qpairs_per_ctrlr'] = max_qpairs_per_ctrlr
75 if in_capsule_data_size:
76 params['in_capsule_data_size'] = in_capsule_data_size
77 if max_io_size:
78 params['max_io_size'] = max_io_size
79 if io_unit_size:
80 params['io_unit_size'] = io_unit_size
81 if max_aq_depth:
82 params['max_aq_depth'] = max_aq_depth
9f95a23c
TL
83 if num_shared_buffers:
84 params['num_shared_buffers'] = num_shared_buffers
85 if buf_cache_size:
86 params['buf_cache_size'] = buf_cache_size
87 if max_srq_depth:
88 params['max_srq_depth'] = max_srq_depth
89 if no_srq:
90 params['no_srq'] = no_srq
11fdf7f2
TL
91 return client.call('nvmf_create_transport', params)
92
93
9f95a23c
TL
94def get_nvmf_transports(client):
95 """Get list of NVMe-oF transports.
11fdf7f2
TL
96
97 Returns:
9f95a23c 98 List of NVMe-oF transport objects.
11fdf7f2 99 """
9f95a23c 100 return client.call('get_nvmf_transports')
11fdf7f2
TL
101
102
9f95a23c
TL
103def get_nvmf_subsystems(client):
104 """Get list of NVMe-oF subsystems.
11fdf7f2
TL
105
106 Returns:
9f95a23c 107 List of NVMe-oF subsystem objects.
11fdf7f2 108 """
9f95a23c 109 return client.call('get_nvmf_subsystems')
11fdf7f2
TL
110
111
112def nvmf_subsystem_create(client,
113 nqn,
114 serial_number,
9f95a23c 115 model_number='SPDK bdev Controller',
11fdf7f2
TL
116 allow_any_host=False,
117 max_namespaces=0):
118 """Construct an NVMe over Fabrics target subsystem.
119
120 Args:
121 nqn: Subsystem NQN.
122 serial_number: Serial number of virtual controller.
9f95a23c 123 model_number: Model number of virtual controller.
11fdf7f2
TL
124 allow_any_host: Allow any host (True) or enforce allowed host whitelist (False). Default: False.
125 max_namespaces: Maximum number of namespaces that can be attached to the subsystem (optional). Default: 0 (Unlimited).
126
127 Returns:
128 True or False
129 """
130 params = {
131 'nqn': nqn,
132 }
133
134 if serial_number:
135 params['serial_number'] = serial_number
136
9f95a23c
TL
137 if model_number:
138 params['model_number'] = model_number
139
11fdf7f2
TL
140 if allow_any_host:
141 params['allow_any_host'] = True
142
143 if max_namespaces:
144 params['max_namespaces'] = max_namespaces
145
146 return client.call('nvmf_subsystem_create', params)
147
148
149def nvmf_subsystem_add_listener(client, nqn, trtype, traddr, trsvcid, adrfam):
150 """Add a new listen address to an NVMe-oF subsystem.
151
152 Args:
153 nqn: Subsystem NQN.
154 trtype: Transport type ("RDMA").
155 traddr: Transport address.
156 trsvcid: Transport service ID.
157 adrfam: Address family ("IPv4", "IPv6", "IB", or "FC").
158
159 Returns:
160 True or False
161 """
162 listen_address = {'trtype': trtype,
163 'traddr': traddr,
164 'trsvcid': trsvcid}
165
166 if adrfam:
167 listen_address['adrfam'] = adrfam
168
169 params = {'nqn': nqn,
170 'listen_address': listen_address}
171
172 return client.call('nvmf_subsystem_add_listener', params)
173
174
175def nvmf_subsystem_remove_listener(
176 client,
177 nqn,
178 trtype,
179 traddr,
180 trsvcid,
181 adrfam):
182 """Remove existing listen address from an NVMe-oF subsystem.
183
184 Args:
185 nqn: Subsystem NQN.
186 trtype: Transport type ("RDMA").
187 traddr: Transport address.
188 trsvcid: Transport service ID.
189 adrfam: Address family ("IPv4", "IPv6", "IB", or "FC").
190
191 Returns:
192 True or False
193 """
194 listen_address = {'trtype': trtype,
195 'traddr': traddr,
196 'trsvcid': trsvcid}
197
198 if adrfam:
199 listen_address['adrfam'] = adrfam
200
201 params = {'nqn': nqn,
202 'listen_address': listen_address}
203
204 return client.call('nvmf_subsystem_remove_listener', params)
205
206
207def nvmf_subsystem_add_ns(client, nqn, bdev_name, nsid=None, nguid=None, eui64=None, uuid=None):
208 """Add a namespace to a subsystem.
209
210 Args:
211 nqn: Subsystem NQN.
212 bdev_name: Name of bdev to expose as a namespace.
213 nsid: Namespace ID (optional).
214 nguid: 16-byte namespace globally unique identifier in hexadecimal (optional).
215 eui64: 8-byte namespace EUI-64 in hexadecimal (e.g. "ABCDEF0123456789") (optional).
216 uuid: Namespace UUID (optional).
217
218 Returns:
219 The namespace ID
220 """
221 ns = {'bdev_name': bdev_name}
222
223 if nsid:
224 ns['nsid'] = nsid
225
226 if nguid:
227 ns['nguid'] = nguid
228
229 if eui64:
230 ns['eui64'] = eui64
231
232 if uuid:
233 ns['uuid'] = uuid
234
235 params = {'nqn': nqn,
236 'namespace': ns}
237
238 return client.call('nvmf_subsystem_add_ns', params)
239
240
241def nvmf_subsystem_remove_ns(client, nqn, nsid):
242 """Remove a existing namespace from a subsystem.
243
244 Args:
245 nqn: Subsystem NQN.
246 nsid: Namespace ID.
247
248 Returns:
249 True or False
250 """
251 params = {'nqn': nqn,
252 'nsid': nsid}
253
254 return client.call('nvmf_subsystem_remove_ns', params)
255
256
257def nvmf_subsystem_add_host(client, nqn, host):
258 """Add a host NQN to the whitelist of allowed hosts.
259
260 Args:
261 nqn: Subsystem NQN.
262 host: Host NQN to add to the list of allowed host NQNs
263
264 Returns:
265 True or False
266 """
267 params = {'nqn': nqn,
268 'host': host}
269
270 return client.call('nvmf_subsystem_add_host', params)
271
272
273def nvmf_subsystem_remove_host(client, nqn, host):
274 """Remove a host NQN from the whitelist of allowed hosts.
275
276 Args:
277 nqn: Subsystem NQN.
278 host: Host NQN to remove to the list of allowed host NQNs
279
280 Returns:
281 True or False
282 """
283 params = {'nqn': nqn,
284 'host': host}
285
286 return client.call('nvmf_subsystem_remove_host', params)
287
288
289def nvmf_subsystem_allow_any_host(client, nqn, disable):
290 """Configure a subsystem to allow any host to connect or to enforce the host NQN whitelist.
291
292 Args:
293 nqn: Subsystem NQN.
294 disable: Allow any host (true) or enforce allowed host whitelist (false).
295
296 Returns:
297 True or False
298 """
299 params = {'nqn': nqn, 'allow_any_host': False if disable else True}
300
301 return client.call('nvmf_subsystem_allow_any_host', params)
302
303
304def delete_nvmf_subsystem(client, nqn):
305 """Delete an existing NVMe-oF subsystem.
306
307 Args:
308 nqn: Subsystem NQN.
309
310 Returns:
311 True or False
312 """
313 params = {'nqn': nqn}
314 return client.call('delete_nvmf_subsystem', params)