xref: /spdk/python/spdk/rpc/bdev.py (revision 83ba9086796471697a4975a58f60e2392bccd08c)
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_nvme_set_keys(client, name, dhchap_key=None, dhchap_ctrlr_key=None):
1028    """Set DH-HMAC-CHAP keys and force (re)authentication on all connected qpairs.
1029    Args:
1030        name: name of the NVMe controller
1031        dhchap_key: DH-HMAC-CHAP key name
1032        dhchap_ctrlr_key: DH-HMAC-CHAP controller key name
1033    """
1034    params = {'name': name}
1035    if dhchap_key is not None:
1036        params['dhchap_key'] = dhchap_key
1037    if dhchap_ctrlr_key is not None:
1038        params['dhchap_ctrlr_key'] = dhchap_ctrlr_key
1039    return client.call('bdev_nvme_set_keys', params)
1040
1041
1042def bdev_zone_block_create(client, name, base_bdev, zone_capacity, optimal_open_zones):
1043    """Creates a virtual zone device on top of existing non-zoned bdev.
1044    Args:
1045        name: Zone device name
1046        base_bdev: Base Nvme bdev name
1047        zone_capacity: Surfaced zone capacity in blocks
1048        optimal_open_zones: Number of zones required to reach optimal write speed (optional, default: 1)
1049    Returns:
1050        Name of created block device.
1051    """
1052    params = dict()
1053    params['name'] = name
1054    params['base_bdev'] = base_bdev
1055    params['zone_capacity'] = zone_capacity
1056    params['optimal_open_zones'] = optimal_open_zones
1057    return client.call('bdev_zone_block_create', params)
1058
1059
1060def bdev_zone_block_delete(client, name):
1061    """Remove block zone bdev from the system.
1062    Args:
1063        name: name of block zone bdev to delete
1064    """
1065    params = dict()
1066    params['name'] = name
1067    return client.call('bdev_zone_block_delete', params)
1068
1069
1070def bdev_rbd_register_cluster(client, name=None, user_id=None, config_param=None, config_file=None, key_file=None, core_mask=None):
1071    """Create a Rados Cluster object of the Ceph RBD backend.
1072    Args:
1073        name: name of Rados Cluster
1074        user_id: Ceph user name (optional)
1075        config_param: map of config keys to values (optional)
1076        config_file: file path of Ceph configuration file (optional)
1077        key_file: file path of Ceph key file (optional)
1078        core_mask: core mask for librbd IO context threads (optional)
1079    Returns:
1080        Name of registered Rados Cluster object.
1081    """
1082    params = dict()
1083    if name is not None:
1084        params['name'] = name
1085    if user_id is not None:
1086        params['user_id'] = user_id
1087    if config_param is not None:
1088        params['config_param'] = config_param
1089    if config_file is not None:
1090        params['config_file'] = config_file
1091    if key_file is not None:
1092        params['key_file'] = key_file
1093    if core_mask is not None:
1094        params['core_mask'] = core_mask
1095    return client.call('bdev_rbd_register_cluster', params)
1096
1097
1098def bdev_rbd_unregister_cluster(client, name):
1099    """Remove Rados cluster object from the system.
1100    Args:
1101        name: name of Rados cluster object to unregister
1102    """
1103    params = dict()
1104    params['name'] = name
1105    return client.call('bdev_rbd_unregister_cluster', params)
1106
1107
1108def bdev_rbd_get_clusters_info(client, name=None):
1109    """Get the cluster(s) info
1110    Args:
1111        name: name of Rados cluster object to query (optional; if omitted, query all clusters)
1112    Returns:
1113        List of registered Rados cluster information objects.
1114    """
1115    params = dict()
1116    if name is not None:
1117        params['name'] = name
1118    return client.call('bdev_rbd_get_clusters_info', params)
1119
1120
1121def bdev_rbd_create(client, pool_name, rbd_name, block_size, name=None, user_id=None, config=None, cluster_name=None, uuid=None):
1122    """Create a Ceph RBD block device.
1123    Args:
1124        pool_name: Ceph RBD pool name
1125        rbd_name: Ceph RBD image name
1126        block_size: block size of RBD volume
1127        name: name of block device (optional)
1128        user_id: Ceph user name (optional)
1129        config: map of config keys to values (optional)
1130        cluster_name: Name to identify Rados cluster (optional)
1131        uuid: UUID of block device (optional)
1132    Returns:
1133        Name of created block device.
1134    """
1135    params = dict()
1136    params['pool_name'] = pool_name
1137    params['rbd_name'] = rbd_name
1138    params['block_size'] = block_size
1139    if name is not None:
1140        params['name'] = name
1141    if user_id is not None:
1142        params['user_id'] = user_id
1143    if config is not None:
1144        params['config'] = config
1145    if cluster_name is not None:
1146        params['cluster_name'] = cluster_name
1147    else:
1148        print("WARNING:bdev_rbd_create should be used with specifying -c to have a cluster name after bdev_rbd_register_cluster.")
1149    if uuid is not None:
1150        params['uuid'] = uuid
1151    return client.call('bdev_rbd_create', params)
1152
1153
1154def bdev_rbd_delete(client, name):
1155    """Remove rbd bdev from the system.
1156    Args:
1157        name: name of rbd bdev to delete
1158    """
1159    params = dict()
1160    params['name'] = name
1161    return client.call('bdev_rbd_delete', params)
1162
1163
1164def bdev_rbd_resize(client, name, new_size):
1165    """Resize rbd bdev in the system.
1166    Args:
1167        name: name of rbd bdev to resize
1168        new_size: new bdev size of resize operation. The unit is MiB
1169    """
1170    params = dict()
1171    params['name'] = name
1172    params['new_size'] = new_size
1173    return client.call('bdev_rbd_resize', params)
1174
1175
1176def bdev_error_create(client, base_name, uuid=None):
1177    """Construct an error injection block device.
1178    Args:
1179        base_name: base bdev name
1180        uuid: UUID for this bdev (optional)
1181    """
1182    params = dict()
1183    params['base_name'] = base_name
1184    if uuid is not None:
1185        params['uuid'] = uuid
1186    return client.call('bdev_error_create', params)
1187
1188
1189def bdev_delay_create(client, base_bdev_name, name, avg_read_latency, p99_read_latency, avg_write_latency, p99_write_latency, uuid=None):
1190    """Construct a delay block device.
1191    Args:
1192        base_bdev_name: name of the existing bdev
1193        name: name of block device
1194        avg_read_latency: complete 99% of read ops with this delay
1195        p99_read_latency: complete 1% of read ops with this delay
1196        avg_write_latency: complete 99% of write ops with this delay
1197        p99_write_latency: complete 1% of write ops with this delay
1198        uuid: UUID of block device (optional)
1199    Returns:
1200        Name of created block device.
1201    """
1202    params = dict()
1203    params['base_bdev_name'] = base_bdev_name
1204    params['name'] = name
1205    params['avg_read_latency'] = avg_read_latency
1206    params['p99_read_latency'] = p99_read_latency
1207    params['avg_write_latency'] = avg_write_latency
1208    params['p99_write_latency'] = p99_write_latency
1209    if uuid is not None:
1210        params['uuid'] = uuid
1211    return client.call('bdev_delay_create', params)
1212
1213
1214def bdev_delay_delete(client, name):
1215    """Remove delay bdev from the system.
1216    Args:
1217        name: name of delay bdev to delete
1218    """
1219    params = dict()
1220    params['name'] = name
1221    return client.call('bdev_delay_delete', params)
1222
1223
1224def bdev_delay_update_latency(client, delay_bdev_name, latency_type, latency_us):
1225    """Update the latency value for a delay block device
1226    Args:
1227        delay_bdev_name: name of the delay bdev
1228        latency_type: 'one of: avg_read, avg_write, p99_read, p99_write. No other values accepted.'
1229        latency_us: 'new latency value.'
1230    Returns:
1231        True if successful, or a specific error otherwise.
1232    """
1233    params = dict()
1234    params['delay_bdev_name'] = delay_bdev_name
1235    params['latency_type'] = latency_type
1236    params['latency_us'] = latency_us
1237    return client.call('bdev_delay_update_latency', params)
1238
1239
1240def bdev_error_delete(client, name):
1241    """Remove error bdev from the system.
1242    Args:
1243        bdev_name: name of error bdev to delete
1244    """
1245    params = dict()
1246    params['name'] = name
1247    return client.call('bdev_error_delete', params)
1248
1249
1250def bdev_iscsi_set_options(client, timeout_sec=None):
1251    """Set options for the bdev iscsi.
1252    Args:
1253        timeout_sec: Timeout for command, in seconds, if 0, don't track timeout
1254    """
1255    params = dict()
1256    if timeout_sec is not None:
1257        params['timeout_sec'] = timeout_sec
1258    return client.call('bdev_iscsi_set_options', params)
1259
1260
1261def bdev_iscsi_create(client, name, url, initiator_iqn):
1262    """Construct an iSCSI block device.
1263    Args:
1264        name: name of block device
1265        url: iSCSI URL
1266        initiator_iqn: IQN name to be used by initiator
1267    Returns:
1268        Name of created block device.
1269    """
1270    params = dict()
1271    params['name'] = name
1272    params['url'] = url
1273    params['initiator_iqn'] = initiator_iqn
1274    return client.call('bdev_iscsi_create', params)
1275
1276
1277def bdev_iscsi_delete(client, name):
1278    """Remove iSCSI bdev from the system.
1279    Args:
1280        bdev_name: name of iSCSI bdev to delete
1281    """
1282    params = dict()
1283    params['name'] = name
1284    return client.call('bdev_iscsi_delete', params)
1285
1286
1287def bdev_passthru_create(client, base_bdev_name, name, uuid=None):
1288    """Construct a pass-through block device.
1289    Args:
1290        base_bdev_name: name of the existing bdev
1291        name: name of block device
1292        uuid: UUID of block device (optional)
1293    Returns:
1294        Name of created block device.
1295    """
1296    params = dict()
1297    params['base_bdev_name'] = base_bdev_name
1298    params['name'] = name
1299    if uuid is not None:
1300        params['uuid'] = uuid
1301    return client.call('bdev_passthru_create', params)
1302
1303
1304def bdev_passthru_delete(client, name):
1305    """Remove pass through bdev from the system.
1306    Args:
1307        name: name of pass through bdev to delete
1308    """
1309    params = dict()
1310    params['name'] = name
1311    return client.call('bdev_passthru_delete', params)
1312
1313
1314def bdev_opal_create(client, nvme_ctrlr_name, nsid, locking_range_id, range_start, range_length, password):
1315    """Create opal virtual block devices from a base nvme bdev.
1316    Args:
1317        nvme_ctrlr_name: name of the nvme ctrlr
1318        nsid: namespace ID of nvme ctrlr
1319        locking_range_id: locking range ID corresponding to this virtual bdev
1320        range_start: start address of this locking range
1321        range_length: length of this locking range
1322        password: admin password of base nvme bdev
1323    Returns:
1324        Name of the new created block devices.
1325    """
1326    params = dict()
1327    params['nvme_ctrlr_name'] = nvme_ctrlr_name
1328    params['nsid'] = nsid
1329    params['locking_range_id'] = locking_range_id
1330    params['range_start'] = range_start
1331    params['range_length'] = range_length
1332    params['password'] = password
1333    return client.call('bdev_opal_create', params)
1334
1335
1336def bdev_opal_get_info(client, bdev_name, password):
1337    """Get opal locking range info.
1338    Args:
1339        bdev_name: name of opal vbdev to get info
1340        password: admin password
1341    Returns:
1342        Locking range info.
1343    """
1344    params = dict()
1345    params['bdev_name'] = bdev_name
1346    params['password'] = password
1347    return client.call('bdev_opal_get_info', params)
1348
1349
1350def bdev_opal_delete(client, bdev_name, password):
1351    """Delete opal virtual bdev from the system.
1352    Args:
1353        bdev_name: name of opal vbdev to delete
1354        password: admin password of base nvme bdev
1355    """
1356    params = dict()
1357    params['bdev_name'] = bdev_name
1358    params['password'] = password
1359    return client.call('bdev_opal_delete', params)
1360
1361
1362def bdev_opal_new_user(client, bdev_name, admin_password, user_id, user_password):
1363    """Add a user to opal bdev who can set lock state for this bdev.
1364    Args:
1365        bdev_name: name of opal vbdev
1366        admin_password: admin password
1367        user_id: ID of the user who will be added to this opal bdev
1368        user_password: password set for this user
1369    """
1370    params = dict()
1371    params['bdev_name'] = bdev_name
1372    params['admin_password'] = admin_password
1373    params['user_id'] = user_id
1374    params['user_password'] = user_password
1375    return client.call('bdev_opal_new_user', params)
1376
1377
1378def bdev_opal_set_lock_state(client, bdev_name, user_id, password, lock_state):
1379    """set lock state for an opal bdev.
1380    Args:
1381        bdev_name: name of opal vbdev
1382        user_id: ID of the user who will set lock state
1383        password: password of the user
1384        lock_state: lock state to set
1385    """
1386    params = dict()
1387    params['bdev_name'] = bdev_name
1388    params['user_id'] = user_id
1389    params['password'] = password
1390    params['lock_state'] = lock_state
1391    return client.call('bdev_opal_set_lock_state', params)
1392
1393
1394def bdev_split_create(client, base_bdev, split_count, split_size_mb=None):
1395    """Create split block devices from a base bdev.
1396    Args:
1397        base_bdev: name of bdev to split
1398        split_count: number of split bdevs to create
1399        split_size_mb: size of each split volume in MiB (optional)
1400    Returns:
1401        List of created block devices.
1402    """
1403    params = dict()
1404    params['base_bdev'] = base_bdev
1405    params['split_count'] = split_count
1406    if split_size_mb is not None:
1407        params['split_size_mb'] = split_size_mb
1408    return client.call('bdev_split_create', params)
1409
1410
1411def bdev_split_delete(client, base_bdev):
1412    """Delete split block devices.
1413    Args:
1414        base_bdev: name of previously split bdev
1415    """
1416    params = dict()
1417    params['base_bdev'] = base_bdev
1418    return client.call('bdev_split_delete', params)
1419
1420
1421def bdev_ftl_create(client, name, base_bdev, cache, **kwargs):
1422    """Construct FTL bdev
1423    Args:
1424        name: name of the bdev
1425        base_bdev: name of the base bdev
1426        cache: name of the cache device
1427        kwargs: optional parameters
1428    """
1429    params = dict()
1430    params['name'] = name
1431    params['base_bdev'] = base_bdev
1432    params['cache'] = cache
1433    for key, value in kwargs.items():
1434        if value is not None:
1435            params[key] = value
1436    return client.call('bdev_ftl_create', params)
1437
1438
1439def bdev_ftl_load(client, name, base_bdev, cache, **kwargs):
1440    """Load FTL bdev
1441    Args:
1442        name: name of the bdev
1443        base_bdev: name of the base bdev
1444        cache: Name of the cache device
1445        kwargs: optional parameters
1446    """
1447    params = dict()
1448    params['name'] = name
1449    params['base_bdev'] = base_bdev
1450    params['cache'] = cache
1451    for key, value in kwargs.items():
1452        if value is not None:
1453            params[key] = value
1454    return client.call('bdev_ftl_load', params)
1455
1456
1457def bdev_ftl_unload(client, name, fast_shutdown=None):
1458    """Unload FTL bdev
1459    Args:
1460        name: name of the bdev
1461        fast_shutdown: When set FTL will minimize persisted data during deletion and rely on shared memory during next load
1462    """
1463    params = dict()
1464    params['name'] = name
1465    if fast_shutdown is not None:
1466        params['fast_shutdown'] = fast_shutdown
1467    return client.call('bdev_ftl_unload', params)
1468
1469
1470def bdev_ftl_delete(client, name, fast_shutdown=None):
1471    """Delete FTL bdev
1472    Args:
1473        name: name of the bdev
1474        fast_shutdown: When set FTL will minimize persisted data during deletion and rely on shared memory during next load
1475    """
1476    params = dict()
1477    params['name'] = name
1478    if fast_shutdown is not None:
1479        params['fast_shutdown'] = fast_shutdown
1480    return client.call('bdev_ftl_delete', params)
1481
1482
1483def bdev_ftl_unmap(client, name, lba, num_blocks):
1484    """FTL unmap
1485    Args:
1486        name: name of the bdev
1487        lba: starting lba to be unmapped
1488        num_blocks: number of blocks to unmap
1489    """
1490    params = dict()
1491    params['name'] = name
1492    params['lba'] = lba
1493    params['num_blocks'] = num_blocks
1494    return client.call('bdev_ftl_unmap', params)
1495
1496
1497def bdev_ftl_get_stats(client, name):
1498    """get FTL stats
1499    Args:
1500        name: name of the bdev
1501    """
1502    params = dict()
1503    params['name'] = name
1504    return client.call('bdev_ftl_get_stats', params)
1505
1506
1507def bdev_ftl_get_properties(client, name):
1508    """Get FTL properties
1509    Args:
1510        name: name of the bdev
1511    """
1512    params = dict()
1513    params['name'] = name
1514    return client.call('bdev_ftl_get_properties', params)
1515
1516
1517def bdev_ftl_set_property(client, name, ftl_property, value):
1518    """Set FTL property
1519    Args:
1520        name: name of the bdev
1521        ftl_property: name of the property to be set
1522        value: The new value of the updated property
1523    """
1524    params = dict()
1525    params['name'] = name
1526    params['ftl_property'] = ftl_property
1527    params['value'] = value
1528    return client.call('bdev_ftl_set_property', params)
1529
1530
1531def bdev_get_bdevs(client, name=None, timeout=None):
1532    """Get information about block devices.
1533    Args:
1534        name: bdev name to query (optional; if omitted, query all bdevs)
1535        timeout: time in ms to wait for the bdev with specified name to appear
1536    Returns:
1537        List of bdev information objects.
1538    """
1539    params = dict()
1540    if name is not None:
1541        params['name'] = name
1542    if timeout is not None:
1543        params['timeout'] = timeout
1544    return client.call('bdev_get_bdevs', params)
1545
1546
1547def bdev_get_iostat(client, name=None, per_channel=None, reset_mode=None):
1548    """Get I/O statistics for block devices.
1549    Args:
1550        name: bdev name to query (optional; if omitted, query all bdevs)
1551        per_channel: display per channel IO stats for specified bdev
1552        reset_mode: mode to reset stats after getting: all, maxmin, none (optional: if omitted, no reset will happen)
1553    Returns:
1554        I/O statistics for the requested block devices.
1555    """
1556    params = dict()
1557    if name is not None:
1558        params['name'] = name
1559    if per_channel is not None:
1560        params['per_channel'] = per_channel
1561    if reset_mode is not None:
1562        params['reset_mode'] = reset_mode
1563    return client.call('bdev_get_iostat', params)
1564
1565
1566def bdev_reset_iostat(client, name=None, mode=None):
1567    """Reset I/O statistics for block devices.
1568    Args:
1569        name: bdev name to reset (optional; if omitted, reset all bdevs)
1570        mode: mode to reset: all, maxmin (optional: if omitted, reset all fields)
1571    """
1572    params = dict()
1573    if name is not None:
1574        params['name'] = name
1575    if mode is not None:
1576        params['mode'] = mode
1577    return client.call('bdev_reset_iostat', params)
1578
1579
1580def bdev_enable_histogram(client, name, enable, opc):
1581    """Control whether histogram is enabled for specified bdev.
1582    Args:
1583        name: name of bdev
1584        enable: Enable or disable histogram on specified device
1585        opc: name of io_type (optional)
1586    """
1587    params = dict()
1588    params['name'] = name
1589    params['enable'] = enable
1590    if opc:
1591        params['opc'] = opc
1592    return client.call('bdev_enable_histogram', params)
1593
1594
1595def bdev_get_histogram(client, name):
1596    """Get histogram for specified bdev.
1597    Args:
1598        name: name of bdev
1599    """
1600    params = dict()
1601    params['name'] = name
1602    return client.call('bdev_get_histogram', params)
1603
1604
1605def bdev_error_inject_error(client, name, io_type, error_type, num=None,
1606                            queue_depth=None, corrupt_offset=None, corrupt_value=None):
1607    """Inject an error via an error bdev.
1608    Args:
1609        name: name of error bdev
1610        io_type: one of "clear", "read", "write", "unmap", "flush", or "all"
1611        error_type: one of "failure", "pending", "corrupt_data" or "nomem"
1612        num: number of commands to fail
1613        queue_depth: the queue depth at which to trigger the error
1614        corrupt_offset: offset in bytes to xor with corrupt_value
1615        corrupt_value: value for xor (1-255, 0 is invalid)
1616    """
1617    params = dict()
1618    params['name'] = name
1619    params['io_type'] = io_type
1620    params['error_type'] = error_type
1621    if num is not None:
1622        params['num'] = num
1623    if queue_depth is not None:
1624        params['queue_depth'] = queue_depth
1625    if corrupt_offset is not None:
1626        params['corrupt_offset'] = corrupt_offset
1627    if corrupt_value is not None:
1628        params['corrupt_value'] = corrupt_value
1629    return client.call('bdev_error_inject_error', params)
1630
1631
1632def bdev_set_qd_sampling_period(client, name, period):
1633    """Enable queue depth tracking on a specified bdev.
1634    Args:
1635        name: name of a bdev on which to track queue depth.
1636        period: period (in microseconds) at which to update the queue depth reading. If set to 0, polling will be disabled.
1637    """
1638    params = dict()
1639    params['name'] = name
1640    params['period'] = period
1641    return client.call('bdev_set_qd_sampling_period', params)
1642
1643
1644def bdev_set_qos_limit(
1645        client,
1646        name,
1647        rw_ios_per_sec=None,
1648        rw_mbytes_per_sec=None,
1649        r_mbytes_per_sec=None,
1650        w_mbytes_per_sec=None):
1651    """Set QoS rate limit on a block device.
1652    Args:
1653        name: name of block device
1654        rw_ios_per_sec: R/W IOs per second limit (>=1000, example: 20000). 0 means unlimited.
1655        rw_mbytes_per_sec: R/W megabytes per second limit (>=10, example: 100). 0 means unlimited.
1656        r_mbytes_per_sec: Read megabytes per second limit (>=10, example: 100). 0 means unlimited.
1657        w_mbytes_per_sec: Write megabytes per second limit (>=10, example: 100). 0 means unlimited.
1658    """
1659    params = dict()
1660    params['name'] = name
1661    if rw_ios_per_sec is not None:
1662        params['rw_ios_per_sec'] = rw_ios_per_sec
1663    if rw_mbytes_per_sec is not None:
1664        params['rw_mbytes_per_sec'] = rw_mbytes_per_sec
1665    if r_mbytes_per_sec is not None:
1666        params['r_mbytes_per_sec'] = r_mbytes_per_sec
1667    if w_mbytes_per_sec is not None:
1668        params['w_mbytes_per_sec'] = w_mbytes_per_sec
1669    return client.call('bdev_set_qos_limit', params)
1670
1671
1672def bdev_nvme_apply_firmware(client, bdev_name, filename):
1673    """Download and commit firmware to NVMe device.
1674    Args:
1675        bdev_name: name of NVMe block device
1676        filename: filename of the firmware to download
1677    """
1678    params = dict()
1679    params['bdev_name'] = bdev_name
1680    params['filename'] = filename
1681    return client.call('bdev_nvme_apply_firmware', params)
1682
1683
1684def bdev_nvme_get_transport_statistics(client):
1685    """Get bdev_nvme poll group transport statistics"""
1686    return client.call('bdev_nvme_get_transport_statistics')
1687
1688
1689def bdev_nvme_get_controller_health_info(client, name):
1690    """Display health log of the required NVMe bdev controller.
1691    Args:
1692        name: name of the required NVMe bdev controller
1693    Returns:
1694        Health log for the requested NVMe bdev controller.
1695    """
1696    params = dict()
1697    params['name'] = name
1698    return client.call('bdev_nvme_get_controller_health_info', params)
1699
1700
1701def bdev_daos_create(client, num_blocks, block_size, pool, cont, name, oclass=None, uuid=None):
1702    """Construct DAOS block device.
1703    Args:
1704        num_blocks: size of block device in blocks
1705        block_size: block size of device; must be a power of 2 and at least 512
1706        pool: UUID of DAOS pool
1707        cont: UUID of DAOS container
1708        name: name of block device (also the name of the backend file on DAOS DFS)
1709        oclass: DAOS object class (optional)
1710        uuid: UUID of block device (optional)
1711    Returns:
1712        Name of created block device.
1713    """
1714    params = dict()
1715    params['num_blocks'] = num_blocks
1716    params['block_size'] = block_size
1717    params['pool'] = pool
1718    params['cont'] = cont
1719    params['name'] = name
1720    if oclass is not None:
1721        params['oclass'] = oclass
1722    if uuid is not None:
1723        params['uuid'] = uuid
1724    return client.call('bdev_daos_create', params)
1725
1726
1727def bdev_daos_delete(client, name):
1728    """Delete DAOS block device.
1729    Args:
1730        bdev_name: name of DAOS bdev to delete
1731    """
1732    params = dict()
1733    params['name'] = name
1734    return client.call('bdev_daos_delete', params)
1735
1736
1737def bdev_daos_resize(client, name, new_size):
1738    """Resize DAOS bdev in the system.
1739    Args:
1740        name: name of DAOS bdev to resize
1741        new_size: new bdev size of resize operation. The unit is MiB
1742    """
1743    params = dict()
1744    params['name'] = name
1745    params['new_size'] = new_size
1746    return client.call('bdev_daos_resize', params)
1747
1748
1749def bdev_nvme_start_mdns_discovery(client, name, svcname, hostnqn=None):
1750    """Start discovery with mDNS
1751    Args:
1752        name: bdev name prefix; "n" + unique seqno + namespace ID will be appended to create unique names
1753        svcname: service to discover ("_nvme-disc._tcp")
1754        hostnqn: NQN to connect from (optional)
1755    """
1756    params = dict()
1757    params['name'] = name
1758    params['svcname'] = svcname
1759    if hostnqn is not None:
1760        params['hostnqn'] = hostnqn
1761    return client.call('bdev_nvme_start_mdns_discovery', params)
1762
1763
1764def bdev_nvme_stop_mdns_discovery(client, name):
1765    """Stop a previously started mdns discovery service
1766    Args:
1767        name: name of the discovery service to stop
1768    """
1769    params = dict()
1770    params['name'] = name
1771    return client.call('bdev_nvme_stop_mdns_discovery', params)
1772
1773
1774def bdev_nvme_get_mdns_discovery_info(client):
1775    """Get information about the automatic mdns discovery
1776    """
1777    return client.call('bdev_nvme_get_mdns_discovery_info')
1778