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 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): 853 """Reset NVMe controller. 854 855 Args: 856 name: controller name 857 """ 858 859 params = {'name': name} 860 861 return client.call('bdev_nvme_reset_controller', params) 862 863 864def bdev_nvme_start_discovery(client, name, trtype, traddr, adrfam=None, trsvcid=None, 865 hostnqn=None, wait_for_attach=None, ctrlr_loss_timeout_sec=None, 866 reconnect_delay_sec=None, fast_io_fail_timeout_sec=None, 867 attach_timeout_ms=None): 868 """Start discovery with the specified discovery subsystem 869 870 Args: 871 name: bdev name prefix; "n" + namespace ID will be appended to create unique names 872 trtype: transport type ("PCIe", "RDMA", "FC", "TCP") 873 traddr: transport address (PCI BDF or IP address) 874 adrfam: address family ("IPv4", "IPv6", "IB", or "FC") 875 trsvcid: transport service ID (port number for IP-based addresses) 876 hostnqn: NQN to connect from (optional) 877 wait_for_attach: Wait to complete RPC until all discovered NVM subsystems have attached (optional) 878 ctrlr_loss_timeout_sec: Time to wait until ctrlr is reconnected before deleting ctrlr. 879 -1 means infinite reconnect retries. 0 means no reconnect retry. 880 If reconnect_delay_sec is zero, ctrlr_loss_timeout_sec has to be zero. 881 If reconnect_delay_sec is non-zero, ctrlr_loss_timeout_sec has to be -1 or not less than reconnect_delay_sec. 882 (optional) 883 reconnect_delay_sec: Time to delay a reconnect retry. 884 If ctrlr_loss_timeout_sec is zero, reconnect_delay_sec has to be zero. 885 If ctrlr_loss_timeout_sec is -1, reconnect_delay_sec has to be non-zero. 886 If ctrlr_loss_timeout_sec is not -1 or zero, reconnect_sec has to be non-zero and less than ctrlr_loss_timeout_sec. 887 (optional) 888 fail_io_fast_timeout_sec: Time to wait until ctrlr is reconnected before failing I/O to ctrlr. 889 0 means no such timeout. 890 If fast_io_fail_timeout_sec is not zero, it has to be not less than reconnect_delay_sec and less than 891 ctrlr_loss_timeout_sec if ctrlr_loss_timeout_sec is not -1. (optional) 892 attach_timeout_ms: Time to wait until the discovery and all discovered NVM subsystems are attached (optional) 893 """ 894 params = {'name': name, 895 'trtype': trtype, 896 'traddr': traddr} 897 898 if hostnqn: 899 params['hostnqn'] = hostnqn 900 901 if adrfam: 902 params['adrfam'] = adrfam 903 904 if trsvcid: 905 params['trsvcid'] = trsvcid 906 907 if wait_for_attach: 908 params['wait_for_attach'] = True 909 910 if attach_timeout_ms is not None: 911 params['attach_timeout_ms'] = attach_timeout_ms 912 913 if ctrlr_loss_timeout_sec is not None: 914 params['ctrlr_loss_timeout_sec'] = ctrlr_loss_timeout_sec 915 916 if reconnect_delay_sec is not None: 917 params['reconnect_delay_sec'] = reconnect_delay_sec 918 919 if fast_io_fail_timeout_sec is not None: 920 params['fast_io_fail_timeout_sec'] = fast_io_fail_timeout_sec 921 922 return client.call('bdev_nvme_start_discovery', params) 923 924 925def bdev_nvme_stop_discovery(client, name): 926 """Stop a previously started discovery service 927 928 Args: 929 name: name of discovery service to start 930 """ 931 params = {'name': name} 932 933 return client.call('bdev_nvme_stop_discovery', params) 934 935 936def bdev_nvme_get_discovery_info(client): 937 """Get information about the automatic discovery 938 """ 939 return client.call('bdev_nvme_get_discovery_info') 940 941 942def bdev_nvme_get_io_paths(client, name): 943 """Display all or the specified NVMe bdev's active I/O paths 944 945 Args: 946 name: Name of the NVMe bdev (optional) 947 948 Returns: 949 List of active I/O paths 950 """ 951 params = {} 952 if name: 953 params['name'] = name 954 return client.call('bdev_nvme_get_io_paths', params) 955 956 957def bdev_nvme_set_preferred_path(client, name, cntlid): 958 """Set the preferred I/O path for an NVMe bdev when in multipath mode 959 960 Args: 961 name: NVMe bdev name 962 cntlid: NVMe-oF controller ID 963 """ 964 965 params = {'name': name, 966 'cntlid': cntlid} 967 968 return client.call('bdev_nvme_set_preferred_path', params) 969 970 971def bdev_nvme_set_multipath_policy(client, name, policy, selector, rr_min_io): 972 """Set multipath policy of the NVMe bdev 973 974 Args: 975 name: NVMe bdev name 976 policy: Multipath policy (active_passive or active_active) 977 selector: Multipath selector (round_robin, queue_depth) 978 rr_min_io: Number of IO to route to a path before switching to another one (optional) 979 """ 980 981 params = {'name': name, 982 'policy': policy} 983 if selector: 984 params['selector'] = selector 985 if rr_min_io: 986 params['rr_min_io'] = rr_min_io 987 988 return client.call('bdev_nvme_set_multipath_policy', params) 989 990 991def bdev_nvme_get_path_iostat(client, name): 992 """Get I/O statistics for IO paths of the block device. 993 994 Args: 995 name: bdev name to query 996 997 Returns: 998 I/O statistics for IO paths of the requested block device. 999 """ 1000 params = {'name': name} 1001 1002 return client.call('bdev_nvme_get_path_iostat', params) 1003 1004 1005def bdev_nvme_cuse_register(client, name): 1006 """Register CUSE devices on NVMe controller. 1007 1008 Args: 1009 name: Name of the operating NVMe controller 1010 """ 1011 params = {'name': name} 1012 1013 return client.call('bdev_nvme_cuse_register', params) 1014 1015 1016def bdev_nvme_cuse_unregister(client, name): 1017 """Unregister CUSE devices on NVMe controller. 1018 1019 Args: 1020 name: Name of the operating NVMe controller 1021 """ 1022 params = {'name': name} 1023 1024 return client.call('bdev_nvme_cuse_unregister', params) 1025 1026 1027def bdev_zone_block_create(client, name, base_bdev, zone_capacity, optimal_open_zones): 1028 """Creates a virtual zone device on top of existing non-zoned bdev. 1029 1030 Args: 1031 name: Zone device name 1032 base_bdev: Base Nvme bdev name 1033 zone_capacity: Surfaced zone capacity in blocks 1034 optimal_open_zones: Number of zones required to reach optimal write speed (optional, default: 1) 1035 1036 Returns: 1037 Name of created block device. 1038 """ 1039 params = {'name': name, 1040 'base_bdev': base_bdev, 1041 'zone_capacity': zone_capacity, 1042 'optimal_open_zones': optimal_open_zones} 1043 1044 return client.call('bdev_zone_block_create', params) 1045 1046 1047def bdev_zone_block_delete(client, name): 1048 """Remove block zone bdev from the system. 1049 1050 Args: 1051 name: name of block zone bdev to delete 1052 """ 1053 params = {'name': name} 1054 return client.call('bdev_zone_block_delete', params) 1055 1056 1057def bdev_rbd_register_cluster(client, name, user=None, config_param=None, config_file=None, key_file=None, core_mask=None): 1058 """Create a Rados Cluster object of the Ceph RBD backend. 1059 1060 Args: 1061 name: name of Rados Cluster 1062 user: Ceph user name (optional) 1063 config_param: map of config keys to values (optional) 1064 config_file: file path of Ceph configuration file (optional) 1065 key_file: file path of Ceph key file (optional) 1066 core_mask: core mask for librbd IO context threads (optional) 1067 1068 Returns: 1069 Name of registered Rados Cluster object. 1070 """ 1071 params = {'name': name} 1072 1073 if user is not None: 1074 params['user_id'] = user 1075 if config_param is not None: 1076 params['config_param'] = config_param 1077 if config_file is not None: 1078 params['config_file'] = config_file 1079 if key_file is not None: 1080 params['key_file'] = key_file 1081 if core_mask is not None: 1082 params['core_mask'] = core_mask 1083 1084 return client.call('bdev_rbd_register_cluster', params) 1085 1086 1087def bdev_rbd_unregister_cluster(client, name): 1088 """Remove Rados cluster object from the system. 1089 1090 Args: 1091 name: name of Rados cluster object to unregister 1092 """ 1093 params = {'name': name} 1094 return client.call('bdev_rbd_unregister_cluster', params) 1095 1096 1097def bdev_rbd_get_clusters_info(client, name): 1098 """Get the cluster(s) info 1099 1100 Args: 1101 name: name of Rados cluster object to query (optional; if omitted, query all clusters) 1102 1103 Returns: 1104 List of registered Rados cluster information objects. 1105 """ 1106 params = {} 1107 if name: 1108 params['name'] = name 1109 return client.call('bdev_rbd_get_clusters_info', params) 1110 1111 1112def bdev_rbd_create(client, pool_name, rbd_name, block_size, name=None, user=None, config=None, cluster_name=None, uuid=None): 1113 """Create a Ceph RBD block device. 1114 1115 Args: 1116 pool_name: Ceph RBD pool name 1117 rbd_name: Ceph RBD image name 1118 block_size: block size of RBD volume 1119 name: name of block device (optional) 1120 user: Ceph user name (optional) 1121 config: map of config keys to values (optional) 1122 cluster_name: Name to identify Rados cluster (optional) 1123 uuid: UUID of block device (optional) 1124 1125 Returns: 1126 Name of created block device. 1127 """ 1128 params = { 1129 'pool_name': pool_name, 1130 'rbd_name': rbd_name, 1131 'block_size': block_size, 1132 } 1133 1134 if name: 1135 params['name'] = name 1136 if user is not None: 1137 params['user_id'] = user 1138 if config is not None: 1139 params['config'] = config 1140 if cluster_name is not None: 1141 params['cluster_name'] = cluster_name 1142 else: 1143 print("WARNING:bdev_rbd_create should be used with specifying -c to have a cluster name after bdev_rbd_register_cluster.") 1144 if uuid is not None: 1145 params['uuid'] = uuid 1146 1147 return client.call('bdev_rbd_create', params) 1148 1149 1150def bdev_rbd_delete(client, name): 1151 """Remove rbd bdev from the system. 1152 1153 Args: 1154 name: name of rbd bdev to delete 1155 """ 1156 params = {'name': name} 1157 return client.call('bdev_rbd_delete', params) 1158 1159 1160def bdev_rbd_resize(client, name, new_size): 1161 """Resize rbd bdev in the system. 1162 1163 Args: 1164 name: name of rbd bdev to resize 1165 new_size: new bdev size of resize operation. The unit is MiB 1166 """ 1167 params = { 1168 'name': name, 1169 'new_size': new_size, 1170 } 1171 return client.call('bdev_rbd_resize', params) 1172 1173 1174def bdev_error_create(client, base_name, uuid=None): 1175 """Construct an error injection block device. 1176 1177 Args: 1178 base_name: base bdev name 1179 uuid: UUID for this bdev (optional) 1180 """ 1181 params = {'base_name': base_name} 1182 if uuid is not None: 1183 params['uuid'] = uuid 1184 return client.call('bdev_error_create', params) 1185 1186 1187def bdev_delay_create(client, base_bdev_name, name, avg_read_latency, p99_read_latency, avg_write_latency, p99_write_latency, uuid=None): 1188 """Construct a delay block device. 1189 1190 Args: 1191 base_bdev_name: name of the existing bdev 1192 name: name of block device 1193 avg_read_latency: complete 99% of read ops with this delay 1194 p99_read_latency: complete 1% of read ops with this delay 1195 avg_write_latency: complete 99% of write ops with this delay 1196 p99_write_latency: complete 1% of write ops with this delay 1197 uuid: UUID of block device (optional) 1198 1199 Returns: 1200 Name of created block device. 1201 """ 1202 params = { 1203 'base_bdev_name': base_bdev_name, 1204 'name': name, 1205 'avg_read_latency': avg_read_latency, 1206 'p99_read_latency': p99_read_latency, 1207 'avg_write_latency': avg_write_latency, 1208 'p99_write_latency': p99_write_latency, 1209 } 1210 if uuid: 1211 params['uuid'] = uuid 1212 return client.call('bdev_delay_create', params) 1213 1214 1215def bdev_delay_delete(client, name): 1216 """Remove delay bdev from the system. 1217 1218 Args: 1219 name: name of delay bdev to delete 1220 """ 1221 params = {'name': name} 1222 return client.call('bdev_delay_delete', params) 1223 1224 1225def bdev_delay_update_latency(client, delay_bdev_name, latency_type, latency_us): 1226 """Update the latency value for a delay block device 1227 1228 Args: 1229 delay_bdev_name: name of the delay bdev 1230 latency_type: 'one of: avg_read, avg_write, p99_read, p99_write. No other values accepted.' 1231 latency_us: 'new latency value.' 1232 1233 Returns: 1234 True if successful, or a specific error otherwise. 1235 """ 1236 params = { 1237 'delay_bdev_name': delay_bdev_name, 1238 'latency_type': latency_type, 1239 'latency_us': latency_us, 1240 } 1241 return client.call('bdev_delay_update_latency', params) 1242 1243 1244def bdev_error_delete(client, name): 1245 """Remove error bdev from the system. 1246 1247 Args: 1248 bdev_name: name of error bdev to delete 1249 """ 1250 params = {'name': name} 1251 return client.call('bdev_error_delete', params) 1252 1253 1254def bdev_iscsi_set_options(client, timeout_sec): 1255 """Set options for the bdev iscsi. 1256 1257 Args: 1258 timeout_sec: Timeout for command, in seconds, if 0, don't track timeout 1259 """ 1260 params = {} 1261 1262 if timeout_sec is not None: 1263 params['timeout_sec'] = timeout_sec 1264 1265 return client.call('bdev_iscsi_set_options', params) 1266 1267 1268def bdev_iscsi_create(client, name, url, initiator_iqn): 1269 """Construct an iSCSI block device. 1270 1271 Args: 1272 name: name of block device 1273 url: iSCSI URL 1274 initiator_iqn: IQN name to be used by initiator 1275 1276 Returns: 1277 Name of created block device. 1278 """ 1279 params = { 1280 'name': name, 1281 'url': url, 1282 'initiator_iqn': initiator_iqn, 1283 } 1284 return client.call('bdev_iscsi_create', params) 1285 1286 1287def bdev_iscsi_delete(client, name): 1288 """Remove iSCSI bdev from the system. 1289 1290 Args: 1291 bdev_name: name of iSCSI bdev to delete 1292 """ 1293 params = {'name': name} 1294 return client.call('bdev_iscsi_delete', params) 1295 1296 1297def bdev_passthru_create(client, base_bdev_name, name): 1298 """Construct a pass-through block device. 1299 1300 Args: 1301 base_bdev_name: name of the existing bdev 1302 name: name of block device 1303 1304 Returns: 1305 Name of created block device. 1306 """ 1307 params = { 1308 'base_bdev_name': base_bdev_name, 1309 'name': name, 1310 } 1311 return client.call('bdev_passthru_create', params) 1312 1313 1314def bdev_passthru_delete(client, name): 1315 """Remove pass through bdev from the system. 1316 1317 Args: 1318 name: name of pass through bdev to delete 1319 """ 1320 params = {'name': name} 1321 return client.call('bdev_passthru_delete', params) 1322 1323 1324def bdev_opal_create(client, nvme_ctrlr_name, nsid, locking_range_id, range_start, range_length, password): 1325 """Create opal virtual block devices from a base nvme bdev. 1326 1327 Args: 1328 nvme_ctrlr_name: name of the nvme ctrlr 1329 nsid: namespace ID of nvme ctrlr 1330 locking_range_id: locking range ID corresponding to this virtual bdev 1331 range_start: start address of this locking range 1332 range_length: length of this locking range 1333 password: admin password of base nvme bdev 1334 1335 Returns: 1336 Name of the new created block devices. 1337 """ 1338 params = { 1339 'nvme_ctrlr_name': nvme_ctrlr_name, 1340 'nsid': nsid, 1341 'locking_range_id': locking_range_id, 1342 'range_start': range_start, 1343 'range_length': range_length, 1344 'password': password, 1345 } 1346 1347 return client.call('bdev_opal_create', params) 1348 1349 1350def bdev_opal_get_info(client, bdev_name, password): 1351 """Get opal locking range info. 1352 1353 Args: 1354 bdev_name: name of opal vbdev to get info 1355 password: admin password 1356 1357 Returns: 1358 Locking range info. 1359 """ 1360 params = { 1361 'bdev_name': bdev_name, 1362 'password': password, 1363 } 1364 1365 return client.call('bdev_opal_get_info', params) 1366 1367 1368def bdev_opal_delete(client, bdev_name, password): 1369 """Delete opal virtual bdev from the system. 1370 1371 Args: 1372 bdev_name: name of opal vbdev to delete 1373 password: admin password of base nvme bdev 1374 """ 1375 params = { 1376 'bdev_name': bdev_name, 1377 'password': password, 1378 } 1379 1380 return client.call('bdev_opal_delete', params) 1381 1382 1383def bdev_opal_new_user(client, bdev_name, admin_password, user_id, user_password): 1384 """Add a user to opal bdev who can set lock state for this bdev. 1385 1386 Args: 1387 bdev_name: name of opal vbdev 1388 admin_password: admin password 1389 user_id: ID of the user who will be added to this opal bdev 1390 user_password: password set for this user 1391 """ 1392 params = { 1393 'bdev_name': bdev_name, 1394 'admin_password': admin_password, 1395 'user_id': user_id, 1396 'user_password': user_password, 1397 } 1398 1399 return client.call('bdev_opal_new_user', params) 1400 1401 1402def bdev_opal_set_lock_state(client, bdev_name, user_id, password, lock_state): 1403 """set lock state for an opal bdev. 1404 1405 Args: 1406 bdev_name: name of opal vbdev 1407 user_id: ID of the user who will set lock state 1408 password: password of the user 1409 lock_state: lock state to set 1410 """ 1411 params = { 1412 'bdev_name': bdev_name, 1413 'user_id': user_id, 1414 'password': password, 1415 'lock_state': lock_state, 1416 } 1417 1418 return client.call('bdev_opal_set_lock_state', params) 1419 1420 1421def bdev_split_create(client, base_bdev, split_count, split_size_mb=None): 1422 """Create split block devices from a base bdev. 1423 1424 Args: 1425 base_bdev: name of bdev to split 1426 split_count: number of split bdevs to create 1427 split_size_mb: size of each split volume in MiB (optional) 1428 1429 Returns: 1430 List of created block devices. 1431 """ 1432 params = { 1433 'base_bdev': base_bdev, 1434 'split_count': split_count, 1435 } 1436 if split_size_mb: 1437 params['split_size_mb'] = split_size_mb 1438 1439 return client.call('bdev_split_create', params) 1440 1441 1442def bdev_split_delete(client, base_bdev): 1443 """Delete split block devices. 1444 1445 Args: 1446 base_bdev: name of previously split bdev 1447 """ 1448 params = { 1449 'base_bdev': base_bdev, 1450 } 1451 1452 return client.call('bdev_split_delete', params) 1453 1454 1455def bdev_ftl_create(client, name, base_bdev, **kwargs): 1456 """Construct FTL bdev 1457 1458 Args: 1459 name: name of the bdev 1460 base_bdev: name of the base bdev 1461 kwargs: optional parameters 1462 """ 1463 params = {'name': name, 1464 'base_bdev': base_bdev} 1465 for key, value in kwargs.items(): 1466 if value is not None: 1467 params[key] = value 1468 1469 return client.call('bdev_ftl_create', params) 1470 1471 1472def bdev_ftl_load(client, name, base_bdev, **kwargs): 1473 """Load 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_load', params) 1487 1488 1489def bdev_ftl_unload(client, name, fast_shutdown): 1490 """Unload FTL bdev 1491 1492 Args: 1493 name: name of the bdev 1494 """ 1495 params = {'name': name, 1496 'fast_shutdown': fast_shutdown} 1497 1498 return client.call('bdev_ftl_unload', params) 1499 1500 1501def bdev_ftl_delete(client, name, fast_shutdown): 1502 """Delete FTL bdev 1503 1504 Args: 1505 name: name of the bdev 1506 """ 1507 params = {'name': name, 1508 'fast_shutdown': fast_shutdown} 1509 1510 return client.call('bdev_ftl_delete', params) 1511 1512 1513def bdev_ftl_unmap(client, name, lba, num_blocks): 1514 """FTL unmap 1515 1516 Args: 1517 name: name of the bdev 1518 lba: starting lba to be unmapped 1519 num_blocks: number of blocks to unmap 1520 """ 1521 params = {'name': name, 1522 'lba': lba, 1523 'num_blocks': num_blocks} 1524 1525 return client.call('bdev_ftl_unmap', params) 1526 1527 1528def bdev_ftl_get_stats(client, name): 1529 """get FTL stats 1530 1531 Args: 1532 name: name of the bdev 1533 """ 1534 params = {'name': name} 1535 1536 return client.call('bdev_ftl_get_stats', params) 1537 1538 1539def bdev_get_bdevs(client, name=None, timeout=None): 1540 """Get information about block devices. 1541 1542 Args: 1543 name: bdev name to query (optional; if omitted, query all bdevs) 1544 timeout: time in ms to wait for the bdev with specified name to appear 1545 1546 Returns: 1547 List of bdev information objects. 1548 """ 1549 params = {} 1550 if name: 1551 params['name'] = name 1552 if timeout: 1553 params['timeout'] = timeout 1554 return client.call('bdev_get_bdevs', params) 1555 1556 1557def bdev_get_iostat(client, name=None, per_channel=None): 1558 """Get I/O statistics for block devices. 1559 1560 Args: 1561 name: bdev name to query (optional; if omitted, query all bdevs) 1562 per_channel: display per channel IO stats for specified bdev 1563 1564 Returns: 1565 I/O statistics for the requested block devices. 1566 """ 1567 params = {} 1568 if name: 1569 params['name'] = name 1570 if per_channel: 1571 params['per_channel'] = per_channel 1572 return client.call('bdev_get_iostat', params) 1573 1574 1575def bdev_reset_iostat(client, name=None, mode=None): 1576 """Reset I/O statistics for block devices. 1577 1578 Args: 1579 name: bdev name to reset (optional; if omitted, reset all bdevs) 1580 mode: mode to reset: all, maxmin (optional: if omitted, reset all fields) 1581 """ 1582 params = {} 1583 if name: 1584 params['name'] = name 1585 if mode: 1586 params['mode'] = mode 1587 1588 return client.call('bdev_reset_iostat', params) 1589 1590 1591def bdev_enable_histogram(client, name, enable): 1592 """Control whether histogram is enabled for specified bdev. 1593 1594 Args: 1595 bdev_name: name of bdev 1596 """ 1597 params = {'name': name, "enable": enable} 1598 return client.call('bdev_enable_histogram', params) 1599 1600 1601def bdev_get_histogram(client, name): 1602 """Get histogram for specified bdev. 1603 1604 Args: 1605 bdev_name: name of bdev 1606 """ 1607 params = {'name': name} 1608 return client.call('bdev_get_histogram', params) 1609 1610 1611def bdev_error_inject_error(client, name, io_type, error_type, num, 1612 corrupt_offset, corrupt_value): 1613 """Inject an error via an error bdev. 1614 1615 Args: 1616 name: name of error bdev 1617 io_type: one of "clear", "read", "write", "unmap", "flush", or "all" 1618 error_type: one of "failure", "pending", or "corrupt_data" 1619 num: number of commands to fail 1620 corrupt_offset: offset in bytes to xor with corrupt_value 1621 corrupt_value: value for xor (1-255, 0 is invalid) 1622 """ 1623 params = { 1624 'name': name, 1625 'io_type': io_type, 1626 'error_type': error_type, 1627 } 1628 1629 if num: 1630 params['num'] = num 1631 if corrupt_offset: 1632 params['corrupt_offset'] = corrupt_offset 1633 if corrupt_value: 1634 params['corrupt_value'] = corrupt_value 1635 1636 return client.call('bdev_error_inject_error', params) 1637 1638 1639def bdev_set_qd_sampling_period(client, name, period): 1640 """Enable queue depth tracking on a specified bdev. 1641 1642 Args: 1643 name: name of a bdev on which to track queue depth. 1644 period: period (in microseconds) at which to update the queue depth reading. If set to 0, polling will be disabled. 1645 """ 1646 1647 params = {} 1648 params['name'] = name 1649 params['period'] = period 1650 return client.call('bdev_set_qd_sampling_period', params) 1651 1652 1653def bdev_set_qos_limit( 1654 client, 1655 name, 1656 rw_ios_per_sec=None, 1657 rw_mbytes_per_sec=None, 1658 r_mbytes_per_sec=None, 1659 w_mbytes_per_sec=None): 1660 """Set QoS rate limit on a block device. 1661 1662 Args: 1663 name: name of block device 1664 rw_ios_per_sec: R/W IOs per second limit (>=1000, example: 20000). 0 means unlimited. 1665 rw_mbytes_per_sec: R/W megabytes per second limit (>=10, example: 100). 0 means unlimited. 1666 r_mbytes_per_sec: Read megabytes per second limit (>=10, example: 100). 0 means unlimited. 1667 w_mbytes_per_sec: Write megabytes per second limit (>=10, example: 100). 0 means unlimited. 1668 """ 1669 params = {} 1670 params['name'] = name 1671 if rw_ios_per_sec is not None: 1672 params['rw_ios_per_sec'] = rw_ios_per_sec 1673 if rw_mbytes_per_sec is not None: 1674 params['rw_mbytes_per_sec'] = rw_mbytes_per_sec 1675 if r_mbytes_per_sec is not None: 1676 params['r_mbytes_per_sec'] = r_mbytes_per_sec 1677 if w_mbytes_per_sec is not None: 1678 params['w_mbytes_per_sec'] = w_mbytes_per_sec 1679 return client.call('bdev_set_qos_limit', params) 1680 1681 1682def bdev_nvme_apply_firmware(client, bdev_name, filename): 1683 """Download and commit firmware to NVMe device. 1684 1685 Args: 1686 bdev_name: name of NVMe block device 1687 filename: filename of the firmware to download 1688 """ 1689 params = { 1690 'filename': filename, 1691 'bdev_name': bdev_name, 1692 } 1693 return client.call('bdev_nvme_apply_firmware', params) 1694 1695 1696def bdev_nvme_get_transport_statistics(client): 1697 """Get bdev_nvme poll group transport statistics""" 1698 return client.call('bdev_nvme_get_transport_statistics') 1699 1700 1701def bdev_nvme_get_controller_health_info(client, name): 1702 """Display health log of the required NVMe bdev controller. 1703 1704 Args: 1705 name: name of the required NVMe bdev controller 1706 1707 Returns: 1708 Health log for the requested NVMe bdev controller. 1709 """ 1710 params = {} 1711 params['name'] = name 1712 return client.call('bdev_nvme_get_controller_health_info', params) 1713 1714 1715def bdev_daos_create(client, num_blocks, block_size, pool, cont, name, oclass=None, uuid=None): 1716 """Construct DAOS block device. 1717 1718 Args: 1719 num_blocks: size of block device in blocks 1720 block_size: block size of device; must be a power of 2 and at least 512 1721 name: name of block device (also the name of the backend file on DAOS DFS) 1722 pool: UUID of DAOS pool 1723 cont: UUID of DAOS container 1724 uuid: UUID of block device (optional) 1725 oclass: DAOS object class (optional) 1726 1727 Returns: 1728 Name of created block device. 1729 """ 1730 params = {'num_blocks': num_blocks, 'block_size': block_size, 'pool': pool, 'cont': cont, 'name': name} 1731 if uuid: 1732 params['uuid'] = uuid 1733 if oclass: 1734 params['oclass'] = oclass 1735 return client.call('bdev_daos_create', params) 1736 1737 1738def bdev_daos_delete(client, name): 1739 """Delete DAOS block device. 1740 1741 Args: 1742 bdev_name: name of DAOS bdev to delete 1743 """ 1744 params = {'name': name} 1745 return client.call('bdev_daos_delete', params) 1746 1747 1748def bdev_daos_resize(client, name, new_size): 1749 """Resize DAOS bdev in the system. 1750 Args: 1751 name: name of DAOS bdev to resize 1752 new_size: new bdev size of resize operation. The unit is MiB 1753 """ 1754 params = { 1755 'name': name, 1756 'new_size': new_size, 1757 } 1758 return client.call('bdev_daos_resize', params) 1759 1760 1761def bdev_nvme_start_mdns_discovery(client, name, svcname, hostnqn=None): 1762 """Start discovery with mDNS 1763 1764 Args: 1765 name: bdev name prefix; "n" + unique seqno + namespace ID will be appended to create unique names 1766 svcname: service to discover ("_nvme-disc._tcp") 1767 hostnqn: NQN to connect from (optional) 1768 """ 1769 params = {'name': name, 1770 'svcname': svcname} 1771 1772 if hostnqn: 1773 params['hostnqn'] = hostnqn 1774 return client.call('bdev_nvme_start_mdns_discovery', params) 1775 1776 1777def bdev_nvme_stop_mdns_discovery(client, name): 1778 """Stop a previously started mdns discovery service 1779 1780 Args: 1781 name: name of the discovery service to stop 1782 """ 1783 params = {'name': name} 1784 1785 return client.call('bdev_nvme_stop_mdns_discovery', params) 1786 1787 1788def bdev_nvme_get_mdns_discovery_info(client): 1789 """Get information about the automatic mdns discovery 1790 """ 1791 return client.call('bdev_nvme_get_mdns_discovery_info') 1792