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