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