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