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