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