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