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