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