xref: /spdk/python/spdk/rpc/bdev.py (revision d4d015a572e1af7b2818e44218c1e661a61545ec)
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=None):
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    if conserve_cpu is not None:
559        params['conserve_cpu'] = conserve_cpu
560    return client.call('bdev_xnvme_create', params)
561
562
563def bdev_xnvme_delete(client, name):
564    """Delete a xNVMe bdev.
565    Args:
566        name: name of xNVMe bdev to delete
567    """
568    params = dict()
569    params['name'] = name
570    return client.call('bdev_xnvme_delete', params)
571
572
573def bdev_nvme_set_options(client, action_on_timeout=None, timeout_us=None, timeout_admin_us=None,
574                          keep_alive_timeout_ms=None, arbitration_burst=None,
575                          low_priority_weight=None, medium_priority_weight=None, high_priority_weight=None,
576                          nvme_adminq_poll_period_us=None, nvme_ioq_poll_period_us=None, io_queue_requests=None,
577                          delay_cmd_submit=None, transport_retry_count=None, bdev_retry_count=None,
578                          transport_ack_timeout=None, ctrlr_loss_timeout_sec=None, reconnect_delay_sec=None,
579                          fast_io_fail_timeout_sec=None, disable_auto_failback=None, generate_uuids=None,
580                          transport_tos=None, nvme_error_stat=None, rdma_srq_size=None, io_path_stat=None,
581                          allow_accel_sequence=None, rdma_max_cq_size=None, rdma_cm_event_timeout_ms=None,
582                          dhchap_digests=None, dhchap_dhgroups=None):
583    """Set options for the bdev nvme. This is startup command.
584    Args:
585        action_on_timeout:  action to take on command time out. Valid values are: none, reset, abort (optional)
586        timeout_us: Timeout for each command, in microseconds. If 0, don't track timeouts (optional)
587        timeout_admin_us: Timeout for each admin command, in microseconds. If 0, treat same as io timeouts (optional)
588        keep_alive_timeout_ms: Keep alive timeout period in millisecond, default is 10s (optional)
589        arbitration_burst: The value is expressed as a power of two (optional)
590        low_priority_weight: The number of commands that may be executed from the low priority queue at one time (optional)
591        medium_priority_weight: The number of commands that may be executed from the medium priority queue at one time (optional)
592        high_priority_weight: The number of commands that may be executed from the high priority queue at one time (optional)
593        nvme_adminq_poll_period_us: How often the admin queue is polled for asynchronous events in microseconds (optional)
594        nvme_ioq_poll_period_us: How often to poll I/O queues for completions in microseconds (optional)
595        io_queue_requests: The number of requests allocated for each NVMe I/O queue. Default: 512 (optional)
596        delay_cmd_submit: Enable delayed NVMe command submission to allow batching of multiple commands (optional)
597        transport_retry_count: The number of attempts per I/O in the transport layer when an I/O fails (optional)
598        bdev_retry_count: The number of attempts per I/O in the bdev layer when an I/O fails. -1 means infinite retries. (optional)
599        transport_ack_timeout: Time to wait ack until packet retransmission for RDMA or until closes connection for TCP.
600        Range 0-31 where 0 is driver-specific default value (optional)
601        ctrlr_loss_timeout_sec: Time to wait until ctrlr is reconnected before deleting ctrlr.
602        -1 means infinite reconnect retries. 0 means no reconnect retry.
603        If reconnect_delay_sec is zero, ctrlr_loss_timeout_sec has to be zero.
604        If reconnect_delay_sec is non-zero, ctrlr_loss_timeout_sec has to be -1 or not less than reconnect_delay_sec.
605        This can be overridden by bdev_nvme_attach_controller. (optional)
606        reconnect_delay_sec: Time to delay a reconnect retry.
607        If ctrlr_loss_timeout_sec is zero, reconnect_delay_sec has to be zero.
608        If ctrlr_loss_timeout_sec is -1, reconnect_delay_sec has to be non-zero.
609        If ctrlr_loss_timeout_sec is not -1 or zero, reconnect_sec has to be non-zero and less than ctrlr_loss_timeout_sec.
610        This can be overridden by bdev_nvme_attach_controller. (optional)
611        fast_io_fail_timeout_sec: Time to wait until ctrlr is reconnected before failing I/O to ctrlr.
612        0 means no such timeout.
613        If fast_io_fail_timeout_sec is not zero, it has to be not less than reconnect_delay_sec and less than
614        ctrlr_loss_timeout_sec if ctrlr_loss_timeout_sec is not -1.
615        This can be overridden by bdev_nvme_attach_controller. (optional)
616        disable_auto_failback: Disable automatic failback. bdev_nvme_set_preferred_path can be used to do manual failback.
617        By default, immediately failback to the preferred I/O path if it is restored. (optional)
618        generate_uuids: Enable generation of unique identifiers for NVMe bdevs only if they do not provide UUID themselves.
619        These strings are based on device serial number and namespace ID and will always be the same for that device.
620        transport_tos: IPv4 Type of Service value. Only applicable for RDMA transports.
621        The default is 0 which means no TOS is applied. (optional)
622        nvme_error_stat: Enable collecting NVMe error counts. (optional)
623        rdma_srq_size: Set the size of a shared rdma receive queue. Default: 0 (disabled) (optional)
624        io_path_stat: Enable collection I/O path stat of each io path. (optional)
625        allow_accel_sequence: Allow NVMe bdevs to advertise support for accel sequences if the
626        controller also supports them. (optional)
627        rdma_max_cq_size: The maximum size of a rdma completion queue. Default: 0 (unlimited) (optional)
628        rdma_cm_event_timeout_ms: Time to wait for RDMA CM event. Only applicable for RDMA transports.
629        dhchap_digests: List of allowed DH-HMAC-CHAP digests. (optional)
630        dhchap_dhgroups: List of allowed DH-HMAC-CHAP DH groups. (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    return client.call('bdev_nvme_set_options', params)
692
693
694def bdev_nvme_set_hotplug(client, enable, period_us=None):
695    """Set options for the bdev nvme. This is startup command.
696    Args:
697       enable: True to enable hotplug, False to disable.
698       period_us: how often the hotplug is processed for insert and remove events. Set 0 to reset to default. (optional)
699    """
700    params = dict()
701    params['enable'] = enable
702    if period_us is not None:
703        params['period_us'] = period_us
704    return client.call('bdev_nvme_set_hotplug', params)
705
706
707def bdev_nvme_attach_controller(client, name, trtype, traddr, adrfam=None, trsvcid=None,
708                                priority=None, subnqn=None, hostnqn=None, hostaddr=None,
709                                hostsvcid=None, prchk_reftag=None, prchk_guard=None,
710                                hdgst=None, ddgst=None, fabrics_connect_timeout_us=None,
711                                multipath=None, num_io_queues=None, ctrlr_loss_timeout_sec=None,
712                                reconnect_delay_sec=None, fast_io_fail_timeout_sec=None,
713                                psk=None, max_bdevs=None, dhchap_key=None, dhchap_ctrlr_key=None,
714                                allow_unrecognized_csi=None):
715    """Construct block device for each NVMe namespace in the attached controller.
716    Args:
717        name: bdev name prefix; "n" + namespace ID will be appended to create unique names
718        trtype: transport type ("PCIe", "RDMA", "FC", "TCP")
719        traddr: transport address (PCI BDF or IP address)
720        adrfam: address family ("IPv4", "IPv6", "IB", or "FC")
721        trsvcid: transport service ID (port number for IP-based addresses)
722        priority: transport connection priority (Sock priority for TCP-based transports; optional)
723        subnqn: subsystem NQN to connect to (optional)
724        hostnqn: NQN to connect from (optional)
725        hostaddr: host transport address (IP address for IP-based transports, NULL for PCIe or FC; optional)
726        hostsvcid: host transport service ID (port number for IP-based transports, NULL for PCIe or FC; optional)
727        prchk_reftag: Enable checking of PI reference tag for I/O processing (optional)
728        prchk_guard: Enable checking of PI guard for I/O processing (optional)
729        hdgst: Enable TCP header digest (optional)
730        ddgst: Enable TCP data digest (optional)
731        fabrics_connect_timeout_us: Fabrics connect timeout in us (optional)
732        multipath: The behavior when multiple paths are created ("disable", "failover", or "multipath"; failover if not specified)
733        num_io_queues: The number of IO queues to request during initialization. (optional)
734        ctrlr_loss_timeout_sec: Time to wait until ctrlr is reconnected before deleting ctrlr.
735        -1 means infinite reconnect retries. 0 means no reconnect retry.
736        If reconnect_delay_sec is zero, ctrlr_loss_timeout_sec has to be zero.
737        If reconnect_delay_sec is non-zero, ctrlr_loss_timeout_sec has to be -1 or not less than reconnect_delay_sec.
738        (optional)
739        reconnect_delay_sec: Time to delay a reconnect retry.
740        If ctrlr_loss_timeout_sec is zero, reconnect_delay_sec has to be zero.
741        If ctrlr_loss_timeout_sec is -1, reconnect_delay_sec has to be non-zero.
742        If ctrlr_loss_timeout_sec is not -1 or zero, reconnect_sec has to be non-zero and less than ctrlr_loss_timeout_sec.
743        (optional)
744        fast_io_fail_timeout_sec: Time to wait until ctrlr is reconnected before failing I/O to ctrlr.
745        0 means no such timeout.
746        If fast_io_fail_timeout_sec is not zero, it has to be not less than reconnect_delay_sec and less than
747        ctrlr_loss_timeout_sec if ctrlr_loss_timeout_sec is not -1. (optional)
748        psk: Set PSK file path and enable TCP SSL socket implementation (optional)
749        max_bdevs: Size of the name array for newly created bdevs. Default is 128. (optional)
750        dhchap_key: DH-HMAC-CHAP key name.
751        dhchap_ctrlr_key: DH-HMAC-CHAP controller key name.
752        allow_unrecognized_csi: Allow attaching namespaces with unrecognized command set identifiers. These will only support NVMe
753        passthrough.
754    Returns:
755        Names of created block devices.
756    """
757    params = dict()
758    params['name'] = name
759    params['trtype'] = trtype
760    params['traddr'] = traddr
761    if adrfam is not None:
762        params['adrfam'] = adrfam
763    if trsvcid is not None:
764        params['trsvcid'] = trsvcid
765    if priority is not None:
766        params['priority'] = priority
767    if subnqn is not None:
768        params['subnqn'] = subnqn
769    if hostnqn is not None:
770        params['hostnqn'] = hostnqn
771    if hostaddr is not None:
772        params['hostaddr'] = hostaddr
773    if hostsvcid is not None:
774        params['hostsvcid'] = hostsvcid
775    if prchk_reftag is not None:
776        params['prchk_reftag'] = prchk_reftag
777    if prchk_guard is not None:
778        params['prchk_guard'] = prchk_guard
779    if hdgst is not None:
780        params['hdgst'] = hdgst
781    if ddgst is not None:
782        params['ddgst'] = ddgst
783    if fabrics_connect_timeout_us is not None:
784        params['fabrics_connect_timeout_us'] = fabrics_connect_timeout_us
785    if multipath is not None:
786        params['multipath'] = multipath
787    if num_io_queues is not None:
788        params['num_io_queues'] = num_io_queues
789    if ctrlr_loss_timeout_sec is not None:
790        params['ctrlr_loss_timeout_sec'] = ctrlr_loss_timeout_sec
791    if reconnect_delay_sec is not None:
792        params['reconnect_delay_sec'] = reconnect_delay_sec
793    if fast_io_fail_timeout_sec is not None:
794        params['fast_io_fail_timeout_sec'] = fast_io_fail_timeout_sec
795    if psk is not None:
796        params['psk'] = psk
797    if max_bdevs is not None:
798        params['max_bdevs'] = max_bdevs
799    if dhchap_key is not None:
800        params['dhchap_key'] = dhchap_key
801    if dhchap_ctrlr_key is not None:
802        params['dhchap_ctrlr_key'] = dhchap_ctrlr_key
803    if allow_unrecognized_csi is not None:
804        params['allow_unrecognized_csi'] = allow_unrecognized_csi
805    return client.call('bdev_nvme_attach_controller', params)
806
807
808def bdev_nvme_detach_controller(client, name, trtype=None, traddr=None,
809                                adrfam=None, trsvcid=None, subnqn=None,
810                                hostaddr=None, hostsvcid=None):
811    """Detach NVMe controller and delete any associated bdevs. Optionally,
812       If all of the transport ID options are specified, only remove that
813       transport path from the specified controller. If that is the only
814       available path for the controller, this will also result in the
815       controller being detached and the associated bdevs being deleted.
816    Args:
817        name: controller name
818        trtype: transport type ("PCIe", "RDMA")
819        traddr: transport address (PCI BDF or IP address)
820        adrfam: address family ("IPv4", "IPv6", "IB", or "FC")
821        trsvcid: transport service ID (port number for IP-based addresses)
822        subnqn: subsystem NQN to connect to (optional)
823        hostaddr: Host address (IP address)
824        hostsvcid: transport service ID on host side (port number)
825    """
826    params = dict()
827    params['name'] = name
828    if trtype is not None:
829        params['trtype'] = trtype
830    if traddr is not None:
831        params['traddr'] = traddr
832    if adrfam is not None:
833        params['adrfam'] = adrfam
834    if trsvcid is not None:
835        params['trsvcid'] = trsvcid
836    if subnqn is not None:
837        params['subnqn'] = subnqn
838    if hostaddr is not None:
839        params['hostaddr'] = hostaddr
840    if hostsvcid is not None:
841        params['hostsvcid'] = hostsvcid
842    return client.call('bdev_nvme_detach_controller', params)
843
844
845def bdev_nvme_reset_controller(client, name, cntlid=None):
846    """Reset an NVMe controller or all NVMe controllers in an NVMe bdev controller.
847    Args:
848        name: controller name
849        cntlid: NVMe controller ID (optional)
850    """
851    params = dict()
852    params['name'] = name
853    if cntlid is not None:
854        params['cntlid'] = cntlid
855    return client.call('bdev_nvme_reset_controller', params)
856
857
858def bdev_nvme_enable_controller(client, name, cntlid=None):
859    """Enable an NVMe controller or all NVMe controllers in an NVMe bdev controller.
860    Args:
861        name: controller name
862        cntlid: NVMe controller ID (optional)
863    """
864    params = dict()
865    params['name'] = name
866    if cntlid is not None:
867        params['cntlid'] = cntlid
868    return client.call('bdev_nvme_enable_controller', params)
869
870
871def bdev_nvme_disable_controller(client, name, cntlid=None):
872    """Disable an NVMe controller or all NVMe controllers in an NVMe bdev controller.
873    Args:
874        name: controller name
875        cntlid: NVMe controller ID (optional)
876    """
877    params = dict()
878    params['name'] = name
879    if cntlid is not None:
880        params['cntlid'] = cntlid
881    return client.call('bdev_nvme_disable_controller', params)
882
883
884def bdev_nvme_start_discovery(client, name, trtype, traddr, adrfam=None, trsvcid=None,
885                              hostnqn=None, wait_for_attach=None, ctrlr_loss_timeout_sec=None,
886                              reconnect_delay_sec=None, fast_io_fail_timeout_sec=None,
887                              attach_timeout_ms=None):
888    """Start discovery with the specified discovery subsystem
889    Args:
890        name: bdev name prefix; "n" + namespace ID will be appended to create unique names
891        trtype: transport type ("PCIe", "RDMA", "FC", "TCP")
892        traddr: transport address (PCI BDF or IP address)
893        adrfam: address family ("IPv4", "IPv6", "IB", or "FC")
894        trsvcid: transport service ID (port number for IP-based addresses)
895        hostnqn: NQN to connect from (optional)
896        wait_for_attach: Wait to complete RPC until all discovered NVM subsystems have attached (optional)
897        ctrlr_loss_timeout_sec: Time to wait until ctrlr is reconnected before deleting ctrlr.
898        -1 means infinite reconnect retries. 0 means no reconnect retry.
899        If reconnect_delay_sec is zero, ctrlr_loss_timeout_sec has to be zero.
900        If reconnect_delay_sec is non-zero, ctrlr_loss_timeout_sec has to be -1 or not less than reconnect_delay_sec.
901        (optional)
902        reconnect_delay_sec: Time to delay a reconnect retry.
903        If ctrlr_loss_timeout_sec is zero, reconnect_delay_sec has to be zero.
904        If ctrlr_loss_timeout_sec is -1, reconnect_delay_sec has to be non-zero.
905        If ctrlr_loss_timeout_sec is not -1 or zero, reconnect_sec has to be non-zero and less than ctrlr_loss_timeout_sec.
906        (optional)
907        fast_io_fail_timeout_sec: Time to wait until ctrlr is reconnected before failing I/O to ctrlr.
908        0 means no such timeout.
909        If fast_io_fail_timeout_sec is not zero, it has to be not less than reconnect_delay_sec and less than
910        ctrlr_loss_timeout_sec if ctrlr_loss_timeout_sec is not -1. (optional)
911        attach_timeout_ms: Time to wait until the discovery and all discovered NVM subsystems are attached (optional)
912    """
913    params = dict()
914    params['name'] = name
915    params['trtype'] = trtype
916    params['traddr'] = traddr
917    if adrfam is not None:
918        params['adrfam'] = adrfam
919    if trsvcid is not None:
920        params['trsvcid'] = trsvcid
921    if hostnqn is not None:
922        params['hostnqn'] = hostnqn
923    if wait_for_attach is not None:
924        params['wait_for_attach'] = wait_for_attach
925    if ctrlr_loss_timeout_sec is not None:
926        params['ctrlr_loss_timeout_sec'] = ctrlr_loss_timeout_sec
927    if reconnect_delay_sec is not None:
928        params['reconnect_delay_sec'] = reconnect_delay_sec
929    if fast_io_fail_timeout_sec is not None:
930        params['fast_io_fail_timeout_sec'] = fast_io_fail_timeout_sec
931    if attach_timeout_ms is not None:
932        params['attach_timeout_ms'] = attach_timeout_ms
933    return client.call('bdev_nvme_start_discovery', params)
934
935
936def bdev_nvme_stop_discovery(client, name):
937    """Stop a previously started discovery service
938    Args:
939        name: name of discovery service to start
940    """
941    params = dict()
942    params['name'] = name
943    return client.call('bdev_nvme_stop_discovery', params)
944
945
946def bdev_nvme_get_discovery_info(client):
947    """Get information about the automatic discovery
948    """
949    return client.call('bdev_nvme_get_discovery_info')
950
951
952def bdev_nvme_get_io_paths(client, name=None):
953    """Display all or the specified NVMe bdev's active I/O paths
954    Args:
955        name: Name of the NVMe bdev (optional)
956    Returns:
957        List of active I/O paths
958    """
959    params = dict()
960    if name is not None:
961        params['name'] = name
962    return client.call('bdev_nvme_get_io_paths', params)
963
964
965def bdev_nvme_set_preferred_path(client, name, cntlid):
966    """Set the preferred I/O path for an NVMe bdev when in multipath mode
967    Args:
968        name: NVMe bdev name
969        cntlid: NVMe-oF controller ID
970    """
971    params = dict()
972    params['name'] = name
973    params['cntlid'] = cntlid
974    return client.call('bdev_nvme_set_preferred_path', params)
975
976
977def bdev_nvme_set_multipath_policy(client, name, policy, selector=None, rr_min_io=None):
978    """Set multipath policy of the NVMe bdev
979    Args:
980        name: NVMe bdev name
981        policy: Multipath policy (active_passive or active_active)
982        selector: Multipath selector (round_robin, queue_depth)
983        rr_min_io: Number of IO to route to a path before switching to another one (optional)
984    """
985    params = dict()
986    params['name'] = name
987    params['policy'] = policy
988    if selector is not None:
989        params['selector'] = selector
990    if rr_min_io is not None:
991        params['rr_min_io'] = rr_min_io
992    return client.call('bdev_nvme_set_multipath_policy', params)
993
994
995def bdev_nvme_get_path_iostat(client, name):
996    """Get I/O statistics for IO paths of the block device.
997    Args:
998        name: bdev name to query
999    Returns:
1000        I/O statistics for IO paths of the requested block device.
1001    """
1002    params = dict()
1003    params['name'] = name
1004    return client.call('bdev_nvme_get_path_iostat', params)
1005
1006
1007def bdev_nvme_cuse_register(client, name):
1008    """Register CUSE devices on NVMe controller.
1009    Args:
1010        name: Name of the operating NVMe controller
1011    """
1012    params = dict()
1013    params['name'] = name
1014    return client.call('bdev_nvme_cuse_register', params)
1015
1016
1017def bdev_nvme_cuse_unregister(client, name):
1018    """Unregister CUSE devices on NVMe controller.
1019    Args:
1020        name: Name of the operating NVMe controller
1021    """
1022    params = dict()
1023    params['name'] = name
1024    return client.call('bdev_nvme_cuse_unregister', params)
1025
1026
1027def bdev_zone_block_create(client, name, base_bdev, zone_capacity, optimal_open_zones):
1028    """Creates a virtual zone device on top of existing non-zoned bdev.
1029    Args:
1030        name: Zone device name
1031        base_bdev: Base Nvme bdev name
1032        zone_capacity: Surfaced zone capacity in blocks
1033        optimal_open_zones: Number of zones required to reach optimal write speed (optional, default: 1)
1034    Returns:
1035        Name of created block device.
1036    """
1037    params = dict()
1038    params['name'] = name
1039    params['base_bdev'] = base_bdev
1040    params['zone_capacity'] = zone_capacity
1041    params['optimal_open_zones'] = optimal_open_zones
1042    return client.call('bdev_zone_block_create', params)
1043
1044
1045def bdev_zone_block_delete(client, name):
1046    """Remove block zone bdev from the system.
1047    Args:
1048        name: name of block zone bdev to delete
1049    """
1050    params = dict()
1051    params['name'] = name
1052    return client.call('bdev_zone_block_delete', params)
1053
1054
1055def bdev_rbd_register_cluster(client, name=None, user_id=None, config_param=None, config_file=None, key_file=None, core_mask=None):
1056    """Create a Rados Cluster object of the Ceph RBD backend.
1057    Args:
1058        name: name of Rados Cluster
1059        user_id: Ceph user name (optional)
1060        config_param: map of config keys to values (optional)
1061        config_file: file path of Ceph configuration file (optional)
1062        key_file: file path of Ceph key file (optional)
1063        core_mask: core mask for librbd IO context threads (optional)
1064    Returns:
1065        Name of registered Rados Cluster object.
1066    """
1067    params = dict()
1068    if name is not None:
1069        params['name'] = name
1070    if user_id is not None:
1071        params['user_id'] = user_id
1072    if config_param is not None:
1073        params['config_param'] = config_param
1074    if config_file is not None:
1075        params['config_file'] = config_file
1076    if key_file is not None:
1077        params['key_file'] = key_file
1078    if core_mask is not None:
1079        params['core_mask'] = core_mask
1080    return client.call('bdev_rbd_register_cluster', params)
1081
1082
1083def bdev_rbd_unregister_cluster(client, name):
1084    """Remove Rados cluster object from the system.
1085    Args:
1086        name: name of Rados cluster object to unregister
1087    """
1088    params = dict()
1089    params['name'] = name
1090    return client.call('bdev_rbd_unregister_cluster', params)
1091
1092
1093def bdev_rbd_get_clusters_info(client, name=None):
1094    """Get the cluster(s) info
1095    Args:
1096        name: name of Rados cluster object to query (optional; if omitted, query all clusters)
1097    Returns:
1098        List of registered Rados cluster information objects.
1099    """
1100    params = dict()
1101    if name is not None:
1102        params['name'] = name
1103    return client.call('bdev_rbd_get_clusters_info', params)
1104
1105
1106def bdev_rbd_create(client, pool_name, rbd_name, block_size, name=None, user_id=None, config=None, cluster_name=None, uuid=None):
1107    """Create a Ceph RBD block device.
1108    Args:
1109        pool_name: Ceph RBD pool name
1110        rbd_name: Ceph RBD image name
1111        block_size: block size of RBD volume
1112        name: name of block device (optional)
1113        user_id: Ceph user name (optional)
1114        config: map of config keys to values (optional)
1115        cluster_name: Name to identify Rados cluster (optional)
1116        uuid: UUID of block device (optional)
1117    Returns:
1118        Name of created block device.
1119    """
1120    params = dict()
1121    params['pool_name'] = pool_name
1122    params['rbd_name'] = rbd_name
1123    params['block_size'] = block_size
1124    if name is not None:
1125        params['name'] = name
1126    if user_id is not None:
1127        params['user_id'] = user_id
1128    if config is not None:
1129        params['config'] = config
1130    if cluster_name is not None:
1131        params['cluster_name'] = cluster_name
1132    else:
1133        print("WARNING:bdev_rbd_create should be used with specifying -c to have a cluster name after bdev_rbd_register_cluster.")
1134    if uuid is not None:
1135        params['uuid'] = uuid
1136    return client.call('bdev_rbd_create', params)
1137
1138
1139def bdev_rbd_delete(client, name):
1140    """Remove rbd bdev from the system.
1141    Args:
1142        name: name of rbd bdev to delete
1143    """
1144    params = dict()
1145    params['name'] = name
1146    return client.call('bdev_rbd_delete', params)
1147
1148
1149def bdev_rbd_resize(client, name, new_size):
1150    """Resize rbd bdev in the system.
1151    Args:
1152        name: name of rbd bdev to resize
1153        new_size: new bdev size of resize operation. The unit is MiB
1154    """
1155    params = dict()
1156    params['name'] = name
1157    params['new_size'] = new_size
1158    return client.call('bdev_rbd_resize', params)
1159
1160
1161def bdev_error_create(client, base_name, uuid=None):
1162    """Construct an error injection block device.
1163    Args:
1164        base_name: base bdev name
1165        uuid: UUID for this bdev (optional)
1166    """
1167    params = dict()
1168    params['base_name'] = base_name
1169    if uuid is not None:
1170        params['uuid'] = uuid
1171    return client.call('bdev_error_create', params)
1172
1173
1174def bdev_delay_create(client, base_bdev_name, name, avg_read_latency, p99_read_latency, avg_write_latency, p99_write_latency, uuid=None):
1175    """Construct a delay block device.
1176    Args:
1177        base_bdev_name: name of the existing bdev
1178        name: name of block device
1179        avg_read_latency: complete 99% of read ops with this delay
1180        p99_read_latency: complete 1% of read ops with this delay
1181        avg_write_latency: complete 99% of write ops with this delay
1182        p99_write_latency: complete 1% of write ops with this delay
1183        uuid: UUID of block device (optional)
1184    Returns:
1185        Name of created block device.
1186    """
1187    params = dict()
1188    params['base_bdev_name'] = base_bdev_name
1189    params['name'] = name
1190    params['avg_read_latency'] = avg_read_latency
1191    params['p99_read_latency'] = p99_read_latency
1192    params['avg_write_latency'] = avg_write_latency
1193    params['p99_write_latency'] = p99_write_latency
1194    if uuid is not None:
1195        params['uuid'] = uuid
1196    return client.call('bdev_delay_create', params)
1197
1198
1199def bdev_delay_delete(client, name):
1200    """Remove delay bdev from the system.
1201    Args:
1202        name: name of delay bdev to delete
1203    """
1204    params = dict()
1205    params['name'] = name
1206    return client.call('bdev_delay_delete', params)
1207
1208
1209def bdev_delay_update_latency(client, delay_bdev_name, latency_type, latency_us):
1210    """Update the latency value for a delay block device
1211    Args:
1212        delay_bdev_name: name of the delay bdev
1213        latency_type: 'one of: avg_read, avg_write, p99_read, p99_write. No other values accepted.'
1214        latency_us: 'new latency value.'
1215    Returns:
1216        True if successful, or a specific error otherwise.
1217    """
1218    params = dict()
1219    params['delay_bdev_name'] = delay_bdev_name
1220    params['latency_type'] = latency_type
1221    params['latency_us'] = latency_us
1222    return client.call('bdev_delay_update_latency', params)
1223
1224
1225def bdev_error_delete(client, name):
1226    """Remove error bdev from the system.
1227    Args:
1228        bdev_name: name of error bdev to delete
1229    """
1230    params = dict()
1231    params['name'] = name
1232    return client.call('bdev_error_delete', params)
1233
1234
1235def bdev_iscsi_set_options(client, timeout_sec=None):
1236    """Set options for the bdev iscsi.
1237    Args:
1238        timeout_sec: Timeout for command, in seconds, if 0, don't track timeout
1239    """
1240    params = dict()
1241    if timeout_sec is not None:
1242        params['timeout_sec'] = timeout_sec
1243    return client.call('bdev_iscsi_set_options', params)
1244
1245
1246def bdev_iscsi_create(client, name, url, initiator_iqn):
1247    """Construct an iSCSI block device.
1248    Args:
1249        name: name of block device
1250        url: iSCSI URL
1251        initiator_iqn: IQN name to be used by initiator
1252    Returns:
1253        Name of created block device.
1254    """
1255    params = dict()
1256    params['name'] = name
1257    params['url'] = url
1258    params['initiator_iqn'] = initiator_iqn
1259    return client.call('bdev_iscsi_create', params)
1260
1261
1262def bdev_iscsi_delete(client, name):
1263    """Remove iSCSI bdev from the system.
1264    Args:
1265        bdev_name: name of iSCSI bdev to delete
1266    """
1267    params = dict()
1268    params['name'] = name
1269    return client.call('bdev_iscsi_delete', params)
1270
1271
1272def bdev_passthru_create(client, base_bdev_name, name, uuid=None):
1273    """Construct a pass-through block device.
1274    Args:
1275        base_bdev_name: name of the existing bdev
1276        name: name of block device
1277        uuid: UUID of block device (optional)
1278    Returns:
1279        Name of created block device.
1280    """
1281    params = dict()
1282    params['base_bdev_name'] = base_bdev_name
1283    params['name'] = name
1284    if uuid is not None:
1285        params['uuid'] = uuid
1286    return client.call('bdev_passthru_create', params)
1287
1288
1289def bdev_passthru_delete(client, name):
1290    """Remove pass through bdev from the system.
1291    Args:
1292        name: name of pass through bdev to delete
1293    """
1294    params = dict()
1295    params['name'] = name
1296    return client.call('bdev_passthru_delete', params)
1297
1298
1299def bdev_opal_create(client, nvme_ctrlr_name, nsid, locking_range_id, range_start, range_length, password):
1300    """Create opal virtual block devices from a base nvme bdev.
1301    Args:
1302        nvme_ctrlr_name: name of the nvme ctrlr
1303        nsid: namespace ID of nvme ctrlr
1304        locking_range_id: locking range ID corresponding to this virtual bdev
1305        range_start: start address of this locking range
1306        range_length: length of this locking range
1307        password: admin password of base nvme bdev
1308    Returns:
1309        Name of the new created block devices.
1310    """
1311    params = dict()
1312    params['nvme_ctrlr_name'] = nvme_ctrlr_name
1313    params['nsid'] = nsid
1314    params['locking_range_id'] = locking_range_id
1315    params['range_start'] = range_start
1316    params['range_length'] = range_length
1317    params['password'] = password
1318    return client.call('bdev_opal_create', params)
1319
1320
1321def bdev_opal_get_info(client, bdev_name, password):
1322    """Get opal locking range info.
1323    Args:
1324        bdev_name: name of opal vbdev to get info
1325        password: admin password
1326    Returns:
1327        Locking range info.
1328    """
1329    params = dict()
1330    params['bdev_name'] = bdev_name
1331    params['password'] = password
1332    return client.call('bdev_opal_get_info', params)
1333
1334
1335def bdev_opal_delete(client, bdev_name, password):
1336    """Delete opal virtual bdev from the system.
1337    Args:
1338        bdev_name: name of opal vbdev to delete
1339        password: admin password of base nvme bdev
1340    """
1341    params = dict()
1342    params['bdev_name'] = bdev_name
1343    params['password'] = password
1344    return client.call('bdev_opal_delete', params)
1345
1346
1347def bdev_opal_new_user(client, bdev_name, admin_password, user_id, user_password):
1348    """Add a user to opal bdev who can set lock state for this bdev.
1349    Args:
1350        bdev_name: name of opal vbdev
1351        admin_password: admin password
1352        user_id: ID of the user who will be added to this opal bdev
1353        user_password: password set for this user
1354    """
1355    params = dict()
1356    params['bdev_name'] = bdev_name
1357    params['admin_password'] = admin_password
1358    params['user_id'] = user_id
1359    params['user_password'] = user_password
1360    return client.call('bdev_opal_new_user', params)
1361
1362
1363def bdev_opal_set_lock_state(client, bdev_name, user_id, password, lock_state):
1364    """set lock state for an opal bdev.
1365    Args:
1366        bdev_name: name of opal vbdev
1367        user_id: ID of the user who will set lock state
1368        password: password of the user
1369        lock_state: lock state to set
1370    """
1371    params = dict()
1372    params['bdev_name'] = bdev_name
1373    params['user_id'] = user_id
1374    params['password'] = password
1375    params['lock_state'] = lock_state
1376    return client.call('bdev_opal_set_lock_state', params)
1377
1378
1379def bdev_split_create(client, base_bdev, split_count, split_size_mb=None):
1380    """Create split block devices from a base bdev.
1381    Args:
1382        base_bdev: name of bdev to split
1383        split_count: number of split bdevs to create
1384        split_size_mb: size of each split volume in MiB (optional)
1385    Returns:
1386        List of created block devices.
1387    """
1388    params = dict()
1389    params['base_bdev'] = base_bdev
1390    params['split_count'] = split_count
1391    if split_size_mb is not None:
1392        params['split_size_mb'] = split_size_mb
1393    return client.call('bdev_split_create', params)
1394
1395
1396def bdev_split_delete(client, base_bdev):
1397    """Delete split block devices.
1398    Args:
1399        base_bdev: name of previously split bdev
1400    """
1401    params = dict()
1402    params['base_bdev'] = base_bdev
1403    return client.call('bdev_split_delete', params)
1404
1405
1406def bdev_ftl_create(client, name, base_bdev, cache, **kwargs):
1407    """Construct FTL bdev
1408    Args:
1409        name: name of the bdev
1410        base_bdev: name of the base bdev
1411        cache: name of the cache device
1412        kwargs: optional parameters
1413    """
1414    params = dict()
1415    params['name'] = name
1416    params['base_bdev'] = base_bdev
1417    params['cache'] = cache
1418    for key, value in kwargs.items():
1419        if value is not None:
1420            params[key] = value
1421    return client.call('bdev_ftl_create', params)
1422
1423
1424def bdev_ftl_load(client, name, base_bdev, cache, **kwargs):
1425    """Load FTL bdev
1426    Args:
1427        name: name of the bdev
1428        base_bdev: name of the base bdev
1429        cache: Name of the cache device
1430        kwargs: optional parameters
1431    """
1432    params = dict()
1433    params['name'] = name
1434    params['base_bdev'] = base_bdev
1435    params['cache'] = cache
1436    for key, value in kwargs.items():
1437        if value is not None:
1438            params[key] = value
1439    return client.call('bdev_ftl_load', params)
1440
1441
1442def bdev_ftl_unload(client, name, fast_shutdown=None):
1443    """Unload FTL bdev
1444    Args:
1445        name: name of the bdev
1446        fast_shutdown: When set FTL will minimize persisted data during deletion and rely on shared memory during next load
1447    """
1448    params = dict()
1449    params['name'] = name
1450    if fast_shutdown is not None:
1451        params['fast_shutdown'] = fast_shutdown
1452    return client.call('bdev_ftl_unload', params)
1453
1454
1455def bdev_ftl_delete(client, name, fast_shutdown=None):
1456    """Delete FTL bdev
1457    Args:
1458        name: name of the bdev
1459        fast_shutdown: When set FTL will minimize persisted data during deletion and rely on shared memory during next load
1460    """
1461    params = dict()
1462    params['name'] = name
1463    if fast_shutdown is not None:
1464        params['fast_shutdown'] = fast_shutdown
1465    return client.call('bdev_ftl_delete', params)
1466
1467
1468def bdev_ftl_unmap(client, name, lba, num_blocks):
1469    """FTL unmap
1470    Args:
1471        name: name of the bdev
1472        lba: starting lba to be unmapped
1473        num_blocks: number of blocks to unmap
1474    """
1475    params = dict()
1476    params['name'] = name
1477    params['lba'] = lba
1478    params['num_blocks'] = num_blocks
1479    return client.call('bdev_ftl_unmap', params)
1480
1481
1482def bdev_ftl_get_stats(client, name):
1483    """get FTL stats
1484    Args:
1485        name: name of the bdev
1486    """
1487    params = dict()
1488    params['name'] = name
1489    return client.call('bdev_ftl_get_stats', params)
1490
1491
1492def bdev_ftl_get_properties(client, name):
1493    """Get FTL properties
1494    Args:
1495        name: name of the bdev
1496    """
1497    params = dict()
1498    params['name'] = name
1499    return client.call('bdev_ftl_get_properties', params)
1500
1501
1502def bdev_ftl_set_property(client, name, ftl_property, value):
1503    """Set FTL property
1504    Args:
1505        name: name of the bdev
1506        ftl_property: name of the property to be set
1507        value: The new value of the updated property
1508    """
1509    params = dict()
1510    params['name'] = name
1511    params['ftl_property'] = ftl_property
1512    params['value'] = value
1513    return client.call('bdev_ftl_set_property', params)
1514
1515
1516def bdev_get_bdevs(client, name=None, timeout=None):
1517    """Get information about block devices.
1518    Args:
1519        name: bdev name to query (optional; if omitted, query all bdevs)
1520        timeout: time in ms to wait for the bdev with specified name to appear
1521    Returns:
1522        List of bdev information objects.
1523    """
1524    params = dict()
1525    if name is not None:
1526        params['name'] = name
1527    if timeout is not None:
1528        params['timeout'] = timeout
1529    return client.call('bdev_get_bdevs', params)
1530
1531
1532def bdev_get_iostat(client, name=None, per_channel=None):
1533    """Get I/O statistics for block devices.
1534    Args:
1535        name: bdev name to query (optional; if omitted, query all bdevs)
1536        per_channel: display per channel IO stats for specified bdev
1537    Returns:
1538        I/O statistics for the requested block devices.
1539    """
1540    params = dict()
1541    if name is not None:
1542        params['name'] = name
1543    if per_channel is not None:
1544        params['per_channel'] = per_channel
1545    return client.call('bdev_get_iostat', params)
1546
1547
1548def bdev_reset_iostat(client, name=None, mode=None):
1549    """Reset I/O statistics for block devices.
1550    Args:
1551        name: bdev name to reset (optional; if omitted, reset all bdevs)
1552        mode: mode to reset: all, maxmin (optional: if omitted, reset all fields)
1553    """
1554    params = dict()
1555    if name is not None:
1556        params['name'] = name
1557    if mode is not None:
1558        params['mode'] = mode
1559    return client.call('bdev_reset_iostat', params)
1560
1561
1562def bdev_enable_histogram(client, name, enable, opc):
1563    """Control whether histogram is enabled for specified bdev.
1564    Args:
1565        name: name of bdev
1566        enable: Enable or disable histogram on specified device
1567        opc: name of io_type (optional)
1568    """
1569    params = dict()
1570    params['name'] = name
1571    params['enable'] = enable
1572    if opc:
1573        params['opc'] = opc
1574    return client.call('bdev_enable_histogram', params)
1575
1576
1577def bdev_get_histogram(client, name):
1578    """Get histogram for specified bdev.
1579    Args:
1580        name: name of bdev
1581    """
1582    params = dict()
1583    params['name'] = name
1584    return client.call('bdev_get_histogram', params)
1585
1586
1587def bdev_error_inject_error(client, name, io_type, error_type, num=None,
1588                            queue_depth=None, corrupt_offset=None, corrupt_value=None):
1589    """Inject an error via an error bdev.
1590    Args:
1591        name: name of error bdev
1592        io_type: one of "clear", "read", "write", "unmap", "flush", or "all"
1593        error_type: one of "failure", "pending", "corrupt_data" or "nomem"
1594        num: number of commands to fail
1595        queue_depth: the queue depth at which to trigger the error
1596        corrupt_offset: offset in bytes to xor with corrupt_value
1597        corrupt_value: value for xor (1-255, 0 is invalid)
1598    """
1599    params = dict()
1600    params['name'] = name
1601    params['io_type'] = io_type
1602    params['error_type'] = error_type
1603    if num is not None:
1604        params['num'] = num
1605    if queue_depth is not None:
1606        params['queue_depth'] = queue_depth
1607    if corrupt_offset is not None:
1608        params['corrupt_offset'] = corrupt_offset
1609    if corrupt_value is not None:
1610        params['corrupt_value'] = corrupt_value
1611    return client.call('bdev_error_inject_error', params)
1612
1613
1614def bdev_set_qd_sampling_period(client, name, period):
1615    """Enable queue depth tracking on a specified bdev.
1616    Args:
1617        name: name of a bdev on which to track queue depth.
1618        period: period (in microseconds) at which to update the queue depth reading. If set to 0, polling will be disabled.
1619    """
1620    params = dict()
1621    params['name'] = name
1622    params['period'] = period
1623    return client.call('bdev_set_qd_sampling_period', params)
1624
1625
1626def bdev_set_qos_limit(
1627        client,
1628        name,
1629        rw_ios_per_sec=None,
1630        rw_mbytes_per_sec=None,
1631        r_mbytes_per_sec=None,
1632        w_mbytes_per_sec=None):
1633    """Set QoS rate limit on a block device.
1634    Args:
1635        name: name of block device
1636        rw_ios_per_sec: R/W IOs per second limit (>=1000, example: 20000). 0 means unlimited.
1637        rw_mbytes_per_sec: R/W megabytes per second limit (>=10, example: 100). 0 means unlimited.
1638        r_mbytes_per_sec: Read megabytes per second limit (>=10, example: 100). 0 means unlimited.
1639        w_mbytes_per_sec: Write megabytes per second limit (>=10, example: 100). 0 means unlimited.
1640    """
1641    params = dict()
1642    params['name'] = name
1643    if rw_ios_per_sec is not None:
1644        params['rw_ios_per_sec'] = rw_ios_per_sec
1645    if rw_mbytes_per_sec is not None:
1646        params['rw_mbytes_per_sec'] = rw_mbytes_per_sec
1647    if r_mbytes_per_sec is not None:
1648        params['r_mbytes_per_sec'] = r_mbytes_per_sec
1649    if w_mbytes_per_sec is not None:
1650        params['w_mbytes_per_sec'] = w_mbytes_per_sec
1651    return client.call('bdev_set_qos_limit', params)
1652
1653
1654def bdev_nvme_apply_firmware(client, bdev_name, filename):
1655    """Download and commit firmware to NVMe device.
1656    Args:
1657        bdev_name: name of NVMe block device
1658        filename: filename of the firmware to download
1659    """
1660    params = dict()
1661    params['bdev_name'] = bdev_name
1662    params['filename'] = filename
1663    return client.call('bdev_nvme_apply_firmware', params)
1664
1665
1666def bdev_nvme_get_transport_statistics(client):
1667    """Get bdev_nvme poll group transport statistics"""
1668    return client.call('bdev_nvme_get_transport_statistics')
1669
1670
1671def bdev_nvme_get_controller_health_info(client, name):
1672    """Display health log of the required NVMe bdev controller.
1673    Args:
1674        name: name of the required NVMe bdev controller
1675    Returns:
1676        Health log for the requested NVMe bdev controller.
1677    """
1678    params = dict()
1679    params['name'] = name
1680    return client.call('bdev_nvme_get_controller_health_info', params)
1681
1682
1683def bdev_daos_create(client, num_blocks, block_size, pool, cont, name, oclass=None, uuid=None):
1684    """Construct DAOS block device.
1685    Args:
1686        num_blocks: size of block device in blocks
1687        block_size: block size of device; must be a power of 2 and at least 512
1688        pool: UUID of DAOS pool
1689        cont: UUID of DAOS container
1690        name: name of block device (also the name of the backend file on DAOS DFS)
1691        oclass: DAOS object class (optional)
1692        uuid: UUID of block device (optional)
1693    Returns:
1694        Name of created block device.
1695    """
1696    params = dict()
1697    params['num_blocks'] = num_blocks
1698    params['block_size'] = block_size
1699    params['pool'] = pool
1700    params['cont'] = cont
1701    params['name'] = name
1702    if oclass is not None:
1703        params['oclass'] = oclass
1704    if uuid is not None:
1705        params['uuid'] = uuid
1706    return client.call('bdev_daos_create', params)
1707
1708
1709def bdev_daos_delete(client, name):
1710    """Delete DAOS block device.
1711    Args:
1712        bdev_name: name of DAOS bdev to delete
1713    """
1714    params = dict()
1715    params['name'] = name
1716    return client.call('bdev_daos_delete', params)
1717
1718
1719def bdev_daos_resize(client, name, new_size):
1720    """Resize DAOS bdev in the system.
1721    Args:
1722        name: name of DAOS bdev to resize
1723        new_size: new bdev size of resize operation. The unit is MiB
1724    """
1725    params = dict()
1726    params['name'] = name
1727    params['new_size'] = new_size
1728    return client.call('bdev_daos_resize', params)
1729
1730
1731def bdev_nvme_start_mdns_discovery(client, name, svcname, hostnqn=None):
1732    """Start discovery with mDNS
1733    Args:
1734        name: bdev name prefix; "n" + unique seqno + namespace ID will be appended to create unique names
1735        svcname: service to discover ("_nvme-disc._tcp")
1736        hostnqn: NQN to connect from (optional)
1737    """
1738    params = dict()
1739    params['name'] = name
1740    params['svcname'] = svcname
1741    if hostnqn is not None:
1742        params['hostnqn'] = hostnqn
1743    return client.call('bdev_nvme_start_mdns_discovery', params)
1744
1745
1746def bdev_nvme_stop_mdns_discovery(client, name):
1747    """Stop a previously started mdns discovery service
1748    Args:
1749        name: name of the discovery service to stop
1750    """
1751    params = dict()
1752    params['name'] = name
1753    return client.call('bdev_nvme_stop_mdns_discovery', params)
1754
1755
1756def bdev_nvme_get_mdns_discovery_info(client):
1757    """Get information about the automatic mdns discovery
1758    """
1759    return client.call('bdev_nvme_get_mdns_discovery_info')
1760