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