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