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