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