xref: /spdk/python/spdk/rpc/bdev.py (revision 8a6101458532c70e17ff48c2d48391f284a0fdd5)
1#  SPDX-License-Identifier: BSD-3-Clause
2#  Copyright (C) 2017 Intel Corporation.
3#  All rights reserved.
4#  Copyright (c) 2022 Dell Inc, or its subsidiaries.
5#  Copyright (c) 2024 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
6
7
8def bdev_set_options(client, bdev_io_pool_size=None, bdev_io_cache_size=None,
9                     bdev_auto_examine=None, iobuf_small_cache_size=None,
10                     iobuf_large_cache_size=None):
11    """Set parameters for the bdev subsystem.
12    Args:
13        bdev_io_pool_size: number of bdev_io structures in shared buffer pool (optional)
14        bdev_io_cache_size: maximum number of bdev_io structures cached per thread (optional)
15        bdev_auto_examine: if set to false, the bdev layer will not examine every disks automatically (optional)
16        iobuf_small_cache_size: size of the small iobuf per thread cache
17        iobuf_large_cache_size: size of the large iobuf per thread cache
18    """
19    params = dict()
20    if bdev_io_pool_size is not None:
21        params['bdev_io_pool_size'] = bdev_io_pool_size
22    if bdev_io_cache_size is not None:
23        params['bdev_io_cache_size'] = bdev_io_cache_size
24    if bdev_auto_examine is not None:
25        params['bdev_auto_examine'] = bdev_auto_examine
26    if iobuf_small_cache_size is not None:
27        params['iobuf_small_cache_size'] = iobuf_small_cache_size
28    if iobuf_large_cache_size is not None:
29        params['iobuf_large_cache_size'] = iobuf_large_cache_size
30    return client.call('bdev_set_options', params)
31
32
33def bdev_examine(client, name):
34    """Examine a bdev manually. If the bdev does not exist yet when this RPC is called,
35    it will be examined when it is created
36    Args:
37        name: name of the bdev
38    """
39    params = dict()
40    params['name'] = name
41    return client.call('bdev_examine', params)
42
43
44def bdev_wait_for_examine(client):
45    """Report when all bdevs have been examined
46    """
47    return client.call('bdev_wait_for_examine')
48
49
50def bdev_compress_create(client, base_bdev_name, pm_path, lb_size=None):
51    """Construct a compress virtual block device.
52    Args:
53        base_bdev_name: name of the underlying base bdev
54        pm_path: path to persistent memory
55        lb_size: logical block size for the compressed vol in bytes.  Must be 4K or 512.
56    Returns:
57        Name of created virtual block device.
58    """
59    params = dict()
60    params['base_bdev_name'] = base_bdev_name
61    params['pm_path'] = pm_path
62    if lb_size is not None:
63        params['lb_size'] = lb_size
64    return client.call('bdev_compress_create', params)
65
66
67def bdev_compress_delete(client, name):
68    """Delete compress virtual block device.
69    Args:
70        name: name of compress vbdev to delete
71    """
72    params = dict()
73    params['name'] = name
74    return client.call('bdev_compress_delete', params)
75
76
77def bdev_compress_get_orphans(client, name=None):
78    """Get a list of comp bdevs that do not have a pmem file (aka orphaned).
79    Args:
80        name: comp bdev name to query (optional; if omitted, query all comp bdevs)
81    Returns:
82        List of comp bdev names.
83    """
84    params = dict()
85    if name is not None:
86        params['name'] = name
87    return client.call('bdev_compress_get_orphans', params)
88
89
90def bdev_crypto_create(client, base_bdev_name, name, crypto_pmd=None, key=None, cipher=None, key2=None, key_name=None):
91    """Construct a crypto virtual block device.
92    Args:
93        base_bdev_name: name of the underlying base bdev
94        name: name for the crypto vbdev
95        crypto_pmd: name of the DPDK crypto driver to use
96        key: key
97        cipher: crypto algorithm to use
98        key2: Optional second part of the key
99        key_name: The key name to use in crypto operations
100    Returns:
101        Name of created virtual block device.
102    """
103    params = dict()
104    params['base_bdev_name'] = base_bdev_name
105    params['name'] = name
106    if crypto_pmd is not None:
107        params['crypto_pmd'] = crypto_pmd
108    if key is not None:
109        params['key'] = key
110    if cipher is not None:
111        params['cipher'] = cipher
112    if key2 is not None:
113        params['key2'] = key2
114    if key_name is not None:
115        params['key_name'] = key_name
116    return client.call('bdev_crypto_create', params)
117
118
119def bdev_crypto_delete(client, name):
120    """Delete crypto virtual block device.
121    Args:
122        name: name of crypto vbdev to delete
123    """
124    params = dict()
125    params['name'] = name
126    return client.call('bdev_crypto_delete', params)
127
128
129def bdev_ocf_create(client, name, mode, cache_bdev_name, core_bdev_name, cache_line_size=None):
130    """Add an OCF block device
131    Args:
132        name: name of constructed OCF bdev
133        mode: OCF cache mode: {'wb', 'wt', 'pt', 'wa', 'wi', 'wo'}
134        cache_bdev_name: name of underlying cache bdev
135        core_bdev_name: name of underlying core bdev
136        cache_line_size: OCF cache line size. The unit is KiB: {4, 8, 16, 32, 64}
137    Returns:
138        Name of created block device
139    """
140    params = dict()
141    params['name'] = name
142    params['mode'] = mode
143    params['cache_bdev_name'] = cache_bdev_name
144    params['core_bdev_name'] = core_bdev_name
145    if cache_line_size is not None:
146        params['cache_line_size'] = cache_line_size
147    return client.call('bdev_ocf_create', params)
148
149
150def bdev_ocf_delete(client, name):
151    """Delete an OCF device
152    Args:
153        name: name of OCF bdev
154    """
155    params = dict()
156    params['name'] = name
157    return client.call('bdev_ocf_delete', params)
158
159
160def bdev_ocf_get_stats(client, name):
161    """Get statistics of chosen OCF block device
162    Args:
163        name: name of OCF bdev
164    Returns:
165        Statistics as json object
166    """
167    params = dict()
168    params['name'] = name
169    return client.call('bdev_ocf_get_stats', params)
170
171
172def bdev_ocf_reset_stats(client, name):
173    """Reset statistics of chosen OCF block device
174    Args:
175        name: name of OCF bdev
176    Returns:
177        None
178    """
179    params = dict()
180    params['name'] = name
181    return client.call('bdev_ocf_reset_stats', params)
182
183
184def bdev_ocf_get_bdevs(client, name=None):
185    """Get list of OCF devices including unregistered ones
186    Args:
187        name: name of OCF vbdev or name of cache device or name of core device (optional)
188    Returns:
189        Array of OCF devices with their current status
190    """
191    params = dict()
192    if name is not None:
193        params['name'] = name
194    return client.call('bdev_ocf_get_bdevs', params)
195
196
197def bdev_ocf_set_cache_mode(client, name, mode):
198    """Set cache mode of OCF block device
199    Args:
200        name: name of OCF bdev
201        mode: OCF cache mode: {'wb', 'wt', 'pt', 'wa', 'wi', 'wo'}
202    Returns:
203        New cache mode name
204    """
205    params = dict()
206    params['name'] = name
207    params['mode'] = mode
208    return client.call('bdev_ocf_set_cache_mode', params)
209
210
211def bdev_ocf_set_seqcutoff(client, name, policy, threshold=None, promotion_count=None):
212    """Set sequential cutoff parameters on all cores for the given OCF cache device
213    Args:
214        name: Name of OCF cache bdev
215        policy: Sequential cutoff policy
216        threshold: Activation threshold [KiB] (optional)
217        promotion_count: Promotion request count (optional)
218    """
219    params = dict()
220    params['name'] = name
221    params['policy'] = policy
222    if threshold is not None:
223        params['threshold'] = threshold
224    if promotion_count is not None:
225        params['promotion_count'] = promotion_count
226    return client.call('bdev_ocf_set_seqcutoff', params)
227
228
229def bdev_ocf_flush_start(client, name):
230    """Start flushing OCF cache device
231    Args:
232        name: name of OCF bdev
233    """
234    params = dict()
235    params['name'] = name
236    return client.call('bdev_ocf_flush_start', params)
237
238
239def bdev_ocf_flush_status(client, name):
240    """Get flush status of OCF cache device
241    Args:
242        name: name of OCF bdev
243    Returns:
244        Flush status
245    """
246    params = dict()
247    params['name'] = name
248    return client.call('bdev_ocf_flush_status', params)
249
250
251def bdev_malloc_create(client, num_blocks, block_size, physical_block_size=None, name=None, uuid=None, optimal_io_boundary=None,
252                       md_size=None, md_interleave=None, dif_type=None, dif_is_head_of_md=None):
253    """Construct a malloc block device.
254    Args:
255        num_blocks: size of block device in blocks
256        block_size: Data block size of device; must be a power of 2 and at least 512
257        physical_block_size: Physical block size of device; must be a power of 2 and at least 512 (optional)
258        name: name of block device (optional)
259        uuid: UUID of block device (optional)
260        optimal_io_boundary: Split on optimal IO boundary, in number of blocks, default 0 (disabled, optional)
261        md_size: metadata size of device (0, 8, 16, 32, 64, or 128), default 0 (optional)
262        md_interleave: metadata location, interleaved if set, and separated if omitted (optional)
263        dif_type: protection information type (optional)
264        dif_is_head_of_md: protection information is in the first 8 bytes of metadata (optional)
265    Returns:
266        Name of created block device.
267    """
268    params = dict()
269    params['num_blocks'] = num_blocks
270    params['block_size'] = block_size
271    if physical_block_size is not None:
272        params['physical_block_size'] = physical_block_size
273    if name is not None:
274        params['name'] = name
275    if uuid is not None:
276        params['uuid'] = uuid
277    if optimal_io_boundary is not None:
278        params['optimal_io_boundary'] = optimal_io_boundary
279    if md_size is not None:
280        params['md_size'] = md_size
281    if md_interleave is not None:
282        params['md_interleave'] = md_interleave
283    if dif_type is not None:
284        params['dif_type'] = dif_type
285    if dif_is_head_of_md is not None:
286        params['dif_is_head_of_md'] = dif_is_head_of_md
287    return client.call('bdev_malloc_create', params)
288
289
290def bdev_malloc_delete(client, name):
291    """Delete malloc block device.
292    Args:
293        bdev_name: name of malloc bdev to delete
294    """
295    params = dict()
296    params['name'] = name
297    return client.call('bdev_malloc_delete', params)
298
299
300def bdev_null_create(client, num_blocks, block_size, name, physical_block_size=None, uuid=None, md_size=None,
301                     dif_type=None, dif_is_head_of_md=None):
302    """Construct a null block device.
303    Args:
304        num_blocks: size of block device in blocks
305        block_size: block size of device; data part size must be a power of 2 and at least 512
306        name: name of block device
307        physical_block_size: physical block size of the device; data part size must be a power of 2 and at least 512 (optional)
308        uuid: UUID of block device (optional)
309        md_size: metadata size of device (optional)
310        dif_type: protection information type (optional)
311        dif_is_head_of_md: protection information is in the first 8 bytes of metadata (optional)
312    Returns:
313        Name of created block device.
314    """
315    params = dict()
316    params['num_blocks'] = num_blocks
317    params['block_size'] = block_size
318    params['name'] = name
319    if physical_block_size is not None:
320        params['physical_block_size'] = physical_block_size
321    if uuid is not None:
322        params['uuid'] = uuid
323    if md_size is not None:
324        params['md_size'] = md_size
325    if dif_type is not None:
326        params['dif_type'] = dif_type
327    if dif_is_head_of_md is not None:
328        params['dif_is_head_of_md'] = dif_is_head_of_md
329    return client.call('bdev_null_create', params)
330
331
332def bdev_null_delete(client, name):
333    """Remove null bdev from the system.
334    Args:
335        name: name of null bdev to delete
336    """
337    params = dict()
338    params['name'] = name
339    return client.call('bdev_null_delete', params)
340
341
342def bdev_null_resize(client, name, new_size):
343    """Resize null bdev in the system.
344    Args:
345        name: name of null bdev to resize
346        new_size: new bdev size of resize operation. The unit is MiB
347    """
348    params = dict()
349    params['name'] = name
350    params['new_size'] = new_size
351    return client.call('bdev_null_resize', params)
352
353
354def bdev_raid_set_options(client, process_window_size_kb=None):
355    """Set options for bdev raid.
356    Args:
357        process_window_size_kb: Background process (e.g. rebuild) window size in KiB
358    """
359    params = dict()
360    if process_window_size_kb is not None:
361        params['process_window_size_kb'] = process_window_size_kb
362    return client.call('bdev_raid_set_options', params)
363
364
365def bdev_raid_get_bdevs(client, category):
366    """Get list of raid bdevs based on category
367    Args:
368        category: any one of all or online or configuring or offline
369    Returns:
370        List of raid bdev details
371    """
372    params = dict()
373    params['category'] = category
374    return client.call('bdev_raid_get_bdevs', params)
375
376
377def bdev_raid_create(client, name, raid_level, base_bdevs, strip_size_kb=None, uuid=None, superblock=None):
378    """Create raid bdev. Either strip size arg will work but one is required.
379    Args:
380        name: user defined raid bdev name
381        raid_level: raid level of raid bdev, supported values 0
382        base_bdevs: Space separated names of Nvme bdevs in double quotes, like "Nvme0n1 Nvme1n1 Nvme2n1"
383        strip_size_kb: strip size of raid bdev in KB, supported values like 8, 16, 32, 64, 128, 256, etc
384        uuid: UUID for this raid bdev (optional)
385        superblock: information about raid bdev will be stored in superblock on each base bdev,
386                    disabled by default due to backward compatibility
387    Returns:
388        None
389    """
390    params = dict()
391    params['name'] = name
392    params['raid_level'] = raid_level
393    params['base_bdevs'] = base_bdevs
394    if strip_size_kb is not None:
395        params['strip_size_kb'] = strip_size_kb
396    if uuid is not None:
397        params['uuid'] = uuid
398    if superblock is not None:
399        params['superblock'] = superblock
400    return client.call('bdev_raid_create', params)
401
402
403def bdev_raid_delete(client, name):
404    """Delete raid bdev
405    Args:
406        name: raid bdev name
407    Returns:
408        None
409    """
410    params = dict()
411    params['name'] = name
412    return client.call('bdev_raid_delete', params)
413
414
415def bdev_raid_add_base_bdev(client, base_bdev, raid_bdev):
416    """Add base bdev to existing raid bdev
417    Args:
418        base_bdev: base bdev name
419        raid_bdev: raid bdev name
420    Returns:
421        None
422    """
423    params = dict()
424    params['base_bdev'] = base_bdev
425    params['raid_bdev'] = raid_bdev
426    return client.call('bdev_raid_add_base_bdev', params)
427
428
429def bdev_raid_remove_base_bdev(client, name):
430    """Remove base bdev from existing raid bdev
431    Args:
432        name: base bdev name
433    Returns:
434        None
435    """
436    params = dict()
437    params['name'] = name
438    return client.call('bdev_raid_remove_base_bdev', params)
439
440
441def bdev_aio_create(client, filename, name, block_size=None, readonly=None, fallocate=None):
442    """Construct a Linux AIO block device.
443    Args:
444        filename: path to device or file (ex: /dev/sda)
445        name: name of block device
446        block_size: block size of device (optional; autodetected if omitted)
447        readonly: set aio bdev as read-only
448        fallocate: enable fallocate for UNMAP/WRITEZEROS support (note that fallocate syscall would block reactor)
449    Returns:
450        Name of created block device.
451    """
452    params = dict()
453    params['filename'] = filename
454    params['name'] = name
455    if block_size is not None:
456        params['block_size'] = block_size
457    if readonly is not None:
458        params['readonly'] = readonly
459    if fallocate is not None:
460        params['fallocate'] = fallocate
461    return client.call('bdev_aio_create', params)
462
463
464def bdev_aio_rescan(client, name):
465    """Rescan a Linux AIO block device.
466    Args:
467        name: name of aio bdev to rescan
468    """
469    params = dict()
470    params['name'] = name
471    return client.call('bdev_aio_rescan', params)
472
473
474def bdev_aio_delete(client, name):
475    """Remove aio bdev from the system.
476    Args:
477        name: name of aio bdev to delete
478    """
479    params = dict()
480    params['name'] = name
481    return client.call('bdev_aio_delete', params)
482
483
484def bdev_uring_create(client, filename, name, block_size=None, uuid=None):
485    """Create a bdev with Linux io_uring backend.
486    Args:
487        filename: path to device or file (ex: /dev/nvme0n1)
488        name: name of bdev
489        block_size: block size of device (optional; autodetected if omitted)
490        uuid: UUID of block device (optional)
491    Returns:
492        Name of created bdev.
493    """
494    params = dict()
495    params['filename'] = filename
496    params['name'] = name
497    if block_size is not None:
498        params['block_size'] = block_size
499    if uuid is not None:
500        params['uuid'] = uuid
501    return client.call('bdev_uring_create', params)
502
503
504def bdev_uring_rescan(client, name):
505    """Rescan a Linux URING block device.
506    Args:
507        name: name of uring bdev to rescan
508    """
509    params = dict()
510    params['name'] = name
511    return client.call('bdev_uring_rescan', params)
512
513
514def bdev_uring_delete(client, name):
515    """Delete a uring bdev.
516    Args:
517        name: name of uring bdev to delete
518    """
519    params = dict()
520    params['name'] = name
521    return client.call('bdev_uring_delete', params)
522
523
524def bdev_xnvme_create(client, filename, name, io_mechanism, conserve_cpu=None):
525    """Create a bdev with xNVMe backend.
526    Args:
527        filename: path to device or file (ex: /dev/nvme0n1)
528        name: name of xNVMe bdev to create
529        io_mechanism: I/O mechanism to use (ex: io_uring, io_uring_cmd, etc.)
530        conserve_cpu: Whether or not to conserve CPU when polling (default: False)
531    Returns:
532        Name of created bdev.
533    """
534    params = dict()
535    params['filename'] = filename
536    params['name'] = name
537    params['io_mechanism'] = io_mechanism
538    if conserve_cpu is not None:
539        params['conserve_cpu'] = conserve_cpu
540    return client.call('bdev_xnvme_create', params)
541
542
543def bdev_xnvme_delete(client, name):
544    """Delete a xNVMe bdev.
545    Args:
546        name: name of xNVMe bdev to delete
547    """
548    params = dict()
549    params['name'] = name
550    return client.call('bdev_xnvme_delete', params)
551
552
553def bdev_nvme_set_options(client, action_on_timeout=None, timeout_us=None, timeout_admin_us=None,
554                          keep_alive_timeout_ms=None, arbitration_burst=None,
555                          low_priority_weight=None, medium_priority_weight=None, high_priority_weight=None,
556                          nvme_adminq_poll_period_us=None, nvme_ioq_poll_period_us=None, io_queue_requests=None,
557                          delay_cmd_submit=None, transport_retry_count=None, bdev_retry_count=None,
558                          transport_ack_timeout=None, ctrlr_loss_timeout_sec=None, reconnect_delay_sec=None,
559                          fast_io_fail_timeout_sec=None, disable_auto_failback=None, generate_uuids=None,
560                          transport_tos=None, nvme_error_stat=None, rdma_srq_size=None, io_path_stat=None,
561                          allow_accel_sequence=None, rdma_max_cq_size=None, rdma_cm_event_timeout_ms=None,
562                          dhchap_digests=None, dhchap_dhgroups=None):
563    """Set options for the bdev nvme. This is startup command.
564    Args:
565        action_on_timeout:  action to take on command time out. Valid values are: none, reset, abort (optional)
566        timeout_us: Timeout for each command, in microseconds. If 0, don't track timeouts (optional)
567        timeout_admin_us: Timeout for each admin command, in microseconds. If 0, treat same as io timeouts (optional)
568        keep_alive_timeout_ms: Keep alive timeout period in millisecond, default is 10s (optional)
569        arbitration_burst: The value is expressed as a power of two (optional)
570        low_priority_weight: The number of commands that may be executed from the low priority queue at one time (optional)
571        medium_priority_weight: The number of commands that may be executed from the medium priority queue at one time (optional)
572        high_priority_weight: The number of commands that may be executed from the high priority queue at one time (optional)
573        nvme_adminq_poll_period_us: How often the admin queue is polled for asynchronous events in microseconds (optional)
574        nvme_ioq_poll_period_us: How often to poll I/O queues for completions in microseconds (optional)
575        io_queue_requests: The number of requests allocated for each NVMe I/O queue. Default: 512 (optional)
576        delay_cmd_submit: Enable delayed NVMe command submission to allow batching of multiple commands (optional)
577        transport_retry_count: The number of attempts per I/O in the transport layer when an I/O fails (optional)
578        bdev_retry_count: The number of attempts per I/O in the bdev layer when an I/O fails. -1 means infinite retries. (optional)
579        transport_ack_timeout: Time to wait ack until packet retransmission for RDMA or until closes connection for TCP.
580        Range 0-31 where 0 is driver-specific default value (optional)
581        ctrlr_loss_timeout_sec: Time to wait until ctrlr is reconnected before deleting ctrlr.
582        -1 means infinite reconnect retries. 0 means no reconnect retry.
583        If reconnect_delay_sec is zero, ctrlr_loss_timeout_sec has to be zero.
584        If reconnect_delay_sec is non-zero, ctrlr_loss_timeout_sec has to be -1 or not less than reconnect_delay_sec.
585        This can be overridden by bdev_nvme_attach_controller. (optional)
586        reconnect_delay_sec: Time to delay a reconnect retry.
587        If ctrlr_loss_timeout_sec is zero, reconnect_delay_sec has to be zero.
588        If ctrlr_loss_timeout_sec is -1, reconnect_delay_sec has to be non-zero.
589        If ctrlr_loss_timeout_sec is not -1 or zero, reconnect_sec has to be non-zero and less than ctrlr_loss_timeout_sec.
590        This can be overridden by bdev_nvme_attach_controller. (optional)
591        fast_io_fail_timeout_sec: Time to wait until ctrlr is reconnected before failing I/O to ctrlr.
592        0 means no such timeout.
593        If fast_io_fail_timeout_sec is not zero, it has to be not less than reconnect_delay_sec and less than
594        ctrlr_loss_timeout_sec if ctrlr_loss_timeout_sec is not -1.
595        This can be overridden by bdev_nvme_attach_controller. (optional)
596        disable_auto_failback: Disable automatic failback. bdev_nvme_set_preferred_path can be used to do manual failback.
597        By default, immediately failback to the preferred I/O path if it is restored. (optional)
598        generate_uuids: Enable generation of unique identifiers for NVMe bdevs only if they do not provide UUID themselves.
599        These strings are based on device serial number and namespace ID and will always be the same for that device.
600        transport_tos: IPv4 Type of Service value. Only applicable for RDMA transports.
601        The default is 0 which means no TOS is applied. (optional)
602        nvme_error_stat: Enable collecting NVMe error counts. (optional)
603        rdma_srq_size: Set the size of a shared rdma receive queue. Default: 0 (disabled) (optional)
604        io_path_stat: Enable collection I/O path stat of each io path. (optional)
605        allow_accel_sequence: Allow NVMe bdevs to advertise support for accel sequences if the
606        controller also supports them. (optional)
607        rdma_max_cq_size: The maximum size of a rdma completion queue. Default: 0 (unlimited) (optional)
608        rdma_cm_event_timeout_ms: Time to wait for RDMA CM event. Only applicable for RDMA transports.
609        dhchap_digests: List of allowed DH-HMAC-CHAP digests. (optional)
610        dhchap_dhgroups: List of allowed DH-HMAC-CHAP DH groups. (optional)
611    """
612    params = dict()
613    if action_on_timeout is not None:
614        params['action_on_timeout'] = action_on_timeout
615    if timeout_us is not None:
616        params['timeout_us'] = timeout_us
617    if timeout_admin_us is not None:
618        params['timeout_admin_us'] = timeout_admin_us
619    if keep_alive_timeout_ms is not None:
620        params['keep_alive_timeout_ms'] = keep_alive_timeout_ms
621    if arbitration_burst is not None:
622        params['arbitration_burst'] = arbitration_burst
623    if low_priority_weight is not None:
624        params['low_priority_weight'] = low_priority_weight
625    if medium_priority_weight is not None:
626        params['medium_priority_weight'] = medium_priority_weight
627    if high_priority_weight is not None:
628        params['high_priority_weight'] = high_priority_weight
629    if nvme_adminq_poll_period_us is not None:
630        params['nvme_adminq_poll_period_us'] = nvme_adminq_poll_period_us
631    if nvme_ioq_poll_period_us is not None:
632        params['nvme_ioq_poll_period_us'] = nvme_ioq_poll_period_us
633    if io_queue_requests is not None:
634        params['io_queue_requests'] = io_queue_requests
635    if delay_cmd_submit is not None:
636        params['delay_cmd_submit'] = delay_cmd_submit
637    if transport_retry_count is not None:
638        params['transport_retry_count'] = transport_retry_count
639    if bdev_retry_count is not None:
640        params['bdev_retry_count'] = bdev_retry_count
641    if transport_ack_timeout is not None:
642        params['transport_ack_timeout'] = transport_ack_timeout
643    if ctrlr_loss_timeout_sec is not None:
644        params['ctrlr_loss_timeout_sec'] = ctrlr_loss_timeout_sec
645    if reconnect_delay_sec is not None:
646        params['reconnect_delay_sec'] = reconnect_delay_sec
647    if fast_io_fail_timeout_sec is not None:
648        params['fast_io_fail_timeout_sec'] = fast_io_fail_timeout_sec
649    if disable_auto_failback is not None:
650        params['disable_auto_failback'] = disable_auto_failback
651    if generate_uuids is not None:
652        params['generate_uuids'] = generate_uuids
653    if transport_tos is not None:
654        params['transport_tos'] = transport_tos
655    if nvme_error_stat is not None:
656        params['nvme_error_stat'] = nvme_error_stat
657    if rdma_srq_size is not None:
658        params['rdma_srq_size'] = rdma_srq_size
659    if io_path_stat is not None:
660        params['io_path_stat'] = io_path_stat
661    if allow_accel_sequence is not None:
662        params['allow_accel_sequence'] = allow_accel_sequence
663    if rdma_max_cq_size is not None:
664        params['rdma_max_cq_size'] = rdma_max_cq_size
665    if rdma_cm_event_timeout_ms is not None:
666        params['rdma_cm_event_timeout_ms'] = rdma_cm_event_timeout_ms
667    if dhchap_digests is not None:
668        params['dhchap_digests'] = dhchap_digests
669    if dhchap_dhgroups is not None:
670        params['dhchap_dhgroups'] = dhchap_dhgroups
671    return client.call('bdev_nvme_set_options', params)
672
673
674def bdev_nvme_set_hotplug(client, enable, period_us=None):
675    """Set options for the bdev nvme. This is startup command.
676    Args:
677       enable: True to enable hotplug, False to disable.
678       period_us: how often the hotplug is processed for insert and remove events. Set 0 to reset to default. (optional)
679    """
680    params = dict()
681    params['enable'] = enable
682    if period_us is not None:
683        params['period_us'] = period_us
684    return client.call('bdev_nvme_set_hotplug', params)
685
686
687def bdev_nvme_attach_controller(client, name, trtype, traddr, adrfam=None, trsvcid=None,
688                                priority=None, subnqn=None, hostnqn=None, hostaddr=None,
689                                hostsvcid=None, prchk_reftag=None, prchk_guard=None,
690                                hdgst=None, ddgst=None, fabrics_connect_timeout_us=None,
691                                multipath=None, num_io_queues=None, ctrlr_loss_timeout_sec=None,
692                                reconnect_delay_sec=None, fast_io_fail_timeout_sec=None,
693                                psk=None, max_bdevs=None, dhchap_key=None, dhchap_ctrlr_key=None):
694    """Construct block device for each NVMe namespace in the attached controller.
695    Args:
696        name: bdev name prefix; "n" + namespace ID will be appended to create unique names
697        trtype: transport type ("PCIe", "RDMA", "FC", "TCP")
698        traddr: transport address (PCI BDF or IP address)
699        adrfam: address family ("IPv4", "IPv6", "IB", or "FC")
700        trsvcid: transport service ID (port number for IP-based addresses)
701        priority: transport connection priority (Sock priority for TCP-based transports; optional)
702        subnqn: subsystem NQN to connect to (optional)
703        hostnqn: NQN to connect from (optional)
704        hostaddr: host transport address (IP address for IP-based transports, NULL for PCIe or FC; optional)
705        hostsvcid: host transport service ID (port number for IP-based transports, NULL for PCIe or FC; optional)
706        prchk_reftag: Enable checking of PI reference tag for I/O processing (optional)
707        prchk_guard: Enable checking of PI guard for I/O processing (optional)
708        hdgst: Enable TCP header digest (optional)
709        ddgst: Enable TCP data digest (optional)
710        fabrics_connect_timeout_us: Fabrics connect timeout in us (optional)
711        multipath: The behavior when multiple paths are created ("disable", "failover", or "multipath"; failover if not specified)
712        num_io_queues: The number of IO queues to request during initialization. (optional)
713        ctrlr_loss_timeout_sec: Time to wait until ctrlr is reconnected before deleting ctrlr.
714        -1 means infinite reconnect retries. 0 means no reconnect retry.
715        If reconnect_delay_sec is zero, ctrlr_loss_timeout_sec has to be zero.
716        If reconnect_delay_sec is non-zero, ctrlr_loss_timeout_sec has to be -1 or not less than reconnect_delay_sec.
717        (optional)
718        reconnect_delay_sec: Time to delay a reconnect retry.
719        If ctrlr_loss_timeout_sec is zero, reconnect_delay_sec has to be zero.
720        If ctrlr_loss_timeout_sec is -1, reconnect_delay_sec has to be non-zero.
721        If ctrlr_loss_timeout_sec is not -1 or zero, reconnect_sec has to be non-zero and less than ctrlr_loss_timeout_sec.
722        (optional)
723        fast_io_fail_timeout_sec: Time to wait until ctrlr is reconnected before failing I/O to ctrlr.
724        0 means no such timeout.
725        If fast_io_fail_timeout_sec is not zero, it has to be not less than reconnect_delay_sec and less than
726        ctrlr_loss_timeout_sec if ctrlr_loss_timeout_sec is not -1. (optional)
727        psk: Set PSK file path and enable TCP SSL socket implementation (optional)
728        max_bdevs: Size of the name array for newly created bdevs. Default is 128. (optional)
729        dhchap_key: DH-HMAC-CHAP key name.
730        dhchap_ctrlr_key: DH-HMAC-CHAP controller key name.
731    Returns:
732        Names of created block devices.
733    """
734    params = dict()
735    params['name'] = name
736    params['trtype'] = trtype
737    params['traddr'] = traddr
738    if adrfam is not None:
739        params['adrfam'] = adrfam
740    if trsvcid is not None:
741        params['trsvcid'] = trsvcid
742    if priority is not None:
743        params['priority'] = priority
744    if subnqn is not None:
745        params['subnqn'] = subnqn
746    if hostnqn is not None:
747        params['hostnqn'] = hostnqn
748    if hostaddr is not None:
749        params['hostaddr'] = hostaddr
750    if hostsvcid is not None:
751        params['hostsvcid'] = hostsvcid
752    if prchk_reftag is not None:
753        params['prchk_reftag'] = prchk_reftag
754    if prchk_guard is not None:
755        params['prchk_guard'] = prchk_guard
756    if hdgst is not None:
757        params['hdgst'] = hdgst
758    if ddgst is not None:
759        params['ddgst'] = ddgst
760    if fabrics_connect_timeout_us is not None:
761        params['fabrics_connect_timeout_us'] = fabrics_connect_timeout_us
762    if multipath is not None:
763        params['multipath'] = multipath
764    if num_io_queues is not None:
765        params['num_io_queues'] = num_io_queues
766    if ctrlr_loss_timeout_sec is not None:
767        params['ctrlr_loss_timeout_sec'] = ctrlr_loss_timeout_sec
768    if reconnect_delay_sec is not None:
769        params['reconnect_delay_sec'] = reconnect_delay_sec
770    if fast_io_fail_timeout_sec is not None:
771        params['fast_io_fail_timeout_sec'] = fast_io_fail_timeout_sec
772    if psk is not None:
773        params['psk'] = psk
774    if max_bdevs is not None:
775        params['max_bdevs'] = max_bdevs
776    if dhchap_key is not None:
777        params['dhchap_key'] = dhchap_key
778    if dhchap_ctrlr_key is not None:
779        params['dhchap_ctrlr_key'] = dhchap_ctrlr_key
780    return client.call('bdev_nvme_attach_controller', params)
781
782
783def bdev_nvme_detach_controller(client, name, trtype=None, traddr=None,
784                                adrfam=None, trsvcid=None, subnqn=None,
785                                hostaddr=None, hostsvcid=None):
786    """Detach NVMe controller and delete any associated bdevs. Optionally,
787       If all of the transport ID options are specified, only remove that
788       transport path from the specified controller. If that is the only
789       available path for the controller, this will also result in the
790       controller being detached and the associated bdevs being deleted.
791    Args:
792        name: controller name
793        trtype: transport type ("PCIe", "RDMA")
794        traddr: transport address (PCI BDF or IP address)
795        adrfam: address family ("IPv4", "IPv6", "IB", or "FC")
796        trsvcid: transport service ID (port number for IP-based addresses)
797        subnqn: subsystem NQN to connect to (optional)
798        hostaddr: Host address (IP address)
799        hostsvcid: transport service ID on host side (port number)
800    """
801    params = dict()
802    params['name'] = name
803    if trtype is not None:
804        params['trtype'] = trtype
805    if traddr is not None:
806        params['traddr'] = traddr
807    if adrfam is not None:
808        params['adrfam'] = adrfam
809    if trsvcid is not None:
810        params['trsvcid'] = trsvcid
811    if subnqn is not None:
812        params['subnqn'] = subnqn
813    if hostaddr is not None:
814        params['hostaddr'] = hostaddr
815    if hostsvcid is not None:
816        params['hostsvcid'] = hostsvcid
817    return client.call('bdev_nvme_detach_controller', params)
818
819
820def bdev_nvme_reset_controller(client, name, cntlid=None):
821    """Reset an NVMe controller or all NVMe controllers in an NVMe bdev controller.
822    Args:
823        name: controller name
824        cntlid: NVMe controller ID (optional)
825    """
826    params = dict()
827    params['name'] = name
828    if cntlid is not None:
829        params['cntlid'] = cntlid
830    return client.call('bdev_nvme_reset_controller', params)
831
832
833def bdev_nvme_enable_controller(client, name, cntlid=None):
834    """Enable an NVMe controller or all NVMe controllers in an NVMe bdev controller.
835    Args:
836        name: controller name
837        cntlid: NVMe controller ID (optional)
838    """
839    params = dict()
840    params['name'] = name
841    if cntlid is not None:
842        params['cntlid'] = cntlid
843    return client.call('bdev_nvme_enable_controller', params)
844
845
846def bdev_nvme_disable_controller(client, name, cntlid=None):
847    """Disable an NVMe controller or all NVMe controllers in an NVMe bdev controller.
848    Args:
849        name: controller name
850        cntlid: NVMe controller ID (optional)
851    """
852    params = dict()
853    params['name'] = name
854    if cntlid is not None:
855        params['cntlid'] = cntlid
856    return client.call('bdev_nvme_disable_controller', params)
857
858
859def bdev_nvme_start_discovery(client, name, trtype, traddr, adrfam=None, trsvcid=None,
860                              hostnqn=None, wait_for_attach=None, ctrlr_loss_timeout_sec=None,
861                              reconnect_delay_sec=None, fast_io_fail_timeout_sec=None,
862                              attach_timeout_ms=None):
863    """Start discovery with the specified discovery subsystem
864    Args:
865        name: bdev name prefix; "n" + namespace ID will be appended to create unique names
866        trtype: transport type ("PCIe", "RDMA", "FC", "TCP")
867        traddr: transport address (PCI BDF or IP address)
868        adrfam: address family ("IPv4", "IPv6", "IB", or "FC")
869        trsvcid: transport service ID (port number for IP-based addresses)
870        hostnqn: NQN to connect from (optional)
871        wait_for_attach: Wait to complete RPC until all discovered NVM subsystems have attached (optional)
872        ctrlr_loss_timeout_sec: Time to wait until ctrlr is reconnected before deleting ctrlr.
873        -1 means infinite reconnect retries. 0 means no reconnect retry.
874        If reconnect_delay_sec is zero, ctrlr_loss_timeout_sec has to be zero.
875        If reconnect_delay_sec is non-zero, ctrlr_loss_timeout_sec has to be -1 or not less than reconnect_delay_sec.
876        (optional)
877        reconnect_delay_sec: Time to delay a reconnect retry.
878        If ctrlr_loss_timeout_sec is zero, reconnect_delay_sec has to be zero.
879        If ctrlr_loss_timeout_sec is -1, reconnect_delay_sec has to be non-zero.
880        If ctrlr_loss_timeout_sec is not -1 or zero, reconnect_sec has to be non-zero and less than ctrlr_loss_timeout_sec.
881        (optional)
882        fast_io_fail_timeout_sec: Time to wait until ctrlr is reconnected before failing I/O to ctrlr.
883        0 means no such timeout.
884        If fast_io_fail_timeout_sec is not zero, it has to be not less than reconnect_delay_sec and less than
885        ctrlr_loss_timeout_sec if ctrlr_loss_timeout_sec is not -1. (optional)
886        attach_timeout_ms: Time to wait until the discovery and all discovered NVM subsystems are attached (optional)
887    """
888    params = dict()
889    params['name'] = name
890    params['trtype'] = trtype
891    params['traddr'] = traddr
892    if adrfam is not None:
893        params['adrfam'] = adrfam
894    if trsvcid is not None:
895        params['trsvcid'] = trsvcid
896    if hostnqn is not None:
897        params['hostnqn'] = hostnqn
898    if wait_for_attach is not None:
899        params['wait_for_attach'] = wait_for_attach
900    if ctrlr_loss_timeout_sec is not None:
901        params['ctrlr_loss_timeout_sec'] = ctrlr_loss_timeout_sec
902    if reconnect_delay_sec is not None:
903        params['reconnect_delay_sec'] = reconnect_delay_sec
904    if fast_io_fail_timeout_sec is not None:
905        params['fast_io_fail_timeout_sec'] = fast_io_fail_timeout_sec
906    if attach_timeout_ms is not None:
907        params['attach_timeout_ms'] = attach_timeout_ms
908    return client.call('bdev_nvme_start_discovery', params)
909
910
911def bdev_nvme_stop_discovery(client, name):
912    """Stop a previously started discovery service
913    Args:
914        name: name of discovery service to start
915    """
916    params = dict()
917    params['name'] = name
918    return client.call('bdev_nvme_stop_discovery', params)
919
920
921def bdev_nvme_get_discovery_info(client):
922    """Get information about the automatic discovery
923    """
924    return client.call('bdev_nvme_get_discovery_info')
925
926
927def bdev_nvme_get_io_paths(client, name=None):
928    """Display all or the specified NVMe bdev's active I/O paths
929    Args:
930        name: Name of the NVMe bdev (optional)
931    Returns:
932        List of active I/O paths
933    """
934    params = dict()
935    if name is not None:
936        params['name'] = name
937    return client.call('bdev_nvme_get_io_paths', params)
938
939
940def bdev_nvme_set_preferred_path(client, name, cntlid):
941    """Set the preferred I/O path for an NVMe bdev when in multipath mode
942    Args:
943        name: NVMe bdev name
944        cntlid: NVMe-oF controller ID
945    """
946    params = dict()
947    params['name'] = name
948    params['cntlid'] = cntlid
949    return client.call('bdev_nvme_set_preferred_path', params)
950
951
952def bdev_nvme_set_multipath_policy(client, name, policy, selector=None, rr_min_io=None):
953    """Set multipath policy of the NVMe bdev
954    Args:
955        name: NVMe bdev name
956        policy: Multipath policy (active_passive or active_active)
957        selector: Multipath selector (round_robin, queue_depth)
958        rr_min_io: Number of IO to route to a path before switching to another one (optional)
959    """
960    params = dict()
961    params['name'] = name
962    params['policy'] = policy
963    if selector is not None:
964        params['selector'] = selector
965    if rr_min_io is not None:
966        params['rr_min_io'] = rr_min_io
967    return client.call('bdev_nvme_set_multipath_policy', params)
968
969
970def bdev_nvme_get_path_iostat(client, name):
971    """Get I/O statistics for IO paths of the block device.
972    Args:
973        name: bdev name to query
974    Returns:
975        I/O statistics for IO paths of the requested block device.
976    """
977    params = dict()
978    params['name'] = name
979    return client.call('bdev_nvme_get_path_iostat', params)
980
981
982def bdev_nvme_cuse_register(client, name):
983    """Register CUSE devices on NVMe controller.
984    Args:
985        name: Name of the operating NVMe controller
986    """
987    params = dict()
988    params['name'] = name
989    return client.call('bdev_nvme_cuse_register', params)
990
991
992def bdev_nvme_cuse_unregister(client, name):
993    """Unregister CUSE devices on NVMe controller.
994    Args:
995        name: Name of the operating NVMe controller
996    """
997    params = dict()
998    params['name'] = name
999    return client.call('bdev_nvme_cuse_unregister', params)
1000
1001
1002def bdev_zone_block_create(client, name, base_bdev, zone_capacity, optimal_open_zones):
1003    """Creates a virtual zone device on top of existing non-zoned bdev.
1004    Args:
1005        name: Zone device name
1006        base_bdev: Base Nvme bdev name
1007        zone_capacity: Surfaced zone capacity in blocks
1008        optimal_open_zones: Number of zones required to reach optimal write speed (optional, default: 1)
1009    Returns:
1010        Name of created block device.
1011    """
1012    params = dict()
1013    params['name'] = name
1014    params['base_bdev'] = base_bdev
1015    params['zone_capacity'] = zone_capacity
1016    params['optimal_open_zones'] = optimal_open_zones
1017    return client.call('bdev_zone_block_create', params)
1018
1019
1020def bdev_zone_block_delete(client, name):
1021    """Remove block zone bdev from the system.
1022    Args:
1023        name: name of block zone bdev to delete
1024    """
1025    params = dict()
1026    params['name'] = name
1027    return client.call('bdev_zone_block_delete', params)
1028
1029
1030def bdev_rbd_register_cluster(client, name=None, user_id=None, config_param=None, config_file=None, key_file=None, core_mask=None):
1031    """Create a Rados Cluster object of the Ceph RBD backend.
1032    Args:
1033        name: name of Rados Cluster
1034        user_id: Ceph user name (optional)
1035        config_param: map of config keys to values (optional)
1036        config_file: file path of Ceph configuration file (optional)
1037        key_file: file path of Ceph key file (optional)
1038        core_mask: core mask for librbd IO context threads (optional)
1039    Returns:
1040        Name of registered Rados Cluster object.
1041    """
1042    params = dict()
1043    if name is not None:
1044        params['name'] = name
1045    if user_id is not None:
1046        params['user_id'] = user_id
1047    if config_param is not None:
1048        params['config_param'] = config_param
1049    if config_file is not None:
1050        params['config_file'] = config_file
1051    if key_file is not None:
1052        params['key_file'] = key_file
1053    if core_mask is not None:
1054        params['core_mask'] = core_mask
1055    return client.call('bdev_rbd_register_cluster', params)
1056
1057
1058def bdev_rbd_unregister_cluster(client, name):
1059    """Remove Rados cluster object from the system.
1060    Args:
1061        name: name of Rados cluster object to unregister
1062    """
1063    params = dict()
1064    params['name'] = name
1065    return client.call('bdev_rbd_unregister_cluster', params)
1066
1067
1068def bdev_rbd_get_clusters_info(client, name=None):
1069    """Get the cluster(s) info
1070    Args:
1071        name: name of Rados cluster object to query (optional; if omitted, query all clusters)
1072    Returns:
1073        List of registered Rados cluster information objects.
1074    """
1075    params = dict()
1076    if name is not None:
1077        params['name'] = name
1078    return client.call('bdev_rbd_get_clusters_info', params)
1079
1080
1081def bdev_rbd_create(client, pool_name, rbd_name, block_size, name=None, user_id=None, config=None, cluster_name=None, uuid=None):
1082    """Create a Ceph RBD block device.
1083    Args:
1084        pool_name: Ceph RBD pool name
1085        rbd_name: Ceph RBD image name
1086        block_size: block size of RBD volume
1087        name: name of block device (optional)
1088        user_id: Ceph user name (optional)
1089        config: map of config keys to values (optional)
1090        cluster_name: Name to identify Rados cluster (optional)
1091        uuid: UUID of block device (optional)
1092    Returns:
1093        Name of created block device.
1094    """
1095    params = dict()
1096    params['pool_name'] = pool_name
1097    params['rbd_name'] = rbd_name
1098    params['block_size'] = block_size
1099    if name is not None:
1100        params['name'] = name
1101    if user_id is not None:
1102        params['user_id'] = user_id
1103    if config is not None:
1104        params['config'] = config
1105    if cluster_name is not None:
1106        params['cluster_name'] = cluster_name
1107    else:
1108        print("WARNING:bdev_rbd_create should be used with specifying -c to have a cluster name after bdev_rbd_register_cluster.")
1109    if uuid is not None:
1110        params['uuid'] = uuid
1111    return client.call('bdev_rbd_create', params)
1112
1113
1114def bdev_rbd_delete(client, name):
1115    """Remove rbd bdev from the system.
1116    Args:
1117        name: name of rbd bdev to delete
1118    """
1119    params = dict()
1120    params['name'] = name
1121    return client.call('bdev_rbd_delete', params)
1122
1123
1124def bdev_rbd_resize(client, name, new_size):
1125    """Resize rbd bdev in the system.
1126    Args:
1127        name: name of rbd bdev to resize
1128        new_size: new bdev size of resize operation. The unit is MiB
1129    """
1130    params = dict()
1131    params['name'] = name
1132    params['new_size'] = new_size
1133    return client.call('bdev_rbd_resize', params)
1134
1135
1136def bdev_error_create(client, base_name, uuid=None):
1137    """Construct an error injection block device.
1138    Args:
1139        base_name: base bdev name
1140        uuid: UUID for this bdev (optional)
1141    """
1142    params = dict()
1143    params['base_name'] = base_name
1144    if uuid is not None:
1145        params['uuid'] = uuid
1146    return client.call('bdev_error_create', params)
1147
1148
1149def bdev_delay_create(client, base_bdev_name, name, avg_read_latency, p99_read_latency, avg_write_latency, p99_write_latency, uuid=None):
1150    """Construct a delay block device.
1151    Args:
1152        base_bdev_name: name of the existing bdev
1153        name: name of block device
1154        avg_read_latency: complete 99% of read ops with this delay
1155        p99_read_latency: complete 1% of read ops with this delay
1156        avg_write_latency: complete 99% of write ops with this delay
1157        p99_write_latency: complete 1% of write ops with this delay
1158        uuid: UUID of block device (optional)
1159    Returns:
1160        Name of created block device.
1161    """
1162    params = dict()
1163    params['base_bdev_name'] = base_bdev_name
1164    params['name'] = name
1165    params['avg_read_latency'] = avg_read_latency
1166    params['p99_read_latency'] = p99_read_latency
1167    params['avg_write_latency'] = avg_write_latency
1168    params['p99_write_latency'] = p99_write_latency
1169    if uuid is not None:
1170        params['uuid'] = uuid
1171    return client.call('bdev_delay_create', params)
1172
1173
1174def bdev_delay_delete(client, name):
1175    """Remove delay bdev from the system.
1176    Args:
1177        name: name of delay bdev to delete
1178    """
1179    params = dict()
1180    params['name'] = name
1181    return client.call('bdev_delay_delete', params)
1182
1183
1184def bdev_delay_update_latency(client, delay_bdev_name, latency_type, latency_us):
1185    """Update the latency value for a delay block device
1186    Args:
1187        delay_bdev_name: name of the delay bdev
1188        latency_type: 'one of: avg_read, avg_write, p99_read, p99_write. No other values accepted.'
1189        latency_us: 'new latency value.'
1190    Returns:
1191        True if successful, or a specific error otherwise.
1192    """
1193    params = dict()
1194    params['delay_bdev_name'] = delay_bdev_name
1195    params['latency_type'] = latency_type
1196    params['latency_us'] = latency_us
1197    return client.call('bdev_delay_update_latency', params)
1198
1199
1200def bdev_error_delete(client, name):
1201    """Remove error bdev from the system.
1202    Args:
1203        bdev_name: name of error bdev to delete
1204    """
1205    params = dict()
1206    params['name'] = name
1207    return client.call('bdev_error_delete', params)
1208
1209
1210def bdev_iscsi_set_options(client, timeout_sec=None):
1211    """Set options for the bdev iscsi.
1212    Args:
1213        timeout_sec: Timeout for command, in seconds, if 0, don't track timeout
1214    """
1215    params = dict()
1216    if timeout_sec is not None:
1217        params['timeout_sec'] = timeout_sec
1218    return client.call('bdev_iscsi_set_options', params)
1219
1220
1221def bdev_iscsi_create(client, name, url, initiator_iqn):
1222    """Construct an iSCSI block device.
1223    Args:
1224        name: name of block device
1225        url: iSCSI URL
1226        initiator_iqn: IQN name to be used by initiator
1227    Returns:
1228        Name of created block device.
1229    """
1230    params = dict()
1231    params['name'] = name
1232    params['url'] = url
1233    params['initiator_iqn'] = initiator_iqn
1234    return client.call('bdev_iscsi_create', params)
1235
1236
1237def bdev_iscsi_delete(client, name):
1238    """Remove iSCSI bdev from the system.
1239    Args:
1240        bdev_name: name of iSCSI bdev to delete
1241    """
1242    params = dict()
1243    params['name'] = name
1244    return client.call('bdev_iscsi_delete', params)
1245
1246
1247def bdev_passthru_create(client, base_bdev_name, name, uuid=None):
1248    """Construct a pass-through block device.
1249    Args:
1250        base_bdev_name: name of the existing bdev
1251        name: name of block device
1252        uuid: UUID of block device (optional)
1253    Returns:
1254        Name of created block device.
1255    """
1256    params = dict()
1257    params['base_bdev_name'] = base_bdev_name
1258    params['name'] = name
1259    if uuid is not None:
1260        params['uuid'] = uuid
1261    return client.call('bdev_passthru_create', params)
1262
1263
1264def bdev_passthru_delete(client, name):
1265    """Remove pass through bdev from the system.
1266    Args:
1267        name: name of pass through bdev to delete
1268    """
1269    params = dict()
1270    params['name'] = name
1271    return client.call('bdev_passthru_delete', params)
1272
1273
1274def bdev_opal_create(client, nvme_ctrlr_name, nsid, locking_range_id, range_start, range_length, password):
1275    """Create opal virtual block devices from a base nvme bdev.
1276    Args:
1277        nvme_ctrlr_name: name of the nvme ctrlr
1278        nsid: namespace ID of nvme ctrlr
1279        locking_range_id: locking range ID corresponding to this virtual bdev
1280        range_start: start address of this locking range
1281        range_length: length of this locking range
1282        password: admin password of base nvme bdev
1283    Returns:
1284        Name of the new created block devices.
1285    """
1286    params = dict()
1287    params['nvme_ctrlr_name'] = nvme_ctrlr_name
1288    params['nsid'] = nsid
1289    params['locking_range_id'] = locking_range_id
1290    params['range_start'] = range_start
1291    params['range_length'] = range_length
1292    params['password'] = password
1293    return client.call('bdev_opal_create', params)
1294
1295
1296def bdev_opal_get_info(client, bdev_name, password):
1297    """Get opal locking range info.
1298    Args:
1299        bdev_name: name of opal vbdev to get info
1300        password: admin password
1301    Returns:
1302        Locking range info.
1303    """
1304    params = dict()
1305    params['bdev_name'] = bdev_name
1306    params['password'] = password
1307    return client.call('bdev_opal_get_info', params)
1308
1309
1310def bdev_opal_delete(client, bdev_name, password):
1311    """Delete opal virtual bdev from the system.
1312    Args:
1313        bdev_name: name of opal vbdev to delete
1314        password: admin password of base nvme bdev
1315    """
1316    params = dict()
1317    params['bdev_name'] = bdev_name
1318    params['password'] = password
1319    return client.call('bdev_opal_delete', params)
1320
1321
1322def bdev_opal_new_user(client, bdev_name, admin_password, user_id, user_password):
1323    """Add a user to opal bdev who can set lock state for this bdev.
1324    Args:
1325        bdev_name: name of opal vbdev
1326        admin_password: admin password
1327        user_id: ID of the user who will be added to this opal bdev
1328        user_password: password set for this user
1329    """
1330    params = dict()
1331    params['bdev_name'] = bdev_name
1332    params['admin_password'] = admin_password
1333    params['user_id'] = user_id
1334    params['user_password'] = user_password
1335    return client.call('bdev_opal_new_user', params)
1336
1337
1338def bdev_opal_set_lock_state(client, bdev_name, user_id, password, lock_state):
1339    """set lock state for an opal bdev.
1340    Args:
1341        bdev_name: name of opal vbdev
1342        user_id: ID of the user who will set lock state
1343        password: password of the user
1344        lock_state: lock state to set
1345    """
1346    params = dict()
1347    params['bdev_name'] = bdev_name
1348    params['user_id'] = user_id
1349    params['password'] = password
1350    params['lock_state'] = lock_state
1351    return client.call('bdev_opal_set_lock_state', params)
1352
1353
1354def bdev_split_create(client, base_bdev, split_count, split_size_mb=None):
1355    """Create split block devices from a base bdev.
1356    Args:
1357        base_bdev: name of bdev to split
1358        split_count: number of split bdevs to create
1359        split_size_mb: size of each split volume in MiB (optional)
1360    Returns:
1361        List of created block devices.
1362    """
1363    params = dict()
1364    params['base_bdev'] = base_bdev
1365    params['split_count'] = split_count
1366    if split_size_mb is not None:
1367        params['split_size_mb'] = split_size_mb
1368    return client.call('bdev_split_create', params)
1369
1370
1371def bdev_split_delete(client, base_bdev):
1372    """Delete split block devices.
1373    Args:
1374        base_bdev: name of previously split bdev
1375    """
1376    params = dict()
1377    params['base_bdev'] = base_bdev
1378    return client.call('bdev_split_delete', params)
1379
1380
1381def bdev_ftl_create(client, name, base_bdev, cache, **kwargs):
1382    """Construct FTL bdev
1383    Args:
1384        name: name of the bdev
1385        base_bdev: name of the base bdev
1386        cache: name of the cache device
1387        kwargs: optional parameters
1388    """
1389    params = dict()
1390    params['name'] = name
1391    params['base_bdev'] = base_bdev
1392    params['cache'] = cache
1393    for key, value in kwargs.items():
1394        if value is not None:
1395            params[key] = value
1396    return client.call('bdev_ftl_create', params)
1397
1398
1399def bdev_ftl_load(client, name, base_bdev, cache, **kwargs):
1400    """Load FTL bdev
1401    Args:
1402        name: name of the bdev
1403        base_bdev: name of the base bdev
1404        cache: Name of the cache device
1405        kwargs: optional parameters
1406    """
1407    params = dict()
1408    params['name'] = name
1409    params['base_bdev'] = base_bdev
1410    params['cache'] = cache
1411    for key, value in kwargs.items():
1412        if value is not None:
1413            params[key] = value
1414    return client.call('bdev_ftl_load', params)
1415
1416
1417def bdev_ftl_unload(client, name, fast_shutdown=None):
1418    """Unload FTL bdev
1419    Args:
1420        name: name of the bdev
1421        fast_shutdown: When set FTL will minimize persisted data during deletion and rely on shared memory during next load
1422    """
1423    params = dict()
1424    params['name'] = name
1425    if fast_shutdown is not None:
1426        params['fast_shutdown'] = fast_shutdown
1427    return client.call('bdev_ftl_unload', params)
1428
1429
1430def bdev_ftl_delete(client, name, fast_shutdown=None):
1431    """Delete FTL bdev
1432    Args:
1433        name: name of the bdev
1434        fast_shutdown: When set FTL will minimize persisted data during deletion and rely on shared memory during next load
1435    """
1436    params = dict()
1437    params['name'] = name
1438    if fast_shutdown is not None:
1439        params['fast_shutdown'] = fast_shutdown
1440    return client.call('bdev_ftl_delete', params)
1441
1442
1443def bdev_ftl_unmap(client, name, lba, num_blocks):
1444    """FTL unmap
1445    Args:
1446        name: name of the bdev
1447        lba: starting lba to be unmapped
1448        num_blocks: number of blocks to unmap
1449    """
1450    params = dict()
1451    params['name'] = name
1452    params['lba'] = lba
1453    params['num_blocks'] = num_blocks
1454    return client.call('bdev_ftl_unmap', params)
1455
1456
1457def bdev_ftl_get_stats(client, name):
1458    """get FTL stats
1459    Args:
1460        name: name of the bdev
1461    """
1462    params = dict()
1463    params['name'] = name
1464    return client.call('bdev_ftl_get_stats', params)
1465
1466
1467def bdev_ftl_get_properties(client, name):
1468    """Get FTL properties
1469    Args:
1470        name: name of the bdev
1471    """
1472    params = dict()
1473    params['name'] = name
1474    return client.call('bdev_ftl_get_properties', params)
1475
1476
1477def bdev_ftl_set_property(client, name, ftl_property, value):
1478    """Set FTL property
1479    Args:
1480        name: name of the bdev
1481        ftl_property: name of the property to be set
1482        value: The new value of the updated property
1483    """
1484    params = dict()
1485    params['name'] = name
1486    params['ftl_property'] = ftl_property
1487    params['value'] = value
1488    return client.call('bdev_ftl_set_property', params)
1489
1490
1491def bdev_get_bdevs(client, name=None, timeout=None):
1492    """Get information about block devices.
1493    Args:
1494        name: bdev name to query (optional; if omitted, query all bdevs)
1495        timeout: time in ms to wait for the bdev with specified name to appear
1496    Returns:
1497        List of bdev information objects.
1498    """
1499    params = dict()
1500    if name is not None:
1501        params['name'] = name
1502    if timeout is not None:
1503        params['timeout'] = timeout
1504    return client.call('bdev_get_bdevs', params)
1505
1506
1507def bdev_get_iostat(client, name=None, per_channel=None):
1508    """Get I/O statistics for block devices.
1509    Args:
1510        name: bdev name to query (optional; if omitted, query all bdevs)
1511        per_channel: display per channel IO stats for specified bdev
1512    Returns:
1513        I/O statistics for the requested block devices.
1514    """
1515    params = dict()
1516    if name is not None:
1517        params['name'] = name
1518    if per_channel is not None:
1519        params['per_channel'] = per_channel
1520    return client.call('bdev_get_iostat', params)
1521
1522
1523def bdev_reset_iostat(client, name=None, mode=None):
1524    """Reset I/O statistics for block devices.
1525    Args:
1526        name: bdev name to reset (optional; if omitted, reset all bdevs)
1527        mode: mode to reset: all, maxmin (optional: if omitted, reset all fields)
1528    """
1529    params = dict()
1530    if name is not None:
1531        params['name'] = name
1532    if mode is not None:
1533        params['mode'] = mode
1534    return client.call('bdev_reset_iostat', params)
1535
1536
1537def bdev_enable_histogram(client, name, enable):
1538    """Control whether histogram is enabled for specified bdev.
1539    Args:
1540        name: name of bdev
1541        enable: Enable or disable histogram on specified device
1542    """
1543    params = dict()
1544    params['name'] = name
1545    params['enable'] = enable
1546    return client.call('bdev_enable_histogram', params)
1547
1548
1549def bdev_get_histogram(client, name):
1550    """Get histogram for specified bdev.
1551    Args:
1552        name: name of bdev
1553    """
1554    params = dict()
1555    params['name'] = name
1556    return client.call('bdev_get_histogram', params)
1557
1558
1559def bdev_error_inject_error(client, name, io_type, error_type, num=None,
1560                            queue_depth=None, corrupt_offset=None, corrupt_value=None):
1561    """Inject an error via an error bdev.
1562    Args:
1563        name: name of error bdev
1564        io_type: one of "clear", "read", "write", "unmap", "flush", or "all"
1565        error_type: one of "failure", "pending", "corrupt_data" or "nomem"
1566        num: number of commands to fail
1567        queue_depth: the queue depth at which to trigger the error
1568        corrupt_offset: offset in bytes to xor with corrupt_value
1569        corrupt_value: value for xor (1-255, 0 is invalid)
1570    """
1571    params = dict()
1572    params['name'] = name
1573    params['io_type'] = io_type
1574    params['error_type'] = error_type
1575    if num is not None:
1576        params['num'] = num
1577    if queue_depth is not None:
1578        params['queue_depth'] = queue_depth
1579    if corrupt_offset is not None:
1580        params['corrupt_offset'] = corrupt_offset
1581    if corrupt_value is not None:
1582        params['corrupt_value'] = corrupt_value
1583    return client.call('bdev_error_inject_error', params)
1584
1585
1586def bdev_set_qd_sampling_period(client, name, period):
1587    """Enable queue depth tracking on a specified bdev.
1588    Args:
1589        name: name of a bdev on which to track queue depth.
1590        period: period (in microseconds) at which to update the queue depth reading. If set to 0, polling will be disabled.
1591    """
1592    params = dict()
1593    params['name'] = name
1594    params['period'] = period
1595    return client.call('bdev_set_qd_sampling_period', params)
1596
1597
1598def bdev_set_qos_limit(
1599        client,
1600        name,
1601        rw_ios_per_sec=None,
1602        rw_mbytes_per_sec=None,
1603        r_mbytes_per_sec=None,
1604        w_mbytes_per_sec=None):
1605    """Set QoS rate limit on a block device.
1606    Args:
1607        name: name of block device
1608        rw_ios_per_sec: R/W IOs per second limit (>=1000, example: 20000). 0 means unlimited.
1609        rw_mbytes_per_sec: R/W megabytes per second limit (>=10, example: 100). 0 means unlimited.
1610        r_mbytes_per_sec: Read megabytes per second limit (>=10, example: 100). 0 means unlimited.
1611        w_mbytes_per_sec: Write megabytes per second limit (>=10, example: 100). 0 means unlimited.
1612    """
1613    params = dict()
1614    params['name'] = name
1615    if rw_ios_per_sec is not None:
1616        params['rw_ios_per_sec'] = rw_ios_per_sec
1617    if rw_mbytes_per_sec is not None:
1618        params['rw_mbytes_per_sec'] = rw_mbytes_per_sec
1619    if r_mbytes_per_sec is not None:
1620        params['r_mbytes_per_sec'] = r_mbytes_per_sec
1621    if w_mbytes_per_sec is not None:
1622        params['w_mbytes_per_sec'] = w_mbytes_per_sec
1623    return client.call('bdev_set_qos_limit', params)
1624
1625
1626def bdev_nvme_apply_firmware(client, bdev_name, filename):
1627    """Download and commit firmware to NVMe device.
1628    Args:
1629        bdev_name: name of NVMe block device
1630        filename: filename of the firmware to download
1631    """
1632    params = dict()
1633    params['bdev_name'] = bdev_name
1634    params['filename'] = filename
1635    return client.call('bdev_nvme_apply_firmware', params)
1636
1637
1638def bdev_nvme_get_transport_statistics(client):
1639    """Get bdev_nvme poll group transport statistics"""
1640    return client.call('bdev_nvme_get_transport_statistics')
1641
1642
1643def bdev_nvme_get_controller_health_info(client, name):
1644    """Display health log of the required NVMe bdev controller.
1645    Args:
1646        name: name of the required NVMe bdev controller
1647    Returns:
1648        Health log for the requested NVMe bdev controller.
1649    """
1650    params = dict()
1651    params['name'] = name
1652    return client.call('bdev_nvme_get_controller_health_info', params)
1653
1654
1655def bdev_daos_create(client, num_blocks, block_size, pool, cont, name, oclass=None, uuid=None):
1656    """Construct DAOS block device.
1657    Args:
1658        num_blocks: size of block device in blocks
1659        block_size: block size of device; must be a power of 2 and at least 512
1660        pool: UUID of DAOS pool
1661        cont: UUID of DAOS container
1662        name: name of block device (also the name of the backend file on DAOS DFS)
1663        oclass: DAOS object class (optional)
1664        uuid: UUID of block device (optional)
1665    Returns:
1666        Name of created block device.
1667    """
1668    params = dict()
1669    params['num_blocks'] = num_blocks
1670    params['block_size'] = block_size
1671    params['pool'] = pool
1672    params['cont'] = cont
1673    params['name'] = name
1674    if oclass is not None:
1675        params['oclass'] = oclass
1676    if uuid is not None:
1677        params['uuid'] = uuid
1678    return client.call('bdev_daos_create', params)
1679
1680
1681def bdev_daos_delete(client, name):
1682    """Delete DAOS block device.
1683    Args:
1684        bdev_name: name of DAOS bdev to delete
1685    """
1686    params = dict()
1687    params['name'] = name
1688    return client.call('bdev_daos_delete', params)
1689
1690
1691def bdev_daos_resize(client, name, new_size):
1692    """Resize DAOS bdev in the system.
1693    Args:
1694        name: name of DAOS bdev to resize
1695        new_size: new bdev size of resize operation. The unit is MiB
1696    """
1697    params = dict()
1698    params['name'] = name
1699    params['new_size'] = new_size
1700    return client.call('bdev_daos_resize', params)
1701
1702
1703def bdev_nvme_start_mdns_discovery(client, name, svcname, hostnqn=None):
1704    """Start discovery with mDNS
1705    Args:
1706        name: bdev name prefix; "n" + unique seqno + namespace ID will be appended to create unique names
1707        svcname: service to discover ("_nvme-disc._tcp")
1708        hostnqn: NQN to connect from (optional)
1709    """
1710    params = dict()
1711    params['name'] = name
1712    params['svcname'] = svcname
1713    if hostnqn is not None:
1714        params['hostnqn'] = hostnqn
1715    return client.call('bdev_nvme_start_mdns_discovery', params)
1716
1717
1718def bdev_nvme_stop_mdns_discovery(client, name):
1719    """Stop a previously started mdns discovery service
1720    Args:
1721        name: name of the discovery service to stop
1722    """
1723    params = dict()
1724    params['name'] = name
1725    return client.call('bdev_nvme_stop_mdns_discovery', params)
1726
1727
1728def bdev_nvme_get_mdns_discovery_info(client):
1729    """Get information about the automatic mdns discovery
1730    """
1731    return client.call('bdev_nvme_get_mdns_discovery_info')
1732