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